2013-08-16 05:23:54 +01:00
|
|
|
/**
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2013 Albert Vaca <albertvaka@gmail.com>
|
2013-08-15 23:25:13 +01:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2013-08-15 23:25:13 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "devicessortproxymodel.h"
|
2013-08-21 17:25:44 +01:00
|
|
|
|
2019-04-30 18:03:24 +01:00
|
|
|
#include "dbusinterfaces.h"
|
|
|
|
#include "devicesmodel.h"
|
2013-08-15 23:25:13 +01:00
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
DevicesSortProxyModel::DevicesSortProxyModel(DevicesModel *devicesModel)
|
2013-08-15 23:25:13 +01:00
|
|
|
: QSortFilterProxyModel(devicesModel)
|
|
|
|
{
|
|
|
|
setSourceModel(devicesModel);
|
2019-05-04 16:37:13 +01:00
|
|
|
setSortRole(DevicesModel::StatusModelRole);
|
2013-08-15 23:25:13 +01:00
|
|
|
sort(0);
|
|
|
|
}
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
bool DevicesSortProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
2013-08-15 23:25:13 +01:00
|
|
|
{
|
2022-09-10 22:23:52 +01:00
|
|
|
QAbstractItemModel *model = sourceModel();
|
|
|
|
Q_ASSERT(qobject_cast<DevicesModel *>(model));
|
2015-03-23 06:08:37 +00:00
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
// Show connected devices first
|
2015-03-23 06:08:37 +00:00
|
|
|
int statusLeft = model->data(left, DevicesModel::StatusModelRole).toInt();
|
|
|
|
int statusRight = model->data(right, DevicesModel::StatusModelRole).toInt();
|
|
|
|
|
|
|
|
if (statusLeft != statusRight) {
|
|
|
|
return statusLeft > statusRight;
|
|
|
|
}
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
// Fallback to alphabetical order
|
2015-03-23 06:08:37 +00:00
|
|
|
QString nameLeft = model->data(left, DevicesModel::NameModelRole).toString();
|
|
|
|
QString nameRight = model->data(right, DevicesModel::NameModelRole).toString();
|
|
|
|
|
|
|
|
return nameLeft > nameRight;
|
2013-08-15 23:25:13 +01:00
|
|
|
}
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
bool DevicesSortProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
|
2013-08-15 23:25:13 +01:00
|
|
|
{
|
|
|
|
Q_UNUSED(source_row);
|
|
|
|
Q_UNUSED(source_parent);
|
2022-09-10 22:23:52 +01:00
|
|
|
// Possible to-do: Implement filter
|
2013-08-15 23:25:13 +01:00
|
|
|
return true;
|
|
|
|
}
|
2023-07-26 09:15:11 +01:00
|
|
|
|
|
|
|
#include "moc_devicessortproxymodel.cpp"
|