Salome HOME
Issue #2079 : Select parent feature for default Constructions. Disable popup menu...
[modules/shaper.git] / src / ModuleBase / ModuleBase_PagedContainer.cpp
index d067e100c6132365785787373c2bdb665079a8c7..8723cbd778aad168f207e7025d1925b8f62c75bd 100644 (file)
@@ -1,3 +1,4 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
 /*
  * ModuleBase_PagedContainer.cpp
  *
 #include <ModelAPI_AttributeString.h>
 
 #include <QWidget>
-#include <Qlist>
+#include <QList>
 #include <QVBoxLayout>
 
 
-ModuleBase_PagedContainer::ModuleBase_PagedContainer(QWidget* theParent, const Config_WidgetAPI* theData,
-                                                     const std::string& theParentId)
-: ModuleBase_ModelWidget(theParent, theData, theParentId),
+ModuleBase_PagedContainer::ModuleBase_PagedContainer(QWidget* theParent,
+                                                     const Config_WidgetAPI* theData)
+: ModuleBase_ModelWidget(theParent, theData),
   myIsFocusOnCurrentPage(false)
 {
+  // it is not obligatory to be ignored when property panel tries to activate next active widget
+  // but if focus is moved to this control, it can accept it.
+  myIsObligatory = false;
 }
 
 ModuleBase_PagedContainer::~ModuleBase_PagedContainer()
@@ -29,10 +33,15 @@ ModuleBase_PagedContainer::~ModuleBase_PagedContainer()
 }
 
 int ModuleBase_PagedContainer::addPage(ModuleBase_PageBase* thePage,
-                                      const QString& theName, const QString& theCaseId)
+                                      const QString& theName, const QString& theCaseId,
+                                      const QPixmap& theIcon )
 {
+  if (!myPages.count()) {
+    setDefaultValue(theCaseId.toStdString());
+  }
   myCaseIds << theCaseId;
   myPages << thePage;
+
   return myPages.count();
 }
 
@@ -65,7 +74,7 @@ void ModuleBase_PagedContainer::enableFocusProcessing()
   myIsFocusOnCurrentPage = true;
 }
 
-bool ModuleBase_PagedContainer::restoreValue()
+bool ModuleBase_PagedContainer::restoreValueCustom()
 {
   // A rare case when plugin was not loaded.
   if(!myFeature)
@@ -86,7 +95,7 @@ void ModuleBase_PagedContainer::activateCustom()
   focusTo();
 }
 
-bool ModuleBase_PagedContainer::storeValueCustom() const
+bool ModuleBase_PagedContainer::storeValueCustom()
 {
   // A rare case when plugin was not loaded.
   if(!myFeature)
@@ -95,14 +104,20 @@ bool ModuleBase_PagedContainer::storeValueCustom() const
   AttributeStringPtr aStringAttr = aData->string(attributeID());
   QString aWidgetValue = myCaseIds.at(currentPageIndex());
   aStringAttr->setValue(aWidgetValue.toStdString());
+  updateObject(myFeature); // for preview
   return true;
 }
 
 
 void ModuleBase_PagedContainer::onPageChanged()
 {
-  storeValue();
-  if (myIsFocusOnCurrentPage) focusTo();
+  if (!storeValue())
+    return;
+  // focus might be changed only if the value is correcly stored
+  // if it is not stored, reentrant manager will handle by this widget
+  // after it will restart operation, the widget might be removed
+  if (myIsFocusOnCurrentPage)
+    focusTo();
 }