aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/types
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2019-02-21 17:35:39 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2019-02-22 13:13:28 +0000
commit22435f49499342ff102411c025efb8007dfa62a2 (patch)
tree51bbc0375849451355e8397a77752c95d83349ed /src/qml/types
parent2d79c167e0e127e99a4b439dc3c8536770c110a9 (diff)
TableModel.roleDataProvider: replace row, column with index argument
QModelIndex has various advantages over separate int row and column in TableModel API; we intend to expose it via an invokable index() method and via a context property for delegates, and use it in the invokable data() function. So we should be consistent by using it in roleDataProvider too. This way the callback only requires 3 arguments instead of 4, and the first one is potentially extensible, just in case. Change-Id: I7b1bc9ea5adb64941979d83901b3566278357e98 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/qml/types')
-rw-r--r--src/qml/types/qqmltablemodel.cpp25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/qml/types/qqmltablemodel.cpp b/src/qml/types/qqmltablemodel.cpp
index 9bf8c7f562..c4bddfaa62 100644
--- a/src/qml/types/qqmltablemodel.cpp
+++ b/src/qml/types/qqmltablemodel.cpp
@@ -42,6 +42,7 @@
#include <QtCore/qloggingcategory.h>
#include <QtQml/qqmlinfo.h>
#include <QtQml/qqmlengine.h>
+#include <private/qv4engine_p.h>
QT_BEGIN_NAMESPACE
@@ -555,14 +556,14 @@ void QQmlTableModel::setRow(int rowIndex, const QVariant &row)
When assigned, it will be called each time data() is called, to enable
extracting arbitrary values, converting the data in arbitrary ways, or even
- doing calculations. It takes 4 arguments: \c row, \c column, \c role (as a
- string), and \c cellData, which is the complete data that is stored in the
- given cell. (If the cell contains a JS object with multiple named values,
- the entire object will be given in cellData.) The function that you define
- must return the value to be used; for example a typical delegate will
- display the value returned for the \c display role, so you can check
- whether that is the role and return data in a form that is suitable for the
- delegate to show:
+ doing calculations. It takes 3 arguments: \c index (\l QModelIndex),
+ \c role (string), and \c cellData (object), which is the complete data that
+ is stored in the given cell. (If the cell contains a JS object with
+ multiple named values, the entire object will be given in \c cellData.)
+ The function that you define must return the value to be used; for example
+ a typical delegate will display the value returned for the \c display role,
+ so you can check whether that is the role and return data in a form that is
+ suitable for the delegate to show:
\snippet qml/tablemodel/roleDataProvider.qml 0
*/
@@ -637,9 +638,11 @@ QVariant QQmlTableModel::data(const QModelIndex &index, int role) const
const QVariantList rowData = mRows.at(row).toList();
if (mRoleDataProvider.isCallable()) {
- const auto args = QJSValueList() << row << column <<
- QString::fromUtf8(mRoleNames.value(role)) <<
- qmlEngine(this)->toScriptValue(rowData.at(column));
+ auto engine = qmlEngine(this);
+ const auto args = QJSValueList() <<
+ QJSValue(engine->handle(), engine->handle()->fromVariant(QVariant(QVariant::ModelIndex, &index))) <<
+ QString::fromUtf8(mRoleNames.value(role)) <<
+ engine->toScriptValue(rowData.at(column));
return const_cast<QQmlTableModel*>(this)->mRoleDataProvider.call(args).toVariant();
}