Salome HOME
Switch and Toolbox refactored: common methods are extracted into base class
authorsbh <sergey.belash@opencascade.com>
Fri, 13 Mar 2015 16:06:25 +0000 (19:06 +0300)
committersbh <sergey.belash@opencascade.com>
Fri, 13 Mar 2015 16:06:25 +0000 (19:06 +0300)
src/ConstructionPlugin/plane_widget.xml
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_PagedContainer.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_PagedContainer.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetFactory.cpp
src/ModuleBase/ModuleBase_WidgetSwitch.cpp
src/ModuleBase/ModuleBase_WidgetSwitch.h
src/ModuleBase/ModuleBase_WidgetToolbox.cpp
src/ModuleBase/ModuleBase_WidgetToolbox.h

index 492bffad028d5e870085e4d8d86b237c9410c098..7600c1b19808c6db8f505ea22b511053d1bf114d 100644 (file)
@@ -1,23 +1,20 @@
 <!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
 
 <source>
-  <!-- 
   <switch id="CreationMethod">
-    <case id="PlaneByFaceAndDistance">
-   -->
-  <shape_selector id="planeFace"
-                  label="Plane face"
-                  tooltip="Select a planar face"
-                  shape_types="face">
-    <selection_filter id="FaceFilter" parameters="plane"/>
-  </shape_selector>
-  <doublevalue id="distance" 
-               label="Distance" 
-               tooltip="Distance from selected face to plane" 
+    <case id="PlaneByFaceAndDistance" title="On some distance from a face">
+      <shape_selector id="planeFace"
+                      label="Plane face"
+                      tooltip="Select a planar face"
+                      shape_types="face">
+        <selection_filter id="FaceFilter" parameters="plane"/>
+      </shape_selector>
+      <doublevalue id="distance" 
+                   label="Distance" 
+                   tooltip="Distance from selected face to plane" 
                default="0" />
-<!-- 
     </case>
-    <case id="PlaneByGeneralEquation">
+    <case id="PlaneByGeneralEquation" title="By palne equation parameters">
       <doublevalue id="A" 
                    label="A:" 
                    tooltip="The A parameter from general plane equation (Ax+By+Cz+D=0)" 
@@ -36,5 +33,4 @@
                    default="0" />
     </case>
   </switch>
- -->
 </source>
