X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FModuleBase%2FModuleBase_ModelWidget.cpp;h=e0ac58445270badf66dd16681c699911c1f3f07d;hb=8c68ad2a530b1656e2ffa26ebdbc22f20482f361;hp=c84b8e6462063d7de4692decf84aea7ed3365414;hpb=a26b3aee26fc2761728ea778939800b9b02e2a61;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index c84b8e646..e0ac58445 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -5,11 +5,13 @@ // Author: Natalia ERMOLAEVA #include "ModuleBase_ModelWidget.h" +#include "ModuleBase_Tools.h" #include #include #include #include +#include #include #include @@ -17,19 +19,22 @@ #include #include -#include -#include #include #include +//#define DEBUG_VALUE_STATE + ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent, const Config_WidgetAPI* theData, const std::string& theParentId) : QWidget(theParent), myParentId(theParentId), myIsEditing(false), - myState(Stored) + myState(Stored), + myIsValueStateBlocked(false) { + myIsInternal = theData->getBooleanAttribute(ATTR_INTERNAL, false); + myDefaultValue = theData->getProperty(ATTR_DEFAULT); myUseReset = theData->getBooleanAttribute(ATTR_USE_RESET, true); myIsComputedDefault = theData->getProperty(ATTR_DEFAULT) == DOUBLE_WDG_DEFAULT_COMPUTED; @@ -54,17 +59,67 @@ bool ModuleBase_ModelWidget::isInitialized(ObjectPtr theObject) const return theObject->data()->attribute(attributeID())->isInitialized(); } +QString ModuleBase_ModelWidget::getValueStateError() const +{ + QString anError = ""; + + ModuleBase_ModelWidget::ValueState aState = getValueState(); + if (aState != ModuleBase_ModelWidget::Stored) { + AttributePtr anAttr = feature()->attribute(attributeID()); + if (anAttr.get()) { + QString anAttributeName = anAttr->id().c_str(); + switch (aState) { + case ModuleBase_ModelWidget::ModifiedInViewer: + anError = "Attribute \"" + anAttributeName + + "\" is locked by modification value in the viewer."; + break; + case ModuleBase_ModelWidget::Reset: + anError = "Attribute \"" + anAttributeName + "\" is not initialized."; + break; + case ModuleBase_ModelWidget::ModifiedInPP: // Apply should be enabled in this mode + default: + break; + } + } + } + return anError; +} + +QString ModuleBase_ModelWidget::getError() const +{ + QString anError; + + if (!feature().get()) + return anError; + + std::string anAttributeID = attributeID(); + AttributePtr anAttribute = feature()->attribute(anAttributeID); + if (!anAttribute.get()) + return anError; + + std::string aValidatorID; + std::string anErrorMsg; + + static ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators(); + if (!aValidators->validate(anAttribute, aValidatorID, anErrorMsg)) { + if (anErrorMsg.empty()) + anErrorMsg = "unknown error."; + anErrorMsg = anAttributeID + " - " + aValidatorID + ": " + anErrorMsg; + } + + anError = QString::fromStdString(anErrorMsg); + if (anError.isEmpty()) + anError = getValueStateError(); + + return anError; +} + void ModuleBase_ModelWidget::enableFocusProcessing() { QList aMyControls = getControls(); foreach(QWidget* eachControl, aMyControls) { - if (myIsObligatory) { eachControl->setFocusPolicy(Qt::StrongFocus); eachControl->installEventFilter(this); - } - else { - eachControl->setFocusPolicy(Qt::NoFocus); - } } } @@ -75,21 +130,10 @@ void ModuleBase_ModelWidget::setHighlighted(bool isHighlighted) QLabel* aLabel = qobject_cast(aWidget); // We won't set the effect to QLabels - it looks ugly if(aLabel) continue; - if(isHighlighted) { - // If effect is the installed on a different widget, setGraphicsEffect() will - // remove the effect from the widget and install it on this widget. - // That's why we create a new effect for each widget - QGraphicsDropShadowEffect* aGlowEffect = new QGraphicsDropShadowEffect(); - aGlowEffect->setOffset(.0); - aGlowEffect->setBlurRadius(10.0); - aGlowEffect->setColor(QColor(0, 170, 255)); // Light-blue color, #00AAFF - aWidget->setGraphicsEffect(aGlowEffect); - } else { - QGraphicsEffect* anEffect = aWidget->graphicsEffect(); - if(anEffect) - anEffect->deleteLater(); - aWidget->setGraphicsEffect(NULL); - } + // If effect is the installed on a different widget, setGraphicsEffect() will + // remove the effect from the widget and install it on this widget. + // That's why we create a new effect for each widget + ModuleBase_Tools::setShadowEffect(aWidget, isHighlighted); } } @@ -108,7 +152,7 @@ bool ModuleBase_ModelWidget::focusTo() for (; anIt != aLast && !isFocusAccepted; anIt++) { QWidget* aWidget = *anIt; if (aWidget && aWidget->focusPolicy() != Qt::NoFocus) { - aWidget->setFocus(); + ModuleBase_Tools::setFocus(aWidget, "ModuleBase_ModelWidget::focusTo()"); isFocusAccepted = true; } } @@ -128,6 +172,14 @@ void ModuleBase_ModelWidget::activate() activateCustom(); } +void ModuleBase_ModelWidget::deactivate() +{ + myIsValueStateBlocked = false; + if (myState == ModifiedInPP || myState == ModifiedInViewer) + storeValue(); + myState = Stored; +} + void ModuleBase_ModelWidget::initializeValueByActivate() { if (isComputedDefault()) { @@ -177,14 +229,43 @@ bool ModuleBase_ModelWidget::storeValue() return isDone; } +#ifdef DEBUG_VALUE_STATE +std::string getDebugInfo(const ModuleBase_ModelWidget::ValueState& theState) +{ + std::string anInfo; + switch (theState) { + case ModuleBase_ModelWidget::Stored: anInfo = "Stored "; break; + case ModuleBase_ModelWidget::ModifiedInPP: anInfo = "ModifiedInPP "; break; + case ModuleBase_ModelWidget::ModifiedInViewer: anInfo = "ModifiedInViewer"; break; + case ModuleBase_ModelWidget::Reset: anInfo = "Reset "; break; + default: break; + } + return anInfo; +} -void ModuleBase_ModelWidget::setValueState(const ValueState& theState) +#endif +ModuleBase_ModelWidget::ValueState ModuleBase_ModelWidget::setValueState + (const ModuleBase_ModelWidget::ValueState& theState) { - if (myState == theState) - return; + ValueState aState = myState; + + if (myState != theState && !myIsValueStateBlocked) { +#ifdef DEBUG_VALUE_STATE + qDebug(QString("setValueState: previous state = %1,\t new state = %2") + .arg(getDebugInfo(myState).c_str()) + .arg(getDebugInfo(theState).c_str()).toStdString().c_str()); +#endif + myState = theState; + emit valueStateChanged(aState); + } + return aState; +} - myState = theState; - emit valueStateChanged(); +bool ModuleBase_ModelWidget::blockValueState(const bool theBlocked) +{ + bool isBlocked = myIsValueStateBlocked; + myIsValueStateBlocked = theBlocked; + return isBlocked; } bool ModuleBase_ModelWidget::restoreValue() @@ -196,14 +277,6 @@ bool ModuleBase_ModelWidget::restoreValue() return isDone; } -void ModuleBase_ModelWidget::storeValueByApply() -{ - // do not emit signal about update the currenty feature object - // in order to do not perform additional redisplay in the viewer. - // It should happens by finish operation of the apply action - storeValueCustom(); -} - void ModuleBase_ModelWidget::updateObject(ObjectPtr theObj) { blockUpdateViewer(true); @@ -229,6 +302,13 @@ bool ModuleBase_ModelWidget::processEnter() return false; } +bool ModuleBase_ModelWidget::processDelete() +{ + // we consider that model objects eats delete key in order to + // do nothing by for example symbol delete in line edit or spin box + return true; +} + bool ModuleBase_ModelWidget::eventFilter(QObject* theObject, QEvent *theEvent) { QWidget* aWidget = qobject_cast(theObject); @@ -242,6 +322,20 @@ bool ModuleBase_ModelWidget::eventFilter(QObject* theObject, QEvent *theEvent) emit focusInWidget(this); } } + else if (theEvent->type() == QEvent::FocusOut) { + QFocusEvent* aFocusEvent = dynamic_cast(theEvent); + + Qt::FocusReason aReason = aFocusEvent->reason(); + bool aMouseOrKey = aReason == Qt::MouseFocusReason || + aReason == Qt::TabFocusReason || + aReason == Qt::BacktabFocusReason || + aReason == Qt::OtherFocusReason; // to process widget->setFocus() + if (aMouseOrKey && getControls().contains(aWidget)) { + if (getValueState() == ModifiedInPP) { + storeValue(); + } + } + } // pass the event on to the parent class return QObject::eventFilter(theObject, theEvent); @@ -256,7 +350,7 @@ void ModuleBase_ModelWidget::onWidgetValuesChanged() //************************************************************** void ModuleBase_ModelWidget::onWidgetValuesModified() { - setValueState(Modified); + setValueState(ModifiedInPP); } //**************************************************************