+#ifdef DEBUG_WIDGET_INSTANCE
+ qDebug("ModuleBase_ModelWidget::activate");
+#endif
+ // 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()) {
+ AttributePtr anAttribute = myFeature->data()->attribute(myAttributeID);
+ if (anAttribute.get() != NULL && !anAttribute->isInitialized())
+ initializeValueByActivate();
+ }
+
+ if (myWidgetValidator)
+ myWidgetValidator->activateFilters(true);
+
+ activateCustom();
+}
+
+void ModuleBase_ModelWidget::deactivate()
+{
+#ifdef DEBUG_WIDGET_INSTANCE
+ qDebug("ModuleBase_ModelWidget::deactivate");
+#endif
+ myIsValueStateBlocked = false;
+ myState = Stored;
+ if (myWidgetValidator)
+ myWidgetValidator->activateFilters(false);
+}
+
+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;
+}
+#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;
+}
+
+#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 aState;