Salome HOME
Use choice control for groups
authorvsv <vsv@opencascade.com>
Mon, 4 Dec 2017 16:15:48 +0000 (19:15 +0300)
committervsv <vsv@opencascade.com>
Mon, 4 Dec 2017 16:15:48 +0000 (19:15 +0300)
src/ModuleBase/ModuleBase_ChoiceCtrl.cpp
src/ModuleBase/ModuleBase_ChoiceCtrl.h
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.h
src/XGUI/XGUI_pictures.qrc

index 4d915b80194f8a74e6e423f5b7562437cbcc14d6..38afff3ca6c30efbff3e1c77d4778253554e7f83 100644 (file)
@@ -173,3 +173,14 @@ void ModuleBase_ChoiceCtrl::setChoiceList(const QStringList& theChoiceList)
     myCombo->addItems(theChoiceList);
   }
 }
+
+QString ModuleBase_ChoiceCtrl::textValue() const
+{
+  switch (myType) {
+  case RadioButtons:
+    return myButtons->checkedButton()->toolTip();
+  case ComboBox:
+    return myCombo->currentText();
+  }
+  return "";
+}
index 3f9c5de9b1f2e2805fb6a305fb4aca3921dc85eb..09530b9294ebfed2519d0d0b9dd3b1df26ceb62a 100644 (file)
@@ -32,6 +32,13 @@ class QComboBox;
 class QGroupBox;
 class QButtonGroup;
 
+/**
+* \ingroup GUI
+* A Choice control. It provides a choice in several strings.
+* It can be represented by several radiobuttons or by combo box.
+* Radio buttons can be represented as by radiou buttons with text
+* or by icons in toggle buttons.
+*/
 class MODULEBASE_EXPORT ModuleBase_ChoiceCtrl: public QWidget
 {
 Q_OBJECT
@@ -41,36 +48,70 @@ public:
     ComboBox
   };
 
+  /**
+  * Constructor
+  * \param theParent a parent widget
+  * \param theChoiceList a list of choice strings
+  * \param theIconsList a list of icon names for radiou buttons
+  * \param theType a type of choice representation
+  * \param theButtonsDir direction of radio buttons placement
+  */
   ModuleBase_ChoiceCtrl(QWidget* theParent,
                         const QStringList& theChoiceList,
                         const QStringList& theIconsList,
                         ControlType theType = RadioButtons,
                         Qt::Orientation theButtonsDir = Qt::Horizontal);
 
+  /// Set label for the controls.
+  /// It is a label for combo box and title for group of radio buttons.
+  /// \param theText a text of the label
   void setLabel(const QString& theText);
 
+  /// Set Icon for the label. Used only for combo box.
+  /// \param theIcon a name of icon
   void setLabelIcon(const QString& theIcon);
 
+  /// Set value: Id of button or item of combo box.
+  /// \param theVal a value (from 0 to number of items)
   void setValue(int theVal);
 
+  /// Set tool tip for label. Used only for combo box.
   void setTooltip(QString theTip);
 
+  /// Returns currently selected value
   int value() const;
 
+  /// Returns text of currently selected value
+  QString textValue() const;
+
+  /// Transfer focus on itself
   bool focusTo();
 
+  /// Returns controls for activation
   QList<QWidget*> getControls() const;
 
+  /// Set list of choice
+  /// \param theChoiceList a string list of items
   void setChoiceList(const QStringList& theChoiceList);
 
 signals:
+  /// A signal raised on change of current value
   void valueChanged(int theVal);
 
 private:
+  /// Control type
   ControlType myType;
+
+  /// A label for cmbo box
   QLabel* myLabel;
+
+  /// A combo box represerntation of control
   QComboBox* myCombo;
+
+  /// A group box for radio buttons
   QGroupBox* myGroupBox;
+
+  /// A group of buttons
   QButtonGroup* myButtons;
 };
 
index 973b9b6ec5aeaa7d02d27de41f478b5d5fac19bc..fd4fd7bcbd120015da418a91494a86043d889148 100755 (executable)
@@ -29,6 +29,7 @@
 #include <ModuleBase_ViewerPrs.h>
 #include <ModuleBase_IconFactory.h>
 #include <ModuleBase_Events.h>
+#include <ModuleBase_ChoiceCtrl.h>
 
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Object.h>
@@ -117,34 +118,56 @@ void printHistoryInfo(const QString& theMethodName, int theCurrentHistoryIndex,
 }
 #endif
 
