From: sbh Date: Fri, 27 Feb 2015 13:17:42 +0000 (+0300) Subject: Implementatation of Toolbox as ModelWidget X-Git-Tag: V_1.1.0~155^2~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4cad27a7349b67fff83e26883dd636e15a95922c;p=modules%2Fshaper.git Implementatation of Toolbox as ModelWidget --- diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp index 4f3fae9db..258ed85e9 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -23,10 +24,14 @@ ConstructionPlugin_Axis::ConstructionPlugin_Axis() void ConstructionPlugin_Axis::initAttributes() { + data()->addAttribute(ConstructionPlugin_Axis::METHOD(), + ModelAPI_AttributeString::type()); data()->addAttribute(ConstructionPlugin_Axis::POINT_FIRST(), ModelAPI_AttributeSelection::type()); data()->addAttribute(ConstructionPlugin_Axis::POINT_SECOND(), ModelAPI_AttributeSelection::type()); + data()->addAttribute(ConstructionPlugin_Axis::CYLINDRICAL_FACE(), + ModelAPI_AttributeSelection::type()); } void ConstructionPlugin_Axis::execute() diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.h b/src/ConstructionPlugin/ConstructionPlugin_Axis.h index ef021ba50..473d3e352 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Axis.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Axis.h @@ -31,6 +31,13 @@ class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomP static const std::string CONSTRUCTION_AXIS_KIND("Axis"); return CONSTRUCTION_AXIS_KIND; } + + /// attribute name for first point + inline static const std::string& METHOD() + { + static const std::string METHOD_ATTR("creationMethod"); + return METHOD_ATTR; + } /// attribute name for first point inline static const std::string& POINT_FIRST() { @@ -43,6 +50,12 @@ class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomP static const std::string POINT_ATTR_SECOND("secondPoint"); return POINT_ATTR_SECOND; } + /// attribute name for second point + inline static const std::string& CYLINDRICAL_FACE() + { + static const std::string CYLINDRICAL_FACE_ATTR("cylindricalFace"); + return CYLINDRICAL_FACE_ATTR; + } /// default color for an axis inline static const std::string& DEFAULT_COLOR() { diff --git a/src/ConstructionPlugin/axis_widget.xml b/src/ConstructionPlugin/axis_widget.xml index 004274569..5b5540166 100644 --- a/src/ConstructionPlugin/axis_widget.xml +++ b/src/ConstructionPlugin/axis_widget.xml @@ -1,7 +1,7 @@ - + #include #include +#include #include #include @@ -96,6 +97,7 @@ void ModuleBase_WidgetFactory::createWidget(QWidget* theParent) myWidgetApi->toChildWidget(); do { QString aPageName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME)); + QString aCaseId = qs(myWidgetApi->getProperty(_ID)); QWidget* aPage = new QWidget(aWidget); createWidget(aPage); ModuleBase_Tools::adjustMargins(aPage); @@ -103,10 +105,9 @@ void ModuleBase_WidgetFactory::createWidget(QWidget* theParent) ModuleBase_WidgetSwitch* aSwitch = qobject_cast(aWidget); aSwitch->addPage(aPage, aPageName); } else if (aWdgType == WDG_TOOLBOX) { - QToolBox* aToolbox = qobject_cast(aWidget); - aToolbox->addItem(aPage, aPageName); + ModuleBase_WidgetToolbox* aToolbox = qobject_cast(aWidget); + aToolbox->addPage(aPage, aPageName, aCaseId); } - } while (myWidgetApi->toNextWidget()); } if (aWidget && !isStretchLayout) { @@ -182,34 +183,25 @@ QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType QWidget* ModuleBase_WidgetFactory::createContainer(const std::string& theType, QWidget* theParent) { - QWidget* result = NULL; + QWidget* aResult = NULL; if (theType == WDG_GROUP || theType == WDG_CHECK_GROUP) { QGroupBox* aGroupBox = new QGroupBox(theParent); aGroupBox->setCheckable(theType == WDG_CHECK_GROUP); - result = aGroupBox; + aResult = aGroupBox; } else if (theType == WDG_TOOLBOX) { - result = new QToolBox(theParent); - // Dark-grey rounded tabs with button-like border #and bold font - QString css = "QToolBox::tab{background-color:#c8c8c8;" - "border-radius:5px;" - "border:1px inset;" - //"font-weight:700;" - "border-color:#fff #505050 #505050 #fff;}"; - result->setStyleSheet(css); - // default vertical size policy is preferred - QSizePolicy aSizePolicy = result->sizePolicy(); - aSizePolicy.setVerticalPolicy(QSizePolicy::MinimumExpanding); - result->setSizePolicy(aSizePolicy); + ModuleBase_WidgetToolbox* aWdg = new ModuleBase_WidgetToolbox(theParent, myWidgetApi, myParentId); + myModelWidgets.append(aWdg); + aResult = aWdg; } else if (theType == WDG_SWITCH) { - result = new ModuleBase_WidgetSwitch(theParent); + aResult = new ModuleBase_WidgetSwitch(theParent); } else if (theType == WDG_TOOLBOX_BOX || theType == WDG_SWITCH_CASE) { // Do nothing for "box" and "case" - result = NULL; + aResult = NULL; } #ifdef _DEBUG else {qDebug() << "ModuleBase_WidgetFactory::fillWidget: find bad container type";} #endif - return result; + return aResult; } QWidget* ModuleBase_WidgetFactory::labelControl(QWidget* theParent) diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.h b/src/ModuleBase/ModuleBase_WidgetFactory.h index 93b8443ae..71834e86d 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.h +++ b/src/ModuleBase/ModuleBase_WidgetFactory.h @@ -58,7 +58,7 @@ class MODULEBASE_EXPORT ModuleBase_WidgetFactory /// Create a widget of container type /// \param theType a type /// \param theParent a parent widget - QWidget* createContainer(const std::string& theType, QWidget* theParent = NULL); + QWidget* createContainer(const std::string& theType, QWidget* theParent); /// Create label widget /// \param theParent a parent widget diff --git a/src/ModuleBase/ModuleBase_WidgetToolbox.cpp b/src/ModuleBase/ModuleBase_WidgetToolbox.cpp new file mode 100644 index 000000000..220be9b70 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetToolbox.cpp @@ -0,0 +1,89 @@ +/* + * ModuleBase_WidgetToolbox.cpp + * + * Created on: Feb 27, 2015 + * Author: sbh + */ + +#include +#include + +#include + +#include +#include + +ModuleBase_WidgetToolbox::ModuleBase_WidgetToolbox(QWidget* theParent, const Config_WidgetAPI* theData, + const std::string& theParentId) +: ModuleBase_ModelWidget(theParent, theData, theParentId) +{ + QVBoxLayout* aMainLayout = new QVBoxLayout(this); + ModuleBase_Tools::zeroMargins(aMainLayout); + myToolBox = new QToolBox(this); + // Dark-grey rounded tabs with button-like border #and bold font + QString css = "QToolBox::tab{background-color:#c8c8c8;" + "border-radius:5px;" + "border:1px inset;" + //"font-weight:700;" + "border-color:#fff #505050 #505050 #fff;}"; + myToolBox->setStyleSheet(css); + // default vertical size policy is preferred + QSizePolicy aSizePolicy = myToolBox->sizePolicy(); + aSizePolicy.setVerticalPolicy(QSizePolicy::MinimumExpanding); + myToolBox->setSizePolicy(aSizePolicy); + aMainLayout->addWidget(myToolBox); + + connect(myToolBox, SIGNAL(currentChanged(int)), this, SLOT(onPageChanged())); +} + +ModuleBase_WidgetToolbox::~ModuleBase_WidgetToolbox() +{ +} + +int ModuleBase_WidgetToolbox::addPage(QWidget* theWidget, + const QString& theName, const QString& theCaseId) +{ + myCaseIds << theCaseId; + return myToolBox->addItem(theWidget, theName); +} + +bool ModuleBase_WidgetToolbox::restoreValue() +{ + // A rare case when plugin was not loaded. + if(!myFeature) + return false; + DataPtr aData = myFeature->data(); + AttributeStringPtr aStringAttr = aData->string(attributeID()); + QString aCaseId = QString::fromStdString(aStringAttr->value()); + int idx = myCaseIds.indexOf(aCaseId); + if (idx == -1) + return false; + bool isSignalsBlocked = myToolBox->blockSignals(true); + myToolBox->setCurrentIndex(idx); + myToolBox->blockSignals(isSignalsBlocked); + return true; +} + +QList ModuleBase_WidgetToolbox::getControls() const +{ + QList aList; + aList << myToolBox; + return aList; +} + +bool ModuleBase_WidgetToolbox::storeValueCustom() const +{ + // A rare case when plugin was not loaded. + if(!myFeature) + return false; + DataPtr aData = myFeature->data(); + AttributeStringPtr aStringAttr = aData->string(attributeID()); + QString aWidgetValue = myCaseIds.at(myToolBox->currentIndex()); + aStringAttr->setValue(aWidgetValue.toStdString()); + return true; +} + +void ModuleBase_WidgetToolbox::onPageChanged() +{ + storeValue(); +} diff --git a/src/ModuleBase/ModuleBase_WidgetToolbox.h b/src/ModuleBase/ModuleBase_WidgetToolbox.h new file mode 100644 index 000000000..c57c75e02 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetToolbox.h @@ -0,0 +1,39 @@ +/* + * ModuleBase_WidgetToolbox.h + * + * Created on: Feb 27, 2015 + * Author: sbh + */ + +#ifndef MODULEBASE_WIDGETTOOLBOX_H_ +#define MODULEBASE_WIDGETTOOLBOX_H_ + +#include + +#include + +class ModuleBase_WidgetToolbox : public ModuleBase_ModelWidget +{ + Q_OBJECT + public: + ModuleBase_WidgetToolbox(QWidget* theParent, const Config_WidgetAPI* theData, + const std::string& theParentId); + virtual ~ModuleBase_WidgetToolbox(); + + virtual bool restoreValue(); + virtual QList getControls() const; + + int addPage(QWidget* theWidget, const QString& theName, const QString& theCaseId); + + protected: + virtual bool storeValueCustom() const; + + protected slots: + void onPageChanged(); + + private: + QToolBox* myToolBox; + QStringList myCaseIds; +}; + +#endif /* MODULEBASE_WIDGETTOOLBOX_H_ */ diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 9f5a0083d..86107e2d9 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -653,7 +653,8 @@ void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation) QList aWidgets = aFactory.getModelWidgets(); foreach (ModuleBase_ModelWidget* aWidget, aWidgets) { bool isStoreValue = !theOperation->isEditOperation() && - !aWidget->getDefaultValue().empty() && !aWidget->isComputedDefault(); + !aWidget->getDefaultValue().empty() && + !aWidget->isComputedDefault(); aWidget->setFeature(theOperation->feature(), isStoreValue); aWidget->enableFocusProcessing(); }