index 9b834e9ad5e7c9d02f0c6e6344c90e2c5117db9a..cf2020c1201b461db91435e0f5c99151e2bcb54b 100644 (file)
@@ -23,7 +23,6 @@ SET(PROJECT_HEADERS
        ModuleBase_WidgetDoubleValue.h
        ModuleBase_WidgetEditor.h
        ModuleBase_WidgetFactory.h
-       ModuleBase_WidgetSwitch.h
        ModuleBase_WidgetShapeSelector.h
        ModuleBase_IWorkshop.h
        ModuleBase_Definitions.h
@@ -44,10 +43,12 @@ SET(PROJECT_HEADERS
        ModuleBase_IPrefMgr.h
        ModuleBase_Preferences.h
        ModuleBase_ActionInfo.h
-       ModuleBase_WidgetToolbox.h
        ModuleBase_PageBase.h
        ModuleBase_PageWidget.h 
        ModuleBase_PageGroupBox.h
+       ModuleBase_PagedContainer.h
+       ModuleBase_WidgetSwitch.h
+       ModuleBase_WidgetToolbox.h
        ModuleBase_WidgetValidated.h
 )
 
@@ -71,7 +72,6 @@ SET(PROJECT_SOURCES
        ModuleBase_WidgetDoubleValue.cpp
        ModuleBase_WidgetEditor.cpp
        ModuleBase_WidgetFactory.cpp
-       ModuleBase_WidgetSwitch.cpp
        ModuleBase_WidgetShapeSelector.cpp
        ModuleBase_WidgetChoice.cpp
        ModuleBase_WidgetFileSelector.cpp
@@ -83,10 +83,12 @@ SET(PROJECT_SOURCES
        ModuleBase_WidgetLabel.cpp
        ModuleBase_Preferences.cpp
        ModuleBase_ActionInfo.cpp
-       ModuleBase_WidgetToolbox.cpp
        ModuleBase_PageBase.cpp
        ModuleBase_PageWidget.cpp
        ModuleBase_PageGroupBox.cpp
+       ModuleBase_PagedContainer.cpp
+       ModuleBase_WidgetSwitch.cpp
+       ModuleBase_WidgetToolbox.cpp
        ModuleBase_WidgetValidated.cpp
 )
 
diff --git a/src/ModuleBase/ModuleBase_PagedContainer.cpp b/src/ModuleBase/ModuleBase_PagedContainer.cpp
new file mode 100644 (file)
index 0000000..d067e10
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * ModuleBase_PagedContainer.cpp
+ *
+ *  Created on: Mar 13, 2015
+ *      Author: sbh
+ */
+
+#include <ModuleBase_PagedContainer.h>
+#include <ModuleBase_PageBase.h>
+#include <ModuleBase_ModelWidget.h>
+#include <ModuleBase_Tools.h>
+
+#include <ModelAPI_AttributeString.h>
+
+#include <QWidget>
+#include <Qlist>
+#include <QVBoxLayout>
+
+
+ModuleBase_PagedContainer::ModuleBase_PagedContainer(QWidget* theParent, const Config_WidgetAPI* theData,
+                                                     const std::string& theParentId)
+: ModuleBase_ModelWidget(theParent, theData, theParentId),
+  myIsFocusOnCurrentPage(false)
+{
+}
+
+ModuleBase_PagedContainer::~ModuleBase_PagedContainer()
+{
+}
+
+int ModuleBase_PagedContainer::addPage(ModuleBase_PageBase* thePage,
+                                      const QString& theName, const QString& theCaseId)
+{
+  myCaseIds << theCaseId;
+  myPages << thePage;
+  return myPages.count();
+}
+
+QList<QWidget*> ModuleBase_PagedContainer::getControls() const
+{
+  QList<QWidget*> aResult;
+  int anIndex = currentPageIndex();
+  QList<ModuleBase_ModelWidget*> aModelWidgets = myPages[anIndex]->modelWidgets();
+  foreach(ModuleBase_ModelWidget* eachModelWidget, aModelWidgets) {
+    aResult << eachModelWidget->getControls();
+  }
+  return aResult;
+}
+
+bool ModuleBase_PagedContainer::focusTo()
+{
+  int anIndex = currentPageIndex();
+  if (anIndex > myPages.count())
+    return false;
+  return myPages[anIndex]->takeFocus();
+}
+
+void ModuleBase_PagedContainer::setHighlighted(bool)
+{
+  //page containers should not be highlighted, do nothing
+}
+
+void ModuleBase_PagedContainer::enableFocusProcessing()
+{
+  myIsFocusOnCurrentPage = true;
+}
+
+bool ModuleBase_PagedContainer::restoreValue()
+{
+  // A rare case when plugin was not loaded.
+  if(!myFeature)
+    return false;
+  DataPtr aData = myFeature->data();
+  AttributeStringPtr aStringAttr = aData->string(attributeID());
+  QString aCaseId = QString::fromStdString(aStringAttr->value());
+  int idx = myCaseIds.indexOf(aCaseId);
+  if (idx == -1)
+    return false;
+  setCurrentPageIndex(idx);
+  return true;
+}
+
+void ModuleBase_PagedContainer::activateCustom()
+{
+  // activate current page
+  focusTo();
+}
+
+bool ModuleBase_PagedContainer::storeValueCustom() const
+{
+  // A rare case when plugin was not loaded.
+  if(!myFeature)
+    return false;
+  DataPtr aData = myFeature->data();
+  AttributeStringPtr aStringAttr = aData->string(attributeID());
+  QString aWidgetValue = myCaseIds.at(currentPageIndex());
+  aStringAttr->setValue(aWidgetValue.toStdString());
+  return true;
+}
+
+
+void ModuleBase_PagedContainer::onPageChanged()
+{
+  storeValue();
+  if (myIsFocusOnCurrentPage) focusTo();
+}
+
+
diff --git a/src/ModuleBase/ModuleBase_PagedContainer.h b/src/ModuleBase/ModuleBase_PagedContainer.h
new file mode 100644 (file)
index 0000000..d0677d3
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * ModuleBase_PagedContainer.h
+ *
+ *  Created on: Mar 13, 2015
+ *      Author: sbh
+ */
+
+#ifndef MODULEBASE_PAGEDCONTAINER_H_
+#define MODULEBASE_PAGEDCONTAINER_H_
+
+#include <ModuleBase.h>
+#include <ModuleBase_ModelWidget.h>
+
+class ModuleBase_PageBase;
+
+class MODULEBASE_EXPORT ModuleBase_PagedContainer : public ModuleBase_ModelWidget
+{
+  Q_OBJECT
+ public:
+  ModuleBase_PagedContainer(QWidget* theParent, const Config_WidgetAPI* theData,
+                           const std::string& theParentId);
+  virtual ~ModuleBase_PagedContainer();
+
+  virtual int addPage(ModuleBase_PageBase* theWidget,
+                      const QString& theName, const QString& theCaseId);
+  // ModuleBase_ModelWidget
+  virtual QList<QWidget*> getControls() const;
+  virtual bool focusTo();
+  virtual void setHighlighted(bool isHighlighted);
+  virtual void enableFocusProcessing();
+  virtual bool restoreValue();
+
+ protected:
+  virtual int currentPageIndex() const = 0;
+  virtual void setCurrentPageIndex(int ) = 0;
+  // ModuleBase_ModelWidget
+  virtual void activateCustom();
+  virtual bool storeValueCustom() const;
+
+ protected slots:
+  void onPageChanged();
+
+ private:
+  bool myIsFocusOnCurrentPage;
+  QStringList myCaseIds;
+  QList<ModuleBase_PageBase*> myPages;
+
+};
+
+#endif /* MODULEBASE_PAGEDCONTAINER_H_ */
index 1731271aa941e79046335d8bc17245976d2cb71f..93c3e7271a86ea824de85398c0f4571bf0c8774a 100644 (file)
@@ -103,13 +103,9 @@ void ModuleBase_WidgetFactory::createWidget(ModuleBase_PageBase* thePage)
           QString aCaseId = qs(myWidgetApi->getProperty(_ID));
           ModuleBase_PageBase* aPage = new ModuleBase_PageWidget(aWidget);
           createWidget(aPage);
-          QWidget* aCasePageWidget = dynamic_cast<QWidget*>(aPage);
-          if (aWdgType == WDG_SWITCH) {
-            ModuleBase_WidgetSwitch* aSwitch = qobject_cast<ModuleBase_WidgetSwitch*>(aWidget);
-            aSwitch->addPage(aCasePageWidget, aPageName);
-          } else if (aWdgType == WDG_TOOLBOX) {
-            ModuleBase_WidgetToolbox* aToolbox = qobject_cast<ModuleBase_WidgetToolbox*>(aWidget);
-            aToolbox->addPage(aPage, aPageName, aCaseId);
+          if (aWdgType == WDG_SWITCH || aWdgType == WDG_TOOLBOX) {
+            ModuleBase_PagedContainer* aContainer = qobject_cast<ModuleBase_PagedContainer*>(aWidget);
+            aContainer->addPage(aPage, aPageName, aCaseId);
           }
         } while (myWidgetApi->toNextWidget());
       }
index aec77a6b99403faccf2023d2ce21d5c00184cada..8cd931574f11f63c76ce57bfc12a96b68f64d3f2 100644 (file)
 #include <ModuleBase_WidgetSwitch.h>
 #include <ModuleBase_ModelWidget.h>
 #include <ModuleBase_PageBase.h>
+#include <ModuleBase_Tools.h>
 
 #include <QComboBox>
-#include <QVBoxLayout>
+#include <QFrame>
 #include <QSpacerItem>
-
+#include <QStackedLayout>
+#include <QVBoxLayout>
 
 ModuleBase_WidgetSwitch::ModuleBase_WidgetSwitch(QWidget* theParent, const Config_WidgetAPI* theData,
                                                  const std::string& theParentId)
-: ModuleBase_ModelWidget(theParent, theData, theParentId)
+: ModuleBase_PagedContainer(theParent, theData, theParentId)
 {
-  myMainLay = new QVBoxLayout(this);
-  myMainLay->setContentsMargins(2, 4, 2, 2);
+  QVBoxLayout*  aMainLay = new QVBoxLayout(this);
+  //aMainLay->setContentsMargins(2, 4, 2, 2);
+  ModuleBase_Tools::adjustMargins(aMainLay);
   myCombo = new QComboBox(this);
   myCombo->hide();
-  myMainLay->addWidget(myCombo);
-  //this->setFrameShape(QFrame::StyledPanel);
-  connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setCurrentIndex(int)));
-  connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SIGNAL(currentPageChanged(int)));
+  myPagesLayout = new QStackedLayout(this);
+  aMainLay->addWidget(myCombo);
+  aMainLay->addLayout(myPagesLayout, 1);
+  setLayout(aMainLay);
 
