public slots:
/// SLOT, that is called after the operation is validated and feature validation errors have changed.
- virtual void onValidationStateChanged() = 0;
+ //virtual void onValidationStateChanged() = 0;
protected slots:
/// Process values changed event for processing feature attribute validation errors.
//XGUI_Displayer* aDisp = workshop()->displayer();
//aDisp->closeLocalContexts();
emit planeSelected(plane());
+ emit valuesChanged();
// after the plane is selected in the sketch, the sketch selection should be activated
// it can not be performed in the sketch label widget because, we don't need to switch off
// the selection by any label deactivation, but need to switch it off by stop the sketch
#include <ModelAPI_Validator.h>
#include <QLabel>
+#include <QAction>
+#include <QApplication>
+#include <QDesktopWidget>
+#include <QDialog>
+#include <QCursor>
+#include <QHBoxLayout>
+#include <QLabel>
+
+const QString INVALID_VALUE = "invalid_action";
+
XGUI_ErrorMgr::XGUI_ErrorMgr(QObject* theParent /*= 0*/)
- : ModuleBase_IErrorMgr(theParent)
+ : ModuleBase_IErrorMgr(theParent),
+ myErrorDialog(0),
+ myErrorLabel(0)
{
}
}
+bool XGUI_ErrorMgr::canProcessClick(QAction* theAction, const FeaturePtr& theFeature)
+{
+ QString aData = theAction->data().toString();
+
+ bool isActionEnabled = theAction->data() != INVALID_VALUE;
+
+ QString anError = getFeatureError(theFeature);
+ 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;
+}
+
+void XGUI_ErrorMgr::updateActionState(QAction* theAction, const FeaturePtr& theFeature,
+ const bool theEnabled)
+{
+ bool isActionEnabled = theAction->data() != INVALID_VALUE;
+ if (theEnabled == isActionEnabled)
+ return;
+
+ theAction->setIcon(theEnabled ? QIcon(":pictures/button_ok.png"): QIcon(":pictures/button_ok_error.png"));
+ QWidget* aWidget = myPropertyPanel->headerWidget();
+ if (theEnabled) {
+ theAction->setData("");
+ aWidget->setToolTip("");
+ }
+ else {
+ theAction->setData(INVALID_VALUE);
+ aWidget->setToolTip(getFeatureError(theFeature));
+ }
+}
+
const char* toString(ModelAPI_ExecState theExecState)
{
#define TO_STRING(__NAME__) case __NAME__: return #__NAME__;
#undef TO_STRING
}
-void XGUI_ErrorMgr::onValidationStateChanged()
+/*void XGUI_ErrorMgr::onValidationStateChanged()
{
XGUI_OperationMgr* anOperationMgr = dynamic_cast<XGUI_OperationMgr*>(sender());
if (!anOperationMgr)
if (!myPropertyPanel || !aFOperation)
return;
- // get feature
FeaturePtr aFeature = aFOperation->feature();
- if (!aFeature.get() || !aFeature->data()->isValid())
- return;
-
- // set error indication
- QString anError = QString::fromStdString(aFeature->error());
- if (anError.isEmpty()) {
- bool isDone = ( aFeature->data()->execState() == ModelAPI_StateDone
- || aFeature->data()->execState() == ModelAPI_StateMustBeUpdated );
- if (!isDone)
- anError = toString(aFeature->data()->execState());
- }
+ 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()
#include "XGUI.h"
#include <ModuleBase_IErrorMgr.h>
+#include <ModelAPI_Feature.h>
+
+class QAction;
+class QDialog;
+class QLabel;
class XGUI_EXPORT XGUI_ErrorMgr : public ModuleBase_IErrorMgr
{
/// Virtual destructor
virtual ~XGUI_ErrorMgr();
+ /// It updates the action state according to the given parameter
+ /// \param theAction an action to be changed
+ /// \param theFeature an feature that corresponds to the action
+ /// \param theEnabled an enable state
+ void updateActionState(QAction* theAction, const FeaturePtr& theFeature,
+ const bool theEnabled);
+
+ /// 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 onValidationStateChanged();
protected slots:
/// Reimplemented from ModuleBase_ErrorMgr::onWidgetChanged().
virtual void onWidgetChanged();
+
+private:
+ /// Returns the feature error message
+ /// \param theFeature a feature
+ /// \return the error message
+ QString getFeatureError(const FeaturePtr& theFeature) const;
+
+private:
+ QDialog* myErrorDialog; /// contains the error message
+ QLabel* myErrorLabel; /// contains an error information
};
#endif // XGUI_ErrorMgr_H
\ No newline at end of file
SLOT(onOperationCommitted(ModuleBase_Operation*)));
connect(myOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)),
SLOT(onOperationAborted(ModuleBase_Operation*)));
- connect(myOperationMgr, SIGNAL(validationStateChanged(bool)),
- myErrorMgr, SLOT(onValidationStateChanged()));
+ //connect(myOperationMgr, SIGNAL(validationStateChanged(bool)),
+ // myErrorMgr, SLOT(onValidationStateChanged()));
if (myMainWindow)
connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
}
}
+//******************************************************
+void XGUI_Workshop::onAcceptActionClicked()
+{
+ QAction* anAction = dynamic_cast<QAction*>(sender());
+ XGUI_OperationMgr* anOperationMgr = operationMgr();
+ if (anOperationMgr) {
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (anOperationMgr->currentOperation());
+ if (aFOperation) {
+ if (errorMgr()->canProcessClick(anAction, aFOperation->feature()))
+ myOperationMgr->onCommitOperation();
+ }
+ }
+}
+
+//******************************************************
+void XGUI_Workshop::onValidationStateChanged(bool theEnabled)
+{
+ XGUI_OperationMgr* anOperationMgr = operationMgr();
+ if (anOperationMgr) {
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (anOperationMgr->currentOperation());
+ if (aFOperation) {
+ QAction* anAction = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
+ myErrorMgr->updateActionState(anAction, aFOperation->feature(), theEnabled);
+ }
+ }
+}
+
//******************************************************
void XGUI_Workshop::deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer)
myPropertyPanel->installEventFilter(myOperationMgr);
QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
- connect(aOkAct, SIGNAL(triggered()), myOperationMgr, SLOT(onCommitOperation()));
+ connect(aOkAct, SIGNAL(triggered()), this, SLOT(onAcceptActionClicked()));
+
QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
connect(myPropertyPanel, SIGNAL(noMoreWidgets()), myModule, SLOT(onNoMoreWidgets()));
connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)),
myOperationMgr, SLOT(onKeyReleased(QKeyEvent*)));
connect(myOperationMgr, SIGNAL(validationStateChanged(bool)),
- aOkAct, SLOT(setEnabled(bool)));
+ this, SLOT(onValidationStateChanged(bool)));
}
//******************************************************
return myOperationMgr;
}
+ //! ! Returns error manager.
+ XGUI_ErrorMgr* errorMgr() const
+ {
+ return myErrorMgr;
+ }
+
//! ! Returns an actions manager
XGUI_ActionsMgr* actionsMgr() const
{
/// Set waiting cursor
void onStartWaiting();
+ /// Called by Ok button clicked in the property panel. Asks the error manager whether
+ /// the operation can be commited and do it if it returns true.
+ void onAcceptActionClicked();
+
+ /// Listens the corresponded signal from operation manager and send it with the Ok
+ /// action to operation manager.
+ /// \param theEnabled an enabled state for the action
+ void onValidationStateChanged(bool theEnabled);
+
+ //connect(myOperationMgr, SIGNAL(validationStateChanged(bool)),
+ // aOkAct, SLOT(setEnabled(bool)));
+
+
private:
/// Init menu
void initMenu();
#include "XGUI_WorkshopListener.h"
#include "XGUI_Workshop.h"
#include "XGUI_Displayer.h"
+#include "XGUI_ErrorMgr.h"
#include "XGUI_OperationMgr.h"
#include "XGUI_SalomeConnector.h"
#include "XGUI_ActionsMgr.h"
//one button is used for all features, which can have nested actions, so it is obtained from
// the action manager
QAction* anAcceptAllAction = aWorkshop->actionsMgr()->operationStateAction(XGUI_ActionsMgr::AcceptAll, NULL);
+ bool aActionToBeUpdated = false;
if (aWorkshop->isSalomeMode()) {
XGUI_SalomeConnector* aSalomeConnector = aWorkshop->salomeConnector();
XGUI_ActionsMgr* anActionsMgr = aWorkshop->actionsMgr();
if (aSalomeConnector->isNestedFeature(anActionsMgr->action(theFeatureId.c_str())))
- anAcceptAllAction->setEnabled(theState);
+ aActionToBeUpdated = true;
} else {
AppElements_MainMenu* aMenuBar = aWorkshop->mainWindow()->menuObject();
AppElements_Command* aCommand = aMenuBar->feature(theFeatureId.c_str());
if (aCommand && aCommand->button()->additionalButtonWidget())
- anAcceptAllAction->setEnabled(theState);
+ aActionToBeUpdated = true;
+ }
+ if (aActionToBeUpdated) {
+ anAcceptAllAction->setEnabled(theState);
}
}
<file>pictures/button_cancel.png</file>
<file>pictures/button_help.png</file>
<file>pictures/button_ok.png</file>
+ <file>pictures/button_ok_error.png</file>
<file>pictures/assembly.png</file>
<file>pictures/delete.png</file>