+
+QStringList getIconsList(const QStringList& theNames)
+{
+  QStringList aIcons;
+  foreach (QString aName, theNames) {
+    QString aUName = aName.toUpper();
+    if ((aUName == "VERTICES") || (aUName == "VERTEX"))
+      aIcons << ":pictures/vertex32.png";
+    else if ((aUName == "EDGES") || (aUName == "EDGE"))
+      aIcons << ":pictures/edge32.png";
+    else if ((aUName == "FACES") || (aUName == "FACE"))
+      aIcons << ":pictures/face32.png";
+    else if ((aUName == "SOLIDS") || (aUName == "SOLID"))
+      aIcons << ":pictures/solid32.png";
+  }
+  return aIcons;
+}
+
+
+
 ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParent,
                                                                ModuleBase_IWorkshop* theWorkshop,
                                                                const Config_WidgetAPI* theData)
 : ModuleBase_WidgetSelector(theParent, theWorkshop, theData),
   myIsSetSelectionBlocked(false), myCurrentHistoryIndex(-1)
 {
+  std::string aPropertyTypes = theData->getProperty("type_choice");
+  QString aTypesStr = aPropertyTypes.c_str();
+  myShapeTypes = aTypesStr.split(' ', QString::SkipEmptyParts);
+  myIsUseChoice = theData->getBooleanAttribute("use_choice", false);
+
   QGridLayout* aMainLay = new QGridLayout(this);
   ModuleBase_Tools::adjustMargins(aMainLay);
 
-  QLabel* aTypeLabel = new QLabel(tr("Type"), this);
-  aMainLay->addWidget(aTypeLabel, 0, 0);
-
-  myTypeCombo = new QComboBox(this);
-  // There is no sense to parameterize list of types while we can not parameterize selection mode
+  //QLabel* aTypeLabel = new QLabel(tr("Type"), this);
+  //aMainLay->addWidget(aTypeLabel, 0, 0);
 
-  std::string aPropertyTypes = theData->getProperty("type_choice");
-  QString aTypesStr = aPropertyTypes.c_str();
-  QStringList aShapeTypes = aTypesStr.split(' ', QString::SkipEmptyParts);
+  //myTypeCombo = new QComboBox(this);
+  QStringList aIconsList = getIconsList(myShapeTypes);
+  myTypeCtrl = new ModuleBase_ChoiceCtrl(this, myShapeTypes, aIconsList);
+  myTypeCtrl->setLabel(tr("Type"));
+  myTypeCtrl->setValue(0);
 
-  myIsUseChoice = theData->getBooleanAttribute("use_choice", false);
-
-  if (!aShapeTypes.empty())
-    myTypeCombo->addItems(aShapeTypes);
-  aMainLay->addWidget(myTypeCombo, 0, 1);
+  // There is no sense to parameterize list of types while we can not parameterize selection mode
+  //if (!aShapeTypes.empty())
+  //  myTypeCombo->addItems(aShapeTypes);
+  aMainLay->addWidget(myTypeCtrl, 0, 0, 1, 2);
   // if the xml definition contains one type, the controls to select a type should not be shown
-  if (aShapeTypes.size() <= 1 || !myIsUseChoice) {
-    aTypeLabel->setVisible(false);
-    myTypeCombo->setVisible(false);
+  if (myShapeTypes.size() <= 1 || !myIsUseChoice) {
+    myTypeCtrl->setVisible(false);
   }
 
   QString aLabelText = translate(theData->getProperty("label"));
@@ -152,7 +175,7 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen
   aMainLay->addWidget(aListLabel, 1, 0);
   // if the xml definition contains one type, an information label
   // should be shown near to the latest
-  if (aShapeTypes.size() <= 1) {
+  if (myShapeTypes.size() <= 1) {
     QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
     if (!aLabelIcon.isEmpty()) {
       QLabel* aSelectedLabel = new QLabel("", this);
@@ -174,7 +197,7 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen
   //aMainLay->addWidget(new QLabel(this)); //FIXME(sbh)???
   //aMainLay->setRowMinimumHeight(3, 20);
   //this->setLayout(aMainLay);
-  connect(myTypeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onSelectionTypeChanged()));
+  connect(myTypeCtrl, SIGNAL(valueChanged(int)), this, SLOT(onSelectionTypeChanged()));
 
   myCopyAction = ModuleBase_Tools::createAction(QIcon(":pictures/copy.png"), tr("Copy"),
                           myWorkshop->desktop(), this, SLOT(onCopyItem()));
@@ -230,7 +253,8 @@ bool ModuleBase_WidgetMultiSelector::storeValueCustom()
   std::string aType = anAttribute->attributeType();
   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
     AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID());
-    aSelectionListAttr->setSelectionType(myTypeCombo->currentText().toStdString());
+    //aSelectionListAttr->setSelectionType(myTypeCombo->currentText().toStdString());
+    aSelectionListAttr->setSelectionType(myTypeCtrl->textValue().toStdString());
   }
   return true;
 }
@@ -498,7 +522,7 @@ void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()
   std::string aType = anAttribute->attributeType();
   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
     AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID());
