diff --git a/src/blackgui/models/listmodelbase.cpp b/src/blackgui/models/listmodelbase.cpp index b72f97a58..247225ec7 100644 --- a/src/blackgui/models/listmodelbase.cpp +++ b/src/blackgui/models/listmodelbase.cpp @@ -97,12 +97,12 @@ namespace BlackGui * Update */ template - int CListModelBase::update(const ContainerType &container) + int CListModelBase::update(const ContainerType &container, bool sort) { // KWB remove: qDebug() will be removed soon qDebug() << "update" << this->objectName() << "size" << container.size(); this->beginResetModel(); - this->m_container = (container.size() > 1 && this->hasValidSortColumn() ? + this->m_container = (sort && container.size() > 1 && this->hasValidSortColumn() ? this->sortListByColumn(container, this->getSortColumn(), this->m_sortOrder) : container); this->endResetModel(); @@ -192,12 +192,8 @@ namespace BlackGui Q_ASSERT(!propertyIndex.isEmpty()); if (propertyIndex.isEmpty()) return list; // at release build do nothing - // KWB: qDebug() will be removed soon - qDebug() << "sort" << this->objectName() << "column" << column << propertyIndex.toQString(); - // sort the values - return list.sorted - ([ = ](const ObjectType & a, const ObjectType & b) -> bool + auto p = [ = ](const ObjectType & a, const ObjectType & b) -> bool { QVariant aQv = a.propertyByIndex(propertyIndex); QVariant bQv = b.propertyByIndex(propertyIndex); @@ -205,8 +201,11 @@ namespace BlackGui BlackMisc::compareQVariants(aQv, bQv) : BlackMisc::compareQVariants(bQv, aQv); return compare < 0; - } - ); // sorted + }; + + // KWB: qDebug() will be removed soon + qDebug() << "sort" << this->objectName() << "column" << column << propertyIndex.toQString(); + return list.sorted(p); // synchronous sorted } /* diff --git a/src/blackgui/models/listmodelbase.h b/src/blackgui/models/listmodelbase.h index 3611b7d35..5912a6a93 100644 --- a/src/blackgui/models/listmodelbase.h +++ b/src/blackgui/models/listmodelbase.h @@ -92,8 +92,8 @@ namespace BlackGui Qt::ItemFlags flags(const QModelIndex &index) const override; //! Update by new container - //! \remarks a sorting is performed if a valid sort column is set - virtual int update(const ContainerType &container); + //! \remarks a sorting is performed only if a valid sort column is set + virtual int update(const ContainerType &container, bool sort = true); //! Update single element virtual void update(const QModelIndex &index, const ObjectType &object); diff --git a/src/blackgui/views/viewbase.h b/src/blackgui/views/viewbase.h index ee3ba1aea..6ba7dea64 100644 --- a/src/blackgui/views/viewbase.h +++ b/src/blackgui/views/viewbase.h @@ -84,10 +84,10 @@ namespace BlackGui virtual void clear() override { Q_ASSERT(this->m_model); this->m_model->clear(); } //! Update whole container - template int updateContainer(const ContainerType &container, bool resize = true) + template int updateContainer(const ContainerType &container, bool sort = true, bool resize = true) { Q_ASSERT(this->m_model); - int c = this->m_model->update(container); + int c = this->m_model->update(container, sort); if (!resize) return c; this->resizeColumnsToContents(); this->resizeRowsToContents();