+  connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onPageChanged()));
+  connect(myCombo, SIGNAL(activated(int)), myPagesLayout, SLOT(setCurrentIndex(int)));
 }
 
 ModuleBase_WidgetSwitch::~ModuleBase_WidgetSwitch()
 {
 }
 
-QList<QWidget*> ModuleBase_WidgetSwitch::getControls() const
-{
-  QList<QWidget*> aList;
-  aList << myCombo;
-  return aList;
-}
-
-int ModuleBase_WidgetSwitch::addPage(QWidget* theWidget, const QString& theName)
-{
-  return insertPage(count(), theWidget, theName);
-}
-
-int ModuleBase_WidgetSwitch::count() const
-{
-  return myCombo->count();
-}
-
-int ModuleBase_WidgetSwitch::currentIndex() const
-{
-  return myCombo->currentIndex();
-}
-
-QWidget* ModuleBase_WidgetSwitch::currentWidget() const
-{
-  int idx = currentIndex();
-  return myCases[idx];
-}
-
-int ModuleBase_WidgetSwitch::indexOf(QWidget* theWidget) const
-{
-  return myCases.indexOf(theWidget);
-}
 
-int ModuleBase_WidgetSwitch::insertPage(int theIndex, QWidget* theWidget, const QString& theName)
+int ModuleBase_WidgetSwitch::addPage(ModuleBase_PageBase* thePage, const QString& theName,
+                                                                   const QString& theCaseId)
 {
-  int index = theIndex < count() ? theIndex : count();
-  if (count() == 0)
+  int aSuperCount = ModuleBase_PagedContainer::addPage(thePage, theName, theCaseId);
+  myCombo->addItem(theName);
+  int aResultCount = myCombo->count();
+  if (aResultCount == 1)
     myCombo->show();
-  myCombo->insertItem(index, theName);
-  myCases.insert(index, theWidget);
-  myMainLay->addWidget(theWidget);
-  setCurrentIndex(theIndex);
-  return index;
+  QFrame* aFrame = dynamic_cast<QFrame*>(thePage);
+  aFrame->setFrameShape(QFrame::Box);
+  aFrame->setFrameStyle(QFrame::Sunken);
+  myPagesLayout->addWidget(aFrame);
+  return aResultCount;
 }
 
