Salome HOME
Issue #1659 New widget for supporting optional inputs : rename CheckGroupBox to Optio...
authornds <nds@opencascade.com>
Thu, 14 Jul 2016 07:46:44 +0000 (10:46 +0300)
committernds <nds@opencascade.com>
Thu, 14 Jul 2016 07:46:44 +0000 (10:46 +0300)
src/Config/Config_Common.cpp
src/Config/Config_FeatureReader.cpp
src/Config/Config_Keywords.h
src/Config/Config_WidgetAPI.cpp
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_WidgetCheckGroupBox.cpp [deleted file]
src/ModuleBase/ModuleBase_WidgetCheckGroupBox.h [deleted file]
src/ModuleBase/ModuleBase_WidgetFactory.cpp
src/ModuleBase/ModuleBase_WidgetOptionalBox.cpp [new file with mode: 0755]
src/ModuleBase/ModuleBase_WidgetOptionalBox.h [new file with mode: 0755]

index ac274ada8ef73524c07911d8ca5f976664e4dc64..6d89535e7edf6a6553264933b25ff86c0381e338 100644 (file)
@@ -56,14 +56,14 @@ bool isAttributeNode(xmlNodePtr theNode)
     return false;\r
   // it's parent is "feature" or "source" or page ("case" or "box")\r
   if(!hasParent(theNode, NODE_FEATURE, NODE_SOURCE, \r
-                         WDG_GROUP, WDG_CHECK_GROUP,\r
+                         WDG_GROUP, WDG_OPTIONALBOX,\r
                          WDG_TOOLBOX_BOX, WDG_SWITCH_CASE, NULL))\r
     return false;\r
 \r
   //it should not be a "source" or a "validator" node\r
   bool isLogical = isNode(theNode, NODE_SOURCE, NODE_VALIDATOR, NODE_SELFILTER, NULL);\r
   bool isPagedContainer = isNode(theNode, WDG_TOOLBOX, WDG_TOOLBOX_BOX,\r
-                                          WDG_GROUP, WDG_CHECK_GROUP,\r
+                                          WDG_GROUP, WDG_OPTIONALBOX,\r
                                           WDG_SWITCH, WDG_SWITCH_CASE,  NULL);\r
   return !isLogical && !isPagedContainer;\r
 }\r
@@ -73,7 +73,7 @@ bool isWidgetNode(xmlNodePtr theNode)
   if(!isElementNode(theNode))\r
     return false;\r
   // it's parent is "feature" or "source" or a page ("box", "case")\r
