A processing for the double click in the viewer.
#include <Events_Loop.h>
-#include <ModelAPI_Validator.h>
#include <ModelAPI_Events.h>
#include <ModelAPI_CompositeFeature.h>
#include <ModelAPI_Session.h>
return ModelAPI_Tools::getFeatureError(theFeature).c_str();
}
-QString ModuleBase_IModule::getWidgetError(ModuleBase_ModelWidget* theWidget)
-{
- QString anError;
-
- if (!theWidget || !theWidget->feature().get())
- return anError;
-
- std::string anAttributeID = theWidget->attributeID();
- AttributePtr anAttribute = theWidget->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 = theWidget->getValueStateError();
-
- return anError;
-}
-
void ModuleBase_IModule::grantedOperationIds(ModuleBase_Operation* theOperation,
QStringList& theIds) const
{
//! \return string value\r
virtual QString getFeatureError(const FeaturePtr& theFeature);\r
\r
- //! Returns the widget error, get it from the attribute validator and state of the widget\r
- //! If the feature is correct, it returns an empty value\r
- //! \return string value\r
- virtual QString getWidgetError(ModuleBase_ModelWidget* theWidget);\r
-\r
/// Returns list of granted operation indices\r
virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;\r
\r
#include <ModelAPI_Attribute.h>
#include <ModelAPI_Events.h>
#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
#include <Config_Keywords.h>
#include <Config_WidgetAPI.h>
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();
/// By default it returns true
virtual bool canSetValue() const { return true; };
+ //! Returns the widget error, get it from the attribute validator and state of the widget
+ //! If the feature is correct, it returns an empty value
+ //! \return string value
+ QString getError() const;
+
/// Set the given wrapped value to the current widget
/// This value should be processed in the widget according to the needs
/// \param theValues the wrapped selection values
std::shared_ptr<GeomAPI_Pnt2d> aPnt = std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, aY));
setPoint(feature(), aPnt);
- emit focusOutWidget(this);
+
+ // if the validator of the control returns false, focus should not be switched
+ if (getError().isEmpty())
+ emit focusOutWidget(this);
}
void PartSet_WidgetPoint2dDistance::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
QString aWidgetError = "";
if (!isApplyEnabledByActiveWidget) {
anError = myWorkshop->module()->getFeatureError(theFeature);
- aWidgetError = myWorkshop->module()->getWidgetError(anActiveWidget);
+ if (anActiveWidget)
+ aWidgetError = anActiveWidget->getError();
if (anError.isEmpty())
anError = aWidgetError;
}
void XGUI_ErrorMgr::updateAcceptAllAction(const FeaturePtr& theFeature)
{
QString anError = myWorkshop->module()->getFeatureError(theFeature);
- if (anError.isEmpty())
- anError = myWorkshop->module()->getWidgetError(activeWidget());
-
+ if (anError.isEmpty()) {
+ ModuleBase_ModelWidget* anActiveWidget = activeWidget();
+ if (anActiveWidget)
+ anError = anActiveWidget->getError();
+ }
XGUI_ActionsMgr* anActionsMgr = workshop()->actionsMgr();
if (workshop()->isFeatureOfNested(theFeature)) {
QAction* anAcceptAllAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll, NULL);
if (!aModelWidget || !aModelWidget->feature().get())
return;
- QString aWidgetError = myWorkshop->module()->getWidgetError(aModelWidget);
+ QString aWidgetError = aModelWidget->getError();
updateToolTip(aModelWidget, aWidgetError);
}