adding active and selected knowledge to model
This commit is contained in:
parent
7266a0b047
commit
56086dfe74
5 changed files with 70 additions and 2 deletions
|
@ -230,6 +230,7 @@ ColumnLayout {
|
|||
rightClickMenu.popup();
|
||||
else {
|
||||
serviceItemList.currentIndex = index;
|
||||
serviceItemModel.select(index);
|
||||
/* currentServiceItem = index; */
|
||||
/* changeItem(index); */
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<int, QByteArray> 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<int>() << 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;
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue