From 13b0b0348a5eebb6ae7df076be4b458ae326b182 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Tue, 18 Oct 2022 16:57:25 -0500 Subject: [PATCH] adding deactivate and inserts default to deactivated and deselected --- src/serviceitemmodel.cpp | 32 ++++++++++++++++++++++++++++++++ src/serviceitemmodel.h | 1 + 2 files changed, 33 insertions(+) diff --git a/src/serviceitemmodel.cpp b/src/serviceitemmodel.cpp index 5dbe753..9318e3e 100644 --- a/src/serviceitemmodel.cpp +++ b/src/serviceitemmodel.cpp @@ -217,12 +217,16 @@ void ServiceItemModel::insertItem(const int &index, ServiceItem *item) { void ServiceItemModel::addItem(const QString &name, const QString &type) { ServiceItem *item = new ServiceItem(name, type); + item->setSelected(false); + item->setActive(false); addItem(item); } void ServiceItemModel::addItem(const QString &name, const QString &type, const QString &background, const QString &backgroundType) { ServiceItem *item = new ServiceItem(name, type, background, backgroundType); + item->setSelected(false); + item->setActive(false); addItem(item); } @@ -230,6 +234,8 @@ void ServiceItemModel::addItem(const QString &name, const QString &type, const QString &background, const QString &backgroundType, const QStringList &text) { ServiceItem *item = new ServiceItem(name, type, background, backgroundType, text); + item->setSelected(false); + item->setActive(false); addItem(item); qDebug() << name << type << background; } @@ -239,6 +245,8 @@ void ServiceItemModel::addItem(const QString &name, const QString &type, const QStringList &text, const QString &audio) { ServiceItem *item = new ServiceItem(name, type, background, backgroundType, text, audio); + item->setSelected(false); + item->setActive(false); addItem(item); qDebug() << name << type << background; } @@ -249,6 +257,8 @@ void ServiceItemModel::addItem(const QString &name, const QString &type, const QString &font, const int &fontSize) { ServiceItem *item = new ServiceItem(name, type, background, backgroundType, text, audio, font, fontSize); + item->setSelected(false); + item->setActive(false); addItem(item); qDebug() << "#################################"; qDebug() << name << type << font << fontSize; @@ -257,6 +267,8 @@ void ServiceItemModel::addItem(const QString &name, const QString &type, void ServiceItemModel::insertItem(const int &index, const QString &name, const QString &type) { ServiceItem *item = new ServiceItem(name, type); + item->setSelected(false); + item->setActive(false); insertItem(index, item); qDebug() << name << type; } @@ -264,6 +276,8 @@ void ServiceItemModel::insertItem(const int &index, const QString &name, const Q void ServiceItemModel::insertItem(const int &index, const QString &name, const QString &type, const QString &background, const QString &backgroundType) { ServiceItem *item = new ServiceItem(name, type, background, backgroundType); + item->setSelected(false); + item->setActive(false); insertItem(index, item); qDebug() << name << type << background; } @@ -282,6 +296,8 @@ void ServiceItemModel::insertItem(const int &index, const QString &name, const QString &audio) { ServiceItem *item = new ServiceItem(name, type, background, backgroundType, text, audio); + item->setSelected(false); + item->setActive(false); insertItem(index, item); qDebug() << name << type << background << text; } @@ -292,6 +308,8 @@ void ServiceItemModel::insertItem(const int &index, const QString &name, const QString &audio, const QString &font, const int &fontSize) { ServiceItem *item = new ServiceItem(name, type, background, backgroundType, text, audio, font, fontSize); + item->setSelected(false); + item->setActive(false); insertItem(index, item); qDebug() << "#################################"; qDebug() << name << type << font << fontSize; @@ -406,6 +424,8 @@ QVariantList ServiceItemModel::getItems() { itm["audio"] = item->audio(); itm["font"] = item->font(); itm["fontSize"] = item->fontSize(); + itm["selected"] = item->selected(); + itm["active"] = item->active(); data.append(itm); } qDebug() << "$$$$$$$$$$$$$$$$$$$$$$$$$$$"; @@ -461,6 +481,18 @@ bool ServiceItemModel::activate(int id) { return true; } +bool ServiceItemModel::deactivate(int id) { + QModelIndex idx = index(id); + ServiceItem *item = m_items[idx.row()]; + + item->setActive(false); + qDebug() << "################"; + qDebug() << "deactivated" << item->name(); + qDebug() << "################"; + emit dataChanged(idx, idx, QVector() << ActiveRole); + return true; +} + bool ServiceItemModel::save(QUrl file) { qDebug() << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"; qDebug() << "Saving..."; diff --git a/src/serviceitemmodel.h b/src/serviceitemmodel.h index 06bbcc8..d696c79 100644 --- a/src/serviceitemmodel.h +++ b/src/serviceitemmodel.h @@ -87,6 +87,7 @@ public: Q_INVOKABLE bool moveUp(int index); Q_INVOKABLE bool select(int id); Q_INVOKABLE bool activate(int id); + Q_INVOKABLE bool deactivate(int id); Q_INVOKABLE QVariantMap getItem(int index) const; Q_INVOKABLE QVariantList getItems(); Q_INVOKABLE void clearAll();