• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

rocs/VisualEditor

  • sources
  • kde-4.14
  • kdeedu
  • rocs
  • VisualEditor
  • Tools
ToolManager.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Rocs.
3  Copyright 2010-2011 Tomaz Canabrava <tomaz.canabrava@gmail.com>
4  Copyright 2010 Wagner Reck <wagner.reck@gmail.com>
5  Copyright 2012-2013 Andreas Cord-Landwehr <cola@uni-paderborn.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #include "ToolManager.h"
22 
23 #include "ToolsPluginInterface.h"
24 
25 #include <KServiceTypeTrader>
26 #include <KPluginInfo>
27 #include <KDebug>
28 
29 class ToolManagerPrivate
30 {
31 public:
32  typedef KPluginInfo::List KPluginList;
33 
34  QObject *_parent;
35  bool _initialized;
36  KPluginList _toolsPluginsInfo;
37  QMap<KPluginInfo, ToolsPluginInterface*> _toolsPluginsMap;
38 
39  ToolManagerPrivate(QObject *parent)
40  : _parent(parent)
41  , _initialized(false)
42  {
43  _toolsPluginsInfo = KPluginInfo::fromServices(KServiceTypeTrader::self()->query("Rocs/ToolPlugin"));
44  }
45 
46  ~ToolManagerPrivate()
47  {
48  }
49 
50  void lazyInit()
51  {
52  if (!_initialized) {
53  _initialized = true;
54  loadPlugins();
55  }
56  }
57 
58  bool loadPlugin(QString name)
59  {
60  KPluginInfo kpi = PluginInfoFromName(name);
61 
62  if (kpi.isValid()) {
63  QString error;
64  ToolsPluginInterface * plugin = KServiceTypeTrader::createInstanceFromQuery<ToolsPluginInterface>(
65  QString::fromLatin1("Rocs/ToolPlugin"),
66  QString::fromLatin1("[Name]=='%1'").arg(name),
67  _parent,
68  QVariantList(),
69  &error);
70 
71  if (plugin) {
72  _toolsPluginsMap.insert(kpi, plugin);
73  kpi.setPluginEnabled(true);
74  return true;
75  }
76 
77  else {
78  kWarning() << "Error while loading plugin: " << name << error;
79  }
80 
81  } else {
82  kWarning() << "Error while loading tool plugin " << name;
83  }
84  return false;
85  }
86 
87  void loadPlugins()
88  {
89  foreach(const KPluginInfo &info, _toolsPluginsInfo) {
90  loadPlugin(info.name());
91  }
92  }
93 
94  KPluginInfo PluginInfoFromName(const QString &name)
95  {
96  foreach(const KPluginInfo &info, _toolsPluginsInfo) {
97  if (info.name() == name) {
98  return info;
99  }
100  }
101  return KPluginInfo();
102  }
103 };
104 
105 ToolManager & ToolManager::self()
106 {
107  static ToolManager instance;
108  instance.d->lazyInit();
109  return instance;
110 }
111 
112 
113 ToolManager::ToolManager()
114  : d(new ToolManagerPrivate(this))
115 {
116 }
117 
118 
119 ToolManager::~ToolManager()
120 {
121 }
122 
123 
124 KPluginInfo ToolManager::pluginInfo(ToolsPluginInterface *plugin)
125 {
126  if (d->_toolsPluginsMap.keys(plugin).length() == 0) {
127  d->loadPlugin(plugin->displayName());
128  }
129 
130  return d->_toolsPluginsMap.key(plugin);
131 }
132 
133 
134 QList<ToolsPluginInterface *> ToolManager::plugins() const
135 {
136  QList<ToolsPluginInterface *> plugins;
137 
138  QMap<KPluginInfo, ToolsPluginInterface *>::const_iterator iter;
139  for (iter = d->_toolsPluginsMap.constBegin(); iter != d->_toolsPluginsMap.constEnd(); ++iter) {
140  if (iter.key().isPluginEnabled()){
141  plugins.append(d->_toolsPluginsMap[iter.key()]);
142  }
143  }
144  return plugins;
145 }
ToolManager::plugins
QList< ToolsPluginInterface * > plugins() const
Return list of available tool plugins.
Definition: ToolManager.cpp:134
QMap< KPluginInfo, ToolsPluginInterface * >
ToolsPluginInterface::displayName
QString displayName()
Returns the display name of this plugin.
Definition: ToolsPluginInterface.cpp:54
ToolManager::pluginInfo
KPluginInfo pluginInfo(ToolsPluginInterface *plugin)
Definition: ToolManager.cpp:124
QList::append
void append(const T &value)
QObject
QString
QList
ToolsPluginInterface
This interface must be implemented by all Visual graph editor tools.
Definition: ToolsPluginInterface.h:73
ToolManager::self
static ToolManager & self()
Returns self reference to tool manager.
Definition: ToolManager.cpp:105
ToolManager.h
QMap::key
const Key key(const T &value) const
ToolsPluginInterface.h
QString::fromLatin1
QString fromLatin1(const char *str, int size)
ToolManager
This singelton class provides access to all available visual graph editor tools.
Definition: ToolManager.h:35
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:16:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

rocs/VisualEditor

Skip menu "rocs/VisualEditor"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal