]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Replace combobox by radiobuttons in boolean operations
authorvsv <vitaly.smetannikov@opencascade.com>
Thu, 5 Nov 2015 16:19:38 +0000 (19:19 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Thu, 5 Nov 2015 16:19:50 +0000 (19:19 +0300)
src/FeaturesPlugin/boolean_widget.xml
src/ModuleBase/ModuleBase_WidgetChoice.cpp
src/ModuleBase/ModuleBase_WidgetChoice.h
src/PartSet/PartSet_icons.qrc
src/PartSet/icons/bool_common.png [new file with mode: 0644]
src/PartSet/icons/bool_cut.png [new file with mode: 0644]
src/PartSet/icons/bool_fuse.png [new file with mode: 0644]

index 8fc0925caf92ddcaa47fbb9ff07a5abfaf2a4230..cdf755b6c21010fecaf50b1413579a93c2ceea84 100644 (file)
@@ -1,9 +1,18 @@
 <!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
 
 <source>
+  <choice id="bool_type"
+    widget_type="radiobuttons"
+    buttons_dir="horizontal"
+    label="Operation type" 
+    tooltip="Type of boolean operation"
+    string_list="Cut Fuse Common"
+    icons_list=":icons/bool_cut.png :icons/bool_fuse.png :icons/bool_common.png"
+    default="0"
+  />
   <multi_selector id="main_objects"
     label="Main objects"
-    icon=":icons/cut_shape.png"
+    icon=""
     tooltip="Select a solid objects"
     type_choice="Solids"
     concealment="true">
   </multi_selector>
   <multi_selector id="tool_objects" 
     label="Tool object" 
-    icon=":icons/cut_tool.png
+    icon="" 
     tooltip="Select a tool solid"
     type_choice="Solids"
     concealment="true" >
     <validator id="PartSet_DifferentObjects"/>
     <validator id="GeomValidators_ShapeType" parameters="empty,solid"/>
   </multi_selector>
-  <choice id="bool_type" 
-    label="Type" 
-    tooltip="Type of boolean operation"
-    string_list="Cut Fuse Common"
-    default="0"
-  />
   <validator id="GeomValidators_BooleanArguments" parameters="main_objects,tool_objects,bool_type"/>
 </source>
index c89508324c86fb47807bb34de494e79ef99ac2f5..4b09ffab63f7f6fd637f3132ca66ebb2789934a4 100644 (file)
 #include <QLayout>
 #include <QLabel>
 #include <QComboBox>
+#include <QButtonGroup>
+#include <QGroupBox>
+#include <QRadioButton>
+#include <QToolButton>
+
 
 ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent, 
                                                  const Config_WidgetAPI* theData, 
                                                  const std::string& theParentId)
-    : ModuleBase_ModelWidget(theParent, theData, theParentId)
+    : ModuleBase_ModelWidget(theParent, theData, theParentId), myCombo(0), myButtons(0)
 {
   QHBoxLayout* aLayout = new QHBoxLayout(this);
   ModuleBase_Tools::adjustMargins(aLayout);
 
   QString aLabelText = QString::fromStdString(theData->widgetLabel());
   QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
-  myLabel = new QLabel(aLabelText, this);
-  if (!aLabelIcon.isEmpty())
-    myLabel->setPixmap(QPixmap(aLabelIcon));
-  aLayout->addWidget(myLabel);
-
-  std::string aToolstr = theData->widgetTooltip();
-  if (!aToolstr.empty()) {
-    myLabel->setToolTip(QString::fromStdString(aToolstr));
-  }
-
-  myCombo = new QComboBox(this);
-  aLayout->addWidget(myCombo, 1);
   std::string aTypes = theData->getProperty("string_list");
   QStringList aList = QString(aTypes.c_str()).split(' ');
-  myCombo->addItems(aList);
 
-  connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
+  // Widget type can be combobox or radiobuttons
+  std::string aWgtType = theData->getProperty("widget_type");
+  if ((aWgtType.length() > 0) && (aWgtType == "radiobuttons")) {
+    myButtons = new QButtonGroup(this);
+    QGroupBox* aGroupBox = new QGroupBox(aLabelText, this);
+    aLayout->addWidget(aGroupBox);
+
+
+    QLayout* aBtnLayout = 0;
+    std::string aWgtDir = theData->getProperty("buttons_dir");
+    if (aWgtDir == "horizontal")
+      aBtnLayout = new QHBoxLayout(aGroupBox);
+    else 
+      aBtnLayout = new QVBoxLayout(aGroupBox);
+    ModuleBase_Tools::adjustMargins(aBtnLayout);
+
+    std::string aIcons = theData->getProperty("icons_list");
+    QStringList aIconList = QString(aIcons.c_str()).split(' ');
+    if (aIconList.length() == aList.length()) {
+      int aId = 0;
+      foreach(QString aBtnTxt, aList) {
+        QToolButton* aBtn = new QToolButton(aGroupBox);
+        aBtn->setCheckable(true);
+        aBtn->setToolTip(aBtnTxt);
+
+        QPixmap aIcon(aIconList.at(aId));
+        aBtn->setIcon(aIcon);
+        aBtn->setIconSize(aIcon.size());
+        
+        aBtnLayout->addWidget(aBtn);
+        myButtons->addButton(aBtn, aId++);
+      }
+
+    } else {
+      int aId = 0;
+      foreach(QString aBtnTxt, aList) {
+        QRadioButton* aBtn = new QRadioButton(aBtnTxt, aGroupBox);
+        aBtnLayout->addWidget(aBtn);
+        myButtons->addButton(aBtn, aId++);
+      }
+    }
+    myButtons->button(0)->setChecked(true);
+    connect(myButtons, SIGNAL(buttonClicked(int)), this, SLOT(onCurrentIndexChanged(int)));
+  } else {
+    myLabel = new QLabel(aLabelText, this);
+    if (!aLabelIcon.isEmpty())
+      myLabel->setPixmap(QPixmap(aLabelIcon));
+    aLayout->addWidget(myLabel);
+
+    std::string aToolstr = theData->widgetTooltip();
+    if (!aToolstr.empty()) {
+      myLabel->setToolTip(QString::fromStdString(aToolstr));
+    }
+
+    myCombo = new QComboBox(this);
+    aLayout->addWidget(myCombo, 1);
+    myCombo->addItems(aList);
+
+    connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
+  }
 }
 
 ModuleBase_WidgetChoice::~ModuleBase_WidgetChoice()
