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_WidgetIntValue.h>
19 #include <ModuleBase_WidgetBoolValue.h>
20 #include <ModuleBase_WidgetFileSelector.h>
21 #include <ModuleBase_WidgetChoice.h>
22 #include <ModuleBase_IWorkshop.h>
23 #include <ModuleBase_IModule.h>
24 #include <ModuleBase_Tools.h>
25 #include <ModuleBase_WidgetLineEdit.h>
26 #include <ModuleBase_WidgetMultiSelector.h>
27 #include <ModuleBase_WidgetLabel.h>
28 #include <ModuleBase_WidgetErrorLabel.h>
29 #include <ModuleBase_WidgetToolbox.h>
30 #include <ModuleBase_PageBase.h>
31 #include <ModuleBase_PageGroupBox.h>
32 #include <ModuleBase_PageWidget.h>
33 #include <ModuleBase_WidgetExprEditor.h>
35 #include <ModelAPI_Validator.h>
36 #include <ModelAPI_Session.h>
38 #include <Config_Keywords.h>
39 #include <Config_WidgetAPI.h>
42 #include <QHBoxLayout>
43 #include <QGridLayout>
45 #include <QMetaProperty>
58 ModuleBase_WidgetFactory::ModuleBase_WidgetFactory(const std::string& theXmlRepresentation,
59 ModuleBase_IWorkshop* theWorkshop)
60 : myWorkshop(theWorkshop)
62 myWidgetApi = new Config_WidgetAPI(theXmlRepresentation);
65 ModuleBase_WidgetFactory::~ModuleBase_WidgetFactory()
70 void ModuleBase_WidgetFactory::createWidget(ModuleBase_PageBase* thePage)
72 myParentId = myWidgetApi->widgetId();
73 if (!myWidgetApi->toChildWidget())
76 do { //Iterate over each node
77 std::string aWdgType = myWidgetApi->widgetType();
78 // Create PageGroup TODO: extract
79 if (myWidgetApi->isGroupBoxWidget()) {
80 //if current widget is groupbox (container) process it's children recursively
81 QString aGroupName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME));
82 ModuleBase_PageGroupBox* aPage = new ModuleBase_PageGroupBox(thePage->pageWidget());
83 aPage->setTitle(aGroupName);
85 thePage->addPageWidget(aPage);
87 // Create a ModelWidget
88 ModuleBase_ModelWidget* aWidget = createWidgetByType(aWdgType, thePage->pageWidget());
90 if (!myWidgetApi->getBooleanAttribute(ATTR_INTERNAL, false)) {
91 thePage->addModelWidget(aWidget);
93 aWidget->setVisible(false);
96 // Create PagedContainer TODO: extract
97 if (myWidgetApi->isPagedWidget()) {
98 //If current widget is toolbox or switch-casebox then fetch all
99 //it's pages recursively and setup into the widget.
100 myWidgetApi->toChildWidget();
102 QString aPageName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME));
103 QString aCaseId = qs(myWidgetApi->getProperty(_ID));
104 ModuleBase_PageBase* aPage = new ModuleBase_PageWidget(aWidget);
106 if (aWdgType == WDG_SWITCH || aWdgType == WDG_TOOLBOX) {
107 ModuleBase_PagedContainer* aContainer = qobject_cast<ModuleBase_PagedContainer*>(aWidget);
109 QString anIconPath = qs( myWidgetApi->getProperty( CONTAINER_PAGE_ICON ) );
110 QPixmap anIcon( anIconPath );
111 aContainer->addPage( aPage, aPageName, aCaseId, anIcon );
113 } while (myWidgetApi->toNextWidget());
116 } while (myWidgetApi->toNextWidget());
118 thePage->alignToTop();
121 ModuleBase_ModelWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType,
124 ModuleBase_ModelWidget* result = NULL;
126 if (theType == WDG_INFO) {
127 result = new ModuleBase_WidgetLabel(theParent, myWidgetApi, myParentId);
128 } else if (theType == WDG_ERRORINFO) {
129 result = new ModuleBase_WidgetErrorLabel(theParent, myWidgetApi, myParentId);
130 } else if (theType == WDG_DOUBLEVALUE) {
131 result = new ModuleBase_WidgetDoubleValue(theParent, myWidgetApi, myParentId);
132 } else if (theType == WDG_INTEGERVALUE) {
133 result = new ModuleBase_WidgetIntValue(theParent, myWidgetApi, myParentId);
134 } else if (theType == WDG_SHAPE_SELECTOR) {
135 result = new ModuleBase_WidgetShapeSelector(theParent, myWorkshop, myWidgetApi, myParentId);
136 } else if (theType == WDG_BOOLVALUE) {
137 result = new ModuleBase_WidgetBoolValue(theParent, myWidgetApi, myParentId);
138 //} else if (theType == WDG_DOUBLEVALUE_EDITOR) {
139 // result = new ModuleBase_WidgetEditor(theParent, myWidgetApi, myParentId);
140 } else if (theType == WDG_FILE_SELECTOR) {
141 result = new ModuleBase_WidgetFileSelector(theParent, myWidgetApi, myParentId);
142 } else if (theType == WDG_CHOICE) {
143 result = new ModuleBase_WidgetChoice(theParent, myWidgetApi, myParentId);
144 } else if (theType == WDG_STRINGVALUE) {
145 std::string aPlaceHolder = myWidgetApi->getProperty( WDG_PLACE_HOLDER );
146 result = new ModuleBase_WidgetLineEdit( theParent, myWidgetApi, myParentId, aPlaceHolder );
147 } else if (theType == WDG_EXPR_EDITOR) {
148 std::string aPlaceHolder = myWidgetApi->getProperty( WDG_PLACE_HOLDER );
149 result = new ModuleBase_WidgetExprEditor( theParent, myWidgetApi, myParentId, aPlaceHolder );
150 } else if (theType == WDG_MULTISELECTOR) {
151 result = new ModuleBase_WidgetMultiSelector(theParent, myWorkshop, myWidgetApi, myParentId);
152 } else if (theType == WDG_TOOLBOX) {
153 result = new ModuleBase_WidgetToolbox(theParent, myWidgetApi, myParentId);
154 } else if (theType == WDG_SWITCH) {
155 result = new ModuleBase_WidgetSwitch(theParent, myWidgetApi, myParentId);
156 } else if (theType == WDG_TOOLBOX_BOX || theType == WDG_SWITCH_CASE) {
157 // Do nothing for "box" and "case"
160 result = myWorkshop->module()->createWidgetByType(theType, theParent, myWidgetApi, myParentId);
163 qDebug("ModuleBase_WidgetFactory::fillWidget: find bad widget type %s", theType.c_str());
168 myModelWidgets.append(result);
173 QString ModuleBase_WidgetFactory::qs(const std::string& theStdString)
175 return QString::fromStdString(theStdString);