summaryrefslogtreecommitdiffstats
path: root/src/datavisualization/data/baritemmodelhandler.cpp
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2013-09-27 11:04:58 +0300
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2013-09-27 11:39:25 +0300
commitd4d99e49c147f4f61c0d5e84e59c023789fae17d (patch)
treeba01feecf4a818b95b5260d6419589c7b5536768 /src/datavisualization/data/baritemmodelhandler.cpp
parent2d9dbd6bcb2c1a75f0a4230868854c495b2d530a (diff)
Allow resetting with existing array for bars and scatter
Improves performance when array dimensions do not change Task-number: QTRD-2335 Change-Id: I2733ff3552009a19cf285bc91426f595b64795dd Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src/datavisualization/data/baritemmodelhandler.cpp')
-rw-r--r--src/datavisualization/data/baritemmodelhandler.cpp40
1 files changed, 29 insertions, 11 deletions
diff --git a/src/datavisualization/data/baritemmodelhandler.cpp b/src/datavisualization/data/baritemmodelhandler.cpp
index f456604b..f7611668 100644
--- a/src/datavisualization/data/baritemmodelhandler.cpp
+++ b/src/datavisualization/data/baritemmodelhandler.cpp
@@ -23,7 +23,9 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE
BarItemModelHandler::BarItemModelHandler(QItemModelBarDataProxy *proxy, QObject *parent)
: AbstractItemModelHandler(parent),
- m_proxy(proxy)
+ m_proxy(proxy),
+ m_proxyArray(0),
+ m_columnCount(0)
{
}
@@ -49,7 +51,6 @@ void BarItemModelHandler::resolveModel()
QStringList rowLabels;
QStringList columnLabels;
- QBarDataArray *newProxyArray = new QBarDataArray;
QHash<int, QByteArray> roleHash = m_itemModel->roleNames();
// Default to display role if no mapping
@@ -58,17 +59,25 @@ void BarItemModelHandler::resolveModel()
int columnCount = m_itemModel->columnCount();
if (mapping->useModelCategories()) {
+ // If dimensions have changed, recreate the array
+ if (m_proxyArray != m_proxy->array() || columnCount != m_columnCount
+ || rowCount != m_proxyArray->size()) {
+ m_proxyArray = new QBarDataArray;
+ m_proxyArray->reserve(rowCount);
+ for (int i = 0; i < rowCount; i++)
+ m_proxyArray->append(new QBarDataRow(columnCount));
+ }
for (int i = 0; i < rowCount; i++) {
- QBarDataRow *newProxyRow = new QBarDataRow(columnCount);
+ QBarDataRow &newProxyRow = *m_proxyArray->at(i);
for (int j = 0; j < columnCount; j++)
- (*newProxyRow)[j].setValue(m_itemModel->index(i, j).data(valueRole).toReal());
- newProxyArray->append(newProxyRow);
+ newProxyRow[j].setValue(m_itemModel->index(i, j).data(valueRole).toReal());
}
// Generate labels from headers if using model rows/columns
for (int i = 0; i < rowCount; i++)
rowLabels << m_itemModel->headerData(i, Qt::Vertical).toString();
for (int i = 0; i < columnCount; i++)
columnLabels << m_itemModel->headerData(i, Qt::Horizontal).toString();
+ m_columnCount = columnCount;
} else {
int rowRole = roleHash.key(mapping->rowRole().toLatin1());
int columnRole = roleHash.key(mapping->columnRole().toLatin1());
@@ -112,19 +121,28 @@ void BarItemModelHandler::resolveModel()
else
columnList = mapping->columnCategories();
+ // If dimensions have changed, recreate the array
+ if (m_proxyArray != m_proxy->array() || columnList.size() != m_columnCount
+ || rowList.size() != m_proxyArray->size()) {
+ m_proxyArray = new QBarDataArray;
+ m_proxyArray->reserve(rowList.size());
+ for (int i = 0; i < rowList.size(); i++)
+ m_proxyArray->append(new QBarDataRow(columnList.size()));
+ }
// Create new data array from itemValueMap
- foreach (QString rowKey, rowList) {
- QBarDataRow *newProxyRow = new QBarDataRow(columnList.size());
- for (int i = 0; i < columnList.size(); i++)
- (*newProxyRow)[i].setValue(itemValueMap[rowKey][columnList.at(i)]);
- newProxyArray->append(newProxyRow);
+ 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++)
+ newProxyRow[j].setValue(itemValueMap[rowKey][columnList.at(j)]);
}
rowLabels = rowList;
columnLabels = columnList;
+ m_columnCount = columnList.size();
}
- m_proxy->resetArray(newProxyArray, rowLabels, columnLabels);
+ m_proxy->resetArray(m_proxyArray, rowLabels, columnLabels);
}
QT_DATAVISUALIZATION_END_NAMESPACE