diff options
Diffstat (limited to 'src/datavis3dqml2')
-rw-r--r-- | src/datavis3dqml2/datavis3dqml2.pro | 30 | ||||
-rw-r--r-- | src/datavis3dqml2/datavis3dqml2_plugin.cpp | 67 | ||||
-rw-r--r-- | src/datavis3dqml2/datavis3dqml2_plugin.h | 82 | ||||
-rw-r--r-- | src/datavis3dqml2/declarativebars.cpp | 450 | ||||
-rw-r--r-- | src/datavis3dqml2/declarativebars.h | 233 | ||||
-rw-r--r-- | src/datavis3dqml2/declarativebars_p.h | 228 | ||||
-rw-r--r-- | src/datavis3dqml2/declarativebarsrenderer.cpp | 86 | ||||
-rw-r--r-- | src/datavis3dqml2/declarativebarsrenderer_p.h | 65 | ||||
-rw-r--r-- | src/datavis3dqml2/declarativemaps.cpp | 241 | ||||
-rw-r--r-- | src/datavis3dqml2/declarativemaps.h | 105 | ||||
-rw-r--r-- | src/datavis3dqml2/declarativemaps_p.h | 139 | ||||
-rw-r--r-- | src/datavis3dqml2/declarativemapsrenderer.cpp | 79 | ||||
-rw-r--r-- | src/datavis3dqml2/declarativemapsrenderer_p.h | 62 | ||||
-rw-r--r-- | src/datavis3dqml2/declarativescatter.cpp | 328 | ||||
-rw-r--r-- | src/datavis3dqml2/declarativescatter_p.h | 175 | ||||
-rw-r--r-- | src/datavis3dqml2/declarativescatterrenderer.cpp | 87 | ||||
-rw-r--r-- | src/datavis3dqml2/declarativescatterrenderer_p.h | 65 |
17 files changed, 1746 insertions, 776 deletions
diff --git a/src/datavis3dqml2/datavis3dqml2.pro b/src/datavis3dqml2/datavis3dqml2.pro index 59abef57..c994c5be 100644 --- a/src/datavis3dqml2/datavis3dqml2.pro +++ b/src/datavis3dqml2/datavis3dqml2.pro @@ -6,27 +6,33 @@ CONFIG += qt plugin TARGET = $$qtLibraryTarget($$TARGET) uri = com.digia.QtDataVis3D -staticlib:DEFINES+=QTENTERPRISE_DATAVIS3D_STATICLIB +static { + DEFINES += QT_DATAVIS3D_STATICLIB + CONFIG -= static staticlib +} # Input -INCLUDEPATH += ../datavis3d/engine +INCLUDEPATH += ../datavis3d/engine \ + ../datavis3d/global \ + ../datavis3d/data SOURCES += \ datavis3dqml2_plugin.cpp \ declarativebars.cpp \ - declarativemaps.cpp #\ - #declarativedataitem.cpp \ - #declarativedatarow.cpp \ - #declarativedataset.cpp + declarativebarsrenderer.cpp \ + declarativescatter.cpp \ + declarativescatterrenderer.cpp \ + declarativemaps.cpp \ + declarativemapsrenderer.cpp HEADERS += \ datavis3dqml2_plugin.h \ - declarativebars.h \ - declarativemaps.h \ #\ - declarativebars_p.h - #declarativedataitem.h \ - #declarativedatarow.h \ - #declarativedataset.h + declarativebars_p.h \ + declarativebarsrenderer_p.h \ + declarativescatter_p.h \ + declarativescatterrenderer_p.h \ + declarativemaps_p.h \ + declarativemapsrenderer_p.h OTHER_FILES = qmldir diff --git a/src/datavis3dqml2/datavis3dqml2_plugin.cpp b/src/datavis3dqml2/datavis3dqml2_plugin.cpp index 86923cde..d1e534f8 100644 --- a/src/datavis3dqml2/datavis3dqml2_plugin.cpp +++ b/src/datavis3dqml2/datavis3dqml2_plugin.cpp @@ -1,63 +1,48 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** 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. ** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the +** 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. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and Digia. ** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com ** ****************************************************************************/ #include "datavis3dqml2_plugin.h" #include <qqml.h> -#include <QDebug> -QTENTERPRISE_DATAVIS3D_BEGIN_NAMESPACE + +QT_DATAVIS3D_BEGIN_NAMESPACE void Datavis3dqml2Plugin::registerTypes(const char *uri) { - qDebug() << "Datavis3dqml2Plugin::registerTypes()"; - // @uri com.digia.QtDataVis3D - qmlRegisterType<QDataItem>(uri, 1, 0, "DataItem"); - qmlRegisterType<QDataRow>(uri, 1, 0, "DataRow"); - qmlRegisterType<QDataSet>(uri, 1, 0, "DataSet"); + qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel", + QLatin1String("Trying to create uncreatable: AbstractItemModel.")); + qmlRegisterUncreatableType<QDataVis>(uri, 1, 0, "DataVis", + QLatin1String("Trying to create uncreatable: DataVis.")); + qmlRegisterUncreatableType<QAbstractAxis>(uri, 1, 0, "AbstractAxis", + QLatin1String("Trying to create uncreatable: AbstractAxis.")); + + qmlRegisterType<QItemModelBarDataMapping>(uri, 1, 0, "BarDataMapping"); + qmlRegisterType<QItemModelMapDataMapping>(uri, 1, 0, "MapDataMapping"); + qmlRegisterType<QItemModelScatterDataMapping>(uri, 1, 0, "ScatterDataMapping"); qmlRegisterType<DeclarativeBars>(uri, 1, 0, "Bars3D"); -} + qmlRegisterType<DeclarativeMaps>(uri, 1, 0, "Maps3D"); + qmlRegisterType<DeclarativeScatter>(uri, 1, 0, "Scatter3D"); -//#include "moc_datavis3dqml2_plugin.cpp" + qmlRegisterType<QValueAxis>(uri, 1, 0, "ValueAxis"); + qmlRegisterType<QCategoryAxis>(uri, 1, 0, "CategoryAxis"); +} -QTENTERPRISE_DATAVIS3D_END_NAMESPACE +QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3dqml2/datavis3dqml2_plugin.h b/src/datavis3dqml2/datavis3dqml2_plugin.h index 9dcf00cb..ac88e1b5 100644 --- a/src/datavis3dqml2/datavis3dqml2_plugin.h +++ b/src/datavis3dqml2/datavis3dqml2_plugin.h @@ -1,75 +1,53 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** 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. ** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the +** 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. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and Digia. ** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com ** ****************************************************************************/ #ifndef DATAVIS3DQML2_PLUGIN_H #define DATAVIS3DQML2_PLUGIN_H -#include "QtDataVis3D/qdatavis3dglobal.h" -#include "QtDataVis3D/qdatavis3namespace.h" -#include "qdataitem.h" -#include "qdatarow.h" -#include "qdataset.h" - -#include "declarativebars.h" -#include "declarativemaps.h" -//#include "declarativedataitem.h" -//#include "declarativedatarow.h" -//#include "declarativedataset.h" +#include "datavis3dglobal_p.h" +#include "declarativebars_p.h" +#include "declarativemaps_p.h" +#include "declarativescatter_p.h" +#include "qitemmodelbardatamapping.h" +#include "qitemmodelmapdatamapping.h" +#include "qitemmodelscatterdatamapping.h" +#include "qvalueaxis.h" +#include "qcategoryaxis.h" #include <QQmlExtensionPlugin> -QTENTERPRISE_DATAVIS3D_USE_NAMESPACE - -//Q_DECLARE_METATYPE(DeclarativeDataItem *) -//Q_DECLARE_METATYPE(DeclarativeDataRow *) -//Q_DECLARE_METATYPE(DeclarativeDataSet *) +QT_DATAVIS3D_USE_NAMESPACE Q_DECLARE_METATYPE(DeclarativeBars *) Q_DECLARE_METATYPE(DeclarativeMaps *) +Q_DECLARE_METATYPE(DeclarativeScatter *) + +Q_DECLARE_METATYPE(QItemModelBarDataMapping *) +Q_DECLARE_METATYPE(QItemModelMapDataMapping *) +Q_DECLARE_METATYPE(QItemModelScatterDataMapping *) +Q_DECLARE_METATYPE(QAbstractItemModel *) +Q_DECLARE_METATYPE(QDataVis *) -Q_DECLARE_METATYPE(QDataItem *) -Q_DECLARE_METATYPE(QDataRow *) -Q_DECLARE_METATYPE(QDataSet *) +Q_DECLARE_METATYPE(QAbstractAxis *) +Q_DECLARE_METATYPE(QCategoryAxis *) +Q_DECLARE_METATYPE(QValueAxis *) -QTENTERPRISE_DATAVIS3D_BEGIN_NAMESPACE +QT_DATAVIS3D_BEGIN_NAMESPACE class Datavis3dqml2Plugin : public QQmlExtensionPlugin { @@ -80,7 +58,7 @@ public: void registerTypes(const char *uri); }; -QTENTERPRISE_DATAVIS3D_END_NAMESPACE +QT_DATAVIS3D_END_NAMESPACE #endif // DATAVIS3DQML2_PLUGIN_H diff --git a/src/datavis3dqml2/declarativebars.cpp b/src/datavis3dqml2/declarativebars.cpp index 3194baa5..e7af7f8c 100644 --- a/src/datavis3dqml2/declarativebars.cpp +++ b/src/datavis3dqml2/declarativebars.cpp @@ -1,63 +1,50 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** 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. ** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the +** 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. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and Digia. ** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com ** ****************************************************************************/ -#include "declarativebars.h" -#include "bars3dshared_p.h" +#include "declarativebars_p.h" +#include "declarativebarsrenderer_p.h" +#include "qitemmodelbardataproxy.h" +#include "qvalueaxis.h" -#include <QtQuick/QQuickWindow> -#include <QtGui/QOpenGLFramebufferObject> -#include <QOpenGLContext> -#include <QGuiApplication> -#include <QThread> -#include <QDebug> +QT_DATAVIS3D_BEGIN_NAMESPACE -QTENTERPRISE_DATAVIS3D_BEGIN_NAMESPACE +const QString smoothString(QStringLiteral("Smooth")); -DeclarativeBars::DeclarativeBars(QQuickItem *parent): QQuickItem(parent), m_cachedState(new DeclarativeBarsCachedStatePrivate()), m_shared(0) +DeclarativeBars::DeclarativeBars(QQuickItem *parent) + : QQuickItem(parent), + m_shared(0), + m_initialisedSize(0, 0), + m_cameraPreset(QDataVis::NoPreset), + m_theme(QDataVis::ThemeDefault) { setFlags(QQuickItem::ItemHasContents); + setAcceptedMouseButtons(Qt::AllButtons); - setRotation(180.0); + // TODO: These seem to have no effect; find a way to activate anti-aliasing setAntialiasing(true); setSmooth(true); + + // Create the shared component on the main GUI thread. + m_shared = new Bars3dController(boundingRect().toRect()); + QObject::connect(m_shared, &Bars3dController::shadowQualityChanged, this, + &DeclarativeBars::handleShadowQualityUpdate); + + m_shared->setDataProxy(new QItemModelBarDataProxy); } DeclarativeBars::~DeclarativeBars() @@ -65,316 +52,329 @@ DeclarativeBars::~DeclarativeBars() delete m_shared; } -QSGNode *DeclarativeBars::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) +void DeclarativeBars::handleShadowQualityUpdate(QDataVis::ShadowQuality quality) { - qDebug() << "Enter DeclarativeBars::updatePaintNode"; - // Delete old node and recreate it. This function gets called when window geometry changes. - if (oldNode) - delete oldNode; - - if (!m_shared) - m_shared = new Bars3dShared(boundingRect().toRect()); - - // Lazy initialization of shared object on the SGRenderThread - m_shared->initializeOpenGL(); - - // We need to create a node class that does the rendering (ie. a node that "captures" the rendering we do) - qDebug() << "DeclarativeBars::updatePaintNode Creating new node"; - - // Create the new render node - DeclarativeBarsRenderer *node = new DeclarativeBarsRenderer(window(), m_shared); - node->setRect(boundingRect()); - m_shared->setBoundingRect(boundingRect().toRect()); - - if (m_cachedState->m_isSampleSpaceSet) { - m_shared->setupSampleSpace(m_cachedState->m_samplesRow, m_cachedState->m_samplesColumn, m_cachedState->m_labelRow, m_cachedState->m_labelColumn, m_cachedState->m_labelHeight); - m_cachedState->m_isSampleSpaceSet = false; - } + emit shadowQualityChanged(quality); +} - if (m_cachedState->m_dataRow) { - m_shared->addDataRow(m_cachedState->m_dataRow); - m_cachedState->m_dataRow = 0; - } +void DeclarativeBars::classBegin() +{ + qDebug() << "classBegin"; +} - if (m_cachedState->m_isSelectionModeSet) { - m_shared->setSelectionMode(m_cachedState->m_selectionMode); - m_cachedState->m_isSelectionModeSet = false; - } +void DeclarativeBars::componentComplete() +{ + qDebug() << "componentComplete"; +} - if (m_cachedState->m_isLabelTransparencySet) { - m_shared->setLabelTransparency(m_cachedState->m_labelTransparency); - m_cachedState->m_isLabelTransparencySet = false; +QSGNode *DeclarativeBars::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) +{ + // If old node exists and has right size, reuse it. + if (oldNode && m_initialisedSize == boundingRect().size().toSize()) { + // Update bounding rectangle (that has same size as before). + static_cast<DeclarativeBarsRenderer *>( oldNode )->setRect(boundingRect()); + return oldNode; } - if (m_cachedState->m_isShadowQualitySet) { - m_shared->setShadowQuality(m_cachedState->m_shadowQuality); - m_cachedState->m_isShadowQualitySet = false; - } + // Create a new render node when size changes or if there is no node yet + m_initialisedSize = boundingRect().size().toSize(); - if (m_cachedState->m_isGridSet) { - m_shared->setGridEnabled(m_cachedState->m_isGridEnabled); - m_cachedState->m_isGridSet = false; - } + // Delete old node + if (oldNode) + delete oldNode; - qDebug() << "Exit DeclarativeBars::updatePaintNode"; + // Create a new one and set it's bounding rectangle + DeclarativeBarsRenderer *node = new DeclarativeBarsRenderer(window(), m_shared); + node->setRect(boundingRect()); + m_shared->setBoundingRect(boundingRect().toRect()); return node; } -void DeclarativeBars::setBarSpecs(QSizeF thickness, QSizeF spacing, bool relative) +void DeclarativeBars::setupSampleSpace(int rowCount, int columnCount) { - m_shared->setBarSpecs(thickness, spacing, relative); + m_shared->setupSampleSpace(rowCount, columnCount); } -void DeclarativeBars::setBarType(BarStyle style, bool smooth) +void DeclarativeBars::setBarColor(QColor baseColor, QColor heightColor, QColor depthColor, + bool uniform) { - m_shared->setBarType(style, smooth); + m_shared->setObjectColor(baseColor, heightColor, depthColor, uniform); } -void DeclarativeBars::setupSampleSpace(int samplesRow, int samplesColumn, const QString &labelRow, - const QString &labelColumn, const QString &labelHeight) +void DeclarativeBars::setCameraPosition(qreal horizontal, qreal vertical, int distance) { - m_cachedState->m_samplesRow = samplesRow; - m_cachedState->m_samplesColumn = samplesColumn; - m_cachedState->m_labelRow = labelRow; - m_cachedState->m_labelColumn = labelColumn; - m_cachedState->m_labelHeight = labelHeight; - m_cachedState->m_isSampleSpaceSet = true; + m_shared->setCameraPosition(GLfloat(horizontal), GLfloat(vertical), GLint(distance)); } - -void DeclarativeBars::setCameraPreset(CameraPreset preset) +void DeclarativeBars::setData(QAbstractItemModel *data) { - m_shared->setCameraPreset(preset); + static_cast<QItemModelBarDataProxy *>(m_shared->dataProxy())->setItemModel(data); } -void DeclarativeBars::setCameraPosition(GLfloat horizontal, GLfloat vertical, GLint distance) +QAbstractItemModel *DeclarativeBars::data() { - m_shared->setCameraPosition(horizontal, vertical, distance); + return static_cast<QItemModelBarDataProxy *>(m_shared->dataProxy())->itemModel(); } -void DeclarativeBars::setTheme(ColorTheme theme) +void DeclarativeBars::setMapping(QItemModelBarDataMapping *mapping) { - m_shared->setTheme(theme); + static_cast<QItemModelBarDataProxy *>(m_shared->dataProxy())->setMapping(mapping); } -void DeclarativeBars::setBarColor(QColor baseColor, QColor heightColor, QColor depthColor, bool uniform) +QCategoryAxis *DeclarativeBars::axisX() const { - m_shared->setBarColor(baseColor, heightColor, depthColor, uniform); + return static_cast<QCategoryAxis *>(m_shared->axisX()); } +void DeclarativeBars::setAxisX(QCategoryAxis *axis) +{ + m_shared->setAxisX(axis); +} -void DeclarativeBars::setFontSize(float fontsize) +QValueAxis *DeclarativeBars::axisY() const { - m_shared->setFontSize(fontsize); + return static_cast<QValueAxis *>(m_shared->axisY()); } -float DeclarativeBars::fontSize() +void DeclarativeBars::setAxisY(QValueAxis *axis) { - return m_shared->fontSize(); + m_shared->setAxisY(axis); } -void DeclarativeBars::setFont(const QFont &font) +QCategoryAxis *DeclarativeBars::axisZ() const { - m_shared->setFont(font); + return static_cast<QCategoryAxis *>(m_shared->axisZ()); } -QFont DeclarativeBars::font() +void DeclarativeBars::setAxisZ(QCategoryAxis *axis) { - return m_shared->font(); + m_shared->setAxisZ(axis); } -void DeclarativeBars::setLabelTransparency(DeclarativeBars::LabelTransparency transparency) +QItemModelBarDataMapping *DeclarativeBars::mapping() const { - m_cachedState->m_labelTransparency = QtDataVis3D::LabelTransparency(transparency); - m_cachedState->m_isLabelTransparencySet = true; + return static_cast<QItemModelBarDataProxy *>(m_shared->dataProxy())->mapping(); } -DeclarativeBars::LabelTransparency DeclarativeBars::labelTransparency() +void DeclarativeBars::setBarThickness(QSizeF thickness) { - return DeclarativeBars::LabelTransparency(m_shared->labelTransparency()); + m_shared->setBarSpecs(thickness, barSpacing(), isBarSpacingRelative()); } -void DeclarativeBars::setGridEnabled(bool enable) +QSizeF DeclarativeBars::barThickness() { - m_cachedState->m_isGridEnabled = enable; - m_cachedState->m_isGridSet = true; + return m_shared->barThickness(); } -bool DeclarativeBars::gridEnabled() +void DeclarativeBars::setBarSpacing(QSizeF spacing) { - return m_shared->gridEnabled(); + m_shared->setBarSpecs(barThickness(), spacing, isBarSpacingRelative()); } -void DeclarativeBars::setBackgroundEnabled(bool enable) +QSizeF DeclarativeBars::barSpacing() { - m_shared->setBackgroundEnabled(enable); + return m_shared->barSpacing(); } -bool DeclarativeBars::backgroundEnabled() +void DeclarativeBars::setBarSpacingRelative(bool relative) { - return m_shared->backgroundEnabled(); + m_shared->setBarSpecs(barThickness(), barSpacing(), relative); } -void DeclarativeBars::setTickCount(GLint tickCount, GLfloat step, GLfloat minimum) +bool DeclarativeBars::isBarSpacingRelative() { - m_shared->setTickCount(tickCount, step, minimum); + return m_shared->isBarSpecRelative(); } -void DeclarativeBars::addDataRow(const QVector<float> &dataRow, const QString &labelRow, - const QVector<QString> &labelsColumn) +void DeclarativeBars::setBarType(QDataVis::MeshStyle style) { - qDebug() << "Enter DeclarativeBars::addDataRow(const QVector<float> &dataRow...)"; - m_shared->addDataRow(dataRow, labelRow, labelsColumn); + QString objFile = m_shared->meshFileName(); + bool smooth = objFile.endsWith(smoothString); + m_shared->setBarType(style, smooth); } -void DeclarativeBars::addDataRow(const QVector<QDataItem*> &dataRow, const QString &labelRow, - const QVector<QString> &labelsColumn) +QDataVis::MeshStyle DeclarativeBars::barType() { - qDebug() << "Enter DeclarativeBars::addDataRow(const QVector<QDataItem*> &dataRow...)"; - m_shared->addDataRow(dataRow, labelRow, labelsColumn); + QString objFile = m_shared->meshFileName(); + if (objFile.contains("/sphere")) + return QDataVis::Spheres; + else + return QDataVis::Dots; } -void DeclarativeBars::addDataRow(QDataRow *dataRow) +void DeclarativeBars::setBarSmooth(bool smooth) { - qDebug() << "Enter DeclarativeBars::addDataRow(QDataRow *dataRow)"; - m_cachedState->m_dataRow = dataRow; + QString objFile = m_shared->meshFileName(); + if (objFile.endsWith(smoothString)) { + if (smooth) + return; // Already smooth; do nothing + else // Rip Smooth off the end + objFile.resize(objFile.indexOf(smoothString)); + } else { + if (!smooth) // Already flat; do nothing + return; + else // Append Smooth to the end + objFile.append(smoothString); + } + m_shared->setMeshFileName(objFile); } -void DeclarativeBars::addDataSet(const QVector< QVector<float> > &data, const QVector<QString> &labelsRow, - const QVector<QString> &labelsColumn) +bool DeclarativeBars::barSmooth() { - m_shared->addDataSet(data, labelsRow,labelsColumn); + QString objFile = m_shared->meshFileName(); + return objFile.endsWith(smoothString); } -void DeclarativeBars::addDataSet(const QVector< QVector<QDataItem*> > &data, - const QVector<QString> &labelsRow, - const QVector<QString> &labelsColumn) +void DeclarativeBars::setMeshFileName(const QString &objFileName) { - m_shared->addDataSet(data, labelsRow, labelsColumn); + m_shared->setMeshFileName(objFileName); } -void DeclarativeBars::addDataSet(QDataSet* dataSet) +QString DeclarativeBars::meshFileName() { - m_shared->addDataSet(dataSet); + return m_shared->meshFileName(); } -void DeclarativeBars::setSelectionMode(DeclarativeBars::SelectionMode mode) +void DeclarativeBars::setCameraPreset(QDataVis::CameraPreset preset) { - m_cachedState->m_selectionMode = QtDataVis3D::SelectionMode(mode); - m_cachedState->m_isSelectionModeSet = true; + // TODO: Implement correctly once "improved camera api" (QTRD-2122) is implemented + // We need to save this locally, as there are no getters for it in controller + m_cameraPreset = preset; + m_shared->setCameraPreset(preset); } -DeclarativeBars::SelectionMode DeclarativeBars::selectionMode() +QDataVis::CameraPreset DeclarativeBars::cameraPreset() { - return DeclarativeBars::SelectionMode(m_shared->selectionMode()); + return m_cameraPreset; } -void DeclarativeBars::setShadow(DeclarativeBars::ShadowQuality quality) +void DeclarativeBars::setTheme(QDataVis::ColorTheme theme) { - m_cachedState->m_shadowQuality = QtDataVis3D::ShadowQuality(quality); - m_cachedState->m_isShadowQualitySet = true; + // TODO: Implement correctly once "user-modifiable themes" (QTRD-2120) is implemented + // We need to save this locally, as there are no getters for it in controller + m_theme = theme; + m_shared->setColorTheme(theme); } -DeclarativeBars::ShadowQuality DeclarativeBars::shadow() +QDataVis::ColorTheme DeclarativeBars::theme() { - return DeclarativeBars::ShadowQuality(m_shared->shadowQuality()); + return m_theme; } -void DeclarativeBars::setMeshFileName(const QString &objFileName) +void DeclarativeBars::setFontSize(float fontsize) { - m_shared->setMeshFileName(objFileName); + m_shared->setFontSize(fontsize); } +float DeclarativeBars::fontSize() +{ + return m_shared->fontSize(); +} +void DeclarativeBars::setFont(const QFont &font) +{ + m_shared->setFont(font); +} +QFont DeclarativeBars::font() +{ + return m_shared->font(); +} -DeclarativeBarsRenderer::DeclarativeBarsRenderer(QQuickWindow *window, Bars3dShared *renderer) - : m_fbo(0), - m_texture(0), - m_window(window), - m_barsRenderer(renderer) +void DeclarativeBars::setLabelTransparency(QDataVis::LabelTransparency transparency) { - qDebug() << "DeclarativeBarsRenderer::DeclarativeBarsRenderer()"; - connect(m_window, SIGNAL(beforeRendering()), this, SLOT(render()), Qt::DirectConnection); - qDebug() << "QQuickWindow::openglContext()->thread()" << m_window->openglContext()->thread(); - qDebug() << "QGuiApplication::instance()->thread()" << QGuiApplication::instance()->thread(); + m_shared->setLabelTransparency(transparency); } -DeclarativeBarsRenderer::~DeclarativeBarsRenderer() +QDataVis::LabelTransparency DeclarativeBars::labelTransparency() { - delete m_texture; - delete m_fbo; + return m_shared->labelTransparency(); } -void DeclarativeBarsRenderer::render() +void DeclarativeBars::setGridVisible(bool visible) { - static bool firstRender = true; - if (firstRender) qDebug() << "DeclarativeBarsRenderer::render() running on thread "<< QThread::currentThread(); - firstRender = false; + m_shared->setGridEnabled(visible); +} - QSize size = rect().size().toSize(); +bool DeclarativeBars::isGridVisible() +{ + return m_shared->gridEnabled(); +} - if (!m_fbo) { - QOpenGLFramebufferObjectFormat format; - format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); - m_fbo = new QOpenGLFramebufferObject(size, format); - m_texture = m_window->createTextureFromId(m_fbo->texture(), size); +void DeclarativeBars::setBackgroundVisible(bool visible) +{ + m_shared->setBackgroundEnabled(visible); +} - // TODO: If we create the vis3d this way, how do we connect it with QML? - // Should we create it at QML and give it to DataVisView using a property (setVisualizer or similar)? - // DataVisView can then give it here as an argument in constructor? +bool DeclarativeBars::isBackgroundVisible() +{ + return m_shared->backgroundEnabled(); +} - // TODO: For testing. Add some data to scene. - QVector< QVector<float> > data; - QVector<float> row; - for (float j = 0.0f; j < 5.0f; j++) { - for (float i = 0.0f; i < 5.0f; i++) - row.append(j / 10.0f + i / 10.0f); - data.append(row); - row.clear(); - } +void DeclarativeBars::setSelectionMode(QDataVis::SelectionMode mode) +{ + m_shared->setSelectionMode(mode); +} - setTexture(m_texture); - } +QDataVis::SelectionMode DeclarativeBars::selectionMode() +{ + return m_shared->selectionMode(); +} - m_fbo->bind(); +void DeclarativeBars::setShadowQuality(QDataVis::ShadowQuality quality) +{ + m_shared->setShadowQuality(quality); +} - // SGRendering State resets between calls... - glDepthMask(true); - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_LESS); - glEnable(GL_CULL_FACE); - glCullFace(GL_BACK); +QDataVis::ShadowQuality DeclarativeBars::shadowQuality() +{ + return m_shared->shadowQuality(); +} - // Emulate mouse movement - // TODO: Remove this and implement properly - static int rot = 0; - rot += 5; - if (rot > 2870) rot = 0; - m_barsRenderer->m_mousePos.setX(rot); - m_barsRenderer->m_mousePos.setY(100); +int DeclarativeBars::rows() const +{ + return m_shared->rowCount(); +} - // Call the shared rendering function - m_barsRenderer->render(); +void DeclarativeBars::setRows(int rows) +{ + setupSampleSpace(rows, columns()); +} - m_fbo->bindDefault(); +int DeclarativeBars::columns() const +{ + return m_shared->columnCount(); +} - m_window->update(); +void DeclarativeBars::setColumns(int columns) +{ + setupSampleSpace(rows(), columns); } +void DeclarativeBars::mousePressEvent(QMouseEvent *event) +{ + QPoint mousePos = event->pos(); + //mousePos.setY(height() - mousePos.y()); + m_shared->mousePressEvent(event, mousePos); +} -DeclarativeBarsCachedStatePrivate::DeclarativeBarsCachedStatePrivate() : - m_isSampleSpaceSet(false), - m_labelRow(QStringLiteral("")), - m_labelColumn(QStringLiteral("")), - m_labelHeight(QStringLiteral("")), - m_dataRow(0) +void DeclarativeBars::mouseReleaseEvent(QMouseEvent *event) { + QPoint mousePos = event->pos(); + //mousePos.setY(height() - mousePos.y()); + m_shared->mouseReleaseEvent(event, mousePos); } -DeclarativeBarsCachedStatePrivate::~DeclarativeBarsCachedStatePrivate() +void DeclarativeBars::mouseMoveEvent(QMouseEvent *event) { + QPoint mousePos = event->pos(); + //mousePos.setY(height() - mousePos.y()); + m_shared->mouseMoveEvent(event, mousePos); } +void DeclarativeBars::wheelEvent(QWheelEvent *event) +{ + m_shared->wheelEvent(event); +} -QTENTERPRISE_DATAVIS3D_END_NAMESPACE +QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3dqml2/declarativebars.h b/src/datavis3dqml2/declarativebars.h deleted file mode 100644 index 8194cd7d..00000000 --- a/src/datavis3dqml2/declarativebars.h +++ /dev/null @@ -1,233 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtDataVis3D module. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef DECLARATIVEBARS_H -#define DECLARATIVEBARS_H - -#include "bars3dshared_p.h" -#include "qdatavis3dglobal.h" -#include "qdatavis3namespace.h" -#include "declarativebars_p.h" - -#include <qsgsimpletexturenode.h> -#include <QQuickItem> -#include <QObject> - -class QOpenGLFramebufferObject; -class QSGTexture; -class QQuickWindow; - -QTENTERPRISE_DATAVIS3D_BEGIN_NAMESPACE - -class DeclarativeBars : public QQuickItem -{ - Q_OBJECT - Q_PROPERTY(SelectionMode selectionMode READ selectionMode WRITE setSelectionMode) - Q_PROPERTY(LabelTransparency labelTransparency READ labelTransparency WRITE setLabelTransparency) - Q_PROPERTY(ShadowQuality shadowQuality READ shadow WRITE setShadow) - Q_PROPERTY(bool grid READ gridEnabled WRITE setGridEnabled) - Q_PROPERTY(int width READ width WRITE setWidth) - Q_PROPERTY(int height READ height WRITE setHeight) - Q_ENUMS(SelectionMode) - Q_ENUMS(ShadowQuality) - Q_ENUMS(LabelTransparency) - -protected: - Bars3dShared *m_shared; - DeclarativeBarsCachedStatePrivate *m_cachedState; - -public: - // Duplicated here to be able to use the same enums - enum SelectionMode { - ModeNone = 0, - ModeBar, - ModeBarAndRow, - ModeBarAndColumn, - ModeBarRowAndColumn, - ModeZoomRow, - ModeZoomColumn - }; - - enum ShadowQuality { - ShadowNone = 0, - ShadowLow = 1, - ShadowMedium = 3, - ShadowHigh = 5 - }; - - enum LabelTransparency { - TransparencyNone = 0, // Full solid, using colors from theme - TransparencyFromTheme, // Use colors and transparencies from theme - TransparencyNoBackground // Draw just text on transparent background - }; - -public: - explicit DeclarativeBars(QQuickItem *parent = 0); - ~DeclarativeBars(); - - // Add a row of data. Each new row is added to the front of the sample space, moving previous - // rows back (if sample space is more than one row deep) - Q_INVOKABLE void addDataRow(const QVector<GLfloat> &dataRow, - const QString &labelRow = QString(), - const QVector<QString> &labelsColumn = QVector<QString>()); - // ownership of dataItems is transferred - Q_INVOKABLE void addDataRow(const QVector<QDataItem*> &dataRow, - const QString &labelRow = QString(), - const QVector<QString> &labelsColumn = QVector<QString>()); - // ownership of dataRow is transferred - Q_INVOKABLE void addDataRow(QDataRow *dataRow); - - // Add complete data set at a time, as a vector of data rows - Q_INVOKABLE void addDataSet(const QVector< QVector<GLfloat> > &data, - const QVector<QString> &labelsRow = QVector<QString>(), - const QVector<QString> &labelsColumn = QVector<QString>()); - - // ownership of dataItems is transferred - Q_INVOKABLE void addDataSet(const QVector< QVector<QDataItem*> > &data, - const QVector<QString> &labelsRow = QVector<QString>(), - const QVector<QString> &labelsColumn = QVector<QString>()); - // ownership of dataSet is transferred - Q_INVOKABLE void addDataSet(QDataSet* dataSet); - - // bar thickness, spacing between bars, and is spacing relative to thickness or absolute - // y -component sets the thickness/spacing of z -direction - // With relative 0.0f means side-to-side, 1.0f = one thickness in between - Q_INVOKABLE void setBarSpecs(QSizeF thickness = QSizeF(1.0f, 1.0f), - QSizeF spacing = QSizeF(1.0f, 1.0f), - bool relative = true); - - // bar type; bars (=cubes), pyramids, cones, cylinders, etc. - Q_INVOKABLE void setBarType(BarStyle style, bool smooth = false); - - // override bar type with own mesh - Q_INVOKABLE void setMeshFileName(const QString &objFileName); - - // how many samples per row and column, and names for axes - Q_INVOKABLE void setupSampleSpace(int samplesRow, int samplesColumn, - const QString &labelRow = QString(), - const QString &labelColumn = QString(), - const QString &labelHeight = QString()); - - // Select preset camera placement - Q_INVOKABLE void setCameraPreset(CameraPreset preset); - - // Set camera rotation if you don't want to use the presets (in horizontal (-180...180) and - // vertical (0...90) (or (-90...90) if there are negative values) angles and distance in - // percentage (10...500)) - Q_INVOKABLE void setCameraPosition(GLfloat horizontal, GLfloat vertical, GLint distance = 100); - - // Set theme (bar colors, shaders, window color, background colors, light intensity and text - // colors are affected) - Q_INVOKABLE void setTheme(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 - Q_INVOKABLE void setBarColor(QColor baseColor, QColor heightColor, QColor depthColor, - bool uniform = true); - - // Set tick count and step. Note; tickCount * step should be the maximum possible value of data - // set. Minimum is the absolute minimum possible value a bar can have. This is especially - // important to set if values can be negative. - Q_INVOKABLE void setTickCount(GLint tickCount, GLfloat step, GLfloat minimum = 0.0f); - - // TODO: light placement API - - // Change selection mode; single bar, bar and row, bar and column, or all - void setSelectionMode(SelectionMode mode); - SelectionMode selectionMode(); - - // Font size adjustment - void setFontSize(float fontsize); - float fontSize(); - - // Set font - void setFont(const QFont &font); - QFont font(); - - // Label transparency adjustment - void setLabelTransparency(LabelTransparency transparency); - LabelTransparency labelTransparency(); - - // Enable or disable background grid - void setGridEnabled(bool enable); - bool gridEnabled(); - - // Enable or disable background mesh - void setBackgroundEnabled(bool enable); - bool backgroundEnabled(); - - // Adjust shadow quality - void setShadowQuality(ShadowQuality quality); - ShadowQuality shadowQuality(); - - // Adjust shadow quality - void setShadow(DeclarativeBars::ShadowQuality quality); - DeclarativeBars::ShadowQuality shadow(); - - protected: - QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *); - -}; - -// TODO: If we use texture node, our rendering is done into a texture that is then drawn to the -// qquickwindow -> selection will not work -class DeclarativeBarsRenderer : public QObject, public QSGSimpleTextureNode -{ - Q_OBJECT - -public: - DeclarativeBarsRenderer(QQuickWindow *window, Bars3dShared *shared); - ~DeclarativeBarsRenderer(); - -public slots: - void render(); - -private: - QOpenGLFramebufferObject *m_fbo; - QSGTexture *m_texture; - QQuickWindow *m_window; - Bars3dShared *m_barsRenderer; -}; - -QTENTERPRISE_DATAVIS3D_END_NAMESPACE -QTENTERPRISE_DATAVIS3D_USE_NAMESPACE - -#endif diff --git a/src/datavis3dqml2/declarativebars_p.h b/src/datavis3dqml2/declarativebars_p.h index 62dcc708..07dc21d4 100644 --- a/src/datavis3dqml2/declarativebars_p.h +++ b/src/datavis3dqml2/declarativebars_p.h @@ -1,41 +1,18 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** 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. ** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the +** 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. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and Digia. ** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com ** ****************************************************************************/ @@ -43,7 +20,7 @@ // W A R N I N G // ------------- // -// This file is not part of the Qt API. It exists purely as an +// 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. // @@ -52,45 +29,178 @@ #ifndef DECLARATIVEBARS_P_H #define DECLARATIVEBARS_P_H -#include "QtDataVis3D/qdatavis3dglobal.h" -#include "QtDataVis3D/qdatavis3namespace.h" -#include <QString> +#include "datavis3dglobal_p.h" +#include "bars3dcontroller_p.h" +#include "declarativebars_p.h" +#include "qitemmodelbardatamapping.h" +#include "qvalueaxis.h" +#include "qcategoryaxis.h" -QTENTERPRISE_DATAVIS3D_BEGIN_NAMESPACE +#include <QAbstractItemModel> +#include <QQuickItem> +#include <QObject> +#include <QQuickWindow> -class QDataRow; +QT_DATAVIS3D_BEGIN_NAMESPACE -class DeclarativeBarsCachedStatePrivate +class DeclarativeBars : public QQuickItem { + Q_OBJECT + Q_PROPERTY(QAbstractItemModel *data READ data WRITE setData) + Q_PROPERTY(QItemModelBarDataMapping *mapping READ mapping WRITE setMapping) + Q_PROPERTY(QCategoryAxis *axisX READ axisX WRITE setAxisX) + Q_PROPERTY(QValueAxis *axisY READ axisY WRITE setAxisY) + Q_PROPERTY(QCategoryAxis *axisZ READ axisZ WRITE setAxisZ) + Q_PROPERTY(QtDataVis3D::QDataVis::SelectionMode selectionMode READ selectionMode WRITE setSelectionMode) + Q_PROPERTY(QtDataVis3D::QDataVis::LabelTransparency labelTransparency READ labelTransparency WRITE setLabelTransparency) + Q_PROPERTY(QtDataVis3D::QDataVis::ShadowQuality shadowQuality READ shadowQuality WRITE setShadowQuality) + Q_PROPERTY(QtDataVis3D::QDataVis::MeshStyle barType READ barType WRITE setBarType) + Q_PROPERTY(QtDataVis3D::QDataVis::CameraPreset cameraPreset READ cameraPreset WRITE setCameraPreset) + Q_PROPERTY(QtDataVis3D::QDataVis::ColorTheme theme READ theme WRITE setTheme) + Q_PROPERTY(QSizeF barThickness READ barThickness WRITE setBarThickness) + Q_PROPERTY(QSizeF barSpacing READ barSpacing WRITE setBarSpacing) + Q_PROPERTY(bool barSpacingRelative READ isBarSpacingRelative WRITE setBarSpacingRelative) + Q_PROPERTY(bool barSmooth READ barSmooth WRITE setBarSmooth) + Q_PROPERTY(QString meshFileName READ meshFileName WRITE setMeshFileName) + Q_PROPERTY(QFont font READ font WRITE setFont) + Q_PROPERTY(float fontSize READ fontSize WRITE setFontSize) + Q_PROPERTY(bool gridVisible READ isGridVisible WRITE setGridVisible) + Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible) + Q_PROPERTY(int rows READ rows WRITE setRows) + Q_PROPERTY(int columns READ columns WRITE setColumns) + Q_ENUMS(QtDataVis3D::QDataVis::SelectionMode) + Q_ENUMS(QtDataVis3D::QDataVis::ShadowQuality) + Q_ENUMS(QtDataVis3D::QDataVis::LabelTransparency) + Q_ENUMS(QtDataVis3D::QDataVis::MeshStyle) + Q_ENUMS(QtDataVis3D::QDataVis::CameraPreset) + Q_ENUMS(QtDataVis3D::QDataVis::ColorTheme) + public: - explicit DeclarativeBarsCachedStatePrivate(); - ~DeclarativeBarsCachedStatePrivate(); + explicit DeclarativeBars(QQuickItem *parent = 0); + ~DeclarativeBars(); + + void classBegin(); + void componentComplete(); + + // how many samples per row and column + Q_INVOKABLE void setupSampleSpace(int rowCount, int columnCount); + + // 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 + Q_INVOKABLE void setBarColor(QColor baseColor, QColor heightColor, QColor depthColor, + bool uniform = true); + + // Set camera rotation if you don't want to use the presets (in horizontal (-180...180) and + // vertical (0...90) (or (-90...90) if there are negative values) angles and distance in + // percentage (10...500)) + Q_INVOKABLE void setCameraPosition(qreal horizontal, qreal vertical, int distance); + + // Add whole data set. + void setData(QAbstractItemModel *data); + QAbstractItemModel *data(); + + QItemModelBarDataMapping *mapping() const; + void setMapping(QItemModelBarDataMapping *mapping); + + QCategoryAxis *axisX() const; + void setAxisX(QCategoryAxis *axis); + QValueAxis *axisY() const; + void setAxisY(QValueAxis *axis); + QCategoryAxis *axisZ() const; + void setAxisZ(QCategoryAxis *axis); + + // Set bar thickness. Y -component sets the thickness of z -direction. + void setBarThickness(QSizeF thickness); + QSizeF barThickness(); + + // Set spacing between bars. Y -component sets the spacing of z -direction. + // If spacing is relative, 0.0f means side-to-side and 1.0f = one thickness in between. + void setBarSpacing(QSizeF spacing); + QSizeF barSpacing(); + + // Set bar spacing relative to thickness or absolute + void setBarSpacingRelative(bool relative); + bool isBarSpacingRelative(); + + // Bar type + void setBarType(QDataVis::MeshStyle style); + QDataVis::MeshStyle barType(); + + // Bar smoothing + void setBarSmooth(bool smooth); + bool barSmooth(); + + // override object type with own mesh + void setMeshFileName(const QString &objFileName); + QString meshFileName(); + + // Select preset camera placement + void setCameraPreset(QDataVis::CameraPreset preset); + QDataVis::CameraPreset cameraPreset(); + + // Set theme (object colors, shaders, window color, background colors, light intensity and text + // colors are affected) + void setTheme(QDataVis::ColorTheme theme); + QDataVis::ColorTheme theme(); + + // Change selection mode; single bar, bar and row, bar and column, or all + void setSelectionMode(QDataVis::SelectionMode mode); + QDataVis::SelectionMode selectionMode(); + + // Font size adjustment + void setFontSize(float fontsize); + float fontSize(); + + // Set font + void setFont(const QFont &font); + QFont font(); + + // Label transparency adjustment + void setLabelTransparency(QDataVis::LabelTransparency transparency); + QDataVis::LabelTransparency labelTransparency(); + + // Enable or disable background grid + void setGridVisible(bool visible); + bool isGridVisible(); + + // Enable or disable background mesh + void setBackgroundVisible(bool visible); + bool isBackgroundVisible(); + + // Adjust shadow quality + void setShadowQuality(QDataVis::ShadowQuality quality); + QDataVis::ShadowQuality shadowQuality(); + + int rows() const; + void setRows(int rows); - bool m_isSampleSpaceSet; - int m_cachedState; - int m_samplesRow; - int m_samplesColumn; - QString m_labelRow; - QString m_labelColumn; - QString m_labelHeight; + int columns() const; + void setColumns(int columns); - QDataRow *m_dataRow; +public slots: + // Used to detect when shadow quality changes autonomously due to e.g. resizing. + void handleShadowQualityUpdate(QDataVis::ShadowQuality quality); - bool m_isSelectionModeSet; - SelectionMode m_selectionMode; +signals: + // Signals shadow quality changes. + void shadowQualityChanged(QDataVis::ShadowQuality quality); - bool m_isLabelTransparencySet; - LabelTransparency m_labelTransparency; +protected: + Bars3dController *m_shared; - bool m_isShadowQualitySet; - ShadowQuality m_shadowQuality; + QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *); + void mousePressEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void wheelEvent(QWheelEvent *event); - bool m_isGridSet; - bool m_isGridEnabled; +private: + QSize m_initialisedSize; + QDataVis::CameraPreset m_cameraPreset; + QDataVis::ColorTheme m_theme; }; -QTENTERPRISE_DATAVIS3D_END_NAMESPACE -QTENTERPRISE_DATAVIS3D_USE_NAMESPACE +QT_DATAVIS3D_END_NAMESPACE -#endif // DECLARATIVEBARS_P_H +#endif diff --git a/src/datavis3dqml2/declarativebarsrenderer.cpp b/src/datavis3dqml2/declarativebarsrenderer.cpp new file mode 100644 index 00000000..1ecd4003 --- /dev/null +++ b/src/datavis3dqml2/declarativebarsrenderer.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** 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 "declarativebarsrenderer_p.h" + +#include <QtQuick/QQuickWindow> +#include <QtGui/QOpenGLFramebufferObject> + +QT_DATAVIS3D_BEGIN_NAMESPACE + +DeclarativeBarsRenderer::DeclarativeBarsRenderer(QQuickWindow *window, Bars3dController *renderer) + : m_fbo(0), + m_texture(0), + m_window(window), + m_barsRenderer(renderer) +{ + connect(m_window, SIGNAL(beforeSynchronizing()), this, SLOT(synchDataToRenderer()), Qt::DirectConnection); + connect(m_window, SIGNAL(beforeRendering()), this, SLOT(renderFBO()), Qt::DirectConnection); +} + +DeclarativeBarsRenderer::~DeclarativeBarsRenderer() +{ + delete m_texture; + delete m_fbo; +} + +void DeclarativeBarsRenderer::synchDataToRenderer() +{ + m_barsRenderer->initializeOpenGL(); + m_barsRenderer->synchDataToRenderer(); +} + +void DeclarativeBarsRenderer::renderFBO() +{ + QSize size = rect().size().toSize(); + + // Create FBO + if (!m_fbo) { + QOpenGLFramebufferObjectFormat format; + format.setAttachment(QOpenGLFramebufferObject::Depth); + m_fbo = new QOpenGLFramebufferObject(size, format); + m_texture = m_window->createTextureFromId(m_fbo->texture(), size); + + setTexture(m_texture); + + // Flip texture + // TODO: Can be gotten rid of once support for texture flipping becomes available (in Qt5.2) + QSize ts = m_texture->textureSize(); + QRectF sourceRect(0, 0, ts.width(), ts.height()); + float tmp = sourceRect.top(); + sourceRect.setTop(sourceRect.bottom()); + sourceRect.setBottom(tmp); + QSGGeometry *geometry = this->geometry(); + QSGGeometry::updateTexturedRectGeometry(geometry, rect(), + m_texture->convertToNormalizedSourceRect(sourceRect)); + markDirty(DirtyMaterial); + //qDebug() << "create node" << m_fbo->handle() << m_texture->textureId() << m_fbo->size(); + } + + // Call the shared rendering function + m_fbo->bind(); + + m_barsRenderer->render(m_fbo->handle()); + + m_fbo->release(); + + // New view is in the FBO, request repaint of scene graph + m_window->update(); +} + +QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3dqml2/declarativebarsrenderer_p.h b/src/datavis3dqml2/declarativebarsrenderer_p.h new file mode 100644 index 00000000..1b40d3df --- /dev/null +++ b/src/datavis3dqml2/declarativebarsrenderer_p.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** 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 DECLARATIVEBARSRENDERER_H +#define DECLARATIVEBARSRENDERER_H + +#include "datavis3dglobal_p.h" +#include "bars3dcontroller_p.h" +#include <qsgsimpletexturenode.h> + +class QOpenGLFramebufferObject; +class QSGTexture; +class QQuickWindow; + +QT_DATAVIS3D_BEGIN_NAMESPACE + +class DeclarativeBarsRenderer : public QObject, public QSGSimpleTextureNode +{ + Q_OBJECT + +public: + DeclarativeBarsRenderer(QQuickWindow *window, Bars3dController *shared); + ~DeclarativeBarsRenderer(); + +public slots: + // Used to synch up data model from controller to renderer while main thread is locked + void synchDataToRenderer(); + // Renders view to FBO before render cycle starts. + void renderFBO(); + +private: + QOpenGLFramebufferObject *m_fbo; + QSGTexture *m_texture; + QQuickWindow *m_window; + Bars3dController *m_barsRenderer; +}; + +QT_DATAVIS3D_END_NAMESPACE + +#endif diff --git a/src/datavis3dqml2/declarativemaps.cpp b/src/datavis3dqml2/declarativemaps.cpp index a5bb2318..7be239f2 100644 --- a/src/datavis3dqml2/declarativemaps.cpp +++ b/src/datavis3dqml2/declarativemaps.cpp @@ -1,86 +1,229 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** 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. ** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the +** 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. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and Digia. ** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com ** ****************************************************************************/ -#include "declarativemaps.h" - -#include <QDebug> +#include "declarativemaps_p.h" +#include "declarativemapsrenderer_p.h" +#include "qitemmodelmapdataproxy.h" -QTENTERPRISE_DATAVIS3D_BEGIN_NAMESPACE +QT_DATAVIS3D_BEGIN_NAMESPACE -DeclarativeMaps::DeclarativeMaps() +DeclarativeMaps::DeclarativeMaps(QQuickItem *parent) + : QQuickItem(parent), + m_shared(0), + m_initializedSize(0, 0) { + setFlags(QQuickItem::ItemHasContents); + setAcceptedMouseButtons(Qt::AllButtons); + + // TODO: These seem to have no effect; find a way to activate anti-aliasing + setAntialiasing(true); + setSmooth(true); } DeclarativeMaps::~DeclarativeMaps() { + delete m_shared; +} + +void DeclarativeMaps::classBegin() +{ + qDebug() << "classBegin"; +} + +void DeclarativeMaps::componentComplete() +{ + qDebug() << "componentComplete"; +} + +QSGNode *DeclarativeMaps::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) +{ + if (!m_shared) { + m_shared = new Maps3DController(boundingRect().toRect()); + m_shared->setDataProxy(new QItemModelMapDataProxy); + m_shared->initializeOpenGL(); + } + + // If old node exists and has right size, reuse it. + if (oldNode && m_initializedSize == boundingRect().size().toSize()) { + // Update bounding rectangle (that has same size as before). + static_cast<DeclarativeMapsRenderer *>( oldNode )->setRect(boundingRect()); + return oldNode; + } + + // Create a new render node when size changes or if there is no node yet + m_initializedSize = boundingRect().size().toSize(); + + // Delete old node + if (oldNode) + delete oldNode; + + // Create a new one and set it's bounding rectangle + DeclarativeMapsRenderer *node = new DeclarativeMapsRenderer(window(), m_shared); + node->setRect(boundingRect()); + m_shared->setBoundingRect(boundingRect().toRect()); + return node; +} + +void DeclarativeMaps::setData(QAbstractItemModel *data) +{ + static_cast<QItemModelMapDataProxy *>(m_shared->dataProxy())->setItemModel(data); +} + +QAbstractItemModel *DeclarativeMaps::data() +{ + return static_cast<QItemModelMapDataProxy *>(m_shared->dataProxy())->itemModel(); +} + +void DeclarativeMaps::setBarSpecs(const QVector3D &thickness, + Q3DMaps::AdjustmentDirection direction) +{ + m_shared->setBarSpecs(thickness, direction); +} + +void DeclarativeMaps::setBarType(QDataVis::MeshStyle style, bool smooth) +{ + m_shared->setBarType(style, smooth); +} + +void DeclarativeMaps::setMeshFileName(const QString &objFileName) +{ + m_shared->setMeshFileName(objFileName); +} + +void DeclarativeMaps::setCameraPreset(QDataVis::CameraPreset preset) +{ + m_shared->setCameraPreset(preset); +} + +void DeclarativeMaps::setCameraPosition(GLfloat horizontal, GLfloat vertical, GLint distance) +{ + m_shared->setCameraPosition(horizontal, vertical, distance); +} + +void DeclarativeMaps::setTheme(QDataVis::ColorTheme theme) +{ + m_shared->setTheme(theme); +} + +void DeclarativeMaps::setBarColor(QColor baseColor, QColor heightColor, bool uniform) +{ + m_shared->setBarColor(baseColor, heightColor, uniform); +} + +void DeclarativeMaps::setAreaSpecs(const QRect &areaRect, const QImage &image) +{ + m_shared->setAreaSpecs(areaRect, image); +} + +void DeclarativeMaps::setImage(const QImage &image) +{ + m_shared->setImage(image); +} + +void DeclarativeMaps::setImage(const QString &imageUrl) +{ + m_shared->setImage(QImage(imageUrl)); +} + +void DeclarativeMaps::setSelectionMode(QDataVis::SelectionMode mode) +{ + m_shared->setSelectionMode(mode); +} + +QDataVis::SelectionMode DeclarativeMaps::selectionMode() +{ + return m_shared->selectionMode(); +} + +void DeclarativeMaps::setFontSize(float fontsize) +{ + m_shared->setFontSize(fontsize); +} + +float DeclarativeMaps::fontSize() +{ + return m_shared->fontSize(); +} + +void DeclarativeMaps::setFont(const QFont &font) +{ + m_shared->setFont(font); +} + +QFont DeclarativeMaps::font() +{ + return m_shared->font(); +} + +void DeclarativeMaps::setLabelTransparency(QDataVis::LabelTransparency transparency) +{ + m_shared->setLabelTransparency(transparency); +} + +QDataVis::LabelTransparency DeclarativeMaps::labelTransparency() +{ + return m_shared->labelTransparency(); +} + +void DeclarativeMaps::setShadowQuality(QDataVis::ShadowQuality quality) +{ + m_shared->setShadowQuality(quality); +} + +QDataVis::ShadowQuality DeclarativeMaps::shadowQuality() +{ + return m_shared->shadowQuality(); } -void DeclarativeMaps::setSelMode(DeclarativeMaps::SelectionMode mode) +QItemModelMapDataMapping *DeclarativeMaps::mapping() const { - setSelectionMode(QtDataVis3D::SelectionMode(mode)); + return static_cast<QItemModelMapDataProxy *>(m_shared->dataProxy())->mapping(); } -DeclarativeMaps::SelectionMode DeclarativeMaps::selMode() +void DeclarativeMaps::setMapping(QItemModelMapDataMapping *mapping) { - return DeclarativeMaps::SelectionMode(selectionMode()); + static_cast<QItemModelMapDataProxy *>(m_shared->dataProxy())->setMapping(mapping); } -void DeclarativeMaps::setTransparency(DeclarativeMaps::LabelTransparency transparency) +void DeclarativeMaps::mousePressEvent(QMouseEvent *event) { - setLabelTransparency(QtDataVis3D::LabelTransparency(transparency)); + QPoint mousePos = event->pos(); + //mousePos.setY(height() - mousePos.y()); + m_shared->mousePressEvent(event, mousePos); } -DeclarativeMaps::LabelTransparency DeclarativeMaps::transparency() +void DeclarativeMaps::mouseReleaseEvent(QMouseEvent *event) { - return DeclarativeMaps::LabelTransparency(labelTransparency()); + QPoint mousePos = event->pos(); + //mousePos.setY(height() - mousePos.y()); + m_shared->mouseReleaseEvent(event, mousePos); } -void DeclarativeMaps::setShadow(DeclarativeMaps::ShadowQuality quality) +void DeclarativeMaps::mouseMoveEvent(QMouseEvent *event) { - setShadowQuality(QtDataVis3D::ShadowQuality(quality)); + QPoint mousePos = event->pos(); + //mousePos.setY(height() - mousePos.y()); + m_shared->mouseMoveEvent(event, mousePos); } -DeclarativeMaps::ShadowQuality DeclarativeMaps::shadow() +void DeclarativeMaps::wheelEvent(QWheelEvent *event) { - return DeclarativeMaps::ShadowQuality(shadowQuality()); + m_shared->wheelEvent(event); } -QTENTERPRISE_DATAVIS3D_END_NAMESPACE +QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3dqml2/declarativemaps.h b/src/datavis3dqml2/declarativemaps.h deleted file mode 100644 index aef00c76..00000000 --- a/src/datavis3dqml2/declarativemaps.h +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtDataVis3D module. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef DECLARATIVEMAPS_H -#define DECLARATIVEMAPS_H - -#include "QtDataVis3D/qdatavis3dglobal.h" -#include "QtDataVis3D/qdatavis3namespace.h" -#include "q3dmaps.h" - -QTENTERPRISE_DATAVIS3D_BEGIN_NAMESPACE - -class DeclarativeMaps : public Q3DMaps -{ - Q_OBJECT - Q_PROPERTY(SelectionMode selectionMode READ selMode WRITE setSelMode) - Q_PROPERTY(LabelTransparency labelTransparency READ transparency WRITE setTransparency) - Q_PROPERTY(ShadowQuality shadowQuality READ shadow WRITE setShadow) - Q_ENUMS(SelectionMode) - Q_ENUMS(ShadowQuality) - Q_ENUMS(LabelTransparency) - -public: - // Duplicated here to be able to use the same enums - enum SelectionMode { - ModeNone = 0, - ModeBar, - ModeBarAndRow, - ModeBarAndColumn, - ModeBarRowAndColumn, - ModeZoomRow, - ModeZoomColumn - }; - - enum ShadowQuality { - ShadowNone = 0, - ShadowLow = 1, - ShadowMedium = 3, - ShadowHigh = 5 - }; - - enum LabelTransparency { - TransparencyNone = 0, // Full solid, using colors from theme - TransparencyFromTheme, // Use colors and transparencies from theme - TransparencyNoBackground // Draw just text on transparent background - }; - -public: - explicit DeclarativeMaps(); - ~DeclarativeMaps(); - - // Change selection mode; single bar, bar and row, bar and column, or all - void setSelMode(DeclarativeMaps::SelectionMode mode); - DeclarativeMaps::SelectionMode selMode(); - - // Label transparency adjustment - void setTransparency(DeclarativeMaps::LabelTransparency transparency); - DeclarativeMaps::LabelTransparency transparency(); - - // Adjust shadow quality - void setShadow(DeclarativeMaps::ShadowQuality quality); - DeclarativeMaps::ShadowQuality shadow(); -}; - -QTENTERPRISE_DATAVIS3D_END_NAMESPACE - -#endif diff --git a/src/datavis3dqml2/declarativemaps_p.h b/src/datavis3dqml2/declarativemaps_p.h new file mode 100644 index 00000000..ba2da0b3 --- /dev/null +++ b/src/datavis3dqml2/declarativemaps_p.h @@ -0,0 +1,139 @@ +/**************************************************************************** +** +** 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 DECLARATIVEMAPS_P_H +#define DECLARATIVEMAPS_P_H + +#include "datavis3dglobal_p.h" +#include "maps3dcontroller_p.h" +#include "declarativemaps_p.h" +#include "qitemmodelmapdatamapping.h" + +#include <QAbstractItemModel> +#include <QQuickItem> +#include <QObject> + +QT_DATAVIS3D_BEGIN_NAMESPACE + +class DeclarativeMaps : public QQuickItem +{ + Q_OBJECT + Q_PROPERTY(QAbstractItemModel *data READ data WRITE setData) + Q_PROPERTY(QtDataVis3D::QDataVis::SelectionMode selectionMode READ selectionMode WRITE setSelectionMode) + Q_PROPERTY(QtDataVis3D::QDataVis::LabelTransparency labelTransparency READ labelTransparency WRITE setLabelTransparency) + Q_PROPERTY(QtDataVis3D::QDataVis::ShadowQuality shadowQuality READ shadowQuality WRITE setShadowQuality) + Q_PROPERTY(QFont font READ font WRITE setFont) + Q_PROPERTY(float fontSize READ fontSize WRITE setFontSize) + Q_PROPERTY(QItemModelMapDataMapping *mapping READ mapping WRITE setMapping) + Q_ENUMS(QtDataVis3D::QDataVis::SelectionMode) + Q_ENUMS(QtDataVis3D::QDataVis::ShadowQuality) + Q_ENUMS(QtDataVis3D::QDataVis::LabelTransparency) + +public: + explicit DeclarativeMaps(QQuickItem *parent = 0); + ~DeclarativeMaps(); + + void classBegin(); + void componentComplete(); + + void setData(QAbstractItemModel *data); + QAbstractItemModel *data(); + + // 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. + Q_INVOKABLE 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. + Q_INVOKABLE void setBarType(QDataVis::MeshStyle style, bool smooth = false); + + // override bar type with own mesh + Q_INVOKABLE void setMeshFileName(const QString &objFileName); + + // Select preset camera placement + Q_INVOKABLE 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)) + Q_INVOKABLE 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) + Q_INVOKABLE 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 + Q_INVOKABLE void setBarColor(QColor baseColor, QColor heightColor, bool uniform = true); + + // Set area specs + Q_INVOKABLE void setAreaSpecs(const QRect &areaRect, const QImage &image); + + // Set area image + Q_INVOKABLE void setImage(const QImage &image); + Q_INVOKABLE void setImage(const QString &imageUrl); + + // Change selection mode; single bar, bar and row, bar and column, or all + void setSelectionMode(QDataVis::SelectionMode mode); + QDataVis::SelectionMode selectionMode(); + + // Font size adjustment + void setFontSize(float fontsize); + float fontSize(); + + // Set font + void setFont(const QFont &font); + QFont font(); + + // Label transparency adjustment + void setLabelTransparency(QDataVis::LabelTransparency transparency); + QDataVis::LabelTransparency labelTransparency(); + + // Adjust shadow quality + void setShadowQuality(QDataVis::ShadowQuality quality); + QDataVis::ShadowQuality shadowQuality(); + + QItemModelMapDataMapping *mapping() const; + void setMapping(QItemModelMapDataMapping *mapping); + +protected: + Maps3DController *m_shared; + + QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *); + + void mousePressEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void wheelEvent(QWheelEvent *event); + +private: + QSize m_initializedSize; +}; + +QT_DATAVIS3D_END_NAMESPACE + +#endif diff --git a/src/datavis3dqml2/declarativemapsrenderer.cpp b/src/datavis3dqml2/declarativemapsrenderer.cpp new file mode 100644 index 00000000..6e8dc2db --- /dev/null +++ b/src/datavis3dqml2/declarativemapsrenderer.cpp @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** 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 "declarativemapsrenderer_p.h" + +#include <QtQuick/QQuickWindow> +#include <QtGui/QOpenGLFramebufferObject> + +QT_DATAVIS3D_BEGIN_NAMESPACE + +DeclarativeMapsRenderer::DeclarativeMapsRenderer(QQuickWindow *window, Maps3DController *renderer) + : m_fbo(0), + m_texture(0), + m_window(window), + m_mapsRenderer(renderer) +{ + connect(m_window, SIGNAL(beforeRendering()), this, SLOT(render()), Qt::DirectConnection); +} + +DeclarativeMapsRenderer::~DeclarativeMapsRenderer() +{ + delete m_texture; + delete m_fbo; +} + +void DeclarativeMapsRenderer::render() +{ + QSize size = rect().size().toSize(); + + // Create FBO + if (!m_fbo) { + QOpenGLFramebufferObjectFormat format; + format.setAttachment(QOpenGLFramebufferObject::Depth); + m_fbo = new QOpenGLFramebufferObject(size, format); + m_texture = m_window->createTextureFromId(m_fbo->texture(), size); + + setTexture(m_texture); + + // Flip texture + // TODO: Can be gotten rid of once support for texture flipping becomes available (in Qt5.2) + QSize ts = m_texture->textureSize(); + QRectF sourceRect(0, 0, ts.width(), ts.height()); + float tmp = sourceRect.top(); + sourceRect.setTop(sourceRect.bottom()); + sourceRect.setBottom(tmp); + QSGGeometry *geometry = this->geometry(); + QSGGeometry::updateTexturedRectGeometry(geometry, rect(), + m_texture->convertToNormalizedSourceRect(sourceRect)); + markDirty(DirtyMaterial); + //qDebug() << "create node" << m_fbo->handle() << m_texture->textureId() << m_fbo->size(); + } + + // Call the shared rendering function + m_fbo->bind(); + + m_mapsRenderer->render(m_fbo->handle()); + + m_fbo->release(); + + // New view is in the FBO, request repaint of scene graph + m_window->update(); +} + +QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3dqml2/declarativemapsrenderer_p.h b/src/datavis3dqml2/declarativemapsrenderer_p.h new file mode 100644 index 00000000..755764c9 --- /dev/null +++ b/src/datavis3dqml2/declarativemapsrenderer_p.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** 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 DECLARATIVEMAPSRENDERER_P_H +#define DECLARATIVEMAPSRENDERER_P_H + +#include "datavis3dglobal_p.h" +#include "maps3dcontroller_p.h" +#include <qsgsimpletexturenode.h> + +class QOpenGLFramebufferObject; +class QSGTexture; +class QQuickWindow; + +QT_DATAVIS3D_BEGIN_NAMESPACE + +class DeclarativeMapsRenderer : public QObject, public QSGSimpleTextureNode +{ + Q_OBJECT + +public: + DeclarativeMapsRenderer(QQuickWindow *window, Maps3DController *shared); + ~DeclarativeMapsRenderer(); + +public slots: + void render(); + +private: + QOpenGLFramebufferObject *m_fbo; + QSGTexture *m_texture; + QQuickWindow *m_window; + Maps3DController *m_mapsRenderer; +}; + +QT_DATAVIS3D_END_NAMESPACE + +#endif diff --git a/src/datavis3dqml2/declarativescatter.cpp b/src/datavis3dqml2/declarativescatter.cpp new file mode 100644 index 00000000..90daf0e3 --- /dev/null +++ b/src/datavis3dqml2/declarativescatter.cpp @@ -0,0 +1,328 @@ +/**************************************************************************** +** +** 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 "declarativescatter_p.h" +#include "declarativescatterrenderer_p.h" +#include "qitemmodelscatterdataproxy.h" + +QT_DATAVIS3D_BEGIN_NAMESPACE + +const QString smoothString(QStringLiteral("Smooth")); + +DeclarativeScatter::DeclarativeScatter(QQuickItem *parent) + : QQuickItem(parent), + m_shared(0), + m_initialisedSize(0, 0), + m_cameraPreset(QDataVis::NoPreset), + m_theme(QDataVis::ThemeDefault) +{ + setFlags(QQuickItem::ItemHasContents); + setAcceptedMouseButtons(Qt::AllButtons); + + // TODO: These seem to have no effect; find a way to activate anti-aliasing + setAntialiasing(true); + setSmooth(true); + + // Create the shared component on the main GUI thread. + m_shared = new Scatter3DController(boundingRect().toRect()); + QObject::connect(m_shared, &Scatter3DController::shadowQualityChanged, this, + &DeclarativeScatter::handleShadowQualityUpdate); + + m_shared->setDataProxy(new QItemModelScatterDataProxy); +} + +DeclarativeScatter::~DeclarativeScatter() +{ + delete m_shared; +} + +void DeclarativeScatter::handleShadowQualityUpdate(QDataVis::ShadowQuality quality) +{ + emit shadowQualityChanged(quality); +} + +void DeclarativeScatter::classBegin() +{ + qDebug() << "classBegin"; +} + +void DeclarativeScatter::componentComplete() +{ + qDebug() << "componentComplete"; +} + +QSGNode *DeclarativeScatter::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) +{ + // If old node exists and has right size, reuse it. + if (oldNode && m_initialisedSize == boundingRect().size().toSize()) { + // Update bounding rectangle (that has same size as before). + static_cast<DeclarativeScatterRenderer *>( oldNode )->setRect(boundingRect()); + return oldNode; + } + + // Create a new render node when size changes or if there is no node yet + m_initialisedSize = boundingRect().size().toSize(); + + // Delete old node + if (oldNode) + delete oldNode; + + // Create a new one and set it's bounding rectangle + DeclarativeScatterRenderer *node = new DeclarativeScatterRenderer(window(), m_shared); + node->setRect(boundingRect()); + m_shared->setBoundingRect(boundingRect().toRect()); + return node; +} + +void DeclarativeScatter::setCameraPosition(qreal horizontal, qreal vertical, int distance) +{ + m_shared->setCameraPosition(GLfloat(horizontal), GLfloat(vertical), GLint(distance)); +} + +void DeclarativeScatter::setObjectColor(QColor baseColor, QColor heightColor, QColor depthColor, + bool uniform) +{ + m_shared->setObjectColor(baseColor, heightColor, depthColor, uniform); +} + +void DeclarativeScatter::setData(QAbstractItemModel *data) +{ + static_cast<QItemModelScatterDataProxy *>(m_shared->dataProxy())->setItemModel(data); +} + +QAbstractItemModel *DeclarativeScatter::data() +{ + return static_cast<QItemModelScatterDataProxy *>(m_shared->dataProxy())->itemModel(); +} + +void DeclarativeScatter::setMapping(QItemModelScatterDataMapping *mapping) +{ + static_cast<QItemModelScatterDataProxy *>(m_shared->dataProxy())->setMapping(mapping); +} + +QItemModelScatterDataMapping *DeclarativeScatter::mapping() const +{ + return static_cast<QItemModelScatterDataProxy *>(m_shared->dataProxy())->mapping(); +} + +QValueAxis *DeclarativeScatter::axisX() const +{ + return static_cast<QValueAxis *>(m_shared->axisX()); +} + +void DeclarativeScatter::setAxisX(QValueAxis *axis) +{ + m_shared->setAxisX(axis); +} + +QValueAxis *DeclarativeScatter::axisY() const +{ + return static_cast<QValueAxis *>(m_shared->axisY()); +} + +void DeclarativeScatter::setAxisY(QValueAxis *axis) +{ + m_shared->setAxisY(axis); +} + +QValueAxis *DeclarativeScatter::axisZ() const +{ + return static_cast<QValueAxis *>(m_shared->axisZ()); +} + +void DeclarativeScatter::setAxisZ(QValueAxis *axis) +{ + m_shared->setAxisZ(axis); +} + +void DeclarativeScatter::setObjectType(QDataVis::MeshStyle style) +{ + QString objFile = m_shared->meshFileName(); + bool smooth = objFile.endsWith(smoothString); + m_shared->setObjectType(style, smooth); +} + +QDataVis::MeshStyle DeclarativeScatter::objectType() +{ + QString objFile = m_shared->meshFileName(); + if (objFile.contains("/sphere")) + return QDataVis::Spheres; + else + return QDataVis::Dots; +} + +void DeclarativeScatter::setObjectSmooth(bool smooth) +{ + QString objFile = m_shared->meshFileName(); + if (objFile.endsWith(smoothString)) { + if (smooth) + return; // Already smooth; do nothing + else // Rip Smooth off the end + objFile.resize(objFile.indexOf(smoothString)); + } else { + if (!smooth) // Already flat; do nothing + return; + else // Append Smooth to the end + objFile.append(smoothString); + } + m_shared->setMeshFileName(objFile); +} + +bool DeclarativeScatter::objectSmooth() +{ + QString objFile = m_shared->meshFileName(); + return objFile.endsWith(smoothString); +} + +void DeclarativeScatter::setMeshFileName(const QString &objFileName) +{ + m_shared->setMeshFileName(objFileName); +} + +QString DeclarativeScatter::meshFileName() +{ + return m_shared->meshFileName(); +} + +void DeclarativeScatter::setCameraPreset(QDataVis::CameraPreset preset) +{ + // TODO: Implement correctly once "improved camera api" (QTRD-2122) is implemented + // We need to save this locally, as there are no getters for it in controller + m_cameraPreset = preset; + m_shared->setCameraPreset(preset); +} + +QDataVis::CameraPreset DeclarativeScatter::cameraPreset() +{ + return m_cameraPreset; +} + +void DeclarativeScatter::setTheme(QDataVis::ColorTheme theme) +{ + // TODO: Implement correctly once "user-modifiable themes" (QTRD-2120) is implemented + // We need to save this locally, as there are no getters for it in controller + m_theme = theme; + m_shared->setColorTheme(theme); + + // TODO: Investigate why the beforeSynchronizing() signal requires update and is not sent automatically when this value changes, + // but is sent wen e.g. enable/disable background changes. + update(); +} + +QDataVis::ColorTheme DeclarativeScatter::theme() +{ + return m_theme; +} + +void DeclarativeScatter::setFontSize(float fontsize) +{ + m_shared->setFontSize(fontsize); +} + +float DeclarativeScatter::fontSize() +{ + return m_shared->fontSize(); +} + +void DeclarativeScatter::setFont(const QFont &font) +{ + m_shared->setFont(font); +} + +QFont DeclarativeScatter::font() +{ + return m_shared->font(); +} + +void DeclarativeScatter::setLabelTransparency(QDataVis::LabelTransparency transparency) +{ + m_shared->setLabelTransparency(transparency); +} + +QDataVis::LabelTransparency DeclarativeScatter::labelTransparency() +{ + return m_shared->labelTransparency(); +} + +void DeclarativeScatter::setGridVisible(bool visible) +{ + m_shared->setGridEnabled(visible); +} + +bool DeclarativeScatter::isGridVisible() +{ + return m_shared->gridEnabled(); +} + +void DeclarativeScatter::setBackgroundVisible(bool visible) +{ + m_shared->setBackgroundEnabled(visible); +} + +bool DeclarativeScatter::isBackgroundVisible() +{ + return m_shared->backgroundEnabled(); +} + +void DeclarativeScatter::setSelectionMode(QDataVis::SelectionMode mode) +{ + m_shared->setSelectionMode(mode); +} + +QDataVis::SelectionMode DeclarativeScatter::selectionMode() +{ + return m_shared->selectionMode(); +} + +void DeclarativeScatter::setShadowQuality(QDataVis::ShadowQuality quality) +{ + m_shared->setShadowQuality(quality); +} + +QDataVis::ShadowQuality DeclarativeScatter::shadowQuality() +{ + return m_shared->shadowQuality(); +} + +void DeclarativeScatter::mousePressEvent(QMouseEvent *event) +{ + QPoint mousePos = event->pos(); + //mousePos.setY(height() - mousePos.y()); + m_shared->mousePressEvent(event, mousePos); +} + +void DeclarativeScatter::mouseReleaseEvent(QMouseEvent *event) +{ + QPoint mousePos = event->pos(); + //mousePos.setY(height() - mousePos.y()); + m_shared->mouseReleaseEvent(event, mousePos); +} + +void DeclarativeScatter::mouseMoveEvent(QMouseEvent *event) +{ + QPoint mousePos = event->pos(); + //mousePos.setY(height() - mousePos.y()); + m_shared->mouseMoveEvent(event, mousePos); +} + +void DeclarativeScatter::wheelEvent(QWheelEvent *event) +{ + m_shared->wheelEvent(event); +} + +QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3dqml2/declarativescatter_p.h b/src/datavis3dqml2/declarativescatter_p.h new file mode 100644 index 00000000..dce5c021 --- /dev/null +++ b/src/datavis3dqml2/declarativescatter_p.h @@ -0,0 +1,175 @@ +/**************************************************************************** +** +** 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 DECLARATIVESCATTER_P_H +#define DECLARATIVESCATTER_P_H + +#include "datavis3dglobal_p.h" +#include "scatter3dcontroller_p.h" +#include "declarativescatter_p.h" +#include "qitemmodelscatterdatamapping.h" +#include "qvalueaxis.h" + +#include <QAbstractItemModel> +#include <QQuickItem> +#include <QObject> + +QT_DATAVIS3D_BEGIN_NAMESPACE + +class DeclarativeScatter : public QQuickItem +{ + Q_OBJECT + Q_PROPERTY(QAbstractItemModel *data READ data WRITE setData) + Q_PROPERTY(QItemModelScatterDataMapping *mapping READ mapping WRITE setMapping) + Q_PROPERTY(QValueAxis *axisX READ axisX WRITE setAxisX) + Q_PROPERTY(QValueAxis *axisY READ axisY WRITE setAxisY) + Q_PROPERTY(QValueAxis *axisZ READ axisZ WRITE setAxisZ) + Q_PROPERTY(QtDataVis3D::QDataVis::SelectionMode selectionMode READ selectionMode WRITE setSelectionMode) + Q_PROPERTY(QtDataVis3D::QDataVis::LabelTransparency labelTransparency READ labelTransparency WRITE setLabelTransparency) + Q_PROPERTY(QtDataVis3D::QDataVis::ShadowQuality shadowQuality READ shadowQuality WRITE setShadowQuality) + Q_PROPERTY(QtDataVis3D::QDataVis::MeshStyle objectType READ objectType WRITE setObjectType) + Q_PROPERTY(QtDataVis3D::QDataVis::CameraPreset cameraPreset READ cameraPreset WRITE setCameraPreset) + Q_PROPERTY(QtDataVis3D::QDataVis::ColorTheme theme READ theme WRITE setTheme) + Q_PROPERTY(bool objectSmooth READ objectSmooth WRITE setObjectSmooth) + Q_PROPERTY(QString meshFileName READ meshFileName WRITE setMeshFileName) + Q_PROPERTY(QFont font READ font WRITE setFont) + Q_PROPERTY(float fontSize READ fontSize WRITE setFontSize) + Q_PROPERTY(bool gridVisible READ isGridVisible WRITE setGridVisible) + Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible) + Q_ENUMS(QtDataVis3D::QDataVis::SelectionMode) + Q_ENUMS(QtDataVis3D::QDataVis::ShadowQuality) + Q_ENUMS(QtDataVis3D::QDataVis::LabelTransparency) + Q_ENUMS(QtDataVis3D::QDataVis::MeshStyle) + Q_ENUMS(QtDataVis3D::QDataVis::CameraPreset) + Q_ENUMS(QtDataVis3D::QDataVis::ColorTheme) + +public: + explicit DeclarativeScatter(QQuickItem *parent = 0); + ~DeclarativeScatter(); + + void classBegin(); + void componentComplete(); + + // Set camera rotation if you don't want to use the presets (in horizontal (-180...180) and + // vertical (-90...90) angles and distance in percentage (10...500)) + Q_INVOKABLE void setCameraPosition(qreal horizontal, qreal vertical, int distance); + + // 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 + Q_INVOKABLE void setObjectColor(QColor baseColor, QColor heightColor, QColor depthColor, + bool uniform = true); + + // Add whole data set. + void setData(QAbstractItemModel *data); + QAbstractItemModel *data(); + + QItemModelScatterDataMapping *mapping() const; + void setMapping(QItemModelScatterDataMapping *mapping); + + QValueAxis *axisX() const; + void setAxisX(QValueAxis *axis); + QValueAxis *axisY() const; + void setAxisY(QValueAxis *axis); + QValueAxis *axisZ() const; + void setAxisZ(QValueAxis *axis); + + // Object type + void setObjectType(QDataVis::MeshStyle style); + QDataVis::MeshStyle objectType(); + + // Object smoothing + void setObjectSmooth(bool smooth); + bool objectSmooth(); + + // override object type with own mesh + void setMeshFileName(const QString &objFileName); + QString meshFileName(); + + // Select preset camera placement + void setCameraPreset(QDataVis::CameraPreset preset); + QDataVis::CameraPreset cameraPreset(); + + // Set theme (object colors, shaders, window color, background colors, light intensity and text + // colors are affected) + void setTheme(QDataVis::ColorTheme theme); + QDataVis::ColorTheme theme(); + + // Change selection mode + void setSelectionMode(QDataVis::SelectionMode mode); + QDataVis::SelectionMode selectionMode(); + + // Font size adjustment + void setFontSize(float fontsize); + float fontSize(); + + // Set font + void setFont(const QFont &font); + QFont font(); + + // Label transparency adjustment + void setLabelTransparency(QDataVis::LabelTransparency transparency); + QDataVis::LabelTransparency labelTransparency(); + + // Enable or disable background grid + void setGridVisible(bool visible); + bool isGridVisible(); + + // Enable or disable background mesh + void setBackgroundVisible(bool visible); + bool isBackgroundVisible(); + + // Adjust shadow quality + void setShadowQuality(QDataVis::ShadowQuality quality); + QDataVis::ShadowQuality shadowQuality(); + +public slots: + // Used to detect when shadow quality changes autonomously due to e.g. resizing. + void handleShadowQualityUpdate(QDataVis::ShadowQuality quality); + +signals: + // Signals shadow quality changes. + void shadowQualityChanged(QDataVis::ShadowQuality quality); + +protected: + Scatter3DController *m_shared; + QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *); + + void mousePressEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void wheelEvent(QWheelEvent *event); + +private: + QSize m_initialisedSize; + QDataVis::CameraPreset m_cameraPreset; + QDataVis::ColorTheme m_theme; +}; + +QT_DATAVIS3D_END_NAMESPACE + +#endif diff --git a/src/datavis3dqml2/declarativescatterrenderer.cpp b/src/datavis3dqml2/declarativescatterrenderer.cpp new file mode 100644 index 00000000..23c59c26 --- /dev/null +++ b/src/datavis3dqml2/declarativescatterrenderer.cpp @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** 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 "declarativescatterrenderer_p.h" + +#include <QtQuick/QQuickWindow> +#include <QtGui/QOpenGLFramebufferObject> + +QT_DATAVIS3D_BEGIN_NAMESPACE + +DeclarativeScatterRenderer::DeclarativeScatterRenderer(QQuickWindow *window, + Scatter3DController *renderer) + : m_fbo(0), + m_texture(0), + m_window(window), + m_scatterRenderer(renderer) +{ + connect(m_window, SIGNAL(beforeSynchronizing()), this, SLOT(synchDataToRenderer()), Qt::DirectConnection); + connect(m_window, SIGNAL(beforeRendering()), this, SLOT(renderFBO()), Qt::DirectConnection); +} + +DeclarativeScatterRenderer::~DeclarativeScatterRenderer() +{ + delete m_texture; + delete m_fbo; +} + +void DeclarativeScatterRenderer::synchDataToRenderer() +{ + m_scatterRenderer->initializeOpenGL(); + m_scatterRenderer->synchDataToRenderer(); +} + +void DeclarativeScatterRenderer::renderFBO() +{ + QSize size = rect().size().toSize(); + + // Create FBO + if (!m_fbo) { + QOpenGLFramebufferObjectFormat format; + format.setAttachment(QOpenGLFramebufferObject::Depth); + m_fbo = new QOpenGLFramebufferObject(size, format); + m_texture = m_window->createTextureFromId(m_fbo->texture(), size); + + setTexture(m_texture); + + // Flip texture + // TODO: Can be gotten rid of once support for texture flipping becomes available (in Qt5.2) + QSize ts = m_texture->textureSize(); + QRectF sourceRect(0, 0, ts.width(), ts.height()); + float tmp = sourceRect.top(); + sourceRect.setTop(sourceRect.bottom()); + sourceRect.setBottom(tmp); + QSGGeometry *geometry = this->geometry(); + QSGGeometry::updateTexturedRectGeometry(geometry, rect(), + m_texture->convertToNormalizedSourceRect(sourceRect)); + markDirty(DirtyMaterial); + //qDebug() << "create node" << m_fbo->handle() << m_texture->textureId() << m_fbo->size(); + } + + // Call the shared rendering function + m_fbo->bind(); + + m_scatterRenderer->render(m_fbo->handle()); + + m_fbo->release(); + + // New view is in the FBO, request repaint of scene graph + m_window->update(); +} + +QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3dqml2/declarativescatterrenderer_p.h b/src/datavis3dqml2/declarativescatterrenderer_p.h new file mode 100644 index 00000000..498b1d83 --- /dev/null +++ b/src/datavis3dqml2/declarativescatterrenderer_p.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** 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 DECLARATIVESCATTERRENDERER_P_H +#define DECLARATIVESCATTERRENDERER_P_H + +#include "datavis3dglobal_p.h" +#include "scatter3dcontroller_p.h" +#include <qsgsimpletexturenode.h> + +class QOpenGLFramebufferObject; +class QSGTexture; +class QQuickWindow; + +QT_DATAVIS3D_BEGIN_NAMESPACE + +class DeclarativeScatterRenderer : public QObject, public QSGSimpleTextureNode +{ + Q_OBJECT + +public: + DeclarativeScatterRenderer(QQuickWindow *window, Scatter3DController *shared); + ~DeclarativeScatterRenderer(); + +public slots: + // Used to synch up data model from controller to renderer while main thread is locked + void synchDataToRenderer(); + // Renders view to FBO before render cycle starts. + void renderFBO(); + +private: + QOpenGLFramebufferObject *m_fbo; + QSGTexture *m_texture; + QQuickWindow *m_window; + Scatter3DController *m_scatterRenderer; +}; + +QT_DATAVIS3D_END_NAMESPACE + +#endif |