X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_ModelWidget.cpp;h=8a85cd6f49d438e2419fb271686611e9721d456d;hb=622ac935fd1d8a5bc282ee127666a3e9d1954713;hp=ff7554f1dff06e840c764d1b6da435c2985129c7;hpb=5c212d40c54726dafdbc0c396802b65bce8c4d38;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index ff7554f1d..8a85cd6f4 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -5,12 +5,15 @@ // Author: Natalia ERMOLAEVA #include "ModuleBase_ModelWidget.h" +#include "ModuleBase_ViewerPrs.h" #include "ModuleBase_Tools.h" +#include "ModuleBase_WidgetValidator.h" #include #include #include #include +#include #include #include @@ -18,20 +21,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) + const Config_WidgetAPI* theData) : QWidget(theParent), - myParentId(theParentId), myIsEditing(false), myState(Stored), - myIsValueStateBlocked(false) + myIsValueStateBlocked(false), + myFlushUpdateBlocked(false), + myWidgetValidator(0) { + 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; @@ -66,10 +71,6 @@ QString ModuleBase_ModelWidget::getValueStateError() const if (anAttr.get()) { QString anAttributeName = anAttr->id().c_str(); switch (aState) { - case ModuleBase_ModelWidget::ModifiedInPP: - anError = "Attribute \"" + anAttributeName + - "\" modification is not applyed. Please click \"Enter\" or \"Tab\"."; - break; case ModuleBase_ModelWidget::ModifiedInViewer: anError = "Attribute \"" + anAttributeName + "\" is locked by modification value in the viewer."; @@ -77,23 +78,50 @@ QString ModuleBase_ModelWidget::getValueStateError() const 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 bool theValueStateChecked) 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() && theValueStateChecked) + 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); - } } } @@ -104,29 +132,23 @@ 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); } } -void ModuleBase_ModelWidget::setFeature(const FeaturePtr& theFeature, const bool theToStoreValue) +void ModuleBase_ModelWidget::setFeature(const FeaturePtr& theFeature, const bool theToStoreValue, + const bool isUpdateFlushed) { + /// it is possible to give this flag as parameter in storeValue/storeCustomValue + /// after debug, it may be corrected + myFlushUpdateBlocked = !isUpdateFlushed; myFeature = theFeature; if (theToStoreValue) storeValue(); + myFlushUpdateBlocked = false; } bool ModuleBase_ModelWidget::focusTo() @@ -154,15 +176,22 @@ void ModuleBase_ModelWidget::activate() if (anAttribute.get() != NULL && !anAttribute->isInitialized()) initializeValueByActivate(); } + + if (myWidgetValidator) + myWidgetValidator->activateFilters(true); + activateCustom(); } void ModuleBase_ModelWidget::deactivate() { myIsValueStateBlocked = false; - if (myState == ModifiedInPP) + if (myState == ModifiedInPP || myState == ModifiedInViewer) storeValue(); myState = Stored; + + if (myWidgetValidator) + myWidgetValidator->activateFilters(false); } void ModuleBase_ModelWidget::initializeValueByActivate() @@ -214,11 +243,32 @@ 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; +} -ModuleBase_ModelWidget::ValueState ModuleBase_ModelWidget::setValueState(const ModuleBase_ModelWidget::ValueState& theState) +#endif +ModuleBase_ModelWidget::ValueState ModuleBase_ModelWidget::setValueState + (const ModuleBase_ModelWidget::ValueState& theState) { 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); } @@ -241,13 +291,12 @@ bool ModuleBase_ModelWidget::restoreValue() return isDone; } -void ModuleBase_ModelWidget::updateObject(ObjectPtr theObj) +void ModuleBase_ModelWidget::updateObject(ObjectPtr theObject) { - blockUpdateViewer(true); - - Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); - - blockUpdateViewer(false); + if (!myFlushUpdateBlocked) { + ModuleBase_Tools::flushUpdated(theObject); + emit objectUpdated(); + } } void ModuleBase_ModelWidget::moveObject(ObjectPtr theObj) @@ -266,6 +315,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); @@ -287,8 +343,11 @@ bool ModuleBase_ModelWidget::eventFilter(QObject* theObject, QEvent *theEvent) aReason == Qt::TabFocusReason || aReason == Qt::BacktabFocusReason || aReason == Qt::OtherFocusReason; // to process widget->setFocus() - if (aMouseOrKey && getControls().contains(aWidget) && getValueState() == ModifiedInPP) - storeValue(); + if (aMouseOrKey && getControls().contains(aWidget)) { + if (getValueState() == ModifiedInPP) { + storeValue(); + } + } } // pass the event on to the parent class @@ -306,23 +365,3 @@ void ModuleBase_ModelWidget::onWidgetValuesModified() { setValueState(ModifiedInPP); } - -//************************************************************** -void ModuleBase_ModelWidget::blockUpdateViewer(const bool theValue) -{ - // the viewer update should be blocked in order to avoid the temporary feature content - // when the solver processes the feature, the redisplay message can be flushed - // what caused the display in the viewer preliminary states of object - // e.g. fillet feature, angle value change - std::shared_ptr aMsg; - if (theValue) { - aMsg = std::shared_ptr( - new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED))); - } - else { - // the viewer update should be unblocked - aMsg = std::shared_ptr( - new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED))); - } - Events_Loop::loop()->send(aMsg); -}