summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2013-09-10 16:26:11 +0300
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2013-09-11 10:42:53 +0300
commitd93f5f3b64fdb52cc150232f6b6d80ffdb57db78 (patch)
tree4a99ecc02c2e885b56abb1082527e482967b84f8 /src
parentd315336b202ec1c1260f96945a23fde6d2c41b69 (diff)
QBarDataProxy now has list of row and column labels
Category axes use those labels if no explicit labels are set to them. + Other misc fixes Task-number: QTRD-2252 Change-Id: Idc15e0cc1cdeb08195b2e2baeead9cfef2533e04 Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/datavisualization/axis/q3dcategoryaxis.cpp49
-rw-r--r--src/datavisualization/axis/q3dcategoryaxis.h4
-rw-r--r--src/datavisualization/axis/q3dcategoryaxis_p.h8
-rw-r--r--src/datavisualization/data/baritemmodelhandler.cpp12
-rw-r--r--src/datavisualization/data/qbardataproxy.cpp291
-rw-r--r--src/datavisualization/data/qbardataproxy.h24
-rw-r--r--src/datavisualization/data/qbardataproxy_p.h24
-rw-r--r--src/datavisualization/engine/abstract3dcontroller_p.h2
-rw-r--r--src/datavisualization/engine/abstract3drenderer_p.h2
-rw-r--r--src/datavisualization/engine/bars3dcontroller.cpp45
-rw-r--r--src/datavisualization/engine/bars3dcontroller_p.h5
-rw-r--r--src/datavisualization/engine/q3dscene.cpp1
-rw-r--r--src/datavisualization/engine/q3dwindow.h2
-rw-r--r--src/datavisualization/engine/surface3drenderer.cpp1
14 files changed, 422 insertions, 48 deletions
diff --git a/src/datavisualization/axis/q3dcategoryaxis.cpp b/src/datavisualization/axis/q3dcategoryaxis.cpp
index 55a27f52..90a7ff45 100644
--- a/src/datavisualization/axis/q3dcategoryaxis.cpp
+++ b/src/datavisualization/axis/q3dcategoryaxis.cpp
@@ -18,6 +18,8 @@
#include "q3dcategoryaxis.h"
#include "q3dcategoryaxis_p.h"
+#include "bars3dcontroller_p.h"
+#include "qbardataproxy.h"
QT_DATAVISUALIZATION_BEGIN_NAMESPACE
@@ -53,7 +55,12 @@ Q3DCategoryAxis::~Q3DCategoryAxis()
* \property Q3DCategoryAxis::categoryLabels
*
* Defines labels for axis applied to categories. If there are fewer labels than categories, the
- * remaining ones do not have a label.
+ * remaining ones do not have a label. If category labels are not explicitly defined, labels are
+ * generated from the data row and column labels.
+ *
+ * \note CategoryLabels actually reads/writes the Q3DAbstractAxis::labels property,
+ * which is read only there. Since subclass cannot have property with same name,
+ * this partially duplicate property is necessary.
*/
QStringList Q3DCategoryAxis::categoryLabels() const
{
@@ -62,7 +69,24 @@ QStringList Q3DCategoryAxis::categoryLabels() const
void Q3DCategoryAxis::setCategoryLabels(const QStringList &labels)
{
- if (d_ptr->m_labels != labels) {
+ dptr()->m_labelsExplicitlySet = !labels.isEmpty();
+ bool labelsFromData = false;
+
+ // Get labels from data proxy if axis is attached to a bar controller and an active axis there
+ if (labels.isEmpty()) {
+ Bars3DController *controller = qobject_cast<Bars3DController *>(parent());
+ if (controller) {
+ if (controller->axisX() == this) {
+ controller->handleDataRowLabelsChanged();
+ labelsFromData = true;
+ } else if (controller->axisZ() == this) {
+ controller->handleDataColumnLabelsChanged();
+ labelsFromData = true;
+ }
+ }
+ }
+
+ if (!labelsFromData && d_ptr->m_labels != labels) {
d_ptr->m_labels = labels;
emit labelsChanged();
}
@@ -77,7 +101,8 @@ Q3DCategoryAxisPrivate *Q3DCategoryAxis::dptr()
}
Q3DCategoryAxisPrivate::Q3DCategoryAxisPrivate(Q3DCategoryAxis *q)
- : Q3DAbstractAxisPrivate(q, Q3DAbstractAxis::AxisTypeCategory)
+ : Q3DAbstractAxisPrivate(q, Q3DAbstractAxis::AxisTypeCategory),
+ m_labelsExplicitlySet(false)
{
}
@@ -85,4 +110,22 @@ Q3DCategoryAxisPrivate::~Q3DCategoryAxisPrivate()
{
}
+/*!
+ * \internal
+ * Controller uses this function to set labels from data proxy as category labels.
+ * If the labels have been explicitly set by user, data proxy labels are not used.
+ */
+void Q3DCategoryAxisPrivate::setDataLabels(const QStringList &labels)
+{
+ if (!m_labelsExplicitlySet && m_labels != labels) {
+ m_labels = labels;
+ emit qptr()->labelsChanged();
+ }
+}
+
+Q3DCategoryAxis *Q3DCategoryAxisPrivate::qptr()
+{
+ return static_cast<Q3DCategoryAxis *>(q_ptr);
+}
+
QT_DATAVISUALIZATION_END_NAMESPACE
diff --git a/src/datavisualization/axis/q3dcategoryaxis.h b/src/datavisualization/axis/q3dcategoryaxis.h
index 8b7f966c..bf5e66fd 100644
--- a/src/datavisualization/axis/q3dcategoryaxis.h
+++ b/src/datavisualization/axis/q3dcategoryaxis.h
@@ -28,9 +28,6 @@ class Q3DCategoryAxisPrivate;
class QT_DATAVISUALIZATION_EXPORT Q3DCategoryAxis : public Q3DAbstractAxis
{
Q_OBJECT
- // Note: categoryLabels actually reads/writes the labels property in abstract axis,
- // which is read only there. Since subclass cannot have property with same name,
- // this partially duplicate property is necessary.
Q_PROPERTY(QStringList categoryLabels READ categoryLabels WRITE setCategoryLabels)
public:
@@ -47,6 +44,7 @@ protected:
private:
Q_DISABLE_COPY(Q3DCategoryAxis)
+ friend class Bars3DController;
};
QT_DATAVISUALIZATION_END_NAMESPACE
diff --git a/src/datavisualization/axis/q3dcategoryaxis_p.h b/src/datavisualization/axis/q3dcategoryaxis_p.h
index f7fa7b35..9b66e48a 100644
--- a/src/datavisualization/axis/q3dcategoryaxis_p.h
+++ b/src/datavisualization/axis/q3dcategoryaxis_p.h
@@ -42,6 +42,14 @@ class Q3DCategoryAxisPrivate : public Q3DAbstractAxisPrivate
public:
Q3DCategoryAxisPrivate(Q3DCategoryAxis *q);
virtual ~Q3DCategoryAxisPrivate();
+
+ void setDataLabels(const QStringList &labels);
+
+private:
+ Q3DCategoryAxis *qptr();
+
+ bool m_labelsExplicitlySet;
+ friend class Q3DCategoryAxis;
};
QT_DATAVISUALIZATION_END_NAMESPACE
diff --git a/src/datavisualization/data/baritemmodelhandler.cpp b/src/datavisualization/data/baritemmodelhandler.cpp
index ec922f2b..07a802cd 100644
--- a/src/datavisualization/data/baritemmodelhandler.cpp
+++ b/src/datavisualization/data/baritemmodelhandler.cpp
@@ -88,7 +88,17 @@ void BarItemModelHandler::resolveModel()
}
}
- m_proxy->resetArray(newProxyArray);
+ // Generate labels from headers if using model rows/columns
+ QStringList rowLabels;
+ QStringList columnLabels;
+ if (useModelRows) {
+ 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_proxy->resetArray(newProxyArray, rowLabels, columnLabels);
}
QT_DATAVISUALIZATION_END_NAMESPACE
diff --git a/src/datavisualization/data/qbardataproxy.cpp b/src/datavisualization/data/qbardataproxy.cpp
index 85400831..418bb747 100644
--- a/src/datavisualization/data/qbardataproxy.cpp
+++ b/src/datavisualization/data/qbardataproxy.cpp
@@ -37,6 +37,12 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE
* 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.
*
+ * 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
+ * row manipulation methods provide an alternate versions that don't affect the row labels.
+ * This enables the option of having row labels that relate to the position of the data in the
+ * array rather than the data itself.
+ *
* QBarDataProxy supports the following format tags for QAbstractDataProxy::setItemLabelFormat():
* \table
* \row
@@ -88,37 +94,82 @@ QBarDataProxy::~QBarDataProxy()
}
/*!
+ * Clears the existing array and row and column labels.
+ */
+void QBarDataProxy::resetArray()
+{
+ resetArray(0, QStringList(), QStringList());
+}
+
+/*!
* 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.
+ * Row and column labels are not affected.
*/
void QBarDataProxy::resetArray(QBarDataArray *newArray)
{
- if (dptr()->resetArray(newArray))
+ if (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.
+ * 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();
}
/*!
* Changes existing rows by replacing a row at \a rowIndex with \a row.
+ * Existing row labels are not affected.
*/
void QBarDataProxy::setRow(int rowIndex, QBarDataRow *row)
{
- dptr()->setRow(rowIndex, row);
+ dptr()->setRow(rowIndex, row, 0);
+ emit rowsChanged(rowIndex, 1);
+}
+
+/*!
+ * Changes existing rows by replacing a row at \a rowIndex with \a row.
+ * Changes the row label to the \a label.
+ */
+void QBarDataProxy::setRow(int rowIndex, QBarDataRow *row, const QString &label)
+{
+ dptr()->setRow(rowIndex, row, &label);
emit rowsChanged(rowIndex, 1);
}
/*!
* Changes existing rows by replacing a rows starting at \a rowIndex with \a rows.
+ * Existing row labels are not affected.
*/
void QBarDataProxy::setRows(int rowIndex, const QBarDataArray &rows)
{
- dptr()->setRows(rowIndex, rows);
+ dptr()->setRows(rowIndex, rows, 0);
emit rowsChanged(rowIndex, rows.size());
}
/*!
- * Changes a single item at \a rowIndex, \a columnIndex with \a item.
+ * Changes existing rows by replacing a rows starting at \a rowIndex with \a rows.
+ * The row labels are changed to \a labels.
+ */
+void QBarDataProxy::setRows(int rowIndex, const QBarDataArray &rows, const QStringList &labels)
+{
+ dptr()->setRows(rowIndex, rows, &labels);
+ emit rowsChanged(rowIndex, rows.size());
+}
+
+/*!
+ * Changes a single item at \a rowIndex, \a columnIndex to the \a item.
*/
void QBarDataProxy::setItem(int rowIndex, int columnIndex, const QBarDataItem &item)
{
@@ -128,56 +179,111 @@ void QBarDataProxy::setItem(int rowIndex, int columnIndex, const QBarDataItem &i
/*!
* Adds a new \a row to the end of array.
+ * Existing row labels are not affected.
*
* \return index of the added row.
*/
int QBarDataProxy::addRow(QBarDataRow *row)
{
- int addIndex = dptr()->addRow(row);
+ int addIndex = dptr()->addRow(row, 0);
+ emit rowsAdded(addIndex, 1);
+ return addIndex;
+}
+
+/*!
+ * Adds a new \a row with the \a label to the end of array.
+ *
+ * \return index of the added row.
+ */
+int QBarDataProxy::addRow(QBarDataRow *row, const QString &label)
+{
+ int addIndex = dptr()->addRow(row, &label);
emit rowsAdded(addIndex, 1);
return addIndex;
}
/*!
* Adds new \a rows to the end of array.
+ * Existing row labels are not affected.
*
* \return index of the first added row.
*/
int QBarDataProxy::addRows(const QBarDataArray &rows)
{
- int addIndex = dptr()->addRows(rows);
+ int addIndex = dptr()->addRows(rows, 0);
+ emit rowsAdded(addIndex, rows.size());
+ return addIndex;
+}
+
+/*!
+ * Adds new \a rows with \a labels to the end of array.
+ *
+ * \return index of the first added row.
+ */
+int QBarDataProxy::addRows(const QBarDataArray &rows, const QStringList &labels)
+{
+ int addIndex = dptr()->addRows(rows, &labels);
emit rowsAdded(addIndex, rows.size());
return addIndex;
}
/*!
- * Inserts a new \a row to \a rowIndex. If rowIndex is equal to array size, rows are added to end
- * of the array.
+ * Inserts a new \a row into \a rowIndex.
+ * If rowIndex is equal to array size, rows are added to end of the array.
+ * Any existing row labels are not affected.
+ * \note Row labels array will be out of sync with row array after this call,
+ * if there were labeled rows beyond the inserted row.
*/
void QBarDataProxy::insertRow(int rowIndex, QBarDataRow *row)
{
- dptr()->insertRow(rowIndex, row);
+ dptr()->insertRow(rowIndex, row, 0);
emit rowsInserted(rowIndex, 1);
}
/*!
- * Inserts new \a rows to \a rowIndex. If rowIndex is equal to array size, rows are added to end
- * of the array.
+ * Inserts a new \a row with the \a label into \a rowIndex.
+ * If rowIndex is equal to array size, rows are added to end of the array.
+ */
+void QBarDataProxy::insertRow(int rowIndex, QBarDataRow *row, const QString &label)
+{
+ dptr()->insertRow(rowIndex, row, &label);
+ emit rowsInserted(rowIndex, 1);
+}
+
+/*!
+ * Inserts new \a rows into \a rowIndex.
+ * If rowIndex is equal to array size, rows are added to end of the array.
+ * Any existing row labels are not affected.
+ * \note Row labels array will be out of sync with row array after this call,
+ * if there were labeled rows beyond the inserted rows.
*/
void QBarDataProxy::insertRows(int rowIndex, const QBarDataArray &rows)
{
- dptr()->insertRows(rowIndex, rows);
+ dptr()->insertRows(rowIndex, rows, 0);
+ emit rowsInserted(rowIndex, rows.size());
+}
+
+/*!
+ * Inserts new \a rows with \a labels into \a rowIndex.
+ * If rowIndex is equal to array size, rows are added to end of the array.
+ */
+void QBarDataProxy::insertRows(int rowIndex, const QBarDataArray &rows, const QStringList &labels)
+{
+ dptr()->insertRows(rowIndex, rows, &labels);
emit rowsInserted(rowIndex, rows.size());
}
/*!
* Removes \a removeCount rows staring at \a rowIndex. Attempting to remove rows past the end of the
- * array does nothing.
+ * array does nothing. If \a removeLabels is true, corresponding row labels are also removed. Otherwise
+ * the row labels are not affected.
+ * \note If \a removeLabels is false, the row labels array will be out of sync with the row array
+ * if there are labeled rows beyond the removed rows.
*/
-void QBarDataProxy::removeRows(int rowIndex, int removeCount)
+void QBarDataProxy::removeRows(int rowIndex, int removeCount, bool removeLabels)
{
- if (rowIndex < rowCount()) {
- dptr()->removeRows(rowIndex, removeCount);
+ if (rowIndex < rowCount() && removeCount >= 1) {
+ dptr()->removeRows(rowIndex, removeCount, removeLabels);
emit rowsRemoved(rowIndex, removeCount);
}
}
@@ -185,7 +291,7 @@ void QBarDataProxy::removeRows(int rowIndex, int removeCount)
/*!
* \property QBarDataProxy::rowCount
*
- * \return row count in the array.
+ * Row count in the array.
*/
int QBarDataProxy::rowCount() const
{
@@ -193,6 +299,45 @@ int QBarDataProxy::rowCount() const
}
/*!
+ * \property QBarDataProxy::rowLabels
+ *
+ * Optional row labels for the array. Indexes in this array match row indexes in data array.
+ * If the list is shorter than row count, all rows will not get labels.
+ */
+
+QStringList QBarDataProxy::rowLabels() const
+{
+ return dptrc()->m_rowLabels;
+}
+
+void QBarDataProxy::setRowLabels(const QStringList &labels)
+{
+ if (dptr()->m_rowLabels != labels) {
+ dptr()->m_rowLabels = labels;
+ emit rowLabelsChanged();
+ }
+}
+
+/*!
+ * \property QBarDataProxy::columnLabels
+ *
+ * Optional column labels for the array. Indexes in this array match column indexes in rows.
+ * If the list is shorter than the longest row, all columns will not get labels.
+ */
+QStringList QBarDataProxy::columnLabels() const
+{
+ return dptrc()->m_columnLabels;
+}
+
+void QBarDataProxy::setColumnLabels(const QStringList &labels)
+{
+ if (dptr()->m_columnLabels != labels) {
+ dptr()->m_columnLabels = labels;
+ emit columnLabelsChanged();
+ }
+}
+
+/*!
* \return pointer to the data array.
*/
const QBarDataArray *QBarDataProxy::array() const
@@ -291,8 +436,14 @@ QBarDataProxyPrivate::~QBarDataProxyPrivate()
clearArray();
}
-bool QBarDataProxyPrivate::resetArray(QBarDataArray *newArray)
+bool QBarDataProxyPrivate::resetArray(QBarDataArray *newArray, const QStringList *rowLabels,
+ const QStringList *columnLabels)
{
+ if (rowLabels)
+ qptr()->setRowLabels(*rowLabels);
+ if (columnLabels)
+ qptr()->setColumnLabels(*columnLabels);
+
if (!m_dataArray->size() && (!newArray || !newArray->size()))
return false;
@@ -306,17 +457,22 @@ bool QBarDataProxyPrivate::resetArray(QBarDataArray *newArray)
return true;
}
-void QBarDataProxyPrivate::setRow(int rowIndex, QBarDataRow *row)
+void QBarDataProxyPrivate::setRow(int rowIndex, QBarDataRow *row, const QString *label)
{
Q_ASSERT(rowIndex >= 0 && rowIndex < m_dataArray->size());
+
+ if (label)
+ fixRowLabels(rowIndex, 1, QStringList(*label), false);
clearRow(rowIndex);
(*m_dataArray)[rowIndex] = row;
}
-void QBarDataProxyPrivate::setRows(int rowIndex, const QBarDataArray &rows)
+void QBarDataProxyPrivate::setRows(int rowIndex, const QBarDataArray &rows, const QStringList *labels)
{
QBarDataArray &dataArray = *m_dataArray;
Q_ASSERT(rowIndex >= 0 && (rowIndex + rows.size()) <= dataArray.size());
+ if (labels)
+ fixRowLabels(rowIndex, rows.size(), *labels, false);
for (int i = 0; i < rows.size(); i++) {
clearRow(rowIndex);
dataArray[rowIndex] = rows.at(i);
@@ -332,43 +488,63 @@ void QBarDataProxyPrivate::setItem(int rowIndex, int columnIndex, const QBarData
row[columnIndex] = item;
}
-int QBarDataProxyPrivate::addRow(QBarDataRow *row)
+int QBarDataProxyPrivate::addRow(QBarDataRow *row, const QString *label)
{
int currentSize = m_dataArray->size();
+ if (label)
+ fixRowLabels(currentSize, 1, QStringList(*label), false);
m_dataArray->append(row);
return currentSize;
}
-int QBarDataProxyPrivate::addRows(const QBarDataArray &rows)
+int QBarDataProxyPrivate::addRows(const QBarDataArray &rows, const QStringList *labels)
{
int currentSize = m_dataArray->size();
+ if (labels)
+ fixRowLabels(currentSize, rows.size(), *labels, false);
for (int i = 0; i < rows.size(); i++)
m_dataArray->append(rows.at(i));
return currentSize;
}
-void QBarDataProxyPrivate::insertRow(int rowIndex, QBarDataRow *row)
+void QBarDataProxyPrivate::insertRow(int rowIndex, QBarDataRow *row, const QString *label)
{
Q_ASSERT(rowIndex >= 0 && rowIndex <= m_dataArray->size());
+ if (label)
+ fixRowLabels(rowIndex, 1, QStringList(*label), true);
m_dataArray->insert(rowIndex, row);
}
-void QBarDataProxyPrivate::insertRows(int rowIndex, const QBarDataArray &rows)
+void QBarDataProxyPrivate::insertRows(int rowIndex, const QBarDataArray &rows, const QStringList *labels)
{
Q_ASSERT(rowIndex >= 0 && rowIndex <= m_dataArray->size());
+ if (labels)
+ fixRowLabels(rowIndex, rows.size(), *labels, true);
for (int i = 0; i < rows.size(); i++)
m_dataArray->insert(rowIndex++, rows.at(i));
}
-void QBarDataProxyPrivate::removeRows(int rowIndex, int removeCount)
+void QBarDataProxyPrivate::removeRows(int rowIndex, int removeCount, bool removeLabels)
{
Q_ASSERT(rowIndex >= 0);
int maxRemoveCount = m_dataArray->size() - rowIndex;
removeCount = qMin(removeCount, maxRemoveCount);
+ bool labelsChanged = false;
for (int i = 0; i < removeCount; i++) {
clearRow(rowIndex);
m_dataArray->removeAt(rowIndex);
+ if (removeLabels && m_rowLabels.size() > rowIndex) {
+ m_rowLabels.removeAt(rowIndex);
+ labelsChanged = true;
+ }
}
+ if (labelsChanged)
+ emit qptr()->rowLabelsChanged();
+}
+
+QBarDataProxy *QBarDataProxyPrivate::qptr()
+{
+ return static_cast<QBarDataProxy *>(q_ptr);
}
void QBarDataProxyPrivate::clearRow(int rowIndex)
@@ -387,6 +563,71 @@ void QBarDataProxyPrivate::clearArray()
delete m_dataArray;
}
+/*!
+ * \internal
+ * Fixes the row label array to include specified labels.
+ */
+void QBarDataProxyPrivate::fixRowLabels(int startIndex, int count, const QStringList &newLabels, bool isInsert)
+{
+ bool changed = false;
+ int currentSize = m_rowLabels.size();
+
+ int newSize = newLabels.size();
+ if (startIndex >= currentSize) {
+ // Adding labels past old label array, create empty strings to fill intervening space
+ if (newSize) {
+ for (int i = currentSize; i < startIndex; i++)
+ m_rowLabels << QString();
+ // Doesn't matter if insert, append, or just change when there were no existing
+ // strings, just append new strings.
+ m_rowLabels << newLabels;
+ changed = true;
+ }
+ } else {
+ if (isInsert) {
+ int insertIndex = startIndex;
+ if (count)
+ changed = true;
+ for (int i = 0; i < count; i++) {
+ if (i < newSize)
+ m_rowLabels.insert(insertIndex++, newLabels.at(i));
+ else
+ m_rowLabels.insert(insertIndex++, QString());
+ }
+ } else {
+ // Either append or change, replace labels up to array end and then add new ones
+ int lastChangeIndex = count + startIndex;
+ int newIndex = 0;
+ for (int i = startIndex; i < lastChangeIndex; i++) {
+ if (i >= currentSize) {
+ // Label past the current size, so just append the new label
+ if (newSize < newIndex) {
+ changed = true;
+ m_rowLabels << newLabels.at(newIndex);
+ } else {
+ break; // No point appending empty strings, so just exit
+ }
+ } else if (newSize > newIndex) {
+ // Replace existing label
+ if (m_rowLabels.at(i) != newLabels.at(newIndex)) {
+ changed = true;
+ m_rowLabels[i] = newLabels.at(newIndex);
+ }
+ } else {
+ // No more new labels, so clear existing label
+ if (!m_rowLabels.at(i).isEmpty()) {
+ changed = true;
+ m_rowLabels[i] = QString();
+ }
+ }
+ newIndex++;
+ }
+ }
+ }
+ if (changed)
+ emit qptr()->rowLabelsChanged();
+}
+
QPair<GLfloat, GLfloat> QBarDataProxyPrivate::limitValues(int startRow, int endRow, int startColumn, int endColumn)
{
QPair<GLfloat, GLfloat> limits = qMakePair(0.0f, 0.0f);
diff --git a/src/datavisualization/data/qbardataproxy.h b/src/datavisualization/data/qbardataproxy.h
index 78f3d789..758700df 100644
--- a/src/datavisualization/data/qbardataproxy.h
+++ b/src/datavisualization/data/qbardataproxy.h
@@ -22,6 +22,7 @@
#include <QtDataVisualization/qabstractdataproxy.h>
#include <QtDataVisualization/qbardataitem.h>
#include <QVector>
+#include <QStringList>
QT_DATAVISUALIZATION_BEGIN_NAMESPACE
@@ -35,7 +36,8 @@ class QT_DATAVISUALIZATION_EXPORT QBarDataProxy : public QAbstractDataProxy
Q_OBJECT
Q_PROPERTY(int rowCount READ rowCount)
-
+ Q_PROPERTY(QStringList rowLabels READ rowLabels WRITE setRowLabels NOTIFY rowLabelsChanged)
+ Q_PROPERTY(QStringList columnLabels READ columnLabels WRITE setColumnLabels NOTIFY columnLabelsChanged)
public:
explicit QBarDataProxy(QObject *parent = 0);
virtual ~QBarDataProxy();
@@ -50,14 +52,25 @@ public:
*/
int rowCount() const;
+
+ QStringList rowLabels() const;
+ void setRowLabels(const QStringList &labels);
+ QStringList columnLabels() const;
+ void setColumnLabels(const QStringList &labels);
+
const QBarDataArray *array() const;
const QBarDataRow *rowAt(int rowIndex) const;
const QBarDataItem *itemAt(int rowIndex, int columnIndex) const;
+ void resetArray();
void resetArray(QBarDataArray *newArray);
+ void resetArray(QBarDataArray *newArray, const QStringList &rowLabels,
+ const QStringList &columnLabels);
void setRow(int rowIndex, QBarDataRow *row);
+ void setRow(int rowIndex, QBarDataRow *row, const QString &label);
void setRows(int rowIndex, const QBarDataArray &rows);
+ void setRows(int rowIndex, const QBarDataArray &rows, const QStringList &labels);
// Setting a column is comparatively inefficient as it changes all rows.
// Can resize rows that are shorter than columnIndex.
@@ -69,16 +82,20 @@ public:
// TODO setItems(int rowIndex, int columnIndex, QBarDataArray *items);
int addRow(QBarDataRow *row);
+ int addRow(QBarDataRow *row, const QString &label);
int addRows(const QBarDataArray &rows);
+ int addRows(const QBarDataArray &rows, const QStringList &labels);
// TODO int addColumn(const QBarDataRow &column); // returns the index of the added column
// TODO int addColumns(const QBarDataArray &columns); // returns the index of the first added column
void insertRow(int rowIndex, QBarDataRow *row);
+ void insertRow(int rowIndex, QBarDataRow *row, const QString &label);
void insertRows(int rowIndex, const QBarDataArray &rows);
+ void insertRows(int rowIndex, const QBarDataArray &rows, const QStringList &labels);
// TODO void insertColumn(int columnIndex, const QBarDataRow &column);
// TODO void insertColumns(int columnIndex, const QBarDataArray &columns);
- void removeRows(int rowIndex, int removeCount);
+ void removeRows(int rowIndex, int removeCount, bool removeLabels = true);
// TODO void removeColumns(int columnIndex, int removeCount);
signals:
@@ -94,6 +111,9 @@ signals:
void itemChanged(int rowIndex, int columnIndex); // TODO remove once itemsChanged is added?
// TODO void itemsChanged(int rowIndex, int columnIndex, int rowCount, int columnCount);
+ void rowLabelsChanged();
+ void columnLabelsChanged();
+
protected:
explicit QBarDataProxy(QBarDataProxyPrivate *d, QObject *parent = 0);
QBarDataProxyPrivate *dptr();
diff --git a/src/datavisualization/data/qbardataproxy_p.h b/src/datavisualization/data/qbardataproxy_p.h
index ab64c4a1..6aa9d2cb 100644
--- a/src/datavisualization/data/qbardataproxy_p.h
+++ b/src/datavisualization/data/qbardataproxy_p.h
@@ -42,23 +42,29 @@ public:
QBarDataProxyPrivate(QBarDataProxy *q);
virtual ~QBarDataProxyPrivate();
- bool resetArray(QBarDataArray *newArray);
- void setRow(int rowIndex, QBarDataRow *row);
- void setRows(int rowIndex, const QBarDataArray &rows);
+ bool 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);
void setItem(int rowIndex, int columnIndex, const QBarDataItem &item);
- int addRow(QBarDataRow *row);
- int addRows(const QBarDataArray &rows);
- void insertRow(int rowIndex, QBarDataRow *row);
- void insertRows(int rowIndex, const QBarDataArray &rows);
- void removeRows(int rowIndex, int removeCount);
+ int addRow(QBarDataRow *row, const QString *label);
+ int addRows(const QBarDataArray &rows, const QStringList *labels);
+ void insertRow(int rowIndex, QBarDataRow *row, const QString *label);
+ void insertRows(int rowIndex, const QBarDataArray &rows, const QStringList *labels);
+ void removeRows(int rowIndex, int removeCount, bool removeLabels);
- QPair<GLfloat, GLfloat> limitValues(int startRow, int startColumn, int rowCount, int columnCount);
+ QPair<GLfloat, GLfloat> limitValues(int startRow, int startColumn, int rowCount,
+ int columnCount);
private:
+ QBarDataProxy *qptr();
void clearRow(int rowIndex);
void clearArray();
+ void fixRowLabels(int startIndex, int count, const QStringList &newLabels, bool isInsert);
QBarDataArray *m_dataArray;
+ QStringList m_rowLabels;
+ QStringList m_columnLabels;
private:
friend class QBarDataProxy;
diff --git a/src/datavisualization/engine/abstract3dcontroller_p.h b/src/datavisualization/engine/abstract3dcontroller_p.h
index 1419c0f4..c406f087 100644
--- a/src/datavisualization/engine/abstract3dcontroller_p.h
+++ b/src/datavisualization/engine/abstract3dcontroller_p.h
@@ -176,7 +176,7 @@ protected:
bool m_renderPending;
explicit Abstract3DController(QRect boundRect, QObject *parent = 0);
- ~Abstract3DController();
+ virtual ~Abstract3DController();
public:
diff --git a/src/datavisualization/engine/abstract3drenderer_p.h b/src/datavisualization/engine/abstract3drenderer_p.h
index 1edca798..49a40209 100644
--- a/src/datavisualization/engine/abstract3drenderer_p.h
+++ b/src/datavisualization/engine/abstract3drenderer_p.h
@@ -86,7 +86,7 @@ protected:
QString generateValueLabel(const QString &format, qreal value);
public:
- ~Abstract3DRenderer();
+ virtual ~Abstract3DRenderer();
void updateDataModel(QAbstractDataProxy *dataProxy);
diff --git a/src/datavisualization/engine/bars3dcontroller.cpp b/src/datavisualization/engine/bars3dcontroller.cpp
index 90987fc5..1f4d44c0 100644
--- a/src/datavisualization/engine/bars3dcontroller.cpp
+++ b/src/datavisualization/engine/bars3dcontroller.cpp
@@ -21,7 +21,7 @@
#include "camerahelper_p.h"
#include "q3dabstractaxis_p.h"
#include "q3dvalueaxis_p.h"
-#include "q3dcategoryaxis.h"
+#include "q3dcategoryaxis_p.h"
#include "qbardataproxy_p.h"
#include <QMatrix4x4>
@@ -128,11 +128,18 @@ void Bars3DController::setActiveDataProxy(QAbstractDataProxy *proxy)
&Bars3DController::handleRowsInserted);
QObject::connect(barDataProxy, &QBarDataProxy::itemChanged, this,
&Bars3DController::handleItemChanged);
+ QObject::connect(barDataProxy, &QBarDataProxy::rowLabelsChanged, this,
+ &Bars3DController::handleDataRowLabelsChanged);
+ QObject::connect(barDataProxy, &QBarDataProxy::columnLabelsChanged, this,
+ &Bars3DController::handleDataColumnLabelsChanged);
adjustValueAxisRange();
// Always clear selection on proxy change
setSelectedBarPos(noSelectionPoint());
+
+ handleDataRowLabelsChanged();
+ handleDataColumnLabelsChanged();
}
void Bars3DController::handleArrayReset()
@@ -209,6 +216,26 @@ void Bars3DController::handleItemChanged(int rowIndex, int columnIndex)
emitNeedRender();
}
+void Bars3DController::handleDataRowLabelsChanged()
+{
+ if (m_axisX && m_data) {
+ // Grab a sublist equal to data window (no need to have more labels in axis)
+ // TODO once axis controls data window, this needs to change
+ QStringList subList = static_cast<QBarDataProxy *>(m_data)->rowLabels().mid(0, m_rowCount);
+ static_cast<Q3DCategoryAxis *>(m_axisX)->dptr()->setDataLabels(subList);
+ }
+}
+
+void Bars3DController::handleDataColumnLabelsChanged()
+{
+ if (m_axisZ && m_data) {
+ // Grab a sublist equal to data window (no need to have more labels in axis)
+ // TODO once axis controls data window, this needs to change
+ QStringList subList = static_cast<QBarDataProxy *>(m_data)->columnLabels().mid(0, m_columnCount);
+ static_cast<Q3DCategoryAxis *>(m_axisZ)->dptr()->setDataLabels(subList);
+ }
+}
+
void Bars3DController::handleSelectedBarPosChanged(const QPoint &position)
{
QPoint pos = position;
@@ -235,6 +262,18 @@ QPoint Bars3DController::noSelectionPoint()
return noSelectionPos;
}
+void Bars3DController::setAxisX(Q3DAbstractAxis *axis)
+{
+ Abstract3DController::setAxisX(axis);
+ handleDataRowLabelsChanged();
+}
+
+void Bars3DController::setAxisZ(Q3DAbstractAxis *axis)
+{
+ Abstract3DController::setAxisZ(axis);
+ handleDataColumnLabelsChanged();
+}
+
void Bars3DController::setBarSpecs(GLfloat thicknessRatio, const QSizeF &spacing, bool relative)
{
m_barThicknessRatio = thicknessRatio;
@@ -296,6 +335,10 @@ void Bars3DController::setDataWindow(int rowCount, int columnCount)
m_changeTracker.sampleSpaceChanged = true;
m_isDataDirty = true; // Render item array is recreated in renderer
+
+ handleDataRowLabelsChanged();
+ handleDataColumnLabelsChanged();
+
emitNeedRender();
}
diff --git a/src/datavisualization/engine/bars3dcontroller_p.h b/src/datavisualization/engine/bars3dcontroller_p.h
index 69ead98a..6dbaf742 100644
--- a/src/datavisualization/engine/bars3dcontroller_p.h
+++ b/src/datavisualization/engine/bars3dcontroller_p.h
@@ -114,6 +114,9 @@ public:
static QPoint noSelectionPoint();
+ virtual void setAxisX(Q3DAbstractAxis *axis);
+ virtual void setAxisZ(Q3DAbstractAxis *axis);
+
public slots:
void handleArrayReset();
void handleRowsAdded(int startIndex, int count);
@@ -121,6 +124,8 @@ public slots:
void handleRowsRemoved(int startIndex, int count);
void handleRowsInserted(int startIndex, int count);
void handleItemChanged(int rowIndex, int columnIndex);
+ void handleDataRowLabelsChanged();
+ void handleDataColumnLabelsChanged();
void handleSelectedBarPosChanged(const QPoint &position);
diff --git a/src/datavisualization/engine/q3dscene.cpp b/src/datavisualization/engine/q3dscene.cpp
index 49c08bbc..b39daab6 100644
--- a/src/datavisualization/engine/q3dscene.cpp
+++ b/src/datavisualization/engine/q3dscene.cpp
@@ -28,6 +28,7 @@
QT_DATAVISUALIZATION_BEGIN_NAMESPACE
Q3DScene::Q3DScene(QObject *parent) :
+ QObject(parent),
d_ptr(new Q3DScenePrivate(this))
{
}
diff --git a/src/datavisualization/engine/q3dwindow.h b/src/datavisualization/engine/q3dwindow.h
index 4a76c677..c46e293a 100644
--- a/src/datavisualization/engine/q3dwindow.h
+++ b/src/datavisualization/engine/q3dwindow.h
@@ -36,7 +36,7 @@ class QT_DATAVISUALIZATION_EXPORT Q3DWindow : public QWindow, protected QOpenGLF
public:
explicit Q3DWindow(QWindow *parent = 0);
- ~Q3DWindow();
+ virtual ~Q3DWindow();
protected slots:
void renderLater();
diff --git a/src/datavisualization/engine/surface3drenderer.cpp b/src/datavisualization/engine/surface3drenderer.cpp
index f39a0228..55fb9d6f 100644
--- a/src/datavisualization/engine/surface3drenderer.cpp
+++ b/src/datavisualization/engine/surface3drenderer.cpp
@@ -232,7 +232,6 @@ void Surface3DRenderer::updateScene(Q3DScene *scene)
void Surface3DRenderer::render(GLuint defaultFboHandle)
{
m_cachedScene->setUnderSideCameraEnabled(m_hasNegativeValues);
- Q3DCamera *camera = m_cachedScene->camera();
if (defaultFboHandle) {
glDepthMask(true);
glEnable(GL_DEPTH_TEST);