summaryrefslogtreecommitdiffstats
path: root/src/datavisualization/data/scatteritemmodelhandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/datavisualization/data/scatteritemmodelhandler.cpp')
-rw-r--r--src/datavisualization/data/scatteritemmodelhandler.cpp19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/datavisualization/data/scatteritemmodelhandler.cpp b/src/datavisualization/data/scatteritemmodelhandler.cpp
index a6430297..34230ae0 100644
--- a/src/datavisualization/data/scatteritemmodelhandler.cpp
+++ b/src/datavisualization/data/scatteritemmodelhandler.cpp
@@ -23,7 +23,8 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE
ScatterItemModelHandler::ScatterItemModelHandler(QItemModelScatterDataProxy *proxy, QObject *parent)
: AbstractItemModelHandler(parent),
- m_proxy(proxy)
+ m_proxy(proxy),
+ m_proxyArray(0)
{
}
@@ -37,30 +38,29 @@ void ScatterItemModelHandler::resolveModel()
QItemModelScatterDataMapping *mapping = static_cast<QItemModelScatterDataMapping *>(m_activeMapping);
if (m_itemModel.isNull() || !mapping) {
m_proxy->resetArray(0);
+ m_proxyArray = 0;
return;
}
static const int noRoleIndex = -1;
QHash<int, QByteArray> roleHash = m_itemModel->roleNames();
- //const int labelRole = roleHash.key(mapping->labelRole().toLatin1(), noRoleIndex);
const int xPosRole = roleHash.key(mapping->xPosRole().toLatin1(), noRoleIndex);
const int yPosRole = roleHash.key(mapping->yPosRole().toLatin1(), noRoleIndex);
const int zPosRole = roleHash.key(mapping->zPosRole().toLatin1(), noRoleIndex);
- // Default valueRole to display role if no mapping
- //const int valueRole = roleHash.key(mapping->valueRole().toLatin1(), Qt::DisplayRole);
const int columnCount = m_itemModel->columnCount();
const int rowCount = m_itemModel->rowCount();
const int totalCount = rowCount * columnCount;
int runningCount = 0;
+ // If dimensions have changed, recreate the array
+ if (m_proxyArray != m_proxy->array() || totalCount != m_proxyArray->size())
+ m_proxyArray = new QScatterDataArray(totalCount);
+
// Parse data into newProxyArray
- QScatterDataArray *newProxyArray = new QScatterDataArray(totalCount);
for (int i = 0; i < rowCount; i++) {
for (int j = 0; j < columnCount; j++) {
QModelIndex index = m_itemModel->index(i, j);
- //if (labelRole != noRoleIndex)
- // (*newProxyArray)[runningCount].setLabel(index.data(labelRole).toString());
float xPos(0.0f);
float yPos(0.0f);
float zPos(0.0f);
@@ -70,13 +70,12 @@ void ScatterItemModelHandler::resolveModel()
yPos = index.data(yPosRole).toFloat();
if (zPosRole != noRoleIndex)
zPos = index.data(zPosRole).toFloat();
- (*newProxyArray)[runningCount].setPosition(QVector3D(xPos, yPos, zPos));
- //(*newProxyArray)[runningCount].setValue(index.data(valueRole).toReal());
+ (*m_proxyArray)[runningCount].setPosition(QVector3D(xPos, yPos, zPos));
runningCount++;
}
}
- m_proxy->resetArray(newProxyArray);
+ m_proxy->resetArray(m_proxyArray);
}
QT_DATAVISUALIZATION_END_NAMESPACE