X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_ModelWidget.cpp;h=f0d33055320a9a9d21ef2fd36029e063aa75a5e1;hb=d481e13e400f2ea0e35c25884e73ccddaffd0f70;hp=4c672c5b67086f02a9d06be9c11df9e8c1ae219f;hpb=0762e940f001e4860da8cfd16400df23e3dfb088;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index 4c672c5b6..f0d330553 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -1,6 +1,6 @@ // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -// File: ModuleBase_ModelWidget.h +// File: ModuleBase_ModelWidget.cpp // Created: 25 Apr 2014 // Author: Natalia ERMOLAEVA @@ -17,21 +17,37 @@ #include #include -#include #include #include #include +#include -ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent, const Config_WidgetAPI* theData, +ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent, + const Config_WidgetAPI* theData, const std::string& theParentId) - : QObject(theParent), - myParentId(theParentId) + : QWidget(theParent), + myParentId(theParentId), + myIsEditing(false), + myState(Stored), + myIsValueStateBlocked(false) { myDefaultValue = theData->getProperty(ATTR_DEFAULT); - myIsComputedDefault = false; + myUseReset = theData->getBooleanAttribute(ATTR_USE_RESET, true); + myIsComputedDefault = theData->getProperty(ATTR_DEFAULT) == DOUBLE_WDG_DEFAULT_COMPUTED; myAttributeID = theData ? theData->widgetId() : ""; + myIsObligatory = theData->getBooleanAttribute(ATTR_OBLIGATORY, true); connect(this, SIGNAL(valuesChanged()), this, SLOT(onWidgetValuesChanged())); + connect(this, SIGNAL(valuesModified()), this, SLOT(onWidgetValuesModified())); +} + +bool ModuleBase_ModelWidget::reset() +{ + bool aResult = resetCustom(); + if (aResult) + setValueState(Reset); + + return aResult; } bool ModuleBase_ModelWidget::isInitialized(ObjectPtr theObject) const @@ -43,8 +59,13 @@ void ModuleBase_ModelWidget::enableFocusProcessing() { QList aMyControls = getControls(); foreach(QWidget* eachControl, aMyControls) { - eachControl->setFocusPolicy(Qt::StrongFocus); - eachControl->installEventFilter(this); + if (myIsObligatory) { + eachControl->setFocusPolicy(Qt::StrongFocus); + eachControl->installEventFilter(this); + } + else { + eachControl->setFocusPolicy(Qt::NoFocus); + } } } @@ -84,49 +105,163 @@ bool ModuleBase_ModelWidget::focusTo() { QList aControls = getControls(); QList::const_iterator anIt = aControls.begin(), aLast = aControls.end(); - for (; anIt != aLast; anIt++) { + bool isFocusAccepted = false; + for (; anIt != aLast && !isFocusAccepted; anIt++) { QWidget* aWidget = *anIt; if (aWidget && aWidget->focusPolicy() != Qt::NoFocus) { aWidget->setFocus(); - break; + isFocusAccepted = true; } } - return true; + return isFocusAccepted; } void ModuleBase_ModelWidget::activate() { + // the control value is stored to the mode by the focus in on the widget + // we need the value is initialized in order to enable the apply button in the property panel. + // It should happens in the creation mode only because all fields are filled in the edition mode if (!isEditingMode()) { - // the control value is stored to the mode by the focus in on the widget - // we need the value is initialized in order to enable the apply button in the property panel - // it should happens only in the creation mode because during edition all fields are filled - storeValue(); + AttributePtr anAttribute = myFeature->data()->attribute(myAttributeID); + if (anAttribute.get() != NULL && !anAttribute->isInitialized()) + initializeValueByActivate(); } activateCustom(); } -void ModuleBase_ModelWidget::updateObject(ObjectPtr theObj) const +void ModuleBase_ModelWidget::deactivate() +{ + myIsValueStateBlocked = false; + if (myState == ModifiedInPP) + storeValue(); + myState = Stored; +} + +void ModuleBase_ModelWidget::initializeValueByActivate() +{ + if (isComputedDefault()) { + if (myFeature->compute(myAttributeID)) { + restoreValue(); + } + } + else { + storeValue(); + } +} + +QWidget* ModuleBase_ModelWidget::getControlAcceptingFocus(const bool isFirst) +{ + QWidget* aControl = 0; + + QList aControls = getControls(); + int aSize = aControls.size(); + + if (isFirst) { + for (int i = 0; i < aSize && !aControl; i++) { + if (aControls[i]->focusPolicy() != Qt::NoFocus) + aControl = aControls[i]; + } + } + else { + for (int i = aSize - 1; i >= 0 && !aControl; i--) { + if (aControls[i]->focusPolicy() != Qt::NoFocus) + aControl = aControls[i]; + } + } + return aControl; +} + +void ModuleBase_ModelWidget::setDefaultValue(const std::string& theValue) +{ + myDefaultValue = theValue; +} + +bool ModuleBase_ModelWidget::storeValue() +{ + setValueState(Stored); + + emit beforeValuesChanged(); + bool isDone = storeValueCustom(); + emit afterValuesChanged(); + + return isDone; +} + +ModuleBase_ModelWidget::ValueState ModuleBase_ModelWidget::setValueState(const ModuleBase_ModelWidget::ValueState& theState) +{ + ValueState aState = myState; + if (myState != theState && !myIsValueStateBlocked) { + myState = theState; + emit valueStateChanged(aState); + } + return aState; +} + +bool ModuleBase_ModelWidget::blockValueState(const bool theBlocked) +{ + bool isBlocked = myIsValueStateBlocked; + myIsValueStateBlocked = theBlocked; + return isBlocked; +} + +bool ModuleBase_ModelWidget::restoreValue() { + emit beforeValuesRestored(); + bool isDone = restoreValueCustom(); + emit afterValuesRestored(); + + return isDone; +} + +void ModuleBase_ModelWidget::updateObject(ObjectPtr theObj) +{ + blockUpdateViewer(true); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); - static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY); - ModelAPI_EventCreator::get()->sendUpdated(theObj, anEvent); + + blockUpdateViewer(false); } -void ModuleBase_ModelWidget::moveObject(ObjectPtr theObj) const +void ModuleBase_ModelWidget::moveObject(ObjectPtr theObj) { + //blockUpdateViewer(true); + static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED); ModelAPI_EventCreator::get()->sendUpdated(theObj, anEvent); Events_Loop::loop()->flush(anEvent); + + //blockUpdateViewer(false); +} + +bool ModuleBase_ModelWidget::processEnter() +{ + return false; } bool ModuleBase_ModelWidget::eventFilter(QObject* theObject, QEvent *theEvent) { QWidget* aWidget = qobject_cast(theObject); if (theEvent->type() == QEvent::FocusIn) { + #ifdef _DEBUG + // The following two lines are for debugging purpose only + QFocusEvent* aFocusEvent = dynamic_cast(theEvent); + bool isWinFocus = aFocusEvent->reason() == Qt::ActiveWindowFocusReason; + #endif if (getControls().contains(aWidget)) { 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) && getValueState() == ModifiedInPP) + storeValue(); + } // pass the event on to the parent class return QObject::eventFilter(theObject, theEvent); @@ -137,3 +272,29 @@ void ModuleBase_ModelWidget::onWidgetValuesChanged() { storeValue(); } + +//************************************************************** +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); +}