// Author: Natalia ERMOLAEVA
#include "ModuleBase_ModelWidget.h"
+#include "ModuleBase_ViewerPrs.h"
#include "ModuleBase_Tools.h"
+#include "ModuleBase_WidgetValidator.h"
#include <ModelAPI_Data.h>
#include <ModelAPI_Attribute.h>
#include <QLabel>
#include <QFocusEvent>
+//#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),
+ 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;
if (anAttribute.get() != NULL && !anAttribute->isInitialized())
initializeValueByActivate();
}
+
+ if (myWidgetValidator)
+ myWidgetValidator->activateFilters(true);
+
activateCustom();
}
if (myState == ModifiedInPP || myState == ModifiedInViewer)
storeValue();
myState = Stored;
+
+ if (myWidgetValidator)
+ myWidgetValidator->activateFilters(false);
}
void ModuleBase_ModelWidget::initializeValueByActivate()
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);
}
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);
+ ModuleBase_Tools::flushUpdated(theObject);
+ emit objectUpdated();
}
void ModuleBase_ModelWidget::moveObject(ObjectPtr theObj)
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<QWidget*>(theObject);
{
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);
-}