-bool ModuleBase_WidgetSwitch::isPageEnabled(int index) const
+int ModuleBase_WidgetSwitch::currentPageIndex() const
 {
-  return myCases[index]->isEnabled();
+  int aComboIndex = myCombo->currentIndex();
+  return aComboIndex;
 }
 
-QString ModuleBase_WidgetSwitch::pageText(int index) const
-{
-  return myCombo->itemText(index);
-}
-
-QString ModuleBase_WidgetSwitch::pageToolTip(int index) const
-{
-  return myCases[index]->toolTip();
-}
-
-void ModuleBase_WidgetSwitch::removePage(int index)
-{
-  myCombo->removeItem(index);
-  myCases.removeAt(index);
-  if (count() == 0) {
-    myCombo->hide();
-  }
-}
-
-void ModuleBase_WidgetSwitch::setPageEnabled(int index, bool enabled)
-{
-  myCases[index]->setEnabled(enabled);
-}
-
-void ModuleBase_WidgetSwitch::setPageName(int index, const QString& theName)
-{
-  myCombo->setItemText(index, theName);
-}
-
-void ModuleBase_WidgetSwitch::setPageToolTip(int index, const QString& toolTip)
-{
-  myCases[index]->setToolTip(toolTip);
-}
-
-void ModuleBase_WidgetSwitch::setCurrentIndex(int index)
-{
-  myCombo->setCurrentIndex(index);
-  refresh();
-}
 
