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
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue