multi select for service item

This commit is contained in:
Chris Cochrun 2023-01-23 21:35:34 -06:00
parent 50c17705f6
commit 02c4c8a47a
3 changed files with 49 additions and 3 deletions

View file

@ -510,6 +510,35 @@ bool ServiceItemModel::select(int id) {
return true;
}
bool ServiceItemModel::selectItems(QVariantList items) {
qDebug() << "Let's select some items!";
for (int i = 0; i < m_items.length(); i++) {
QModelIndex idx = index(i);
ServiceItem *item = m_items[idx.row()];
if (item->selected()) {
item->setSelected(false);
qDebug() << "################";
qDebug() << "deselected" << item->name();
qDebug() << "################";
emit dataChanged(idx, idx, QVector<int>() << SelectedRole);
}
}
qDebug() << "All things have been deselected";
foreach (QVariant it, items) {
int i = it.toInt();
QModelIndex idx = index(i);
ServiceItem *item = m_items[idx.row()];
if (!item->selected()) {
item->setSelected(true);
qDebug() << "################";
qDebug() << "selected" << item->name();
qDebug() << "################";
emit dataChanged(idx, idx, QVector<int>() << SelectedRole);
}
}
return true;
}
bool ServiceItemModel::activate(int id) {
QModelIndex idx = index(id);
ServiceItem *item = m_items[idx.row()];

View file

@ -99,6 +99,7 @@ public:
Q_INVOKABLE bool moveDown(int index);
Q_INVOKABLE bool moveUp(int index);
Q_INVOKABLE bool select(int id);
Q_INVOKABLE bool selectItems(QVariantList items);
Q_INVOKABLE bool activate(int id);
Q_INVOKABLE bool deactivate(int id);
Q_INVOKABLE QVariantMap getItem(int index) const;