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; 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) { bool ServiceItemModel::activate(int id) {
QModelIndex idx = index(id); QModelIndex idx = index(id);
ServiceItem *item = m_items[idx.row()]; ServiceItem *item = m_items[idx.row()];

View file

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

View file

@ -240,7 +240,9 @@ Item {
onClicked: { onClicked: {
if (mouse.button === Qt.RightButton) if (mouse.button === Qt.RightButton)
rightClickMenu.popup(mouse); rightClickMenu.popup(mouse);
else { else if ((mouse.button === Qt.LeftButton) && (mouse.modifiers === Qt.ShiftModifier)) {
selectItems(index);
} else {
serviceItemList.currentIndex = index; serviceItemList.currentIndex = index;
ServiceItemModel.select(index); ServiceItemModel.select(index);
} }
@ -577,7 +579,21 @@ Item {
/* totalServiceItems++; */ /* totalServiceItems++; */
} }
function changeItem() { function selectItems(index) {
if (index === serviceItemList.currentIndex)
return;
var arr = [];
if (index > serviceItemList.currentIndex) {
for (let i = serviceItemList.currentIndex; i < index + 1; i++) {
arr.push(i);
console.log("Select all these here items..." + arr);
}
} else {
for (let i = serviceItemList.currentIndex; i > index - 1; i--) {
arr.push(i);
console.log("Select all these here items..." + arr);
}
}
ServiceItemModel.selectItems(arr);
} }
} }