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>
34 #include <ModuleBase_WidgetCreatorFactory.h>
36 #include <ModelAPI_Validator.h>
37 #include <ModelAPI_Session.h>
39 #include <Config_Keywords.h>
40 #include <Config_WidgetAPI.h>
43 #include <QHBoxLayout>
44 #include <QGridLayout>
46 #include <QMetaProperty>
59 ModuleBase_WidgetFactory::ModuleBase_WidgetFactory(const std::string& theXmlRepresentation,
60 ModuleBase_IWorkshop* theWorkshop)
61 : myWorkshop(theWorkshop)
63 myWidgetApi = new Config_WidgetAPI(theXmlRepresentation);
66 ModuleBase_WidgetFactory::~ModuleBase_WidgetFactory()
71 void ModuleBase_WidgetFactory::createWidget(ModuleBase_PageBase* thePage)
73 myParentId = myWidgetApi->widgetId();
74 if (!myWidgetApi->toChildWidget())
77 do { //Iterate over each node
78 std::string aWdgType = myWidgetApi->widgetType();
79 // Create PageGroup TODO: extract
80 if (myWidgetApi->isGroupBoxWidget()) {
81 //if current widget is groupbox (container) process it's children recursively
82 QString aGroupName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME));
83 ModuleBase_PageGroupBox* aPage = new ModuleBase_PageGroupBox(thePage->pageWidget());
84 aPage->setTitle(aGroupName);
86 thePage->addPageWidget(aPage);
88 // Create a ModelWidget
89 ModuleBase_ModelWidget* aWidget = createWidgetByType(aWdgType, thePage->pageWidget());
91 if (!myWidgetApi->getBooleanAttribute(ATTR_INTERNAL, false)) {
92 thePage->addModelWidget(aWidget);
94 aWidget->setVisible(false);
97 // Create PagedContainer TODO: extract
98 if (myWidgetApi->isPagedWidget()) {
99 //If current widget is toolbox or switch-casebox then fetch all
100 //it's pages recursively and setup into the widget.
101 myWidgetApi->toChildWidget();
103 QString aPageName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME));
104 QString aCaseId = qs(myWidgetApi->getProperty(_ID));
105 ModuleBase_PageBase* aPage = new ModuleBase_PageWidget(aWidget);
107 if (aWdgType == WDG_SWITCH || aWdgType == WDG_TOOLBOX) {
108 ModuleBase_PagedContainer* aContainer = qobject_cast<ModuleBase_PagedContainer*>(aWidget);
110 QString anIconPath = qs( myWidgetApi->getProperty( CONTAINER_PAGE_ICON ) );
111 QPixmap anIcon( anIconPath );
112 aContainer->addPage( aPage, aPageName, aCaseId, anIcon );
114 } while (myWidgetApi->toNextWidget());
117 } while (myWidgetApi->toNextWidget());
119 thePage->alignToTop();
122 ModuleBase_ModelWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType,
125 ModuleBase_ModelWidget* result = NULL;
127 if (theType == WDG_INFO) {
128 result = new ModuleBase_WidgetLabel(theParent, myWidgetApi, myParentId);
129 } else if (theType == WDG_ERRORINFO) {
130 result = new ModuleBase_WidgetErrorLabel(theParent, myWidgetApi, myParentId);
131 } else if (theType == WDG_DOUBLEVALUE) {
132 result = new ModuleBase_WidgetDoubleValue(theParent, myWidgetApi, myParentId);
133 } else if (theType == WDG_INTEGERVALUE) {
134 result = new ModuleBase_WidgetIntValue(theParent, myWidgetApi, myParentId);
135 } else if (theType == WDG_SHAPE_SELECTOR) {
136 result = new ModuleBase_WidgetShapeSelector(theParent, myWorkshop, myWidgetApi, myParentId);
137 } else if (theType == WDG_BOOLVALUE) {
138 result = new ModuleBase_WidgetBoolValue(theParent, myWidgetApi, myParentId);
139 //} else if (theType == WDG_DOUBLEVALUE_EDITOR) {
140 // result = new ModuleBase_WidgetEditor(theParent, myWidgetApi, myParentId);
141 } else if (theType == WDG_FILE_SELECTOR) {
142 result = new ModuleBase_WidgetFileSelector(theParent, myWidgetApi, myParentId);
143 } else if (theType == WDG_CHOICE) {
144 result = new ModuleBase_WidgetChoice(theParent, myWidgetApi, myParentId);
145 } else if (theType == WDG_STRINGVALUE) {
146 std::string aPlaceHolder = myWidgetApi->getProperty( WDG_PLACE_HOLDER );
147 result = new ModuleBase_WidgetLineEdit( theParent, myWidgetApi, myParentId, aPlaceHolder );
148 } else if (theType == WDG_EXPR_EDITOR) {
149 std::string aPlaceHolder = myWidgetApi->getProperty( WDG_PLACE_HOLDER );
150 result = new ModuleBase_WidgetExprEditor( theParent, myWidgetApi, myParentId, aPlaceHolder );
151 } else if (theType == WDG_MULTISELECTOR) {
152 result = new ModuleBase_WidgetMultiSelector(theParent, myWorkshop, myWidgetApi, myParentId);
153 } else if (theType == WDG_TOOLBOX) {
154 result = new ModuleBase_WidgetToolbox(theParent, myWidgetApi, myParentId);
155 } else if (theType == WDG_SWITCH) {
156 result = new ModuleBase_WidgetSwitch(theParent, myWidgetApi, myParentId);
157 } else if (theType == WDG_TOOLBOX_BOX || theType == WDG_SWITCH_CASE ||
158 theType == NODE_VALIDATOR) {
159 // Do nothing for "box" and "case"
162 result = myWorkshop->module()->createWidgetByType(theType, theParent, myWidgetApi, myParentId);
164 result = ModuleBase_WidgetCreatorFactory::get()->createWidgetByType(theType, theParent);
167 qDebug("ModuleBase_WidgetFactory::fillWidget: find bad widget type %s", theType.c_str());
172 myModelWidgets.append(result);
176 QString ModuleBase_WidgetFactory::qs(const std::string& theStdString)
178 return QString::fromStdString(theStdString);