-    aSelectionListAttr->setSelectionType(myTypeCombo->currentText().toStdString());
+    aSelectionListAttr->setSelectionType(myTypeCtrl->textValue().toStdString());
   }
 
   // clear attribute values
@@ -630,12 +654,13 @@ QIntList ModuleBase_WidgetMultiSelector::shapeTypes() const
 {
   QIntList aShapeTypes;
 
-  if (myTypeCombo->count() > 1 && myIsUseChoice) {
-    aShapeTypes.append(ModuleBase_Tools::shapeType(myTypeCombo->currentText()));
+  if (myShapeTypes.length() > 1 && myIsUseChoice) {
+    aShapeTypes.append(ModuleBase_Tools::shapeType(myTypeCtrl->textValue()));
   }
   else {
-    for (int i = 0, aCount = myTypeCombo->count(); i < aCount; i++)
-      aShapeTypes.append(ModuleBase_Tools::shapeType(myTypeCombo->itemText(i)));
+    foreach (QString aType, myShapeTypes) {
+      aShapeTypes.append(ModuleBase_Tools::shapeType(aType));
+    }
   }
   return aShapeTypes;
 }
@@ -645,18 +670,21 @@ void ModuleBase_WidgetMultiSelector::setCurrentShapeType(const int theShapeType)
 {
   QString aShapeTypeName;
 
-  for (int idx = 0; idx < myTypeCombo->count(); ++idx) {
-    aShapeTypeName = myTypeCombo->itemText(idx);
+  //for (int idx = 0; idx < myTypeCombo->count(); ++idx) {
+  //  aShapeTypeName = myTypeCombo->itemText(idx);
+  int idx = 0;
+  foreach (QString aShapeTypeName, myShapeTypes) {
     int aRefType = ModuleBase_Tools::shapeType(aShapeTypeName);
-    if(aRefType == theShapeType && idx != myTypeCombo->currentIndex()) {
+    if(aRefType == theShapeType && idx != myTypeCtrl->value()) {
       bool aWasActivated = activateSelectionAndFilters(false);
-      bool isBlocked = myTypeCombo->blockSignals(true);
-      myTypeCombo->setCurrentIndex(idx);
-      myTypeCombo->blockSignals(isBlocked);
+      bool isBlocked = myTypeCtrl->blockSignals(true);
+      myTypeCtrl->setValue(idx);
+      myTypeCtrl->blockSignals(isBlocked);
       if (aWasActivated)
         activateSelectionAndFilters(true);
       break;
     }
+    idx++;
   }
 }
 
index 74b0ff510ea36567495b8204b91dbfb30d0653ae..ca4830e67f3c3cd1e5a00607fda7d8cbd0782a17 100755 (executable)
 
 class QWidget;
 class QListWidget;
-class QComboBox;
+//class QComboBox;
 class ModuleBase_IWorkshop;
 class QAction;
+class ModuleBase_ChoiceCtrl;
 
 
 /**
@@ -218,8 +219,10 @@ protected:
   /// List control
   QListWidget* myListControl;
 
-  /// Combobox of types
-  QComboBox* myTypeCombo;
+  QStringList myShapeTypes;
+
+  /// Control for types
+  ModuleBase_ChoiceCtrl* myTypeCtrl;
 
   /// Provides correspondance between Result object and its shape
   typedef QPair<ResultPtr, GeomShapePtr> GeomSelection;
index d2f9f767e9b3b78a12f0140004ff3f5c5856298f..02d5d716b40138699e5de0e24e356f6d5c61fdc5 100644 (file)
@@ -62,5 +62,9 @@
      <file>pictures/eyeopen.png</file>
 
      <file>pictures/transparency.png</file>
+     <file>pictures/solid32.png</file>
+     <file>pictures/face32.png</file>
+     <file>pictures/edge32.png</file>
+     <file>pictures/vertex32.png</file>
  </qresource>
  </RCC>