From 3633474dc23f402b50d10ce1fdd78d80481d2046 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 7 Sep 2017 07:32:42 +0200 Subject: [PATCH] #1830 AppFwk : Expand tree if item count has changed --- .../cafTestApplication/MainWindow.cpp | 30 +++++++++---------- .../cafPdmUiTreeSelectionEditor.cpp | 8 +++++ .../cafPdmUiTreeSelectionQModel.cpp | 18 +++++++---- .../cafPdmUiTreeSelectionQModel.h | 2 ++ 4 files changed, 36 insertions(+), 22 deletions(-) diff --git a/Fwk/AppFwk/cafTests/cafTestApplication/MainWindow.cpp b/Fwk/AppFwk/cafTests/cafTestApplication/MainWindow.cpp index 822b461fda..79e840913c 100644 --- a/Fwk/AppFwk/cafTests/cafTestApplication/MainWindow.cpp +++ b/Fwk/AppFwk/cafTests/cafTestApplication/MainWindow.cpp @@ -58,7 +58,7 @@ public: { CAF_PDM_InitObject("Small Demo Object", ":/images/win/filenew.png", "This object is a demo of the CAF framework", "This object is a demo of the CAF framework"); - CAF_PDM_InitField(&m_toggleField, "Toggle", false, "Toggle Field", "", "Toggle Field tooltip", " Toggle Field whatsthis"); + CAF_PDM_InitField(&m_toggleField, "Toggle", false, "Add Items To Multi Select", "", "Toggle Field tooltip", " Toggle Field whatsthis"); CAF_PDM_InitField(&m_doubleField, "BigNumber", 0.0, "Big Number", "", "Enter a big number here", "This is a place you can enter a big real value if you want" ); CAF_PDM_InitField(&m_intField, "IntNumber", 0, "Small Number", "", "Enter some small number here", "This is a place you can enter a small integer value if you want"); CAF_PDM_InitField(&m_textField, "TextField", QString(""), "Text", "", "Text tooltip", "This is a place you can enter a small integer value if you want"); @@ -138,20 +138,7 @@ public: options.push_back(itemInfo); } -/* - static int s_additionalSubItems = 0; - s_additionalSubItems++; - for (auto i = 0; i < s_additionalSubItems; i++) - { - text = "Second_b_" + QString::number(i); - caf::PdmOptionItemInfo itemInfo = caf::PdmOptionItemInfo(text, text); - itemInfo.setLevel(1); - options.push_back(itemInfo); - } -*/ - - - int additionalSubItems = 0; + int additionalSubItems = 2; for (auto i = 0; i < additionalSubItems; i++) { text = "Second_b_" + QString::number(i); @@ -160,7 +147,18 @@ public: options.push_back(itemInfo); } - + static int s_additionalSubItems = 0; + if (m_toggleField()) + { + s_additionalSubItems++; + } + for (auto i = 0; i < s_additionalSubItems; i++) + { + text = "Second_b_" + QString::number(i); + caf::PdmOptionItemInfo itemInfo = caf::PdmOptionItemInfo(text, text); + itemInfo.setLevel(1); + options.push_back(itemInfo); + } text = "Third"; options.push_back(caf::PdmOptionItemInfo(text, text)); diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeSelectionEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeSelectionEditor.cpp index 94e5295b43..8583d3a722 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeSelectionEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeSelectionEditor.cpp @@ -87,9 +87,17 @@ void PdmUiTreeSelectionEditor::configureAndUpdateUi(const QString& uiConfigName) caf::PdmUiTreeSelectionQModel* treeSelectionQModel = dynamic_cast(m_treeView->model()); if (treeSelectionQModel) { + bool itemCountHasChaged = false; + if (treeSelectionQModel->optionItemCount() != options.size()) itemCountHasChaged = true; + // TODO: If the count is different between incoming and current list of items, // use cafQTreeViewStateSerializer to restore collapsed state treeSelectionQModel->setOptions(this, options); + + if (itemCountHasChaged) + { + m_treeView->expandAll(); + } } } diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeSelectionQModel.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeSelectionQModel.cpp index 2c4b50d886..e873740d3d 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeSelectionQModel.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeSelectionQModel.cpp @@ -58,10 +58,10 @@ caf::PdmUiTreeSelectionQModel::PdmUiTreeSelectionQModel(QObject *parent /*= 0*/) //-------------------------------------------------------------------------------------------------- void caf::PdmUiTreeSelectionQModel::setOptions(caf::PdmUiFieldEditorHandle* field, const QList& options) { - bool itemCountIsChanged = false; - if (m_options.size() != options.size()) + bool itemCountHasChanged = false; + if (optionItemCount() != options.size()) { - itemCountIsChanged = true; + itemCountHasChanged = true; } m_uiFieldHandle = field; @@ -69,12 +69,20 @@ void caf::PdmUiTreeSelectionQModel::setOptions(caf::PdmUiFieldEditorHandle* fiel computeOptionItemTreeData(); - if (itemCountIsChanged) + if (itemCountHasChanged) { reset(); } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +int caf::PdmUiTreeSelectionQModel::optionItemCount() const +{ + return m_options.size(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -198,8 +206,6 @@ bool caf::PdmUiTreeSelectionQModel::setData(const QModelIndex &index, const QVar emit signalSelectionStateForIndexHasChanged(toOptionItemIndex(index), isSelected); - emit dataChanged(index, index); - return true; } diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeSelectionQModel.h b/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeSelectionQModel.h index 0efe26f7c2..f4f7b1fece 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeSelectionQModel.h +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiTreeSelectionQModel.h @@ -72,6 +72,8 @@ public: void setOptions(caf::PdmUiFieldEditorHandle* field, const QList& options); + int optionItemCount() const; + virtual Qt::ItemFlags flags(const QModelIndex &index) const override; virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override;