refs #325 added sort flag for models / views, allow to update, but not to sort

This commit is contained in:
Klaus Basan
2014-10-02 17:43:51 +02:00
parent 053c248f06
commit 2a11411bc0
3 changed files with 12 additions and 13 deletions

View File

@@ -97,12 +97,12 @@ namespace BlackGui
* Update
*/
template <typename ObjectType, typename ContainerType>
int CListModelBase<ObjectType, ContainerType>::update(const ContainerType &container)
int CListModelBase<ObjectType, ContainerType>::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
}
/*

View File

@@ -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);

View File

@@ -84,10 +84,10 @@ namespace BlackGui
virtual void clear() override { Q_ASSERT(this->m_model); this->m_model->clear(); }
//! Update whole container
template<class ContainerType> int updateContainer(const ContainerType &container, bool resize = true)
template<class ContainerType> 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();