-void ModuleBase_WidgetSwitch::refresh()
+void ModuleBase_WidgetSwitch::setCurrentPageIndex(int theIndex)
 {
-  foreach(QWidget* eachWidget, myCases)
-  {
-    eachWidget->setVisible(false);
-  }
-  if (currentIndex() >= myCases.count())
-    return;
-  myCases[currentIndex()]->setVisible(true);
+  bool isComboSignalsBlocked = myCombo->blockSignals(true);
+  bool isPagesLayoutSignalsBlocked = myPagesLayout->blockSignals(true);
+  myCombo->setCurrentIndex(theIndex);
+  myPagesLayout->setCurrentIndex(theIndex);
+  myCombo->blockSignals(isComboSignalsBlocked);
+  myPagesLayout->blockSignals(isPagesLayoutSignalsBlocked);
 }
index 1f10c2eead1072a7116d95eeaf2e156248d7a4d8..5772a3d0878dd2b03be3bf56c77cc83df163b4c8 100644 (file)
@@ -7,20 +7,20 @@
  *      Author: sbh
  */
 
-#ifndef ModuleBase_WidgetSwitch_H_
-#define ModuleBase_WidgetSwitch_H_
+#ifndef MODULEBASE_WIDGETSWITCH_H_
+#define MODULEBASE_WIDGETSWITCH_H_
 
 #include <ModuleBase.h>
-#include <ModuleBase_ModelWidget.h>
+#include <ModuleBase_PagedContainer.h>
 
 class QComboBox;
-class QVBoxLayout;
+class QStackedLayout;
 
 /**
 * \ingroup GUI
 * Implements a model widget for swithch as a container widget. It can be defined in XML with "switch" keyword
 */
-class MODULEBASE_EXPORT ModuleBase_WidgetSwitch : public ModuleBase_ModelWidget
+class MODULEBASE_EXPORT ModuleBase_WidgetSwitch : public ModuleBase_PagedContainer
 {
   Q_OBJECT
  public:
@@ -31,96 +31,22 @@ class MODULEBASE_EXPORT ModuleBase_WidgetSwitch : public ModuleBase_ModelWidget
                           const std::string& theParentId);
   virtual ~ModuleBase_WidgetSwitch();
 
-  virtual bool restoreValue() {
-    return false;
-  }
-
-  virtual QList<QWidget*> getControls() const;
-
-  virtual bool focusTo() {
-    return false;
-  }
-
   /// Add a page to the widget
   /// \param theWidget a page widget
   /// \param theName a name of page
-  int addPage(QWidget* theWidget, const QString & theName);
-
-  /// Returns count of pages
-  int count() const;
-
-  /// Returns index of current page
-  int currentIndex() const;
-
-  /// Returns current widget (page)
-  QWidget * currentWidget() const;
-
-  /// Returns index of widget (page)
-  /// \param theWidget a widget page
-  int indexOf(QWidget * theWidget) const;
-
-  /// Insert page
-  /// \param index an index (position) to insert 
-  /// \param theWidget a page widget
-  /// \param theName a name of the page
-  int insertPage(int index, QWidget * theWidget, const QString & theName);
-
-  /// Returns True if a page by given index is enabled
-  /// \param index index of the page
-  bool isPageEnabled(int index) const;
-
-  /// Returns text of the page by its id
-  /// \param index index of the page
-  QString pageText(int index) const;
-
-  /// Returns tooltip of the page by its id
-  /// \param index index of the page
-  QString pageToolTip(int index) const;
+  virtual int addPage(ModuleBase_PageBase* theWidget,
+                        const QString& theName, const QString& theCaseId);
 
