2 * ModuleBase_WidgetToolbox.cpp
4 * Created on: Feb 27, 2015
8 #include <ModuleBase_WidgetToolbox.h>
9 #include <ModuleBase_Tools.h>
11 #include <ModelAPI_AttributeString.h>
14 #include <QVBoxLayout>
16 ModuleBase_WidgetToolbox::ModuleBase_WidgetToolbox(QWidget* theParent, const Config_WidgetAPI* theData,
17 const std::string& theParentId)
18 : ModuleBase_ModelWidget(theParent, theData, theParentId)
20 QVBoxLayout* aMainLayout = new QVBoxLayout(this);
21 ModuleBase_Tools::zeroMargins(aMainLayout);
22 myToolBox = new QToolBox(this);
23 // Dark-grey rounded tabs with button-like border #and bold font
24 QString css = "QToolBox::tab{background-color:#c8c8c8;"
28 "border-color:#fff #505050 #505050 #fff;}";
29 myToolBox->setStyleSheet(css);
30 // default vertical size policy is preferred
31 QSizePolicy aSizePolicy = myToolBox->sizePolicy();
32 aSizePolicy.setVerticalPolicy(QSizePolicy::MinimumExpanding);
33 myToolBox->setSizePolicy(aSizePolicy);
34 aMainLayout->addWidget(myToolBox);
36 connect(myToolBox, SIGNAL(currentChanged(int)), this, SLOT(onPageChanged()));
39 ModuleBase_WidgetToolbox::~ModuleBase_WidgetToolbox()
43 int ModuleBase_WidgetToolbox::addPage(QWidget* theWidget,
44 const QString& theName, const QString& theCaseId)
46 myCaseIds << theCaseId;
47 return myToolBox->addItem(theWidget, theName);
50 bool ModuleBase_WidgetToolbox::restoreValue()
52 // A rare case when plugin was not loaded.
55 DataPtr aData = myFeature->data();
56 AttributeStringPtr aStringAttr = aData->string(attributeID());
57 QString aCaseId = QString::fromStdString(aStringAttr->value());
58 int idx = myCaseIds.indexOf(aCaseId);
61 bool isSignalsBlocked = myToolBox->blockSignals(true);
62 myToolBox->setCurrentIndex(idx);
63 myToolBox->blockSignals(isSignalsBlocked);
67 QList<QWidget*> ModuleBase_WidgetToolbox::getControls() const
69 QList<QWidget*> aList;
74 bool ModuleBase_WidgetToolbox::storeValueCustom() const
76 // A rare case when plugin was not loaded.
79 DataPtr aData = myFeature->data();
80 AttributeStringPtr aStringAttr = aData->string(attributeID());
81 QString aWidgetValue = myCaseIds.at(myToolBox->currentIndex());
82 aStringAttr->setValue(aWidgetValue.toStdString());
86 void ModuleBase_WidgetToolbox::onPageChanged()