summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Nicoletti <[email protected]>2018-01-27 00:17:51 -0200
committerDaniel Nicoletti <[email protected]>2018-01-27 00:17:51 -0200
commit2f85d739082587b994dabd55ed06762252e838b2 (patch)
tree500ddc0eceb649a8d93c487a0fff509a29488609
parentad261afa38dee796781eb8ec8cf39e0d393c4faf (diff)
Change sort order when adding a new printer
-rw-r--r--add-printer/DevicesModel.cpp23
-rw-r--r--add-printer/DevicesModel.h9
2 files changed, 22 insertions, 10 deletions
diff --git a/add-printer/DevicesModel.cpp b/add-printer/DevicesModel.cpp
index 74e0838..4ecf6ea 100644
--- a/add-printer/DevicesModel.cpp
+++ b/add-printer/DevicesModel.cpp
@@ -289,18 +289,19 @@ QStandardItem *DevicesModel::createItem(const QString &device_class,
QStandardItem *catItem;
switch (kind) {
case Networked:
- catItem = findCreateCategory(i18nc("@item", "Discovered Network Printers"));
+ catItem = findCreateCategory(i18nc("@item", "Discovered Network Printers"), kind);
catItem->appendRow(stdItem);
break;
case OtherNetworked:
- catItem = findCreateCategory(i18nc("@item", "Other Network Printers"));
+ catItem = findCreateCategory(i18nc("@item", "Other Network Printers"), kind);
catItem->appendRow(stdItem);
break;
case Local:
- catItem = findCreateCategory(i18nc("@item", "Local Printers"));
+ catItem = findCreateCategory(i18nc("@item", "Local Printers"), kind);
catItem->appendRow(stdItem);
break;
default:
+ stdItem->setData(kind, Qt::UserRole);
appendRow(stdItem);
}
@@ -357,21 +358,31 @@ void DevicesModel::groupedDevicesFallback()
}
}
-QStandardItem* DevicesModel::findCreateCategory(const QString &category)
+QStandardItem* DevicesModel::findCreateCategory(const QString &category, Kind kind)
{
for (int i = 0; i < rowCount(); ++i) {
QStandardItem *catItem = item(i);
- if (catItem->text() == category) {
+ if (catItem->data(Qt::UserRole).toInt() == kind) {
return catItem;
}
}
+ int pos = 0;
+ for (int i = 0; i < rowCount(); ++i, ++pos) {
+ QStandardItem *catItem = item(i);
+ if (catItem->data(Qt::UserRole).toInt() > kind) {
+ pos = i;
+ break;
+ }
+ }
+
auto catItem = new QStandardItem(category);
QFont font = catItem->font();
font.setBold(true);
catItem->setFont(font);
+ catItem->setData(kind, Qt::UserRole);
catItem->setFlags(Qt::ItemIsEnabled);
- appendRow(catItem);
+ insertRow(pos, catItem);
// Emit the parent so the view expand the item
emit parentAdded(indexFromItem(catItem));
diff --git a/add-printer/DevicesModel.h b/add-printer/DevicesModel.h
index ab38642..c55983b 100644
--- a/add-printer/DevicesModel.h
+++ b/add-printer/DevicesModel.h
@@ -33,7 +33,6 @@ class KCupsRequest;
class DevicesModel : public QStandardItemModel
{
Q_OBJECT
- Q_ENUMS(Role)
public:
enum Role {
DeviceClass = Qt::UserRole + 2,
@@ -44,13 +43,15 @@ public:
DeviceUris,
DeviceLocation
};
+ Q_ENUM(Role)
enum Kind {
+ Other,
Local,
Networked,
- OtherNetworked,
- Other
+ OtherNetworked
};
+ Q_ENUM(Kind)
explicit DevicesModel(QObject *parent = 0);
@@ -96,7 +97,7 @@ private slots:
void groupedDevicesFallback();
private:
- QStandardItem *findCreateCategory(const QString &category);
+ QStandardItem *findCreateCategory(const QString &category, Kind kind);
KCupsRequest *m_request;
MapSMapSS m_mappedDevices;