FougTools  0.7.0dev-046fb6a
Handy tools for C++, Qt and OpenCascade
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
plugins_loader.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** FougTools
3 ** Copyright Fougue (30 Mar. 2015)
4 ** contact@fougue.pro
5 **
6 ** This software is a computer program whose purpose is to provide utility
7 ** tools for the C++ language and the Qt toolkit.
8 **
9 ** This software is governed by the CeCILL-C license under French law and
10 ** abiding by the rules of distribution of free software. You can use,
11 ** modify and/ or redistribute the software under the terms of the CeCILL-C
12 ** license as circulated by CEA, CNRS and INRIA at the following URL
13 ** "http://www.cecill.info".
14 ****************************************************************************/
15 
16 #pragma once
17 
18 #include "core.h"
20 
21 #include <QtCore/QObject>
22 #include <QtCore/QString>
23 #include <QtCore/QVector>
24 
25 namespace qtcore {
26 
28 {
29 public:
31 
32  PluginsLoader();
33  ~PluginsLoader();
34 
35  bool autoDeletePlugins() const;
36  void setAutoDeletePlugins(bool on);
37 
38  void addPath(const QString& path);
39  void removePath(const QString& path);
40  QStringList paths() const;
41  void setPaths(const QStringList& paths);
42 
43  QStringList fileNameFilters() const;
44  void setFileNameFilters(const QStringList& nameFilters);
45 
46  void loadPlugins(InstanceFilter* filter, QStringList* errors = NULL);
47  void loadPlugins(
48  const QList<InstanceFilter*>& filters, QStringList* errors = NULL);
49  void discardPlugin(QObject* plugin);
50 
51  QString pluginFileName(const QObject* plugin) const;
52  QVector<QObject*> plugins() const;
53  template<typename INTERFACE> QVector<INTERFACE*> castPlugins() const;
54 
55 private:
56  class Private;
57  Private* const d;
58 };
59 
60 
61 
62 // --
63 // -- Implementation
64 // --
65 
74 template<typename INTERFACE>
75 QVector<INTERFACE *> PluginsLoader::castPlugins() const
76 {
77  QVector<INTERFACE *> typPlugins;
78  foreach (QObject* plugin, this->plugins()) {
79  INTERFACE* typPlugin = qobject_cast<INTERFACE*>(plugin);
80  if (typPlugin != NULL)
81  typPlugins.append(typPlugin);
82  }
83  return typPlugins;
84 }
85 
86 } // namespace qtcore
QVector< INTERFACE * > castPlugins() const
Definition: plugins_loader.h:75
Provides run-time loading of Qt-based plugins located into search paths.
Definition: plugins_loader.h:27
#define QTTOOLS_CORE_EXPORT
Definition: core.h:27
Definition: grid_numbering.cpp:19
QVector< QObject * > plugins() const
Returns all loaded plugin root components.
Definition: plugins_loader.cpp:228
PluginsLoader_InstanceFilter InstanceFilter
Definition: plugins_loader.h:30
Provides plugin filter to be used with PluginsLoader.
Definition: plugins_loader_instance_filter.h:23