const std::string& theParentId)
: QWidget(theParent),
myParentId(theParentId),
- myIsEditing(false)
+ myIsEditing(false),
+ myState(Stored),
+ myIsValueStateBlocked(false)
{
myDefaultValue = theData->getProperty(ATTR_DEFAULT);
myUseReset = theData->getBooleanAttribute(ATTR_USE_RESET, true);
myAttributeID = theData ? theData->widgetId() : "";
myIsObligatory = theData->getBooleanAttribute(ATTR_OBLIGATORY, true);
- std::list<std::string> anAttributes = theData->getAttributes();
- for (auto it = anAttributes.begin(); it != anAttributes.end(); ++it) {
- std::string aRole = theData->getAttributeProperty(*it, ATTR_ROLE);
- myRoleAttributesID[aRole] << *it;
- }
-
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
}
}
-std::string ModuleBase_ModelWidget::attributeID(const std::string& theRole/* = std::string()*/) const
-{
- if (theRole.empty())
- return myAttributeID;
-
- if (myRoleAttributesID.contains(theRole) && !myRoleAttributesID[theRole].isEmpty())
- return myRoleAttributesID[theRole].last();
-
- return std::string();
-}
-
void ModuleBase_ModelWidget::setFeature(const FeaturePtr& theFeature, const bool theToStoreValue)
{
myFeature = theFeature;
// It should happens in the creation mode only because all fields are filled in the edition mode
if (!isEditingMode()) {
AttributePtr anAttribute = myFeature->data()->attribute(myAttributeID);
- if (anAttribute.get() != NULL && !anAttribute->isInitialized()) {
- if (isComputedDefault()) {
- if (myFeature->compute(myAttributeID)) {
- restoreValue();
- }
- }
- else {
- storeValue();
- }
- }
+ if (anAttribute.get() != NULL && !anAttribute->isInitialized())
+ initializeValueByActivate();
}
activateCustom();
}
+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<QWidget*> 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();
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)
{
+ //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)
if (getControls().contains(aWidget)) {
emit focusInWidget(this);
}
- }
+ }
+ else if (theEvent->type() == QEvent::FocusOut) {
+ QFocusEvent* aFocusEvent = dynamic_cast<QFocusEvent*>(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);
{
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<Events_Message> aMsg;
+ if (theValue) {
+ aMsg = std::shared_ptr<Events_Message>(
+ new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)));
+ }
+ else {
+ // the viewer update should be unblocked
+ aMsg = std::shared_ptr<Events_Message>(
+ new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED)));
+ }
+ Events_Loop::loop()->send(aMsg);
+}