aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/doc/snippets/qml/tablemodel/roleDataProvider.qml4
-rw-r--r--src/qml/types/qqmltablemodel.cpp25
-rw-r--r--tests/auto/qml/qqmltablemodel/data/roleDataProvider.qml4
3 files changed, 18 insertions, 15 deletions
diff --git a/src/qml/doc/snippets/qml/tablemodel/roleDataProvider.qml b/src/qml/doc/snippets/qml/tablemodel/roleDataProvider.qml
index 6c8ae3f1fc..63978a370d 100644
--- a/src/qml/doc/snippets/qml/tablemodel/roleDataProvider.qml
+++ b/src/qml/doc/snippets/qml/tablemodel/roleDataProvider.qml
@@ -59,10 +59,10 @@ TableView {
[{ fruitType: "Apple" }, { fruitPrice: 1.50 }],
[{ fruitType: "Orange" }, { fruitPrice: 2.50 }]
]
- roleDataProvider: function(row, column, role, cellData) {
+ roleDataProvider: function(index, role, cellData) {
if (role === "display") {
if (cellData.hasOwnProperty("fruitPrice")) {
- console.log("taxing your fruit " + JSON.stringify(cellData))
+ console.log("row", index.row, "taxing your fruit", JSON.stringify(cellData))
return (cellData.fruitPrice * (1 + taxPercent / 100)).toFixed(2);
}
else if (cellData.hasOwnProperty("fruitType"))
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();
}
diff --git a/tests/auto/qml/qqmltablemodel/data/roleDataProvider.qml b/tests/auto/qml/qqmltablemodel/data/roleDataProvider.qml
index 825a1ad071..2706ea54fd 100644
--- a/tests/auto/qml/qqmltablemodel/data/roleDataProvider.qml
+++ b/tests/auto/qml/qqmltablemodel/data/roleDataProvider.qml
@@ -43,12 +43,12 @@ Item {
[ { name: "Rex" }, { age: 3 } ],
[ { name: "Buster" }, { age: 5 } ]
]
- roleDataProvider: function(row, column, role, cellData) {
+ roleDataProvider: function(index, role, cellData) {
if (role === "display") {
// Age will now be in dog years
if (cellData.hasOwnProperty("age"))
return (cellData.age * 7);
- else if (column === 0)
+ else if (index.column === 0)
return (cellData.name);
}
return cellData;