@@ -149,7 +149,7 @@ class RDTreeWidgetModel : public QAbstractItemModel
149
149
if (!index.isValid ())
150
150
return 0 ;
151
151
152
- return QAbstractItemModel::flags (index);
152
+ return QAbstractItemModel::flags (index) | Qt::ItemIsUserCheckable ;
153
153
}
154
154
155
155
QVariant headerData (int section, Qt::Orientation orientation, int role) const override
@@ -230,6 +230,63 @@ class RDTreeWidgetModel : public QAbstractItemModel
230
230
return QVariant ();
231
231
}
232
232
233
+ bool setData (const QModelIndex &index, const QVariant &value, int role)
234
+ {
235
+ RDTreeWidgetItem *item = itemForIndex (index);
236
+
237
+ // invisible root element has no data
238
+ if (!item->m_parent )
239
+ return false ;
240
+
241
+ bool ret = false ;
242
+
243
+ if (role == Qt::DisplayRole)
244
+ {
245
+ if (index.column () < item->m_text .count ())
246
+ {
247
+ item->m_text [index.column ()] = value;
248
+ ret = true ;
249
+ }
250
+ }
251
+ else if (role == Qt::DecorationRole)
252
+ {
253
+ if (index.column () < item->m_icons .count ())
254
+ {
255
+ item->m_icons [index.column ()] = value.value <QIcon>();
256
+ ret = true ;
257
+ }
258
+ }
259
+ else if (role == Qt::BackgroundRole)
260
+ {
261
+ item->m_back = value.value <QBrush>();
262
+ ret = true ;
263
+ }
264
+ else if (role == Qt::ForegroundRole)
265
+ {
266
+ item->m_fore = value.value <QBrush>();
267
+ ret = true ;
268
+ }
269
+ else if (role == Qt::ToolTipRole && !widget->m_instantTooltips )
270
+ {
271
+ item->m_tooltip = value.toString ();
272
+ ret = true ;
273
+ }
274
+ else if (role == Qt::FontRole)
275
+ {
276
+ ret = false ;
277
+ }
278
+ else
279
+ {
280
+ item->setData (index.column (), role, value);
281
+ ret = true ;
282
+ }
283
+
284
+ if (ret)
285
+ widget->itemDataChanged (item, index.column (), role);
286
+
287
+ return ret;
288
+ }
289
+
233
290
private:
234
291
RDTreeWidget *widget;
235
292
};
0 commit comments