@@ -55,7 +106,10 @@ bool ModuleBase_WidgetChoice::storeValueCustom() const
   DataPtr aData = myFeature->data();
   std::shared_ptr<ModelAPI_AttributeInteger> aIntAttr = aData->integer(attributeID());
 
-  aIntAttr->setValue(myCombo->currentIndex());
+  if (myCombo)
+    aIntAttr->setValue(myCombo->currentIndex());
+  else
+    aIntAttr->setValue(myButtons->checkedId());
   updateObject(myFeature);
   return true;
 }
@@ -65,22 +119,39 @@ bool ModuleBase_WidgetChoice::restoreValueCustom()
   DataPtr aData = myFeature->data();
   std::shared_ptr<ModelAPI_AttributeInteger> aIntAttr = aData->integer(attributeID());
 
-  bool isBlocked = myCombo->blockSignals(true);
-  myCombo->setCurrentIndex(aIntAttr->value());
-  myCombo->blockSignals(isBlocked);
+  if (aIntAttr->value() != -1) {
+    if (myCombo) {
+      bool isBlocked = myCombo->blockSignals(true);
+      myCombo->setCurrentIndex(aIntAttr->value());
+      myCombo->blockSignals(isBlocked);
+    } else {
+      bool isBlocked = myButtons->blockSignals(true);
+      myButtons->button(aIntAttr->value())->setChecked(true);
+      myButtons->blockSignals(isBlocked);
+    }
+  }
   return true;
 }
 
 bool ModuleBase_WidgetChoice::focusTo()
 {
-  myCombo->setFocus();
+  if (myCombo)
+    myCombo->setFocus();
+  else
+    myButtons->button(0)->setFocus();
   return true;
 }
 
 QList<QWidget*> ModuleBase_WidgetChoice::getControls() const
 {
   QList<QWidget*> aControls;
-  aControls.append(myCombo);
+  if (myCombo)
+    aControls.append(myCombo);
+  //else {
+  //  //foreach(QAbstractButton* aBtn, myButtons->buttons())
+  //  //if (myButtons->checkedId() != -1)
+  //  //  aControls.append(myButtons->button(myButtons->checkedId()));
+  //}
   return aControls;
 }
 
index 72f6df4cd2e15eebbe100559cd7b8e4d6f7ba0d8..8e25ee1f935cee0b94ea01007976b923b3105328 100644 (file)
@@ -13,6 +13,7 @@
 class QWidget;
 class QLabel;
 class QComboBox;
+class QButtonGroup;
 
 /**
 * \ingroup GUI
@@ -25,6 +26,12 @@ class QComboBox;
 *     string_list="Cut Fuse Common"
 *   />
 * \endcode
+* Aditionally can be used: 
+* A key "widget_type". It can have values "combobox" or "radiobuttons".
+* By default it uses "combobox".
+* A key "buttons_dir" which is applicable only for "radiobuttons" mode.
+* It defines direction of radiobuttons layout. it can be "vertical" or "horizontal"
+* Default value is "vertical"
 */
 class MODULEBASE_EXPORT ModuleBase_WidgetChoice : public ModuleBase_ModelWidget
 {
@@ -62,6 +69,7 @@ private:
 
   /// The control
   QComboBox* myCombo;
+  QButtonGroup* myButtons;
 };
 
 #endif
index 8361c656e4ada29214b55946577fd15b02731319..8b840862acc7e7f991f6a04faa116c67f46634ea 100644 (file)
@@ -74,5 +74,8 @@
      <file>icons/by_two_points_32x32.png</file>
      <file>icons/cylindrical_face_32x32.png</file>
      <file>icons/dimension_vert_32x32.png</file>
+     <file>icons/bool_cut.png</file>
+     <file>icons/bool_fuse.png</file>
+     <file>icons/bool_common.png</file>
  </qresource>
  </RCC>
diff --git a/src/PartSet/icons/bool_common.png b/src/PartSet/icons/bool_common.png
new file mode 100644 (file)
index 0000000..99812c5
Binary files /dev/null and b/src/PartSet/icons/bool_common.png differ
diff --git a/src/PartSet/icons/bool_cut.png b/src/PartSet/icons/bool_cut.png
new file mode 100644 (file)
index 0000000..dd494d7
Binary files /dev/null and b/src/PartSet/icons/bool_cut.png differ
diff --git a/src/PartSet/icons/bool_fuse.png b/src/PartSet/icons/bool_fuse.png
new file mode 100644 (file)
index 0000000..5369a50
Binary files /dev/null and b/src/PartSet/icons/bool_fuse.png differ