diff options
author | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2013-09-04 08:24:21 +0300 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2013-09-04 08:28:42 +0300 |
commit | dd3a2d591cfd775311f54425220263b1aa2f3798 (patch) | |
tree | b8516337ef117a24826cb49106196a6965dd9699 /src/datavis3d | |
parent | bc1771d0ea20eb3b42beccddbe852541e107ab65 (diff) |
Remove maps
Change-Id: I4414919764f5c33242847d9ac873ae03845a00b4
Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src/datavis3d')
29 files changed, 2 insertions, 4056 deletions
diff --git a/src/datavis3d/data/data.pri b/src/datavis3d/data/data.pri index 873b9a0e..312a8658 100644 --- a/src/datavis3d/data/data.pri +++ b/src/datavis3d/data/data.pri @@ -12,20 +12,11 @@ HEADERS += \ $$PWD/qitemmodelbardatamapping_p.h \ $$PWD/qitemmodelbardataproxy_p.h \ $$PWD/qitemmodelbardataproxy.h \ - $$PWD/maprenderitem_p.h \ - $$PWD/qmapdataitem.h \ - $$PWD/qmapdataitem_p.h \ - $$PWD/qmapdataproxy.h \ - $$PWD/qmapdataproxy_p.h \ $$PWD/scatterrenderitem_p.h \ $$PWD/qscatterdataitem.h \ $$PWD/qscatterdataitem_p.h \ $$PWD/qscatterdataproxy.h \ $$PWD/qscatterdataproxy_p.h \ - $$PWD/qitemmodelmapdatamapping.h \ - $$PWD/qitemmodelmapdatamapping_p.h \ - $$PWD/qitemmodelmapdataproxy.h \ - $$PWD/qitemmodelmapdataproxy_p.h \ $$PWD/qitemmodelscatterdatamapping.h \ $$PWD/qitemmodelscatterdatamapping_p.h \ $$PWD/qitemmodelscatterdataproxy.h \ @@ -45,14 +36,9 @@ SOURCES += \ $$PWD/qbardataitem.cpp \ $$PWD/qitemmodelbardatamapping.cpp \ $$PWD/qitemmodelbardataproxy.cpp \ - $$PWD/maprenderitem.cpp \ - $$PWD/qmapdataitem.cpp \ - $$PWD/qmapdataproxy.cpp \ $$PWD/scatterrenderitem.cpp \ $$PWD/qscatterdataitem.cpp \ $$PWD/qscatterdataproxy.cpp \ - $$PWD/qitemmodelmapdatamapping.cpp \ - $$PWD/qitemmodelmapdataproxy.cpp \ $$PWD/qitemmodelscatterdatamapping.cpp \ $$PWD/qitemmodelscatterdataproxy.cpp \ $$PWD/abstractitemmodelhandler.cpp \ diff --git a/src/datavis3d/data/maprenderitem.cpp b/src/datavis3d/data/maprenderitem.cpp deleted file mode 100644 index d737e6f6..00000000 --- a/src/datavis3d/data/maprenderitem.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc -** All rights reserved. -** For any questions to Digia, please use contact form at http://qt.digia.com -** -** This file is part of the QtDataVis3D module. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** contact form at http://qt.digia.com -** -****************************************************************************/ - -#include "maprenderitem_p.h" -#include "maps3drenderer_p.h" // TODO remove when maps refactored -#include "maps3dcontroller_p.h" // TODO should be renderer -#include "qmapdataproxy.h" - -QT_DATAVIS3D_BEGIN_NAMESPACE - -MapRenderItem::MapRenderItem() - : BarRenderItem() -{ -} - -MapRenderItem::MapRenderItem(const MapRenderItem &other) - : BarRenderItem(other) -{ - m_renderer = other.m_renderer; - m_mapPosition = other.m_mapPosition; - m_itemLabel = other.m_itemLabel; -} - -MapRenderItem::~MapRenderItem() -{ -} - -QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3d/data/maprenderitem_p.h b/src/datavis3d/data/maprenderitem_p.h deleted file mode 100644 index f8f877af..00000000 --- a/src/datavis3d/data/maprenderitem_p.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc -** All rights reserved. -** For any questions to Digia, please use contact form at http://qt.digia.com -** -** This file is part of the QtDataVis3D module. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** contact form at http://qt.digia.com -** -****************************************************************************/ - -// -// 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 MAPRENDERITEM_P_H -#define MAPRENDERITEM_P_H - -#include "barrenderitem_p.h" - -QT_DATAVIS3D_BEGIN_NAMESPACE - -class Maps3DRenderer; -class Maps3DController; // TODO remove when maps refactored - -class MapRenderItem : public BarRenderItem -{ -public: - MapRenderItem(); - MapRenderItem(const MapRenderItem &other); - virtual ~MapRenderItem(); - - inline const QPointF &mapPosition() const { return m_mapPosition; } - inline void setMapPosition(const QPointF &pos) { m_mapPosition = pos; } - - inline const QString &itemLabel() const { return m_itemLabel; } - inline void setItemLabel(const QString &label) { m_itemLabel = label; } - - // TODO should be in abstract, but currently there is no abstract renderer - // TODO change when maps refactored - inline void setRenderer(Maps3DController *renderer) { m_renderer = renderer; } - -protected: - Maps3DController *m_renderer; - QPointF m_mapPosition; - QString m_itemLabel; // from QMapDataItem::label() - unformatted item label - - friend class QMapDataItem; -}; - -typedef QVector<MapRenderItem> MapRenderItemArray; - -QT_DATAVIS3D_END_NAMESPACE - -#endif diff --git a/src/datavis3d/data/qabstractdataproxy.h b/src/datavis3d/data/qabstractdataproxy.h index 99b28e1f..ccf66b20 100644 --- a/src/datavis3d/data/qabstractdataproxy.h +++ b/src/datavis3d/data/qabstractdataproxy.h @@ -37,9 +37,8 @@ public: enum DataType { DataTypeNone = 0, DataTypeBar = 1, - DataTypeMap = 2, - DataTypeScatter = 4, - DataTypeSurface = 8 + DataTypeScatter = 2, + DataTypeSurface = 4 }; protected: diff --git a/src/datavis3d/data/qitemmodelmapdatamapping.cpp b/src/datavis3d/data/qitemmodelmapdatamapping.cpp deleted file mode 100644 index bdc23b7f..00000000 --- a/src/datavis3d/data/qitemmodelmapdatamapping.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc -** All rights reserved. -** For any questions to Digia, please use contact form at http://qt.digia.com -** -** This file is part of the QtDataVis3D module. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** contact form at http://qt.digia.com -** -****************************************************************************/ - -#include "qitemmodelmapdatamapping_p.h" - -QT_DATAVIS3D_BEGIN_NAMESPACE - -/*! - * \class QItemModelMapDataMapping - * \inmodule QtDataVis3D - * \brief Data model mapping for Q3DMaps. - * \since 1.0.0 - * - * QItemModelMapDataMapping is used to define roles for mapping data in QAbstractItemModel to - * Q3DMaps. - * - * TO BE CHECKED (add more explanations and/or example) - * - * \sa QItemModelMapDataProxy - */ - -/*! - * Constructs QItemModelMapDataMapping with the given \a parent. - */ -QItemModelMapDataMapping::QItemModelMapDataMapping(QObject *parent) - : QObject(parent), - d_ptr(new QItemModelMapDataMappingPrivate(this)) -{ -} - -/*! - * Constructs QItemModelMapDataMapping with \a labelRole, \a xPosRole, \a zPosRole, - * \a valueRole and the given \a parent. - */ -QItemModelMapDataMapping::QItemModelMapDataMapping(const QString &labelRole, - const QString &xPosRole, - const QString &zPosRole, - const QString &valueRole, - QObject *parent) - : QObject(parent), - d_ptr(new QItemModelMapDataMappingPrivate(this)) -{ - d_ptr->m_labelRole = labelRole; - d_ptr->m_xPosRole = xPosRole; - d_ptr->m_zPosRole = zPosRole; - d_ptr->m_valueRole = valueRole; -} - -/*! - * Destroys QItemModelMapDataMapping. - */ -QItemModelMapDataMapping::~QItemModelMapDataMapping() -{ -} - -/*! - * \property QItemModelMapDataMapping::labelRole - * - * Defines the label role for the mapping. - */ -void QItemModelMapDataMapping::setLabelRole(const QString &role) -{ - d_ptr->m_labelRole = role; - emit mappingChanged(); -} - -QString QItemModelMapDataMapping::labelRole() const -{ - return d_ptr->m_labelRole; -} - -/*! - * \property QItemModelMapDataMapping::xPosRole - * - * Defines the x position role for the mapping. - */ -void QItemModelMapDataMapping::setXPosRole(const QString &role) -{ - d_ptr->m_xPosRole = role; - emit mappingChanged(); -} - -QString QItemModelMapDataMapping::xPosRole() const -{ - return d_ptr->m_xPosRole; -} - -/*! - * \property QItemModelMapDataMapping::zPosRole - * - * Defines the z position role for the mapping. - */ -void QItemModelMapDataMapping::setZPosRole(const QString &role) -{ - d_ptr->m_zPosRole = role; - emit mappingChanged(); -} - -QString QItemModelMapDataMapping::zPosRole() const -{ - return d_ptr->m_zPosRole; -} - -/*! - * \property QItemModelMapDataMapping::valueRole - * - * Defines the value role for the mapping. - */ -void QItemModelMapDataMapping::setValueRole(const QString &role) -{ - d_ptr->m_valueRole = role; - emit mappingChanged(); -} - -QString QItemModelMapDataMapping::valueRole() const -{ - return d_ptr->m_valueRole; -} - - -/*! - * Changes \a labelRole, \a xPosRole, \a zPosRole and \a valueRole to the mapping. - * - * Emits mappingChanged() signal after remapping. - */ -void QItemModelMapDataMapping::remap(const QString &labelRole, const QString &xPosRole, - const QString &zPosRole, const QString &valueRole) -{ - d_ptr->m_labelRole = labelRole; - d_ptr->m_xPosRole = xPosRole; - d_ptr->m_zPosRole = zPosRole; - d_ptr->m_valueRole = valueRole; - - emit mappingChanged(); -} - -// QItemModelMapDataMappingPrivate - -QItemModelMapDataMappingPrivate::QItemModelMapDataMappingPrivate(QItemModelMapDataMapping *q) - : QObject(0), - q_ptr(q) -{ -} - -QItemModelMapDataMappingPrivate::~QItemModelMapDataMappingPrivate() -{ -} - -QT_DATAVIS3D_END_NAMESPACE - diff --git a/src/datavis3d/data/qitemmodelmapdatamapping.h b/src/datavis3d/data/qitemmodelmapdatamapping.h deleted file mode 100644 index 6c6acdae..00000000 --- a/src/datavis3d/data/qitemmodelmapdatamapping.h +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc -** All rights reserved. -** For any questions to Digia, please use contact form at http://qt.digia.com -** -** This file is part of the QtDataVis3D module. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** contact form at http://qt.digia.com -** -****************************************************************************/ - -#ifndef QITEMMODELMAPDATAMAPPING_H -#define QITEMMODELMAPDATAMAPPING_H - -#include <QtDataVis3D/qdatavis3denums.h> -#include <QStringList> - -QT_DATAVIS3D_BEGIN_NAMESPACE - -class QItemModelMapDataMappingPrivate; - -class QT_DATAVIS3D_EXPORT QItemModelMapDataMapping : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString labelRole READ labelRole WRITE setLabelRole NOTIFY mappingChanged) - Q_PROPERTY(QString xPosRole READ xPosRole WRITE setXPosRole NOTIFY mappingChanged) - Q_PROPERTY(QString zPosRole READ zPosRole WRITE setZPosRole NOTIFY mappingChanged) - Q_PROPERTY(QString valueRole READ valueRole WRITE setValueRole NOTIFY mappingChanged) - -public: - explicit QItemModelMapDataMapping(QObject *parent = 0); - QItemModelMapDataMapping(const QString &labelRole, const QString &xPosRole, - const QString &zPosRole, const QString &valueRole, - QObject *parent = 0); - virtual ~QItemModelMapDataMapping(); - - void setLabelRole(const QString &role); - QString labelRole() const; - void setXPosRole(const QString &role); - QString xPosRole() const; - void setZPosRole(const QString &role); - QString zPosRole() const; - void setValueRole(const QString &role); - QString valueRole() const; - - void remap(const QString &labelRole, const QString &xPosRole, - const QString &zPosRole, const QString &valueRole); - -signals: - void mappingChanged(); - -private: - Q_DISABLE_COPY(QItemModelMapDataMapping) - QScopedPointer<QItemModelMapDataMappingPrivate> d_ptr; -}; - - -QT_DATAVIS3D_END_NAMESPACE - -#endif diff --git a/src/datavis3d/data/qitemmodelmapdatamapping_p.h b/src/datavis3d/data/qitemmodelmapdatamapping_p.h deleted file mode 100644 index c289f565..00000000 --- a/src/datavis3d/data/qitemmodelmapdatamapping_p.h +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc -** All rights reserved. -** For any questions to Digia, please use contact form at http://qt.digia.com -** -** This file is part of the QtDataVis3D module. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** contact form at http://qt.digia.com -** -****************************************************************************/ - -// -// 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 "qitemmodelmapdatamapping.h" - -#ifndef QITEMMODELMAPDATAMAPPING_P_H -#define QITEMMODELMAPDATAMAPPING_P_H - -QT_DATAVIS3D_BEGIN_NAMESPACE - -class QItemModelMapDataMappingPrivate : public QObject -{ - Q_OBJECT -public: - QItemModelMapDataMappingPrivate(QItemModelMapDataMapping *q); - virtual ~QItemModelMapDataMappingPrivate(); - -private: - QString m_labelRole; - QString m_xPosRole; - QString m_zPosRole; - QString m_valueRole; - - QItemModelMapDataMapping *q_ptr; - - friend class QItemModelMapDataMapping; -}; - -QT_DATAVIS3D_END_NAMESPACE - -#endif diff --git a/src/datavis3d/data/qitemmodelmapdataproxy.cpp b/src/datavis3d/data/qitemmodelmapdataproxy.cpp deleted file mode 100644 index 6288d979..00000000 --- a/src/datavis3d/data/qitemmodelmapdataproxy.cpp +++ /dev/null @@ -1,347 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc -** All rights reserved. -** For any questions to Digia, please use contact form at http://qt.digia.com -** -** This file is part of the QtDataVis3D module. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** contact form at http://qt.digia.com -** -****************************************************************************/ - -#include "qitemmodelmapdataproxy_p.h" -#include <QTimer> - -QT_DATAVIS3D_BEGIN_NAMESPACE - -/*! - * \class QItemModelMapDataProxy - * \inmodule QtDataVis3D - * \brief Proxy class for Q3DMaps data model mapping. - * \since 1.0.0 - * - * QItemModelMapDataProxy allows you to use QAbstractItemModel derived models as a data source - * for Q3DMaps. It maps roles defined in QItemModelMapDataMapping to roles in the model. - */ - -/*! - * Constructs QItemModelMapDataProxy. - */ -QItemModelMapDataProxy::QItemModelMapDataProxy() : - QMapDataProxy(new QItemModelMapDataProxyPrivate(this)) -{ -} - -/*! - * Constructs QItemModelMapDataProxy with \a itemModel and \a mapping. Does not take ownership of - * the model or the mapping, but does connect to them to listen for changes. - */ -QItemModelMapDataProxy::QItemModelMapDataProxy(QAbstractItemModel *itemModel, - QItemModelMapDataMapping *mapping) : - QMapDataProxy(new QItemModelMapDataProxyPrivate(this)) -{ - dptr()->setItemModel(itemModel); - dptr()->setActiveMapping(mapping); -} - -/*! - * Destroys QItemModelMapDataProxy. - */ -QItemModelMapDataProxy::~QItemModelMapDataProxy() -{ -} - -/*! - * \property QItemModelMapDataProxy::itemModel - * - * Defines item model. Does not take ownership of the model, but does connect to it to listen for - * changes. - */ -void QItemModelMapDataProxy::setItemModel(const QAbstractItemModel *itemModel) -{ - dptr()->setItemModel(itemModel); -} - -const QAbstractItemModel *QItemModelMapDataProxy::itemModel() const -{ - return dptrc()->m_itemModel.data(); -} - -/*! - * \property QItemModelMapDataProxy::activeMapping - * - * Defines data mapping. Proxy takes ownership of the \a mapping. - * Modifying a mapping that is set to the proxy will trigger data set re-resolving. - */ -void QItemModelMapDataProxy::setActiveMapping(QItemModelMapDataMapping *mapping) -{ - dptr()->setActiveMapping(mapping); -} - -QItemModelMapDataMapping *QItemModelMapDataProxy::activeMapping() const -{ - return dptrc()->m_mapping; -} - -/*! - * \internal - */ -QItemModelMapDataProxyPrivate *QItemModelMapDataProxy::dptr() -{ - return static_cast<QItemModelMapDataProxyPrivate *>(d_ptr.data()); -} - -/*! - * \internal - */ -const QItemModelMapDataProxyPrivate *QItemModelMapDataProxy::dptrc() const -{ - return static_cast<const QItemModelMapDataProxyPrivate *>(d_ptr.data()); -} - -// QItemModelMapDataProxyPrivate - -QItemModelMapDataProxyPrivate::QItemModelMapDataProxyPrivate(QItemModelMapDataProxy *q) - : QMapDataProxyPrivate(q), - m_mapping(0), - resolvePending(0) -{ - m_resolveTimer.setSingleShot(true); - QObject::connect(&m_resolveTimer, &QTimer::timeout, - this, &QItemModelMapDataProxyPrivate::handlePendingResolve); -} - -QItemModelMapDataProxyPrivate::~QItemModelMapDataProxyPrivate() -{ -} - -void QItemModelMapDataProxyPrivate::setItemModel(const QAbstractItemModel *itemModel) -{ - if (!m_itemModel.isNull()) - QObject::disconnect(m_itemModel, 0, this, 0); - - m_itemModel = itemModel; - - if (!m_itemModel.isNull()) { - QObject::connect(m_itemModel.data(), &QAbstractItemModel::columnsInserted, - this, &QItemModelMapDataProxyPrivate::handleColumnsInserted); - QObject::connect(m_itemModel.data(), &QAbstractItemModel::columnsMoved, - this, &QItemModelMapDataProxyPrivate::handleColumnsMoved); - QObject::connect(m_itemModel.data(), &QAbstractItemModel::columnsRemoved, - this, &QItemModelMapDataProxyPrivate::handleColumnsRemoved); - QObject::connect(m_itemModel.data(), &QAbstractItemModel::dataChanged, - this, &QItemModelMapDataProxyPrivate::handleDataChanged); - QObject::connect(m_itemModel.data(), &QAbstractItemModel::layoutChanged, - this, &QItemModelMapDataProxyPrivate::handleLayoutChanged); - QObject::connect(m_itemModel.data(), &QAbstractItemModel::modelReset, - this, &QItemModelMapDataProxyPrivate::handleModelReset); - QObject::connect(m_itemModel.data(), &QAbstractItemModel::rowsInserted, - this, &QItemModelMapDataProxyPrivate::handleRowsInserted); - QObject::connect(m_itemModel.data(), &QAbstractItemModel::rowsMoved, - this, &QItemModelMapDataProxyPrivate::handleRowsMoved); - QObject::connect(m_itemModel.data(), &QAbstractItemModel::rowsRemoved, - this, &QItemModelMapDataProxyPrivate::handleRowsRemoved); - } - if (!m_resolveTimer.isActive()) - m_resolveTimer.start(0); -} - -void QItemModelMapDataProxyPrivate::setActiveMapping(QItemModelMapDataMapping *mapping) -{ - if (m_mapping) { - QObject::disconnect(m_mapping, &QItemModelMapDataMapping::mappingChanged, - this, &QItemModelMapDataProxyPrivate::handleMappingChanged); - } - - m_mapping = mapping; - - if (m_mapping) { - QObject::connect(m_mapping, &QItemModelMapDataMapping::mappingChanged, - this, &QItemModelMapDataProxyPrivate::handleMappingChanged); - } - - if (!m_resolveTimer.isActive()) - m_resolveTimer.start(0); -} - -void QItemModelMapDataProxyPrivate::handleColumnsInserted(const QModelIndex &parent, - int start, int end) -{ - Q_UNUSED(parent) - Q_UNUSED(start) - Q_UNUSED(end) - - // Resolve new items - if (!m_resolveTimer.isActive()) - m_resolveTimer.start(0); // TODO Resolving entire model is inefficient -} - -void QItemModelMapDataProxyPrivate::handleColumnsMoved(const QModelIndex &sourceParent, - int sourceStart, - int sourceEnd, - const QModelIndex &destinationParent, - int destinationColumn) -{ - Q_UNUSED(sourceParent) - Q_UNUSED(sourceStart) - Q_UNUSED(sourceEnd) - Q_UNUSED(destinationParent) - Q_UNUSED(destinationColumn) - - // Resolve moved items - if (!m_resolveTimer.isActive()) - m_resolveTimer.start(0); // TODO Resolving entire model is inefficient -} - -void QItemModelMapDataProxyPrivate::handleColumnsRemoved(const QModelIndex &parent, - int start, int end) -{ - Q_UNUSED(parent) - Q_UNUSED(start) - Q_UNUSED(end) - - // Remove old items - if (!m_resolveTimer.isActive()) - m_resolveTimer.start(0); // TODO Resolving entire model is inefficient -} - -void QItemModelMapDataProxyPrivate::handleDataChanged(const QModelIndex &topLeft, - const QModelIndex &bottomRight, - const QVector<int> &roles) -{ - Q_UNUSED(topLeft) - Q_UNUSED(bottomRight) - Q_UNUSED(roles) - - // Resolve changed items - if (!m_resolveTimer.isActive()) - m_resolveTimer.start(0); // TODO Resolving entire model is inefficient -} - -void QItemModelMapDataProxyPrivate::handleLayoutChanged(const QList<QPersistentModelIndex> &parents, - QAbstractItemModel::LayoutChangeHint hint) -{ - Q_UNUSED(parents) - Q_UNUSED(hint) - - // Resolve moved items - if (!m_resolveTimer.isActive()) - m_resolveTimer.start(0); // TODO Resolving entire model is inefficient -} - -void QItemModelMapDataProxyPrivate::handleModelReset() -{ - // Data cleared, reset array - if (!m_resolveTimer.isActive()) - m_resolveTimer.start(0); // TODO Resolving entire model is inefficient -} - -void QItemModelMapDataProxyPrivate::handleRowsInserted(const QModelIndex &parent, - int start, int end) -{ - Q_UNUSED(parent) - Q_UNUSED(start) - Q_UNUSED(end) - - // Resolve new items - if (!m_resolveTimer.isActive()) - m_resolveTimer.start(0); // TODO Resolving entire model is inefficient -} - -void QItemModelMapDataProxyPrivate::handleRowsMoved(const QModelIndex &sourceParent, - int sourceStart, - int sourceEnd, - const QModelIndex &destinationParent, - int destinationRow) -{ - Q_UNUSED(sourceParent) - Q_UNUSED(sourceStart) - Q_UNUSED(sourceEnd) - Q_UNUSED(destinationParent) - Q_UNUSED(destinationRow) - - // Resolve moved items - if (!m_resolveTimer.isActive()) - m_resolveTimer.start(0); // TODO Resolving entire model is inefficient -} - -void QItemModelMapDataProxyPrivate::handleRowsRemoved(const QModelIndex &parent, int start, int end) -{ - Q_UNUSED(parent) - Q_UNUSED(start) - Q_UNUSED(end) - - // Resolve removed items - if (!m_resolveTimer.isActive()) - m_resolveTimer.start(0); // TODO Resolving entire model is inefficient -} - -void QItemModelMapDataProxyPrivate::handleMappingChanged() -{ - if (!m_resolveTimer.isActive()) - m_resolveTimer.start(0); -} - -void QItemModelMapDataProxyPrivate::handlePendingResolve() -{ - resolveModel(); -} - -// Resolve entire item model into QMapDataArray. -void QItemModelMapDataProxyPrivate::resolveModel() -{ - if (m_itemModel.isNull() || !m_mapping) { - qptr()->resetArray(0); - return; - } - - static const int noRoleIndex = -1; - - QHash<int, QByteArray> roleHash = m_itemModel->roleNames(); - const int labelRole = roleHash.key(m_mapping->labelRole().toLatin1(), noRoleIndex); - const int xPosRole = roleHash.key(m_mapping->xPosRole().toLatin1(), noRoleIndex); - const int zPosRole = roleHash.key(m_mapping->zPosRole().toLatin1(), noRoleIndex); - // Default valueRole to display role if no mapping - const int valueRole = roleHash.key(m_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; - - // Parse data into newProxyArray - QMapDataArray *newProxyArray = new QMapDataArray(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()); - qreal xPos(qreal(0.0)); - qreal yPos(qreal(0.0)); - if (xPosRole != noRoleIndex) - xPos = index.data(xPosRole).toReal(); - if (zPosRole != noRoleIndex) - yPos = index.data(zPosRole).toReal(); // z position is mapped to y of QPoint - (*newProxyArray)[runningCount].setMapPosition(QPointF(xPos, yPos)); - (*newProxyArray)[runningCount].setValue(index.data(valueRole).toReal()); - runningCount++; - } - } - - qDebug() << __FUNCTION__ << "Total count:" << newProxyArray->size(); - - qptr()->resetArray(newProxyArray); -} - -QItemModelMapDataProxy *QItemModelMapDataProxyPrivate::qptr() -{ - return static_cast<QItemModelMapDataProxy *>(q_ptr); -} - -QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3d/data/qitemmodelmapdataproxy.h b/src/datavis3d/data/qitemmodelmapdataproxy.h deleted file mode 100644 index 6d817b46..00000000 --- a/src/datavis3d/data/qitemmodelmapdataproxy.h +++ /dev/null @@ -1,58 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc -** All rights reserved. -** For any questions to Digia, please use contact form at http://qt.digia.com -** -** This file is part of the QtDataVis3D module. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** contact form at http://qt.digia.com -** -****************************************************************************/ - -#ifndef QITEMMODELMAPDATAPROXY_H -#define QITEMMODELMAPDATAPROXY_H - -#include <QtDataVis3D/qmapdataproxy.h> -#include <QtDataVis3D/qitemmodelmapdatamapping.h> -#include <QAbstractItemModel> -#include <QStringList> - -QT_DATAVIS3D_BEGIN_NAMESPACE - -class QItemModelMapDataProxyPrivate; - -class QT_DATAVIS3D_EXPORT QItemModelMapDataProxy : public QMapDataProxy -{ - Q_OBJECT - Q_PROPERTY(const QAbstractItemModel* itemModel READ itemModel WRITE setItemModel) - Q_PROPERTY(QItemModelMapDataMapping* activeMapping READ activeMapping WRITE setActiveMapping) - -public: - explicit QItemModelMapDataProxy(); - explicit QItemModelMapDataProxy(QAbstractItemModel *itemModel, QItemModelMapDataMapping *mapping); - virtual ~QItemModelMapDataProxy(); - - void setItemModel(const QAbstractItemModel *itemModel); - const QAbstractItemModel *itemModel() const; - - void setActiveMapping(QItemModelMapDataMapping *mapping); - QItemModelMapDataMapping *activeMapping() const; - -protected: - QItemModelMapDataProxyPrivate *dptr(); - const QItemModelMapDataProxyPrivate *dptrc() const; - -private: - Q_DISABLE_COPY(QItemModelMapDataProxy) -}; - -QT_DATAVIS3D_END_NAMESPACE - -#endif diff --git a/src/datavis3d/data/qitemmodelmapdataproxy_p.h b/src/datavis3d/data/qitemmodelmapdataproxy_p.h deleted file mode 100644 index ce73c54b..00000000 --- a/src/datavis3d/data/qitemmodelmapdataproxy_p.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc -** All rights reserved. -** For any questions to Digia, please use contact form at http://qt.digia.com -** -** This file is part of the QtDataVis3D module. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** contact form at http://qt.digia.com -** -****************************************************************************/ - -// -// 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 QITEMMODELMAPDATAPROXY_P_H -#define QITEMMODELMAPDATAPROXY_P_H - -#include "qitemmodelmapdataproxy.h" -#include "qmapdataproxy_p.h" -#include <QPointer> -#include <QTimer> - -QT_DATAVIS3D_BEGIN_NAMESPACE - -class QItemModelMapDataProxyPrivate : public QMapDataProxyPrivate -{ - Q_OBJECT -public: - QItemModelMapDataProxyPrivate(QItemModelMapDataProxy *q); - virtual ~QItemModelMapDataProxyPrivate(); - - void setItemModel(const QAbstractItemModel *itemModel); - void setActiveMapping(QItemModelMapDataMapping *mapping); - -public slots: - void handleColumnsInserted(const QModelIndex &parent, int start, int end); - void handleColumnsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, - const QModelIndex &destinationParent, int destinationColumn); - void handleColumnsRemoved(const QModelIndex &parent, int start, int end); - void handleDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, - const QVector<int> &roles = QVector<int> ()); - void handleLayoutChanged(const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex> (), - QAbstractItemModel::LayoutChangeHint hint = QAbstractItemModel::NoLayoutChangeHint); - void handleModelReset(); - void handleRowsInserted(const QModelIndex &parent, int start, int end); - void handleRowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, - const QModelIndex &destinationParent, int destinationRow); - void handleRowsRemoved(const QModelIndex &parent, int start, int end); - - void handleMappingChanged(); - void handlePendingResolve(); - -private: - void resolveModel(); - QItemModelMapDataProxy *qptr(); - - QPointer<const QAbstractItemModel> m_itemModel; // Not owned - QItemModelMapDataMapping *m_mapping; - bool resolvePending; - QTimer m_resolveTimer; - - friend class QItemModelMapDataProxy; -}; - -QT_DATAVIS3D_END_NAMESPACE - -#endif diff --git a/src/datavis3d/data/qmapdataitem.cpp b/src/datavis3d/data/qmapdataitem.cpp deleted file mode 100644 index 47e1a659..00000000 --- a/src/datavis3d/data/qmapdataitem.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc -** All rights reserved. -** For any questions to Digia, please use contact form at http://qt.digia.com -** -** This file is part of the QtDataVis3D module. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** contact form at http://qt.digia.com -** -****************************************************************************/ - -#include "qmapdataitem_p.h" - -QT_DATAVIS3D_BEGIN_NAMESPACE - -/*! - * \class QMapDataItem - * \inmodule QtDataVis3D - * \brief The QMapDataItem class provides a container for resolved data to be added to maps graphs. - * \since 1.0.0 - * - * A QMapDataItem holds data for a single rendered bar in a maps graph. - * Maps data proxies parse data into QMapDataItem instances for visualizing. - * - * \sa QMapDataProxy, {Qt Data Visualization 3D C++ Classes} - */ - -/*! - * Constructs QMapDataItem. - */ -QMapDataItem::QMapDataItem() - : QBarDataItem() -{ -} - -/*! - * Constructs a copy of \a other. - */ -QMapDataItem::QMapDataItem(const QMapDataItem &other) - : QBarDataItem(other) -{ - operator=(other); -} - -/*! - * Destroys QMapDataItem. - */ -QMapDataItem::~QMapDataItem() -{ -} - -/*! - * Assigns a copy of \a other to this object. - */ -QMapDataItem &QMapDataItem::operator=(const QMapDataItem &other) -{ - QBarDataItem::operator =(other); - m_mapPosition = other.m_mapPosition; - m_label = other.m_label; - - return *this; -} - -/*! - * Sets \a position on the map to this data item. - */ -void QMapDataItem::setMapPosition(const QPointF &position) -{ - m_mapPosition = position; -} - -/*! - * \return position of this data item. - */ -QPointF QMapDataItem::mapPosition() const -{ - return m_mapPosition; -} - -/*! - * Sets \a label to this data item. - */ -void QMapDataItem::setLabel(const QString &label) -{ - m_label = label; -} - -/*! - * \return label of this data item. - */ -QString QMapDataItem::label() const -{ - return m_label; -} - -/*! - * \internal - */ -void QMapDataItem::createExtraData() -{ - if (!d_ptr) - d_ptr = new QMapDataItemPrivate; -} - -QMapDataItemPrivate::QMapDataItemPrivate() - : QBarDataItemPrivate() -{ -} - -QMapDataItemPrivate::~QMapDataItemPrivate() -{ -} - -QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3d/data/qmapdataitem.h b/src/datavis3d/data/qmapdataitem.h deleted file mode 100644 index 240b03dd..00000000 --- a/src/datavis3d/data/qmapdataitem.h +++ /dev/null @@ -1,57 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc -** All rights reserved. -** For any questions to Digia, please use contact form at http://qt.digia.com -** -** This file is part of the QtDataVis3D module. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** contact form at http://qt.digia.com -** -****************************************************************************/ - -#ifndef QMAPDATAITEM_H -#define QMAPDATAITEM_H - -#include <QtDataVis3D/qdatavis3denums.h> -#include <QtDataVis3D/qbardataitem.h> -#include <QPointF> - -QT_DATAVIS3D_BEGIN_NAMESPACE - -class QMapDataItemPrivate; - -class QT_DATAVIS3D_EXPORT QMapDataItem : public QBarDataItem -{ -public: - QMapDataItem(); - QMapDataItem(const QMapDataItem &other); - ~QMapDataItem(); - - QMapDataItem &operator=(const QMapDataItem &other); - - void setMapPosition(const QPointF &position); - QPointF mapPosition() const; - - void setLabel(const QString &label); - QString label() const; - -protected: - virtual void createExtraData(); - - QMapDataItemPrivate *d_ptr; - -private: - QPointF m_mapPosition; - QString m_label; -}; - -QT_DATAVIS3D_END_NAMESPACE - -#endif diff --git a/src/datavis3d/data/qmapdataitem_p.h b/src/datavis3d/data/qmapdataitem_p.h deleted file mode 100644 index 2926e3ef..00000000 --- a/src/datavis3d/data/qmapdataitem_p.h +++ /dev/null @@ -1,52 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc -** All rights reserved. -** For any questions to Digia, please use contact form at http://qt.digia.com -** -** This file is part of the QtDataVis3D module. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** contact form at http://qt.digia.com -** -****************************************************************************/ - -// -// 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 QMAPDATAITEM_P_H -#define QMAPDATAITEM_P_H - -#include "datavis3dglobal_p.h" -#include "qmapdataitem.h" -#include "qbardataitem_p.h" - -QT_DATAVIS3D_BEGIN_NAMESPACE - -class QMapDataItemPrivate : public QBarDataItemPrivate -{ -public: - QMapDataItemPrivate(); - virtual ~QMapDataItemPrivate(); - - // TODO stores other data for map items besides position - -protected: - friend class QMapDataItem; -}; - -QT_DATAVIS3D_END_NAMESPACE - -#endif diff --git a/src/datavis3d/data/qmapdataproxy.cpp b/src/datavis3d/data/qmapdataproxy.cpp deleted file mode 100644 index 1e0db088..00000000 --- a/src/datavis3d/data/qmapdataproxy.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc -** All rights reserved. -** For any questions to Digia, please use contact form at http://qt.digia.com -** -** This file is part of the QtDataVis3D module. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** contact form at http://qt.digia.com -** -****************************************************************************/ - -#include "qmapdataproxy.h" -#include "qmapdataproxy_p.h" - -QT_DATAVIS3D_BEGIN_NAMESPACE - -/*! - * \class QMapDataProxy - * \inmodule QtDataVis3D - * \brief Proxy class for Q3DMaps. - * \since 1.0.0 - * - * QMapDataProxy handles adding, inserting, changing and removing data. - * - * QMapDataProxy takes ownership of all QMapDataArrays and QMapDataItems passed to it. - */ - -/*! - * Constructs QMapDataProxy with the given \a parent. - */ -QMapDataProxy::QMapDataProxy(QObject *parent) : - QAbstractDataProxy(new QMapDataProxyPrivate(this), parent) -{ -} - -/*! - * \internal - */ -QMapDataProxy::QMapDataProxy(QMapDataProxyPrivate *d, QObject *parent) : - QAbstractDataProxy(d, parent) -{ -} - -/*! - * Destroys QMapDataProxy. - */ -QMapDataProxy::~QMapDataProxy() -{ -} - -/*! - * Clears the existing array and takes ownership of the \a newArray. Do not use \a newArray pointer - * to further modify data after QMapDataProxy assumes ownership of it, as such modifications will - * not trigger proper signals. - * Passing null array clears all data. - */ -void QMapDataProxy::resetArray(QMapDataArray *newArray) -{ - if (dptr()->resetArray(newArray)) - emit arrayReset(); -} - -/*! - * \return item count in the array. - */ -int QMapDataProxy::itemCount() const -{ - return dptrc()->m_dataArray.size(); -} - -/*! - * \return pointer to the data array. - */ -const QMapDataArray *QMapDataProxy::array() const -{ - return &dptrc()->m_dataArray; -} - -/*! - * \return pointer to the item at \a index. It is guaranteed to be valid only until next call - * that modifies data. - */ -const QMapDataItem *QMapDataProxy::itemAt(int index) const -{ - return &dptrc()->m_dataArray.at(index); -} - -/*! - * \internal - */ -QMapDataProxyPrivate *QMapDataProxy::dptr() -{ - return static_cast<QMapDataProxyPrivate *>(d_ptr.data()); -} - -/*! - * \internal - */ -const QMapDataProxyPrivate *QMapDataProxy::dptrc() const -{ - return static_cast<const QMapDataProxyPrivate *>(d_ptr.data()); -} - -/*! - * \fn void QMapDataProxy::arrayReset() - * - * Emitted when data array is reset. - */ - -/*! - * \fn void QMapDataProxy::itemsAdded(int startIndex, int count) - * - * Emitted when items have been added. Provides \a startIndex and \a count of items added. - */ - -/*! - * \fn void QMapDataProxy::itemsChanged(int startIndex, int count) - * - * Emitted when items have changed. Provides \a startIndex and \a count of changed items. - */ - -/*! - * \fn void QMapDataProxy::itemsRemoved(int startIndex, int count) - * - * 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. - */ - -/*! - * \fn void QMapDataProxy::itemsInserted(int startIndex, int count) - * - * Emitted when items have been inserted. Provides \a startIndex and \a count of inserted items. - */ - -// QBarDataProxyPrivate - -QMapDataProxyPrivate::QMapDataProxyPrivate(QMapDataProxy *q) - : QAbstractDataProxyPrivate(q, QAbstractDataProxy::DataTypeMap) -{ -} - -QMapDataProxyPrivate::~QMapDataProxyPrivate() -{ - m_dataArray.clear(); -} - -bool QMapDataProxyPrivate::resetArray(QMapDataArray *newArray) -{ - if (!m_dataArray.size() && (!newArray || !newArray->size())) - return false; - - m_dataArray.clear(); - - if (newArray) { - m_dataArray = *newArray; - delete newArray; - } - - return true; -} - -QPair<GLfloat, GLfloat> QMapDataProxyPrivate::limitValues() -{ - QPair<GLfloat, GLfloat> limits = qMakePair(0.0f, 0.0f); - for (int i = 0; i < m_dataArray.size(); i++) { - const QMapDataItem &item = m_dataArray.at(i); - qreal itemValue = item.value(); - if (limits.second < itemValue) - limits.second = itemValue; - if (limits.first > itemValue) - limits.first = itemValue; - } - return limits; -} - -QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3d/data/qmapdataproxy.h b/src/datavis3d/data/qmapdataproxy.h deleted file mode 100644 index f6d281f9..00000000 --- a/src/datavis3d/data/qmapdataproxy.h +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc -** All rights reserved. -** For any questions to Digia, please use contact form at http://qt.digia.com -** -** This file is part of the QtDataVis3D module. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** contact form at http://qt.digia.com -** -****************************************************************************/ - -#ifndef QMAPDATAPROXY_H -#define QMAPDATAPROXY_H - -#include <QtDataVis3D/qabstractdataproxy.h> -#include <QtDataVis3D/qmapdataitem.h> - -QT_DATAVIS3D_BEGIN_NAMESPACE - -typedef QVector<QMapDataItem> QMapDataArray; - -class QMapDataProxyPrivate; - -class QT_DATAVIS3D_EXPORT QMapDataProxy : public QAbstractDataProxy -{ - Q_OBJECT - -public: - explicit QMapDataProxy(QObject *parent = 0); - virtual ~QMapDataProxy(); - - // TODO: Replace first part of class description in docs with this once all TODOs are done: - /* - * QMapDataProxy handles adding, inserting, changing and removing data. - * QMapDataProxy is optimized to use cases where the only defining characteristics of an individual - * map item are its value and position. Modifying other data such as color or mesh of individual bar - * requires allocating additional data object for the bar. - */ - - int itemCount() const; - const QMapDataArray *array() const; - const QMapDataItem *itemAt(int index) const; // Index needs to exist or this crashes - - void resetArray(QMapDataArray *newArray); - - // TODO void setItem(int index, QMapDataItem *item); - // TODO void setItems(int index, QMapDataArray *items); - - // TODO int addItem(QMapDataItem *item); // returns the index of added item - // TODO int addItems(QMapDataArray *items); // returns the index of added item - - // TODO void insertItem(int index, QMapDataItem *item); - // TODO void insertItems(int index, QMapDataArray *items); - - // TODO void removeItems(int index, int removeCount); - -signals: - void arrayReset(); - void itemsAdded(int startIndex, int count); - void itemsChanged(int startIndex, int count); - void itemsRemoved(int startIndex, int count); - void itemsInserted(int startIndex, int count); - -protected: - explicit QMapDataProxy(QMapDataProxyPrivate *d, QObject *parent = 0); - QMapDataProxyPrivate *dptr(); - const QMapDataProxyPrivate *dptrc() const; - -private: - Q_DISABLE_COPY(QMapDataProxy) - - friend class Maps3DController; -}; - -QT_DATAVIS3D_END_NAMESPACE - -#endif diff --git a/src/datavis3d/data/qmapdataproxy_p.h b/src/datavis3d/data/qmapdataproxy_p.h deleted file mode 100644 index bf3d1d2c..00000000 --- a/src/datavis3d/data/qmapdataproxy_p.h +++ /dev/null @@ -1,58 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc -** All rights reserved. -** For any questions to Digia, please use contact form at http://qt.digia.com -** -** This file is part of the QtDataVis3D module. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** contact form at http://qt.digia.com -** -****************************************************************************/ - -// -// 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 QMAPDATAPROXY_P_H -#define QMAPDATAPROXY_P_H - -#include "qmapdataproxy.h" -#include "qabstractdataproxy_p.h" -#include "qmapdataitem.h" - -QT_DATAVIS3D_BEGIN_NAMESPACE - -class QMapDataProxyPrivate : public QAbstractDataProxyPrivate -{ - Q_OBJECT -public: - QMapDataProxyPrivate(QMapDataProxy *q); - virtual ~QMapDataProxyPrivate(); - - bool resetArray(QMapDataArray *newArray); - - QPair<GLfloat, GLfloat> limitValues(); - -private: - QMapDataArray m_dataArray; - -private: - friend class QMapDataProxy; -}; - -QT_DATAVIS3D_END_NAMESPACE - -#endif // QBARDATAPROXY_P_H diff --git a/src/datavis3d/data/scatterrenderitem_p.h b/src/datavis3d/data/scatterrenderitem_p.h index 6fade03e..cf63ae50 100644 --- a/src/datavis3d/data/scatterrenderitem_p.h +++ b/src/datavis3d/data/scatterrenderitem_p.h @@ -49,7 +49,6 @@ public: //inline qreal size() const { return m_size; } // TODO should be in abstract, but currently there is no abstract renderer - // TODO change when maps refactored inline void setRenderer(Scatter3DRenderer *renderer) { m_renderer = renderer; } protected: diff --git a/src/datavis3d/doc/src/qtdatavis3d-index.qdoc b/src/datavis3d/doc/src/qtdatavis3d-index.qdoc index a199bbe5..b45e7cb6 100644 --- a/src/datavis3d/doc/src/qtdatavis3d-index.qdoc +++ b/src/datavis3d/doc/src/qtdatavis3d-index.qdoc @@ -50,9 +50,7 @@ \list \li \l{Barchart Example} - \li \l{Mapdata Example} \li \l{Qt Quick 2 Barchart Example} - \li \l{Qt Quick 2 Maps Example} \li \l{Qt Quick 2 Scatter Example} \li \l{Rainfall Example} \li \l{Scatter Chart Example} diff --git a/src/datavis3d/engine/engine.pri b/src/datavis3d/engine/engine.pri index f615c5a5..ddc5abd1 100644 --- a/src/datavis3d/engine/engine.pri +++ b/src/datavis3d/engine/engine.pri @@ -2,14 +2,10 @@ HEADERS += $$PWD/q3dwindow_p.h \ $$PWD/q3dwindow.h \ $$PWD/q3dbars.h \ $$PWD/q3dbars_p.h \ - $$PWD/q3dmaps.h \ - $$PWD/q3dmaps_p.h \ $$PWD/theme_p.h \ $$PWD/drawer_p.h \ $$PWD/bars3dcontroller_p.h \ $$PWD/bars3drenderer_p.h \ - $$PWD/maps3dcontroller_p.h \ - $$PWD/maps3drenderer_p.h \ $$PWD/q3dsurface.h \ $$PWD/q3dsurface_p.h \ $$PWD/surface3dcontroller_p.h \ @@ -25,13 +21,10 @@ HEADERS += $$PWD/q3dwindow_p.h \ SOURCES += $$PWD/q3dwindow.cpp \ $$PWD/q3dbars.cpp \ - $$PWD/q3dmaps.cpp \ $$PWD/theme.cpp \ $$PWD/drawer.cpp \ $$PWD/bars3dcontroller.cpp \ $$PWD/bars3drenderer.cpp \ - $$PWD/maps3dcontroller.cpp \ - $$PWD/maps3drenderer.cpp \ $$PWD/q3dsurface.cpp \ $$PWD/surface3drenderer.cpp \ $$PWD/surface3dcontroller.cpp \ diff --git a/src/datavis3d/engine/maps3dcontroller.cpp b/src/datavis3d/engine/maps3dcontroller.cpp deleted file mode 100644 index 21b46eda..00000000 --- a/src/datavis3d/engine/maps3dcontroller.cpp +++ /dev/null @@ -1,1735 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc -** All rights reserved. -** For any questions to Digia, please use contact form at http://qt.digia.com -** -** This file is part of the QtDataVis3D module. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** contact form at http://qt.digia.com -** -****************************************************************************/ - -#include "maps3dcontroller_p.h" -#include "maps3drenderer_p.h" -#include "camerahelper_p.h" -#include "shaderhelper_p.h" -#include "objecthelper_p.h" -#include "texturehelper_p.h" -#include "theme_p.h" -#include "utils_p.h" -#include "drawer_p.h" -#include "maprenderitem_p.h" -#include "qmapdataproxy_p.h" - -#include <QOpenGLFunctions> -#include <QMatrix4x4> -#include <QMouseEvent> -#include <qmath.h> - -#include <QDebug> - -//#define DISPLAY_RENDER_SPEED - -// Commenting this draws the shadow map with perspective projection. Otherwise it's drawn in -// orthographic projection. -//#define USE_WIDER_SHADOWS - -// You can verify that depth buffer drawing works correctly by uncommenting this. -// You should see the scene from where the light is -//#define SHOW_DEPTH_TEXTURE_SCENE - -#ifdef DISPLAY_RENDER_SPEED -#include <QTime> -#endif - -QT_DATAVIS3D_BEGIN_NAMESPACE - -const GLfloat gridLineWidth = 0.005f; -GLfloat distanceMod = 0.0f; -static QVector3D skipColor = QVector3D(255, 255, 255); // Selection texture's background color - -Maps3DController::Maps3DController(const QRect &rect) - : m_camera(new CameraHelper()), - m_barShader(0), - m_depthShader(0), - m_selectionShader(0), - m_backgroundShader(0), - m_labelShader(0), - m_barObj(0), - m_backgroundObj(0), - m_gridLineObj(0), - m_labelObj(0), - m_objFile(QStringLiteral(":/defaultMeshes/bar")), - m_mousePressed(MouseNone), - m_mousePos(QPoint(0, 0)), - m_zoomLevel(100), - m_autoScaleAdjustment(1.0f), - m_horizontalRotation(0.0f), - m_verticalRotation(45.0f), - m_barThickness(QVector3D(1.0f, 1.0f, 1.0f)), - m_heightNormalizer(0.0f), - m_yAdjustment(0.0f), - m_scaleFactor(1.0f), - m_theme(new Theme()), - m_isInitialized(false), - m_selectionMode(QDataVis::ModeItem), - m_selectedBar(0), - m_previouslySelectedBar(0), - m_axisLabelX(QStringLiteral("X")), - m_axisLabelZ(QStringLiteral("Z")), - m_axisLabelY(QStringLiteral("Y")), - m_sceneViewPort(rect.x(), rect.y(), rect.width(), rect.height()), - m_zoomViewPort(rect.x(), rect.y(), rect.width(), rect.height()), - m_zoomActivated(false), - m_textureHelper(new TextureHelper()), - m_labelTransparency(QDataVis::TransparencyFromTheme), - m_font(QFont(QStringLiteral("Arial"))), - m_drawer(new Drawer(*m_theme, m_font, m_labelTransparency)), - m_areaSize(QSizeF(1.0, 1.0)), - m_bgrTexture(0), - m_depthTexture(0), - m_selectionTexture(0), - m_depthFrameBuffer(0), - m_selectionFrameBuffer(0), - m_selectionDepthBuffer(0), - m_updateLabels(true), - m_adjustDirection(Q3DMaps::AdjustHeight), - m_shadowQuality(QDataVis::ShadowLow), - m_shadowQualityToShader(33.3f), - m_bgrHasAlpha(false), - m_boundingRect(rect.x(), rect.y(), rect.width(), rect.height()), - m_data(0), - m_valuesDirty(false) -{ - //m_data->setDrawer(m_drawer); - //QObject::connect(m_drawer, &Drawer::drawerChanged, this, &Maps3DController::updateTextures); -} - -Maps3DController::~Maps3DController() -{ - m_textureHelper->glDeleteFramebuffers(1, &m_depthFrameBuffer); - m_textureHelper->glDeleteFramebuffers(1, &m_selectionFrameBuffer); - m_textureHelper->glDeleteRenderbuffers(1, &m_selectionDepthBuffer); - m_textureHelper->deleteTexture(&m_selectionTexture); - m_textureHelper->deleteTexture(&m_bgrTexture); - delete m_barShader; - delete m_selectionShader; - delete m_backgroundShader; - delete m_barObj; - delete m_backgroundObj; - delete m_gridLineObj; - delete m_textureHelper; - delete m_drawer; - delete m_camera; -} - -void Maps3DController::initializeOpenGL() -{ - // Initialization is called multiple times when Qt Quick components are used - if (m_isInitialized) - return; - - m_renderer = new Maps3DRenderer(this); - initializeOpenGLFunctions(); - - m_textureHelper = new TextureHelper(); - m_drawer->initializeOpenGL(); - - // Initialize shaders -#if !defined(QT_OPENGL_ES_2) - if (m_shadowQuality > QDataVis::ShadowNone) { - if (!m_theme->m_uniformColor) { - initShaders(QStringLiteral(":/shaders/vertexShadow"), - QStringLiteral(":/shaders/fragmentShadowNoTexColorOnY")); - } else { - initShaders(QStringLiteral(":/shaders/vertexShadow"), - QStringLiteral(":/shaders/fragmentShadowNoTex")); - } - initBackgroundShaders(QStringLiteral(":/shaders/vertexShadow"), - QStringLiteral(":/shaders/fragmentShadow")); - } else { - if (!m_theme->m_uniformColor) { - initShaders(QStringLiteral(":/shaders/vertex"), - QStringLiteral(":/shaders/fragmentColorOnY")); - } else { - initShaders(QStringLiteral(":/shaders/vertex"), - QStringLiteral(":/shaders/fragment")); - } - initBackgroundShaders(QStringLiteral(":/shaders/vertexTexture"), - QStringLiteral(":/shaders/fragmentTexture")); - } -#else - if (!m_theme->m_uniformColor) { - initShaders(QStringLiteral(":/shaders/vertexES2"), - QStringLiteral(":/shaders/fragmentColorOnYES2")); - } else { - initShaders(QStringLiteral(":/shaders/vertexES2"), - QStringLiteral(":/shaders/fragmentES2")); - } - initBackgroundShaders(QStringLiteral(":/shaders/vertexTexture"), // Same vertex shader ok for ES2 - QStringLiteral(":/shaders/fragmentTextureES2")); -#endif - initLabelShaders(QStringLiteral(":/shaders/vertexLabel"), - QStringLiteral(":/shaders/fragmentLabel")); - -#if !defined(QT_OPENGL_ES_2) - // Init depth shader (for shadows). Init in any case, easier to handle shadow activation if done via api. - initDepthShader(); -#endif - - // Init selection shader - initSelectionShader(); - - // Load default mesh - loadBarMesh(); - - // Load grid line mesh - loadGridLineMesh(); - - // Load label mesh - loadLabelMesh(); - - // Set OpenGL features - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_LESS); - glEnable(GL_CULL_FACE); - glCullFace(GL_BACK); - -#if !defined(QT_OPENGL_ES_2) - glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); - glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); - glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); -#endif - - // Set initial camera position - // X must be 0 for rotation to work - we can use "setCameraRotation" for setting it later - m_camera->setDefaultCameraOrientation(QVector3D(0.0f, 0.0f, 1.0f + 2.9f * zComp), - QVector3D(0.0f, 0.0f, zComp), - QVector3D(0.0f, 1.0f, 0.0f)); - - // Adjust to default rotation - setCameraPosition(m_horizontalRotation, m_verticalRotation, m_zoomLevel); - - // Set view port - glViewport(0, 0, width(), height()); - - // Set initialized -flag - m_isInitialized = true; - - // Resize in case we've missed resize events - // Resize calls initSelectionBuffer and initDepthBuffer, so they don't need to be called here - resizeNotify(); - - // Load background mesh (we need to be initialized first) - loadBackgroundMesh(); - - // Update default light position -#ifndef USE_WIDER_SHADOWS - distanceMod = 5.0f; -#endif -} - -void Maps3DController::synchDataToRenderer() -{ - // TODO: Implement! -} - - -/*! - * \internal - */ -void Maps3DController::render(const GLuint defaultFboHandle) -{ - if (!m_isInitialized) - return; - -#ifdef DISPLAY_RENDER_SPEED - // For speed computation - static bool firstRender = true; - static QTime lastTime; - static GLint nbFrames = 0; - if (firstRender) { - lastTime.start(); - firstRender = false; - } - - // Measure speed (as milliseconds per frame) - nbFrames++; - if (lastTime.elapsed() >= 1000) { // print only if last measurement was more than 1s ago - qDebug() << qreal(lastTime.elapsed()) / qreal(nbFrames) << "ms/frame (=" << qreal(nbFrames) << "fps)"; - nbFrames = 0; - lastTime.restart(); - } -#endif - - // Update cached values - if (m_valuesDirty) { - const QMapDataArray &dataArray = *m_data->array(); - int dataSize = dataArray.size(); - m_renderItemArray.resize(dataSize); - for (int i = 0; i < dataSize ; i++) { - qreal value = dataArray.at(i).value(); - m_renderItemArray[i].setValue(value); - m_renderItemArray[i].setMapPosition(dataArray.at(i).mapPosition()); - m_renderItemArray[i].setHeight(value / m_heightNormalizer); - m_renderItemArray[i].setItemLabel(dataArray.at(i).label()); - calculateTranslation(m_renderItemArray[i]); - m_renderItemArray[i].setRenderer(this); - } - m_valuesDirty = false; - } - - if (defaultFboHandle) { - glDepthMask(true); - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_LESS); - glEnable(GL_CULL_FACE); - glCullFace(GL_BACK); - } - - // Draw scene - drawScene(defaultFboHandle); -} - -/*! - * \internal - */ -void Maps3DController::drawScene(const GLuint defaultFboHandle) -{ - // Set clear color - QVector3D clearColor = Utils::vectorFromColor(m_theme->m_windowColor); - glClearColor(clearColor.x(), clearColor.y(), clearColor.z(), 1.0f); - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - static QVector3D selection = skipColor; - - // Specify viewport - glViewport(m_sceneViewPort.x(), m_sceneViewPort.y(), - m_sceneViewPort.width(), m_sceneViewPort.height()); - - // Set up projection matrix - QMatrix4x4 projectionMatrix; - projectionMatrix.perspective(45.0f, (GLfloat)m_sceneViewPort.width() - / (GLfloat)m_sceneViewPort.height(), 0.1f, 100.0f); - - // Calculate view matrix - QMatrix4x4 viewMatrix = m_camera->calculateViewMatrix(m_mousePos, - m_zoomLevel * m_autoScaleAdjustment, - m_sceneViewPort.width(), - m_sceneViewPort.height()); - - // Get light position (rotate light with camera, a bit above it (as set in defaultLightPos)) - QVector3D lightPos = m_camera->calculateLightPosition(defaultLightPos, 0.0f, distanceMod); - - // Map adjustment direction to model matrix scaling - GLfloat heightMultiplier = 0.0f; - GLfloat widthMultiplier = 0.0f; - GLfloat depthMultiplier = 0.0f; - GLfloat heightScaler = 0.0f; - GLfloat widthScaler = 0.0f; - GLfloat depthScaler = 0.0f; - switch (m_adjustDirection) { - case Q3DMaps::AdjustHeight: - widthMultiplier = 0.0f; - heightMultiplier = 1.0f; - depthMultiplier = 0.0f; - widthScaler = m_barThickness.x() / m_scaleFactor; - heightScaler = 0.0f; - depthScaler = m_barThickness.z() / m_scaleFactor; - break; - case Q3DMaps::AdjustWidth: - widthMultiplier = 1.0f; - heightMultiplier = 0.0f; - depthMultiplier = 0.0f; - widthScaler = 0.0f; - heightScaler = m_barThickness.y() / m_scaleFactor; - depthScaler = m_barThickness.z() / m_scaleFactor; - break; - case Q3DMaps::AdjustDepth: - widthMultiplier = 0.0f; - heightMultiplier = 0.0f; - depthMultiplier = 1.0f; - widthScaler = m_barThickness.x() / m_scaleFactor; - heightScaler = m_barThickness.y() / m_scaleFactor; - depthScaler = 0.0f; - break; - case Q3DMaps::AdjustRadius: - widthMultiplier = 1.0f; - heightMultiplier = 0.0f; - depthMultiplier = 1.0f; - widthScaler = 0.0f; - heightScaler = m_barThickness.y() / m_scaleFactor; - depthScaler = 0.0f; - break; - case Q3DMaps::AdjustAll: - widthMultiplier = 1.0f; - heightMultiplier = 1.0f; - depthMultiplier = 1.0f; - widthScaler = 0.0f; - heightScaler = 0.0f; - depthScaler = 0.0f; - break; - } - - // Introduce regardless of shadow quality to simplify logic - QMatrix4x4 depthViewMatrix; - QMatrix4x4 depthProjectionMatrix; - -#if !defined(QT_OPENGL_ES_2) - if (m_shadowQuality > QDataVis::ShadowNone) { - // Render scene into a depth texture for using with shadow mapping - // Bind depth shader - m_depthShader->bind(); - - // Set viewport for depth map rendering. Must match texture size. Larger values give smoother shadows. - glViewport(m_sceneViewPort.x(), m_sceneViewPort.y(), - m_sceneViewPort.width() * m_shadowQuality, - m_sceneViewPort.height() * m_shadowQuality); - - // Enable drawing to framebuffer - glBindFramebuffer(GL_FRAMEBUFFER, m_depthFrameBuffer); - glClear(GL_DEPTH_BUFFER_BIT); - - // Set front face culling to reduce self-shadowing issues - glCullFace(GL_FRONT); - - // Get the depth view matrix - // It may be possible to hack lightPos here if we want to make some tweaks to shadow - QVector3D depthLightPos = m_camera->calculateLightPosition( - defaultLightPos, 0.0f, (distanceMod + 1.5f) / m_autoScaleAdjustment); - depthViewMatrix.lookAt(depthLightPos, QVector3D(0.0f, -m_yAdjustment, zComp), - QVector3D(0.0f, 1.0f, 0.0f)); - // TODO: Why does depthViewMatrix.column(3).y() goes to zero when we're directly above? That causes the scene to be not drawn from above -> must be fixed - //qDebug() << lightPos << depthViewMatrix << depthViewMatrix.column(3); - // Set the depth projection matrix -#ifndef USE_WIDER_SHADOWS - // Use this for perspective shadows - depthProjectionMatrix.perspective(15.0f, (GLfloat)m_sceneViewPort.width() - / (GLfloat)m_sceneViewPort.height(), 3.0f, 200.0f); -#else - // Use these for orthographic shadows - //qDebug() << m_areaSize.width() / m_scaleFactor << m_yAdjustment; - GLfloat testAspectRatio = (GLfloat)m_sceneViewPort.width() / (GLfloat)m_sceneViewPort.height(); - depthProjectionMatrix.ortho(-(2.0f * m_areaSize.width()) / m_scaleFactor, - (2.0f * m_areaSize.width()) / m_scaleFactor, - -m_yAdjustment * 4.0f * testAspectRatio, - m_yAdjustment * 4.0f * testAspectRatio, - 0.0f, 100.0f); -#endif -#if 0 - // Draw background to depth buffer (You don't want to do this, except maybe for debugging purposes) - if (m_backgroundObj) { - QMatrix4x4 modelMatrix; - QMatrix4x4 MVPMatrix; - - modelMatrix.translate(0.0f, -m_yAdjustment, zComp); - modelMatrix.scale(QVector3D(m_areaSize.width() / m_scaleFactor, - 1.0f, - m_areaSize.height() / m_scaleFactor)); - modelMatrix.rotate(-90.0f, 1.0f, 0.0f, 0.0f); - - MVPMatrix = depthProjectionMatrix * depthViewMatrix * modelMatrix; - - m_depthShader->setUniformValue(m_depthShader->MVP(), MVPMatrix); - - // 1st attribute buffer : vertices - glEnableVertexAttribArray(m_depthShader->posAtt()); - glBindBuffer(GL_ARRAY_BUFFER, m_backgroundObj->vertexBuf()); - glVertexAttribPointer(m_depthShader->posAtt(), 3, GL_FLOAT, GL_FALSE, 0, (void *)0); - - // Index buffer - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_backgroundObj->elementBuf()); - - // Draw the triangles - glDrawElements(GL_TRIANGLES, m_backgroundObj->indexCount(), GL_UNSIGNED_SHORT, - (void *)0); - - // Free buffers - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - glBindBuffer(GL_ARRAY_BUFFER, 0); - - glDisableVertexAttribArray(m_depthShader->posAtt()); - } -#endif - // Draw bars to depth buffer - for (int bar = 0; bar < m_renderItemArray.size(); bar++) { - const MapRenderItem &item = m_renderItemArray.at(bar); - if (!item.value()) - continue; - - QMatrix4x4 modelMatrix; - QMatrix4x4 MVPMatrix; - - modelMatrix.translate(item.translation().x(), - heightMultiplier * item.height() + heightScaler - m_yAdjustment, - item.translation().z()); - modelMatrix.scale(QVector3D(widthMultiplier * item.height() + widthScaler, - heightMultiplier * item.height() + heightScaler, - depthMultiplier * item.height() + depthScaler)); - - MVPMatrix = depthProjectionMatrix * depthViewMatrix * modelMatrix; - - m_depthShader->setUniformValue(m_depthShader->MVP(), MVPMatrix); - - // 1st attribute buffer : vertices - glEnableVertexAttribArray(m_depthShader->posAtt()); - glBindBuffer(GL_ARRAY_BUFFER, m_barObj->vertexBuf()); - glVertexAttribPointer(m_depthShader->posAtt(), 3, GL_FLOAT, GL_FALSE, 0, (void *)0); - - // Index buffer - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_barObj->elementBuf()); - - // Draw the triangles - glDrawElements(GL_TRIANGLES, m_barObj->indexCount(), GL_UNSIGNED_SHORT, (void *)0); - - // Free buffers - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - glBindBuffer(GL_ARRAY_BUFFER, 0); - - glDisableVertexAttribArray(m_depthShader->posAtt()); - } - - // Disable drawing to framebuffer (= enable drawing to screen) - glBindFramebuffer(GL_FRAMEBUFFER, defaultFboHandle); - - // Reset culling to normal - glCullFace(GL_BACK); - - // Release depth shader - m_depthShader->release(); - - // Revert to original viewport - glViewport(m_sceneViewPort.x(), m_sceneViewPort.y(), - m_sceneViewPort.width(), m_sceneViewPort.height()); - -#if 0 // Use this if you want to see what is being drawn to the framebuffer - // You'll also have to comment out GL_COMPARE_R_TO_TEXTURE -line in texturehelper (if using it) - m_labelShader->bind(); - glEnable(GL_TEXTURE_2D); - QMatrix4x4 modelMatrix; - QMatrix4x4 viewmatrix; - viewmatrix.lookAt(QVector3D(0.0f, 0.0f, 2.5f + zComp), - QVector3D(0.0f, 0.0f, zComp), - QVector3D(0.0f, 1.0f, 0.0f)); - modelMatrix.translate(0.0, 0.0, zComp); - QMatrix4x4 MVPMatrix = projectionMatrix * viewmatrix * modelMatrix; - m_labelShader->setUniformValue(m_labelShader->MVP(), MVPMatrix); - m_drawer->drawObject(m_labelShader, m_labelObj, - m_depthTexture); - glDisable(GL_TEXTURE_2D); - m_labelShader->release(); -#endif - } -#endif - -#if 1 - // Skip selection mode drawing if we're zoomed or have no selection mode - if (!m_zoomActivated && m_selectionMode > QDataVis::ModeNone) { - // Bind selection shader - m_selectionShader->bind(); - - // Draw bars to selection buffer - glBindFramebuffer(GL_FRAMEBUFFER, m_selectionFrameBuffer); - glEnable(GL_DEPTH_TEST); // Needed, otherwise the depth render buffer is not used - glClearColor(skipColor.x() / 255, skipColor.y() / 255, skipColor.z() / 255, 1.0f); // Set clear color to white (= skipColor) - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Needed for clearing the frame buffer - glDisable(GL_DITHER); // disable dithering, it may affect colors if enabled - GLint barIdxRed = 0; - GLint barIdxGreen = 0; - GLint barIdxBlue = 0; - for (int bar = 0; bar < m_renderItemArray.size(); bar++, barIdxRed++) { - const MapRenderItem &item = m_renderItemArray.at(bar); - if (!item.value()) - continue; - - QMatrix4x4 modelMatrix; - QMatrix4x4 MVPMatrix; - - modelMatrix.translate(item.translation().x(), - heightMultiplier * item.height() + heightScaler - m_yAdjustment, - item.translation().z()); - modelMatrix.scale(QVector3D(widthMultiplier * item.height() + widthScaler, - heightMultiplier * item.height() + heightScaler, - depthMultiplier * item.height() + depthScaler)); - - MVPMatrix = projectionMatrix * viewMatrix * modelMatrix; - - if (barIdxRed > 0 && barIdxRed % 256 == 0) { - barIdxRed = 0; - barIdxGreen++; - } - if (barIdxGreen > 0 && barIdxGreen % 256 == 0) { - barIdxGreen = 0; - barIdxBlue++; - } - if (barIdxBlue > 255) - qFatal("Too many objects"); - - QVector3D barColor = QVector3D((GLfloat)barIdxRed / 255.0f, - (GLfloat)barIdxGreen / 255.0f, - (GLfloat)barIdxBlue / 255.0f); - - m_selectionShader->setUniformValue(m_selectionShader->MVP(), MVPMatrix); - m_selectionShader->setUniformValue(m_selectionShader->color(), barColor); - - // 1st attribute buffer : vertices - glEnableVertexAttribArray(m_selectionShader->posAtt()); - glBindBuffer(GL_ARRAY_BUFFER, m_barObj->vertexBuf()); - glVertexAttribPointer(m_selectionShader->posAtt(), 3, GL_FLOAT, GL_FALSE, 0, (void *)0); - - // Index buffer - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_barObj->elementBuf()); - - // Draw the triangles - glDrawElements(GL_TRIANGLES, m_barObj->indexCount(), GL_UNSIGNED_SHORT, (void *)0); - - // Free buffers - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - glBindBuffer(GL_ARRAY_BUFFER, 0); - - glDisableVertexAttribArray(m_selectionShader->posAtt()); - } - glEnable(GL_DITHER); - - // Read color under cursor - if (Maps3DController::MouseOnScene == m_mousePressed) - selection = Utils::getSelection(m_mousePos, height()); - - glBindFramebuffer(GL_FRAMEBUFFER, defaultFboHandle); - - // Release selection shader - m_selectionShader->release(); - -#if 0 // Use this if you want to see what is being drawn to the framebuffer - m_labelShader->bind(); - glDisable(GL_DEPTH_TEST); - glEnable(GL_TEXTURE_2D); - QMatrix4x4 modelMatrix; - QMatrix4x4 viewmatrix; - viewmatrix.lookAt(QVector3D(0.0f, 0.0f, 2.0f + zComp), - QVector3D(0.0f, 0.0f, zComp), - QVector3D(0.0f, 1.0f, 0.0f)); - modelMatrix.translate(0.0, 0.0, zComp); - QMatrix4x4 MVPMatrix = projectionMatrix * viewmatrix * modelMatrix; - m_labelShader->setUniformValue(m_labelShader->MVP(), MVPMatrix); - m_drawer->drawObject(m_labelShader, m_labelObj, - m_selectionTexture); - glDisable(GL_TEXTURE_2D); - m_labelShader->release(); -#endif - } -#if 1 - // Bind bar shader - m_barShader->bind(); - - // Enable texture - glEnable(GL_TEXTURE_2D); - - // Draw bars - // TODO: Handle zoom by camera transformations - //if (!m_zoomActivated) - - bool barSelectionFound = false; - for (int bar = 0; bar < m_renderItemArray.size(); bar++) { - MapRenderItem &item = m_renderItemArray[bar]; - if (!item.value()) - continue; - - QMatrix4x4 modelMatrix; - QMatrix4x4 MVPMatrix; - QMatrix4x4 depthMVPMatrix; - QMatrix4x4 itModelMatrix; - - modelMatrix.translate(item.translation().x(), - heightMultiplier * item.height() + heightScaler - m_yAdjustment, - item.translation().z()); - modelMatrix.scale(QVector3D(widthMultiplier * item.height() + widthScaler, - heightMultiplier * item.height() + heightScaler, - depthMultiplier * item.height() + depthScaler)); - itModelMatrix.scale(QVector3D(widthMultiplier * item.height() + widthScaler, - heightMultiplier * item.height() + heightScaler, - depthMultiplier * item.height() + depthScaler)); - -#ifdef SHOW_DEPTH_TEXTURE_SCENE - MVPMatrix = depthProjectionMatrix * depthViewMatrix * modelMatrix; -#else - MVPMatrix = projectionMatrix * viewMatrix * modelMatrix; -#endif - depthMVPMatrix = depthProjectionMatrix * depthViewMatrix * modelMatrix; - - QVector3D baseColor = Utils::vectorFromColor(m_theme->m_baseColor); - QVector3D heightColor = Utils::vectorFromColor(m_theme->m_heightColor) * item.height(); - - QVector3D barColor = baseColor + heightColor; - - GLfloat lightStrength = m_theme->m_lightStrength; - if (m_selectionMode > QDataVis::ModeNone) { - Maps3DController::SelectionType selectionType = isSelected(bar, selection); - switch (selectionType) { - case Maps3DController::SelectionBar: { - barColor = Utils::vectorFromColor(m_theme->m_highlightBarColor); - lightStrength = m_theme->m_highlightLightStrength; - // Insert data to QDataItem. We have no ownership, don't delete the previous one - if (!m_zoomActivated) { - m_selectedBar = &item; - barSelectionFound = true; - } - break; - } - case Maps3DController::SelectionNone: { - // Current bar is not selected, nor on a row or column - // do nothing - break; - } - default: { - // Unsupported selection mode - // do nothing - break; - } - } - } - - if (item.height() != 0) { - // Set shader bindings - m_barShader->setUniformValue(m_barShader->lightP(), lightPos); - m_barShader->setUniformValue(m_barShader->view(), viewMatrix); - m_barShader->setUniformValue(m_barShader->model(), modelMatrix); - m_barShader->setUniformValue(m_barShader->nModel(), - itModelMatrix.inverted().transposed()); - m_barShader->setUniformValue(m_barShader->MVP(), MVPMatrix); - m_barShader->setUniformValue(m_barShader->color(), barColor); - m_barShader->setUniformValue(m_barShader->ambientS(), m_theme->m_ambientStrength); - -#if !defined(QT_OPENGL_ES_2) - if (m_shadowQuality > QDataVis::ShadowNone) { - // Set shadow shader bindings - m_barShader->setUniformValue(m_barShader->shadowQ(), m_shadowQualityToShader); - m_barShader->setUniformValue(m_barShader->depth(), depthMVPMatrix); - m_barShader->setUniformValue(m_barShader->lightS(), lightStrength / 10.0f); - - // Draw the object - m_drawer->drawObject(m_barShader, m_barObj, 0, m_depthTexture); - } else -#endif - { - // Set shadowless shader bindings - m_barShader->setUniformValue(m_barShader->lightS(), lightStrength); - - // Draw the object - m_drawer->drawObject(m_barShader, m_barObj); - } - } - } - - // Release bar shader - m_barShader->release(); -#if 1 - // Bind background shader - m_backgroundShader->bind(); - if (m_bgrHasAlpha) { - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } - - // Draw background - if (m_backgroundObj) { - QMatrix4x4 modelMatrix; - QMatrix4x4 MVPMatrix; - QMatrix4x4 depthMVPMatrix; - QMatrix4x4 itModelMatrix; - - modelMatrix.translate(0.0f, -m_yAdjustment, zComp); - modelMatrix.scale(QVector3D(m_areaSize.width() / m_scaleFactor, - 1.0f, - m_areaSize.height() / m_scaleFactor)); - modelMatrix.rotate(-90.0f, 1.0f, 0.0f, 0.0f); - itModelMatrix.scale(QVector3D(m_areaSize.width() / m_scaleFactor, - 1.0f, - m_areaSize.height() / m_scaleFactor)); - -#ifdef SHOW_DEPTH_TEXTURE_SCENE - MVPMatrix = depthProjectionMatrix * depthViewMatrix * modelMatrix; -#else - MVPMatrix = projectionMatrix * viewMatrix * modelMatrix; -#endif - depthMVPMatrix = depthProjectionMatrix * depthViewMatrix * modelMatrix; - - // Set shader bindings - m_backgroundShader->setUniformValue(m_backgroundShader->lightP(), lightPos); - m_backgroundShader->setUniformValue(m_backgroundShader->view(), viewMatrix); - m_backgroundShader->setUniformValue(m_backgroundShader->model(), modelMatrix); - m_backgroundShader->setUniformValue(m_backgroundShader->nModel(), - itModelMatrix.inverted().transposed()); - m_backgroundShader->setUniformValue(m_backgroundShader->MVP(), MVPMatrix); - m_backgroundShader->setUniformValue(m_backgroundShader->ambientS(), - m_theme->m_ambientStrength * 3.0f); - -#if !defined(QT_OPENGL_ES_2) - if (m_shadowQuality > QDataVis::ShadowNone) { - // Set shadow shader bindings - m_backgroundShader->setUniformValue(m_backgroundShader->shadowQ(), - m_shadowQualityToShader); - m_backgroundShader->setUniformValue(m_backgroundShader->depth(), - depthMVPMatrix); - m_backgroundShader->setUniformValue(m_backgroundShader->lightS(), - m_theme->m_lightStrength / 25.0f); - - // Draw the object - m_drawer->drawObject(m_backgroundShader, m_backgroundObj, m_bgrTexture, m_depthTexture); - } else -#endif - { - // Set shadowless shader bindings - m_backgroundShader->setUniformValue(m_backgroundShader->lightS(), - m_theme->m_lightStrength); - - // Draw the object - m_drawer->drawObject(m_backgroundShader, m_backgroundObj, m_bgrTexture); - } - } - - // Disable textures - glDisable(GL_TEXTURE_2D); - if (m_bgrHasAlpha) - glDisable(GL_BLEND); - - // Release background shader - m_backgroundShader->release(); -#endif - - // Handle zoom activation and label drawing - if (!barSelectionFound) { - // We have no ownership, don't delete. Just NULL the pointer. - m_selectedBar = NULL; - //if (m_zoomActivated && Maps3DController::MouseOnOverview == m_mousePressed) { - //m_sceneViewPort = QRect(0, 0, width(), height()); - //m_zoomActivated = false; - //} - } /*else if (m_selectionMode >= ModeZoomRow - && Maps3DController::MouseOnScene == m_mousePressed) { - // Activate zoom mode - m_zoomActivated = true; - m_sceneViewPort = QRect(0, height() - height() / 5, width() / 5, height() / 5); - - // Create label textures - for (int col = 0; col < m_zoomSelection->row().size(); col++) { - QDataItem *item = m_zoomSelection->getItem(col); - m_drawer->generateLabelTexture(item); - } - }*/ else { - // Draw the selection label - m_labelShader->bind(); - glDisable(GL_DEPTH_TEST); - glEnable(GL_TEXTURE_2D); - if (m_labelTransparency > QDataVis::TransparencyNone) { - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } - - LabelItem &labelItem = m_selectedBar->selectionLabelItem(); - if (m_previouslySelectedBar != m_selectedBar || m_updateLabels || !labelItem.textureId()) { - m_drawer->generateLabelItem(labelItem, m_selectedBar->selectionLabel()); - m_previouslySelectedBar = m_selectedBar; - } - - m_drawer->drawLabel(*m_selectedBar, labelItem, - viewMatrix, projectionMatrix, - QVector3D(0.0f, m_yAdjustment, zComp), - QVector3D(0.0f, 0.0f, 0.0f), m_selectedBar->height(), - m_selectionMode, m_labelShader, - m_labelObj, m_camera, true); - - glDisable(GL_TEXTURE_2D); - if (m_labelTransparency > QDataVis::TransparencyNone) - glDisable(GL_BLEND); - glEnable(GL_DEPTH_TEST); - - // Release label shader - m_labelShader->release(); - - // Reset label update flag; they should have been updated when we get here - m_updateLabels = false; - } -#if 0 - // TODO: Calculations done temporarily here. When optimizing, move to after data set addition? Keep drawing of the labels here. - // Bind label shader - m_labelShader->bind(); - - glEnable(GL_TEXTURE_2D); - if (m_labelTransparency > TransparencyNone) { - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } - - // Calculate the positions for row and column labels and store them into QDataItems (and QDataRows?) - for (int row = 0; row != m_sampleCount.second; row += 1) { - // Go through all rows and get position of max+1 or min-1 column, depending on x flip - // We need only positions for them, labels have already been generated at QDataSet. Just add LabelItems - rowPos = (row + 1) * (m_barSpacing.height()); - barPos = 0; - GLfloat rotLabelX = -90.0f; - GLfloat rotLabelY = 0.0f; - Qt::AlignmentFlag alignment = Qt::AlignRight; - if (m_zFlipped) - rotLabelY = 180.0f; - if (m_xFlipped) { - barPos = (m_sampleCount.first + 1) * (m_barSpacing.width()); - alignment = Qt::AlignLeft; - } - QVector3D labelPos = QVector3D((m_rowWidth - barPos) / m_scaleFactor, - -m_yAdjustment + 0.005f, // raise a bit over background to avoid depth "glimmering" - (m_columnDepth - rowPos) / m_scaleFactor + zComp); - - // TODO: Try it; draw the label here - - // Create a data item - QDataItem *label = new QDataItem(); - label->setTranslation(labelPos); - if (m_data->d_ptr->rowLabelItems().size() > row) { - label->setLabel(m_data->d_ptr->rowLabelItems().at(m_data->d_ptr->rowLabelItems().size() - - row - 1)); - } - - //qDebug() << "labelPos, row" << row + 1 << ":" << labelPos << m_dataSet->rowLabels().at(row); - - m_drawer->drawLabel(*label, label->label(), viewMatrix, projectionMatrix, - QVector3D(0.0f, m_yAdjustment, zComp), - QVector3D(rotLabelX, rotLabelY, 0.0f), m_heightNormalizer, - m_selectionMode, m_labelShader, - m_labelObj, true, true, Drawer::LabelMid, alignment); - - delete label; - } - for (int bar = 0; bar != m_sampleCount.first; bar += 1) { - // Go through all columns and get position of max+1 or min-1 row, depending on z flip - // We need only positions for them, labels have already been generated at QDataSet. Just add LabelItems - barPos = (bar + 1) * (m_barSpacing.width()); - rowPos = 0; - GLfloat rotLabelX = -90.0f; - GLfloat rotLabelY = 90.0f; - Qt::AlignmentFlag alignment = Qt::AlignLeft; - if (m_xFlipped) - rotLabelY = -90.0f; - if (m_zFlipped) { - rowPos = (m_sampleCount.second + 1) * (m_barSpacing.height()); - alignment = Qt::AlignRight; - } - QVector3D labelPos = QVector3D((m_rowWidth - barPos) / m_scaleFactor, - -m_yAdjustment + 0.005f, // raise a bit over background to avoid depth "glimmering" - (m_columnDepth - rowPos) / m_scaleFactor + zComp); - - // TODO: Try it; draw the label here - - // Create a data item - QDataItem *label = new QDataItem(); - label->setTranslation(labelPos); - if (m_data->d_ptr->columnLabelItems().size() > bar) { - label->setLabel(m_data->d_ptr->columnLabelItems().at( - m_data->d_ptr->columnLabelItems().size() - bar - 1)); - } - - //qDebug() << "labelPos, col" << bar + 1 << ":" << labelPos << m_dataSet->columnLabels().at(bar); - - m_drawer->drawLabel(*label, label->label(), viewMatrix, projectionMatrix, - QVector3D(0.0f, m_yAdjustment, zComp), - QVector3D(rotLabelX, rotLabelY, 0.0f), m_heightNormalizer, - m_selectionMode, m_labelShader, - m_labelObj, true, true, Drawer::LabelMid, alignment); - - delete label; - } - glDisable(GL_TEXTURE_2D); - if (m_labelTransparency > TransparencyNone) - glDisable(GL_BLEND); - - // Release label shader - m_labelShader->release(); -#endif -#endif -#endif -} - -#if defined(Q_OS_ANDROID) -/*! - * \internal - */ -void Maps3DController::mouseDoubleClickEvent(QMouseEvent *event) -{ - if (!m_zoomActivated) { - m_mousePressed = Maps3DController::MouseOnScene; - // update mouse positions to prevent jumping when releasing or repressing a button - m_mousePos = event->pos(); - } -} - -/*! - * \internal - */ -void Maps3DController::touchEvent(QTouchEvent *event) -{ - static int prevDistance = 0; - - QList<QTouchEvent::TouchPoint> points; - points = event->touchPoints(); - - if (points.count() == 2) { - m_mousePressed = Maps3DController::MouseOnPinch; - - QPointF distance = points.at(0).pos() - points.at(1).pos(); - int newDistance = distance.manhattanLength(); - int zoomRate = 1; - if (m_zoomLevel > 100) - zoomRate = 5; - if (newDistance > prevDistance) - m_zoomLevel += zoomRate; - else - m_zoomLevel -= zoomRate; - if (m_zoomLevel > 500) - m_zoomLevel = 500; - else if (m_zoomLevel < 10) - m_zoomLevel = 10; - prevDistance = newDistance; - //qDebug() << "distance" << distance.manhattanLength(); - } -} -#endif - -/*! - * \internal - */ -void Maps3DController::mousePressEvent(QMouseEvent *event, const QPoint &mousePos) -{ - if (Qt::LeftButton == event->button()) { - if (m_zoomActivated) { - //qDebug() << event->pos().x() << event->pos().y() << m_sceneViewPort << m_zoomViewPort; - if (mousePos.x() <= m_sceneViewPort.width() - && mousePos.y() <= m_sceneViewPort.height()) { - m_mousePressed = Maps3DController::MouseOnOverview; - //qDebug() << "Mouse pressed on overview"; - } else { - m_mousePressed = Maps3DController::MouseOnZoom; - //qDebug() << "Mouse pressed on zoom"; - } - } else { -#if !defined(Q_OS_ANDROID) - m_mousePressed = Maps3DController::MouseOnScene; -#else - m_mousePressed = Maps3DController::MouseRotating; -#endif - // update mouse positions to prevent jumping when releasing or repressing a button - m_mousePos = mousePos; - //qDebug() << "Mouse pressed on scene"; - } - } else if (Qt::MiddleButton == event->button()) { - // reset rotations - m_mousePos = QPoint(0, 0); - } else if (Qt::RightButton == event->button()) { -#if !defined(Q_OS_ANDROID) - m_mousePressed = Maps3DController::MouseRotating; -#else - m_mousePressed = Maps3DController::MouseOnScene; -#endif - // update mouse positions to prevent jumping when releasing or repressing a button - m_mousePos = mousePos; - } - m_camera->updateMousePos(m_mousePos); -} - -/*! - * \internal - */ -void Maps3DController::mouseReleaseEvent(QMouseEvent *event, const QPoint &mousePos) -{ - Q_UNUSED(event); - //qDebug() << "mouse button released" << event->button(); - if (Maps3DController::MouseRotating == m_mousePressed) { - // update mouse positions to prevent jumping when releasing or repressing a button - m_mousePos = mousePos; - m_camera->updateMousePos(mousePos); - } - m_mousePressed = Maps3DController::MouseNone; -} - -/*! - * \internal - */ -void Maps3DController::mouseMoveEvent(QMouseEvent *event, const QPoint &mousePos) -{ - Q_UNUSED(event); - if (Maps3DController::MouseRotating == m_mousePressed) { - //qDebug() << "mouse moved while pressed" << event->pos(); - m_mousePos = mousePos; - } -#if 0 - // TODO: Testi - laske kursorin sijainti scenessä - QPointF mouse3D((2.0f * event->pos().x() - width()) / height(), - 1.0f - (2.0f * event->pos().y()) / height()); - //qDebug() << "mouse position in scene" << mouse3D; - - // TODO: Testi laske focal point - GLfloat focalPoint = tan(45.0f / 2.0f); - - // TODO: Testi - laske viewmatriisin kerroin - QVector3D worldRay = QVector3D(0.0f, 0.0f, 0.0f) - QVector3D(mouse3D.x(), mouse3D.y(), - -focalPoint); - //qDebug() << "worldRay" << worldRay; - // multiply viewmatrix with this to get something? -#endif -} - -/*! - * \internal - */ -void Maps3DController::wheelEvent(QWheelEvent *event) -{ - if (m_zoomLevel > 100) - m_zoomLevel += event->angleDelta().y() / 12; - else if (m_zoomLevel > 50) - m_zoomLevel += event->angleDelta().y() / 60; - else - m_zoomLevel += event->angleDelta().y() / 120; - if (m_zoomLevel > 500) - m_zoomLevel = 500; - else if (m_zoomLevel < 10) - m_zoomLevel = 10; -} - -/*! - * \internal - */ -void Maps3DController::resizeNotify() -{ - if (!m_isInitialized) - return; - - // Set view port - if (m_zoomActivated) - m_sceneViewPort = QRect(0, height() - height() / 5, width() / 5, height() / 5); - else - m_sceneViewPort = QRect(0, 0, width(), height()); - m_zoomViewPort = QRect(0, 0, width(), height()); - - // Calculate zoom level based on aspect ratio - GLfloat div; - GLfloat zoomAdjustment; - div = qMin(width(), height()); - zoomAdjustment = defaultRatio * ((width() / div) / (height() / div)); - //qDebug() << "zoom adjustment" << zoomAdjustment; - m_autoScaleAdjustment = qMin(zoomAdjustment, 1.0f); // clamp to 1.0f - - // Re-init selection buffer - initSelectionBuffer(); - -#if !defined(QT_OPENGL_ES_2) - // Re-init depth buffer - initDepthBuffer(); -#endif -} - -void Maps3DController::setBarSpecs(const QVector3D &thickness, - Q3DMaps::AdjustmentDirection direction) -{ - m_barThickness = thickness; - m_adjustDirection = direction; -} - -void Maps3DController::setBarType(QDataVis::MeshStyle style, bool smooth) -{ - if (style == QDataVis::Bars) { - if (smooth) - m_objFile = QStringLiteral(":/defaultMeshes/barSmooth"); - else - m_objFile = QStringLiteral(":/defaultMeshes/bar"); - } else if (style == QDataVis::Pyramids) { - if (smooth) - m_objFile = QStringLiteral(":/defaultMeshes/pyramidSmooth"); - else - m_objFile = QStringLiteral(":/defaultMeshes/pyramid"); - } else if (style == QDataVis::Cones) { - if (smooth) - m_objFile = QStringLiteral(":/defaultMeshes/coneSmooth"); - else - m_objFile = QStringLiteral(":/defaultMeshes/cone"); - } else if (style == QDataVis::Cylinders) { - if (smooth) - m_objFile = QStringLiteral(":/defaultMeshes/cylinderSmooth"); - else - m_objFile = QStringLiteral(":/defaultMeshes/cylinder"); - } else if (style == QDataVis::BevelBars) { - if (smooth) - m_objFile = QStringLiteral(":/defaultMeshes/bevelbarSmooth"); - else - m_objFile = QStringLiteral(":/defaultMeshes/bevelbar"); - } else if (style == QDataVis::Spheres) { - if (smooth) - m_objFile = QStringLiteral(":/defaultMeshes/sphereSmooth"); - else - m_objFile = QStringLiteral(":/defaultMeshes/sphere"); - } - // Reload mesh data - if (m_isInitialized) - loadBarMesh(); -} - -void Maps3DController::setMeshFileName(const QString &objFileName) -{ - m_objFile = objFileName; -} - -void Maps3DController::setCameraPreset(QDataVis::CameraPreset preset) -{ - m_camera->setCameraPreset(preset); -} - -void Maps3DController::setCameraPosition(GLfloat horizontal, GLfloat vertical, GLint distance) -{ - m_horizontalRotation = qBound(-180.0f, horizontal, 180.0f); - m_verticalRotation = qBound(0.0f, vertical, 90.0f); - m_zoomLevel = qBound(10, distance, 500); - m_camera->setCameraRotation(QPointF(m_horizontalRotation, m_verticalRotation)); - //qDebug() << "camera rotation set to" << m_horizontalRotation << m_verticalRotation; -} - -void Maps3DController::setTheme(QDataVis::ColorTheme colorTheme) -{ - m_theme->useColorTheme(colorTheme); - m_drawer->setTheme(*m_theme); -#if !defined(QT_OPENGL_ES_2) - if (m_shadowQuality > QDataVis::ShadowNone) { - // Re-init shaders - if (!m_theme->m_uniformColor) { - initShaders(QStringLiteral(":/shaders/vertexShadow"), - QStringLiteral(":/shaders/fragmentShadowNoTexColorOnY")); - } else { - initShaders(QStringLiteral(":/shaders/vertexShadow"), - QStringLiteral(":/shaders/fragmentShadowNoTex")); - } - } else { - // Re-init shaders - if (!m_theme->m_uniformColor) { - initShaders(QStringLiteral(":/shaders/vertex"), - QStringLiteral(":/shaders/fragmentColorOnY")); - } else { - initShaders(QStringLiteral(":/shaders/vertex"), - QStringLiteral(":/shaders/fragment")); - } - } -#else - if (!m_theme->m_uniformColor) { - initShaders(QStringLiteral(":/shaders/vertexES2"), - QStringLiteral(":/shaders/fragmentColorOnYES2")); - } else { - initShaders(QStringLiteral(":/shaders/vertexES2"), - QStringLiteral(":/shaders/fragmentES2")); - } -#endif - m_updateLabels = true; -} - -void Maps3DController::setBarColor(const QColor &baseColor, const QColor &heightColor, - bool uniform) -{ - m_theme->m_baseColor = baseColor; - m_theme->m_heightColor = heightColor; - if (m_theme->m_uniformColor != uniform) { -#if !defined(QT_OPENGL_ES_2) - if (m_shadowQuality > QDataVis::ShadowNone) { - // Re-init shaders - if (!m_theme->m_uniformColor) { - initShaders(QStringLiteral(":/shaders/vertexShadow"), - QStringLiteral(":/shaders/fragmentShadowNoTexColorOnY")); - } else { - initShaders(QStringLiteral(":/shaders/vertexShadow"), - QStringLiteral(":/shaders/fragmentShadowNoTex")); - } - } else { - // Re-init shaders - if (!m_theme->m_uniformColor) { - initShaders(QStringLiteral(":/shaders/vertex"), - QStringLiteral(":/shaders/fragmentColorOnY")); - } else { - initShaders(QStringLiteral(":/shaders/vertex"), - QStringLiteral(":/shaders/fragment")); - } - } -#else - if (!m_theme->m_uniformColor) { - initShaders(QStringLiteral(":/shaders/vertexES2"), - QStringLiteral(":/shaders/fragmentColorOnYES2")); - } else { - initShaders(QStringLiteral(":/shaders/vertexES2"), - QStringLiteral(":/shaders/fragmentES2")); - } -#endif - } - m_theme->m_uniformColor = uniform; -} - -void Maps3DController::setAreaSpecs(const QRect &areaRect, const QImage &image) -{ - calculateSceneScalingFactors(areaRect); - setImage(image); -} - -void Maps3DController::setImage(const QImage &image) -{ - m_bgrHasAlpha = image.hasAlphaChannel(); - if (m_bgrTexture) - glDeleteTextures(1, &m_bgrTexture); - m_bgrTexture = m_textureHelper->create2DTexture(image, true, true); -} - -void Maps3DController::setSelectionMode(QDataVis::SelectionMode mode) -{ - m_selectionMode = mode; - // Disable zoom if mode changes - //m_zoomActivated = false; - //m_sceneViewPort = QRect(0, 0, width(), height()); -} - -QDataVis::SelectionMode Maps3DController::selectionMode() -{ - return m_selectionMode; -} - -void Maps3DController::setFont(const QFont &font) -{ - m_font = font; - m_drawer->setFont(font); - m_updateLabels = true; -} - -QFont Maps3DController::font() -{ - return m_font; -} - -void Maps3DController::setLabelTransparency(QDataVis::LabelTransparency transparency) -{ - m_labelTransparency = transparency; - m_drawer->setTransparency(transparency); - m_updateLabels = true; -} - -QDataVis::LabelTransparency Maps3DController::labelTransparency() -{ - return m_labelTransparency; -} - -QDataVis::ShadowQuality Maps3DController::setShadowQuality(QDataVis::ShadowQuality quality) -{ - m_shadowQuality = quality; - switch (quality) { - case QDataVis::ShadowLow: - //qDebug() << "ShadowLow"; - m_shadowQualityToShader = 33.3f; - break; - case QDataVis::ShadowMedium: - //qDebug() << "ShadowMedium"; - m_shadowQualityToShader = 100.0f; - break; - case QDataVis::ShadowHigh: - //qDebug() << "ShadowHigh"; - m_shadowQualityToShader = 200.0f; - break; - default: - m_shadowQualityToShader = 0.0f; - break; - } - if (m_isInitialized) { -#if !defined(QT_OPENGL_ES_2) - if (m_shadowQuality > QDataVis::ShadowNone) { - // Re-init shaders - if (!m_theme->m_uniformColor) { - initShaders(QStringLiteral(":/shaders/vertexShadow"), - QStringLiteral(":/shaders/fragmentShadowNoTexColorOnY")); - } else { - initShaders(QStringLiteral(":/shaders/vertexShadow"), - QStringLiteral(":/shaders/fragmentShadowNoTex")); - } - initBackgroundShaders(QStringLiteral(":/shaders/vertexShadow"), - QStringLiteral(":/shaders/fragmentShadow")); - } else { - // Re-init shaders - if (!m_theme->m_uniformColor) { - initShaders(QStringLiteral(":/shaders/vertex"), - QStringLiteral(":/shaders/fragmentColorOnY")); - } else { - initShaders(QStringLiteral(":/shaders/vertex"), - QStringLiteral(":/shaders/fragment")); - } - initBackgroundShaders(QStringLiteral(":/shaders/vertexTexture"), - QStringLiteral(":/shaders/fragmentTexture")); - } - // Re-init depth buffer - initDepthBuffer(); -#else - if (!m_theme->m_uniformColor) { - initShaders(QStringLiteral(":/shaders/vertexES2"), - QStringLiteral(":/shaders/fragmentColorOnYES2")); - } else { - initShaders(QStringLiteral(":/shaders/vertexES2"), - QStringLiteral(":/shaders/fragmentES2")); - } - initBackgroundShaders(QStringLiteral(":/shaders/vertexTexture"), // Same vertex shader ok for ES2 - QStringLiteral(":/shaders/fragmentTextureES2")); -#endif - } - return m_shadowQuality; -} - -QDataVis::ShadowQuality Maps3DController::shadowQuality() -{ - return m_shadowQuality; -} - - - -const QSize Maps3DController::size() -{ - return m_boundingRect.size(); -} - -const QRect Maps3DController::boundingRect() -{ - return m_boundingRect; -} - -void Maps3DController::setBoundingRect(const QRect boundingRect) -{ - m_boundingRect = boundingRect; - resizeNotify(); -} - -void Maps3DController::setWidth(const int width) -{ - m_boundingRect.setWidth(width); - resizeNotify(); -} - -int Maps3DController::width() -{ - return m_boundingRect.width(); -} - -void Maps3DController::setHeight(const int height) -{ - m_boundingRect.setHeight(height); - resizeNotify(); -} - -int Maps3DController::height() -{ - return m_boundingRect.height(); -} - -void Maps3DController::setX(const int x) -{ - m_boundingRect.setX(x); -} - -int Maps3DController::x() -{ - return m_boundingRect.x(); -} - -void Maps3DController::setY(const int y) -{ - m_boundingRect.setY(y); -} - -int Maps3DController::y() -{ - return m_boundingRect.y(); -} - -void Maps3DController::loadBarMesh() -{ - if (m_barObj) - delete m_barObj; - m_barObj = new ObjectHelper(m_objFile); - m_barObj->load(); -} - -void Maps3DController::loadBackgroundMesh() -{ - if (m_backgroundObj) - delete m_backgroundObj; - m_backgroundObj = new ObjectHelper(QStringLiteral(":/defaultMeshes/label")); - m_backgroundObj->load(); -} - -void Maps3DController::loadGridLineMesh() -{ - if (m_gridLineObj) - delete m_gridLineObj; - m_gridLineObj = new ObjectHelper(QStringLiteral(":/defaultMeshes/bar")); - m_gridLineObj->load(); -} - -void Maps3DController::loadLabelMesh() -{ - if (m_labelObj) - delete m_labelObj; - m_labelObj = new ObjectHelper(QStringLiteral(":/defaultMeshes/label")); - m_labelObj->load(); -} - -void Maps3DController::initShaders(const QString &vertexShader, const QString &fragmentShader) -{ - if (m_barShader) - delete m_barShader; - m_barShader = new ShaderHelper(this, vertexShader, fragmentShader); - m_barShader->initialize(); -} - -void Maps3DController::initSelectionShader() -{ - if (m_selectionShader) - delete m_selectionShader; - m_selectionShader = new ShaderHelper(this, QStringLiteral(":/shaders/vertexSelection"), - QStringLiteral(":/shaders/fragmentSelection")); - m_selectionShader->initialize(); -} - -void Maps3DController::initSelectionBuffer() -{ - if (m_selectionTexture) - m_textureHelper->deleteTexture(&m_selectionTexture); - - m_selectionTexture = m_textureHelper->createSelectionTexture(this->size(), - m_selectionFrameBuffer, - m_selectionDepthBuffer); -} - -#if !defined(QT_OPENGL_ES_2) -void Maps3DController::initDepthShader() -{ - if (m_depthShader) - delete m_depthShader; - m_depthShader = new ShaderHelper(this, QStringLiteral(":/shaders/vertexDepth"), - QStringLiteral(":/shaders/fragmentDepth")); - m_depthShader->initialize(); -} - -void Maps3DController::initDepthBuffer() -{ - if (!m_isInitialized) - return; - - if (m_depthTexture) { - m_textureHelper->deleteTexture(&m_depthTexture); - m_depthTexture = 0; - } - - if (m_shadowQuality > QDataVis::ShadowNone) { - m_depthTexture = m_textureHelper->createDepthTexture(this->size(), m_depthFrameBuffer, - m_shadowQuality); - if (!m_depthTexture) { - switch (m_shadowQuality) { - case QDataVis::ShadowHigh: - qWarning("Creating high quality shadows failed. Changing to medium quality."); - (void)setShadowQuality(QDataVis::ShadowMedium); - break; - case QDataVis::ShadowMedium: - qWarning("Creating medium quality shadows failed. Changing to low quality."); - (void)setShadowQuality(QDataVis::ShadowLow); - break; - case QDataVis::ShadowLow: - qWarning("Creating low quality shadows failed. Switching shadows off."); - (void)setShadowQuality(QDataVis::ShadowNone); - break; - default: - // Cannot get here - break; - } - } - } -} -#endif - -void Maps3DController::initBackgroundShaders(const QString &vertexShader, - const QString &fragmentShader) -{ - if (m_backgroundShader) - delete m_backgroundShader; - m_backgroundShader = new ShaderHelper(this, vertexShader, fragmentShader); - m_backgroundShader->initialize(); -} - -void Maps3DController::initLabelShaders(const QString &vertexShader, const QString &fragmentShader) -{ - if (m_labelShader) - delete m_labelShader; - m_labelShader = new ShaderHelper(this, vertexShader, fragmentShader); - m_labelShader->initialize(); -} - -void Maps3DController::updateTextures() -{ - // Drawer has changed; this flag needs to be checked when checking if we need to update labels - m_updateLabels = true; -} - -void Maps3DController::calculateSceneScalingFactors(const QRect &areaRect) -{ - m_areaSize = areaRect.size(); - // Calculate scaling factor so that we can be sure the whole area fits to positive z space - if (zComp > 1.0f) - m_scaleFactor = qMax(m_areaSize.width(), m_areaSize.height()) / zComp; - else - m_scaleFactor = qMax(m_areaSize.width(), m_areaSize.height()); - //qDebug() << "scaleFactor" << m_scaleFactor; -} - -void Maps3DController::calculateHeightAdjustment(const QPair<GLfloat, GLfloat> &limits) -{ - // 2.0f = max difference between minimum and maximum value after scaling with m_heightNormalizer - m_yAdjustment = 2.0f - ((limits.second - limits.first) / m_heightNormalizer); - //qDebug() << m_yAdjustment; -} - -void Maps3DController::calculateTranslation(MapRenderItem &item) -{ - // We need to convert position (which is in coordinates), to translation (which has origin in the center and is scaled) - // -> move pos(center, center) to trans(0, 0) and pos(0, 0) to trans(left, top) - GLfloat xTrans = 2.0f * (item.mapPosition().x() - (m_areaSize.width() / 2.0f)) - / m_scaleFactor; - GLfloat zTrans = 2.0f * (item.mapPosition().y() - (m_areaSize.height() / 2.0f)) - / m_scaleFactor; - //qDebug() << "x, y" << item.mapPosition().x() << item.mapPosition().y(); - item.setTranslation(QVector3D(xTrans, 0.0f, zTrans + zComp)); - //qDebug() << item.translation(); -} - -Maps3DController::SelectionType Maps3DController::isSelected(GLint bar, const QVector3D &selection) -{ - GLubyte barIdxRed = 0; - GLubyte barIdxGreen = 0; - GLubyte barIdxBlue = 0; - //static QVector3D prevSel = selection; // TODO: For debugging - SelectionType isSelectedType = SelectionNone; - - if (selection == skipColor) - return isSelectedType; // skip window - - if (bar <= 255) { - barIdxRed = bar; - } else if (bar <= 65535) { - barIdxGreen = bar / 256; - barIdxRed = bar % 256; - } else { - barIdxBlue = bar / 65535; - barIdxGreen = bar % 65535; - barIdxRed = bar % 256; - } - - QVector3D current = QVector3D(barIdxRed, barIdxGreen, barIdxBlue); - - // TODO: For debugging - //if (selection != prevSel) { - // qDebug() << selection.x() << selection .y() << selection.z(); - // prevSel = selection; - //} - - if (current == selection) - isSelectedType = SelectionBar; - - return isSelectedType; -} - -bool Maps3DController::isValid(const MapRenderItem &item) -{ - bool retval = true; - if (item.value() < 0) { - qCritical("Data item value out of range"); - retval = false; - } else if (item.mapPosition().x() < 0 || item.mapPosition().x() > m_areaSize.width()) { - qCritical("Data item x position out of range"); - retval = false; - } else if (item.mapPosition().y() < 0 || item.mapPosition().y() > m_areaSize.height()) { - qCritical("Data item y position out of range"); - retval = false; - } - return retval; -} - -void Maps3DController::setDataProxy(QMapDataProxy *proxy) -{ - delete m_data; - m_data = proxy; - - QObject::connect(m_data, &QMapDataProxy::arrayReset, this, &Maps3DController::handleArrayReset); - QObject::connect(m_data, &QMapDataProxy::itemsAdded, this, &Maps3DController::handleItemsAdded); - QObject::connect(m_data, &QMapDataProxy::itemsChanged, this, &Maps3DController::handleItemsChanged); - QObject::connect(m_data, &QMapDataProxy::itemsRemoved, this, &Maps3DController::handleItemsRemoved); - QObject::connect(m_data, &QMapDataProxy::itemsInserted, this, &Maps3DController::handleItemsInserted); - - // emit something? Renderer might be interested? -} - -QMapDataProxy *Maps3DController::dataProxy() -{ - return m_data; -} - -void Maps3DController::handleLimitChange() -{ - QPair<GLfloat, GLfloat> limits = m_data->dptr()->limitValues(); - m_heightNormalizer = qMax(qAbs(limits.second), qAbs(limits.first)); - calculateHeightAdjustment(limits); - - //emit limitsChanged(limits); -} - -void Maps3DController::handleArrayReset() -{ - handleLimitChange(); - m_valuesDirty = true; -} - -void Maps3DController::handleItemsAdded(int startIndex, int count) -{ - Q_UNUSED(startIndex) - Q_UNUSED(count) - // TODO should dirty only affected values? - handleLimitChange(); - m_valuesDirty = true; -} - -void Maps3DController::handleItemsChanged(int startIndex, int count) -{ - Q_UNUSED(startIndex) - Q_UNUSED(count) - // TODO should dirty only affected values? - handleLimitChange(); - m_valuesDirty = true; -} - -void Maps3DController::handleItemsRemoved(int startIndex, int count) -{ - Q_UNUSED(startIndex) - Q_UNUSED(count) - // TODO should dirty only affected values? - handleLimitChange(); - m_valuesDirty = true; -} - -void Maps3DController::handleItemsInserted(int startIndex, int count) -{ - Q_UNUSED(startIndex) - Q_UNUSED(count) - // TODO should dirty only affected values? - handleLimitChange(); - m_valuesDirty = true; -} - -QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3d/engine/maps3dcontroller_p.h b/src/datavis3d/engine/maps3dcontroller_p.h deleted file mode 100644 index 7f87db9d..00000000 --- a/src/datavis3d/engine/maps3dcontroller_p.h +++ /dev/null @@ -1,249 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc -** All rights reserved. -** For any questions to Digia, please use contact form at http://qt.digia.com -** -** This file is part of the QtDataVis3D module. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** contact form at http://qt.digia.com -** -****************************************************************************/ - -// -// 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 MAPS3DCONTROLLER_P_H -#define MAPS3DCONTROLLER_P_H - -#include "datavis3dglobal_p.h" -#include "q3dmaps.h" -#include "maprenderitem_p.h" -#include <QOpenGLFunctions> -#include <QFont> - -//#define DISPLAY_RENDER_SPEED - -class QPoint; -class QSizeF; - -QT_DATAVIS3D_BEGIN_NAMESPACE - -class ShaderHelper; -class ObjectHelper; -class TextureHelper; -class Theme; -class Drawer; -class Maps3DRenderer; -class CameraHelper; -class QMapDataProxy; - -class QT_DATAVIS3D_EXPORT Maps3DController : public QObject, public QOpenGLFunctions -{ - Q_OBJECT -public: - enum SelectionType { - SelectionNone = 0, - SelectionBar, - SelectionRow, - SelectionColumn - }; - - enum MousePressType { - MouseNone = 0, - MouseOnScene, - MouseOnOverview, - MouseOnZoom, - MouseRotating, - MouseOnPinch - }; - -public: - Maps3DController(const QRect &rect); - ~Maps3DController(); - - void initializeOpenGL(); - virtual void synchDataToRenderer(); - void render(const GLuint defaultFboHandle = 0); - - // bar specifications; base thickness in x, y and z, enum to indicate which direction is increased with value - // TODO: Start using thickness also in adjustment direction; use it as a relative value. - // For example, in AdjustAll mode setting thickness to (0.1f, 1.0f, 0.5f) would apply value to - // x at 10%, y at 100% and z at 50%. If a dimension is not included, given thickness states its absolute value. - void setBarSpecs(const QVector3D &thickness = QVector3D(1.0f, 1.0f, 1.0f), - Q3DMaps::AdjustmentDirection direction = Q3DMaps::AdjustHeight); - - // bar type; bars (=cubes), pyramids, cones, cylinders, balls, etc. - void setBarType(QDataVis::MeshStyle style, bool smooth = false); - - // override bar type with own mesh - void setMeshFileName(const QString &objFileName); - - // Select preset camera placement - void setCameraPreset(QDataVis::CameraPreset preset); - - // Set camera rotation if you don't want to use the presets (in horizontal (-180...180) and - // vertical (0...90) angles and distance in percentage (10...500)) - void setCameraPosition(GLfloat horizontal, GLfloat vertical, GLint distance = 100); - - // Set theme (bar colors, shaders, window color, background colors, light intensity and text colors are affected) - void setTheme(QDataVis::ColorTheme theme); - - // Set color if you don't want to use themes. Set uniform to false if you want the (height) color to change from bottom to top - void setBarColor(const QColor &baseColor, const QColor &heightColor, bool uniform = true); - - // Set area specs - void setAreaSpecs(const QRect &areaRect, const QImage &image); - - // Set area image - void setImage(const QImage &image); - - // TODO: light placement API - - // Change selection mode; single bar, bar and row, bar and column, or all - void setSelectionMode(QDataVis::SelectionMode mode); - QDataVis::SelectionMode selectionMode(); - - // Set font - void setFont(const QFont &font); - QFont font(); - - // Label transparency adjustment - void setLabelTransparency(QDataVis::LabelTransparency transparency); - QDataVis::LabelTransparency labelTransparency(); - - // Adjust shadow quality - QDataVis::ShadowQuality setShadowQuality(QDataVis::ShadowQuality quality); - QDataVis::ShadowQuality shadowQuality(); - - // Size - const QSize size(); - const QRect boundingRect(); - void setBoundingRect(const QRect boundingRect); - void setWidth(const int width); - int width(); - void setHeight(const int height); - int height(); - void setX(const int x); - int x(); - void setY(const int y); - int y(); - -#if defined(Q_OS_ANDROID) - void mouseDoubleClickEvent(QMouseEvent *event); - void touchEvent(QTouchEvent *event); -#endif - void mousePressEvent(QMouseEvent *event, const QPoint &mousePos); - void mouseReleaseEvent(QMouseEvent *event, const QPoint &mousePos); - void mouseMoveEvent(QMouseEvent *event, const QPoint &mousePos); - void wheelEvent(QWheelEvent *event); - void resizeNotify(); - - void loadBarMesh(); - void loadBackgroundMesh(); - void loadGridLineMesh(); - void loadLabelMesh(); - void initShaders(const QString &vertexShader, const QString &fragmentShader); - void initSelectionShader(); - void initBackgroundShaders(const QString &vertexShader, const QString &fragmentShader); - void initLabelShaders(const QString &vertexShader, const QString &fragmentShader); - void initSelectionBuffer(); -#if !defined(QT_OPENGL_ES_2) - void initDepthShader(); - void initDepthBuffer(); -#endif - void updateTextures(); - void calculateSceneScalingFactors(const QRect &areaRect); - void calculateHeightAdjustment(const QPair<GLfloat, GLfloat> &limits); - void calculateTranslation(MapRenderItem &item); - SelectionType isSelected(GLint bar, const QVector3D &selection); - bool isValid(const MapRenderItem &item); - - // Sets the data proxy. Assumes ownership of the data proxy. Deletes old proxy. - void setDataProxy(QMapDataProxy *proxy); - QMapDataProxy *dataProxy(); - - void handleLimitChange(); - -public slots: - void handleArrayReset(); - void handleItemsAdded(int startIndex, int count); - void handleItemsChanged(int startIndex, int count); - void handleItemsRemoved(int startIndex, int count); - void handleItemsInserted(int startIndex, int count); - -private: - void drawScene(const GLuint defaultFboHandle); - - Maps3DRenderer *m_renderer; - CameraHelper *m_camera; - - ShaderHelper *m_barShader; - ShaderHelper *m_depthShader; - ShaderHelper *m_selectionShader; - ShaderHelper *m_backgroundShader; - ShaderHelper *m_labelShader; - ObjectHelper *m_barObj; - ObjectHelper *m_backgroundObj; - ObjectHelper *m_gridLineObj; - ObjectHelper *m_labelObj; - QString m_objFile; - MousePressType m_mousePressed; - QPoint m_mousePos; - GLint m_zoomLevel; - GLfloat m_autoScaleAdjustment; - GLfloat m_horizontalRotation; - GLfloat m_verticalRotation; - QVector3D m_barThickness; - GLfloat m_heightNormalizer; - GLfloat m_yAdjustment; - GLfloat m_scaleFactor; - Theme *m_theme; - bool m_isInitialized; - QDataVis::SelectionMode m_selectionMode; - BarRenderItem *m_selectedBar; // points to renderitem array - BarRenderItem *m_previouslySelectedBar; // points to renderitem array - QString m_axisLabelX; - QString m_axisLabelZ; - QString m_axisLabelY; - QRect m_sceneViewPort; - QRect m_zoomViewPort; - bool m_zoomActivated; - TextureHelper *m_textureHelper; - QDataVis::LabelTransparency m_labelTransparency; - QFont m_font; - Drawer *m_drawer; - QSizeF m_areaSize; - GLuint m_bgrTexture; - GLuint m_depthTexture; - GLuint m_selectionTexture; - GLuint m_depthFrameBuffer; - GLuint m_selectionFrameBuffer; - GLuint m_selectionDepthBuffer; - bool m_updateLabels; - Q3DMaps::AdjustmentDirection m_adjustDirection; - QDataVis::ShadowQuality m_shadowQuality; - GLfloat m_shadowQualityToShader; - bool m_bgrHasAlpha; - QRect m_boundingRect; - QMapDataProxy *m_data; - bool m_valuesDirty; - MapRenderItemArray m_renderItemArray; -}; - -QT_DATAVIS3D_END_NAMESPACE - -#endif diff --git a/src/datavis3d/engine/maps3drenderer.cpp b/src/datavis3d/engine/maps3drenderer.cpp deleted file mode 100644 index c05f2f51..00000000 --- a/src/datavis3d/engine/maps3drenderer.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc -** All rights reserved. -** For any questions to Digia, please use contact form at http://qt.digia.com -** -** This file is part of the QtDataVis3D module. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** contact form at http://qt.digia.com -** -****************************************************************************/ - -#include "maps3dcontroller_p.h" -#include "maps3drenderer_p.h" -#include "camerahelper_p.h" -#include "shaderhelper_p.h" -#include "objecthelper_p.h" -#include "texturehelper_p.h" -#include "theme_p.h" -#include "utils_p.h" -#include "drawer_p.h" - -#include <QOpenGLFunctions> -#include <QMatrix4x4> -#include <QOpenGLPaintDevice> -#include <QPainter> -#include <QScreen> -#include <QMouseEvent> - -#include <qmath.h> - -#include <QDebug> - -//#define DISPLAY_RENDER_SPEED - -// Uncommenting this draws the shadow map with wider FOV than scene itself, making the light -// seem to be closer to scene than it actually is. This way shadows look slightly better (to me anyway) -#define USE_WIDER_SHADOWS - -// You can verify that depth buffer drawing works correctly by uncommenting this. -// You should see the scene from where the light is -//#define SHOW_DEPTH_TEXTURE_SCENE - -#ifdef DISPLAY_RENDER_SPEED -#include <QTime> -#endif - -QT_DATAVIS3D_BEGIN_NAMESPACE - -//#define DISPLAY_FULL_DATA_ON_SELECTION // Append selection value text with row and column labels - -Maps3DRenderer::Maps3DRenderer(Maps3DController *controller) : QObject(controller) -{ -} - -Maps3DRenderer::~Maps3DRenderer() -{ -} - -void Maps3DRenderer::render(CameraHelper *camera, const GLuint defaultFboHandle) -{ - Q_UNUSED(camera) - Q_UNUSED(defaultFboHandle) - // TODO: Implement -} - - -QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3d/engine/maps3drenderer_p.h b/src/datavis3d/engine/maps3drenderer_p.h deleted file mode 100644 index 89054e83..00000000 --- a/src/datavis3d/engine/maps3drenderer_p.h +++ /dev/null @@ -1,53 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc -** All rights reserved. -** For any questions to Digia, please use contact form at http://qt.digia.com -** -** This file is part of the QtDataVis3D module. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** contact form at http://qt.digia.com -** -****************************************************************************/ - -// -// 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 MAPS3DRENDERER_P_H -#define MAPS3DRENDERER_P_H - -#include <QOpenGLFunctions> - -#include "datavis3dglobal_p.h" -#include "camerahelper_p.h" - -QT_DATAVIS3D_BEGIN_NAMESPACE - -class Maps3DController; - -class QT_DATAVIS3D_EXPORT Maps3DRenderer : public QObject, public QOpenGLFunctions -{ - -public: - explicit Maps3DRenderer(Maps3DController *controller); - ~Maps3DRenderer(); - - void render(CameraHelper *camera, const GLuint defaultFboHandle); -}; - -QT_DATAVIS3D_END_NAMESPACE - -#endif diff --git a/src/datavis3d/engine/q3dmaps.cpp b/src/datavis3d/engine/q3dmaps.cpp deleted file mode 100644 index 3ff9bc7c..00000000 --- a/src/datavis3d/engine/q3dmaps.cpp +++ /dev/null @@ -1,250 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc -** All rights reserved. -** For any questions to Digia, please use contact form at http://qt.digia.com -** -** This file is part of the QtDataVis3D module. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** contact form at http://qt.digia.com -** -****************************************************************************/ - -#include "q3dmaps.h" -#include "q3dmaps_p.h" -#include "maps3dcontroller_p.h" - -#include <QMouseEvent> - -#include <QDebug> - -QT_DATAVIS3D_BEGIN_NAMESPACE - -/*! - * \class Q3DMaps - * \inmodule QtDataVis3D - * \brief The Q3DMaps class provides methods for rendering 3D bars on maps or other planes. - * \since 1.0.0 - * - * This class enables developers to render bars or objects on maps or other planes in 3D and to - * view them by rotating the scene freely. Methods are provided for changing object types, themes - * and so on. - * - * See methods themselves for more complete description. - * - * \sa Q3DBars, {Qt Data Visualization 3D C++ Classes} - */ - -/*! - * Constructs Q3DMaps. - */ -Q3DMaps::Q3DMaps() - : d_ptr(new Q3DMapsPrivate(this, geometry())) -{ - d_ptr->m_shared->initializeOpenGL(); -} - -/*! - * Destructs Q3DMaps. - */ -Q3DMaps::~Q3DMaps() -{ -} - -/*! - * \internal - */ -void Q3DMaps::render() -{ - d_ptr->m_shared->render(); -} - -#if defined(Q_OS_ANDROID) -/*! - * \internal - */ -void Q3DMaps::mouseDoubleClickEvent(QMouseEvent *event) -{ - d_ptr->m_shared->mouseDoubleClickEvent(event); -} - -/*! - * \internal - */ -void Q3DMaps::touchEvent(QTouchEvent *event) -{ - d_ptr->m_shared->touchEvent(event); -} -#endif - -/*! - * \internal - */ -void Q3DMaps::mousePressEvent(QMouseEvent *event) -{ - d_ptr->m_shared->mousePressEvent(event, event->pos()); -} - -/*! - * \internal - */ -void Q3DMaps::mouseReleaseEvent(QMouseEvent *event) -{ - d_ptr->m_shared->mouseReleaseEvent(event, event->pos()); -} - -/*! - * \internal - */ -void Q3DMaps::mouseMoveEvent(QMouseEvent *event) -{ - d_ptr->m_shared->mouseMoveEvent(event, event->pos()); -} - -/*! - * \internal - */ -void Q3DMaps::wheelEvent(QWheelEvent *event) -{ - d_ptr->m_shared->wheelEvent(event); -} - -/*! - * \internal - */ -void Q3DMaps::resizeEvent(QResizeEvent *event) -{ - Q_UNUSED(event); - d_ptr->m_shared->setWidth(width()); - d_ptr->m_shared->setHeight(height()); - d_ptr->m_shared->resizeNotify(); -} - -// TODO: Document -// Size -void Q3DMaps::setWidth(const int width) -{ - d_ptr->m_shared->setWidth(width); - QWindow::setWidth(width); -} - -void Q3DMaps::setHeight(const int height) -{ - d_ptr->m_shared->setHeight(height); - QWindow::setHeight(height); -} - -void Q3DMaps::setBarSpecs(const QVector3D &thickness, AdjustmentDirection direction) -{ - d_ptr->m_shared->setBarSpecs(thickness, direction); -} - -void Q3DMaps::setBarType(QDataVis::MeshStyle style, bool smooth) -{ - d_ptr->m_shared->setBarType(style, smooth); -} - -void Q3DMaps::setMeshFileName(const QString &objFileName) -{ - d_ptr->m_shared->setMeshFileName(objFileName); -} - -void Q3DMaps::setCameraPreset(QDataVis::CameraPreset preset) -{ - d_ptr->m_shared->setCameraPreset(preset); -} - -void Q3DMaps::setCameraPosition(GLfloat horizontal, GLfloat vertical, GLint distance) -{ - d_ptr->m_shared->setCameraPosition(horizontal, vertical, distance); -} - -void Q3DMaps::setTheme(QDataVis::ColorTheme theme) -{ - d_ptr->m_shared->setTheme(theme); -} - -void Q3DMaps::setBarColor(const QColor &baseColor, const QColor &heightColor, bool uniform) -{ - d_ptr->m_shared->setBarColor(baseColor, heightColor, uniform); -} - -void Q3DMaps::setAreaSpecs(const QRect &areaRect, const QImage &image) -{ - d_ptr->m_shared->setAreaSpecs(areaRect, image); -} - -void Q3DMaps::setImage(const QImage &image) -{ - d_ptr->m_shared->setImage(image); -} - -void Q3DMaps::setSelectionMode(QDataVis::SelectionMode mode) -{ - d_ptr->m_shared->setSelectionMode(mode); -} - -QDataVis::SelectionMode Q3DMaps::selectionMode() const -{ - return d_ptr->m_shared->selectionMode(); -} - -void Q3DMaps::setFont(const QFont &font) -{ - d_ptr->m_shared->setFont(font); -} - -QFont Q3DMaps::font() const -{ - return d_ptr->m_shared->font(); -} - -void Q3DMaps::setLabelTransparency(QDataVis::LabelTransparency transparency) -{ - d_ptr->m_shared->setLabelTransparency(transparency); -} - -QDataVis::LabelTransparency Q3DMaps::labelTransparency() const -{ - return d_ptr->m_shared->labelTransparency(); -} - -QDataVis::ShadowQuality Q3DMaps::setShadowQuality(QDataVis::ShadowQuality quality) -{ - return d_ptr->m_shared->setShadowQuality(quality); -} - -QDataVis::ShadowQuality Q3DMaps::shadowQuality() const -{ - return d_ptr->m_shared->shadowQuality(); -} - -void Q3DMaps::setDataProxy(QMapDataProxy *proxy) -{ - d_ptr->m_shared->setDataProxy(proxy); -} - -QMapDataProxy *Q3DMaps::dataProxy() -{ - return d_ptr->m_shared->dataProxy(); -} - -Q3DMapsPrivate::Q3DMapsPrivate(Q3DMaps *q, const QRect &rect) - : q_ptr(q), - m_shared(new Maps3DController(rect)) -{ -} - -Q3DMapsPrivate::~Q3DMapsPrivate() -{ - qDebug() << "Destroying Q3DMapsPrivate"; - delete m_shared; -} - -QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3d/engine/q3dmaps.h b/src/datavis3d/engine/q3dmaps.h deleted file mode 100644 index 0dbeaf14..00000000 --- a/src/datavis3d/engine/q3dmaps.h +++ /dev/null @@ -1,133 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc -** All rights reserved. -** For any questions to Digia, please use contact form at http://qt.digia.com -** -** This file is part of the QtDataVis3D module. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** contact form at http://qt.digia.com -** -****************************************************************************/ - -#ifndef Q3DMAPS_H -#define Q3DMAPS_H - -#include <QtDataVis3D/qdatavis3denums.h> -#include <QtDataVis3D/q3dwindow.h> - -#include <QFont> -#include <QVector3D> - -class QImage; -class QRect; - -QT_DATAVIS3D_BEGIN_NAMESPACE - -class Maps3DController; -class Q3DMapsPrivate; -class QMapDataProxy; - -class QT_DATAVIS3D_EXPORT Q3DMaps : public Q3DWindow -{ - Q_OBJECT - Q_PROPERTY(QFont font READ font WRITE setFont) - -public: - - enum AdjustmentDirection { - AdjustHeight = 0, // map value to y - AdjustWidth, // map value to x - AdjustDepth, // map value to z - AdjustRadius, // map value to x and z - AdjustAll // map value to all (x, y, z) - }; - -public: - explicit Q3DMaps(); - ~Q3DMaps(); - - void setWidth(const int width); - void setHeight(const int height); - - // bar specifications; base thickness in x, y and z, enum to indicate which direction is increased with value - // TODO: Start using thickness also in adjustment direction; use it as a relative value. - // For example, in AdjustAll mode setting thickness to (0.1f, 1.0f, 0.5f) would apply value to - // x at 10%, y at 100% and z at 50%. If a dimension is not included, given thickness states its absolute value. - void setBarSpecs(const QVector3D &thickness = QVector3D(1.0f, 1.0f, 1.0f), - AdjustmentDirection direction = AdjustHeight); - - // bar type; bars (=cubes), pyramids, cones, cylinders, balls, etc. - void setBarType(QDataVis::MeshStyle style, bool smooth = false); - - // override bar type with own mesh - void setMeshFileName(const QString &objFileName); - - // Select preset camera placement - void setCameraPreset(QDataVis::CameraPreset preset); - - // Set camera rotation if you don't want to use the presets (in horizontal (-180...180) and - // vertical (0...90) angles and distance in percentage (10...500)) - void setCameraPosition(GLfloat horizontal, GLfloat vertical, GLint distance = 100); - - // Set theme (bar colors, shaders, window color, background colors, light intensity and text colors are affected) - void setTheme(QDataVis::ColorTheme theme); - - // Set color if you don't want to use themes. Set uniform to false if you want the (height) color to change from bottom to top - void setBarColor(const QColor &baseColor, const QColor &heightColor, bool uniform = true); - - // Set area specs - void setAreaSpecs(const QRect &areaRect, const QImage &image); - - // Set area image - void setImage(const QImage &image); - - // TODO: light placement API - - // Change selection mode; single bar, bar and row, bar and column, or all - void setSelectionMode(QDataVis::SelectionMode mode); - QDataVis::SelectionMode selectionMode() const; - - // Set font - void setFont(const QFont &font); - QFont font() const; - - // Label transparency adjustment - void setLabelTransparency(QDataVis::LabelTransparency transparency); - QDataVis::LabelTransparency labelTransparency() const; - - // Adjust shadow quality - QDataVis::ShadowQuality setShadowQuality(QDataVis::ShadowQuality quality); - QDataVis::ShadowQuality shadowQuality() const; - - // Sets the data proxy. Assumes ownership of the data proxy. Deletes old proxy. - void setDataProxy(QMapDataProxy *proxy); - QMapDataProxy *dataProxy(); - -protected: - void render(); - -#if defined(Q_OS_ANDROID) - void mouseDoubleClickEvent(QMouseEvent *event); - void touchEvent(QTouchEvent *event); -#endif - void mousePressEvent(QMouseEvent *event); - void mouseReleaseEvent(QMouseEvent *event); - void mouseMoveEvent(QMouseEvent *event); - void wheelEvent(QWheelEvent *event); - void resizeEvent(QResizeEvent *event); - -private: - QScopedPointer<Q3DMapsPrivate> d_ptr; - Q_DISABLE_COPY(Q3DMaps) -}; - -QT_DATAVIS3D_END_NAMESPACE - -#endif diff --git a/src/datavis3d/engine/q3dmaps_p.h b/src/datavis3d/engine/q3dmaps_p.h deleted file mode 100644 index 166ed8f7..00000000 --- a/src/datavis3d/engine/q3dmaps_p.h +++ /dev/null @@ -1,51 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc -** All rights reserved. -** For any questions to Digia, please use contact form at http://qt.digia.com -** -** This file is part of the QtDataVis3D module. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** contact form at http://qt.digia.com -** -****************************************************************************/ - -// -// 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 Q3DMAPS_P_H -#define Q3DMAPS_P_H - -#include "maps3dcontroller_p.h" -#include "qdatavis3denums.h" - -QT_DATAVIS3D_BEGIN_NAMESPACE - -class Q3DMaps; - -class Q3DMapsPrivate : public QObject -{ -public: - Q3DMapsPrivate(Q3DMaps *q, const QRect &rect); - ~Q3DMapsPrivate(); - - Q3DMaps *q_ptr; - Maps3DController *m_shared; -}; - -QT_DATAVIS3D_END_NAMESPACE - -#endif diff --git a/src/datavis3d/engine/scatter3drenderer.cpp b/src/datavis3d/engine/scatter3drenderer.cpp index 9759d658..ee5a6cf2 100644 --- a/src/datavis3d/engine/scatter3drenderer.cpp +++ b/src/datavis3d/engine/scatter3drenderer.cpp @@ -241,48 +241,6 @@ void Scatter3DRenderer::drawScene(CameraHelper *camera, GLfloat heightScaler = 0.0f; GLfloat widthScaler = 0.0f; GLfloat depthScaler = 0.0f; - // switch (m_adjustDirection) { - // case Q3DMaps::AdjustHeight: - // widthMultiplier = 0.0f; - // heightMultiplier = 1.0f; - // depthMultiplier = 0.0f; - // widthScaler = m_barThickness.x() / m_scaleFactor; - // heightScaler = 0.0f; - // depthScaler = m_barThickness.z() / m_scaleFactor; - // break; - // case Q3DMaps::AdjustWidth: - // widthMultiplier = 1.0f; - // heightMultiplier = 0.0f; - // depthMultiplier = 0.0f; - // widthScaler = 0.0f; - // heightScaler = m_barThickness.y() / m_scaleFactor; - // depthScaler = m_barThickness.z() / m_scaleFactor; - // break; - // case Q3DMaps::AdjustDepth: - // widthMultiplier = 0.0f; - // heightMultiplier = 0.0f; - // depthMultiplier = 1.0f; - // widthScaler = m_barThickness.x() / m_scaleFactor; - // heightScaler = m_barThickness.y() / m_scaleFactor; - // depthScaler = 0.0f; - // break; - // case Q3DMaps::AdjustRadius: - // widthMultiplier = 1.0f; - // heightMultiplier = 0.0f; - // depthMultiplier = 1.0f; - // widthScaler = 0.0f; - // heightScaler = m_barThickness.y() / m_scaleFactor; - // depthScaler = 0.0f; - // break; - // case Q3DMaps::AdjustAll: - // widthMultiplier = 1.0f; - // heightMultiplier = 1.0f; - // depthMultiplier = 1.0f; - // widthScaler = 0.0f; - // heightScaler = 0.0f; - // depthScaler = 0.0f; - // break; - // } // Introduce regardless of shadow quality to simplify logic QMatrix4x4 depthViewMatrix; diff --git a/src/datavis3d/engine/theme_p.h b/src/datavis3d/engine/theme_p.h index 034be3c2..4b36bdc4 100644 --- a/src/datavis3d/engine/theme_p.h +++ b/src/datavis3d/engine/theme_p.h @@ -51,7 +51,6 @@ private: friend class Abstract3DController; friend class Abstract3DRenderer; friend class Bars3DRenderer; - friend class Maps3DController; friend class Surface3DRenderer; friend class Surface3DController; friend class Scatter3DRenderer; diff --git a/src/datavis3d/utils/texturehelper_p.h b/src/datavis3d/utils/texturehelper_p.h index 561816e5..3acf387a 100644 --- a/src/datavis3d/utils/texturehelper_p.h +++ b/src/datavis3d/utils/texturehelper_p.h @@ -62,7 +62,6 @@ class TextureHelper : protected QOpenGLFunctions QRgb qt_gl_convertToGLFormatHelper(QRgb src_pixel, GLenum texture_format); friend class Bars3DRenderer; - friend class Maps3DController; friend class Surface3DRenderer; friend class Scatter3DRenderer; }; |