2 * ModuleBase_WidgetToolbox.cpp
4 * Created on: Feb 27, 2015
8 #include <ModuleBase_WidgetToolbox.h>
9 #include <ModuleBase_PageBase.h>
10 #include <ModuleBase_Tools.h>
12 #include <ModelAPI_AttributeString.h>
15 #include <QVBoxLayout>
17 ModuleBase_WidgetToolbox::ModuleBase_WidgetToolbox(QWidget* theParent, const Config_WidgetAPI* theData,
18 const std::string& theParentId)
19 : ModuleBase_ModelWidget(theParent, theData, theParentId)
21 QVBoxLayout* aMainLayout = new QVBoxLayout(this);
22 ModuleBase_Tools::zeroMargins(aMainLayout);
23 myToolBox = new QToolBox(this);
24 // Dark-grey rounded tabs with button-like border #and bold font
25 QString css = "QToolBox::tab{background-color:#c8c8c8;"
29 "border-color:#fff #505050 #505050 #fff;}";
30 myToolBox->setStyleSheet(css);
31 // default vertical size policy is preferred
32 QSizePolicy aSizePolicy = myToolBox->sizePolicy();
33 aSizePolicy.setVerticalPolicy(QSizePolicy::MinimumExpanding);
34 myToolBox->setSizePolicy(aSizePolicy);
35 aMainLayout->addWidget(myToolBox);
37 connect(myToolBox, SIGNAL(currentChanged(int)), this, SLOT(onPageChanged()));
40 ModuleBase_WidgetToolbox::~ModuleBase_WidgetToolbox()
44 int ModuleBase_WidgetToolbox::addPage(QWidget* theWidget,
45 const QString& theName, const QString& theCaseId)
47 myCaseIds << theCaseId;
48 return myToolBox->addItem(theWidget, theName);
51 bool ModuleBase_WidgetToolbox::restoreValue()
53 // A rare case when plugin was not loaded.
56 DataPtr aData = myFeature->data();
57 AttributeStringPtr aStringAttr = aData->string(attributeID());
58 QString aCaseId = QString::fromStdString(aStringAttr->value());
59 int idx = myCaseIds.indexOf(aCaseId);
62 bool isSignalsBlocked = myToolBox->blockSignals(true);
63 myToolBox->setCurrentIndex(idx);
64 myToolBox->blockSignals(isSignalsBlocked);
68 QList<QWidget*> ModuleBase_WidgetToolbox::getControls() const
70 QList<QWidget*> aList;
75 bool ModuleBase_WidgetToolbox::focusTo()
80 bool ModuleBase_WidgetToolbox::storeValueCustom() const
82 // A rare case when plugin was not loaded.
85 DataPtr aData = myFeature->data();
86 AttributeStringPtr aStringAttr = aData->string(attributeID());
87 QString aWidgetValue = myCaseIds.at(myToolBox->currentIndex());
88 aStringAttr->setValue(aWidgetValue.toStdString());
92 void ModuleBase_WidgetToolbox::onPageChanged()