From 508dcab350521a7dd7a84bbcb7fea973f9483611 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Fri, 2 Feb 2018 14:31:18 +0100 Subject: QQmlAdaptorModel::Accessors: add support for row and column Accessors wraps the different models used by a QQmlAdaptorModel. This patch will add support for accessing row and column information from those models. Change-Id: Ie4b1870c70750444bc4f288f5f85a20dcad603ff Reviewed-by: Frederik Gladhorn Reviewed-by: J-P Nurmi --- src/qml/util/qqmladaptormodel.cpp | 30 ++++++++++++++++++++++++++++++ src/qml/util/qqmladaptormodel_p.h | 2 ++ 2 files changed, 32 insertions(+) (limited to 'src/qml/util') diff --git a/src/qml/util/qqmladaptormodel.cpp b/src/qml/util/qqmladaptormodel.cpp index 7afafec1fe..96a18a1c3d 100644 --- a/src/qml/util/qqmladaptormodel.cpp +++ b/src/qml/util/qqmladaptormodel.cpp @@ -458,6 +458,16 @@ public: return model.aim()->rowCount(model.rootIndex); } + int rowCount(const QQmlAdaptorModel &model) const override + { + return model.aim()->rowCount(model.rootIndex); + } + + int columnCount(const QQmlAdaptorModel &model) const override + { + return model.aim()->columnCount(model.rootIndex); + } + void cleanup(QQmlAdaptorModel &model, QQmlDelegateModel *vdm) const override { QAbstractItemModel * const aim = model.aim(); @@ -658,6 +668,16 @@ public: return model.list.count(); } + int rowCount(const QQmlAdaptorModel &model) const override + { + return model.list.count(); + } + + int columnCount(const QQmlAdaptorModel &) const override + { + return 1; + } + QVariant value(const QQmlAdaptorModel &model, int index, const QString &role) const override { return role == QLatin1String("modelData") @@ -742,6 +762,16 @@ public: return model.list.count(); } + int rowCount(const QQmlAdaptorModel &model) const override + { + return model.list.count(); + } + + int columnCount(const QQmlAdaptorModel &) const override + { + return 1; + } + QVariant value(const QQmlAdaptorModel &model, int index, const QString &role) const override { if (QObject *object = model.list.at(index).value()) diff --git a/src/qml/util/qqmladaptormodel_p.h b/src/qml/util/qqmladaptormodel_p.h index 7bbddcff07..4d922c68f3 100644 --- a/src/qml/util/qqmladaptormodel_p.h +++ b/src/qml/util/qqmladaptormodel_p.h @@ -74,6 +74,8 @@ public: inline Accessors() {} virtual ~Accessors(); virtual int count(const QQmlAdaptorModel &) const { return 0; } + virtual int rowCount(const QQmlAdaptorModel &) const { return 0; } + virtual int columnCount(const QQmlAdaptorModel &) const { return 0; } virtual void cleanup(QQmlAdaptorModel &, QQmlDelegateModel * = 0) const {} virtual QVariant value(const QQmlAdaptorModel &, int, const QString &) const { -- cgit v1.2.3