Seamly2D
Code documentation
vpropertyfactorymanager.h
Go to the documentation of this file.
1 /************************************************************************
2  **
3  ** @file vpropertyfactorymanager.h
4  ** @author hedgeware <internal(at)hedgeware.net>
5  ** @date
6  **
7  ** @brief
8  ** @copyright
9  ** All rights reserved. This program and the accompanying materials
10  ** are made available under the terms of the GNU Lesser General Public License
11  ** (LGPL) version 2.1 which accompanies this distribution, and is available at
12  ** http://www.gnu.org/licenses/lgpl-2.1.html
13  **
14  ** This library is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  ** Lesser General Public License for more details.
18  **
19  *************************************************************************/
20 
21 #ifndef VPROPERTYFACTORYMANAGER_H
22 #define VPROPERTYFACTORYMANAGER_H
23 
24 #include <qcompilerdetection.h>
25 #include <QMetaObject>
26 #include <QObject>
27 #include <QString>
28 #include <QtGlobal>
29 
30 namespace VPE
31 {
32 
33 class VAbstractPropertyFactory;
34 class VProperty;
35 class VPropertyFactoryManagerPrivate;
36 
37 class VPropertyFactoryManager : public QObject
38 {
39  Q_OBJECT
40 public:
41  //! Constructor
42  explicit VPropertyFactoryManager(QObject* parent = nullptr);
43 
44  //! Destructor
45  virtual ~VPropertyFactoryManager() Q_DECL_OVERRIDE;
46 
47  //! Register a factory to the factory manager
48  //! Note that the manager takes ownership of the factory, so don't delete it.
49  //! You can unregister a factory using unregisterFactory()
50  void registerFactory(const QString& type, VAbstractPropertyFactory* factory);
51 
52  //! Removes a factory from the manager.
53  //! \param factory The factory to unregister
54  //! \param type The type from which to remove the factory. If this is empty, all the types the factory is registered
55  //! for are being removed
56  //! \param delete_if_unused Determines whether the factory should be deleted, if it not used anymore by this
57  //! manager. Default: true. Otherwise, if the factory is unused by this manager, ownership is being passed on.
58  void unregisterFactory(VAbstractPropertyFactory* factory, const QString& type = QString(),
59  bool delete_if_unused = true);
60 
61  //! Returns whether a factory is registered (and thus owned) by this factory manager
63 
64  //! Returns a pointer to a factory registered for a certain type
65  //! \param type The type to return the factory for
66  //! \return Returns NULL, if there is none registered for this type
67  VAbstractPropertyFactory* getFactory(const QString& type);
68 
69  //! Creates a new property of a certain type and assigns a name and description (otionally)
70  //! \param type The type of the property as string
71  //! \param name The name of the property
72  //! \param description The property's description. Optional.
73  //! \param default_value The properties initial value as string. Optional.
74  //! \return Returns the created property or NULL if it couldn't be be created
75  VProperty* createProperty(const QString& type, const QString& name, const QString& description = QString(),
76  const QString& default_value = QString());
77 
78  //! Returns the default manager.
79  //static VPropertyFactoryManager* getDefaultManager();
80 
81  //! Returns a list of all supported property types
82  QStringList getSupportedTypes();
83 
84 protected:
86 
87  //! The default manager
89 private:
90  Q_DISABLE_COPY(VPropertyFactoryManager)
91 };
92 
93 }
94 
95 #endif // VPROPERTYFACTORYMANAGER_H
static VPropertyFactoryManager * DefaultManager
The default manager.
VPropertyFactoryManagerPrivate * d_ptr
virtual ~VPropertyFactoryManager() Q_DECL_OVERRIDE
Destructor.
void unregisterFactory(VAbstractPropertyFactory *factory, const QString &type=QString(), bool delete_if_unused=true)
Removes a factory from the manager.
bool isRegistered(VAbstractPropertyFactory *factory)
Returns whether a factory is registered (and thus owned) by this factory manager.
void registerFactory(const QString &type, VAbstractPropertyFactory *factory)
Register a factory to the factory manager Note that the manager takes ownership of the factory,...
VPropertyFactoryManager(QObject *parent=nullptr)
Constructor.
QStringList getSupportedTypes()
Returns the default manager.
VProperty * createProperty(const QString &type, const QString &name, const QString &description=QString(), const QString &default_value=QString())
Creates a new property of a certain type and assigns a name and description (otionally)
VAbstractPropertyFactory * getFactory(const QString &type)
Returns a pointer to a factory registered for a certain type.