X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FXGUI%2FXGUI_ErrorMgr.cpp;h=40ba050549eabf419e600ade300c4ef91c91286d;hb=c7d72b1e9c2bf38f8cb27f9251c7a332401dc2fe;hp=afacb5d82e77cb29e1212b3a39dda5e9bdd88961;hpb=868158fe6d39b25e60ac528295b1c908821e4af5;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_ErrorMgr.cpp b/src/XGUI/XGUI_ErrorMgr.cpp index afacb5d82..40ba05054 100644 --- a/src/XGUI/XGUI_ErrorMgr.cpp +++ b/src/XGUI/XGUI_ErrorMgr.cpp @@ -1,8 +1,21 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: XGUI_ErrorMgr.cpp -// Created: 22 July 2015 -// Author: Sergey POKHODENKO +// Copyright (C) 2014-2019 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 +// #include "XGUI_ErrorMgr.h" @@ -17,6 +30,9 @@ #include #include +#include +#include + #include #include #include @@ -32,19 +48,22 @@ const QString INVALID_VALUE = "invalid_action"; +//#define DEBUG_ERROR_STATE XGUI_ErrorMgr::XGUI_ErrorMgr(QObject* theParent, ModuleBase_IWorkshop* theWorkshop) : ModuleBase_IErrorMgr(theParent), myErrorDialog(0), myErrorLabel(0), - myWorkshop(theWorkshop) + myWorkshop(theWorkshop), + myAcceptAllToolTip(""), + myAcceptAllStatusTip(""), + myAcceptToolTip(""), + myAcceptStatusTip("") { - } XGUI_ErrorMgr::~XGUI_ErrorMgr() { - } void XGUI_ErrorMgr::updateActions(const FeaturePtr& theFeature) @@ -54,39 +73,103 @@ void XGUI_ErrorMgr::updateActions(const FeaturePtr& theFeature) ModuleBase_OperationFeature* aFOperation = dynamic_cast (workshop()->operationMgr()->currentOperation()); if (aFOperation && aFOperation->feature() == theFeature) { - QAction* anOkAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept); - QString anError = myWorkshop->module()->getFeatureError(theFeature); - ModuleBase_ModelWidget* anActiveWidget = activeWidget(); - QString aWidgetError = myWorkshop->module()->getWidgetError(anActiveWidget); - if (anError.isEmpty()) - anError = aWidgetError; - - updateActionState(anOkAction, anError); + bool isApplyEnabledByActiveWidget = false; + if (anActiveWidget) + isApplyEnabledByActiveWidget = anActiveWidget->getValueState() == + ModuleBase_ModelWidget::ModifiedInPP; + QString anError = ""; + QString aWidgetError = ""; + if (!isApplyEnabledByActiveWidget) { + anError = myWorkshop->module()->getFeatureError(theFeature); + if (anActiveWidget) + aWidgetError = anActiveWidget->getError(); + if (anError.isEmpty()) + anError = aWidgetError; + } + updateAcceptActionState(anError); updateToolTip(anActiveWidget, aWidgetError); + myWorkshop->setStatusBarMessage(anError); + +#ifdef DEBUG_ERROR_STATE + QString anInfo = ModuleBase_Tools::objectInfo(theFeature); + + QString aResultInfo = QString("valid = %1, anError = %2, aWidgetError = %3") + .arg(anError.isEmpty()).arg(anError).arg(aWidgetError); + qDebug(QString("XGUI_ErrorMgr::updateActions for %1, result: %2").arg(anInfo) + .arg(aResultInfo).toStdString().c_str()); +#endif } } void XGUI_ErrorMgr::updateAcceptAllAction(const FeaturePtr& theFeature) { - QString anError = myWorkshop->module()->getFeatureError(theFeature); - if (anError.isEmpty()) - anError = myWorkshop->module()->getWidgetError(activeWidget()); - + 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)) { - QAction* anAcceptAllAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll, NULL); + QAction* anAcceptAllAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll); bool anEnabled = anError.isEmpty(); anAcceptAllAction->setEnabled(anEnabled); - anAcceptAllAction->setToolTip(anError); + anAcceptAllAction->setToolTip(!anEnabled ? anError : myAcceptAllToolTip); + anAcceptAllAction->setStatusTip(!anEnabled ? anError : myAcceptAllStatusTip); } } -void XGUI_ErrorMgr::updateActionState(QAction* theAction, const QString& theError) +bool XGUI_ErrorMgr::isApplyEnabled() const { - bool anEnabled = theError.isEmpty(); + bool isEnabled = false; + XGUI_ActionsMgr* anActionsMgr = workshop()->actionsMgr(); + ModuleBase_OperationFeature* aFOperation = dynamic_cast + (workshop()->operationMgr()->currentOperation()); + if (aFOperation) { + QAction* anOkAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept); + isEnabled = anOkAction && anOkAction->isEnabled(); + } + 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(); - theAction->setEnabled(anEnabled); + 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); + + 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 if (myPropertyPanel) { // update controls error information @@ -101,7 +184,7 @@ void XGUI_ErrorMgr::onWidgetChanged() if (!aModelWidget || !aModelWidget->feature().get()) return; - QString aWidgetError = myWorkshop->module()->getWidgetError(aModelWidget); + QString aWidgetError = aModelWidget->getError(); updateToolTip(aModelWidget, aWidgetError); } @@ -118,12 +201,12 @@ void XGUI_ErrorMgr::updateToolTip(ModuleBase_ModelWidget* theWidget, if (aLabel) continue; // Get the original tool tip of the widget - QString aTTip = aWidget->toolTip().section("Errors:\n", 0, 0).trimmed(); + QString aTTip = aWidget->toolTip().section(tr("Errors:") + "\n", 0, 0).trimmed(); // Add the error message into the tool tip if (!theError.isEmpty()) { if (!aTTip.isEmpty()) aTTip.append('\n'); - aTTip += "Errors:\n" + theError; + aTTip += tr("Errors:") + "\n" + theError; } aWidget->setToolTip(aTTip); //aWidget->setStyleSheet(anError.isEmpty() ? "" : "background-color:pink;");