From 9822dcef071f8c6d6ec2f6b39bab436613493221 Mon Sep 17 00:00:00 2001 From: Jos van den Oever Date: Sat, 19 May 2018 16:46:48 +0200 Subject: [PATCH] Simplify the example by removing the optional roles property --- examples/todos/bindings.json | 6 ++---- examples/todos/src/Bindings.cpp | 27 ++++----------------------- 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/examples/todos/bindings.json b/examples/todos/bindings.json index 10ebc6d..38f97ec 100644 --- a/examples/todos/bindings.json +++ b/examples/todos/bindings.json @@ -19,13 +19,11 @@ "itemProperties": { "completed": { "type": "bool", - "write": true, - "roles": [ [ "display" ] ] + "write": true }, "description": { "type": "QString", - "write": true, - "roles": [ [], [ "display" ] ] + "write": true } }, "functions": { diff --git a/examples/todos/src/Bindings.cpp b/examples/todos/src/Bindings.cpp index 75f8bae..ed76eab 100644 --- a/examples/todos/src/Bindings.cpp +++ b/examples/todos/src/Bindings.cpp @@ -52,7 +52,7 @@ extern "C" { } int Todos::columnCount(const QModelIndex &parent) const { - return (parent.isValid()) ? 0 : 2; + return (parent.isValid()) ? 0 : 1; } bool Todos::hasChildren(const QModelIndex &parent) const @@ -77,7 +77,7 @@ bool Todos::removeRows(int row, int count, const QModelIndex &) QModelIndex Todos::index(int row, int column, const QModelIndex &parent) const { - if (!parent.isValid() && row >= 0 && row < rowCount(parent) && column >= 0 && column < 2) { + if (!parent.isValid() && row >= 0 && row < rowCount(parent) && column >= 0 && column < 1) { return createIndex(row, column, (quintptr)row); } return QModelIndex(); @@ -110,9 +110,6 @@ Qt::ItemFlags Todos::flags(const QModelIndex &i) const if (i.column() == 0) { flags |= Qt::ItemIsEditable; } - if (i.column() == 1) { - flags |= Qt::ItemIsEditable; - } return flags; } @@ -156,18 +153,11 @@ QVariant Todos::data(const QModelIndex &index, int role) const switch (index.column()) { case 0: switch (role) { - case Qt::DisplayRole: case Qt::UserRole + 0: return QVariant::fromValue(completed(index.row())); case Qt::UserRole + 1: return QVariant::fromValue(description(index.row())); } - case 1: - switch (role) { - case Qt::DisplayRole: - case Qt::UserRole + 1: - return QVariant::fromValue(description(index.row())); - } } return QVariant(); } @@ -198,7 +188,7 @@ bool Todos::setHeaderData(int section, Qt::Orientation orientation, const QVaria bool Todos::setData(const QModelIndex &index, const QVariant &value, int role) { if (index.column() == 0) { - if (role == Qt::DisplayRole || role == Qt::UserRole + 0) { + if (role == Qt::UserRole + 0) { if (value.canConvert(qMetaTypeId())) { return setCompleted(index.row(), value.value()); } @@ -209,13 +199,6 @@ bool Todos::setData(const QModelIndex &index, const QVariant &value, int role) } } } - if (index.column() == 1) { - if (role == Qt::DisplayRole || role == Qt::UserRole + 1) { - if (value.canConvert(qMetaTypeId())) { - return setDescription(index.row(), value.value()); - } - } - } return false; } @@ -256,7 +239,7 @@ Todos::Todos(QObject *parent): }, [](Todos* o, quintptr first, quintptr last) { o->dataChanged(o->createIndex(first, 0, first), - o->createIndex(last, 1, last)); + o->createIndex(last, 0, last)); }, [](Todos* o) { o->beginResetModel(); @@ -291,8 +274,6 @@ Todos::~Todos() { } } void Todos::initHeaderData() { - m_headerData.insert(qMakePair(0, Qt::DisplayRole), QVariant("completed")); - m_headerData.insert(qMakePair(1, Qt::DisplayRole), QVariant("description")); } quint64 Todos::activeCount() const {