-  if(!hasParent(theNode, NODE_FEATURE, NODE_SOURCE, WDG_GROUP, WDG_CHECK_GROUP,\r
+  if(!hasParent(theNode, NODE_FEATURE, NODE_SOURCE, WDG_GROUP, WDG_OPTIONALBOX,\r
                          WDG_TOOLBOX_BOX, WDG_SWITCH_CASE, NULL))\r
     return false;\r
 \r
@@ -87,7 +87,7 @@ bool isCaseNode(xmlNodePtr theNode)
   if(!isElementNode(theNode))\r
     return false;\r
 \r
-  return isNode(theNode, WDG_CHECK_GROUP, WDG_SWITCH_CASE, WDG_TOOLBOX_BOX, NULL);\r
+  return isNode(theNode, WDG_OPTIONALBOX, WDG_SWITCH_CASE, WDG_TOOLBOX_BOX, NULL);\r
 }\r
 \r
 bool hasChild(xmlNodePtr theNode)\r
index 4797d9d4a2b9105b8615a96d63b044f480d2f441..5fdd12f6af11cb7972b0588feeb97962c91e7c3f 100644 (file)
@@ -73,7 +73,7 @@ void Config_FeatureReader::processNode(xmlNodePtr theNode)
         aMessage->setConcealment(getBooleanAttribute(theNode, ATTR_CONCEALMENT, false));
 
         std::list<std::pair<std::string, std::string> > aCases;
-        xmlNodePtr aCaseNode = hasParentRecursive(theNode, WDG_SWITCH_CASE, WDG_TOOLBOX_BOX, WDG_CHECK_GROUP, NULL);
+        xmlNodePtr aCaseNode = hasParentRecursive(theNode, WDG_SWITCH_CASE, WDG_TOOLBOX_BOX, WDG_OPTIONALBOX, NULL);
         while(aCaseNode) {
           std::string aCaseNodeID = getProperty(aCaseNode, _ID);
           std::string aSwitchNodeID = "";
@@ -85,7 +85,7 @@ void Config_FeatureReader::processNode(xmlNodePtr theNode)
           else if (!xmlStrcmp(aName, (const xmlChar *) WDG_TOOLBOX_BOX)) {
             aSwitchNode = hasParentRecursive(aCaseNode, WDG_TOOLBOX, NULL);
           }
-          if (!xmlStrcmp(aName, (const xmlChar *) WDG_CHECK_GROUP)) {
+          if (!xmlStrcmp(aName, (const xmlChar *) WDG_OPTIONALBOX)) {
             /// the box is optional, attribute is in case if the optional attribute value is not empty
             aSwitchNode = aCaseNode;
           }
@@ -93,13 +93,13 @@ void Config_FeatureReader::processNode(xmlNodePtr theNode)
             aSwitchNodeID = getProperty(aSwitchNode, _ID);
 
           aCases.push_back(std::make_pair(aSwitchNodeID, aCaseNodeID));
-          aCaseNode = hasParentRecursive(aSwitchNode, WDG_SWITCH_CASE, WDG_TOOLBOX_BOX, WDG_CHECK_GROUP, NULL);
+          aCaseNode = hasParentRecursive(aSwitchNode, WDG_SWITCH_CASE, WDG_TOOLBOX_BOX, WDG_OPTIONALBOX, NULL);
         }
         aMessage->setCases(aCases);
         Events_Loop::loop()->send(aMessage);
       }
     // container pages, like "case" or "box"
-    } else if (isNode(theNode, WDG_CHECK_GROUP, WDG_SWITCH, WDG_SWITCH_CASE,
+    } else if (isNode(theNode, WDG_OPTIONALBOX, WDG_SWITCH, WDG_SWITCH_CASE,
                       WDG_TOOLBOX, WDG_TOOLBOX_BOX, NULL)) {
       storeAttribute(theNode, _ID); // save case:caseId (or box:boxId)
     }
@@ -110,7 +110,7 @@ void Config_FeatureReader::processNode(xmlNodePtr theNode)
 
 void Config_FeatureReader::cleanup(xmlNodePtr theNode)
 {
-  if (isNode(theNode, WDG_CHECK_GROUP, WDG_SWITCH, WDG_SWITCH_CASE,
+  if (isNode(theNode, WDG_OPTIONALBOX, WDG_SWITCH, WDG_SWITCH_CASE,
              WDG_TOOLBOX, WDG_TOOLBOX_BOX, NULL)) {
     // cleanup id of cases when leave case node
     cleanupAttribute(theNode, _ID);
@@ -122,7 +122,7 @@ bool Config_FeatureReader::processChildren(xmlNodePtr theNode)
   bool result = isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NULL);
   if(!result && myIsProcessWidgets) {
     result = isNode(theNode, NODE_FEATURE, 
-                             WDG_GROUP, WDG_CHECK_GROUP,
+                             WDG_GROUP, WDG_OPTIONALBOX,
                              WDG_TOOLBOX, WDG_TOOLBOX_BOX,
                              WDG_SWITCH, WDG_SWITCH_CASE, NULL);
   }
index 0fc75262dd3a8789d26cc607fb4038799a059200..43227a57103e35db29fa81198255c044049c64b7 100644 (file)
@@ -41,7 +41,7 @@ const static char* WDG_ACTION = "action";
 
 // Containers
 const static char* WDG_GROUP = "groupbox";
-const static char* WDG_CHECK_GROUP = "check_groupbox";
+const static char* WDG_OPTIONALBOX = "optionalbox";
 const static char* WDG_TOOLBOX = "toolbox";
 const static char* WDG_TOOLBOX_BOX = "box";
 const static char* WDG_SWITCH = "switch";
index 2b74277a142da5059e4024e55dd9a29efb774165..e8dcbf4be98df31111a8965313a46475d6ffccff 100644 (file)
@@ -81,7 +81,7 @@ std::string Config_WidgetAPI::widgetType() const
 
 bool Config_WidgetAPI::isGroupBoxWidget() const
 {
-  return isNode(myCurrentNode, WDG_GROUP, WDG_CHECK_GROUP,
+  return isNode(myCurrentNode, WDG_GROUP, WDG_OPTIONALBOX,
                 NULL);
 }
 
index c4fe31943fd2fab04a5925cc7e793c10ce1f391d..8dd3b5de7af7af56363a5886f799e563b9e61e30 100644 (file)
@@ -42,7 +42,6 @@ SET(PROJECT_HEADERS
   ModuleBase_ViewerPrs.h
   ModuleBase_WidgetAction.h
   ModuleBase_WidgetBoolValue.h
-  ModuleBase_WidgetCheckGroupBox.h
   ModuleBase_WidgetChoice.h
   ModuleBase_WidgetCreatorFactory.h
   ModuleBase_WidgetDoubleValue.h
@@ -54,6 +53,7 @@ SET(PROJECT_HEADERS
   ModuleBase_WidgetLabel.h
   ModuleBase_WidgetLineEdit.h
   ModuleBase_WidgetMultiSelector.h
+  ModuleBase_WidgetOptionalBox.h
   ModuleBase_WidgetSelector.h
   ModuleBase_WidgetSelectorStore.h
   ModuleBase_WidgetShapeSelector.h
@@ -101,7 +101,6 @@ SET(PROJECT_SOURCES
   ModuleBase_ViewerPrs.cpp
   ModuleBase_WidgetAction.cpp
   ModuleBase_WidgetBoolValue.cpp
-  ModuleBase_WidgetCheckGroupBox.cpp
   ModuleBase_WidgetChoice.cpp
   ModuleBase_WidgetCreatorFactory.cpp
   ModuleBase_WidgetDoubleValue.cpp
@@ -113,6 +112,7 @@ SET(PROJECT_SOURCES
   ModuleBase_WidgetLabel.cpp
   ModuleBase_WidgetLineEdit.cpp
   ModuleBase_WidgetMultiSelector.cpp
+  ModuleBase_WidgetOptionalBox.cpp
   ModuleBase_WidgetSelector.cpp
   ModuleBase_WidgetSelectorStore.cpp
   ModuleBase_WidgetShapeSelector.cpp
diff --git a/src/ModuleBase/ModuleBase_WidgetCheckGroupBox.cpp b/src/ModuleBase/ModuleBase_WidgetCheckGroupBox.cpp
deleted file mode 100755 (executable)
index 6ca136d..0000000
+++ /dev/null
@@ -1,241 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-// File:        ModuleBase_WidgetCheckGroupBox.cpp
-// Created:     13 Dec 2015
-// Author:      Natalia ERMOLAEVA
-
-#include <ModuleBase_WidgetCheckGroupBox.h>
-#include <ModelAPI_AttributeString.h>
-
-#include <Config_WidgetAPI.h>
-#include <Config_Keywords.h>
-
-#include <QWidget>
-#include <QGroupBox>
-#include <QCheckBox>
-#include <QGridLayout>
-#include <QVBoxLayout>
-
-#include <QList>
-
-ModuleBase_WidgetCheckGroupBox::ModuleBase_WidgetCheckGroupBox(QWidget* theParent,
-                                                               const Config_WidgetAPI* theData)
-: ModuleBase_ModelWidget(theParent, theData),
-  ModuleBase_PageBase(),
-  myOptionType(CheckBox),
-  myCheckBoxFrame(0),
-  myCheckBox(0),
-  myCheckBoxLayout(0),
-  myCheckBoxWidget(0),
-  myGroupBox(0),
-  myGroupBoxLayout(0)
-{
-  myToolTip = theData->widgetTooltip();
-  myGroupTitle = theData->getProperty(CONTAINER_PAGE_NAME);
-
-  bool isChecked = theData->getBooleanAttribute(ATTR_DEFAULT, false);
-  setDefaultValue(isChecked ? "true" : "false");
-
-  myMainLayout = new QVBoxLayout(this);
-  ModuleBase_Tools::adjustMargins(myMainLayout);
-}
-
-ModuleBase_WidgetCheckGroupBox::~ModuleBase_WidgetCheckGroupBox()
-{
-}
-
-QWidget* ModuleBase_WidgetCheckGroupBox::pageWidget()
-{
-  return myOptionType == GroupBox ? myGroupBox : (QWidget*)myCheckBoxFrame;
-}
-
-QList<QWidget*> ModuleBase_WidgetCheckGroupBox::getControls() const
-{
-  QList<QWidget*> aControls;
-  if (myOptionType == GroupBox)
-    aControls.append(myGroupBox);
-  else
-    aControls.append(myCheckBoxFrame);
-
-  return aControls;
-}
-
-void ModuleBase_WidgetCheckGroupBox::onPageClicked()
-{
-  storeValue();
-  updateControlsVisibility();
-
-  if (!isEditingMode())
-    emit focusOutWidget(this);
-}
-
-void ModuleBase_WidgetCheckGroupBox::addPageStretch()
-{
-}
-
-void ModuleBase_WidgetCheckGroupBox::placeModelWidget(ModuleBase_ModelWidget* theWidget)
-{
-  if(!isCheckBoxFilled() && myOptionType == CheckBox) {
-    createControl(CheckBox);
-    setOptionType(CheckBox);
-
-    myCheckBoxWidget = theWidget; /// check box frame becomes filled
-    myCheckBoxLayout->addWidget(theWidget);
-  }
-  else {
-    createControl(GroupBox);
-    setOptionType(GroupBox);
-
-    ModuleBase_ModelWidget* aCheckBoxWidget = myCheckBoxWidget;
-    myCheckBoxWidget = 0;
-    if (aCheckBoxWidget) // move the model widget from check box frame to group box frame
-      placeModelWidget(aCheckBoxWidget);
-
-    const int kCol = 0;
-    const int kRow = myGroupBoxLayout->count();
-    // it seems, that the align on left is not necessary here, but leads to widgets, which are
-    // not extended on full width of the parent page. The case is grouped widgets in
-    // the sketch translation operation
-    myGroupBoxLayout->addWidget(theWidget, kRow, kCol, Qt::AlignTop);// | Qt::AlignLeft);
-    myGroupBoxLayout->setRowStretch(kRow, 0);
-  }
-}
-
-void ModuleBase_WidgetCheckGroupBox::placeWidget(QWidget* theWidget)
-{
-  createControl(GroupBox);
-  setOptionType(GroupBox);
-  if (isCheckBoxFilled())
-    placeModelWidget(myCheckBoxWidget);
-
-
-  if (!theWidget) {
-#ifdef _DEBUG
-    std::cout << "ModuleBase_PageGroupBox::placePageWidget: can not cast page" << std::endl;
-#endif
-    return;
-  }
-  const int kCol = 0;
-  const int kRow = myGroupBoxLayout->count();
-  myGroupBoxLayout->addWidget(theWidget, kRow, kCol);
-  myGroupBoxLayout->setRowStretch(kRow, 0);
-}
-
-QLayout* ModuleBase_WidgetCheckGroupBox::pageLayout()
-{
-  return myOptionType == GroupBox ? myGroupBoxLayout : (QLayout*)myCheckBoxLayout;
-}
-
-void ModuleBase_WidgetCheckGroupBox::createControl(const OptionType& theType)
-{
-  if (theType == GroupBox && !myGroupBox) {
-    // group box: more than one model widget is inside
-    myGroupBox = new QGroupBox(this);
-    myGroupBox->setTitle(QString::fromStdString(myGroupTitle));
-    myGroupBox->setVisible(false);
-    myGroupBox->setCheckable(true);
-    myGroupBox->setChecked(getDefaultValue() == "true");
-    myGroupBox->setToolTip(QString::fromStdString(myToolTip));
-
-    myGroupBoxLayout = new QGridLayout(myGroupBox);
-    ModuleBase_Tools::zeroMargins(myGroupBoxLayout);
-    myGroupBox->setLayout(myGroupBoxLayout);
-
-    // default vertical size policy is preferred
-    myMainLayout->addWidget(myGroupBox);
-    connect(myGroupBox, SIGNAL(clicked(bool)), this, SLOT(onPageClicked()));
-  }
-  else if (theType == CheckBox && !myCheckBoxFrame) {
-    myCheckBoxFrame = new QFrame(this);
-    myMainLayout->addWidget(myCheckBoxFrame);
-
-    myCheckBoxLayout = new QHBoxLayout(myCheckBoxFrame);
-    ModuleBase_Tools::adjustMargins(myCheckBoxLayout);
-    myCheckBox = new QCheckBox(myCheckBoxFrame);
-    myCheckBox->setChecked(getDefaultValue() == "true");
-    myCheckBoxLayout->addWidget(myCheckBox);
-
-    connect(myCheckBox, SIGNAL(clicked(bool)), this, SLOT(onPageClicked()));
-  }
-}
-
-bool ModuleBase_WidgetCheckGroupBox::storeValueCustom()
-{
-  DataPtr aData = myFeature->data();
-  AttributeStringPtr aStringAttr = aData->string(attributeID());
-  aStringAttr->setValue(getCurrentValue() ? attributeID() : "");
-
-  updateObject(myFeature);
-
-  return true;
-}
-
-bool ModuleBase_WidgetCheckGroupBox::restoreValueCustom()
-{
-  DataPtr aData = myFeature->data();
-  AttributeStringPtr aStringAttr = aData->string(attributeID());
-  setCurrentValue(!aStringAttr->value().empty());
-
-  return true;
-}
-
-void ModuleBase_WidgetCheckGroupBox::setOptionType(
-                         const ModuleBase_WidgetCheckGroupBox::OptionType& theType)
-{
-  myOptionType = theType;
-
-  bool isGroupBox = myOptionType == GroupBox;
-  if (myCheckBoxFrame)
-    myCheckBoxFrame->setVisible(!isGroupBox);
-  if (myGroupBox)
-    myGroupBox->setVisible(isGroupBox);
-}
-
-bool ModuleBase_WidgetCheckGroupBox::isCheckBoxFilled() const
-{
-  return myCheckBoxWidget != 0;
-}
-
-bool ModuleBase_WidgetCheckGroupBox::getCurrentValue() const
-{
-  bool isGroupBox = myOptionType == GroupBox;
-  return isGroupBox ? myGroupBox->isChecked() : myCheckBox->isChecked();
-}
-
-void ModuleBase_WidgetCheckGroupBox::setCurrentValue(const bool& theValue)
-{
-  bool isGroupBox = myOptionType == GroupBox;
-  if (isGroupBox) {
-    bool isBlocked = myGroupBox->blockSignals(true);
-    myGroupBox->setChecked(theValue);
-    myGroupBox->blockSignals(isBlocked);
-  }
-  else {
-    bool isBlocked = myCheckBox->blockSignals(true);
-    myCheckBox->setChecked(theValue);
-    myCheckBox->blockSignals(isBlocked);
-  }
-  updateControlsVisibility();
-}
-
-void ModuleBase_WidgetCheckGroupBox::updateControlsVisibility()
-{
-  if (myOptionType == GroupBox) {
-    bool aChecked = myGroupBox->isChecked();
-    if (aChecked)
-      ModuleBase_Tools::zeroMargins(myGroupBoxLayout);
-    else
-      ModuleBase_Tools::adjustMargins(myGroupBoxLayout);
-
-    int aNbSubControls = myGroupBoxLayout->count();
-    for (int i = 0; i < aNbSubControls; i++) {
-      QWidget* aWidget = myGroupBoxLayout->itemAt(i)->widget();
-      if (aWidget)
-        aWidget->setVisible(aChecked);
-    }
-  }
-  else {
-    bool aChecked = myCheckBox->isChecked();
-    myCheckBoxWidget->setEnabled(aChecked);
-  }
-}
diff --git a/src/ModuleBase/ModuleBase_WidgetCheckGroupBox.h b/src/ModuleBase/ModuleBase_WidgetCheckGroupBox.h
deleted file mode 100755 (executable)
index 8db7491..0000000
+++ /dev/null
@@ -1,118 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-// File:        ModuleBase_WidgetCheckGroupBox.h
-// Created:     13 Dec 2015
-// Author:      Natalia ERMOLAEVA
-
-#ifndef ModuleBase_WidgetCheckGroupBox_H_
-#define ModuleBase_WidgetCheckGroupBox_H_
-
-#include <ModuleBase.h>
-#include <ModuleBase_PageBase.h>
-#include <ModuleBase_ModelWidget.h>
-
-class QGroupBox;
-class QFrame;
-class QCheckBox;
-class QVBoxLayout;
-class QHBoxLayout;
-class QGridLayout;
-
-/**
-* \ingroup GUI
-* Implements a model widget for switch as a container widget. It can be defined in XML with "toolbox" keyword
-*/
-class MODULEBASE_EXPORT ModuleBase_WidgetCheckGroupBox : public ModuleBase_ModelWidget,
-                                                         public ModuleBase_PageBase
-{
-  Q_OBJECT
-
-  enum OptionType {CheckBox, GroupBox};
-public:
-  /// Constructor
-  /// \param theParent the parent object
-  /// \param theData the widget configuration. The attribute of the model widget is obtained from
-  ModuleBase_WidgetCheckGroupBox(QWidget* theParent, const Config_WidgetAPI* theData);
-  virtual ~ModuleBase_WidgetCheckGroupBox();
-
-  /// Defines if it is supported to set the value in this widget
-  /// \return false because this is an info widget
-  virtual bool canAcceptFocus() const { return false; };
-
-  /// Methods to be redefined from ModuleBase_PageBase: start
-  /// Cast the page to regular QWidget
-  virtual QWidget* pageWidget();
-  /// Methods to be redefined from ModuleBase_PageBase: end
-
-  /// Methods to be redefined from ModuleBase_ModelWidget: start
-  /// Returns list of widget controls
-  /// \return a control list
-  virtual QList<QWidget*> getControls() const;
-  /// Methods to be redefined from ModuleBase_ModelWidget: end
-
-protected slots:
-  // store value to the model
-  void onPageClicked();
-
-protected:
-  /// Methods to be redefined from ModuleBase_PageBase: start
-  /// Adds the given widget to page's layout
-  virtual void placeModelWidget(ModuleBase_ModelWidget* theWidget);
-  /// Adds the given page to page's layout
-  virtual void placeWidget(QWidget* theWidget);
-  /// Returns page's layout (QGridLayout)
-  virtual QLayout* pageLayout();
-  /// Adds a stretch to page's layout
-  virtual void addPageStretch();
-  /// Methods to be redefined from ModuleBase_PageBase: end
-
-
-  /// Methods to be redefined from ModuleBase_ModelWidget: start
-  /// Saves the internal parameters to the given feature
-  /// \return True in success
-  virtual bool storeValueCustom();
-  /// Restore value from attribute data to the widget's control
-  virtual bool restoreValueCustom();
-  /// Methods to be redefined from ModuleBase_ModelWidget: end
-
-private:
-  /// Sets whether Check box or Group box is used currently
-  /// \param theType a type of the control
-  void setOptionType(const OptionType& theType);
-
-  /// Returns true if the model widget is set into the check box frame
-  /// \return boolean value
-  bool isCheckBoxFilled() const;
-
-  /// Creates controls for the given type if it was not perfomed yet
-  /// \param theType a type to create whether check box or group box controls
-  void createControl(const OptionType& theType);
-
-  /// Returns true if control is checked
-  /// \return boolean value
-  bool getCurrentValue() const;
-
-  /// Returns true if control is checked
-  /// \param theValue a new value to fill the control state
-  void setCurrentValue(const bool& theValue);
-
-  /// Makes model widget controls either disabled(for check box mode) or hidden(for group box mode)
-  void updateControlsVisibility();
-
-private:
-  std::string myToolTip; ///< tool tip defined in XML
-  std::string myGroupTitle; ///< a title for group box
-
-  OptionType myOptionType; ///< current option state
-  QVBoxLayout* myMainLayout; ///< the main layout
-  // controls to fill check box frame
-  QFrame* myCheckBoxFrame; ///< frame with check box, to be hidden when group box is used
-  QCheckBox* myCheckBox; ///< control used if only one model widget is placed inside
-  QHBoxLayout* myCheckBoxLayout; ///< layout of check box frame
-  ModuleBase_ModelWidget* myCheckBoxWidget; /// model widget, placed in the check box frame
-  // controls to fill group box frame
-  QGroupBox* myGroupBox; ///< control used if more than model widget is placed inside
-  QGridLayout* myGroupBoxLayout; ///< page's layout
-};
-
-#endif /* ModuleBase_WidgetCheckGroupBox_H_ */
index 8016ab6eaa5d61c52ef9685a7bcd560d0996ae0d..a33522dee055699c0615756a2b186f1a509f689e 100644 (file)
@@ -29,7 +29,7 @@
 #include <ModuleBase_WidgetToolbox.h>
 #include <ModuleBase_PageBase.h>
 #include <ModuleBase_PageGroupBox.h>
-#include <ModuleBase_WidgetCheckGroupBox.h>
+#include <ModuleBase_WidgetOptionalBox.h>
 #include <ModuleBase_PageWidget.h>
 #include <ModuleBase_WidgetExprEditor.h>
 #include <ModuleBase_WidgetCreatorFactory.h>
@@ -257,8 +257,8 @@ ModuleBase_PageBase* ModuleBase_WidgetFactory::createPageByType(const std::strin
     aPage->setTitle(aGroupName);
     aResult = aPage;
   }
-  else if (theType == WDG_CHECK_GROUP) {
-    ModuleBase_WidgetCheckGroupBox* aPage = new ModuleBase_WidgetCheckGroupBox(theParent,
+  else if (theType == WDG_OPTIONALBOX) {
+    ModuleBase_WidgetOptionalBox* aPage = new ModuleBase_WidgetOptionalBox(theParent,
                                                                 myWidgetApi);
     aResult = aPage;
   }
diff --git a/src/ModuleBase/ModuleBase_WidgetOptionalBox.cpp b/src/ModuleBase/ModuleBase_WidgetOptionalBox.cpp
new file mode 100755 (executable)
index 0000000..b2e6ad5
--- /dev/null
@@ -0,0 +1,241 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:        ModuleBase_WidgetOptionalBox.cpp
+// Created:     13 Dec 2015
+// Author:      Natalia ERMOLAEVA
+
+#include <ModuleBase_WidgetOptionalBox.h>
+#include <ModelAPI_AttributeString.h>
+
+#include <Config_WidgetAPI.h>
+#include <Config_Keywords.h>
+
+#include <QWidget>
+#include <QGroupBox>
+#include <QCheckBox>
+#include <QGridLayout>
+#include <QVBoxLayout>
+
+#include <QList>
+
+ModuleBase_WidgetOptionalBox::ModuleBase_WidgetOptionalBox(QWidget* theParent,
+                                                               const Config_WidgetAPI* theData)
+: ModuleBase_ModelWidget(theParent, theData),
+  ModuleBase_PageBase(),
+  myOptionType(CheckBox),
+  myCheckBoxFrame(0),
+  myCheckBox(0),
+  myCheckBoxLayout(0),
+  myCheckBoxWidget(0),
+  myGroupBox(0),
+  myGroupBoxLayout(0)
+{
+  myToolTip = theData->widgetTooltip();
+  myGroupTitle = theData->getProperty(CONTAINER_PAGE_NAME);
+
+  bool isChecked = theData->getBooleanAttribute(ATTR_DEFAULT, false);
+  setDefaultValue(isChecked ? "true" : "false");
+
+  myMainLayout = new QVBoxLayout(this);
+  ModuleBase_Tools::adjustMargins(myMainLayout);
+}
+
+ModuleBase_WidgetOptionalBox::~ModuleBase_WidgetOptionalBox()
+{
+}
+
+QWidget* ModuleBase_WidgetOptionalBox::pageWidget()
+{
+  return myOptionType == GroupBox ? myGroupBox : (QWidget*)myCheckBoxFrame;
+}
+
+QList<QWidget*> ModuleBase_WidgetOptionalBox::getControls() const
+{
+  QList<QWidget*> aControls;
+  if (myOptionType == GroupBox)
+    aControls.append(myGroupBox);
+  else
+    aControls.append(myCheckBoxFrame);
+
+  return aControls;
+}
+
+void ModuleBase_WidgetOptionalBox::onPageClicked()
+{
+  storeValue();
+  updateControlsVisibility();
+
+  if (!isEditingMode())
+    emit focusOutWidget(this);
+}
+
+void ModuleBase_WidgetOptionalBox::addPageStretch()
+{
+}
+
+void ModuleBase_WidgetOptionalBox::placeModelWidget(ModuleBase_ModelWidget* theWidget)
+{
+  if(!isCheckBoxFilled() && myOptionType == CheckBox) {
+    createControl(CheckBox);
+    setOptionType(CheckBox);
+
+    myCheckBoxWidget = theWidget; /// check box frame becomes filled
+    myCheckBoxLayout->addWidget(theWidget);
+  }
+  else {
+    createControl(GroupBox);
+    setOptionType(GroupBox);
+
+    ModuleBase_ModelWidget* aCheckBoxWidget = myCheckBoxWidget;
+    myCheckBoxWidget = 0;
+    if (aCheckBoxWidget) // move the model widget from check box frame to group box frame
+      placeModelWidget(aCheckBoxWidget);
+
+    const int kCol = 0;
+    const int kRow = myGroupBoxLayout->count();
+    // it seems, that the align on left is not necessary here, but leads to widgets, which are
+    // not extended on full width of the parent page. The case is grouped widgets in
+    // the sketch translation operation
+    myGroupBoxLayout->addWidget(theWidget, kRow, kCol, Qt::AlignTop);// | Qt::AlignLeft);
+    myGroupBoxLayout->setRowStretch(kRow, 0);
+  }
+}
+
+void ModuleBase_WidgetOptionalBox::placeWidget(QWidget* theWidget)
+{
+  createControl(GroupBox);
+  setOptionType(GroupBox);
+  if (isCheckBoxFilled())
+    placeModelWidget(myCheckBoxWidget);
+
+
+  if (!theWidget) {
+#ifdef _DEBUG
+    std::cout << "ModuleBase_PageGroupBox::placePageWidget: can not cast page" << std::endl;
+#endif
+    return;
+  }
+  const int kCol = 0;
+  const int kRow = myGroupBoxLayout->count();
+  myGroupBoxLayout->addWidget(theWidget, kRow, kCol);
+  myGroupBoxLayout->setRowStretch(kRow, 0);
+}
+
+QLayout* ModuleBase_WidgetOptionalBox::pageLayout()
+{
+  return myOptionType == GroupBox ? myGroupBoxLayout : (QLayout*)myCheckBoxLayout;
+}
+
+void ModuleBase_WidgetOptionalBox::createControl(const OptionType& theType)
+{
+  if (theType == GroupBox && !myGroupBox) {
+    // group box: more than one model widget is inside
+    myGroupBox = new QGroupBox(this);
+    myGroupBox->setTitle(QString::fromStdString(myGroupTitle));
+    myGroupBox->setVisible(false);
+    myGroupBox->setCheckable(true);
+    myGroupBox->setChecked(getDefaultValue() == "true");
+    myGroupBox->setToolTip(QString::fromStdString(myToolTip));
+
+    myGroupBoxLayout = new QGridLayout(myGroupBox);
+    ModuleBase_Tools::zeroMargins(myGroupBoxLayout);
+    myGroupBox->setLayout(myGroupBoxLayout);
+
+    // default vertical size policy is preferred
+    myMainLayout->addWidget(myGroupBox);
+    connect(myGroupBox, SIGNAL(clicked(bool)), this, SLOT(onPageClicked()));
+  }
+  else if (theType == CheckBox && !myCheckBoxFrame) {
+    myCheckBoxFrame = new QFrame(this);
+    myMainLayout->addWidget(myCheckBoxFrame);
+
+    myCheckBoxLayout = new QHBoxLayout(myCheckBoxFrame);
+    ModuleBase_Tools::adjustMargins(myCheckBoxLayout);
+    myCheckBox = new QCheckBox(myCheckBoxFrame);
+    myCheckBox->setChecked(getDefaultValue() == "true");
+    myCheckBoxLayout->addWidget(myCheckBox);
+
+    connect(myCheckBox, SIGNAL(clicked(bool)), this, SLOT(onPageClicked()));
+  }
+}
+
+bool ModuleBase_WidgetOptionalBox::storeValueCustom()
+{
+  DataPtr aData = myFeature->data();
+  AttributeStringPtr aStringAttr = aData->string(attributeID());
+  aStringAttr->setValue(getCurrentValue() ? attributeID() : "");
+
+  updateObject(myFeature);
+
+  return true;
+}
+
+bool ModuleBase_WidgetOptionalBox::restoreValueCustom()
+{
+  DataPtr aData = myFeature->data();
+  AttributeStringPtr aStringAttr = aData->string(attributeID());
+  setCurrentValue(!aStringAttr->value().empty());
+
+  return true;
+}
+
+void ModuleBase_WidgetOptionalBox::setOptionType(
+                         const ModuleBase_WidgetOptionalBox::OptionType& theType)
+{
+  myOptionType = theType;
+
+  bool isGroupBox = myOptionType == GroupBox;
+  if (myCheckBoxFrame)
+    myCheckBoxFrame->setVisible(!isGroupBox);
+  if (myGroupBox)
+    myGroupBox->setVisible(isGroupBox);
+}
+
+bool ModuleBase_WidgetOptionalBox::isCheckBoxFilled() const
+{
+  return myCheckBoxWidget != 0;
+}
+
+bool ModuleBase_WidgetOptionalBox::getCurrentValue() const
+{
+  bool isGroupBox = myOptionType == GroupBox;
+  return isGroupBox ? myGroupBox->isChecked() : myCheckBox->isChecked();
+}
+
+void ModuleBase_WidgetOptionalBox::setCurrentValue(const bool& theValue)
+{
+  bool isGroupBox = myOptionType == GroupBox;
+  if (isGroupBox) {
+    bool isBlocked = myGroupBox->blockSignals(true);
+    myGroupBox->setChecked(theValue);
+    myGroupBox->blockSignals(isBlocked);
+  }
+  else {
+    bool isBlocked = myCheckBox->blockSignals(true);
+    myCheckBox->setChecked(theValue);
+    myCheckBox->blockSignals(isBlocked);
+  }
+  updateControlsVisibility();
+}
+
+void ModuleBase_WidgetOptionalBox::updateControlsVisibility()
+{
+  if (myOptionType == GroupBox) {
+    bool aChecked = myGroupBox->isChecked();
+    if (aChecked)
+      ModuleBase_Tools::zeroMargins(myGroupBoxLayout);
+    else
+      ModuleBase_Tools::adjustMargins(myGroupBoxLayout);
+
+    int aNbSubControls = myGroupBoxLayout->count();
+    for (int i = 0; i < aNbSubControls; i++) {
+      QWidget* aWidget = myGroupBoxLayout->itemAt(i)->widget();
+      if (aWidget)
+        aWidget->setVisible(aChecked);
+    }
+  }
+  else {
+    bool aChecked = myCheckBox->isChecked();
+    myCheckBoxWidget->setEnabled(aChecked);
+  }
+}
diff --git a/src/ModuleBase/ModuleBase_WidgetOptionalBox.h b/src/ModuleBase/ModuleBase_WidgetOptionalBox.h
new file mode 100755 (executable)
index 0000000..63027a9
--- /dev/null
@@ -0,0 +1,118 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:        ModuleBase_WidgetOptionalBox.h
+// Created:     13 Dec 2015
+// Author:      Natalia ERMOLAEVA
+
+#ifndef ModuleBase_WidgetOptionalBox_H_
+#define ModuleBase_WidgetOptionalBox_H_
+
+#include <ModuleBase.h>
+#include <ModuleBase_PageBase.h>
+#include <ModuleBase_ModelWidget.h>
+
+class QGroupBox;
+class QFrame;
+class QCheckBox;
+class QVBoxLayout;
+class QHBoxLayout;
+class QGridLayout;
+
+/**
+* \ingroup GUI
+* Implements a model widget for switch as a container widget. It can be defined in XML with "toolbox" keyword
+*/
+class MODULEBASE_EXPORT ModuleBase_WidgetOptionalBox : public ModuleBase_ModelWidget,
+                                                         public ModuleBase_PageBase
+{
+  Q_OBJECT
+
+  enum OptionType {CheckBox, GroupBox};
+public:
+  /// Constructor
+  /// \param theParent the parent object
+  /// \param theData the widget configuration. The attribute of the model widget is obtained from
+  ModuleBase_WidgetOptionalBox(QWidget* theParent, const Config_WidgetAPI* theData);
+  virtual ~ModuleBase_WidgetOptionalBox();
+
+  /// Defines if it is supported to set the value in this widget
+  /// \return false because this is an info widget
+  virtual bool canAcceptFocus() const { return false; };
+
+  /// Methods to be redefined from ModuleBase_PageBase: start
+  /// Cast the page to regular QWidget
+  virtual QWidget* pageWidget();
+  /// Methods to be redefined from ModuleBase_PageBase: end
+
+  /// Methods to be redefined from ModuleBase_ModelWidget: start
+  /// Returns list of widget controls
+  /// \return a control list
+  virtual QList<QWidget*> getControls() const;
+  /// Methods to be redefined from ModuleBase_ModelWidget: end
+
+protected slots:
+  // store value to the model
+  void onPageClicked();
+
+protected:
+  /// Methods to be redefined from ModuleBase_PageBase: start
+  /// Adds the given widget to page's layout
+  virtual void placeModelWidget(ModuleBase_ModelWidget* theWidget);
+  /// Adds the given page to page's layout
+  virtual void placeWidget(QWidget* theWidget);
+  /// Returns page's layout (QGridLayout)
+  virtual QLayout* pageLayout();
+  /// Adds a stretch to page's layout
+  virtual void addPageStretch();
+  /// Methods to be redefined from ModuleBase_PageBase: end
+
+
+  /// Methods to be redefined from ModuleBase_ModelWidget: start
+  /// Saves the internal parameters to the given feature
+  /// \return True in success
+  virtual bool storeValueCustom();
+  /// Restore value from attribute data to the widget's control
+  virtual bool restoreValueCustom();
+  /// Methods to be redefined from ModuleBase_ModelWidget: end
+
+private:
+  /// Sets whether Check box or Group box is used currently
+  /// \param theType a type of the control
+  void setOptionType(const OptionType& theType);
+
+  /// Returns true if the model widget is set into the check box frame
+  /// \return boolean value
+  bool isCheckBoxFilled() const;
+
+  /// Creates controls for the given type if it was not perfomed yet
+  /// \param theType a type to create whether check box or group box controls
+  void createControl(const OptionType& theType);
+
+  /// Returns true if control is checked
+  /// \return boolean value
+  bool getCurrentValue() const;
+
+  /// Returns true if control is checked
+  /// \param theValue a new value to fill the control state
+  void setCurrentValue(const bool& theValue);
+
+  /// Makes model widget controls either disabled(for check box mode) or hidden(for group box mode)
+  void updateControlsVisibility();
+
+private:
+  std::string myToolTip; ///< tool tip defined in XML
+  std::string myGroupTitle; ///< a title for group box
+
+  OptionType myOptionType; ///< current option state
+  QVBoxLayout* myMainLayout; ///< the main layout
+  // controls to fill check box frame
+  QFrame* myCheckBoxFrame; ///< frame with check box, to be hidden when group box is used
+  QCheckBox* myCheckBox; ///< control used if only one model widget is placed inside
+  QHBoxLayout* myCheckBoxLayout; ///< layout of check box frame
+  ModuleBase_ModelWidget* myCheckBoxWidget; /// model widget, placed in the check box frame
+  // controls to fill group box frame
+  QGroupBox* myGroupBox; ///< control used if more than model widget is placed inside
+  QGridLayout* myGroupBoxLayout; ///< page's layout
+};
+
+#endif /* ModuleBase_WidgetOptionalBox_H_ */