From 7a8c7cc389388f0e817004bf599af20b26753a69 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Tue, 24 Jan 2023 15:29:56 -0600 Subject: [PATCH] multi select and removal. Slides aren't perfect yet. --- src/cpp/serviceitemmodel.cpp | 16 +++++++++++++++ src/cpp/serviceitemmodel.h | 2 ++ src/cpp/slide.cpp | 2 +- src/cpp/slidemodel.cpp | 33 +++++++++++++++++++++++++++++++ src/cpp/slidemodel.h | 2 ++ src/main.cpp | 4 ++++ src/qml/presenter/ServiceList.qml | 21 ++++++++++++++++++-- 7 files changed, 77 insertions(+), 3 deletions(-) diff --git a/src/cpp/serviceitemmodel.cpp b/src/cpp/serviceitemmodel.cpp index 1604a28..6650bf4 100644 --- a/src/cpp/serviceitemmodel.cpp +++ b/src/cpp/serviceitemmodel.cpp @@ -372,6 +372,22 @@ void ServiceItemModel::removeItem(int index) { endRemoveRows(); } +void ServiceItemModel::removeItems() { + for (int i = m_items.length() - 1; i > -1; i--) { + QModelIndex idx = index(i); + ServiceItem *item = m_items[idx.row()]; + if (item->selected()) { + qDebug() << "Removing item:" << i; + beginRemoveRows(QModelIndex(), i, i); + m_items.removeAt(i); + endRemoveRows(); + emit rowRemoved(i, *item); + qDebug() << "emitted removal of item:" << item->name(); + } + } + +} + bool ServiceItemModel::moveRows(int sourceIndex, int destIndex, int count) { qDebug() << sourceIndex; qDebug() << destIndex; diff --git a/src/cpp/serviceitemmodel.h b/src/cpp/serviceitemmodel.h index 2c173e2..dc46892 100644 --- a/src/cpp/serviceitemmodel.h +++ b/src/cpp/serviceitemmodel.h @@ -95,6 +95,7 @@ public: const QString &audio, const QString &font, const int &fontSize, const int &slideNumber); Q_INVOKABLE void removeItem(int index); + Q_INVOKABLE void removeItems(); Q_INVOKABLE bool moveRows(int sourceIndex, int destIndex, int count); Q_INVOKABLE bool moveDown(int index); Q_INVOKABLE bool moveUp(int index); @@ -114,6 +115,7 @@ signals: void itemAdded(const int &, const ServiceItem &); void itemInserted(const int &, const ServiceItem &); void rowMoved(const int &, const int &, const ServiceItem &); + void rowRemoved(const int &, const ServiceItem &); private: diff --git a/src/cpp/slide.cpp b/src/cpp/slide.cpp index c96e5ab..b288a8b 100644 --- a/src/cpp/slide.cpp +++ b/src/cpp/slide.cpp @@ -112,7 +112,7 @@ void Slide::setServiceItemId(int serviceItemId) if (m_serviceItemId == serviceItemId) return; - qDebug() << "####changing serviceItemId to: " << serviceItemId; + qDebug() << "####changing serviceItemId of" << "to:" << serviceItemId; m_serviceItemId = serviceItemId; emit serviceItemIdChanged(m_serviceItemId); } diff --git a/src/cpp/slidemodel.cpp b/src/cpp/slidemodel.cpp index be5a792..3ac2bd0 100644 --- a/src/cpp/slidemodel.cpp +++ b/src/cpp/slidemodel.cpp @@ -287,6 +287,39 @@ void SlideModel::removeItem(int index) { endRemoveRows(); } +void SlideModel::removeServiceItem(const int &index, const ServiceItem &item) { + qDebug() << "Need to remove serviceItem:" << item.name() << "with" << item.slideNumber() << "slides."; + int id = findSlideIdFromServItm(index); + if (item.slideNumber() > 1) { + for (int i = item.slideNumber() + id; i > id - 1; i--) { + qDebug() << "Removing serviceItem:" << i; + beginRemoveRows(QModelIndex(), i, i); + m_items.removeAt(i); + endRemoveRows(); + m_items[i]->setServiceItemId(index); + } + } else { + qDebug() << "Removing serviceItem:" << id; + beginRemoveRows(QModelIndex(), id, id); + m_items.removeAt(id); + endRemoveRows(); + m_items[id]->setServiceItemId(index); + } +} + +void SlideModel::removeItems() { + for (int i = m_items.length() - 1; i > -1; i--) { + QModelIndex idx = index(i); + Slide *item = m_items[idx.row()]; + if (item->selected()) { + qDebug() << "Removing item:" << i; + beginRemoveRows(QModelIndex(), i, i); + m_items.removeAt(i); + endRemoveRows(); + } + } +} + bool SlideModel::moveRows(int sourceIndex, int destIndex, int count) { qDebug() << index(sourceIndex).row(); qDebug() << index(destIndex).row(); diff --git a/src/cpp/slidemodel.h b/src/cpp/slidemodel.h index 8423200..226b04c 100644 --- a/src/cpp/slidemodel.h +++ b/src/cpp/slidemodel.h @@ -72,6 +72,7 @@ public: const int &slideIndex, const int &imageCount); Q_INVOKABLE void removeItem(int index); + Q_INVOKABLE void removeItems(); Q_INVOKABLE bool moveRows(int sourceIndex, int destIndex, int count); Q_INVOKABLE bool moveDown(int index); Q_INVOKABLE bool moveUp(int index); @@ -84,6 +85,7 @@ public slots: Q_INVOKABLE bool select(int id); Q_INVOKABLE bool activate(int id); Q_INVOKABLE bool deactivate(int id); + Q_INVOKABLE void removeServiceItem(const int &index, const ServiceItem &item); void addItemFromService(const int &index, const ServiceItem &item); void insertItemFromService(const int &index, const ServiceItem &item); void moveRowFromService(const int &fromIndex, const int &toIndex, const ServiceItem &item); diff --git a/src/main.cpp b/src/main.cpp index 3388d16..9c02971 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -155,6 +155,10 @@ int main(int argc, char *argv[]) SIGNAL(rowMoved(const int&, const int&, const ServiceItem&)), slideModel.get(), SLOT(moveRowFromService(const int&, const int&, const ServiceItem&))); + QObject::connect(serviceItemModel.get(), + SIGNAL(rowRemoved(const int&, const ServiceItem&)), + slideModel.get(), + SLOT(removeServiceItem(const int&, const ServiceItem&))); bool loading = serviceItemModel.get()->loadLastSaved(); diff --git a/src/qml/presenter/ServiceList.qml b/src/qml/presenter/ServiceList.qml index 6539b77..c0a4d80 100644 --- a/src/qml/presenter/ServiceList.qml +++ b/src/qml/presenter/ServiceList.qml @@ -90,6 +90,8 @@ Item { implicitWidth: serviceItemList.width height: Kirigami.Units.gridUnit * 2 + property var selectedItems + DropArea { id: serviceDrop anchors.fill: parent @@ -238,8 +240,13 @@ Item { } onClicked: { - if (mouse.button === Qt.RightButton) + if (mouse.button === Qt.RightButton) { + if (!selected) { + serviceItemList.currentIndex = index; + ServiceItemModel.select(index); + } rightClickMenu.popup(mouse); + } else if ((mouse.button === Qt.LeftButton) && (mouse.modifiers === Qt.ShiftModifier)) { selectItems(index); } else { @@ -276,9 +283,15 @@ Item { id: rightClickMenu x: mouse.mouseX y: mouse.mouseY + 10 + Kirigami.Action { + text: "copy" + } + Kirigami.Action { + text: "paste" + } Kirigami.Action { text: "delete" - onTriggered: removeItem(index); + onTriggered: removeItems() } } } @@ -513,6 +526,10 @@ Item { /* totalServiceItems--; */ } + function removeItems() { + ServiceItemModel.removeItems(); + } + function addItem(index, name, type, background, backgroundType, text, audio, font, fontSize, itemID) {