Salome HOME
Issue #2626: Do not use non-initialized attribute for default value definition
[modules/shaper.git] / src / XGUI / XGUI_ErrorMgr.cpp
index 84b2c90a595d8d8cfa7df8a6813b39d2405c9d05..19c1135b9c8c142986d787eba46b2bebee8c625e 100644 (file)
@@ -1,8 +1,22 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        XGUI_ErrorMgr.cpp
-// Created:     22 July 2015
-// Author:      Sergey POKHODENKO
+// 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 "XGUI_ErrorMgr.h"
 
@@ -41,17 +55,12 @@ XGUI_ErrorMgr::XGUI_ErrorMgr(QObject* theParent, ModuleBase_IWorkshop* theWorksh
   : ModuleBase_IErrorMgr(theParent),
     myErrorDialog(0),
     myErrorLabel(0),
-    myWorkshop(theWorkshop)
+    myWorkshop(theWorkshop),
+    myAcceptAllToolTip(""),
+    myAcceptAllStatusTip(""),
+    myAcceptToolTip(""),
+    myAcceptStatusTip("")
 {
-  ModuleBase_ModelWidget* anActiveWidget = activeWidget();
-  XGUI_ActionsMgr* anActionsMgr = workshop()->actionsMgr();
-  QAction* anAcceptAllAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll);
-  myAcceptAllToolTip = anAcceptAllAction->toolTip();
-  myAcceptAllStatusTip = anAcceptAllAction->statusTip();
-
-  QAction* anOkAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
-  myAcceptToolTip = anOkAction->toolTip();
-  myAcceptStatusTip = anOkAction->toolTip();
 }
 
 XGUI_ErrorMgr::~XGUI_ErrorMgr()
@@ -96,11 +105,20 @@ void XGUI_ErrorMgr::updateActions(const FeaturePtr& theFeature)
 
 void XGUI_ErrorMgr::updateAcceptAllAction(const FeaturePtr& theFeature)
 {
-  QString anError = myWorkshop->module()->getFeatureError(theFeature);
-  if (anError.isEmpty()) {
-    ModuleBase_ModelWidget* anActiveWidget = activeWidget();
-    if (anActiveWidget)
-      anError = anActiveWidget->getError();
+  if (myAcceptAllToolTip.isEmpty() && myAcceptToolTip.isEmpty())
+    storeInitialActionValues();
+
+  QString anError = "";
+  /// to allow the module have the button always enabled
+  bool isActionStateEnabled =
+    myWorkshop->module()->isActionEnableStateFixed(XGUI_ActionsMgr::AcceptAll);
+  if (!isActionStateEnabled) {
+    anError = myWorkshop->module()->getFeatureError(theFeature);
+    if (anError.isEmpty()) {
+      ModuleBase_ModelWidget* anActiveWidget = activeWidget();
+      if (anActiveWidget)
+        anError = anActiveWidget->getError();
+    }
   }
   XGUI_ActionsMgr* anActionsMgr = workshop()->actionsMgr();
   if (workshop()->isFeatureOfNested(theFeature)) {
@@ -125,14 +143,32 @@ bool XGUI_ErrorMgr::isApplyEnabled() const
   return isEnabled;
 }
 
+void XGUI_ErrorMgr::storeInitialActionValues()
+{
+  ModuleBase_ModelWidget* anActiveWidget = activeWidget();
+  XGUI_ActionsMgr* anActionsMgr = workshop()->actionsMgr();
+  QAction* anAcceptAllAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll);
+  myAcceptAllToolTip = anAcceptAllAction->toolTip();
+  myAcceptAllStatusTip = anAcceptAllAction->statusTip();
+
+  QAction* anOkAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
+  myAcceptToolTip = anOkAction->toolTip();
+  myAcceptStatusTip = anOkAction->toolTip();
+}
+
 void XGUI_ErrorMgr::updateAcceptActionState(const QString& theError)
 {
   XGUI_ActionsMgr* anActionsMgr = workshop()->actionsMgr();
   QAction* anAcceptAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
+  QAction* anAcceptPlusAction =
+    anActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptPlus);
 
-  bool anEnabled = theError.isEmpty();
+  if (myAcceptAllToolTip.isEmpty() && myAcceptToolTip.isEmpty())
+    storeInitialActionValues();
 
+  bool anEnabled = theError.isEmpty();
   anAcceptAction->setEnabled(anEnabled);
+  anAcceptPlusAction->setEnabled(anEnabled);
   anAcceptAction->setToolTip(anEnabled ? myAcceptToolTip : theError);
   anAcceptAction->setStatusTip(anEnabled ? myAcceptStatusTip : theError);
   // some operations have no property panel, so it is important to check that it is not null