#include <memory>
class ModuleBase_ModelWidget;
+class ModuleBase_PageBase;
class QWidget;
/// Virtual destructor
~ModuleBase_IWidgetCreator();
- /// Returns a list of possible widget types, which this creator can process
- /// \param theTypes
+ /// Returns a container of possible page types, which this creator can process
+ /// \returns types
+ virtual const std::set<std::string>& pageTypes() = 0;
+
+ /// Returns a container of possible widget types, which this creator can process
+ /// \returns types
virtual const std::set<std::string>& widgetTypes() = 0;
- /// Create widget by its type
+ /// Create page by its type
+ /// \param theType a type
+ /// \param theParent a parent widget
+ virtual ModuleBase_PageBase* createPageByType(const std::string& theType,
+ QWidget* theParent) = 0;
+
+ /// Create widget by its type
/// \param theType a type
/// \param theParent a parent widget
virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
std::set<std::string>::const_iterator anIt = aTypes.begin(), aLast = aTypes.end();
for (; anIt != aLast; anIt++) {
std::string aKey = *anIt;
- if (!myModelWidgets.contains(aKey))
- myModelWidgets[aKey] = theCreator;
+ if (!myCreators.contains(aKey))
+ myCreators[aKey] = theCreator;
else {
- Events_Error::send("The" + aKey + " widget XML definition has been already\
- used by another widget creator");
+ Events_Error::send("The" + aKey + " widget XML definition has been already \
+used by another widget creator");
}
}
+
+ const std::set<std::string>& aPTypes = theCreator->pageTypes();
+ for (anIt = aPTypes.begin(), aLast = aPTypes.end(); anIt != aLast; anIt++) {
+ std::string aKey = *anIt;
+ if (!myPageToCreator.contains(aKey))
+ myPageToCreator[aKey] = theCreator;
+ else {
+ Events_Error::send("The" + aKey + " page XML definition has been already \
+used by another widget creator");
+ }
+ }
+}
+
+bool ModuleBase_WidgetCreatorFactory::hasPageWidget(const std::string& theType)
+{
+ return myPageToCreator.contains(theType);
}
+ModuleBase_PageBase* ModuleBase_WidgetCreatorFactory::createPageByType(
+ const std::string& theType, QWidget* theParent)
+{
+ ModuleBase_PageBase* aPage = 0;
+
+ if (myPageToCreator.contains(theType)) {
+ WidgetCreatorPtr aCreator = myPageToCreator[theType];
+ aPage = aCreator->createPageByType(theType, theParent);
+ }
+
+ return aPage;
+}
+
+
ModuleBase_ModelWidget* ModuleBase_WidgetCreatorFactory::createWidgetByType(
const std::string& theType, QWidget* theParent)
{
ModuleBase_ModelWidget* aWidget = 0;
- if (myModelWidgets.contains(theType)) {
- WidgetCreatorPtr aCreator = myModelWidgets[theType];
+ if (myCreators.contains(theType)) {
+ WidgetCreatorPtr aCreator = myCreators[theType];
aWidget = aCreator->createWidgetByType(theType, theParent);
}
#include <ModuleBase_IWidgetCreator.h>
class ModuleBase_ModelWidget;
+class ModuleBase_PageBase;
class QWidget;
/// \param theCreator a new widget creator
void registerCreator(const WidgetCreatorPtr& theCreator);
+ /// Returns true if there is a creator, which can make a page by the type
+ /// \param theType a type
+ bool hasPageWidget(const std::string& theType);
+
+ /// Create page by its type
+ /// \param theType a type
+ /// \param theParent a parent widget
+ ModuleBase_PageBase* createPageByType(const std::string& theType,
+ QWidget* theParent = NULL);
+
/// Create widget by its type
/// \param theType a type
/// \param theParent a parent widget
/// Constructor is hidden
ModuleBase_WidgetCreatorFactory();
- /// List of created model widgets
- QMap<std::string, WidgetCreatorPtr> myModelWidgets;
+ /// Map of widget type in XML to creator
+ QMap<std::string, WidgetCreatorPtr> myCreators;
+
+ /// Map of widget page in XML to creator
+ QMap<std::string, WidgetCreatorPtr> myPageToCreator;
};
typedef std::shared_ptr<ModuleBase_WidgetCreatorFactory> WidgetCreatorFactoryPtr;
do { //Iterate over each node
std::string aWdgType = myWidgetApi->widgetType();
// Create PageGroup TODO: extract
- if (myWidgetApi->isGroupBoxWidget()) {
+ if (myWidgetApi->isGroupBoxWidget() ||
+ ModuleBase_WidgetCreatorFactory::get()->hasPageWidget(aWdgType)) {
+
//if current widget is groupbox (container) process it's children recursively
- QString aGroupName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME));
- ModuleBase_PageGroupBox* aPage = new ModuleBase_PageGroupBox(thePage->pageWidget());
- aPage->setTitle(aGroupName);
+ ModuleBase_PageBase* aPage = createPageByType(aWdgType, thePage->pageWidget());
+
createWidget(aPage);
thePage->addPageWidget(aPage);
} else {
thePage->alignToTop();
}
+ModuleBase_PageBase* ModuleBase_WidgetFactory::createPageByType(const std::string& theType,
+ QWidget* theParent)
+{
+ ModuleBase_PageBase* aResult = NULL;
+
+ if (theType == WDG_GROUP) {
+ QString aGroupName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME));
+ ModuleBase_PageGroupBox* aPage = new ModuleBase_PageGroupBox(theParent);
+ aPage->setTitle(aGroupName);
+ aResult = aPage;
+ }
+
+ if (!aResult)
+ aResult = ModuleBase_WidgetCreatorFactory::get()->createPageByType(theType, theParent);
+
+ return aResult;
+}
+
ModuleBase_ModelWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType,
QWidget* theParent)
{
protected:
/// check if ModuleBase_Widget has expandable widgets in getControls
bool hasExpandingControls(QWidget* theParent);
- /// Create widget by its type
- /// \param theType a type
- /// \param theParent a parent widget
+
+ /// Create page by its type
+ /// \param theType a type
+ /// \param theParent a parent widget
+ ModuleBase_PageBase* createPageByType(const std::string& theType,
+ QWidget* theParent);
+
+ /// Create widget by its type
+ /// \param theType a type
+ /// \param theParent a parent widget
ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
QWidget* theParent = NULL);
SketchShapePlugin_WidgetCreator::SketchShapePlugin_WidgetCreator()
: ModuleBase_IWidgetCreator()
{
- myTypes.insert("sketchshape_groupbox");
+ myPages.insert("sketchshape_groupbox");
+}
+
+const std::set<std::string>& SketchShapePlugin_WidgetCreator::pageTypes()
+{
+ return myPages;
}
const std::set<std::string>& SketchShapePlugin_WidgetCreator::widgetTypes()
return myTypes;
}
+ModuleBase_PageBase* SketchShapePlugin_WidgetCreator::createPageByType(
+ const std::string& theType, QWidget* theParent)
+{
+ ModuleBase_PageBase* aPage = 0;
+ if (myPages.find(theType) == myPages.end())
+ return aPage;
+
+ if (theType == "sketchshape_groupbox") {
+ aPage = new SketchShapePlugin_PageGroupBox(theParent);
+ }
+
+ return aPage;
+}
+
ModuleBase_ModelWidget* SketchShapePlugin_WidgetCreator::createWidgetByType(
const std::string& theType, QWidget* theParent)
{
/// Virtual destructor
~SketchShapePlugin_WidgetCreator() {}
+ /// Returns a container of possible page types, which this creator can process
+ /// \returns types
+ virtual const std::set<std::string>& pageTypes();
+
/// Returns a list of possible widget types, which this creator can process
- /// \return theTypes
+ /// \returns types
virtual const std::set<std::string>& widgetTypes();
+ /// Create page by its type
+ /// \param theType a type
+ /// \param theParent a parent widget
+ virtual ModuleBase_PageBase* createPageByType(const std::string& theType,
+ QWidget* theParent);
+
/// Create widget by its type
/// \param theType a type
/// \param theParent a parent widget
QWidget* theParent = NULL);
private:
+ std::set<std::string> myPages; /// types of pages
std::set<std::string> myTypes; /// types of widgets
};