The correction for widgets, which are not in the parameters dialog.
They also should show tool tip errors.
foreach(const ModuleBase_ModelWidget* aWgt, myPropertyPanel->modelWidgets()) {
connect(aWgt, SIGNAL(afterValuesChanged()), this, SLOT(onWidgetChanged()));
connect(aWgt, SIGNAL(afterValuesRestored()), this, SLOT(onWidgetChanged()));
+ connect(aWgt, SIGNAL(valueStateChanged(int)), this, SLOT(onWidgetChanged()));
}
}
}
#include "ModuleBase_ISelection.h"
#include "ModuleBase_OperationDescription.h"
#include "ModuleBase_OperationFeature.h"
+#include <ModuleBase_ModelWidget.h>
#include <Events_Loop.h>
+#include <ModelAPI_Validator.h>
#include <ModelAPI_Events.h>
#include <ModelAPI_CompositeFeature.h>
#include <ModelAPI_Session.h>
#undef TO_STRING
}
-QString ModuleBase_IModule::getFeatureError(const FeaturePtr& theFeature, const bool isCheckGUI)
+QString ModuleBase_IModule::getFeatureError(const FeaturePtr& theFeature)
{
QString anError;
if (!theFeature.get() || !theFeature->data()->isValid() || theFeature->isAction())
return anError;
}
+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
{
//! Returns the feature error if the current state of the feature in the module is not correct\r
//! If the feature is correct, it returns an empty value\r
//! \return string value\r
- virtual QString getFeatureError(const FeaturePtr& theFeature, const bool isCheckGUI = true);\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
return theObject->data()->attribute(attributeID())->isInitialized();
}
+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::ModifiedInPP:
+ anError = "Attribute \"" + anAttributeName +
+ "\" modification is not applyed. Please click \"Enter\" or \"Tab\".";
+ break;
+ 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;
+ }
+ }
+ }
+ return anError;
+}
+
void ModuleBase_ModelWidget::enableFocusProcessing()
{
QList<QWidget*> aMyControls = getControls();
/// \return the enumeration result
ValueState getValueState() const { return myState; }
+ /// Returns an attribute error according to the value state
+ /// It exists in all cases excepring the "Store" case
+ QString getValueStateError() const;
+
/// Defines if it is supposed that the widget should interact with the viewer.
virtual bool isViewerSelector() { return false; }
myMenuMgr->updateViewerMenu(theStdActions);
}
-QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature, const bool isCheckGUI)
+QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature)
{
- QString anError = ModuleBase_IModule::getFeatureError(theFeature, isCheckGUI);
+ QString anError = ModuleBase_IModule::getFeatureError(theFeature);
if (anError.isEmpty())
- anError = sketchMgr()->getFeatureError(theFeature, isCheckGUI);
+ anError = sketchMgr()->getFeatureError(theFeature);
return anError;
}
//! Returns the feature error if the current state of the feature in the module is not correct
//! If the feature is correct, it returns an empty value
//! \return string value
- virtual QString getFeatureError(const FeaturePtr& theFeature, const bool isCheckGUI = true);
+ virtual QString getFeatureError(const FeaturePtr& theFeature);
/// Returns list of granted operation indices
virtual void grantedOperationIds(ModuleBase_Operation* theOperation, QStringList& theIds) const;
return anError;
}
-QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature, const bool isCheckGUI)
+QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature)
{
QString anError = "";
if (!theFeature.get() || !theFeature->data()->isValid())
AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
anError = aAttributeString->value().c_str();
}
- else {
- ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
- if (isCheckGUI && anActiveWidget) {
- ModuleBase_ModelWidget::ValueState aState = anActiveWidget->getValueState();
- if (aState != ModuleBase_ModelWidget::Stored) {
- AttributePtr anAttr = anActiveWidget->feature()->attribute(anActiveWidget->attributeID());
- if (anAttr.get()) {
- QString anAttributeName = anAttr->id().c_str();
- switch (aState) {
- case ModuleBase_ModelWidget::ModifiedInPP:
- anError = "Attribute \"" + anAttributeName +
- "\" modification is not applyed. Please click \"Enter\" or \"Tab\".";
- break;
- 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;
- }
- }
- }
- }
- }
return anError;
}
//! Incorrect states: the feature is sketch, the solver error value
//! The feature value is reset, this is the flag of sketch mgr
//! \return string value
- QString getFeatureError(const FeaturePtr& theFeature, const bool isCheckGUI = true);
+ QString getFeatureError(const FeaturePtr& theFeature);
/// It nullify internal flags concerned to clicked mouse event
void clearClickedFlags();
ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
(myWorkshop->currentOperation());
- if (!myWorkshop->module()->getFeatureError(aFOperation->feature(), false).isEmpty())
+ if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
return;
if (aFOperation && PartSet_SketcherMgr::isNestedSketchOperation(aFOperation)) {
ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
(myWorkshop->currentOperation());
- if (!myWorkshop->module()->getFeatureError(aFOperation->feature(), false).isEmpty())
+ if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
return isDone;
myRestartingMode = RM_EmptyFeatureUsed;
void XGUI_ErrorMgr::updateActions(const FeaturePtr& theFeature)
{
- QString anError = myWorkshop->module()->getFeatureError(theFeature);
-
//update Ok Action and header of property panel if the current operation started for the feature
XGUI_ActionsMgr* anActionsMgr = workshop()->actionsMgr();
ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
(workshop()->operationMgr()->currentOperation());
if (aFOperation && aFOperation->feature() == theFeature) {
QAction* anOkAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
- updateActionState(anOkAction, theFeature);
+ QString anError = myWorkshop->module()->getFeatureError(theFeature);
+
+ ModuleBase_ModelWidget* anActiveWidget = activeWidget();
+ QString aWidgetError = myWorkshop->module()->getWidgetError(anActiveWidget);
+ if (anError.isEmpty())
+ anError = aWidgetError;
+
+ updateActionState(anOkAction, anError);
+ updateToolTip(anActiveWidget, aWidgetError);
}
}
void XGUI_ErrorMgr::updateAcceptAllAction(const FeaturePtr& theFeature)
{
QString anError = myWorkshop->module()->getFeatureError(theFeature);
+ if (anError.isEmpty())
+ anError = myWorkshop->module()->getWidgetError(activeWidget());
XGUI_ActionsMgr* anActionsMgr = workshop()->actionsMgr();
if (workshop()->isFeatureOfNested(theFeature)) {
}
}
-bool XGUI_ErrorMgr::canProcessClick(QAction* theAction, const FeaturePtr& theFeature)
+void XGUI_ErrorMgr::updateActionState(QAction* theAction, const QString& theError)
{
- QString anError = myWorkshop->module()->getFeatureError(theFeature);
- bool isActionEnabled = anError.isEmpty();
- if (!isActionEnabled && !anError.isEmpty()) {
- if (!myErrorDialog) {
- myErrorDialog = new QDialog(QApplication::desktop(), Qt::Popup);
- QHBoxLayout* aLay = new QHBoxLayout(myErrorDialog);
- aLay->setContentsMargins(0, 0, 0, 0);
-
- QFrame* aMarginWidget = new QFrame(myErrorDialog);
- aMarginWidget->setFrameStyle(QFrame::Panel | QFrame::Raised);
-
- aLay->addWidget(aMarginWidget);
- QHBoxLayout* aMarginLay = new QHBoxLayout(aMarginWidget);
- aMarginLay->setContentsMargins(4, 4, 4, 4);
-
- myErrorLabel = new QLabel(aMarginWidget);
- aMarginLay->addWidget(myErrorLabel);
- }
- myErrorLabel->setText(anError);
- myErrorDialog->move(QCursor::pos());
- myErrorDialog->show();
- }
- return isActionEnabled;
-}
+ bool anEnabled = theError.isEmpty();
-void XGUI_ErrorMgr::updateActionState(QAction* theAction, const FeaturePtr& theFeature/*,
- const bool theEnabled*/)
-{
- QString anError = myWorkshop->module()->getFeatureError(theFeature);
- bool anEnabled = anError.isEmpty();
-
- /*bool isActionEnabled = theAction->data() != INVALID_VALUE;
- if (anEnabled != isActionEnabled) {
- // update enable state of the button
- theAction->setIcon(anEnabled ? QIcon(":pictures/button_ok.png"): QIcon(":pictures/button_ok_error.png"));
- if (anEnabled)
- theAction->setData("");
- else
- theAction->setData(INVALID_VALUE);
- }*/
theAction->setEnabled(anEnabled);
// some operations have no property panel, so it is important to check that it is not null
if (myPropertyPanel) {
// update controls error information
QWidget* aWidget = myPropertyPanel->headerWidget();
if (aWidget)
- aWidget->setToolTip(anError);
+ aWidget->setToolTip(theError);
}
}
-
-/*const char* toString(ModelAPI_ExecState theExecState)
-{
-#define TO_STRING(__NAME__) case __NAME__: return #__NAME__;
- switch (theExecState) {
- TO_STRING(ModelAPI_StateDone)
- TO_STRING(ModelAPI_StateMustBeUpdated)
- TO_STRING(ModelAPI_StateExecFailed)
- TO_STRING(ModelAPI_StateInvalidArgument)
- TO_STRING(ModelAPI_StateNothing)
- default: return "Unknown ExecState.";
- }
-#undef TO_STRING
-}*/
-
-/*void XGUI_ErrorMgr::onValidationStateChanged()
-{
- XGUI_OperationMgr* anOperationMgr = dynamic_cast<XGUI_OperationMgr*>(sender());
- if (!anOperationMgr)
- return;
- ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
- (anOperationMgr->currentOperation());
- if (!myPropertyPanel || !aFOperation)
- return;
-
- FeaturePtr aFeature = aFOperation->feature();
- QString anError = getFeatureError(aFeature);
-
- QWidget* aWidget = myPropertyPanel->headerWidget();
- if (aWidget) {
- aWidget->setToolTip(anError);
- aWidget->setStyleSheet(anError.isEmpty() ? "" : "background-color:pink;");
- }
-}*/
-
-/*QString XGUI_ErrorMgr::getFeatureError(const FeaturePtr& theFeature) const
-{
- QString anError;
- // get feature
- if (!theFeature.get() || !theFeature->data()->isValid())
- return anError;
-
- // set error indication
- anError = QString::fromStdString(theFeature->error());
- if (anError.isEmpty()) {
- bool isDone = ( theFeature->data()->execState() == ModelAPI_StateDone
- || theFeature->data()->execState() == ModelAPI_StateMustBeUpdated );
- if (!isDone)
- anError = toString(theFeature->data()->execState());
- }
-
- return anError;
-}*/
-
void XGUI_ErrorMgr::onWidgetChanged()
{
- static ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators();
-
ModuleBase_ModelWidget* aModelWidget = dynamic_cast<ModuleBase_ModelWidget*>(sender());
if (!aModelWidget || !aModelWidget->feature().get())
return;
- std::string anAttributeID = aModelWidget->attributeID();
- AttributePtr anAttribute = aModelWidget->feature()->attribute(anAttributeID);
- if (!anAttribute.get())
- return;
+ QString aWidgetError = myWorkshop->module()->getWidgetError(aModelWidget);
+ updateToolTip(aModelWidget, aWidgetError);
+}
- std::string aValidatorID;
- std::string anErrorMsg;
- if (!aValidators->validate(anAttribute, aValidatorID, anErrorMsg)) {
- if (anErrorMsg.empty())
- anErrorMsg = "unknown error.";
- anErrorMsg = anAttributeID + " - " + aValidatorID + ": " + anErrorMsg;
- }
+void XGUI_ErrorMgr::updateToolTip(ModuleBase_ModelWidget* theWidget,
+ const QString& theError)
+{
+ if (!theWidget)
+ return;
- QString anError = QString::fromStdString(anErrorMsg);
- QList<QWidget*> aWidgetList = aModelWidget->getControls();
+ QList<QWidget*> aWidgetList = theWidget->getControls();
foreach(QWidget* aWidget, aWidgetList) {
QLabel* aLabel = qobject_cast<QLabel*>(aWidget);
// We won't set the effect to QLabels - it looks ugly
// Get the original tool tip of the widget
QString aTTip = aWidget->toolTip().section("Errors:\n", 0, 0).trimmed();
// Add the error message into the tool tip
- if (!anError.isEmpty()) {
+ if (!theError.isEmpty()) {
if (!aTTip.isEmpty())
aTTip.append('\n');
- aTTip += "Errors:\n" + anError;
+ aTTip += "Errors:\n" + theError;
}
aWidget->setToolTip(aTTip);
//aWidget->setStyleSheet(anError.isEmpty() ? "" : "background-color:pink;");
XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
return aConnector->workshop();
}
+
+ModuleBase_ModelWidget* XGUI_ErrorMgr::activeWidget() const
+{
+ ModuleBase_ModelWidget* anActiveWidget = 0;
+
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (workshop()->operationMgr()->currentOperation());
+ if (aFOperation) {
+ ModuleBase_IPropertyPanel* aPropertyPanel = aFOperation->propertyPanel();
+ if (aPropertyPanel) {
+ anActiveWidget = aPropertyPanel->activeWidget();
+ }
+ }
+ return anActiveWidget;
+}
+
class XGUI_Workshop;
class ModuleBase_IWorkshop;
+class ModuleBase_ModelWidget;
+
class QAction;
class QDialog;
class QLabel;
/// \param theFeature a feature
void updateAcceptAllAction(const FeaturePtr& theFeature);
- /// Return true if the feature has no error. If there is an error and the action
- /// is not valid, the dialog with the error information is shown.
- /// \param theAction an action, which is checked on validity
- /// \param theFeature a feature that provides error information
- bool canProcessClick(QAction* theAction, const FeaturePtr& theFeature);
-
public slots:
/// Reimplemented from ModuleBase_ErrorMgr::onValidationStateChanged().
//virtual void onValidationStateChanged();
virtual void onWidgetChanged();
private:
- /// It updates the action state according to the given parameter
+ /// It disables the action if the error message is not empty
+ /// The message is set to the header tool tip.
/// \param theAction an action to be changed
- /// \param theFeature an feature that corresponds to the action
- void updateActionState(QAction* theAction, const FeaturePtr& theFeature);
+ /// \param theError an error state
+ void updateActionState(QAction* theAction, const QString& theError);
- /// Returns the feature error message
- /// \param theFeature a feature
- /// \return the error message
- //QString getFeatureError(const FeaturePtr& theFeature) const;
+ /// It updates the tool tip of the widget controls according to the widget error
+ /// \param theWidget a widget
+ /// \param theError an error state
+ void updateToolTip(ModuleBase_ModelWidget* theWidget, const QString& theError);
/// Returns casted workshop
XGUI_Workshop* workshop() const;
+ /// Returns an active widget of the current operation
+ /// \return the widget or zero
+ ModuleBase_ModelWidget* activeWidget() const;
+
private:
- ModuleBase_IWorkshop* myWorkshop;
+ ModuleBase_IWorkshop* myWorkshop; /// workshop
QDialog* myErrorDialog; /// contains the error message
QLabel* myErrorLabel; /// contains an error information
};
return;
ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
(currentOperation());
- if(aFOperation && aFOperation->feature().get())
- setApplyEnabled(myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty());
+ if(aFOperation && aFOperation->feature().get()) {
+ QString anError = myWorkshop->module()->getFeatureError(aFOperation->feature());
+ if (anError.isEmpty()) {
+ ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
+ if (aPanel) {
+ ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
+ if (anActiveWidget)
+ anError = myWorkshop->module()->getWidgetError(anActiveWidget);
+ }
+ }
+ setApplyEnabled(anError.isEmpty());
+ }
}
void XGUI_OperationMgr::setApplyEnabled(const bool theEnabled)
if (!aActiveWgt || !aActiveWgt->processEnter()) {
if (!myWorkshop->module()->processEnter(aActiveWgt ? aActiveWgt->attributeID() : "")) {
ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(currentOperation());
- if (!aFOperation || myWorkshop->module()->getFeatureError(aFOperation->feature(), false).isEmpty()) {
+ if (!aFOperation || myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty()) {
emit keyEnterReleased();
commitOperation();
}
ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
(anOperationMgr->currentOperation());
if (aFOperation) {
- if (errorMgr()->canProcessClick(anAction, aFOperation->feature()))
- myOperationMgr->onCommitOperation();
+ //if (errorMgr()->canProcessClick(anAction, aFOperation->feature()))
+ myOperationMgr->onCommitOperation();
}
}
}