#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 "cafCmdFeatureManager.h"
#include "cafPdmUiModelChangeDetector.h"
#include <QAction>
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

View File

@ -73,27 +73,30 @@ class CmdFeature : public QObject
{
Q_OBJECT
public:
CmdFeature() {}
virtual ~CmdFeature() {}
CmdFeature();
virtual ~CmdFeature();
QAction* action();
QAction* action(QString customText);
void refreshEnabledState();
void refreshCheckedState();
QAction* action();
QAction* action(QString customText);
void refreshEnabledState();
void refreshCheckedState();
bool canFeatureBeExecuted() { return this->isCommandEnabled(); }
bool canFeatureBeExecuted();
public slots:
void actionTriggered(bool isChecked) { this->onActionTriggered(isChecked); }
void actionTriggered(bool isChecked);
protected:
virtual void onActionTriggered(bool isChecked) = 0;
virtual void setupActionLook(QAction* actionToSetup) = 0;
virtual bool isCommandEnabled() = 0;
virtual bool isCommandChecked() { return false; }
virtual void onActionTriggered(bool isChecked) = 0;
virtual void setupActionLook(QAction* actionToSetup) = 0;
virtual bool isCommandEnabled() = 0;
virtual bool isCommandChecked();
void disableModelChangeContribution();
private:
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
this->updateConnectedEditors();
PdmUiModelChangeDetector::instance()->setModelIsChanged();
PdmUiModelChangeDetector::instance()->setModelChanged();
}
}

View File

@ -43,7 +43,7 @@ namespace caf {
///
//--------------------------------------------------------------------------------------------------
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()
{
m_modelIsChanged = false;
m_isModelChanged = false;
}
//--------------------------------------------------------------------------------------------------
@ -78,7 +78,7 @@ void PdmUiModelChangeDetector::reset()
//--------------------------------------------------------------------------------------------------
bool PdmUiModelChangeDetector::isModelChanged() const
{
return m_modelIsChanged;
return m_isModelChanged;
}
} // end namespace caf

View File

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