mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 01:05:34 +08:00
refs #768, allow reselection of values when a view is sorted
* reselect callbacks * remark: Only working in some cases as sorting is part of the model, while selection is part of the view (and sorting can take place without the view knowing the model is sorted) * allow to sort by property index * renamed to m_sortColumn
This commit is contained in:
@@ -132,9 +132,15 @@ namespace BlackGui
|
||||
return this->columnToPropertyIndex(index.column());
|
||||
}
|
||||
|
||||
void CListModelBaseNonTemplate::sortByPropertyIndex(const CPropertyIndex &propertyIndex, Qt::SortOrder order)
|
||||
{
|
||||
const int column = this->propertyIndexToColumn(propertyIndex);
|
||||
this->sort(column, order);
|
||||
}
|
||||
|
||||
void CListModelBaseNonTemplate::setSortColumnByPropertyIndex(const BlackMisc::CPropertyIndex &propertyIndex)
|
||||
{
|
||||
this->m_sortedColumn = this->m_columns.propertyIndexToColumn(propertyIndex);
|
||||
this->m_sortColumn = this->m_columns.propertyIndexToColumn(propertyIndex);
|
||||
}
|
||||
|
||||
void CListModelBaseNonTemplate::setSorting(const CPropertyIndex &propertyIndex, Qt::SortOrder order)
|
||||
@@ -146,8 +152,8 @@ namespace BlackGui
|
||||
bool CListModelBaseNonTemplate::hasValidSortColumn() const
|
||||
{
|
||||
|
||||
if (!(this->m_sortedColumn >= 0 && this->m_sortedColumn < this->m_columns.size())) { return false; }
|
||||
return this->m_columns.isSortable(this->m_sortedColumn);
|
||||
if (!(this->m_sortColumn >= 0 && this->m_sortColumn < this->m_columns.size())) { return false; }
|
||||
return this->m_columns.isSortable(this->m_sortColumn);
|
||||
}
|
||||
|
||||
Qt::ItemFlags CListModelBaseNonTemplate::flags(const QModelIndex &index) const
|
||||
@@ -223,7 +229,7 @@ namespace BlackGui
|
||||
}
|
||||
|
||||
CListModelBaseNonTemplate::CListModelBaseNonTemplate(const QString &translationContext, QObject *parent)
|
||||
: QStandardItemModel(parent), m_columns(translationContext), m_sortedColumn(-1), m_sortOrder(Qt::AscendingOrder)
|
||||
: QStandardItemModel(parent), m_columns(translationContext), m_sortColumn(-1), m_sortOrder(Qt::AscendingOrder)
|
||||
{
|
||||
// non unique default name, set translation context as default
|
||||
this->setObjectName(translationContext);
|
||||
@@ -339,7 +345,7 @@ namespace BlackGui
|
||||
const QModelIndex topLeft = index.sibling(index.row(), 0);
|
||||
const QModelIndex bottomRight = index.sibling(index.row(), this->columnCount() - 1);
|
||||
this->m_container[index.row()] = obj;
|
||||
const CVariant co = CVariant::from(obj);
|
||||
const CVariant co = CVariant::fromValue(obj);
|
||||
emit objectChanged(co, propertyIndex);
|
||||
emit this->dataChanged(topLeft, bottomRight);
|
||||
this->updateFilteredContainer();
|
||||
@@ -417,7 +423,7 @@ namespace BlackGui
|
||||
worker->thenWithResult<ContainerType>(this, [this](const ContainerType & sortedContainer)
|
||||
{
|
||||
if (this->m_modelDestroyed) { return; }
|
||||
this->ps_updateContainer(CVariant::from(sortedContainer), false);
|
||||
this->ps_updateContainer(CVariant::fromValue(sortedContainer), false);
|
||||
});
|
||||
worker->then(this, &CListModelBase::asyncUpdateFinished);
|
||||
return worker;
|
||||
@@ -660,11 +666,11 @@ namespace BlackGui
|
||||
template <typename ObjectType, typename ContainerType, bool UseCompare>
|
||||
void CListModelBase<ObjectType, ContainerType, UseCompare>::sort(int column, Qt::SortOrder order)
|
||||
{
|
||||
if (column == this->m_sortedColumn && order == this->m_sortOrder) { return; }
|
||||
if (column == this->m_sortColumn && order == this->m_sortOrder) { return; }
|
||||
|
||||
// new order
|
||||
this->m_sortedColumn = column;
|
||||
this->m_sortOrder = order;
|
||||
this->m_sortColumn = column;
|
||||
this->m_sortOrder = order;
|
||||
if (this->m_container.size() < 2)
|
||||
{
|
||||
return; // nothing to do
|
||||
|
||||
@@ -77,7 +77,10 @@ namespace BlackGui
|
||||
virtual BlackMisc::CPropertyIndex modelIndexToPropertyIndex(const QModelIndex &index) const;
|
||||
|
||||
//! Set sort column
|
||||
virtual void setSortColumn(int column) { this->m_sortedColumn = column; }
|
||||
virtual void setSortColumn(int column) { this->m_sortColumn = column; }
|
||||
|
||||
//! Sort by index
|
||||
void sortByPropertyIndex(const BlackMisc::CPropertyIndex &propertyIndex, Qt::SortOrder order = Qt::AscendingOrder);
|
||||
|
||||
//! Set column for sorting
|
||||
//! \param propertyIndex index of column to be sorted
|
||||
@@ -87,7 +90,7 @@ namespace BlackGui
|
||||
virtual void setSorting(const BlackMisc::CPropertyIndex &propertyIndex, Qt::SortOrder order = Qt::AscendingOrder);
|
||||
|
||||
//! Get sort column property index
|
||||
virtual int getSortColumn() const { return this->m_sortedColumn; }
|
||||
virtual int getSortColumn() const { return this->m_sortColumn; }
|
||||
|
||||
//! Has valid sort column?
|
||||
virtual bool hasValidSortColumn() const;
|
||||
@@ -128,6 +131,7 @@ namespace BlackGui
|
||||
void asyncUpdateFinished();
|
||||
|
||||
//! Data changed
|
||||
//! \remark passing back selected objects so they can be reselected
|
||||
void modelDataChanged(int count, bool withFilter);
|
||||
|
||||
//! Data changed, digest version
|
||||
@@ -164,7 +168,7 @@ namespace BlackGui
|
||||
virtual int performUpdateContainer(const BlackMisc::CVariant &variant, bool sort) = 0;
|
||||
|
||||
CColumns m_columns; //!< columns metadata
|
||||
int m_sortedColumn; //!< currently sorted column
|
||||
int m_sortColumn; //!< currently sorted column
|
||||
bool m_modelDestroyed = false; //!< model is about to be destroyed
|
||||
Qt::SortOrder m_sortOrder; //!< sort order (asc/desc)
|
||||
Qt::DropActions m_dropActions = Qt::IgnoreAction; //!< drop actions
|
||||
@@ -303,7 +307,7 @@ namespace BlackGui
|
||||
//! Update filtered container
|
||||
void updateFilteredContainer();
|
||||
|
||||
//! Row count changed
|
||||
//! Model changed
|
||||
void emitModelDataChanged();
|
||||
|
||||
std::unique_ptr<IModelFilter<ContainerType> > m_filter; //!< Used filter
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace BlackGui
|
||||
this->m_columns.addColumn(CColumn::standardString("category", CStatusMessage::IndexCategoryHumanReadableOrTechnicalAsString));
|
||||
this->m_columns.addColumn(CColumn::standardString("message", CStatusMessage::IndexMessage));
|
||||
|
||||
this->m_sortedColumn = CStatusMessage::IndexUtcTimestamp;
|
||||
this->m_sortColumn = CStatusMessage::IndexUtcTimestamp;
|
||||
this->m_sortOrder = Qt::DescendingOrder;
|
||||
}
|
||||
break;
|
||||
@@ -61,7 +61,7 @@ namespace BlackGui
|
||||
this->m_columns.addColumn(col);
|
||||
this->m_columns.addColumn(CColumn::standardString("message", CStatusMessage::IndexMessage));
|
||||
|
||||
this->m_sortedColumn = CStatusMessage::IndexUtcTimestamp;
|
||||
this->m_sortColumn = CStatusMessage::IndexUtcTimestamp;
|
||||
this->m_sortOrder = Qt::DescendingOrder;
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user