diff --git a/src/qml/presenter/ServiceList.qml b/src/qml/presenter/ServiceList.qml index 729af83..c94d9d1 100644 --- a/src/qml/presenter/ServiceList.qml +++ b/src/qml/presenter/ServiceList.qml @@ -230,6 +230,7 @@ ColumnLayout { rightClickMenu.popup(); else { serviceItemList.currentIndex = index; + serviceItemModel.select(index); /* currentServiceItem = index; */ /* changeItem(index); */ } diff --git a/src/serviceitem.cpp b/src/serviceitem.cpp index a79a6a1..7b86fe3 100644 --- a/src/serviceitem.cpp +++ b/src/serviceitem.cpp @@ -83,6 +83,14 @@ int ServiceItem::fontSize() const { return m_fontSize; } +bool ServiceItem::active() const { + return m_active; +} + +bool ServiceItem::selected() const { + return m_selected; +} + void ServiceItem::setName(QString name) { if (m_name == name) @@ -155,3 +163,21 @@ void ServiceItem::setFontSize(int fontSize) m_fontSize = fontSize; emit fontSizeChanged(m_fontSize); } + +void ServiceItem::setActive(bool active) +{ + if (m_active == active) + return; + + m_active = active; + emit activeChanged(m_active); +} + +void ServiceItem::setSelected(bool selected) +{ + if (m_selected == selected) + return; + + m_selected = selected; + emit selectedChanged(m_selected); +} diff --git a/src/serviceitem.h b/src/serviceitem.h index 44a9409..c7e5443 100644 --- a/src/serviceitem.h +++ b/src/serviceitem.h @@ -15,6 +15,8 @@ class ServiceItem : public QObject Q_PROPERTY(QString audio READ audio WRITE setAudio NOTIFY audioChanged) Q_PROPERTY(QString font READ font WRITE setFont NOTIFY fontChanged) Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged) + Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged) + Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectedChanged) public: explicit ServiceItem(QObject *parent = nullptr); @@ -39,6 +41,8 @@ public: QString audio() const; QString font() const; int fontSize() const; + bool active() const; + bool selected() const; void setName(QString name); void setType(QString type); @@ -48,6 +52,8 @@ public: void setAudio(QString audio); void setFont(QString font); void setFontSize(int fontSize); + void setActive(bool active); + void setSelected(bool selected); signals: void nameChanged(QString name); @@ -58,6 +64,8 @@ signals: void audioChanged(QString audio); void fontChanged(QString font); void fontSizeChanged(int fontSize); + void activeChanged(bool active); + void selectedChanged(bool selected); private: QString m_name; @@ -68,6 +76,8 @@ private: QString m_audio; QString m_font; int m_fontSize; + bool m_active; + bool m_selected; }; #endif // SERVICEITEM_H diff --git a/src/serviceitemmodel.cpp b/src/serviceitemmodel.cpp index b509085..d956131 100644 --- a/src/serviceitemmodel.cpp +++ b/src/serviceitemmodel.cpp @@ -53,6 +53,10 @@ QVariant ServiceItemModel::data(const QModelIndex &index, int role) const { return item->font(); case FontSizeRole: return item->fontSize(); + case ActiveRole: + return item->active(); + case SelectedRole: + return item->selected(); default: return QVariant(); } @@ -66,7 +70,9 @@ QHash ServiceItemModel::roleNames() const { {TextRole, "text"}, {AudioRole, "audio"}, {FontRole, "font"}, - {FontSizeRole, "fontSize"}}; + {FontSizeRole, "fontSize"}, + {ActiveRole, "active"}, + {SelectedRole, "selected"}}; return mapping; } @@ -126,6 +132,18 @@ bool ServiceItemModel::setData(const QModelIndex &index, const QVariant &value, somethingChanged = true; } break; + case ActiveRole: + if (item->active() != value.toBool()) { + item->setActive(value.toBool()); + somethingChanged = true; + } + break; + case SelectedRole: + if (item->selected() != value.toBool()) { + item->setSelected(value.toBool()); + somethingChanged = true; + } + break; if (somethingChanged) { emit dataChanged(index, index, QVector() << role); return true; @@ -353,3 +371,13 @@ QVariantMap ServiceItemModel::getItem(int index) const { } return data; } + +bool ServiceItemModel::select(int id) { + QModelIndex idx = index(id); + ServiceItem *item = m_items[idx.row()]; + item->setSelected(true); + qDebug() << "################"; + qDebug() << "selected" << item->name(); + qDebug() << "################"; + return true; +} diff --git a/src/serviceitemmodel.h b/src/serviceitemmodel.h index 067d840..72eb153 100644 --- a/src/serviceitemmodel.h +++ b/src/serviceitemmodel.h @@ -22,7 +22,9 @@ public: TextRole, AudioRole, FontRole, - FontSizeRole + FontSizeRole, + ActiveRole, + SelectedRole }; // Basic functionality: @@ -83,6 +85,7 @@ public: Q_INVOKABLE bool move(int sourceIndex, int destIndex); Q_INVOKABLE bool moveDown(int index); Q_INVOKABLE bool moveUp(int index); + Q_INVOKABLE bool select(int id); Q_INVOKABLE QVariantMap getItem(int index) const; private: