2 * XGUI_WidgetFactory.cpp
4 * Created on: Apr 3, 2014
8 #include <XGUI_WidgetFactory.h>
9 #include <ModuleBase_Operation.h>
11 #include <Config_Keywords.h>
12 #include <Config_WidgetAPI.h>
15 #include <QHBoxLayout>
17 #include <QMetaProperty>
25 XGUI_WidgetFactory::XGUI_WidgetFactory(ModuleBase_Operation* theOperation)
26 : myOperation(theOperation)
28 QString aXml = myOperation->xmlRepresentation();
29 myWidgetApi = new Config_WidgetAPI(aXml.toStdString());
32 XGUI_WidgetFactory::~XGUI_WidgetFactory()
36 void XGUI_WidgetFactory::fillWidget(QWidget* theParent)
39 if (theParent->layout()) {
40 theParent->layout()->deleteLater();
43 QVBoxLayout* aWidgetLay = new QVBoxLayout(theParent);
44 aWidgetLay->setContentsMargins(0, 0, 0, 0);
46 std::string aWdgType = myWidgetApi->widgetType();
47 QWidget* aWidget = NULL;
48 if (aWdgType == NODE_DOUBLE_WDG) {
49 aWidget = doubleSpinBoxWidget();
52 qDebug() << "XGUI_WidgetFactory::fillWidget: find bad widget type";
56 aWidgetLay->addWidget(aWidget);
58 } while(myWidgetApi->nextWidget());
59 theParent->setLayout(aWidgetLay);
62 QWidget* XGUI_WidgetFactory::doubleSpinBoxWidget()
64 QWidget* result = new QWidget();
65 QHBoxLayout* aControlLay = new QHBoxLayout(result);
66 aControlLay->setContentsMargins(0, 0, 0, 0);
67 QString aLabelText = qs(myWidgetApi->widgetLabel());
68 QString aLabelIcon = qs(myWidgetApi->widgetIcon());
69 QLabel* aLabel = new QLabel(aLabelText);
70 aLabel->setPixmap(QPixmap(aLabelIcon));
72 aControlLay->addWidget(aLabel);
73 QDoubleSpinBox* aBox = new QDoubleSpinBox(result);
74 QString anObjName = QString::fromStdString(myWidgetApi->widgetId());
75 aBox->setObjectName(anObjName);
77 std::string aProp = myWidgetApi->getProperty(DOUBLE_WDG_MIN);
78 double aMinVal = qs(aProp).toDouble(&isOk);
80 aBox->setMinimum(aMinVal);
82 aProp = myWidgetApi->getProperty(DOUBLE_WDG_MAX);
83 double aMaxVal = qs(aProp).toDouble(&isOk);
85 aBox->setMaximum(aMaxVal);
87 aProp = myWidgetApi->getProperty(DOUBLE_WDG_STEP);
88 double aStepVal = qs(aProp).toDouble(&isOk);
90 aBox->setSingleStep(aStepVal);
92 aProp = myWidgetApi->getProperty(DOUBLE_WDG_DFLT);
93 double aDefVal = qs(aProp).toDouble(&isOk);
95 aBox->setValue(aDefVal);
97 QString aTTip = qs(myWidgetApi->widgetTooltip());
98 aBox->setToolTip(aTTip);
99 aControlLay->addWidget(aBox);
100 aControlLay->setStretch(1, 1);
101 result->setLayout(aControlLay);
102 connectWidget(aBox, NODE_DOUBLE_WDG);
106 bool XGUI_WidgetFactory::connectWidget(QWidget* theWidget, const QString& theType)
109 if (theType == NODE_DOUBLE_WDG) {
110 result = QObject::connect(theWidget, SIGNAL(valueChanged(double)),
111 myOperation, SLOT(storeReal(double)));
116 QString XGUI_WidgetFactory::qs(const std::string& theStdString) const
118 return QString::fromStdString(theStdString);