diff --git a/src/blackgui/models/listmodelbase.cpp b/src/blackgui/models/listmodelbase.cpp index 2bd32f24d..7fb18b469 100644 --- a/src/blackgui/models/listmodelbase.cpp +++ b/src/blackgui/models/listmodelbase.cpp @@ -509,7 +509,31 @@ namespace BlackGui beginInsertRows(QModelIndex(), m_container.size(), m_container.size()); m_container.push_back(object); endInsertRows(); - this->updateFilteredContainer(); + + if (this->hasFilter()) + { + // this will change the whole used model as we cannot predict the filter + this->beginResetModel(); + this->updateFilteredContainer(); + this->endResetModel(); + } + this->emitModelDataChanged(); + } + + template + void CListModelBase::push_back(const ContainerType &container) + { + beginInsertRows(QModelIndex(), m_container.size(), m_container.size()); + m_container.push_back(container); + endInsertRows(); + + if (this->hasFilter()) + { + // this will change the whole used model as we cannot predict the filter + this->beginResetModel(); + this->updateFilteredContainer(); + this->endResetModel(); + } this->emitModelDataChanged(); } @@ -522,6 +546,7 @@ namespace BlackGui if (this->hasFilter()) { + // this will change the whole used model as we cannot predict the filter this->beginResetModel(); this->updateFilteredContainer(); this->endResetModel(); @@ -539,6 +564,7 @@ namespace BlackGui if (this->hasFilter()) { + // this will change the whole used model as we cannot predict the filter this->beginResetModel(); this->updateFilteredContainer(); this->endResetModel(); diff --git a/src/blackgui/models/listmodelbase.h b/src/blackgui/models/listmodelbase.h index 0cdfbcfd9..5ee190400 100644 --- a/src/blackgui/models/listmodelbase.h +++ b/src/blackgui/models/listmodelbase.h @@ -255,6 +255,9 @@ namespace BlackGui //! Similar to ContainerType::push_back virtual void push_back(const ObjectType &object); + //! Similar to ContainerType::push_back + virtual void push_back(const ContainerType &container); + //! Similar to ContainerType::insert here inserts at first position virtual void insert(const ObjectType &object); diff --git a/src/blackgui/views/viewbase.cpp b/src/blackgui/views/viewbase.cpp index 33eb8fcd0..00d3da42b 100644 --- a/src/blackgui/views/viewbase.cpp +++ b/src/blackgui/views/viewbase.cpp @@ -972,6 +972,38 @@ namespace BlackGui } } + template + void CViewBase::push_back(const ObjectType &value, bool resize) + { + Q_ASSERT(m_model); + if (this->rowCount() < 1) + { + // this allows presizing + this->updateContainerMaybeAsync(ContainerType({value}), true, resize); + } + else + { + m_model->push_back(value); + if (resize) { this->performModeBasedResizeToContent(); } + } + } + + template + void CViewBase::push_back(const ContainerType &container, bool resize) + { + Q_ASSERT(m_model); + if (this->rowCount() < 1) + { + // this allows presizing + this->updateContainerMaybeAsync(container, true, resize); + } + else + { + m_model->push_back(container); + if (resize) { this->performModeBasedResizeToContent(); } + } + } + template const ObjectType &CViewBase::at(const QModelIndex &index) const { diff --git a/src/blackgui/views/viewbase.h b/src/blackgui/views/viewbase.h index 5a22a3f15..129d10180 100644 --- a/src/blackgui/views/viewbase.h +++ b/src/blackgui/views/viewbase.h @@ -580,6 +580,12 @@ namespace BlackGui //! Insert void insert(const ContainerType &container, bool resize = true); + //! Push back + void push_back(const ObjectType &value, bool resize = true); + + //! Push back + void push_back(const ContainerType &container, bool resize = true); + //! Value object at const ObjectType &at(const QModelIndex &index) const;