Sort devices alphabetically in KCM

This commit is contained in:
Albert Vaca 2015-03-22 23:08:37 -07:00
parent b38939fce8
commit 60d85932db

View file

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