Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 2f85d739 authored by Daniel Nicoletti's avatar Daniel Nicoletti

Change sort order when adding a new printer

BUG: 384625
parent ad261afa
......@@ -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));
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment