Salome HOME
#2205 Ability to customize the arrows and texts of dimensions: GUI correction to...
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetChoice.cpp
index 3c23cbf482d28422acb26c908fbfbd2d2b189f0e..1bc6987e13ca85abce3a4453421d18871d0226da 100644 (file)
@@ -1,8 +1,22 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        ModuleBase_WidgetChoice.cpp
-// Created:     03 Sept 2014
-// Author:      Vitaly Smetannikov
+// 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<mailto:webmaster.salome@opencascade.com>
+//
 
 #include "ModuleBase_WidgetChoice.h"
 #include "ModuleBase_Tools.h"
@@ -41,6 +55,8 @@ ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent,
   if (theData->getBooleanAttribute("use_in_title", false))
     myButtonTitles = aList;
 
+  bool aHasDefaultValue;
+  int aDefaultVal = QString::fromStdString(getDefaultValue()).toInt(&aHasDefaultValue);
   // Widget type can be combobox or radiobuttons
   std::string aWgtType = theData->getProperty("widget_type");
   if ((aWgtType.length() > 0) && (aWgtType == "radiobuttons")) {
@@ -83,7 +99,8 @@ ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent,
         myButtons->addButton(aBtn, aId++);
       }
     }
-    myButtons->button(0)->setChecked(true);
+    int aCheckedId = aHasDefaultValue ? aDefaultVal : 0;
+    myButtons->button(aDefaultVal)->setChecked(true);
     connect(myButtons, SIGNAL(buttonClicked(int)), this, SLOT(onCurrentIndexChanged(int)));
   } else {
     myLabel = new QLabel(aLabelText, this);
@@ -101,6 +118,9 @@ ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent,
 
     myCombo->addItems(aList);
 
+    if (aHasDefaultValue && aDefaultVal < aList.size())
+      myCombo->setCurrentIndex(aDefaultVal);
+
     connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
   }
 }
@@ -134,7 +154,13 @@ bool ModuleBase_WidgetChoice::restoreValueCustom()
       myCombo->blockSignals(isBlocked);
     } else {
       bool isBlocked = myButtons->blockSignals(true);
-      myButtons->button(aIntAttr->value())->setChecked(true);
+      if (aIntAttr->isInitialized())
+        myButtons->button(aIntAttr->value())->setChecked(true);
+      else {
+        bool aHasDefaultValue;
+        int aDefaultVal = QString::fromStdString(getDefaultValue()).toInt(&aHasDefaultValue);
+        myButtons->button(aHasDefaultValue ? aDefaultVal : 0)->setChecked(true);
+      }
       myButtons->blockSignals(isBlocked);
       emit itemSelected(this, aIntAttr->value());
     }