-  /// Remove page by its id
-  /// \param index index of the page
-  void removePage(int index);
-
-  /// Enale/disable a page by its Id
-  /// \param index index of the page
-  /// \param enabled an enable flag
-  void setPageEnabled(int index, bool enabled);
-
-  /// Set page name
-  /// \param index index of the page
-  /// \param text a name of the page
-  void setPageName(int index, const QString & text);
-
-  /// Set page tooltip
-  /// \param index index of the page
-  /// \param toolTip a tooltip of the page
-  void setPageToolTip(int index, const QString & toolTip);
-
- public slots:
+ protected:
+  virtual int currentPageIndex() const;
    /// Set current page by index
   /// \param index index of the page
-  void setCurrentIndex(int index);
-
-signals:
-  /// Emitted on current page change
-  void currentPageChanged(int);
-
- protected:
-  virtual bool storeValueCustom() const {
-    return false;
-  }
-  /// Update widget
-  void refresh();
+  virtual void setCurrentPageIndex(int index);
 
  private:
-   /// Layout
-  QVBoxLayout* myMainLay;
-
   /// Combo box
   QComboBox* myCombo;
-
-  /// List of pages
-  QWidgetList myCases;
+  QStackedLayout* myPagesLayout;
 };
 
 #endif /* ModuleBase_WidgetSwitch_H_ */
index c2e816e8def7cc62560d8cfba373523c5ba29d2f..6a16aa3d2647d6d4057e6352971f686ad02e1a06 100644 (file)
 #include <ModelAPI_AttributeString.h>
 
 #include <QWidget>
-#include <Qlist>
+#include <QList>
 #include <QVBoxLayout>
 
 ModuleBase_WidgetToolbox::ModuleBase_WidgetToolbox(QWidget* theParent, const Config_WidgetAPI* theData,
                                                    const std::string& theParentId)
