summaryrefslogtreecommitdiffstats
path: root/src
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
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')
-rw-r--r--src/datavisualization/data/baritemmodelhandler.cpp40
-rw-r--r--src/datavisualization/data/baritemmodelhandler_p.h2
-rw-r--r--src/datavisualization/data/qbardataproxy.cpp80
-rw-r--r--src/datavisualization/data/qbardataproxy_p.h2
-rw-r--r--src/datavisualization/data/qscatterdataproxy.cpp42
-rw-r--r--src/datavisualization/data/qscatterdataproxy_p.h2
-rw-r--r--src/datavisualization/data/qsurfacedataproxy.cpp2
-rw-r--r--src/datavisualization/data/scatteritemmodelhandler.cpp19
-rw-r--r--src/datavisualization/data/scatteritemmodelhandler_p.h1
-rw-r--r--src/datavisualization/data/scatterrenderitem.cpp6
-rw-r--r--src/datavisualization/data/scatterrenderitem_p.h4
-rw-r--r--src/datavisualization/data/surfaceitemmodelhandler.cpp18
-rw-r--r--src/datavisualization/engine/scatter3drenderer.cpp21
13 files changed, 148 insertions, 91 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
diff --git a/src/datavisualization/data/baritemmodelhandler_p.h b/src/datavisualization/data/baritemmodelhandler_p.h
index 94e83b9d..54b45f2e 100644
--- a/src/datavisualization/data/baritemmodelhandler_p.h
+++ b/src/datavisualization/data/baritemmodelhandler_p.h
@@ -45,6 +45,8 @@ protected:
void virtual resolveModel();
QItemModelBarDataProxy *m_proxy; // Not owned
+ QBarDataArray *m_proxyArray; // Not owned
+ int m_columnCount;
};
QT_DATAVISUALIZATION_END_NAMESPACE
diff --git a/src/datavisualization/data/qbardataproxy.cpp b/src/datavisualization/data/qbardataproxy.cpp
index badbfb7b..f1f36638 100644
--- a/src/datavisualization/data/qbardataproxy.cpp
+++ b/src/datavisualization/data/qbardataproxy.cpp
@@ -34,8 +34,8 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE
*
* QBarDataProxy takes ownership of all QBarDataRows passed to it, whether directly or
* in a QBarDataArray container.
- * QBarDataRow pointers should not be used to modify data further after they have been passed to
- * the proxy, as such modifications will not trigger proper signals.
+ * If you use QBarDataRow pointers to directly modify data after adding the array to the proxy,
+ * you must also emit proper signal to make the graph update.
*
* QBarDataProxy optionally keeps track of row and column labels, which Q3DCategoryAxis can utilize
* to show axis labels. The row and column labels are stored in separate array from the data and
@@ -129,34 +129,35 @@ void QBarDataProxy::resetArray()
}
/*!
- * Clears the existing array and takes ownership of the \a newArray. Do not use \a newArray pointer
- * to further modify data after QBarDataProxy assumes ownership of it, as such modifications will
- * not trigger proper signals.
- * Passing null array clears all data.
+ * Takes ownership of the \a newArray. Clears the existing array and if the \a newArray is
+ * different than the existing array. If it's the same array, this just triggers arrayReset()
+ * signal.
+ * Passing null array deletes the old array and creates a new empty array.
* Row and column labels are not affected.
*/
void QBarDataProxy::resetArray(QBarDataArray *newArray)
{
- if (dptr()->resetArray(newArray, 0, 0))
- emit arrayReset();
+ dptr()->resetArray(newArray, 0, 0);
+ emit arrayReset();
}
/*!
- * Clears the existing array and takes ownership of the \a newArray. Do not use \a newArray pointer
- * to further modify data after QBarDataProxy assumes ownership of it, as such modifications will
- * not trigger proper signals.
- * Passing null array clears all data.
+ * Takes ownership of the \a newArray. Clears the existing array and if the \a newArray is
+ * different than the existing array. If it's the same array, this just triggers arrayReset()
+ * signal.
+ * Passing null array deletes the old array and creates a new empty array.
* The \a rowLabels and \a columnLabels lists specify the new labels for rows and columns.
*/
void QBarDataProxy::resetArray(QBarDataArray *newArray, const QStringList &rowLabels,
const QStringList &columnLabels)
{
- if (dptr()->resetArray(newArray, &rowLabels, &columnLabels))
- emit arrayReset();
+ dptr()->resetArray(newArray, &rowLabels, &columnLabels);
+ emit arrayReset();
}
/*!
- * Changes existing rows by replacing a row at \a rowIndex with \a row.
+ * Changes existing rows by replacing a row at \a rowIndex with \a row. The \a row can be
+ * the same as the existing row already stored at the \a rowIndex.
* Existing row labels are not affected.
*/
void QBarDataProxy::setRow(int rowIndex, QBarDataRow *row)
@@ -166,7 +167,8 @@ void QBarDataProxy::setRow(int rowIndex, QBarDataRow *row)
}
/*!
- * Changes existing rows by replacing a row at \a rowIndex with \a row.
+ * Changes existing rows by replacing a row at \a rowIndex with \a row. The \a row can be
+ * the same as the existing row already stored at the \a rowIndex.
* Changes the row label to the \a label.
*/
void QBarDataProxy::setRow(int rowIndex, QBarDataRow *row, const QString &label)
@@ -177,7 +179,8 @@ void QBarDataProxy::setRow(int rowIndex, QBarDataRow *row, const QString &label)
/*!
* Changes existing rows by replacing a rows starting at \a rowIndex with \a rows.
- * Existing row labels are not affected.
+ * Existing row labels are not affected. The rows in the \a rows array can be
+ * the same as the existing rows already stored at the \a rowIndex.
*/
void QBarDataProxy::setRows(int rowIndex, const QBarDataArray &rows)
{
@@ -187,7 +190,8 @@ void QBarDataProxy::setRows(int rowIndex, const QBarDataArray &rows)
/*!
* Changes existing rows by replacing a rows starting at \a rowIndex with \a rows.
- * The row labels are changed to \a labels.
+ * The row labels are changed to \a labels. The rows in the \a rows array can be
+ * the same as the existing rows already stored at the \a rowIndex.
*/
void QBarDataProxy::setRows(int rowIndex, const QBarDataArray &rows, const QStringList &labels)
{
@@ -415,18 +419,24 @@ const QBarDataProxyPrivate *QBarDataProxy::dptrc() const
* \fn void QBarDataProxy::arrayReset()
*
* Emitted when data array is reset.
+ * If you change the whole array contents without calling resetArray(), you need to
+ * emit this signal yourself or the graph won't get updated.
*/
/*!
* \fn void QBarDataProxy::rowsAdded(int startIndex, int count)
*
* Emitted when rows have been added. Provides \a startIndex and \a count of rows added.
+ * If you add rows directly to the array without calling addRow() or addRows(), you
+ * need to emit this signal yourself or the graph won't get updated.
*/
/*!
* \fn void QBarDataProxy::rowsChanged(int startIndex, int count)
*
* Emitted when rows have changed. Provides \a startIndex and \a count of changed rows.
+ * If you change rows directly in the array without calling setRow() or setRows(), you
+ * need to emit this signal yourself or the graph won't get updated.
*/
/*!
@@ -434,18 +444,24 @@ const QBarDataProxyPrivate *QBarDataProxy::dptrc() const
*
* Emitted when rows have been removed. Provides \a startIndex and \a count of rows removed.
* Index is the current array size if rows were removed from the end of the array.
+ * If you remove rows directly from the array without calling removeRows(), you
+ * need to emit this signal yourself or the graph won't get updated.
*/
/*!
* \fn void QBarDataProxy::rowsInserted(int startIndex, int count)
*
* Emitted when rows have been inserted. Provides \a startIndex and \a count of inserted rows.
+ * If you insert rows directly into the array without calling insertRow() or insertRows(), you
+ * need to emit this signal yourself or the graph won't get updated.
*/
/*!
* \fn void QBarDataProxy::itemChanged(int rowIndex, int columnIndex)
*
* Emitted when an item has changed. Provides \a rowIndex and \a columnIndex of changed item.
+ * If you change an item directly in the array without calling setItem(), you
+ * need to emit this signal yourself or the graph won't get updated.
*/
// QBarDataProxyPrivate
@@ -462,7 +478,7 @@ QBarDataProxyPrivate::~QBarDataProxyPrivate()
clearArray();
}
-bool QBarDataProxyPrivate::resetArray(QBarDataArray *newArray, const QStringList *rowLabels,
+void QBarDataProxyPrivate::resetArray(QBarDataArray *newArray, const QStringList *rowLabels,
const QStringList *columnLabels)
{
if (rowLabels)
@@ -470,17 +486,13 @@ bool QBarDataProxyPrivate::resetArray(QBarDataArray *newArray, const QStringList
if (columnLabels)
qptr()->setColumnLabels(*columnLabels);
- if (!m_dataArray->size() && (!newArray || !newArray->size()))
- return false;
-
- clearArray();
+ if (!newArray)
+ newArray = new QBarDataArray;
- if (newArray)
+ if (newArray != m_dataArray) {
+ clearArray();
m_dataArray = newArray;
- else
- m_dataArray = new QBarDataArray;
-
- return true;
+ }
}
void QBarDataProxyPrivate::setRow(int rowIndex, QBarDataRow *row, const QString *label)
@@ -489,8 +501,10 @@ void QBarDataProxyPrivate::setRow(int rowIndex, QBarDataRow *row, const QString
if (label)
fixRowLabels(rowIndex, 1, QStringList(*label), false);
- clearRow(rowIndex);
- (*m_dataArray)[rowIndex] = row;
+ if (row != m_dataArray->at(rowIndex)) {
+ clearRow(rowIndex);
+ (*m_dataArray)[rowIndex] = row;
+ }
}
void QBarDataProxyPrivate::setRows(int rowIndex, const QBarDataArray &rows, const QStringList *labels)
@@ -500,8 +514,10 @@ void QBarDataProxyPrivate::setRows(int rowIndex, const QBarDataArray &rows, cons
if (labels)
fixRowLabels(rowIndex, rows.size(), *labels, false);
for (int i = 0; i < rows.size(); i++) {
- clearRow(rowIndex);
- dataArray[rowIndex] = rows.at(i);
+ if (rows.at(i) != dataArray.at(rowIndex)) {
+ clearRow(rowIndex);
+ dataArray[rowIndex] = rows.at(i);
+ }
rowIndex++;
}
}
diff --git a/src/datavisualization/data/qbardataproxy_p.h b/src/datavisualization/data/qbardataproxy_p.h
index a0f95d35..4d51bd5b 100644
--- a/src/datavisualization/data/qbardataproxy_p.h
+++ b/src/datavisualization/data/qbardataproxy_p.h
@@ -42,7 +42,7 @@ public:
QBarDataProxyPrivate(QBarDataProxy *q);
virtual ~QBarDataProxyPrivate();
- bool resetArray(QBarDataArray *newArray, const QStringList *rowLabels,
+ void resetArray(QBarDataArray *newArray, const QStringList *rowLabels,
const QStringList *columnLabels);
void setRow(int rowIndex, QBarDataRow *row, const QString *label);
void setRows(int rowIndex, const QBarDataArray &rows, const QStringList *labels);
diff --git a/src/datavisualization/data/qscatterdataproxy.cpp b/src/datavisualization/data/qscatterdataproxy.cpp
index f020ac12..50328d1a 100644
--- a/src/datavisualization/data/qscatterdataproxy.cpp
+++ b/src/datavisualization/data/qscatterdataproxy.cpp
@@ -91,15 +91,17 @@ QScatterDataProxy::~QScatterDataProxy()
}
/*!
- * Clears the existing array and takes ownership of the \a newArray. Do not use \a newArray pointer
- * to further modify data after QScatterDataProxy assumes ownership of it, as such modifications will
- * not trigger proper signals.
- * Passing null array clears all data.
+ * Takes ownership of the \a newArray. Clears the existing array and if the \a newArray is
+ * different than the existing array. If it's the same array, this just triggers arrayReset()
+ * signal.
+ * Passing null array deletes the old array and creates a new empty array.
*/
void QScatterDataProxy::resetArray(QScatterDataArray *newArray)
{
- if (dptr()->resetArray(newArray))
- emit arrayReset();
+ if (dptr()->m_dataArray != newArray)
+ dptr()->resetArray(newArray);
+
+ emit arrayReset();
}
/*!
@@ -220,18 +222,24 @@ const QScatterDataProxyPrivate *QScatterDataProxy::dptrc() const
* \fn void QScatterDataProxy::arrayReset()
*
* Emitted when data array is reset.
+ * If you change the whole array contents without calling resetArray(), you need to
+ * emit this signal yourself or the graph won't get updated.
*/
/*!
* \fn void QScatterDataProxy::itemsAdded(int startIndex, int count)
*
* Emitted when items have been added. Provides \a startIndex and \a count of items added.
+ * If you add items directly to the array without calling addItem() or addItems(), you
+ * need to emit this signal yourself or the graph won't get updated.
*/
/*!
* \fn void QScatterDataProxy::itemsChanged(int startIndex, int count)
*
* Emitted when items have changed. Provides \a startIndex and \a count of changed items.
+ * If you change items directly in the array without calling setItem() or setItems(), you
+ * need to emit this signal yourself or the graph won't get updated.
*/
/*!
@@ -239,12 +247,16 @@ const QScatterDataProxyPrivate *QScatterDataProxy::dptrc() const
*
* Emitted when items have been removed. Provides \a startIndex and \a count of items removed.
* Index may be over current array size if removed from end.
+ * If you remove items directly from the array without calling removeItems(), you
+ * need to emit this signal yourself or the graph won't get updated.
*/
/*!
* \fn void QScatterDataProxy::itemsInserted(int startIndex, int count)
*
* Emitted when items have been inserted. Provides \a startIndex and \a count of inserted items.
+ * If you insert items directly into the array without calling insertItem() or insertItems(), you
+ * need to emit this signal yourself or the graph won't get updated.
*/
// QScatterDataProxyPrivate
@@ -262,20 +274,16 @@ QScatterDataProxyPrivate::~QScatterDataProxyPrivate()
delete m_dataArray;
}
-bool QScatterDataProxyPrivate::resetArray(QScatterDataArray *newArray)
+void QScatterDataProxyPrivate::resetArray(QScatterDataArray *newArray)
{
- if (!m_dataArray->size() && (!newArray || !newArray->size()))
- return false;
-
- m_dataArray->clear();
- delete m_dataArray;
+ if (!newArray)
+ newArray = new QScatterDataArray;
- if (newArray)
+ if (newArray != m_dataArray) {
+ m_dataArray->clear();
+ delete m_dataArray;
m_dataArray = newArray;
- else
- m_dataArray = new QScatterDataArray;
-
- return true;
+ }
}
void QScatterDataProxyPrivate::setItem(int index, const QScatterDataItem &item)
diff --git a/src/datavisualization/data/qscatterdataproxy_p.h b/src/datavisualization/data/qscatterdataproxy_p.h
index fe06fcf9..9920e3a7 100644
--- a/src/datavisualization/data/qscatterdataproxy_p.h
+++ b/src/datavisualization/data/qscatterdataproxy_p.h
@@ -42,7 +42,7 @@ public:
QScatterDataProxyPrivate(QScatterDataProxy *q);
virtual ~QScatterDataProxyPrivate();
- bool resetArray(QScatterDataArray *newArray);
+ void resetArray(QScatterDataArray *newArray);
void setItem(int index, const QScatterDataItem &item);
void setItems(int index, const QScatterDataArray &items);
int addItem(const QScatterDataItem &item);
diff --git a/src/datavisualization/data/qsurfacedataproxy.cpp b/src/datavisualization/data/qsurfacedataproxy.cpp
index 98998f10..3b683bbc 100644
--- a/src/datavisualization/data/qsurfacedataproxy.cpp
+++ b/src/datavisualization/data/qsurfacedataproxy.cpp
@@ -237,6 +237,8 @@ const QSurfaceDataProxyPrivate *QSurfaceDataProxy::dptrc() const
* \fn void QSurfaceDataProxy::arrayReset()
*
* Emitted when data array is reset.
+ * If you change the whole array contents without calling resetArray(), you need to
+ * emit this signal yourself or the graph won't get updated.
*/
/*!
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
diff --git a/src/datavisualization/data/scatteritemmodelhandler_p.h b/src/datavisualization/data/scatteritemmodelhandler_p.h
index c39bc57f..9b8a19a2 100644
--- a/src/datavisualization/data/scatteritemmodelhandler_p.h
+++ b/src/datavisualization/data/scatteritemmodelhandler_p.h
@@ -45,6 +45,7 @@ protected:
void virtual resolveModel();
QItemModelScatterDataProxy *m_proxy; // Not owned
+ QScatterDataArray *m_proxyArray; // Not owned
};
QT_DATAVISUALIZATION_END_NAMESPACE
diff --git a/src/datavisualization/data/scatterrenderitem.cpp b/src/datavisualization/data/scatterrenderitem.cpp
index 1fd7ad97..83c66583 100644
--- a/src/datavisualization/data/scatterrenderitem.cpp
+++ b/src/datavisualization/data/scatterrenderitem.cpp
@@ -23,12 +23,14 @@
QT_DATAVISUALIZATION_BEGIN_NAMESPACE
ScatterRenderItem::ScatterRenderItem()
- : AbstractRenderItem()
+ : AbstractRenderItem(),
+ m_visible(false)
{
}
ScatterRenderItem::ScatterRenderItem(const ScatterRenderItem &other)
- : AbstractRenderItem(other)
+ : AbstractRenderItem(other),
+ m_visible(false)
{
m_position = other.m_position;
}
diff --git a/src/datavisualization/data/scatterrenderitem_p.h b/src/datavisualization/data/scatterrenderitem_p.h
index 09c1246e..46df6c85 100644
--- a/src/datavisualization/data/scatterrenderitem_p.h
+++ b/src/datavisualization/data/scatterrenderitem_p.h
@@ -45,11 +45,15 @@ public:
inline const QVector3D &position() const { return m_position; }
inline void setPosition(const QVector3D &pos);
+ inline const bool isVisible() const { return m_visible; }
+ inline void setVisible(bool visible) { m_visible = visible; }
+
//inline void setSize(qreal size);
//inline qreal size() const { return m_size; }
protected:
QVector3D m_position;
+ bool m_visible;
//qreal m_size; // TODO in case we need a fourth variable that adjusts scatter item size
friend class QScatterDataItem;
diff --git a/src/datavisualization/data/surfaceitemmodelhandler.cpp b/src/datavisualization/data/surfaceitemmodelhandler.cpp
index d32b442b..a9882040 100644
--- a/src/datavisualization/data/surfaceitemmodelhandler.cpp
+++ b/src/datavisualization/data/surfaceitemmodelhandler.cpp
@@ -38,12 +38,14 @@ void SurfaceItemModelHandler::resolveModel()
QItemModelSurfaceDataMapping *mapping = static_cast<QItemModelSurfaceDataMapping *>(m_activeMapping);
if (m_itemModel.isNull() || !mapping) {
m_proxy->resetArray(0);
+ m_proxyArray = 0;
return;
}
if (!mapping->useModelCategories()
&& (mapping->rowRole().isEmpty() || mapping->columnRole().isEmpty())) {
m_proxy->resetArray(0);
+ m_proxyArray = 0;
return;
}
@@ -61,14 +63,12 @@ void SurfaceItemModelHandler::resolveModel()
if (mapping->useModelCategories()) {
// If dimensions have changed, recreate the array
- if (!m_proxyArray || columnCount != m_proxy->columnCount()
+ if (m_proxyArray != m_proxy->array() || columnCount != m_proxy->columnCount()
|| rowCount != m_proxyArray->size()) {
m_proxyArray = new QSurfaceDataArray;
m_proxyArray->reserve(rowCount);
- for (int i = 0; i < rowCount; i++) {
- QSurfaceDataRow *newProxyRow = new QSurfaceDataRow(columnCount);
- m_proxyArray->append(newProxyRow);
- }
+ for (int i = 0; i < rowCount; i++)
+ m_proxyArray->append(new QSurfaceDataRow(columnCount));
}
for (int i = 0; i < rowCount; i++) {
QSurfaceDataRow &newProxyRow = *m_proxyArray->at(i);
@@ -128,14 +128,12 @@ void SurfaceItemModelHandler::resolveModel()
columnList = mapping->columnCategories();
// If dimensions have changed, recreate the array
- if (!m_proxyArray || columnList.size() != m_proxy->columnCount()
+ if (m_proxyArray != m_proxy->array() || columnList.size() != m_proxy->columnCount()
|| rowList.size() != m_proxyArray->size()) {
m_proxyArray = new QSurfaceDataArray;
m_proxyArray->reserve(rowList.size());
- for (int i = 0; i < rowList.size(); i++) {
- QSurfaceDataRow *newProxyRow = new QSurfaceDataRow(columnList.size());
- m_proxyArray->append(newProxyRow);
- }
+ for (int i = 0; i < rowList.size(); i++)
+ m_proxyArray->append(new QSurfaceDataRow(columnList.size()));
}
// Create data array from itemValueMap
for (int i = 0; i < rowList.size(); i++) {
diff --git a/src/datavisualization/engine/scatter3drenderer.cpp b/src/datavisualization/engine/scatter3drenderer.cpp
index 5c643bb2..28359c5a 100644
--- a/src/datavisualization/engine/scatter3drenderer.cpp
+++ b/src/datavisualization/engine/scatter3drenderer.cpp
@@ -140,23 +140,24 @@ void Scatter3DRenderer::initializeOpenGL()
void Scatter3DRenderer::updateDataModel(QScatterDataProxy *dataProxy)
{
- int actualDataSize = 0;
const QScatterDataArray &dataArray = *dataProxy->array();
calculateSceneScalingFactors();
int dataSize = dataArray.size();
- m_renderItemArray.resize(dataSize);
+ if (dataSize != m_renderItemArray.size())
+ m_renderItemArray.resize(dataSize);
for (int i = 0; i < dataSize ; i++) {
QVector3D dotPos = dataArray.at(i).position();
if ((dotPos.x() >= m_axisCacheX.min() && dotPos.x() <= m_axisCacheX.max())
&& (dotPos.y() >= m_axisCacheY.min() && dotPos.y() <= m_axisCacheY.max())
&& (dotPos.z() >= m_axisCacheZ.min() && dotPos.z() <= m_axisCacheZ.max())) {
- m_renderItemArray[actualDataSize].setPosition(dotPos);
- calculateTranslation(m_renderItemArray[actualDataSize]);
- actualDataSize++;
+ m_renderItemArray[i].setPosition(dotPos);
+ m_renderItemArray[i].setVisible(true);
+ calculateTranslation(m_renderItemArray[i]);
+ } else {
+ m_renderItemArray[i].setVisible(false);
}
}
- m_renderItemArray.resize(actualDataSize);
- m_dotSizeScale = (GLfloat)qBound(0.01, (2.0 / qSqrt((qreal)actualDataSize)), 0.1);
+ m_dotSizeScale = (GLfloat)qBound(0.01, (2.0 / qSqrt((qreal)dataSize)), 0.1);
m_selectedItem = 0;
Abstract3DRenderer::updateDataModel(dataProxy);
@@ -295,6 +296,8 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle)
// Draw dots to depth buffer
for (int dot = 0; dot < m_renderItemArray.size(); dot++) {
const ScatterRenderItem &item = m_renderItemArray.at(dot);
+ if (!item.isVisible())
+ continue;
QMatrix4x4 modelMatrix;
QMatrix4x4 MVPMatrix;
@@ -382,6 +385,8 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle)
for (int dot = 0; dot < arraySize; dot++) {
const ScatterRenderItem &item = m_renderItemArray.at(dot);
+ if (!item.isVisible())
+ continue;
QMatrix4x4 modelMatrix;
QMatrix4x4 MVPMatrix;
@@ -479,6 +484,8 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle)
for (int dot = 0; dot < m_renderItemArray.size(); dot++) {
ScatterRenderItem &item = m_renderItemArray[dot];
+ if (!item.isVisible())
+ continue;
QMatrix4x4 modelMatrix;
QMatrix4x4 MVPMatrix;