X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_ErrorMgr.cpp;h=afacb5d82e77cb29e1212b3a39dda5e9bdd88961;hb=59a007784d1e103bcb352c515eb6feafa170f1ff;hp=190f9c1ed303ea9c7d6885beb8466f054c47593f;hpb=92b6738b4a67f24c626b106e2bcf7651577ff2bc;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_ErrorMgr.cpp b/src/XGUI/XGUI_ErrorMgr.cpp index 190f9c1ed..afacb5d82 100644 --- a/src/XGUI/XGUI_ErrorMgr.cpp +++ b/src/XGUI/XGUI_ErrorMgr.cpp @@ -7,8 +7,13 @@ #include "XGUI_ErrorMgr.h" #include "XGUI_OperationMgr.h" +#include "XGUI_ModuleConnector.h" +#include "XGUI_Workshop.h" +#include "XGUI_ActionsMgr.h" #include +#include +#include #include #include @@ -28,10 +33,11 @@ const QString INVALID_VALUE = "invalid_action"; -XGUI_ErrorMgr::XGUI_ErrorMgr(QObject* theParent /*= 0*/) +XGUI_ErrorMgr::XGUI_ErrorMgr(QObject* theParent, ModuleBase_IWorkshop* theWorkshop) : ModuleBase_IErrorMgr(theParent), myErrorDialog(0), - myErrorLabel(0) + myErrorLabel(0), + myWorkshop(theWorkshop) { } @@ -41,131 +47,71 @@ XGUI_ErrorMgr::~XGUI_ErrorMgr() } -bool XGUI_ErrorMgr::canProcessClick(QAction* theAction, const FeaturePtr& theFeature) +void XGUI_ErrorMgr::updateActions(const FeaturePtr& theFeature) { - QString aData = theAction->data().toString(); - - bool isActionEnabled = theAction->data() != INVALID_VALUE; - - QString anError = getFeatureError(theFeature); - if (!isActionEnabled && !anError.isEmpty()) { - if (!myErrorDialog) { - myErrorDialog = new QDialog(QApplication::desktop(), Qt::Popup); - QHBoxLayout* aLay = new QHBoxLayout(myErrorDialog); - aLay->setContentsMargins(0, 0, 0, 0); - - QFrame* aMarginWidget = new QFrame(myErrorDialog); - aMarginWidget->setFrameStyle(QFrame::Panel | QFrame::Raised); - - aLay->addWidget(aMarginWidget); - QHBoxLayout* aMarginLay = new QHBoxLayout(aMarginWidget); - aMarginLay->setContentsMargins(4, 4, 4, 4); - - myErrorLabel = new QLabel(aMarginWidget); - aMarginLay->addWidget(myErrorLabel); - } - myErrorLabel->setText(anError); - myErrorDialog->move(QCursor::pos()); - myErrorDialog->show(); + //update Ok Action and header of property panel if the current operation started for the feature + XGUI_ActionsMgr* anActionsMgr = workshop()->actionsMgr(); + 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); + updateToolTip(anActiveWidget, aWidgetError); } - return isActionEnabled; } -void XGUI_ErrorMgr::updateActionState(QAction* theAction, const FeaturePtr& theFeature, - const bool theEnabled) +void XGUI_ErrorMgr::updateAcceptAllAction(const FeaturePtr& theFeature) { - bool isActionEnabled = theAction->data() != INVALID_VALUE; - if (theEnabled == isActionEnabled) - return; - - theAction->setIcon(theEnabled ? QIcon(":pictures/button_ok.png"): QIcon(":pictures/button_ok_error.png")); - QWidget* aWidget = myPropertyPanel->headerWidget(); - if (theEnabled) { - theAction->setData(""); - aWidget->setToolTip(""); - } - else { - theAction->setData(INVALID_VALUE); - aWidget->setToolTip(getFeatureError(theFeature)); + QString anError = myWorkshop->module()->getFeatureError(theFeature); + if (anError.isEmpty()) + anError = myWorkshop->module()->getWidgetError(activeWidget()); + + XGUI_ActionsMgr* anActionsMgr = workshop()->actionsMgr(); + if (workshop()->isFeatureOfNested(theFeature)) { + QAction* anAcceptAllAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll, NULL); + bool anEnabled = anError.isEmpty(); + anAcceptAllAction->setEnabled(anEnabled); + anAcceptAllAction->setToolTip(anError); } } -const char* toString(ModelAPI_ExecState theExecState) +void XGUI_ErrorMgr::updateActionState(QAction* theAction, const QString& theError) { -#define TO_STRING(__NAME__) case __NAME__: return #__NAME__; - switch (theExecState) { - TO_STRING(ModelAPI_StateDone) - TO_STRING(ModelAPI_StateMustBeUpdated) - TO_STRING(ModelAPI_StateExecFailed) - TO_STRING(ModelAPI_StateInvalidArgument) - TO_STRING(ModelAPI_StateNothing) - default: return "Unknown ExecState."; + bool anEnabled = theError.isEmpty(); + + theAction->setEnabled(anEnabled); + // some operations have no property panel, so it is important to check that it is not null + if (myPropertyPanel) { + // update controls error information + QWidget* aWidget = myPropertyPanel->headerWidget(); + if (aWidget) + aWidget->setToolTip(theError); } -#undef TO_STRING } - -/*void XGUI_ErrorMgr::onValidationStateChanged() -{ - XGUI_OperationMgr* anOperationMgr = dynamic_cast(sender()); - if (!anOperationMgr) - return; - ModuleBase_OperationFeature* aFOperation = dynamic_cast - (anOperationMgr->currentOperation()); - if (!myPropertyPanel || !aFOperation) - return; - - FeaturePtr aFeature = aFOperation->feature(); - QString anError = getFeatureError(aFeature); - - QWidget* aWidget = myPropertyPanel->headerWidget(); - if (aWidget) { - aWidget->setToolTip(anError); - aWidget->setStyleSheet(anError.isEmpty() ? "" : "background-color:pink;"); - } -}*/ - -QString XGUI_ErrorMgr::getFeatureError(const FeaturePtr& theFeature) const -{ - QString anError; - // get feature - if (!theFeature.get() || !theFeature->data()->isValid()) - return anError; - - // set error indication - anError = QString::fromStdString(theFeature->error()); - if (anError.isEmpty()) { - bool isDone = ( theFeature->data()->execState() == ModelAPI_StateDone - || theFeature->data()->execState() == ModelAPI_StateMustBeUpdated ); - if (!isDone) - anError = toString(theFeature->data()->execState()); - } - - return anError; -} - void XGUI_ErrorMgr::onWidgetChanged() { - static ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators(); - ModuleBase_ModelWidget* aModelWidget = dynamic_cast(sender()); if (!aModelWidget || !aModelWidget->feature().get()) return; - std::string anAttributeID = aModelWidget->attributeID(); - AttributePtr anAttribute = aModelWidget->feature()->attribute(anAttributeID); - if (!anAttribute.get()) - return; + QString aWidgetError = myWorkshop->module()->getWidgetError(aModelWidget); + updateToolTip(aModelWidget, aWidgetError); +} - std::string aValidatorID; - std::string anErrorMsg; - if (!aValidators->validate(anAttribute, aValidatorID, anErrorMsg)) { - if (anErrorMsg.empty()) - anErrorMsg = "unknown error."; - anErrorMsg = anAttributeID + " - " + aValidatorID + ": " + anErrorMsg; - } +void XGUI_ErrorMgr::updateToolTip(ModuleBase_ModelWidget* theWidget, + const QString& theError) +{ + if (!theWidget) + return; - QString anError = QString::fromStdString(anErrorMsg); - QList aWidgetList = aModelWidget->getControls(); + QList aWidgetList = theWidget->getControls(); foreach(QWidget* aWidget, aWidgetList) { QLabel* aLabel = qobject_cast(aWidget); // We won't set the effect to QLabels - it looks ugly @@ -174,12 +120,34 @@ void XGUI_ErrorMgr::onWidgetChanged() // Get the original tool tip of the widget QString aTTip = aWidget->toolTip().section("Errors:\n", 0, 0).trimmed(); // Add the error message into the tool tip - if (!anError.isEmpty()) { + if (!theError.isEmpty()) { if (!aTTip.isEmpty()) aTTip.append('\n'); - aTTip += "Errors:\n" + anError; + aTTip += "Errors:\n" + theError; } aWidget->setToolTip(aTTip); //aWidget->setStyleSheet(anError.isEmpty() ? "" : "background-color:pink;"); } } + +XGUI_Workshop* XGUI_ErrorMgr::workshop() const +{ + XGUI_ModuleConnector* aConnector = dynamic_cast(myWorkshop); + return aConnector->workshop(); +} + +ModuleBase_ModelWidget* XGUI_ErrorMgr::activeWidget() const +{ + ModuleBase_ModelWidget* anActiveWidget = 0; + + ModuleBase_OperationFeature* aFOperation = dynamic_cast + (workshop()->operationMgr()->currentOperation()); + if (aFOperation) { + ModuleBase_IPropertyPanel* aPropertyPanel = aFOperation->propertyPanel(); + if (aPropertyPanel) { + anActiveWidget = aPropertyPanel->activeWidget(); + } + } + return anActiveWidget; +} +