multi select for service item
This commit is contained in:
parent
50c17705f6
commit
02c4c8a47a
3 changed files with 49 additions and 3 deletions
|
@ -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()];
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -240,7 +240,9 @@ Item {
|
|||
onClicked: {
|
||||
if (mouse.button === Qt.RightButton)
|
||||
rightClickMenu.popup(mouse);
|
||||
else {
|
||||
else if ((mouse.button === Qt.LeftButton) && (mouse.modifiers === Qt.ShiftModifier)) {
|
||||
selectItems(index);
|
||||
} else {
|
||||
serviceItemList.currentIndex = index;
|
||||
ServiceItemModel.select(index);
|
||||
}
|
||||
|
@ -577,7 +579,21 @@ Item {
|
|||
/* 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue