+QString ModuleBase_ModelWidget::getValueStateError() const
+{
+ QString anError = "";
+
+ ModuleBase_ModelWidget::ValueState aState = getValueState();
+ if (aState != ModuleBase_ModelWidget::Stored) {
+ AttributePtr anAttr = feature()->attribute(attributeID());
+ if (anAttr.get()) {
+ QString anAttributeName = anAttr->id().c_str();
+ switch (aState) {
+ case ModuleBase_ModelWidget::ModifiedInViewer:
+ anError = "Attribute \"" + anAttributeName +
+ "\" is locked by modification value in the viewer.";
+ break;
+ 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
+{
+ 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())
+ anError = getValueStateError();
+
+ return anError;
+}
+
+void ModuleBase_ModelWidget::enableFocusProcessing()
+{
+ QList<QWidget*> aMyControls = getControls();
+ foreach(QWidget* eachControl, aMyControls) {
+ eachControl->setFocusPolicy(Qt::StrongFocus);
+ eachControl->installEventFilter(this);
+ }
+}
+
+void ModuleBase_ModelWidget::setHighlighted(bool isHighlighted)
+{
+ QList<QWidget*> aWidgetList = getControls();
+ foreach(QWidget* aWidget, aWidgetList) {
+ QLabel* aLabel = qobject_cast<QLabel*>(aWidget);
+ // We won't set the effect to QLabels - it looks ugly
+ if(aLabel) continue;
+ // 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)
+{
+ myFeature = theFeature;
+ if (theToStoreValue)
+ storeValue();
+}
+