Sort devices alphabetically in KCM
This commit is contained in:
parent
b38939fce8
commit
60d85932db
1 changed files with 16 additions and 3 deletions
|
@ -40,10 +40,23 @@ void DevicesSortProxyModel::sourceDataChanged(QModelIndex , QModelIndex )
|
||||||
|
|
||||||
bool DevicesSortProxyModel::lessThan(const QModelIndex& left, const QModelIndex& right) const
|
bool DevicesSortProxyModel::lessThan(const QModelIndex& left, const QModelIndex& right) const
|
||||||
{
|
{
|
||||||
QVariant leftData = sourceModel()->data(left, Qt::InitialSortOrderRole);
|
QAbstractItemModel* model = sourceModel();
|
||||||
QVariant rightData = sourceModel()->data(right, Qt::InitialSortOrderRole);
|
Q_ASSERT(qobject_cast<DevicesModel*>(model));
|
||||||
|
|
||||||
|
//Show connected devices first
|
||||||
|
int statusLeft = model->data(left, DevicesModel::StatusModelRole).toInt();
|
||||||
|
int statusRight = model->data(right, DevicesModel::StatusModelRole).toInt();
|
||||||
|
|
||||||
|
if (statusLeft != statusRight) {
|
||||||
|
return statusLeft > statusRight;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Fallback to alphabetical order
|
||||||
|
QString nameLeft = model->data(left, DevicesModel::NameModelRole).toString();
|
||||||
|
QString nameRight = model->data(right, DevicesModel::NameModelRole).toString();
|
||||||
|
|
||||||
|
return nameLeft > nameRight;
|
||||||
|
|
||||||
return leftData.toInt() > rightData.toInt();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DevicesSortProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
|
bool DevicesSortProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
|
||||||
|
|
Loading…
Reference in a new issue