#1401 Notify model change when feature is activated

This commit is contained in:
Magne Sjaastad
2017-04-20 10:17:05 +02:00
parent d7d80bc53e
commit 530400fb28
5 changed files with 77 additions and 20 deletions

View File

@@ -39,12 +39,29 @@
#include "cafCmdExecCommandManager.h" #include "cafCmdExecCommandManager.h"
#include "cafCmdFeatureManager.h" #include "cafCmdFeatureManager.h"
#include "cafPdmUiModelChangeDetector.h"
#include <QAction> #include <QAction>
namespace caf namespace caf
{ {
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
CmdFeature::CmdFeature()
: m_triggerModelChange(true)
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
CmdFeature::~CmdFeature()
{
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
@@ -116,4 +133,41 @@ void CmdFeature::refreshCheckedState()
} }
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool CmdFeature::canFeatureBeExecuted()
{
return this->isCommandEnabled();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdFeature::actionTriggered(bool isChecked)
{
this->onActionTriggered(isChecked);
if (m_triggerModelChange)
{
caf::PdmUiModelChangeDetector::instance()->setModelChanged();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool CmdFeature::isCommandChecked()
{
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdFeature::disableModelChangeContribution()
{
m_triggerModelChange = false;
}
} // end namespace caf } // end namespace caf

View File

@@ -73,27 +73,30 @@ class CmdFeature : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
CmdFeature() {} CmdFeature();
virtual ~CmdFeature() {} virtual ~CmdFeature();
QAction* action(); QAction* action();
QAction* action(QString customText); QAction* action(QString customText);
void refreshEnabledState(); void refreshEnabledState();
void refreshCheckedState(); void refreshCheckedState();
bool canFeatureBeExecuted() { return this->isCommandEnabled(); } bool canFeatureBeExecuted();
public slots: public slots:
void actionTriggered(bool isChecked) { this->onActionTriggered(isChecked); } void actionTriggered(bool isChecked);
protected: protected:
virtual void onActionTriggered(bool isChecked) = 0; virtual void onActionTriggered(bool isChecked) = 0;
virtual void setupActionLook(QAction* actionToSetup) = 0; virtual void setupActionLook(QAction* actionToSetup) = 0;
virtual bool isCommandEnabled() = 0; virtual bool isCommandEnabled() = 0;
virtual bool isCommandChecked() { return false; } virtual bool isCommandChecked();
void disableModelChangeContribution();
private: private:
std::map<QString, QAction*> m_customTextToActionMap; std::map<QString, QAction*> m_customTextToActionMap;
bool m_triggerModelChange;
}; };

View File

@@ -39,7 +39,7 @@ void PdmUiFieldHandle::notifyFieldChanged(const QVariant& oldFieldValue, const Q
// Update field editors // Update field editors
this->updateConnectedEditors(); this->updateConnectedEditors();
PdmUiModelChangeDetector::instance()->setModelIsChanged(); PdmUiModelChangeDetector::instance()->setModelChanged();
} }
} }

View File

@@ -43,7 +43,7 @@ namespace caf {
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
PdmUiModelChangeDetector::PdmUiModelChangeDetector() PdmUiModelChangeDetector::PdmUiModelChangeDetector()
: m_modelIsChanged(false) : m_isModelChanged(false)
{ {
} }
@@ -60,9 +60,9 @@ PdmUiModelChangeDetector* PdmUiModelChangeDetector::instance()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void PdmUiModelChangeDetector::setModelIsChanged() void PdmUiModelChangeDetector::setModelChanged()
{ {
m_modelIsChanged = true; m_isModelChanged = true;
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -70,7 +70,7 @@ void PdmUiModelChangeDetector::setModelIsChanged()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void PdmUiModelChangeDetector::reset() void PdmUiModelChangeDetector::reset()
{ {
m_modelIsChanged = false; m_isModelChanged = false;
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -78,7 +78,7 @@ void PdmUiModelChangeDetector::reset()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
bool PdmUiModelChangeDetector::isModelChanged() const bool PdmUiModelChangeDetector::isModelChanged() const
{ {
return m_modelIsChanged; return m_isModelChanged;
} }
} // end namespace caf } // end namespace caf

View File

@@ -43,7 +43,7 @@ class PdmUiModelChangeDetector
public: public:
static PdmUiModelChangeDetector* instance(); static PdmUiModelChangeDetector* instance();
void setModelIsChanged(); void setModelChanged();
void reset(); void reset();
bool isModelChanged() const; bool isModelChanged() const;
@@ -51,7 +51,7 @@ private:
PdmUiModelChangeDetector(); PdmUiModelChangeDetector();
private: private:
bool m_modelIsChanged; bool m_isModelChanged;
}; };
} // End of namespace caf } // End of namespace caf