#2037 AppFwk : Add support for calling updateUi on all object editors

This function is intended to be called when an object is created or deleted to make sure object editors holds valid data
This commit is contained in:
Magne Sjaastad 2017-10-26 07:20:03 +02:00
parent 57a5f7fc66
commit 58b062cbdf
5 changed files with 74 additions and 8 deletions

View File

@ -38,6 +38,7 @@
#include "cafPdmUiItem.h"
#include "cafPdmUiEditorHandle.h"
#include "cafPdmPtrField.h"
#include "cafPdmUiObjectEditorHandle.h"
namespace caf
{
@ -350,6 +351,16 @@ void PdmUiItem::updateConnectedEditors()
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmUiItem::updateAllRequiredEditors()
{
updateConnectedEditors();
PdmUiObjectEditorHandle::updateUiAllObjectEditors();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -229,8 +229,12 @@ public:
virtual bool isUiGroup() { return false; }
/// Intended to be called when fields in an object has been changed
void updateConnectedEditors();
/// Intended to be called when an object has been created or deleted
void updateAllRequiredEditors();
void updateUiIconFromState(bool isActive, QString uiConfigName = "");
public: // Pdm-Private only

View File

@ -43,6 +43,23 @@
namespace caf
{
std::set<QPointer<PdmUiObjectEditorHandle>> PdmUiObjectEditorHandle::m_sRegisteredObjectEditors;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PdmUiObjectEditorHandle::PdmUiObjectEditorHandle()
{
m_sRegisteredObjectEditors.insert(this);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PdmUiObjectEditorHandle::~PdmUiObjectEditorHandle()
{
m_sRegisteredObjectEditors.erase(this);
}
//--------------------------------------------------------------------------------------------------
///
@ -56,6 +73,14 @@ QWidget* PdmUiObjectEditorHandle::getOrCreateWidget(QWidget* parent)
return m_widget;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QWidget* PdmUiObjectEditorHandle::widget() const
{
return m_widget;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -101,5 +126,20 @@ const caf::PdmObjectHandle* PdmUiObjectEditorHandle::pdmObject() const
}
}
//--------------------------------------------------------------------------------------------------
/// This function is intended to be called after an object has been created or deleted,
/// to ensure all object editors are updated (including valueOptions and UI representation of objects)
//--------------------------------------------------------------------------------------------------
void PdmUiObjectEditorHandle::updateUiAllObjectEditors()
{
for (PdmUiObjectEditorHandle* objEditorHandle : m_sRegisteredObjectEditors)
{
if (objEditorHandle != nullptr)
{
objEditorHandle->updateUi();
}
}
}
} //End of namespace caf

View File

@ -58,24 +58,29 @@ class PdmObjectHandle;
class PdmUiObjectEditorHandle : public PdmUiEditorHandle
{
public:
PdmUiObjectEditorHandle() {}
~PdmUiObjectEditorHandle() {}
PdmUiObjectEditorHandle();
virtual ~PdmUiObjectEditorHandle();
QWidget* getOrCreateWidget(QWidget* parent);
QWidget* widget() { return m_widget; }
QWidget* widget() const;
void setPdmObject(PdmObjectHandle* object);
PdmObjectHandle* pdmObject();
const PdmObjectHandle* pdmObject() const;
/// This function is intended to be called after a PdmObject has been created or deleted
static void updateUiAllObjectEditors();
protected:
/// Supposed to create the top level widget of the editor with a suitable QLayout
virtual QWidget* createWidget(QWidget* parent) = 0;
virtual void cleanupBeforeSettingPdmObject() {};
protected:
private:
QPointer<QWidget> m_widget;
static std::set<QPointer<PdmUiObjectEditorHandle>> m_sRegisteredObjectEditors;
};

View File

@ -726,6 +726,12 @@ MainWindow::~MainWindow()
m_pdmUiTreeView2->setPdmItem(NULL);
m_pdmUiPropertyView->showProperties(NULL);
m_pdmUiTableView->setListField(NULL);
delete m_pdmUiTreeView;
delete m_pdmUiTreeView2;
delete m_pdmUiPropertyView;
delete m_pdmUiTableView;
delete m_customObjectEditor;
}
//--------------------------------------------------------------------------------------------------