summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2013-07-11 12:21:58 +0300
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2013-07-12 07:46:39 +0300
commitde429a77448f8c4a6acb2f95f626db20c835e184 (patch)
tree81e8dc007b2bcc4f1084325325a2bd5ac1c6fafd /src
parentbd7a28a89c30e83a2af516aa3b6914c7389f32aa (diff)
Introduce item model based proxy
QML bars changed to utilize this and example updated Change-Id: Ied22a137c1bc320e7dd98759c16087c2d8d80fb4 Reviewed-by: Mika Salmela <mika.salmela@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/datavis3d/data/data.pri10
-rw-r--r--src/datavis3d/data/qitemmodelbardatamapping.cpp172
-rw-r--r--src/datavis3d/data/qitemmodelbardatamapping.h99
-rw-r--r--src/datavis3d/data/qitemmodelbardatamapping_p.h82
-rw-r--r--src/datavis3d/data/qitemmodelbardataproxy.cpp197
-rw-r--r--src/datavis3d/data/qitemmodelbardataproxy.h83
-rw-r--r--src/datavis3d/data/qitemmodelbardataproxy_p.h89
-rw-r--r--src/datavis3d/data/qvariantbardatamapping.cpp19
-rw-r--r--src/datavis3d/data/qvariantbardatamapping.h17
-rw-r--r--src/datavis3d/data/qvariantbardataproxy.cpp37
-rw-r--r--src/datavis3d/data/qvariantbardataproxy.h5
-rw-r--r--src/datavis3d/data/qvariantbardataproxy_p.h12
-rw-r--r--src/datavis3d/data/qvariantdataset.h1
-rw-r--r--src/datavis3d/engine/bars3drenderer.cpp2
-rw-r--r--src/datavis3d/engine/q3dbars.cpp8
-rw-r--r--src/datavis3d/engine/q3dbars.h4
-rw-r--r--src/datavis3dqml2/datavis3dqml2_plugin.cpp4
-rw-r--r--src/datavis3dqml2/datavis3dqml2_plugin.h17
-rw-r--r--src/datavis3dqml2/declarativebars.cpp207
-rw-r--r--src/datavis3dqml2/declarativebars.h55
-rw-r--r--src/datavis3dqml2/declarativebars_p.h12
21 files changed, 883 insertions, 249 deletions
diff --git a/src/datavis3d/data/data.pri b/src/datavis3d/data/data.pri
index 76c16a57..1cf90111 100644
--- a/src/datavis3d/data/data.pri
+++ b/src/datavis3d/data/data.pri
@@ -20,7 +20,11 @@ HEADERS += \
$$PWD/qvariantbardataproxy_p.h \
$$PWD/qvariantbardataproxy.h \
$$PWD/qvariantbardatamapping.h \
- $$PWD/qvariantbardatamapping_p.h
+ $$PWD/qvariantbardatamapping_p.h \
+ $$PWD/qitemmodelbardatamapping.h \
+ $$PWD/qitemmodelbardatamapping_p.h \
+ $$PWD/qitemmodelbardataproxy_p.h \
+ $$PWD/qitemmodelbardataproxy.h
SOURCES += \
@@ -36,4 +40,6 @@ SOURCES += \
$$PWD/qolddataproxy.cpp \
$$PWD/qvariantdataset.cpp \
$$PWD/qvariantbardataproxy.cpp \
- $$PWD/qvariantbardatamapping.cpp
+ $$PWD/qvariantbardatamapping.cpp \
+ $$PWD/qitemmodelbardatamapping.cpp \
+ $$PWD/qitemmodelbardataproxy.cpp
diff --git a/src/datavis3d/data/qitemmodelbardatamapping.cpp b/src/datavis3d/data/qitemmodelbardatamapping.cpp
new file mode 100644
index 00000000..08557cf0
--- /dev/null
+++ b/src/datavis3d/data/qitemmodelbardatamapping.cpp
@@ -0,0 +1,172 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtDataVis3D module.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qitemmodelbardatamapping_p.h"
+
+QT_DATAVIS3D_BEGIN_NAMESPACE
+
+QItemModelBarDataMapping::QItemModelBarDataMapping()
+ : QObject(0),
+ d_ptr(new QItemModelBarDataMappingPrivate(this))
+{
+}
+
+QItemModelBarDataMapping::QItemModelBarDataMapping(const QItemModelBarDataMapping &other)
+ : QObject(0),
+ d_ptr(new QItemModelBarDataMappingPrivate(this))
+{
+ operator=(other);
+}
+
+QItemModelBarDataMapping::QItemModelBarDataMapping(const QString &rowRole,
+ const QString &columnRole,
+ const QString &valueRole,
+ const QStringList &rowCategories,
+ const QStringList &columnCategories)
+ : QObject(0),
+ d_ptr(new QItemModelBarDataMappingPrivate(this))
+{
+ d_ptr->m_rowRole = rowRole;
+ d_ptr->m_columnRole = columnRole;
+ d_ptr->m_valueRole = valueRole;
+ d_ptr->m_rowCategories = rowCategories;
+ d_ptr->m_columnCategories = columnCategories;
+}
+
+QItemModelBarDataMapping::~QItemModelBarDataMapping()
+{
+}
+
+QItemModelBarDataMapping &QItemModelBarDataMapping::operator=(const QItemModelBarDataMapping &other)
+{
+ d_ptr->m_rowRole = other.d_ptr->m_rowRole;
+ d_ptr->m_columnRole = other.d_ptr->m_columnRole;
+ d_ptr->m_valueRole = other.d_ptr->m_valueRole;
+ d_ptr->m_rowCategories = other.d_ptr->m_rowCategories;
+ d_ptr->m_columnCategories = other.d_ptr->m_columnCategories;
+
+ return *this;
+}
+
+void QItemModelBarDataMapping::setRowRole(const QString &role)
+{
+ d_ptr->m_rowRole = role;
+ emit mappingChanged();
+}
+
+QString QItemModelBarDataMapping::rowRole() const
+{
+ return d_ptr->m_rowRole;
+}
+
+void QItemModelBarDataMapping::setColumnRole(const QString &role)
+{
+ d_ptr->m_columnRole = role;
+ emit mappingChanged();
+}
+
+QString QItemModelBarDataMapping::columnRole() const
+{
+ return d_ptr->m_columnRole;
+}
+
+void QItemModelBarDataMapping::setValueRole(const QString &role)
+{
+ d_ptr->m_valueRole = role;
+ emit mappingChanged();
+}
+
+QString QItemModelBarDataMapping::valueRole() const
+{
+ return d_ptr->m_valueRole;
+}
+
+void QItemModelBarDataMapping::setRowCategories(const QStringList &categories)
+{
+ d_ptr->m_rowCategories = categories;
+ emit mappingChanged();
+}
+
+const QStringList &QItemModelBarDataMapping::rowCategories() const
+{
+ return d_ptr->m_rowCategories;
+}
+
+void QItemModelBarDataMapping::setColumnCategories(const QStringList &categories)
+{
+ d_ptr->m_columnCategories = categories;
+ emit mappingChanged();
+}
+
+const QStringList &QItemModelBarDataMapping::columnCategories() const
+{
+ return d_ptr->m_columnCategories;
+}
+
+void QItemModelBarDataMapping::remap(const QString &rowRole,
+ const QString &columnRole,
+ const QString &valueRole,
+ const QStringList &rowCategories,
+ const QStringList &columnCategories)
+{
+ d_ptr->m_rowRole = rowRole;
+ d_ptr->m_columnRole = columnRole;
+ d_ptr->m_valueRole = valueRole;
+ d_ptr->m_rowCategories = rowCategories;
+ d_ptr->m_columnCategories = columnCategories;
+
+ emit mappingChanged();
+}
+
+// QItemModelBarDataMappingPrivate
+
+QItemModelBarDataMappingPrivate::QItemModelBarDataMappingPrivate(QItemModelBarDataMapping *q)
+ : QObject(0),
+ q_ptr(q)
+{
+}
+
+QItemModelBarDataMappingPrivate::~QItemModelBarDataMappingPrivate()
+{
+}
+
+QT_DATAVIS3D_END_NAMESPACE
+
diff --git a/src/datavis3d/data/qitemmodelbardatamapping.h b/src/datavis3d/data/qitemmodelbardatamapping.h
new file mode 100644
index 00000000..21bea73b
--- /dev/null
+++ b/src/datavis3d/data/qitemmodelbardatamapping.h
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtDataVis3D module.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QITEMMODELBARDATAMAPPING_H
+#define QITEMMODELBARDATAMAPPING_H
+
+#include "qdatavis3dnamespace.h"
+#include <QStringList>
+
+QT_DATAVIS3D_BEGIN_NAMESPACE
+
+class QItemModelBarDataMappingPrivate;
+
+class QT_DATAVIS3D_EXPORT QItemModelBarDataMapping : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QString rowRole READ rowRole WRITE setRowRole)
+ Q_PROPERTY(QString columnRole READ columnRole WRITE setColumnRole)
+ Q_PROPERTY(QString valueRole READ valueRole WRITE setValueRole)
+ Q_PROPERTY(QStringList rowCategories READ rowCategories WRITE setRowCategories)
+ Q_PROPERTY(QStringList columnCategories READ columnCategories WRITE setColumnCategories)
+public:
+ explicit QItemModelBarDataMapping();
+ QItemModelBarDataMapping(const QItemModelBarDataMapping &other);
+ QItemModelBarDataMapping(const QString &rowRole, const QString &columnRole,
+ const QString &valueRole, const QStringList &rowCategories,
+ const QStringList &columnCategories);
+ virtual ~QItemModelBarDataMapping();
+
+ QItemModelBarDataMapping &operator=(const QItemModelBarDataMapping &other);
+
+ // If row categories or column categories is an empty list, use item models's rows and columns for rows and columns.
+ // If the categories are both defined, ignore item model's rows and columns and figure out the rows and columns from
+ // the values of the set roles for each item.
+
+ void setRowRole(const QString &role);
+ QString rowRole() const;
+ void setColumnRole(const QString &role);
+ QString columnRole() const;
+ void setValueRole(const QString &role);
+ QString valueRole() const;
+
+ void setRowCategories(const QStringList &categories);
+ const QStringList &rowCategories() const;
+ void setColumnCategories(const QStringList &categories);
+ const QStringList &columnCategories() const;
+
+ void remap(const QString &rowRole, const QString &columnRole,
+ const QString &valueRole, const QStringList &rowCategories,
+ const QStringList &columnCategories);
+signals:
+ void mappingChanged();
+
+private:
+ QScopedPointer<QItemModelBarDataMappingPrivate> d_ptr;
+};
+
+
+QT_DATAVIS3D_END_NAMESPACE
+
+#endif
diff --git a/src/datavis3d/data/qitemmodelbardatamapping_p.h b/src/datavis3d/data/qitemmodelbardatamapping_p.h
new file mode 100644
index 00000000..19bd5bf9
--- /dev/null
+++ b/src/datavis3d/data/qitemmodelbardatamapping_p.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtDataVis3D module.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the QtDataVis3D API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#include "qitemmodelbardatamapping.h"
+
+#ifndef QITEMMODELBARDATAMAPPING_P_H
+#define QITEMMODELBARDATAMAPPING_P_H
+
+QT_DATAVIS3D_BEGIN_NAMESPACE
+
+class QItemModelBarDataMappingPrivate : public QObject
+{
+ Q_OBJECT
+public:
+ QItemModelBarDataMappingPrivate(QItemModelBarDataMapping *q);
+ virtual ~QItemModelBarDataMappingPrivate();
+
+private:
+ QString m_rowRole;
+ QString m_columnRole;
+ QString m_valueRole;
+
+ // For row/column items, sort items into these categories. Other categories are ignored.
+ QStringList m_rowCategories;
+ QStringList m_columnCategories;
+
+ QItemModelBarDataMapping *q_ptr;
+
+ friend class QItemModelBarDataMapping;
+};
+
+QT_DATAVIS3D_END_NAMESPACE
+
+#endif
diff --git a/src/datavis3d/data/qitemmodelbardataproxy.cpp b/src/datavis3d/data/qitemmodelbardataproxy.cpp
new file mode 100644
index 00000000..f715c19b
--- /dev/null
+++ b/src/datavis3d/data/qitemmodelbardataproxy.cpp
@@ -0,0 +1,197 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtDataVis3D module.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qitemmodelbardataproxy_p.h"
+
+QT_DATAVIS3D_BEGIN_NAMESPACE
+
+QItemModelBarDataProxy::QItemModelBarDataProxy() :
+ QBarDataProxy(new QItemModelBarDataProxyPrivate(this))
+{
+}
+
+QItemModelBarDataProxy::QItemModelBarDataProxy(QAbstractItemModel *itemModel,
+ QItemModelBarDataMapping *mapping) :
+ QBarDataProxy(new QItemModelBarDataProxyPrivate(this))
+{
+ dptr()->setItemModel(itemModel);
+ dptr()->setMapping(mapping);
+}
+
+QItemModelBarDataProxy::~QItemModelBarDataProxy()
+{
+}
+
+void QItemModelBarDataProxy::setItemModel(QAbstractItemModel *itemModel)
+{
+ dptr()->setItemModel(itemModel);
+}
+
+QAbstractItemModel *QItemModelBarDataProxy::itemModel()
+{
+ return dptr()->m_itemModel.data();
+}
+
+void QItemModelBarDataProxy::setMapping(QItemModelBarDataMapping *mapping)
+{
+ dptr()->setMapping(mapping);
+}
+
+QItemModelBarDataMapping *QItemModelBarDataProxy::mapping()
+{
+ return dptr()->m_mapping.data();
+}
+
+QItemModelBarDataProxyPrivate *QItemModelBarDataProxy::dptr()
+{
+ return static_cast<QItemModelBarDataProxyPrivate *>(d_ptr.data());
+}
+
+// QItemModelBarDataProxyPrivate
+
+QItemModelBarDataProxyPrivate::QItemModelBarDataProxyPrivate(QItemModelBarDataProxy *q)
+ : QBarDataProxyPrivate(q)
+{
+}
+
+QItemModelBarDataProxyPrivate::~QItemModelBarDataProxyPrivate()
+{
+}
+
+void QItemModelBarDataProxyPrivate::setItemModel(QAbstractItemModel *itemModel)
+{
+ if (!m_itemModel.isNull()) {
+ // TODO disconnect
+ }
+
+ m_itemModel = itemModel;
+
+ if (!m_itemModel.isNull()) {
+ // TODO
+ //QObject::connect(m_itemModel, &QAbstractItemModel::xxx, this, &QItemModelBarDataProxyPrivate::handleItemsAdded);
+ //QObject::connect(m_itemModel, &QAbstractItemModel::yyy, this, &QItemModelBarDataProxyPrivate::handleDataCleared);
+ }
+ resolveModel();
+}
+
+void QItemModelBarDataProxyPrivate::setMapping(QItemModelBarDataMapping *mapping)
+{
+ if (!m_mapping.isNull())
+ QObject::disconnect(m_mapping.data(), &QItemModelBarDataMapping::mappingChanged, this, &QItemModelBarDataProxyPrivate::handleMappingChanged);
+
+ m_mapping = mapping;
+
+ if (!m_mapping.isNull())
+ QObject::connect(m_mapping.data(), &QItemModelBarDataMapping::mappingChanged, this, &QItemModelBarDataProxyPrivate::handleMappingChanged);
+
+ resolveModel();
+}
+
+void QItemModelBarDataProxyPrivate::handleMappingChanged()
+{
+ resolveModel();
+}
+
+// Resolve entire item model into QBarDataArray.
+void QItemModelBarDataProxyPrivate::resolveModel()
+{
+ if (m_itemModel.isNull() || m_mapping.isNull() || m_mapping->valueRole().isEmpty()) {
+ qptr()->resetArray(0);
+ return;
+ }
+
+ bool useModelRows(false);
+ if (!m_mapping->rowCategories().size() || !m_mapping->columnCategories().size()) {
+ useModelRows = true;
+ } else if (m_mapping->rowRole().isEmpty() || m_mapping->columnRole().isEmpty()) {
+ qptr()->resetArray(0);
+ return;
+ }
+
+ QBarDataArray *newProxyArray = new QBarDataArray;
+ QHash<int, QByteArray> roleHash = m_itemModel->roleNames();
+ int valueRole = roleHash.key(m_mapping->valueRole().toLatin1());
+ int rowCount = m_itemModel->rowCount();
+ int columnCount = m_itemModel->columnCount();
+
+ if (useModelRows) {
+ for (int i = 0; i < rowCount; i++) {
+ QBarDataRow *newProxyRow = new QBarDataRow(columnCount);
+ for (int j = 0; j < columnCount; j++)
+ (*newProxyRow)[i].setValue(m_itemModel->index(i, j).data(valueRole).toReal());
+ newProxyArray->append(newProxyRow);
+ }
+ } else {
+ int rowRole = roleHash.key(m_mapping->rowRole().toLatin1());
+ int columnRole = roleHash.key(m_mapping->columnRole().toLatin1());
+ const QStringList &rowList = m_mapping->rowCategories();
+ const QStringList &columnList = m_mapping->columnCategories();
+
+ // Sort values into rows and columns
+ typedef QHash<QString, qreal> ColumnValueMap;
+ QHash <QString, ColumnValueMap> itemValueMap;
+ for (int i = 0; i < rowCount; i++) {
+ for (int j = 0; j < columnCount; j++) {
+ QModelIndex index = m_itemModel->index(i, j);
+ itemValueMap[index.data(rowRole).toString()][index.data(columnRole).toString()]
+ = index.data(valueRole).toReal();
+ }
+ }
+
+ // 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);
+ }
+ }
+ qDebug() << __FUNCTION__ << "RowCount:" << newProxyArray->size() << "Column count:" << newProxyArray->at(0)->size();
+
+ qptr()->resetArray(newProxyArray);
+}
+
+QItemModelBarDataProxy *QItemModelBarDataProxyPrivate::qptr()
+{
+ return static_cast<QItemModelBarDataProxy *>(q_ptr);
+}
+
+QT_DATAVIS3D_END_NAMESPACE
diff --git a/src/datavis3d/data/qitemmodelbardataproxy.h b/src/datavis3d/data/qitemmodelbardataproxy.h
new file mode 100644
index 00000000..f9f22fa4
--- /dev/null
+++ b/src/datavis3d/data/qitemmodelbardataproxy.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtDataVis3D module.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QITEMMODELBARDATAPROXY_H
+#define QITEMMODELBARDATAPROXY_H
+
+#include "qbardataproxy.h"
+#include "qitemmodelbardatamapping.h"
+#include <QAbstractItemModel>
+#include <QStringList>
+#include <QMap>
+
+QT_DATAVIS3D_BEGIN_NAMESPACE
+
+class QItemModelBarDataProxyPrivate;
+
+class QT_DATAVIS3D_EXPORT QItemModelBarDataProxy : public QBarDataProxy
+{
+ Q_OBJECT
+
+public:
+ explicit QItemModelBarDataProxy();
+ explicit QItemModelBarDataProxy(QAbstractItemModel *itemModel, QItemModelBarDataMapping *mapping);
+ virtual ~QItemModelBarDataProxy();
+
+ // Doesn't gain ownership of the model, but does connect to it to listen for data changes.
+ void setItemModel(QAbstractItemModel *itemModel);
+ QAbstractItemModel *itemModel();
+
+ // Map key (row, column, value) to value index in data item (QVariantItem).
+ // Doesn't gain ownership of mapping, but does connect to it to listen for mapping changes.
+ // Modifying mapping that is set to proxy will trigger dataset re-resolving.
+ void setMapping(QItemModelBarDataMapping *mapping);
+ QItemModelBarDataMapping *mapping();
+
+protected:
+ QItemModelBarDataProxyPrivate *dptr();
+
+private:
+ Q_DISABLE_COPY(QItemModelBarDataProxy)
+};
+
+QT_DATAVIS3D_END_NAMESPACE
+
+#endif
diff --git a/src/datavis3d/data/qitemmodelbardataproxy_p.h b/src/datavis3d/data/qitemmodelbardataproxy_p.h
new file mode 100644
index 00000000..a3764079
--- /dev/null
+++ b/src/datavis3d/data/qitemmodelbardataproxy_p.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtDataVis3D module.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the QtDataVis3D API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef QITEMMODELBARDATAPROXY_P_H
+#define QITEMMODELBARDATAPROXY_P_H
+
+#include "qitemmodelbardataproxy.h"
+#include "qbardataproxy_p.h"
+#include <QPointer>
+
+QT_DATAVIS3D_BEGIN_NAMESPACE
+
+class QT_DATAVIS3D_EXPORT QItemModelBarDataProxyPrivate : public QBarDataProxyPrivate
+{
+ Q_OBJECT
+public:
+ QItemModelBarDataProxyPrivate(QItemModelBarDataProxy *q);
+ virtual ~QItemModelBarDataProxyPrivate();
+
+ void setItemModel(QAbstractItemModel *itemModel);
+ void setMapping(QItemModelBarDataMapping *mapping);
+
+public slots:
+ // TODO proper handlers
+ //void handleItemsAdded(int index, int count);
+ //void handleDataCleared();
+ void handleMappingChanged();
+
+private:
+ void resolveModel();
+ QItemModelBarDataProxy *qptr();
+
+ QPointer<QAbstractItemModel> m_itemModel; // Not owned
+ QPointer<QItemModelBarDataMapping> m_mapping; // Not owned
+
+ friend class QItemModelBarDataProxy;
+};
+
+QT_DATAVIS3D_END_NAMESPACE
+
+#endif
diff --git a/src/datavis3d/data/qvariantbardatamapping.cpp b/src/datavis3d/data/qvariantbardatamapping.cpp
index ecb70d5a..720b99c3 100644
--- a/src/datavis3d/data/qvariantbardatamapping.cpp
+++ b/src/datavis3d/data/qvariantbardatamapping.cpp
@@ -49,6 +49,13 @@ QVariantBarDataMapping::QVariantBarDataMapping()
{
}
+QVariantBarDataMapping::QVariantBarDataMapping(const QVariantBarDataMapping &other)
+ : QObject(0),
+ d_ptr(new QVariantBarDataMappingPrivate(this))
+{
+ operator=(other);
+}
+
QVariantBarDataMapping::QVariantBarDataMapping(int rowIndex, int columnIndex, int valueIndex,
const QStringList &rowCategories,
const QStringList &columnCategories)
@@ -66,6 +73,17 @@ QVariantBarDataMapping::~QVariantBarDataMapping()
{
}
+QVariantBarDataMapping &QVariantBarDataMapping::operator=(const QVariantBarDataMapping &other)
+{
+ d_ptr->m_rowIndex = other.d_ptr->m_rowIndex;
+ d_ptr->m_columnIndex = other.d_ptr->m_columnIndex;
+ d_ptr->m_valueIndex = other.d_ptr->m_valueIndex;
+ d_ptr->m_rowCategories = other.d_ptr->m_rowCategories;
+ d_ptr->m_columnCategories = other.d_ptr->m_columnCategories;
+
+ return *this;
+}
+
void QVariantBarDataMapping::setRowIndex(int index)
{
d_ptr->m_rowIndex = index;
@@ -148,4 +166,5 @@ QVariantBarDataMappingPrivate::~QVariantBarDataMappingPrivate()
{
}
+
QT_DATAVIS3D_END_NAMESPACE
diff --git a/src/datavis3d/data/qvariantbardatamapping.h b/src/datavis3d/data/qvariantbardatamapping.h
index 12ea6ee5..2b2eee6c 100644
--- a/src/datavis3d/data/qvariantbardatamapping.h
+++ b/src/datavis3d/data/qvariantbardatamapping.h
@@ -44,7 +44,6 @@
#include "qdatavis3dnamespace.h"
#include <QStringList>
-#include <QMap>
QT_DATAVIS3D_BEGIN_NAMESPACE
@@ -53,13 +52,21 @@ class QVariantBarDataMappingPrivate;
class QT_DATAVIS3D_EXPORT QVariantBarDataMapping : public QObject
{
Q_OBJECT
+ Q_PROPERTY(int rowIndex READ rowIndex WRITE setRowIndex)
+ Q_PROPERTY(int columnIndex READ columnIndex WRITE setColumnIndex)
+ Q_PROPERTY(int valueIndex READ valueIndex WRITE setValueIndex)
+ Q_PROPERTY(QStringList rowCategories READ rowCategories WRITE setRowCategories)
+ Q_PROPERTY(QStringList columnCategories READ columnCategories WRITE setColumnCategories)
public:
explicit QVariantBarDataMapping();
- explicit QVariantBarDataMapping(int rowIndex, int columnIndex, int valueIndex,
- const QStringList &rowCategories,
- const QStringList &columnCategories);
+ QVariantBarDataMapping(const QVariantBarDataMapping &other);
+ QVariantBarDataMapping(int rowIndex, int columnIndex, int valueIndex,
+ const QStringList &rowCategories,
+ const QStringList &columnCategories);
virtual ~QVariantBarDataMapping();
+ QVariantBarDataMapping &operator=(const QVariantBarDataMapping &other);
+
void setRowIndex(int index);
int rowIndex() const;
void setColumnIndex(int index);
@@ -79,8 +86,6 @@ signals:
void mappingChanged();
private:
- Q_DISABLE_COPY(QVariantBarDataMapping)
-
QScopedPointer<QVariantBarDataMappingPrivate> d_ptr;
};
diff --git a/src/datavis3d/data/qvariantbardataproxy.cpp b/src/datavis3d/data/qvariantbardataproxy.cpp
index a62ae9ff..6f8c9582 100644
--- a/src/datavis3d/data/qvariantbardataproxy.cpp
+++ b/src/datavis3d/data/qvariantbardataproxy.cpp
@@ -67,7 +67,7 @@ void QVariantBarDataProxy::setDataSet(QVariantDataSet *newSet)
QVariantDataSet *QVariantBarDataProxy::dataSet()
{
- return dptr()->m_dataSet;
+ return dptr()->m_dataSet.data();
}
void QVariantBarDataProxy::setMapping(QVariantBarDataMapping *mapping)
@@ -77,7 +77,7 @@ void QVariantBarDataProxy::setMapping(QVariantBarDataMapping *mapping)
QVariantBarDataMapping *QVariantBarDataProxy::mapping()
{
- return dptr()->m_mapping;
+ return dptr()->m_mapping.data();
}
QVariantBarDataProxyPrivate *QVariantBarDataProxy::dptr()
@@ -88,33 +88,38 @@ QVariantBarDataProxyPrivate *QVariantBarDataProxy::dptr()
// QVariantBarDataProxyPrivate
QVariantBarDataProxyPrivate::QVariantBarDataProxyPrivate(QVariantBarDataProxy *q)
- : QBarDataProxyPrivate(q),
- m_dataSet(new QVariantDataSet),
- m_mapping(0)
+ : QBarDataProxyPrivate(q)
{
- connectDataSet();
}
QVariantBarDataProxyPrivate::~QVariantBarDataProxyPrivate()
{
- delete m_dataSet;
- delete m_mapping;
}
void QVariantBarDataProxyPrivate::setDataSet(QVariantDataSet *newSet)
{
- delete m_dataSet;
+ if (!m_dataSet.isNull()) {
+ QObject::disconnect(m_dataSet.data(), &QVariantDataSet::itemsAdded, this, &QVariantBarDataProxyPrivate::handleItemsAdded);
+ QObject::disconnect(m_dataSet.data(), &QVariantDataSet::dataCleared, this, &QVariantBarDataProxyPrivate::handleDataCleared);
+ }
m_dataSet = newSet;
- connectDataSet();
+
+ if (!m_dataSet.isNull()) {
+ QObject::connect(m_dataSet.data(), &QVariantDataSet::itemsAdded, this, &QVariantBarDataProxyPrivate::handleItemsAdded);
+ QObject::connect(m_dataSet.data(), &QVariantDataSet::dataCleared, this, &QVariantBarDataProxyPrivate::handleDataCleared);
+ }
resolveDataSet();
}
void QVariantBarDataProxyPrivate::setMapping(QVariantBarDataMapping *mapping)
{
- delete m_mapping;
+ if (!m_mapping.isNull())
+ QObject::disconnect(m_mapping.data(), &QVariantBarDataMapping::mappingChanged, this, &QVariantBarDataProxyPrivate::handleMappingChanged);
+
m_mapping = mapping;
- QObject::connect(m_mapping, &QVariantBarDataMapping::mappingChanged, this, &QVariantBarDataProxyPrivate::handleMappingChanged);
+ if (!m_mapping.isNull())
+ QObject::connect(m_mapping.data(), &QVariantBarDataMapping::mappingChanged, this, &QVariantBarDataProxyPrivate::handleMappingChanged);
resolveDataSet();
}
@@ -136,16 +141,10 @@ void QVariantBarDataProxyPrivate::handleMappingChanged()
resolveDataSet();
}
-void QVariantBarDataProxyPrivate::connectDataSet()
-{
- QObject::connect(m_dataSet, &QVariantDataSet::itemsAdded, this, &QVariantBarDataProxyPrivate::handleItemsAdded);
- QObject::connect(m_dataSet, &QVariantDataSet::dataCleared, this, &QVariantBarDataProxyPrivate::handleDataCleared);
-}
-
// Resolve entire dataset into QBarDataArray.
void QVariantBarDataProxyPrivate::resolveDataSet()
{
- if (!m_mapping || !m_mapping->rowCategories().size() || !m_mapping->columnCategories().size()) {
+ if (m_dataSet.isNull() || m_mapping.isNull() || !m_mapping->rowCategories().size() || !m_mapping->columnCategories().size()) {
qptr()->resetArray(0);
return;
}
diff --git a/src/datavis3d/data/qvariantbardataproxy.h b/src/datavis3d/data/qvariantbardataproxy.h
index 350df64f..1d48bb63 100644
--- a/src/datavis3d/data/qvariantbardataproxy.h
+++ b/src/datavis3d/data/qvariantbardataproxy.h
@@ -61,11 +61,12 @@ public:
explicit QVariantBarDataProxy(QVariantDataSet *newSet, QVariantBarDataMapping *mapping);
virtual ~QVariantBarDataProxy();
- void setDataSet(QVariantDataSet *newSet); // Gains ownership
+ // Doesn't gain ownership of the dataset, but does connect to it to listen for data changes.
+ void setDataSet(QVariantDataSet *newSet);
QVariantDataSet *dataSet();
// Map key (row, column, value) to value index in data item (QVariantItem).
- // Ownership of the mapping item transfers to proxy.
+ // Doesn't gain ownership of mapping, but does connect to it to listen for mapping changes.
// Modifying mapping that is set to proxy will trigger dataset re-resolving.
void setMapping(QVariantBarDataMapping *mapping);
QVariantBarDataMapping *mapping();
diff --git a/src/datavis3d/data/qvariantbardataproxy_p.h b/src/datavis3d/data/qvariantbardataproxy_p.h
index 23297e79..28fdf005 100644
--- a/src/datavis3d/data/qvariantbardataproxy_p.h
+++ b/src/datavis3d/data/qvariantbardataproxy_p.h
@@ -49,12 +49,13 @@
//
// We mean it.
-#include "qvariantbardataproxy.h"
-#include "qbardataproxy_p.h"
-
#ifndef QVARIANTBARDATAPROXY_P_H
#define QVARIANTBARDATAPROXY_P_H
+#include "qvariantbardataproxy.h"
+#include "qbardataproxy_p.h"
+#include <QPointer>
+
QT_DATAVIS3D_BEGIN_NAMESPACE
class QVariantDataSet;
@@ -75,12 +76,11 @@ public slots:
void handleMappingChanged();
private:
- void connectDataSet();
void resolveDataSet();
QVariantBarDataProxy *qptr();
- QVariantDataSet *m_dataSet;
- QVariantBarDataMapping *m_mapping;
+ QPointer<QVariantDataSet> m_dataSet;
+ QPointer<QVariantBarDataMapping> m_mapping;
friend class QVariantBarDataProxy;
};
diff --git a/src/datavis3d/data/qvariantdataset.h b/src/datavis3d/data/qvariantdataset.h
index 60dde0bb..3eac5cc4 100644
--- a/src/datavis3d/data/qvariantdataset.h
+++ b/src/datavis3d/data/qvariantdataset.h
@@ -65,6 +65,7 @@ public:
int addItem(QVariantDataItem *item);
int addItems(QVariantDataItemList *itemList);
+ // TODO inserts/removes
const QVariantDataItemList &itemList() const;
diff --git a/src/datavis3d/engine/bars3drenderer.cpp b/src/datavis3d/engine/bars3drenderer.cpp
index 65b50112..bc32ed76 100644
--- a/src/datavis3d/engine/bars3drenderer.cpp
+++ b/src/datavis3d/engine/bars3drenderer.cpp
@@ -1699,7 +1699,7 @@ void Bars3dRenderer::updateBackgroundEnabled(bool enable)
void Bars3dRenderer::updateShadowQuality(ShadowQuality quality)
{
- qDebug() << "Bars3dRenderer::setShadowQuality";
+ qDebug() << "Bars3dRenderer::setShadowQuality" << quality;
m_cachedShadowQuality = quality;
switch (quality) {
case ShadowLow:
diff --git a/src/datavis3d/engine/q3dbars.cpp b/src/datavis3d/engine/q3dbars.cpp
index f839df8b..2f3facee 100644
--- a/src/datavis3d/engine/q3dbars.cpp
+++ b/src/datavis3d/engine/q3dbars.cpp
@@ -271,9 +271,9 @@ void Q3DBars::setCameraPreset(CameraPreset preset)
* on data values. Negative vertical angles are allowed only if there are negative bar values.
* Distance is adjustable between 10 and 500.
*/
-void Q3DBars::setCameraPosition(GLfloat horizontal, GLfloat vertical, GLint distance)
+void Q3DBars::setCameraPosition(qreal horizontal, qreal vertical, int distance)
{
- d_ptr->m_shared->setCameraPosition(horizontal, vertical, distance);
+ d_ptr->m_shared->setCameraPosition(GLfloat(horizontal), GLfloat(vertical), GLint(distance));
}
/*!
@@ -499,9 +499,9 @@ QBarDataProxy *Q3DBars::dataProxy()
* Sets tick count and step. Note; tickCount * step should be the maximum possible value of data
* set.
*/
-void Q3DBars::setTickCount(GLint tickCount, GLfloat step, GLfloat minimum)
+void Q3DBars::setTickCount(int tickCount, qreal step, qreal minimum)
{
- d_ptr->m_shared->setTickCount(tickCount, step, minimum);
+ d_ptr->m_shared->setTickCount(GLint(tickCount), GLfloat(step), GLfloat(minimum));
}
Q3DBarsPrivate::Q3DBarsPrivate(Q3DBars *q, QRect rect)
diff --git a/src/datavis3d/engine/q3dbars.h b/src/datavis3d/engine/q3dbars.h
index 6a9922e2..4d71185b 100644
--- a/src/datavis3d/engine/q3dbars.h
+++ b/src/datavis3d/engine/q3dbars.h
@@ -93,7 +93,7 @@ public:
// Set camera rotation if you don't want to use the presets (in horizontal (-180...180) and
// vertical (0...90) (or (-90...90) if there are negative values) angles and distance in
// percentage (10...500))
- void setCameraPosition(GLfloat horizontal, GLfloat vertical, GLint distance = 100);
+ void setCameraPosition(qreal horizontal, qreal vertical, int distance = 100);
// Set theme (bar colors, shaders, window color, background colors, light intensity and text
// colors are affected)
@@ -107,7 +107,7 @@ public:
// Set tick count and step. Note; tickCount * step should be the maximum possible value of data
// set. Minimum is the absolute minimum possible value a bar can have. This is especially
// important to set if values can be negative.
- void setTickCount(GLint tickCount, GLfloat step, GLfloat minimum = 0.0f);
+ void setTickCount(int tickCount, qreal step, qreal minimum = 0.0f);
// override bar type with own mesh
void setMeshFileName(const QString &objFileName);
diff --git a/src/datavis3dqml2/datavis3dqml2_plugin.cpp b/src/datavis3dqml2/datavis3dqml2_plugin.cpp
index 3051e7ae..b6caec61 100644
--- a/src/datavis3dqml2/datavis3dqml2_plugin.cpp
+++ b/src/datavis3dqml2/datavis3dqml2_plugin.cpp
@@ -53,9 +53,7 @@ void Datavis3dqml2Plugin::registerTypes(const char *uri)
qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel",
QLatin1String("Trying to create uncreatable: AbstractItemModel."));
- qmlRegisterType<QDataItem>(uri, 1, 0, "DataItem");
- qmlRegisterType<QDataRow>(uri, 1, 0, "DataRow");
- qmlRegisterType<QDataSet>(uri, 1, 0, "DataSet");
+ qmlRegisterType<QItemModelBarDataMapping>(uri, 1, 0, "BarDataMapping");
qmlRegisterType<DeclarativeBars>(uri, 1, 0, "Bars3D");
qmlRegisterType<DeclarativeMaps>(uri, 1, 0, "Maps3D");
diff --git a/src/datavis3dqml2/datavis3dqml2_plugin.h b/src/datavis3dqml2/datavis3dqml2_plugin.h
index 4985287f..d186006e 100644
--- a/src/datavis3dqml2/datavis3dqml2_plugin.h
+++ b/src/datavis3dqml2/datavis3dqml2_plugin.h
@@ -43,31 +43,18 @@
#define DATAVIS3DQML2_PLUGIN_H
#include "datavis3dglobal_p.h"
-#include "qdataitem.h"
-#include "qdatarow.h"
-#include "qdataset.h"
-
#include "declarativebars.h"
#include "declarativemaps.h"
-//#include "declarativedataitem.h"
-//#include "declarativedatarow.h"
-//#include "declarativedataset.h"
+#include "qitemmodelbardatamapping.h"
#include <QQmlExtensionPlugin>
QT_DATAVIS3D_USE_NAMESPACE
-//Q_DECLARE_METATYPE(DeclarativeDataItem *)
-//Q_DECLARE_METATYPE(DeclarativeDataRow *)
-//Q_DECLARE_METATYPE(DeclarativeDataSet *)
-
Q_DECLARE_METATYPE(DeclarativeBars *)
Q_DECLARE_METATYPE(DeclarativeMaps *)
-Q_DECLARE_METATYPE(QDataItem *)
-Q_DECLARE_METATYPE(QDataRow *)
-Q_DECLARE_METATYPE(QDataSet *)
-
+Q_DECLARE_METATYPE(QItemModelBarDataMapping *)
Q_DECLARE_METATYPE(QAbstractItemModel *)
diff --git a/src/datavis3dqml2/declarativebars.cpp b/src/datavis3dqml2/declarativebars.cpp
index 8363c3d1..3b6641dd 100644
--- a/src/datavis3dqml2/declarativebars.cpp
+++ b/src/datavis3dqml2/declarativebars.cpp
@@ -41,10 +41,7 @@
#include "declarativebars.h"
#include "bars3dcontroller_p.h"
-#include "qdataset.h"
-#include "qdataset_p.h"
-#include "qdatarow_p.h"
-#include "qolddataproxy.h"
+#include "qitemmodelbardataproxy.h"
#include <QtQuick/QQuickWindow>
#include <QtGui/QOpenGLFramebufferObject>
@@ -73,7 +70,7 @@ DeclarativeBars::DeclarativeBars(QQuickItem *parent)
QObject::connect(m_shared, &Bars3dController::shadowQualityChanged, this,
&DeclarativeBars::handleShadowQualityUpdate);
- m_shared->setDataProxy(new QOldDataProxy);
+ m_shared->setDataProxy(new QItemModelBarDataProxy);
}
DeclarativeBars::~DeclarativeBars()
@@ -130,15 +127,13 @@ QSGNode *DeclarativeBars::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData
m_cachedState->m_isGridSet = false;
}
- if (m_cachedState->m_dataRow) {
- static_cast<QOldDataProxy *>(m_shared->m_data)->addDataRow(m_cachedState->m_dataRow);
- m_cachedState->m_dataRow = 0;
+ if (m_cachedState->m_isTickCountSet) {
+ m_shared->setTickCount(GLint(m_cachedState->m_tickCount),
+ GLfloat(m_cachedState->m_tickStep),
+ GLfloat(m_cachedState->m_tickMin));
+ m_cachedState->m_isTickCountSet = false;
}
- if (m_cachedState->m_dataSet) {
- static_cast<QOldDataProxy *>(m_shared->m_data)->addDataSet(m_cachedState->m_dataSet);
- m_cachedState->m_dataSet = 0;
- }
// If old node exists and has right size, reuse it.
if (oldNode && m_initialisedSize == boundingRect().size().toSize()) {
@@ -171,14 +166,10 @@ void DeclarativeBars::setBarType(BarStyle style, bool smooth)
m_shared->setBarType(style, smooth);
}
-void DeclarativeBars::setupSampleSpace(int samplesRow, int samplesColumn, const QString &labelRow,
- const QString &labelColumn, const QString &labelHeight)
+void DeclarativeBars::setupSampleSpace(int samplesRow, int samplesColumn)
{
m_cachedState->m_samplesRow = samplesRow;
m_cachedState->m_samplesColumn = samplesColumn;
- m_cachedState->m_labelRow = labelRow;
- m_cachedState->m_labelColumn = labelColumn;
- m_cachedState->m_labelHeight = labelHeight;
m_cachedState->m_isSampleSpaceSet = true;
update();
@@ -189,9 +180,9 @@ void DeclarativeBars::setCameraPreset(CameraPreset preset)
m_shared->setCameraPreset(preset);
}
-void DeclarativeBars::setCameraPosition(GLfloat horizontal, GLfloat vertical, GLint distance)
+void DeclarativeBars::setCameraPosition(qreal horizontal, qreal vertical, int distance)
{
- m_shared->setCameraPosition(horizontal, vertical, distance);
+ m_shared->setCameraPosition(GLfloat(horizontal), GLfloat(vertical), GLint(distance));
}
void DeclarativeBars::setTheme(ColorTheme theme)
@@ -262,167 +253,81 @@ bool DeclarativeBars::isBackgroundVisible()
return m_shared->backgroundEnabled();
}
-void DeclarativeBars::setTickCount(GLint tickCount, GLfloat step, GLfloat minimum)
+void DeclarativeBars::setTickCount(int tickCount, qreal step, qreal minimum)
{
- m_shared->setTickCount(tickCount, step, minimum);
+ m_cachedState->m_isTickCountSet = true;
+ m_cachedState->m_tickCount = tickCount;
+ m_cachedState->m_tickStep = step;
+ m_cachedState->m_tickMin = minimum;
+
+ update();
}
void DeclarativeBars::setData(QAbstractItemModel *data)
{
- qDebug() << "setData";
- QDataSet *dataset = new QDataSet();
-
- qDebug() << data << data->rowCount() << data->columnCount();
-
- // Get sample space size from data, and set it
- setupSampleSpace(data->rowCount(), data->columnCount());
-
- // TODO: Maps data in QAbstractItemModel to qdatarows and qdataset
-
- // Add data to scene
- addDataSet(dataset);
+ static_cast<QItemModelBarDataProxy *>(m_shared->dataProxy())->setItemModel(data);
}
QAbstractItemModel *DeclarativeBars::data()
{
- // TODO: Map back from qdataset, or store as QAbstractItemModel as well?
- return NULL;
+ return static_cast<QItemModelBarDataProxy *>(m_shared->dataProxy())->itemModel();
}
-void DeclarativeBars::addDataRow(const QVector<float> &dataRow, const QString &labelRow,
- const QVector<QString> &labelsColumn)
+void DeclarativeBars::setSelectionMode(DeclarativeBars::SelectionMode mode)
{
- Q_UNUSED(labelRow)
- Q_UNUSED(labelsColumn)
- qDebug() << "Enter DeclarativeBars::addDataRow(const QVector<float> &dataRow...)";
- // TODO: Save labels to cachedstate
- QDataItem *newItem;
- delete m_cachedState->m_dataRow;
- m_cachedState->m_dataRow = new QDataRow();
- for (int i = 0; i < dataRow.count(); i++) {
- newItem = new QDataItem(dataRow.at(i));
- m_cachedState->m_dataRow->addItem(newItem);
- }
+ m_cachedState->m_selectionMode = QtDataVis3D::SelectionMode(mode);
+ m_cachedState->m_isSelectionModeSet = true;
update();
}
-void DeclarativeBars::addDataRow(const QVector<QDataItem *> &dataRow, const QString &labelRow,
- const QVector<QString> &labelsColumn)
+DeclarativeBars::SelectionMode DeclarativeBars::selectionMode()
{
- Q_UNUSED(labelRow)
- Q_UNUSED(labelsColumn)
- qDebug() << "Enter DeclarativeBars::addDataRow(const QVector<QDataItem*> &dataRow...)";
- // TODO: Save labels to cachedstate
- QDataItem *newItem;
- delete m_cachedState->m_dataRow;
- m_cachedState->m_dataRow = new QDataRow();
- for (int i = 0; i < dataRow.count(); i++) {
- newItem = new QDataItem(*dataRow.at(i));
- m_cachedState->m_dataRow->addItem(newItem);
- }
- update();
+ return DeclarativeBars::SelectionMode(m_shared->selectionMode());
}
-void DeclarativeBars::addDataRow(QDataRow *dataRow)
+void DeclarativeBars::setShadowQuality(DeclarativeBars::ShadowQuality quality)
{
- qDebug() << "Enter DeclarativeBars::addDataRow(QDataRow *dataRow)";
- QDataItem *newItem;
- delete m_cachedState->m_dataRow;
- m_cachedState->m_dataRow = new QDataRow();
- for (int i = 0; i < dataRow->d_ptr->row().count(); i++) {
- newItem = new QDataItem(*dataRow->d_ptr->getItem(i));
- m_cachedState->m_dataRow->addItem(newItem);
- }
+ m_cachedState->m_shadowQuality = QtDataVis3D::ShadowQuality(quality);
+ m_cachedState->m_isShadowQualitySet = true;
update();
}
-void DeclarativeBars::addDataSet(const QVector< QVector<float> > &data,
- const QVector<QString> &labelsRow,
- const QVector<QString> &labelsColumn)
-{
- Q_UNUSED(labelsRow)
- Q_UNUSED(labelsColumn)
- qDebug() << "void DeclarativeBars::addDataSet(const QVector< QVector<float> >...";
- // TODO: Save labels to cachedstate
- QDataItem *newItem;
- QDataRow *newRow;
- delete m_cachedState->m_dataSet;
- m_cachedState->m_dataSet = new QDataSet();
- for (int row = 0; row < data.count(); row++) {
- newRow = new QDataRow();
- for (int i = 0; i < data.at(row).count(); i++) {
- newItem = new QDataItem(data.at(row).at(i));
- newRow->addItem(newItem);
- }
- m_cachedState->m_dataSet->addRow(newRow);
- }
- update();
+DeclarativeBars::ShadowQuality DeclarativeBars::shadowQuality()
+{
+ return DeclarativeBars::ShadowQuality(m_shared->shadowQuality());
}
-void DeclarativeBars::addDataSet(const QVector< QVector<QDataItem *> > &data,
- const QVector<QString> &labelsRow,
- const QVector<QString> &labelsColumn)
-{
- Q_UNUSED(labelsRow)
- Q_UNUSED(labelsColumn)
- qDebug() << "void DeclarativeBars::addDataSet(const QVector< QVector<QDataItem *> >...";
- // TODO: Save labels to cachedstate
- QDataItem *newItem;
- QDataRow *newRow;
- delete m_cachedState->m_dataSet;
- m_cachedState->m_dataSet = new QDataSet();
- for (int row = 0; row < data.count(); row++) {
- newRow = new QDataRow();
- for (int i = 0; i < data.at(row).count(); i++) {
- newItem = new QDataItem(*data.at(row).at(i));
- newRow->addItem(newItem);
- }
- m_cachedState->m_dataSet->addRow(newRow);
- }
- update();
+QItemModelBarDataMapping *DeclarativeBars::mapping() const
+{
+ return static_cast<QItemModelBarDataProxy *>(m_shared->dataProxy())->mapping();
}
-void DeclarativeBars::addDataSet(QDataSet *dataSet)
-{
- qDebug() << "void DeclarativeBars::addDataSet(QDataSet *dataSet)";
- // TODO: Handle labels?
- QDataItem *newItem;
- QDataRow *newRow;
- delete m_cachedState->m_dataSet;
- m_cachedState->m_dataSet = new QDataSet();
- for (int row = 0; row < dataSet->d_ptr->set().count(); row++) {
- newRow = new QDataRow();
- for (int i = 0; i < dataSet->d_ptr->getRow(row)->d_ptr->row().count(); i++) {
- newItem = new QDataItem(*dataSet->d_ptr->getRow(row)->d_ptr->getItem(i));
- newRow->addItem(newItem);
- }
- m_cachedState->m_dataSet->addRow(newRow);
- }
- update();
+void DeclarativeBars::setMapping(QItemModelBarDataMapping *mapping)
+{
+ qDebug() << "Setting the mapping!!";
+ static_cast<QItemModelBarDataProxy *>(m_shared->dataProxy())->setMapping(mapping);
}
-void DeclarativeBars::setSelectionMode(DeclarativeBars::SelectionMode mode)
+int DeclarativeBars::rows() const
{
- m_cachedState->m_selectionMode = QtDataVis3D::SelectionMode(mode);
- m_cachedState->m_isSelectionModeSet = true;
- update();
+ return m_cachedState->m_samplesRow;
}
-DeclarativeBars::SelectionMode DeclarativeBars::selectionMode()
+void DeclarativeBars::setRows(int rows)
{
- return DeclarativeBars::SelectionMode(m_shared->selectionMode());
+ m_cachedState->m_samplesRow = rows;
+ setupSampleSpace(m_cachedState->m_samplesRow, m_cachedState->m_samplesColumn);
}
-void DeclarativeBars::setShadowQuality(DeclarativeBars::ShadowQuality quality)
+int DeclarativeBars::columns() const
{
- m_cachedState->m_shadowQuality = QtDataVis3D::ShadowQuality(quality);
- m_cachedState->m_isShadowQualitySet = true;
- update();
+ return m_cachedState->m_samplesColumn;
}
-DeclarativeBars::ShadowQuality DeclarativeBars::shadowQuality()
+void DeclarativeBars::setColumns(int columns)
{
- return DeclarativeBars::ShadowQuality(m_shared->shadowQuality());
+ m_cachedState->m_samplesColumn = columns;
+ setupSampleSpace(m_cachedState->m_samplesRow, m_cachedState->m_samplesColumn);
}
void DeclarativeBars::setMeshFileName(const QString &objFileName)
@@ -511,11 +416,25 @@ void DeclarativeBarsRenderer::render()
DeclarativeBarsCachedStatePrivate::DeclarativeBarsCachedStatePrivate() :
m_isSampleSpaceSet(false),
+ m_samplesRow(0),
+ m_samplesColumn(0),
m_labelRow(QStringLiteral("")),
m_labelColumn(QStringLiteral("")),
m_labelHeight(QStringLiteral("")),
- m_dataRow(0),
- m_dataSet(0)
+ m_isSelectionModeSet(false),
+ m_selectionMode(ModeNone),
+ m_isLabelTransparencySet(false),
+ m_labelTransparency(TransparencyNone),
+ m_isShadowQualitySet(false),
+ m_shadowQuality(ShadowNone),
+ m_isGridSet(false),
+ m_isGridEnabled(true),
+ m_isTickCountSet(false),
+ m_tickCount(5),
+ m_tickStep(1),
+ m_tickMin(0)
+
+
{
}
diff --git a/src/datavis3dqml2/declarativebars.h b/src/datavis3dqml2/declarativebars.h
index 395fda10..cada9870 100644
--- a/src/datavis3dqml2/declarativebars.h
+++ b/src/datavis3dqml2/declarativebars.h
@@ -45,9 +45,7 @@
#include "datavis3dglobal_p.h"
#include "bars3dcontroller_p.h"
#include "declarativebars_p.h"
-#include "qdataitem.h"
-#include "qdatarow.h"
-#include "qdataset.h"
+#include "qitemmodelbardatamapping.h"
#include <qsgsimpletexturenode.h>
#include <QAbstractItemModel>
@@ -72,12 +70,14 @@ class DeclarativeBars : public QQuickItem
Q_PROPERTY(float fontSize READ fontSize WRITE setFontSize)
Q_PROPERTY(bool gridVisible READ isGridVisible WRITE setGridVisible)
Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible)
- Q_PROPERTY(int width READ width WRITE setWidth)
- Q_PROPERTY(int height READ height WRITE setHeight)
+ Q_PROPERTY(int rows READ rows WRITE setRows)
+ Q_PROPERTY(int columns READ columns WRITE setColumns)
+ Q_PROPERTY(QItemModelBarDataMapping *mapping READ mapping WRITE setMapping)
Q_ENUMS(SelectionMode)
Q_ENUMS(ShadowQuality)
Q_ENUMS(LabelTransparency)
+
protected:
Bars3dController *m_shared;
DeclarativeBarsCachedStatePrivate *m_cachedState;
@@ -127,33 +127,6 @@ public:
void setData(QAbstractItemModel *data);
QAbstractItemModel *data();
- // TODO: Are we going to offer only addData(QAbstractItemModel *data) for QML2?
- // If so, all these adds can be removed, as well as metatypes for dataset and datarow
-
- // Add a row of data. Each new row is added to the front of the sample space, moving previous
- // rows back (if sample space is more than one row deep)
- Q_INVOKABLE void addDataRow(const QVector<GLfloat> &dataRow,
- const QString &labelRow = QString(),
- const QVector<QString> &labelsColumn = QVector<QString>());
- // ownership of dataItems is transferred
- Q_INVOKABLE void addDataRow(const QVector<QDataItem*> &dataRow,
- const QString &labelRow = QString(),
- const QVector<QString> &labelsColumn = QVector<QString>());
- // ownership of dataRow is transferred
- Q_INVOKABLE void addDataRow(QDataRow *dataRow);
-
- // Add complete data set at a time, as a vector of data rows
- Q_INVOKABLE void addDataSet(const QVector< QVector<GLfloat> > &data,
- const QVector<QString> &labelsRow = QVector<QString>(),
- const QVector<QString> &labelsColumn = QVector<QString>());
-
- // ownership of dataItems is transferred
- Q_INVOKABLE void addDataSet(const QVector< QVector<QDataItem*> > &data,
- const QVector<QString> &labelsRow = QVector<QString>(),
- const QVector<QString> &labelsColumn = QVector<QString>());
- // ownership of dataSet is transferred
- Q_INVOKABLE void addDataSet(QDataSet* dataSet);
-
// bar thickness, spacing between bars, and is spacing relative to thickness or absolute
// y -component sets the thickness/spacing of z -direction
// With relative 0.0f means side-to-side, 1.0f = one thickness in between
@@ -168,10 +141,7 @@ public:
Q_INVOKABLE void setMeshFileName(const QString &objFileName);
// how many samples per row and column, and names for axes
- Q_INVOKABLE void setupSampleSpace(int samplesRow, int samplesColumn,
- const QString &labelRow = QString(),
- const QString &labelColumn = QString(),
- const QString &labelHeight = QString());
+ Q_INVOKABLE void setupSampleSpace(int samplesRow, int samplesColumn);
// Select preset camera placement
Q_INVOKABLE void setCameraPreset(CameraPreset preset);
@@ -179,7 +149,7 @@ public:
// Set camera rotation if you don't want to use the presets (in horizontal (-180...180) and
// vertical (0...90) (or (-90...90) if there are negative values) angles and distance in
// percentage (10...500))
- Q_INVOKABLE void setCameraPosition(GLfloat horizontal, GLfloat vertical, GLint distance = 100);
+ Q_INVOKABLE void setCameraPosition(qreal horizontal, qreal vertical, int distance);
// Set theme (bar colors, shaders, window color, background colors, light intensity and text
// colors are affected)
@@ -193,7 +163,7 @@ public:
// Set tick count and step. Note; tickCount * step should be the maximum possible value of data
// set. Minimum is the absolute minimum possible value a bar can have. This is especially
// important to set if values can be negative.
- Q_INVOKABLE void setTickCount(GLint tickCount, GLfloat step, GLfloat minimum = 0.0f);
+ Q_INVOKABLE void setTickCount(int tickCount, qreal step, qreal minimum);
// TODO: light placement API
@@ -225,6 +195,15 @@ public:
void setShadowQuality(ShadowQuality quality);
ShadowQuality shadowQuality();
+ QItemModelBarDataMapping *mapping() const;
+ void setMapping(QItemModelBarDataMapping *mapping);
+
+ int rows() const;
+ void setRows(int rows);
+
+ int columns() const;
+ void setColumns(int columns);
+
public slots:
// Used to detect when shadow quality changes autonomously due to e.g. resizing.
void handleShadowQualityUpdate(QtDataVis3D::ShadowQuality quality);
diff --git a/src/datavis3dqml2/declarativebars_p.h b/src/datavis3dqml2/declarativebars_p.h
index e078d21f..237b69a3 100644
--- a/src/datavis3dqml2/declarativebars_p.h
+++ b/src/datavis3dqml2/declarativebars_p.h
@@ -57,9 +57,6 @@
QT_DATAVIS3D_BEGIN_NAMESPACE
-class QDataRow;
-class QDataSet;
-
class DeclarativeBarsCachedStatePrivate
{
public:
@@ -67,16 +64,12 @@ public:
~DeclarativeBarsCachedStatePrivate();
bool m_isSampleSpaceSet;
- int m_cachedState;
int m_samplesRow;
int m_samplesColumn;
QString m_labelRow;
QString m_labelColumn;
QString m_labelHeight;
- QDataRow *m_dataRow;
- QDataSet *m_dataSet;
-
bool m_isSelectionModeSet;
SelectionMode m_selectionMode;
@@ -88,6 +81,11 @@ public:
bool m_isGridSet;
bool m_isGridEnabled;
+
+ bool m_isTickCountSet;
+ int m_tickCount;
+ qreal m_tickStep;
+ qreal m_tickMin;
};
QT_DATAVIS3D_END_NAMESPACE