From 6982f8b789c68de62b9bb67ae440591e3ca6cd12 Mon Sep 17 00:00:00 2001 From: vsv Date: Wed, 27 Jun 2018 13:03:25 +0300 Subject: [PATCH] Create a radio buttons widget according to point 2.3.2 in CEA specification --- src/Config/Config_FeatureReader.cpp | 7 +- src/Config/Config_Keywords.h | 2 + src/Config/Config_WidgetAPI.cpp | 2 +- src/ConstructionPlugin/point_widget.xml | 14 ++-- src/ModuleBase/CMakeLists.txt | 3 + src/ModuleBase/ModuleBase_WidgetFactory.cpp | 5 +- src/ModuleBase/ModuleBase_WidgetRadiobox.cpp | 85 ++++++++++++++++++++ src/ModuleBase/ModuleBase_WidgetRadiobox.h | 64 +++++++++++++++ 8 files changed, 171 insertions(+), 11 deletions(-) create mode 100644 src/ModuleBase/ModuleBase_WidgetRadiobox.cpp create mode 100644 src/ModuleBase/ModuleBase_WidgetRadiobox.h diff --git a/src/Config/Config_FeatureReader.cpp b/src/Config/Config_FeatureReader.cpp index c0af30ac4..ffb5bc372 100644 --- a/src/Config/Config_FeatureReader.cpp +++ b/src/Config/Config_FeatureReader.cpp @@ -103,6 +103,9 @@ void Config_FeatureReader::processNode(xmlNodePtr theNode) else if (!xmlStrcmp(aName, (const xmlChar *) WDG_TOOLBOX_BOX)) { aSwitchNode = hasParentRecursive(aCaseNode, WDG_TOOLBOX, NULL); } + else if (!xmlStrcmp(aName, (const xmlChar *)WDG_RADIOBOX_ITEM)) { + aSwitchNode = hasParentRecursive(aCaseNode, WDG_RADIOBOX, NULL); + } if (!xmlStrcmp(aName, (const xmlChar *) WDG_OPTIONALBOX)) { /// the box is optional, attribute is in case /// if the optional attribute value is not empty @@ -120,7 +123,8 @@ void Config_FeatureReader::processNode(xmlNodePtr theNode) } // container pages, like "case" or "box" } else if (isNode(theNode, WDG_OPTIONALBOX, WDG_SWITCH, WDG_SWITCH_CASE, - WDG_TOOLBOX, WDG_TOOLBOX_BOX, NULL)) { + WDG_TOOLBOX, WDG_TOOLBOX_BOX, + WDG_RADIOBOX, WDG_RADIOBOX_ITEM, NULL)) { storeAttribute(theNode, _ID); // save case:caseId (or box:boxId) } } @@ -144,6 +148,7 @@ bool Config_FeatureReader::processChildren(xmlNodePtr theNode) result = isNode(theNode, NODE_FEATURE, WDG_GROUP, WDG_OPTIONALBOX, WDG_TOOLBOX, WDG_TOOLBOX_BOX, + WDG_RADIOBOX, WDG_RADIOBOX_ITEM, WDG_SWITCH, WDG_SWITCH_CASE, NULL); } return result; diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index 2e8261fef..db4221167 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -57,6 +57,8 @@ const static char* WDG_ACTION = "action"; const static char* WDG_GROUP = "groupbox"; const static char* WDG_OPTIONALBOX = "optionalbox"; const static char* WDG_TOOLBOX = "toolbox"; +const static char* WDG_RADIOBOX = "radiobox"; +const static char* WDG_RADIOBOX_ITEM = "radio"; const static char* WDG_TOOLBOX_BOX = "box"; const static char* WDG_SWITCH = "switch"; const static char* WDG_SWITCH_CASE = "case"; diff --git a/src/Config/Config_WidgetAPI.cpp b/src/Config/Config_WidgetAPI.cpp index 7a9eac960..023ad2868 100644 --- a/src/Config/Config_WidgetAPI.cpp +++ b/src/Config/Config_WidgetAPI.cpp @@ -99,7 +99,7 @@ bool Config_WidgetAPI::isGroupBoxWidget() const bool Config_WidgetAPI::isPagedWidget() const { - return isNode(myCurrentNode, WDG_TOOLBOX, WDG_SWITCH, + return isNode(myCurrentNode, WDG_TOOLBOX, WDG_SWITCH, WDG_RADIOBOX, NULL); } diff --git a/src/ConstructionPlugin/point_widget.xml b/src/ConstructionPlugin/point_widget.xml index 47918c049..63fd48350 100644 --- a/src/ConstructionPlugin/point_widget.xml +++ b/src/ConstructionPlugin/point_widget.xml @@ -52,33 +52,31 @@ email : webmaster.salome@opencascade.com - - + - - + - - + + #include #include +#include #include #include #include @@ -133,7 +134,7 @@ void ModuleBase_WidgetFactory::createWidget(ModuleBase_PageBase* thePage, bool a QString aCaseId = qs(myWidgetApi->getProperty(_ID)); ModuleBase_PageBase* aPage = new ModuleBase_PageWidget(aWidget); createWidget(aPage); - if (aWdgType == WDG_SWITCH || aWdgType == WDG_TOOLBOX) { + if (aWdgType == WDG_SWITCH || aWdgType == WDG_TOOLBOX || aWdgType == WDG_RADIOBOX) { ModuleBase_PagedContainer* aContainer = qobject_cast(aWidget); @@ -330,6 +331,8 @@ ModuleBase_ModelWidget* ModuleBase_WidgetFactory::createWidgetByType(const std:: result = new ModuleBase_WidgetConcealedObjects(theParent, myWidgetApi); } else if (theType == WDG_TOOLBOX) { result = new ModuleBase_WidgetToolbox(theParent, myWidgetApi); + } else if (theType == WDG_RADIOBOX) { + result = new ModuleBase_WidgetRadiobox(theParent, myWidgetApi); } else if (theType == WDG_SWITCH) { result = new ModuleBase_WidgetSwitch(theParent, myWidgetApi); } else if (theType == WDG_TOOLBOX_BOX || theType == WDG_SWITCH_CASE || diff --git a/src/ModuleBase/ModuleBase_WidgetRadiobox.cpp b/src/ModuleBase/ModuleBase_WidgetRadiobox.cpp new file mode 100644 index 000000000..cf9355956 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetRadiobox.cpp @@ -0,0 +1,85 @@ +// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or +// email : webmaster.salome@opencascade.com +// + +#include +#include + +#include +#include +#include +#include + + +ModuleBase_WidgetRadiobox::ModuleBase_WidgetRadiobox(QWidget* theParent, + const Config_WidgetAPI* theData) + : ModuleBase_PagedContainer(theParent, theData) +{ + myLayout = new QFormLayout(this); + ModuleBase_Tools::adjustMargins(myLayout); + myGroup = new QButtonGroup(this); + myGroup->setExclusive(true); + + connect(myGroup, SIGNAL(buttonToggled(int, bool)), SLOT(onPageChanged())); +} + +ModuleBase_WidgetRadiobox::~ModuleBase_WidgetRadiobox() +{ +} + +int ModuleBase_WidgetRadiobox::addPage(ModuleBase_PageBase* thePage, + const QString& theName, + const QString& theCaseId, + const QPixmap& theIcon) +{ + ModuleBase_PagedContainer::addPage(thePage, theName, theCaseId, theIcon); + QWidget* aWgt = new QWidget(this); + QVBoxLayout* aLay = new QVBoxLayout(aWgt); + aLay->setContentsMargins(0, 0, 0, 0); + + QRadioButton* aButton = new QRadioButton(aWgt); + aButton->setToolTip(theName); + aLay->addStretch(); + aLay->addWidget(aButton); + aLay->addStretch(); + + //QFrame* aFrame = dynamic_cast(thePage); + QWidget* aPage = thePage->pageWidget(); + myLayout->addRow(aWgt, aPage); + myGroup->addButton(aButton, myGroup->buttons().count()); + + bool isDefault = theCaseId.toStdString() == getDefaultValue(); + aButton->setChecked(isDefault); + aPage->setEnabled(isDefault); + connect(aButton, SIGNAL(toggled(bool)), aPage, SLOT(setEnabled(bool))); + + return myGroup->buttons().count(); +} + +int ModuleBase_WidgetRadiobox::currentPageIndex() const +{ + return myGroup->checkedId(); +} + +void ModuleBase_WidgetRadiobox::setCurrentPageIndex(int theIndex) +{ + bool isSignalsBlocked = myGroup->blockSignals(true); + myGroup->button(theIndex)->setChecked(true); + myGroup->blockSignals(isSignalsBlocked); +} diff --git a/src/ModuleBase/ModuleBase_WidgetRadiobox.h b/src/ModuleBase/ModuleBase_WidgetRadiobox.h new file mode 100644 index 000000000..81713d824 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetRadiobox.h @@ -0,0 +1,64 @@ +// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or +// email : webmaster.salome@opencascade.com +// + +#ifndef MODULEBASE_WIDGETRADIOBOX_H_ +#define MODULEBASE_WIDGETRADIOBOX_H_ + +#include +#include + +class QFormLayout; +class QButtonGroup; +class QRadioButton; + +class MODULEBASE_EXPORT ModuleBase_WidgetRadiobox : public ModuleBase_PagedContainer +{ + Q_OBJECT +public: + /// Constructor + /// \param theParent the parent object + /// \param theData the widget configuration. The attribute of the model widget is obtained from + ModuleBase_WidgetRadiobox(QWidget* theParent, const Config_WidgetAPI* theData); + virtual ~ModuleBase_WidgetRadiobox(); + + + /// Add a page to the widget + /// \param theWidget a page widget + /// \param theName a name of page + /// \param theCaseId an Id of the page + /// \param theIcon an icon of the page + virtual int addPage(ModuleBase_PageBase* theWidget, + const QString& theName, + const QString& theCaseId, + const QPixmap& theIcon); + +protected: + /// Implements ModuleBase_PagedContainer + virtual int currentPageIndex() const; + + /// Implements ModuleBase_PagedContainer + virtual void setCurrentPageIndex(int); + +private: + QFormLayout* myLayout; + QButtonGroup* myGroup; +}; + +#endif \ No newline at end of file -- 2.39.2