-: ModuleBase_ModelWidget(theParent, theData, theParentId),
-  myIsPassFocusToCurrentPage(false)
+: ModuleBase_PagedContainer(theParent, theData, theParentId)
 {
   QVBoxLayout* aMainLayout = new QVBoxLayout(this);
   ModuleBase_Tools::zeroMargins(aMainLayout);
@@ -44,81 +43,24 @@ ModuleBase_WidgetToolbox::~ModuleBase_WidgetToolbox()
 int ModuleBase_WidgetToolbox::addPage(ModuleBase_PageBase* thePage,
                                       const QString& theName, const QString& theCaseId)
 {
-  myCaseIds << theCaseId;
-  myPages << thePage;
+  ModuleBase_PagedContainer::addPage(thePage, theName, theCaseId);
   QFrame* aFrame = dynamic_cast<QFrame*>(thePage);
   aFrame->setFrameShape(QFrame::Box);
   aFrame->setFrameStyle(QFrame::Sunken);
-  return myToolBox->addItem(aFrame, theName);
+  myToolBox->addItem(aFrame, theName);
+  return myToolBox->count();
 }
 
-bool ModuleBase_WidgetToolbox::restoreValue()
+int ModuleBase_WidgetToolbox::currentPageIndex() const
 {
-  // A rare case when plugin was not loaded.
-  if(!myFeature)
-    return false;
-  DataPtr aData = myFeature->data();
-  AttributeStringPtr aStringAttr = aData->string(attributeID());
-  QString aCaseId = QString::fromStdString(aStringAttr->value());
-  int idx = myCaseIds.indexOf(aCaseId);
-  if (idx == -1)
-    return false;
-  bool isSignalsBlocked = myToolBox->blockSignals(true);
-  myToolBox->setCurrentIndex(idx);
-  myToolBox->blockSignals(isSignalsBlocked);
-  return true;
-}
-
-QList<QWidget*> ModuleBase_WidgetToolbox::getControls() const
-{
-  QList<QWidget*> aResult;
-  int idx = myToolBox->currentIndex();
-  QList<ModuleBase_ModelWidget*> aModelWidgets = myPages[idx]->modelWidgets();
-  foreach(ModuleBase_ModelWidget* eachModelWidget, aModelWidgets) {
-    aResult << eachModelWidget->getControls();
-  }
-  return aResult;
-}
-
-bool ModuleBase_WidgetToolbox::focusTo()
-{
-  int idx = myToolBox->currentIndex();
-  if (idx > myPages.count())
-    return false;
-  return myPages[idx]->takeFocus();
-}
-
-void ModuleBase_WidgetToolbox::setHighlighted(bool)
-{
-  //page containers sould not be highlighted, do nothing
+  return myToolBox->currentIndex();
 }
 
-void ModuleBase_WidgetToolbox::enableFocusProcessing()
+void ModuleBase_WidgetToolbox::setCurrentPageIndex(int theIndex)
 {
-  myIsPassFocusToCurrentPage = true;
-}
-
-
-void ModuleBase_WidgetToolbox::activateCustom()
-{
-  // activate current page
-  focusTo();
+  bool isSignalsBlocked = myToolBox->blockSignals(true);
+  myToolBox->setCurrentIndex(theIndex);
+  myToolBox->blockSignals(isSignalsBlocked);
 }
 
-bool ModuleBase_WidgetToolbox::storeValueCustom() const
-{
-  // A rare case when plugin was not loaded.
-  if(!myFeature)
-    return false;
-  DataPtr aData = myFeature->data();
-  AttributeStringPtr aStringAttr = aData->string(attributeID());
-  QString aWidgetValue = myCaseIds.at(myToolBox->currentIndex());
-  aStringAttr->setValue(aWidgetValue.toStdString());
-  return true;
-}
 
-void ModuleBase_WidgetToolbox::onPageChanged()
-{
-  storeValue();
-  if (myIsPassFocusToCurrentPage) focusTo();
-}
index 21ab5a2c28dd9a209fb40f2fe03be2b84fe15195..639e90f14da10fd57faa7e709d67af45d574207e 100644 (file)
@@ -8,41 +8,32 @@
 #ifndef MODULEBASE_WIDGETTOOLBOX_H_
 #define MODULEBASE_WIDGETTOOLBOX_H_
 
-#include <ModuleBase_ModelWidget.h>
+#include <ModuleBase.h>
+#include <ModuleBase_PagedContainer.h>
 
 #include <QToolBox>
 
 class ModuleBase_PageBase;
 
-class ModuleBase_WidgetToolbox : public ModuleBase_ModelWidget
+class MODULEBASE_EXPORT ModuleBase_WidgetToolbox : public ModuleBase_PagedContainer
 {
   Q_OBJECT
  public:
   ModuleBase_WidgetToolbox(QWidget* theParent, const Config_WidgetAPI* theData,
                            const std::string& theParentId);
   virtual ~ModuleBase_WidgetToolbox();
-
-  virtual bool restoreValue();
-  virtual QList<QWidget*> getControls() const;
-  virtual bool focusTo();
-  virtual void setHighlighted(bool isHighlighted);
-  virtual void enableFocusProcessing();
-
+  /// Overrides ModuleBase_PagedContainer
   int addPage(ModuleBase_PageBase* theWidget,
               const QString& theName, const QString& theCaseId);
 
  protected:
-  virtual void activateCustom();
-  virtual bool storeValueCustom() const;
-
- protected slots:
-  void onPageChanged();
+  /// Implements ModuleBase_PagedContainer
+  virtual int currentPageIndex() const;
+  /// Implements ModuleBase_PagedContainer
+  virtual void setCurrentPageIndex(int);
 
  private:
-  bool myIsPassFocusToCurrentPage;
   QToolBox* myToolBox;
-  QStringList myCaseIds;
-  QList<ModuleBase_PageBase*> myPages;
 };
 
 #endif /* MODULEBASE_WIDGETTOOLBOX_H_ */