File indexing completed on 2024-04-28 03:51:22
0001 /*. 0002 SPDX-FileCopyrightText: 2007 Vladimir Kuznetsov <ks.vladimir@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef STEP_WORLD_FACTORY_H 0008 #define STEP_WORLD_FACTORY_H 0009 0010 #include <stepcore/factory.h> 0011 0012 class QIcon; 0013 class WorldModel; 0014 class WorldScene; 0015 class StepGraphicsItem; 0016 class ItemCreator; 0017 class ItemMenuHandler; 0018 0019 namespace StepCore { 0020 class Item; 0021 } 0022 0023 struct ExtMetaObject 0024 { 0025 ItemCreator* (*newItemCreator)(const QString& className, 0026 WorldModel* worldModel, WorldScene* worldScene); 0027 StepGraphicsItem* (*newGraphicsItem)(StepCore::Item*, WorldModel*); 0028 ItemMenuHandler* (*newItemMenuHandler)(StepCore::Object*, WorldModel*, QObject*); 0029 0030 bool hasIcon; 0031 QIcon* icon; 0032 }; 0033 0034 0035 /** \brief Factory for creation StepCore::Items and 0036 * querying various static properties. */ 0037 class WorldFactory: public StepCore::Factory 0038 { 0039 public: 0040 WorldFactory(); 0041 ~WorldFactory(); 0042 0043 /** Get ExtMetaObject for given StepCore::MetaObject */ 0044 const ExtMetaObject* extMetaObject(const StepCore::MetaObject* mObject) const 0045 { return _extMetaObjects.value(mObject, NULL); } 0046 /** Get ExtMetaObject by class name */ 0047 const ExtMetaObject* extMetaObject(const QString& name) const 0048 { return extMetaObject(metaObject(name)); } 0049 0050 /** Create ItemCreator for given class */ 0051 ItemCreator* newItemCreator(const QString& className, 0052 WorldModel* worldModel, WorldScene* worldScene) const; 0053 0054 /** Create StepGraphicsItem for given item */ 0055 StepGraphicsItem *newGraphicsItem(StepCore::Item* item, WorldModel* worldModel) const; 0056 0057 /** Create ItemMenuHandler for given object */ 0058 ItemMenuHandler* newItemMenuHandler(StepCore::Object* object, 0059 WorldModel* worldModel, QObject* parent) const; 0060 0061 /** Returns true if the object has associated icon */ 0062 bool hasObjectIcon(const StepCore::MetaObject* mObject) const; 0063 /** Get associated icon for given object */ 0064 const QIcon& objectIcon(const StepCore::MetaObject* mObject) const; 0065 0066 /** Get class names of the objects on ItemPalette */ 0067 QList<QString> paletteMetaObjects() const { return _paletteMetaObjects; } 0068 /** Get class names of the objects in the order of creation */ 0069 QList<QString> orderedMetaObjects() const { return _orderedMetaObjects; } 0070 0071 private: 0072 void loadIcon(const StepCore::MetaObject* metaObject, ExtMetaObject* extMetaObject); 0073 0074 QHash<const void*, const ExtMetaObject*> _extMetaObjects; 0075 QList<QString> _paletteMetaObjects; 0076 QList<QString> _orderedMetaObjects; 0077 0078 QIcon* _nullIcon; 0079 }; 0080 0081 #endif 0082