2 * XGUI_WidgetFactory.cpp
4 * Created on: Apr 3, 2014
8 #include <XGUI_WidgetFactory.h>
10 #include <Config_WidgetAPI.h>
13 #include <QHBoxLayout>
15 #include <QMetaProperty>
22 XGUI_WidgetFactory::XGUI_WidgetFactory(const std::string& theXml)
24 myWidgetApi = new Config_WidgetAPI(theXml);
27 XGUI_WidgetFactory::~XGUI_WidgetFactory()
31 void XGUI_WidgetFactory::fillWidget(QWidget* theParent)
34 if (theParent->layout()) {
35 theParent->layout()->deleteLater();
38 QVBoxLayout* aWidgetLay = new QVBoxLayout(theParent);
40 std::string aWdgType = myWidgetApi->widgetType();
41 QWidget* aWidget = NULL;
42 if (aWdgType == "value") {
43 aWidget = valueWidget();
46 qDebug() << "XGUI_WidgetFactory::fillWidget: find bad widget type";
50 aWidgetLay->addWidget(aWidget);
52 } while(myWidgetApi->nextWidget());
53 aWidgetLay->addStretch(1);
54 theParent->setLayout(aWidgetLay);
57 QWidget* XGUI_WidgetFactory::valueWidget()
59 QWidget* result = new QWidget();
60 QHBoxLayout* aControlLay = new QHBoxLayout(result);
61 QString aLabelVal = qs(myWidgetApi->getProperty("label"));
62 QLabel* aLabel = new QLabel(aLabelVal);
63 aControlLay->addWidget(aLabel);
64 QDoubleSpinBox* aBox = new QDoubleSpinBox(result);
66 double aMinVal = qs(myWidgetApi->getProperty("min")).toDouble(&isOk);
68 aBox->setMinimum(aMinVal);
70 double aMaxVal = qs(myWidgetApi->getProperty("max")).toDouble(&isOk);
72 aBox->setMaximum(aMaxVal);
74 double aStepVal = qs(myWidgetApi->getProperty("step")).toDouble(&isOk);
76 aBox->setSingleStep(aStepVal);
78 double aDefVal = qs(myWidgetApi->getProperty("default")).toDouble(&isOk);
80 aBox->setValue(aDefVal);
82 aControlLay->addWidget(aBox);
83 aControlLay->addStretch();
85 result->setLayout(aControlLay);
89 QString XGUI_WidgetFactory::qs(const std::string& theStdString) const
91 return QString::fromStdString(theStdString);