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>
23 XGUI_WidgetFactory::XGUI_WidgetFactory(const std::string& theXml)
25 myWidgetApi = new Config_WidgetAPI(theXml);
28 XGUI_WidgetFactory::~XGUI_WidgetFactory()
32 void XGUI_WidgetFactory::fillWidget(QWidget* theParent)
35 if (theParent->layout()) {
36 theParent->layout()->deleteLater();
39 QVBoxLayout* aWidgetLay = new QVBoxLayout(theParent);
40 aWidgetLay->setContentsMargins(0, 0, 0, 0);
42 std::string aWdgType = myWidgetApi->widgetType();
43 QWidget* aWidget = NULL;
44 if (aWdgType == "value") {
45 aWidget = valueWidget();
48 qDebug() << "XGUI_WidgetFactory::fillWidget: find bad widget type";
52 aWidgetLay->addWidget(aWidget);
54 } while(myWidgetApi->nextWidget());
55 theParent->setLayout(aWidgetLay);
58 QWidget* XGUI_WidgetFactory::valueWidget()
60 QWidget* result = new QWidget();
61 QHBoxLayout* aControlLay = new QHBoxLayout(result);
62 aControlLay->setContentsMargins(0, 0, 0, 0);
63 QString aLabelText = qs(myWidgetApi->widgetLabel());
64 QString aLabelIcon = qs(myWidgetApi->widgetIcon());
65 QLabel* aLabel = new QLabel(aLabelText);
66 aLabel->setPixmap(QPixmap(aLabelIcon));
68 aControlLay->addWidget(aLabel);
69 QDoubleSpinBox* aBox = new QDoubleSpinBox(result);
71 double aMinVal = qs(myWidgetApi->getProperty("min")).toDouble(&isOk);
73 aBox->setMinimum(aMinVal);
75 double aMaxVal = qs(myWidgetApi->getProperty("max")).toDouble(&isOk);
77 aBox->setMaximum(aMaxVal);
79 double aStepVal = qs(myWidgetApi->getProperty("step")).toDouble(&isOk);
81 aBox->setSingleStep(aStepVal);
83 double aDefVal = qs(myWidgetApi->getProperty("default")).toDouble(&isOk);
85 aBox->setValue(aDefVal);
87 QString aTTip = qs(myWidgetApi->widgetTooltip());
88 aBox->setToolTip(aTTip);
89 aControlLay->addWidget(aBox);
90 aControlLay->setStretch(1, 1);
92 result->setLayout(aControlLay);
96 QString XGUI_WidgetFactory::qs(const std::string& theStdString) const
98 return QString::fromStdString(theStdString);