1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 * ModuleBase_WidgetFactory.cpp
6 * Created on: Apr 3, 2014
10 #include <ModuleBase_WidgetFactory.h>
12 #include <ModuleBase_Operation.h>
13 #include <ModuleBase_OperationDescription.h>
14 #include <ModuleBase_WidgetEditor.h>
15 #include <ModuleBase_WidgetSwitch.h>
16 #include <ModuleBase_WidgetShapeSelector.h>
17 #include <ModuleBase_WidgetDoubleValue.h>
18 #include <ModuleBase_WidgetBoolValue.h>
19 #include <ModuleBase_WidgetFileSelector.h>
20 #include <ModuleBase_WidgetChoice.h>
21 #include <ModuleBase_IWorkshop.h>
22 #include <ModuleBase_IModule.h>
23 #include <ModuleBase_Tools.h>
24 #include <ModuleBase_WidgetLineEdit.h>
25 #include <ModuleBase_WidgetMultiSelector.h>
26 #include <ModuleBase_WidgetLabel.h>
27 #include <ModuleBase_WidgetToolbox.h>
28 #include <ModuleBase_PageBase.h>
29 #include <ModuleBase_PageGroupBox.h>
30 #include <ModuleBase_PageWidget.h>
31 #include <ModuleBase_WidgetExprEditor.h>
33 #include <ModelAPI_Validator.h>
34 #include <ModelAPI_Session.h>
36 #include <Config_Keywords.h>
37 #include <Config_WidgetAPI.h>
40 #include <QHBoxLayout>
41 #include <QGridLayout>
43 #include <QMetaProperty>
56 ModuleBase_WidgetFactory::ModuleBase_WidgetFactory(const std::string& theXmlRepresentation,
57 ModuleBase_IWorkshop* theWorkshop)
58 : myWorkshop(theWorkshop)
60 myWidgetApi = new Config_WidgetAPI(theXmlRepresentation);
63 ModuleBase_WidgetFactory::~ModuleBase_WidgetFactory()
68 void ModuleBase_WidgetFactory::createWidget(ModuleBase_PageBase* thePage)
70 myParentId = myWidgetApi->widgetId();
71 if (!myWidgetApi->toChildWidget())
74 do { //Iterate over each node
75 std::string aWdgType = myWidgetApi->widgetType();
76 // Create PageGroup TODO: extract
77 if (myWidgetApi->isGroupBoxWidget()) {
78 //if current widget is groupbox (container) process it's children recursively
79 QString aGroupName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME));
80 ModuleBase_PageGroupBox* aPage = new ModuleBase_PageGroupBox(thePage->pageWidget());
81 aPage->setTitle(aGroupName);
83 thePage->addPageWidget(aPage);
85 // Create a ModelWidget
86 ModuleBase_ModelWidget* aWidget = createWidgetByType(aWdgType, thePage->pageWidget());
88 if (!myWidgetApi->getBooleanAttribute(ATTR_INTERNAL, false)) {
89 thePage->addModelWidget(aWidget);
91 aWidget->setVisible(false);
94 // Create PagedContainer TODO: extract
95 if (myWidgetApi->isPagedWidget()) {
96 //If current widget is toolbox or switch-casebox then fetch all
97 //it's pages recursively and setup into the widget.
98 myWidgetApi->toChildWidget();
100 QString aPageName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME));
101 QString aCaseId = qs(myWidgetApi->getProperty(_ID));
102 ModuleBase_PageBase* aPage = new ModuleBase_PageWidget(aWidget);
104 if (aWdgType == WDG_SWITCH || aWdgType == WDG_TOOLBOX) {
105 ModuleBase_PagedContainer* aContainer = qobject_cast<ModuleBase_PagedContainer*>(aWidget);
106 aContainer->addPage(aPage, aPageName, aCaseId);
108 } while (myWidgetApi->toNextWidget());
111 } while (myWidgetApi->toNextWidget());
113 thePage->alignToTop();
116 ModuleBase_ModelWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType,
119 ModuleBase_ModelWidget* result = NULL;
121 if (theType == WDG_INFO) {
122 result = new ModuleBase_WidgetLabel(theParent, myWidgetApi, myParentId);
123 } else if (theType == WDG_DOUBLEVALUE) {
124 result = new ModuleBase_WidgetDoubleValue(theParent, myWidgetApi, myParentId);
125 } else if (theType == WDG_SHAPE_SELECTOR) {
126 result = new ModuleBase_WidgetShapeSelector(theParent, myWorkshop, myWidgetApi, myParentId);
127 } else if (theType == WDG_BOOLVALUE) {
128 result = new ModuleBase_WidgetBoolValue(theParent, myWidgetApi, myParentId);
129 //} else if (theType == WDG_DOUBLEVALUE_EDITOR) {
130 // result = new ModuleBase_WidgetEditor(theParent, myWidgetApi, myParentId);
131 } else if (theType == WDG_FILE_SELECTOR) {
132 result = new ModuleBase_WidgetFileSelector(theParent, myWidgetApi, myParentId);
133 } else if (theType == WDG_CHOICE) {
134 result = new ModuleBase_WidgetChoice(theParent, myWidgetApi, myParentId);
135 } else if (theType == WDG_STRINGVALUE) {
136 result = new ModuleBase_WidgetLineEdit(theParent, myWidgetApi, myParentId);
137 } else if (theType == WDG_EXPR_EDITOR) {
138 result = new ModuleBase_WidgetExprEditor(theParent, myWidgetApi, myParentId);
139 } else if (theType == WDG_MULTISELECTOR) {
140 result = new ModuleBase_WidgetMultiSelector(theParent, myWorkshop, myWidgetApi, myParentId);
141 } else if (theType == WDG_TOOLBOX) {
142 result = new ModuleBase_WidgetToolbox(theParent, myWidgetApi, myParentId);
143 } else if (theType == WDG_SWITCH) {
144 result = new ModuleBase_WidgetSwitch(theParent, myWidgetApi, myParentId);
145 } else if (theType == WDG_TOOLBOX_BOX || theType == WDG_SWITCH_CASE) {
146 // Do nothing for "box" and "case"
149 result = myWorkshop->module()->createWidgetByType(theType, theParent, myWidgetApi, myParentId);
152 qDebug("ModuleBase_WidgetFactory::fillWidget: find bad widget type");
157 myModelWidgets.append(result);
162 QString ModuleBase_WidgetFactory::qs(const std::string& theStdString)
164 return QString::fromStdString(theStdString);