Slicer  5.2
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
qSlicerAbstractModuleFactoryManager.h
Go to the documentation of this file.
1 /*==============================================================================
2 
3  Program: 3D Slicer
4 
5  Copyright (c) Kitware Inc.
6 
7  See COPYRIGHT.txt
8  or http://www.slicer.org/copyright/copyright.txt for details.
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 
16  This file was originally developed by Jean-Christophe Fillion-Robin, Kitware Inc.
17  and was partially funded by NIH grant 3P41RR013218-12S1
18 
19 ==============================================================================*/
20 
21 #ifndef __qSlicerAbstractModuleFactoryManager_h
22 #define __qSlicerAbstractModuleFactoryManager_h
23 
24 // Qt includes
25 #include <QObject>
26 #include <QString>
27 
28 // CTK includes
29 #include <ctkAbstractFileBasedFactory.h>
30 
31 #include "qSlicerBaseQTCoreExport.h"
32 
34 
35 class qSlicerAbstractModuleFactoryManagerPrivate;
36 
65 class Q_SLICER_BASE_QTCORE_EXPORT qSlicerAbstractModuleFactoryManager : public QObject
66 {
67  Q_OBJECT
78  Q_PROPERTY(QStringList searchPaths READ searchPaths WRITE setSearchPaths)
79 
80 
81  Q_PROPERTY(QStringList modulesToIgnore READ modulesToIgnore WRITE setModulesToIgnore NOTIFY modulesToIgnoreChanged)
85 public:
86  typedef ctkAbstractFileBasedFactory<qSlicerAbstractCoreModule> qSlicerFileBasedModuleFactory;
87  typedef ctkAbstractFactory<qSlicerAbstractCoreModule> qSlicerModuleFactory;
88 
89  typedef QObject Superclass;
90  qSlicerAbstractModuleFactoryManager(QObject * newParent = nullptr);
91 
95 
97  virtual void printAdditionalInfo();
98 
116  void registerFactory(qSlicerModuleFactory* factory, int priority = 0);
117  void unregisterFactory(qSlicerModuleFactory* factory);
118  void unregisterFactories();
119 
120  void setSearchPaths(const QStringList& searchPaths);
121  QStringList searchPaths()const;
122 
125  inline void addSearchPaths(const QStringList& paths);
127  inline void addSearchPath(const QString& path);
128 
131  inline void removeSearchPaths(const QStringList& paths);
132 
134  inline void removeSearchPath(const QString& path);
135 
136  void setExplicitModules(const QStringList& moduleNames);
137  QStringList explicitModules()const;
138 
139 
144  void setModulesToIgnore(const QStringList& modulesNames);
145  QStringList modulesToIgnore()const;
146 
149  inline void addModuleToIgnore(const QString& moduleName);
150 
153  inline void removeModuleToIgnore(const QString& moduleName);
154 
157  QStringList ignoredModuleNames()const;
158 
161  void registerModules();
162 
163  Q_INVOKABLE void registerModule(const QFileInfo& file);
164 
166  Q_INVOKABLE QStringList registeredModuleNames() const;
167 
169  Q_INVOKABLE bool isRegistered(const QString& name)const;
170 
172  virtual void instantiateModules();
173 
175  Q_INVOKABLE QStringList instantiatedModuleNames() const;
176 
178  Q_INVOKABLE bool isInstantiated(const QString& name)const;
179 
181  Q_INVOKABLE qSlicerAbstractCoreModule* moduleInstance(const QString& moduleName)const;
182 
184  void uninstantiateModules();
185 
187  void setVerboseModuleDiscovery(bool value);
188 
192  QStringList dependentModules(const QString& module)const;
193 
197  QStringList moduleDependees(const QString& module)const;
198 
199 signals:
202  void modulesRegistered(const QStringList& moduleNames);
203  void moduleRegistered(const QString& moduleName);
204 
205  void explicitModulesChanged(const QStringList& moduleNames);
206 
207  void modulesToIgnoreChanged(const QStringList& moduleNames);
208  void moduleIgnored(const QString& moduleName);
209 
210  void modulesInstantiated(const QStringList& moduleNames);
211  void moduleInstantiated(const QString& moduleName);
212 
213  void modulesAboutToBeUninstantiated(const QStringList& moduleNames);
214  void moduleAboutToBeUninstantiated(const QString& moduleName);
215 
216  void modulesUninstantiated(const QStringList& moduleNames);
217  void moduleUninstantiated(const QString& moduleName);
218 
219 public slots:
223  void setIsVerbose(bool flag);
224  bool isVerbose()const;
225 protected:
226  QScopedPointer<qSlicerAbstractModuleFactoryManagerPrivate> d_ptr;
227 
228  void registerModules(const QString& directoryPath);
229 
231  qSlicerAbstractCoreModule* instantiateModule(const QString& name);
232 
234  virtual void uninstantiateModule(const QString& moduleName);
235 
236 private:
237  Q_DECLARE_PRIVATE(qSlicerAbstractModuleFactoryManager);
238  Q_DISABLE_COPY(qSlicerAbstractModuleFactoryManager);
239 };
240 
241 //-----------------------------------------------------------------------------
243 {
244  this->setSearchPaths(this->searchPaths() << paths);
245 }
246 
247 //-----------------------------------------------------------------------------
249 {
250  this->setSearchPaths(this->searchPaths() << path);
251 }
252 
253 //-----------------------------------------------------------------------------
255 {
256  foreach(const QString& path, paths)
257  {
258  this->removeSearchPath(path);
259  }
260 }
261 
262 //-----------------------------------------------------------------------------
264 {
265  QStringList newSearchPaths = this->searchPaths();
266  newSearchPaths.removeAll(path);
267  this->setSearchPaths(newSearchPaths);
268 }
269 
270 //-----------------------------------------------------------------------------
272 {
273  QStringList modules = this->modulesToIgnore();
274  if (modules.contains(moduleName))
275  {
276  return;
277  }
278  modules << moduleName;
279  this->setModulesToIgnore(modules);
280 }
281 
282 //-----------------------------------------------------------------------------
284 {
285  QStringList modules = this->modulesToIgnore();
286  modules.removeAll(moduleName);
287  this->setModulesToIgnore(modules);
288 }
289 
290 #endif
void removeSearchPath(const QString &path)
Utility function that removes a path from the current searchPaths list.
void setModulesToIgnore(const QStringList &modulesNames)
QStringList modulesToIgnore() const
ctkAbstractFactory< qSlicerAbstractCoreModule > qSlicerModuleFactory
void setSearchPaths(const QStringList &searchPaths)
ctkAbstractFileBasedFactory< qSlicerAbstractCoreModule > qSlicerFileBasedModuleFactory
qSlicerAbstractCoreModule is the base class of any module in Slicer.
QScopedPointer< qSlicerAbstractModuleFactoryManagerPrivate > d_ptr
void addSearchPath(const QString &path)
Utility function that adds a path to the current searchPaths list.