diff options
author | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2014-01-29 12:51:55 +0200 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2014-01-29 13:07:16 +0200 |
commit | 201a480af6ad2d36896570683ab87014827b9697 (patch) | |
tree | 3c12f6cf9c5a13a758e0e056515a05c96164b8d0 /src/datavisualization/data/baritemmodelhandler.cpp | |
parent | e616a4737c932546ab5eadee8f4f766d35d260d7 (diff) |
Rotation support for item models
Task-number: QTRD-2654
Change-Id: Ie919c3032731724f750fc0ccb237379454009585
Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src/datavisualization/data/baritemmodelhandler.cpp')
-rw-r--r-- | src/datavisualization/data/baritemmodelhandler.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/datavisualization/data/baritemmodelhandler.cpp b/src/datavisualization/data/baritemmodelhandler.cpp index 611fbcb9..4f44fe1d 100644 --- a/src/datavisualization/data/baritemmodelhandler.cpp +++ b/src/datavisualization/data/baritemmodelhandler.cpp @@ -20,6 +20,8 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION +static const int noRoleIndex = -1; + BarItemModelHandler::BarItemModelHandler(QItemModelBarDataProxy *proxy, QObject *parent) : AbstractItemModelHandler(parent), m_proxy(proxy), @@ -51,8 +53,9 @@ void BarItemModelHandler::resolveModel() QHash<int, QByteArray> roleHash = m_itemModel->roleNames(); - // Default to display role if no mapping + // Default value role to display role if no mapping int valueRole = roleHash.key(m_proxy->valueRole().toLatin1(), Qt::DisplayRole); + int rotationRole = roleHash.key(m_proxy->rotationRole().toLatin1(), noRoleIndex); int rowCount = m_itemModel->rowCount(); int columnCount = m_itemModel->columnCount(); @@ -67,8 +70,11 @@ void BarItemModelHandler::resolveModel() } for (int i = 0; i < rowCount; i++) { QBarDataRow &newProxyRow = *m_proxyArray->at(i); - for (int j = 0; j < columnCount; j++) + for (int j = 0; j < columnCount; j++) { newProxyRow[j].setValue(m_itemModel->index(i, j).data(valueRole).toReal()); + if (rotationRole != noRoleIndex) + newProxyRow[j].setRotation(m_itemModel->index(i, j).data(rotationRole).toReal()); + } } // Generate labels from headers if using model rows/columns for (int i = 0; i < rowCount; i++) @@ -92,12 +98,15 @@ void BarItemModelHandler::resolveModel() // Sort values into rows and columns typedef QHash<QString, float> ColumnValueMap; QHash <QString, ColumnValueMap> itemValueMap; + QHash <QString, ColumnValueMap> itemRotationMap; 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(); + if (rotationRole != noRoleIndex) + itemRotationMap[rowRoleStr][columnRoleStr] = index.data(rotationRole).toReal(); if (generateRows && !rowListHash.value(rowRoleStr, false)) { rowListHash.insert(rowRoleStr, true); rowList << rowRoleStr; @@ -131,8 +140,11 @@ void BarItemModelHandler::resolveModel() for (int i = 0; i < rowList.size(); i++) { QString rowKey = rowList.at(i); QBarDataRow &newProxyRow = *m_proxyArray->at(i); - for (int j = 0; j < columnList.size(); j++) + for (int j = 0; j < columnList.size(); j++) { newProxyRow[j].setValue(itemValueMap[rowKey][columnList.at(j)]); + if (rotationRole != noRoleIndex) + newProxyRow[j].setRotation(itemRotationMap[rowKey][columnList.at(j)]); + } } rowLabels = rowList; |