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();
|
rightClickMenu.popup();
|
||||||
else {
|
else {
|
||||||
serviceItemList.currentIndex = index;
|
serviceItemList.currentIndex = index;
|
||||||
|
serviceItemModel.select(index);
|
||||||
/* currentServiceItem = index; */
|
/* currentServiceItem = index; */
|
||||||
/* changeItem(index); */
|
/* changeItem(index); */
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,6 +83,14 @@ int ServiceItem::fontSize() const {
|
||||||
return m_fontSize;
|
return m_fontSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ServiceItem::active() const {
|
||||||
|
return m_active;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ServiceItem::selected() const {
|
||||||
|
return m_selected;
|
||||||
|
}
|
||||||
|
|
||||||
void ServiceItem::setName(QString name)
|
void ServiceItem::setName(QString name)
|
||||||
{
|
{
|
||||||
if (m_name == name)
|
if (m_name == name)
|
||||||
|
@ -155,3 +163,21 @@ void ServiceItem::setFontSize(int fontSize)
|
||||||
m_fontSize = fontSize;
|
m_fontSize = fontSize;
|
||||||
emit fontSizeChanged(m_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 audio READ audio WRITE setAudio NOTIFY audioChanged)
|
||||||
Q_PROPERTY(QString font READ font WRITE setFont NOTIFY fontChanged)
|
Q_PROPERTY(QString font READ font WRITE setFont NOTIFY fontChanged)
|
||||||
Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
|
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:
|
public:
|
||||||
explicit ServiceItem(QObject *parent = nullptr);
|
explicit ServiceItem(QObject *parent = nullptr);
|
||||||
|
@ -39,6 +41,8 @@ public:
|
||||||
QString audio() const;
|
QString audio() const;
|
||||||
QString font() const;
|
QString font() const;
|
||||||
int fontSize() const;
|
int fontSize() const;
|
||||||
|
bool active() const;
|
||||||
|
bool selected() const;
|
||||||
|
|
||||||
void setName(QString name);
|
void setName(QString name);
|
||||||
void setType(QString type);
|
void setType(QString type);
|
||||||
|
@ -48,6 +52,8 @@ public:
|
||||||
void setAudio(QString audio);
|
void setAudio(QString audio);
|
||||||
void setFont(QString font);
|
void setFont(QString font);
|
||||||
void setFontSize(int fontSize);
|
void setFontSize(int fontSize);
|
||||||
|
void setActive(bool active);
|
||||||
|
void setSelected(bool selected);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void nameChanged(QString name);
|
void nameChanged(QString name);
|
||||||
|
@ -58,6 +64,8 @@ signals:
|
||||||
void audioChanged(QString audio);
|
void audioChanged(QString audio);
|
||||||
void fontChanged(QString font);
|
void fontChanged(QString font);
|
||||||
void fontSizeChanged(int fontSize);
|
void fontSizeChanged(int fontSize);
|
||||||
|
void activeChanged(bool active);
|
||||||
|
void selectedChanged(bool selected);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_name;
|
QString m_name;
|
||||||
|
@ -68,6 +76,8 @@ private:
|
||||||
QString m_audio;
|
QString m_audio;
|
||||||
QString m_font;
|
QString m_font;
|
||||||
int m_fontSize;
|
int m_fontSize;
|
||||||
|
bool m_active;
|
||||||
|
bool m_selected;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SERVICEITEM_H
|
#endif // SERVICEITEM_H
|
||||||
|
|
|
@ -53,6 +53,10 @@ QVariant ServiceItemModel::data(const QModelIndex &index, int role) const {
|
||||||
return item->font();
|
return item->font();
|
||||||
case FontSizeRole:
|
case FontSizeRole:
|
||||||
return item->fontSize();
|
return item->fontSize();
|
||||||
|
case ActiveRole:
|
||||||
|
return item->active();
|
||||||
|
case SelectedRole:
|
||||||
|
return item->selected();
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
@ -66,7 +70,9 @@ QHash<int, QByteArray> ServiceItemModel::roleNames() const {
|
||||||
{TextRole, "text"},
|
{TextRole, "text"},
|
||||||
{AudioRole, "audio"},
|
{AudioRole, "audio"},
|
||||||
{FontRole, "font"},
|
{FontRole, "font"},
|
||||||
{FontSizeRole, "fontSize"}};
|
{FontSizeRole, "fontSize"},
|
||||||
|
{ActiveRole, "active"},
|
||||||
|
{SelectedRole, "selected"}};
|
||||||
|
|
||||||
return mapping;
|
return mapping;
|
||||||
}
|
}
|
||||||
|
@ -126,6 +132,18 @@ bool ServiceItemModel::setData(const QModelIndex &index, const QVariant &value,
|
||||||
somethingChanged = true;
|
somethingChanged = true;
|
||||||
}
|
}
|
||||||
break;
|
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) {
|
if (somethingChanged) {
|
||||||
emit dataChanged(index, index, QVector<int>() << role);
|
emit dataChanged(index, index, QVector<int>() << role);
|
||||||
return true;
|
return true;
|
||||||
|
@ -353,3 +371,13 @@ QVariantMap ServiceItemModel::getItem(int index) const {
|
||||||
}
|
}
|
||||||
return data;
|
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,
|
TextRole,
|
||||||
AudioRole,
|
AudioRole,
|
||||||
FontRole,
|
FontRole,
|
||||||
FontSizeRole
|
FontSizeRole,
|
||||||
|
ActiveRole,
|
||||||
|
SelectedRole
|
||||||
};
|
};
|
||||||
|
|
||||||
// Basic functionality:
|
// Basic functionality:
|
||||||
|
@ -83,6 +85,7 @@ public:
|
||||||
Q_INVOKABLE bool move(int sourceIndex, int destIndex);
|
Q_INVOKABLE bool move(int sourceIndex, int destIndex);
|
||||||
Q_INVOKABLE bool moveDown(int index);
|
Q_INVOKABLE bool moveDown(int index);
|
||||||
Q_INVOKABLE bool moveUp(int index);
|
Q_INVOKABLE bool moveUp(int index);
|
||||||
|
Q_INVOKABLE bool select(int id);
|
||||||
Q_INVOKABLE QVariantMap getItem(int index) const;
|
Q_INVOKABLE QVariantMap getItem(int index) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue