From 58b062cbdf7878fdae85eae10d0e421aa7356d55 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 26 Oct 2017 07:20:03 +0200 Subject: [PATCH] #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 --- .../cafPdmUiCore/cafPdmUiItem.cpp | 11 +++++ .../cafPdmUiCore/cafPdmUiItem.h | 4 ++ .../cafPdmUiObjectEditorHandle.cpp | 40 +++++++++++++++++++ .../cafPdmUiCore/cafPdmUiObjectEditorHandle.h | 21 ++++++---- .../cafTestApplication/MainWindow.cpp | 6 +++ 5 files changed, 74 insertions(+), 8 deletions(-) diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.cpp b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.cpp index 8f90069d98..49834a6061 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.cpp +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.cpp @@ -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(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.h index f41747f3df..d25e4d2198 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiItem.h @@ -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 diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiObjectEditorHandle.cpp b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiObjectEditorHandle.cpp index 3147073b3b..4e7afdbf45 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiObjectEditorHandle.cpp +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiObjectEditorHandle.cpp @@ -43,6 +43,23 @@ namespace caf { +std::set> 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 diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiObjectEditorHandle.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiObjectEditorHandle.h index 82cee1cf95..d09acd52de 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiObjectEditorHandle.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiObjectEditorHandle.h @@ -55,27 +55,32 @@ class PdmObjectHandle; /// Abstract class to handle editors for complete PdmObjects //================================================================================================== -class PdmUiObjectEditorHandle: public PdmUiEditorHandle +class PdmUiObjectEditorHandle : public PdmUiEditorHandle { public: - PdmUiObjectEditorHandle() {} - ~PdmUiObjectEditorHandle() {} + PdmUiObjectEditorHandle(); + virtual ~PdmUiObjectEditorHandle(); - QWidget* getOrCreateWidget(QWidget* parent); - QWidget* widget() { return m_widget; } + QWidget* getOrCreateWidget(QWidget* parent); + 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 QWidget* createWidget(QWidget* parent) = 0; - virtual void cleanupBeforeSettingPdmObject() {}; + virtual void cleanupBeforeSettingPdmObject() {}; -protected: +private: QPointer m_widget; + + static std::set> m_sRegisteredObjectEditors; }; diff --git a/Fwk/AppFwk/cafTests/cafTestApplication/MainWindow.cpp b/Fwk/AppFwk/cafTests/cafTestApplication/MainWindow.cpp index c6b15ec90f..86055f365e 100644 --- a/Fwk/AppFwk/cafTests/cafTestApplication/MainWindow.cpp +++ b/Fwk/AppFwk/cafTests/cafTestApplication/MainWindow.cpp @@ -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; } //--------------------------------------------------------------------------------------------------