From 7669b6ed1aee55b29b06f4077cae537f28f1d9d1 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Thu, 30 Jan 2014 14:20:09 +0200 Subject: Fix surface mapping MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTRD-2528 Change-Id: I2e677519b08d1a634d5024ecc85d82b74f8587ad Reviewed-by: Tomi Korpipää --- .../data/qitemmodelbardataproxy.cpp | 12 +- .../data/qitemmodelbardataproxy.h | 3 +- .../data/qitemmodelsurfacedataproxy.cpp | 180 +++++++++++++++++---- .../data/qitemmodelsurfacedataproxy.h | 34 +++- .../data/qitemmodelsurfacedataproxy_p.h | 4 +- .../data/surfaceitemmodelhandler.cpp | 52 ++++-- .../doc/snippets/doc_src_qtdatavisualization.cpp | 2 +- 7 files changed, 230 insertions(+), 57 deletions(-) (limited to 'src') diff --git a/src/datavisualization/data/qitemmodelbardataproxy.cpp b/src/datavisualization/data/qitemmodelbardataproxy.cpp index 6a1e9c15..6612a387 100644 --- a/src/datavisualization/data/qitemmodelbardataproxy.cpp +++ b/src/datavisualization/data/qitemmodelbardataproxy.cpp @@ -466,24 +466,26 @@ bool QItemModelBarDataProxy::autoColumnCategories() const } /*! - * Changes \a rowRole, \a columnRole, \a valueRole, \a rowCategories and \a columnCategories to the - * mapping. + * Changes \a rowRole, \a columnRole, \a valueRole, \a rotationRole, + * \a rowCategories and \a columnCategories to the mapping. */ void QItemModelBarDataProxy::remap(const QString &rowRole, const QString &columnRole, const QString &valueRole, + const QString &rotationRole, const QStringList &rowCategories, const QStringList &columnCategories) { setRowRole(rowRole); setColumnRole(columnRole); setValueRole(valueRole); + setRotationRole(rotationRole); setRowCategories(rowCategories); setColumnCategories(columnCategories); } /*! - * /return index of the specified \a category in row categories list. + * \return index of the specified \a category in row categories list. * If the row categories list is empty, -1 is returned. * \note If the automatic row categories generation is in use, this method will * not return a valid index before the data in the model is resolved for the first time. @@ -494,7 +496,7 @@ int QItemModelBarDataProxy::rowCategoryIndex(const QString &category) } /*! - * /return index of the specified \a category in column categories list. + * \return index of the specified \a category in column categories list. * If the category is not found, -1 is returned. * \note If the automatic column categories generation is in use, this method will * not return a valid index before the data in the model is resolved for the first time. @@ -551,6 +553,8 @@ void QItemModelBarDataProxyPrivate::connectItemModelHandler() m_itemModelHandler, &AbstractItemModelHandler::handleMappingChanged); QObject::connect(qptr(), &QItemModelBarDataProxy::valueRoleChanged, m_itemModelHandler, &AbstractItemModelHandler::handleMappingChanged); + QObject::connect(qptr(), &QItemModelBarDataProxy::rotationRoleChanged, + m_itemModelHandler, &AbstractItemModelHandler::handleMappingChanged); QObject::connect(qptr(), &QItemModelBarDataProxy::rowCategoriesChanged, m_itemModelHandler, &AbstractItemModelHandler::handleMappingChanged); QObject::connect(qptr(), &QItemModelBarDataProxy::columnCategoriesChanged, diff --git a/src/datavisualization/data/qitemmodelbardataproxy.h b/src/datavisualization/data/qitemmodelbardataproxy.h index f6b0b64f..ce3ccaa3 100644 --- a/src/datavisualization/data/qitemmodelbardataproxy.h +++ b/src/datavisualization/data/qitemmodelbardataproxy.h @@ -87,7 +87,8 @@ public: bool autoColumnCategories() const; void remap(const QString &rowRole, const QString &columnRole, - const QString &valueRole, const QStringList &rowCategories, + const QString &valueRole, const QString &rotationRole, + const QStringList &rowCategories, const QStringList &columnCategories); Q_INVOKABLE int rowCategoryIndex(const QString& category); diff --git a/src/datavisualization/data/qitemmodelsurfacedataproxy.cpp b/src/datavisualization/data/qitemmodelsurfacedataproxy.cpp index 0c206b81..49c4d4ef 100644 --- a/src/datavisualization/data/qitemmodelsurfacedataproxy.cpp +++ b/src/datavisualization/data/qitemmodelsurfacedataproxy.cpp @@ -30,7 +30,7 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION * * QItemModelSurfaceDataProxy allows you to use QAbstractItemModel derived models as a data source * for Q3DSurface. It uses the defined mappings to map data from the model to rows, columns, and - * values of Q3DSurface graph. + * surface points of Q3DSurface graph. * * Data is resolved asynchronously whenever the mapping or the model changes. * QSurfaceDataProxy::arrayReset() is emitted when the data has been resolved. @@ -39,8 +39,12 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION * * 1) If useModelCategories property is set to true, this proxy will map rows and * columns of QAbstractItemModel to rows and columns of Q3DSurface, and uses the value returned for - * Qt::DisplayRole as bar value by default. - * The value role to be used can be redefined if Qt::DisplayRole is not suitable. + * Qt::DisplayRole as Y-position by default. Row and column headers are used for Z-position and + * X-position by default, if they can be converted to floats. Otherwise row and column indices + * are used. + * The Y-position role to be used can be redefined if Qt::DisplayRole is not suitable. + * The Z-position and X-position roles to be used can be redefined if the headers or indices + * are not suitable. * * 2) For models that do not have data already neatly sorted into rows and columns, such as * QAbstractListModel based models, you can define a role from the model to map for each of row, @@ -105,10 +109,18 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION */ /*! - * \qmlproperty string ItemModelSurfaceDataProxy::valueRole - * The value role of the mapping. - * The value indicated by value role is set as Y-coodrinate value of the - * QSurfaceDataItem when model data is resolved. + * \qmlproperty string ItemModelSurfaceDataProxy::xPosRole + * The X position role of the mapping. + */ + +/*! + * \qmlproperty string ItemModelSurfaceDataProxy::yPosRole + * The Y position role of the mapping. + */ + +/*! + * \qmlproperty string ItemModelSurfaceDataProxy::zPosRole + * The Z position role of the mapping. */ /*! @@ -169,17 +181,17 @@ QItemModelSurfaceDataProxy::QItemModelSurfaceDataProxy(const QAbstractItemModel /*! * Constructs QItemModelSurfaceDataProxy with \a itemModel and optional \a parent. Proxy doesn't take * ownership of the \a itemModel, as typically item models are owned by other controls. - * The value role is set to \a valueRole. + * The yPosRole role is set to \a yPosRole. * This constructor is meant to be used with models that have data properly sorted * in rows and columns already, so it also sets useModelCategories property to true. */ QItemModelSurfaceDataProxy::QItemModelSurfaceDataProxy(const QAbstractItemModel *itemModel, - const QString &valueRole, + const QString &yPosRole, QObject *parent) : QSurfaceDataProxy(new QItemModelSurfaceDataProxyPrivate(this), parent) { dptr()->m_itemModelHandler->setItemModel(itemModel); - dptr()->m_valueRole = valueRole; + dptr()->m_yPosRole = yPosRole; dptr()->m_useModelCategories = true; dptr()->connectItemModelHandler(); } @@ -187,33 +199,93 @@ QItemModelSurfaceDataProxy::QItemModelSurfaceDataProxy(const QAbstractItemModel /*! * Constructs QItemModelSurfaceDataProxy with \a itemModel and optional \a parent. Proxy doesn't take * ownership of the \a itemModel, as typically item models are owned by other controls. - * The role mappings are set with \a rowRole, \a columnRole, and \a valueRole. + * The role mappings are set with \a rowRole, \a columnRole, and \a yPosRole. + * The zPosRole and the xPosRole are set to \a rowRole and \a columnRole, respectively. + */ +QItemModelSurfaceDataProxy::QItemModelSurfaceDataProxy(const QAbstractItemModel *itemModel, + const QString &rowRole, + const QString &columnRole, + const QString &yPosRole, + QObject *parent) + : QSurfaceDataProxy(new QItemModelSurfaceDataProxyPrivate(this), parent) +{ + dptr()->m_itemModelHandler->setItemModel(itemModel); + dptr()->m_rowRole = rowRole; + dptr()->m_columnRole = columnRole; + dptr()->m_xPosRole = columnRole; + dptr()->m_yPosRole = yPosRole; + dptr()->m_zPosRole = rowRole; + dptr()->connectItemModelHandler(); +} + +/*! + * Constructs QItemModelSurfaceDataProxy with \a itemModel and optional \a parent. Proxy doesn't take + * ownership of the \a itemModel, as typically item models are owned by other controls. + * The role mappings are set with \a rowRole, \a columnRole, \a xPosRole, \a yPosRole, and + * \a zPosRole. + */ +QItemModelSurfaceDataProxy::QItemModelSurfaceDataProxy(const QAbstractItemModel *itemModel, + const QString &rowRole, + const QString &columnRole, + const QString &xPosRole, + const QString &yPosRole, + const QString &zPosRole, + QObject *parent) + : QSurfaceDataProxy(new QItemModelSurfaceDataProxyPrivate(this), parent) +{ + dptr()->m_itemModelHandler->setItemModel(itemModel); + dptr()->m_rowRole = rowRole; + dptr()->m_columnRole = columnRole; + dptr()->m_xPosRole = xPosRole; + dptr()->m_yPosRole = yPosRole; + dptr()->m_zPosRole = zPosRole; + dptr()->connectItemModelHandler(); +} + +/*! + * Constructs QItemModelSurfaceDataProxy with \a itemModel and optional \a parent. Proxy doesn't take + * ownership of the \a itemModel, as typically item models are owned by other controls. + * The role mappings are set with \a rowRole, \a columnRole, and \a yPosRole. + * The zPosRole and the xPosRole are set to \a rowRole and \a columnRole, respectively. + * Row and column categories are set with \a rowCategories and \a columnCategories. + * This constructor also sets autoRowCategories and autoColumnCategories to false. */ QItemModelSurfaceDataProxy::QItemModelSurfaceDataProxy(const QAbstractItemModel *itemModel, const QString &rowRole, const QString &columnRole, - const QString &valueRole, + const QString &yPosRole, + const QStringList &rowCategories, + const QStringList &columnCategories, QObject *parent) : QSurfaceDataProxy(new QItemModelSurfaceDataProxyPrivate(this), parent) { dptr()->m_itemModelHandler->setItemModel(itemModel); dptr()->m_rowRole = rowRole; dptr()->m_columnRole = columnRole; - dptr()->m_valueRole = valueRole; + dptr()->m_xPosRole = columnRole; + dptr()->m_yPosRole = yPosRole; + dptr()->m_zPosRole = rowRole; + dptr()->m_rowCategories = rowCategories; + dptr()->m_columnCategories = columnCategories; + dptr()->m_autoRowCategories = false; + dptr()->m_autoColumnCategories = false; dptr()->connectItemModelHandler(); } /*! * Constructs QItemModelSurfaceDataProxy with \a itemModel and optional \a parent. Proxy doesn't take * ownership of the \a itemModel, as typically item models are owned by other controls. - * The role mappings are set with \a rowRole, \a columnRole, and \a valueRole. + * The role mappings are set with \a rowRole, \a columnRole, \a xPosRole, \a yPosRole, + * and \a zPosRole. * Row and column categories are set with \a rowCategories and \a columnCategories. * This constructor also sets autoRowCategories and autoColumnCategories to false. */ QItemModelSurfaceDataProxy::QItemModelSurfaceDataProxy(const QAbstractItemModel *itemModel, const QString &rowRole, const QString &columnRole, - const QString &valueRole, + const QString &xPosRole, + const QString &yPosRole, + const QString &zPosRole, const QStringList &rowCategories, const QStringList &columnCategories, QObject *parent) @@ -222,7 +294,9 @@ QItemModelSurfaceDataProxy::QItemModelSurfaceDataProxy(const QAbstractItemModel dptr()->m_itemModelHandler->setItemModel(itemModel); dptr()->m_rowRole = rowRole; dptr()->m_columnRole = columnRole; - dptr()->m_valueRole = valueRole; + dptr()->m_xPosRole = xPosRole; + dptr()->m_yPosRole = yPosRole; + dptr()->m_zPosRole = zPosRole; dptr()->m_rowCategories = rowCategories; dptr()->m_columnCategories = columnCategories; dptr()->m_autoRowCategories = false; @@ -290,21 +364,57 @@ QString QItemModelSurfaceDataProxy::columnRole() const } /*! - * \property QItemModelSurfaceDataProxy::valueRole + * \property QItemModelSurfaceDataProxy::xPosRole + * + * Defines the X position role for the mapping. + */ +void QItemModelSurfaceDataProxy::setXPosRole(const QString &role) +{ + if (dptr()->m_xPosRole != role) { + dptr()->m_xPosRole = role; + emit xPosRoleChanged(role); + } +} + +QString QItemModelSurfaceDataProxy::xPosRole() const +{ + return dptrc()->m_xPosRole; +} + +/*! + * \property QItemModelSurfaceDataProxy::yPosRole * - * Defines the value role for the mapping. + * Defines the Y position role for the mapping. */ -void QItemModelSurfaceDataProxy::setValueRole(const QString &role) +void QItemModelSurfaceDataProxy::setYPosRole(const QString &role) { - if (dptr()->m_valueRole != role) { - dptr()->m_valueRole = role; - emit valueRoleChanged(role); + if (dptr()->m_yPosRole != role) { + dptr()->m_yPosRole = role; + emit yPosRoleChanged(role); } } -QString QItemModelSurfaceDataProxy::valueRole() const +QString QItemModelSurfaceDataProxy::yPosRole() const { - return dptrc()->m_valueRole; + return dptrc()->m_yPosRole; +} + +/*! + * \property QItemModelSurfaceDataProxy::zPosRole + * + * Defines the Z position role for the mapping. + */ +void QItemModelSurfaceDataProxy::setZPosRole(const QString &role) +{ + if (dptr()->m_zPosRole != role) { + dptr()->m_zPosRole = role; + emit zPosRoleChanged(role); + } +} + +QString QItemModelSurfaceDataProxy::zPosRole() const +{ + return dptrc()->m_zPosRole; } /*! @@ -403,24 +513,28 @@ bool QItemModelSurfaceDataProxy::autoColumnCategories() const } /*! - * Changes \a rowRole, \a columnRole, \a valueRole, \a rowCategories and \a columnCategories to the - * mapping. + * Changes \a rowRole, \a columnRole, \a xPosRole, \a yPosRole, \a zPosRole, + * \a rowCategories and \a columnCategories to the mapping. */ void QItemModelSurfaceDataProxy::remap(const QString &rowRole, const QString &columnRole, - const QString &valueRole, + const QString &xPosRole, + const QString &yPosRole, + const QString &zPosRole, const QStringList &rowCategories, const QStringList &columnCategories) { setRowRole(rowRole); setColumnRole(columnRole); - setValueRole(valueRole); + setXPosRole(xPosRole); + setYPosRole(yPosRole); + setZPosRole(zPosRole); setRowCategories(rowCategories); setColumnCategories(columnCategories); } /*! - * /return index of the specified \a category in row categories list. + * \return index of the specified \a category in row categories list. * If the row categories list is empty, -1 is returned. * \note If the automatic row categories generation is in use, this method will * not return a valid index before the data in the model is resolved for the first time. @@ -431,7 +545,7 @@ int QItemModelSurfaceDataProxy::rowCategoryIndex(const QString &category) } /*! - * /return index of the specified \a category in column categories list. + * \return index of the specified \a category in column categories list. * If the category is not found, -1 is returned. * \note If the automatic column categories generation is in use, this method will * not return a valid index before the data in the model is resolved for the first time. @@ -486,7 +600,11 @@ void QItemModelSurfaceDataProxyPrivate::connectItemModelHandler() m_itemModelHandler, &AbstractItemModelHandler::handleMappingChanged); QObject::connect(qptr(), &QItemModelSurfaceDataProxy::columnRoleChanged, m_itemModelHandler, &AbstractItemModelHandler::handleMappingChanged); - QObject::connect(qptr(), &QItemModelSurfaceDataProxy::valueRoleChanged, + QObject::connect(qptr(), &QItemModelSurfaceDataProxy::xPosRoleChanged, + m_itemModelHandler, &AbstractItemModelHandler::handleMappingChanged); + QObject::connect(qptr(), &QItemModelSurfaceDataProxy::yPosRoleChanged, + m_itemModelHandler, &AbstractItemModelHandler::handleMappingChanged); + QObject::connect(qptr(), &QItemModelSurfaceDataProxy::zPosRoleChanged, m_itemModelHandler, &AbstractItemModelHandler::handleMappingChanged); QObject::connect(qptr(), &QItemModelSurfaceDataProxy::rowCategoriesChanged, m_itemModelHandler, &AbstractItemModelHandler::handleMappingChanged); diff --git a/src/datavisualization/data/qitemmodelsurfacedataproxy.h b/src/datavisualization/data/qitemmodelsurfacedataproxy.h index d1e0f2b8..a905f4c7 100644 --- a/src/datavisualization/data/qitemmodelsurfacedataproxy.h +++ b/src/datavisualization/data/qitemmodelsurfacedataproxy.h @@ -33,7 +33,9 @@ class QT_DATAVISUALIZATION_EXPORT QItemModelSurfaceDataProxy : public QSurfaceDa Q_PROPERTY(const QAbstractItemModel* itemModel READ itemModel WRITE setItemModel NOTIFY itemModelChanged) Q_PROPERTY(QString rowRole READ rowRole WRITE setRowRole NOTIFY rowRoleChanged) Q_PROPERTY(QString columnRole READ columnRole WRITE setColumnRole NOTIFY columnRoleChanged) - Q_PROPERTY(QString valueRole READ valueRole WRITE setValueRole NOTIFY valueRoleChanged) + Q_PROPERTY(QString xPosRole READ xPosRole WRITE setXPosRole NOTIFY xPosRoleChanged) + Q_PROPERTY(QString yPosRole READ yPosRole WRITE setYPosRole NOTIFY yPosRoleChanged) + Q_PROPERTY(QString zPosRole READ zPosRole WRITE setZPosRole NOTIFY zPosRoleChanged) Q_PROPERTY(QStringList rowCategories READ rowCategories WRITE setRowCategories NOTIFY rowCategoriesChanged) Q_PROPERTY(QStringList columnCategories READ columnCategories WRITE setColumnCategories NOTIFY columnCategoriesChanged) Q_PROPERTY(bool useModelCategories READ useModelCategories WRITE setUseModelCategories NOTIFY useModelCategoriesChanged) @@ -43,13 +45,22 @@ class QT_DATAVISUALIZATION_EXPORT QItemModelSurfaceDataProxy : public QSurfaceDa public: explicit QItemModelSurfaceDataProxy(QObject *parent = 0); QItemModelSurfaceDataProxy(const QAbstractItemModel *itemModel, QObject *parent = 0); - QItemModelSurfaceDataProxy(const QAbstractItemModel *itemModel, const QString &valueRole, + QItemModelSurfaceDataProxy(const QAbstractItemModel *itemModel, const QString &yPosRole, QObject *parent = 0); QItemModelSurfaceDataProxy(const QAbstractItemModel *itemModel, const QString &rowRole, - const QString &columnRole, const QString &valueRole, + const QString &columnRole, const QString &yPosRole, QObject *parent = 0); QItemModelSurfaceDataProxy(const QAbstractItemModel *itemModel, const QString &rowRole, - const QString &columnRole, const QString &valueRole, + const QString &columnRole, const QString &xPosRole, + const QString &yPosRole, const QString &zPosRole, + QObject *parent = 0); + QItemModelSurfaceDataProxy(const QAbstractItemModel *itemModel, const QString &rowRole, + const QString &columnRole, const QString &yPosRole, + const QStringList &rowCategories, const QStringList &columnCategories, + QObject *parent = 0); + QItemModelSurfaceDataProxy(const QAbstractItemModel *itemModel, const QString &rowRole, + const QString &columnRole, const QString &xPosRole, + const QString &yPosRole, const QString &zPosRole, const QStringList &rowCategories, const QStringList &columnCategories, QObject *parent = 0); virtual ~QItemModelSurfaceDataProxy(); @@ -61,8 +72,12 @@ public: QString rowRole() const; void setColumnRole(const QString &role); QString columnRole() const; - void setValueRole(const QString &role); - QString valueRole() const; + void setXPosRole(const QString &role); + QString xPosRole() const; + void setYPosRole(const QString &role); + QString yPosRole() const; + void setZPosRole(const QString &role); + QString zPosRole() const; void setRowCategories(const QStringList &categories); QStringList rowCategories() const; @@ -77,7 +92,8 @@ public: bool autoColumnCategories() const; void remap(const QString &rowRole, const QString &columnRole, - const QString &valueRole, const QStringList &rowCategories, + const QString &xPosRole, const QString &yPosRole, + const QString &zPosRole, const QStringList &rowCategories, const QStringList &columnCategories); Q_INVOKABLE int rowCategoryIndex(const QString& category); @@ -87,7 +103,9 @@ signals: void itemModelChanged(const QAbstractItemModel* itemModel); void rowRoleChanged(QString role); void columnRoleChanged(QString role); - void valueRoleChanged(QString role); + void xPosRoleChanged(QString role); + void yPosRoleChanged(QString role); + void zPosRoleChanged(QString role); void rowCategoriesChanged(QStringList categories); void columnCategoriesChanged(QStringList categories); void useModelCategoriesChanged(bool enable); diff --git a/src/datavisualization/data/qitemmodelsurfacedataproxy_p.h b/src/datavisualization/data/qitemmodelsurfacedataproxy_p.h index 5049a25e..0aaea8fd 100644 --- a/src/datavisualization/data/qitemmodelsurfacedataproxy_p.h +++ b/src/datavisualization/data/qitemmodelsurfacedataproxy_p.h @@ -52,7 +52,9 @@ private: QString m_rowRole; QString m_columnRole; - QString m_valueRole; + QString m_xPosRole; + QString m_yPosRole; + QString m_zPosRole; // For row/column items, sort items into these categories. Other categories are ignored. QStringList m_rowCategories; diff --git a/src/datavisualization/data/surfaceitemmodelhandler.cpp b/src/datavisualization/data/surfaceitemmodelhandler.cpp index 767425e9..f4383dbf 100644 --- a/src/datavisualization/data/surfaceitemmodelhandler.cpp +++ b/src/datavisualization/data/surfaceitemmodelhandler.cpp @@ -20,6 +20,8 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION +static const int noRoleIndex = -1; + SurfaceItemModelHandler::SurfaceItemModelHandler(QItemModelSurfaceDataProxy *proxy, QObject *parent) : AbstractItemModelHandler(parent), m_proxy(proxy), @@ -50,7 +52,9 @@ void SurfaceItemModelHandler::resolveModel() QHash roleHash = m_itemModel->roleNames(); // Default to display role if no mapping - int valueRole = roleHash.key(m_proxy->valueRole().toLatin1(), Qt::DisplayRole); + int xPosRole = roleHash.key(m_proxy->xPosRole().toLatin1(), noRoleIndex); + int yPosRole = roleHash.key(m_proxy->yPosRole().toLatin1(), Qt::DisplayRole); + int zPosRole = roleHash.key(m_proxy->zPosRole().toLatin1(), noRoleIndex); int rowCount = m_itemModel->rowCount(); int columnCount = m_itemModel->columnCount(); @@ -66,15 +70,41 @@ void SurfaceItemModelHandler::resolveModel() for (int i = 0; i < rowCount; i++) { QSurfaceDataRow &newProxyRow = *m_proxyArray->at(i); for (int j = 0; j < columnCount; j++) { + float xPos = j; + float zPos = i; + if (xPosRole != noRoleIndex) { + xPos = m_itemModel->index(i, j).data(xPosRole).toFloat(); + } else { + QString header = m_itemModel->headerData(j, Qt::Horizontal).toString(); + bool ok = false; + float headerValue = header.toFloat(&ok); + if (ok) + xPos = headerValue; + } + + if (zPosRole != noRoleIndex) { + zPos = m_itemModel->index(i, j).data(zPosRole).toFloat(); + } else { + QString header = m_itemModel->headerData(i, Qt::Vertical).toString(); + bool ok = false; + float headerValue = header.toFloat(&ok); + if (ok) + zPos = headerValue; + } + newProxyRow[j].setPosition( - QVector3D(m_itemModel->headerData(j, Qt::Horizontal).toFloat(), - m_itemModel->index(i, j).data(valueRole).toFloat(), - m_itemModel->headerData(i, Qt::Vertical).toFloat())); + QVector3D(xPos, + m_itemModel->index(i, j).data(yPosRole).toFloat(), + zPos)); } } } else { int rowRole = roleHash.key(m_proxy->rowRole().toLatin1()); int columnRole = roleHash.key(m_proxy->columnRole().toLatin1()); + if (xPosRole == noRoleIndex) + xPosRole = columnRole; + if (zPosRole == noRoleIndex) + zPosRole = rowRole; bool generateRows = m_proxy->autoRowCategories(); bool generateColumns = m_proxy->autoColumnCategories(); @@ -87,14 +117,17 @@ void SurfaceItemModelHandler::resolveModel() QHash columnListHash; // Sort values into rows and columns - typedef QHash ColumnValueMap; + typedef QHash ColumnValueMap; QHash itemValueMap; for (int i = 0; i < rowCount; i++) { for (int j = 0; j < columnCount; j++) { QModelIndex index = m_itemModel->index(i, j); QString rowRoleStr = index.data(rowRole).toString(); QString columnRoleStr = index.data(columnRole).toString(); - itemValueMap[rowRoleStr][columnRoleStr] = index.data(valueRole).toReal(); + QVector3D itemPos(index.data(xPosRole).toReal(), + index.data(yPosRole).toReal(), + index.data(zPosRole).toReal()); + itemValueMap[rowRoleStr][columnRoleStr] = itemPos; if (generateRows && !rowListHash.value(rowRoleStr, false)) { rowListHash.insert(rowRoleStr, true); rowList << rowRoleStr; @@ -128,11 +161,8 @@ void SurfaceItemModelHandler::resolveModel() for (int i = 0; i < rowList.size(); i++) { QString rowKey = rowList.at(i); QSurfaceDataRow &newProxyRow = *m_proxyArray->at(i); - for (int j = 0; j < columnList.size(); j++) { - newProxyRow[j].setPosition(QVector3D(columnList.at(j).toFloat(), - itemValueMap[rowKey][columnList.at(j)], - rowList.at(i).toFloat())); - } + for (int j = 0; j < columnList.size(); j++) + newProxyRow[j].setPosition(itemValueMap[rowKey][columnList.at(j)]); } } diff --git a/src/datavisualization/doc/snippets/doc_src_qtdatavisualization.cpp b/src/datavisualization/doc/snippets/doc_src_qtdatavisualization.cpp index 458eeb45..6c6e49aa 100644 --- a/src/datavisualization/doc/snippets/doc_src_qtdatavisualization.cpp +++ b/src/datavisualization/doc/snippets/doc_src_qtdatavisualization.cpp @@ -72,7 +72,7 @@ QItemModelScatterDataProxy *proxy = new QItemModelScatterDataProxy(customModel, QItemModelSurfaceDataProxy *proxy = new QItemModelSurfaceDataProxy(customModel, QStringLiteral("longitude"), // Row role QStringLiteral("latitude"), // Column role - QStringLiteral("height")); // value role + QStringLiteral("height")); // Y-position role //! [5] //! [6] -- cgit v1.2.3