From dc8a005ad1d88b60a86db469caa6d40d88370585 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomi=20Korpip=C3=A4=C3=A4?= Date: Tue, 13 Aug 2013 10:09:57 +0300 Subject: DeclarativeMaps: Refactoring and cleanup QMLMaps cannot be used, as engine is not refactored yet. Running it crashes -> commented qmlmaps example out. Change-Id: Ieb2c830ddd848721a57b9db77799fb97e05eb227 Change-Id: Ieb2c830ddd848721a57b9db77799fb97e05eb227 Reviewed-by: Miikka Heikkinen --- examples/examples.pro | 2 +- src/datavis3dqml2/datavis3dqml2.pro | 11 +- src/datavis3dqml2/datavis3dqml2_plugin.cpp | 3 - src/datavis3dqml2/datavis3dqml2_plugin.h | 3 +- src/datavis3dqml2/declarativebars.cpp | 5 +- src/datavis3dqml2/declarativebars_p.h | 4 +- src/datavis3dqml2/declarativebarsrenderer.cpp | 1 - src/datavis3dqml2/declarativemaps.cpp | 298 +++-------------------- src/datavis3dqml2/declarativemaps.h | 203 --------------- src/datavis3dqml2/declarativemaps_p.h | 155 ++++++++---- src/datavis3dqml2/declarativemapsrenderer.cpp | 102 ++++++++ src/datavis3dqml2/declarativemapsrenderer_p.h | 85 +++++++ src/datavis3dqml2/declarativescatter.cpp | 1 - src/datavis3dqml2/declarativescatterrenderer.cpp | 1 - 14 files changed, 342 insertions(+), 532 deletions(-) delete mode 100644 src/datavis3dqml2/declarativemaps.h create mode 100644 src/datavis3dqml2/declarativemapsrenderer.cpp create mode 100644 src/datavis3dqml2/declarativemapsrenderer_p.h diff --git a/examples/examples.pro b/examples/examples.pro index 3541c7ad..4db7ed2f 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -4,7 +4,7 @@ SUBDIRS += barchart \ widget \ mapdata \ qmlbarchart \ - qmlmaps \ + #qmlmaps \ qmlscatter \ surfacechart \ scatterchart diff --git a/src/datavis3dqml2/datavis3dqml2.pro b/src/datavis3dqml2/datavis3dqml2.pro index b123bdca..c994c5be 100644 --- a/src/datavis3dqml2/datavis3dqml2.pro +++ b/src/datavis3dqml2/datavis3dqml2.pro @@ -20,18 +20,19 @@ SOURCES += \ datavis3dqml2_plugin.cpp \ declarativebars.cpp \ declarativebarsrenderer.cpp \ - declarativemaps.cpp \ declarativescatter.cpp \ - declarativescatterrenderer.cpp + declarativescatterrenderer.cpp \ + declarativemaps.cpp \ + declarativemapsrenderer.cpp HEADERS += \ datavis3dqml2_plugin.h \ declarativebars_p.h \ declarativebarsrenderer_p.h \ - declarativemaps.h \ - declarativemaps_p.h \ declarativescatter_p.h \ - declarativescatterrenderer_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 5c61099d..1a2804f6 100644 --- a/src/datavis3dqml2/datavis3dqml2_plugin.cpp +++ b/src/datavis3dqml2/datavis3dqml2_plugin.cpp @@ -42,14 +42,11 @@ #include "datavis3dqml2_plugin.h" #include -#include QT_DATAVIS3D_BEGIN_NAMESPACE void Datavis3dqml2Plugin::registerTypes(const char *uri) { - qDebug() << "Datavis3dqml2Plugin::registerTypes()"; - // @uri com.digia.QtDataVis3D qmlRegisterUncreatableType(uri, 1, 0, "AbstractItemModel", QLatin1String("Trying to create uncreatable: AbstractItemModel.")); diff --git a/src/datavis3dqml2/datavis3dqml2_plugin.h b/src/datavis3dqml2/datavis3dqml2_plugin.h index 8861bbe2..4b6a2e8c 100644 --- a/src/datavis3dqml2/datavis3dqml2_plugin.h +++ b/src/datavis3dqml2/datavis3dqml2_plugin.h @@ -44,7 +44,7 @@ #include "datavis3dglobal_p.h" #include "declarativebars_p.h" -#include "declarativemaps.h" +#include "declarativemaps_p.h" #include "declarativescatter_p.h" #include "qitemmodelbardatamapping.h" #include "qitemmodelmapdatamapping.h" @@ -63,7 +63,6 @@ Q_DECLARE_METATYPE(QItemModelMapDataMapping *) Q_DECLARE_METATYPE(QItemModelScatterDataMapping *) Q_DECLARE_METATYPE(QAbstractItemModel *) - QT_DATAVIS3D_BEGIN_NAMESPACE class Datavis3dqml2Plugin : public QQmlExtensionPlugin diff --git a/src/datavis3dqml2/declarativebars.cpp b/src/datavis3dqml2/declarativebars.cpp index 03ceb448..ba77d783 100644 --- a/src/datavis3dqml2/declarativebars.cpp +++ b/src/datavis3dqml2/declarativebars.cpp @@ -41,7 +41,6 @@ #include "declarativebars_p.h" #include "declarativebarsrenderer_p.h" -#include "bars3dcontroller_p.h" #include "qitemmodelbardataproxy.h" #include "qvalueaxis.h" @@ -123,9 +122,9 @@ void DeclarativeBars::setBarType(BarStyle style, bool smooth) m_shared->setBarType(style, smooth); } -void DeclarativeBars::setupSampleSpace(int samplesRow, int samplesColumn) +void DeclarativeBars::setupSampleSpace(int rowCount, int columnCount) { - m_shared->setupSampleSpace(samplesRow, samplesColumn); + m_shared->setupSampleSpace(rowCount, columnCount); } void DeclarativeBars::setCameraPreset(CameraPreset preset) diff --git a/src/datavis3dqml2/declarativebars_p.h b/src/datavis3dqml2/declarativebars_p.h index b80cdcaf..4f243ad2 100644 --- a/src/datavis3dqml2/declarativebars_p.h +++ b/src/datavis3dqml2/declarativebars_p.h @@ -130,8 +130,8 @@ public: // 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); + // how many samples per row and column + Q_INVOKABLE void setupSampleSpace(int rowCount, int columnCount); // Select preset camera placement Q_INVOKABLE void setCameraPreset(CameraPreset preset); diff --git a/src/datavis3dqml2/declarativebarsrenderer.cpp b/src/datavis3dqml2/declarativebarsrenderer.cpp index 798d641c..e89dcfd8 100644 --- a/src/datavis3dqml2/declarativebarsrenderer.cpp +++ b/src/datavis3dqml2/declarativebarsrenderer.cpp @@ -40,7 +40,6 @@ ****************************************************************************/ #include "declarativebarsrenderer_p.h" -#include "bars3dcontroller_p.h" #include #include diff --git a/src/datavis3dqml2/declarativemaps.cpp b/src/datavis3dqml2/declarativemaps.cpp index f8ab70cf..758d2d5e 100644 --- a/src/datavis3dqml2/declarativemaps.cpp +++ b/src/datavis3dqml2/declarativemaps.cpp @@ -39,23 +39,16 @@ ** ****************************************************************************/ -#include "declarativemaps.h" -#include "maps3dcontroller_p.h" +#include "declarativemaps_p.h" +#include "declarativemapsrenderer_p.h" #include "qitemmodelmapdataproxy.h" -#include -#include -#include -#include -#include -#include QT_DATAVIS3D_BEGIN_NAMESPACE DeclarativeMaps::DeclarativeMaps(QQuickItem *parent) : QQuickItem(parent), m_shared(0), - m_cachedState(new DeclarativeMapsCachedStatePrivate()), - m_initializedSize(0,0) + m_initializedSize(0, 0) { setFlags(QQuickItem::ItemHasContents); setAcceptedMouseButtons(Qt::AllButtons); @@ -80,19 +73,6 @@ void DeclarativeMaps::componentComplete() qDebug() << "componentComplete"; } -void DeclarativeMaps::setData(QAbstractItemModel *data) -{ - m_cachedState->m_model = data; -} - -QAbstractItemModel *DeclarativeMaps::data() -{ - if (m_cachedState->m_model) - return m_cachedState->m_model; - else - return static_cast(m_shared->dataProxy())->itemModel(); -} - QSGNode *DeclarativeMaps::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) { if (!m_shared) { @@ -101,96 +81,6 @@ QSGNode *DeclarativeMaps::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData m_shared->initializeOpenGL(); } - if (m_cachedState->m_model) { - static_cast(m_shared->dataProxy())->setItemModel(m_cachedState->m_model); - m_cachedState->m_model = 0; - } - - if (m_cachedState->m_mapping) { - static_cast(m_shared->dataProxy())->setMapping(m_cachedState->m_mapping); - m_cachedState->m_mapping = 0; - } - - // Check if properites have changed that need to be applied while on the SGRenderThread - if (m_cachedState->m_isAreaRectSet) { - m_shared->setAreaSpecs(m_cachedState->m_arearect, m_cachedState->m_image); - m_cachedState->m_isAreaRectSet = false; - } - - if (m_cachedState->m_isImageSet) { - m_shared->setImage(m_cachedState->m_image); - m_cachedState->m_isImageSet = false; - } - - if (m_cachedState->m_isBarSpecsSet) { - m_shared->setBarSpecs(m_cachedState->m_thickness, m_cachedState->m_direction); - m_cachedState->m_isBarSpecsSet = false; - } - - if (m_cachedState->m_isSelectionModeSet) { - m_shared->setSelectionMode(m_cachedState->m_selectionMode); - m_cachedState->m_isSelectionModeSet = false; - } - - if (m_cachedState->m_isLabelTransparencySet) { - m_shared->setLabelTransparency(m_cachedState->m_labelTransparency); - m_cachedState->m_isLabelTransparencySet = false; - } - - if (m_cachedState->m_isShadowQualitySet) { - m_shared->setShadowQuality(m_cachedState->m_shadowQuality); - m_cachedState->m_isShadowQualitySet = false; - } - - if (m_cachedState->m_fontsize) { - m_shared->setFontSize(m_cachedState->m_fontsize); - m_cachedState->m_fontsize = 0.0; - } - - if (m_cachedState->m_isBarStyleSet) { - m_shared->setBarType(m_cachedState->m_barstyle, m_cachedState->m_barsmooth); - m_cachedState->m_isBarStyleSet = false; - } - - if (m_cachedState->m_isMeshSet) { - m_shared->setMeshFileName(m_cachedState->m_meshfilename); - m_cachedState->m_isMeshSet = false; - } - - if (m_cachedState->m_isCameraPresetSet) { - m_shared->setCameraPreset(m_cachedState->m_camerapreset); - m_cachedState->m_isCameraPresetSet = false; - } - - if (m_cachedState->m_camdistance) { - m_shared->setCameraPosition(m_cachedState->m_camhorizontal, - m_cachedState->m_camvertical, - m_cachedState->m_camdistance); - m_cachedState->m_camdistance = 0.0f; - } - - if (m_cachedState->m_isThemeSet) { - m_shared->setTheme(m_cachedState->m_theme); - m_cachedState->m_isThemeSet = false; - } - - if (m_cachedState->m_isColorSet) { - m_shared->setBarColor(m_cachedState->m_basecolor, - m_cachedState->m_heightcolor, - m_cachedState->m_coloruniform); - m_cachedState->m_isColorSet = false; - } - - if (m_cachedState->m_isFontSet) { - m_shared->setFont(m_cachedState->m_font); - m_cachedState->m_isFontSet = false; - } - - if (m_cachedState->m_isLabelTransparencySet) { - m_shared->setLabelTransparency(m_cachedState->m_labelTransparency); - m_cachedState->m_isLabelTransparencySet = false; - } - // 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). @@ -212,167 +102,125 @@ QSGNode *DeclarativeMaps::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData return node; } +void DeclarativeMaps::setData(QAbstractItemModel *data) +{ + static_cast(m_shared->dataProxy())->setItemModel(data); +} + +QAbstractItemModel *DeclarativeMaps::data() +{ + return static_cast(m_shared->dataProxy())->itemModel(); +} + void DeclarativeMaps::setBarSpecs(const QVector3D &thickness, Q3DMaps::AdjustmentDirection direction) { - m_cachedState->m_thickness = thickness; - m_cachedState->m_direction = direction; - m_cachedState->m_isBarSpecsSet = true; - update(); + m_shared->setBarSpecs(thickness, direction); } void DeclarativeMaps::setBarType(BarStyle style, bool smooth) { - m_cachedState->m_barstyle = style; - m_cachedState->m_barsmooth = smooth; - m_cachedState->m_isBarStyleSet = true; - update(); + m_shared->setBarType(style, smooth); } void DeclarativeMaps::setMeshFileName(const QString &objFileName) { - m_cachedState->m_meshfilename = objFileName; - m_cachedState->m_isMeshSet = true; - update(); + m_shared->setMeshFileName(objFileName); } void DeclarativeMaps::setCameraPreset(CameraPreset preset) { - m_cachedState->m_camerapreset = preset; - m_cachedState->m_isCameraPresetSet = true; - update(); + m_shared->setCameraPreset(preset); } void DeclarativeMaps::setCameraPosition(GLfloat horizontal, GLfloat vertical, GLint distance) { - m_cachedState->m_camhorizontal = horizontal; - m_cachedState->m_camvertical = vertical; - m_cachedState->m_camdistance = distance; - update(); + m_shared->setCameraPosition(horizontal, vertical, distance); } void DeclarativeMaps::setTheme(ColorTheme theme) { - m_cachedState->m_theme = theme; - m_cachedState->m_isThemeSet = true; - update(); + m_shared->setTheme(theme); } void DeclarativeMaps::setBarColor(QColor baseColor, QColor heightColor, bool uniform) { - m_cachedState->m_basecolor = baseColor; - m_cachedState->m_heightcolor = heightColor; - m_cachedState->m_coloruniform = uniform; - m_cachedState->m_isColorSet = true; - update(); + m_shared->setBarColor(baseColor, heightColor, uniform); } void DeclarativeMaps::setAreaSpecs(const QRect &areaRect, const QImage &image) { - m_cachedState->m_arearect = areaRect; - m_cachedState->m_isAreaRectSet = true; - m_cachedState->m_image = image; - update(); + m_shared->setAreaSpecs(areaRect, image); } void DeclarativeMaps::setImage(const QImage &image) { - m_cachedState->m_image = image; - m_cachedState->m_isImageSet = true; - update(); + m_shared->setImage(image); } void DeclarativeMaps::setImage(const QString &imageUrl) { - m_cachedState->m_image = QImage(imageUrl); - m_cachedState->m_isImageSet = true; - update(); + m_shared->setImage(QImage(imageUrl)); } void DeclarativeMaps::setSelectionMode(DeclarativeMaps::SelectionMode mode) { - m_cachedState->m_selectionMode = QtDataVis3D::SelectionMode(mode); - m_cachedState->m_isSelectionModeSet = true; - update(); + m_shared->setSelectionMode(QtDataVis3D::SelectionMode(mode)); } DeclarativeMaps::SelectionMode DeclarativeMaps::selectionMode() { - if (m_shared) - return DeclarativeMaps::SelectionMode(m_shared->selectionMode()); - else - return DeclarativeMaps::ModeBar; + return DeclarativeMaps::SelectionMode(m_shared->selectionMode()); } void DeclarativeMaps::setFontSize(float fontsize) { - m_cachedState->m_fontsize = fontsize; + m_shared->setFontSize(fontsize); } float DeclarativeMaps::fontSize() { - if (m_shared) - return m_shared->fontSize(); - else - return QFont(QStringLiteral("Arial")).pointSizeF(); + return m_shared->fontSize(); } void DeclarativeMaps::setFont(const QFont &font) { - m_cachedState->m_font = font; - m_cachedState->m_isFontSet = true; - update(); + m_shared->setFont(font); } QFont DeclarativeMaps::font() { - if (m_shared) - return m_shared->font(); - else - return QFont(QStringLiteral("Arial")); + return m_shared->font(); } void DeclarativeMaps::setLabelTransparency(DeclarativeMaps::LabelTransparency transparency) { - m_cachedState->m_labelTransparency = QtDataVis3D::LabelTransparency(transparency); - m_cachedState->m_isLabelTransparencySet = true; - update(); + m_shared->setLabelTransparency(QtDataVis3D::LabelTransparency(transparency)); } DeclarativeMaps::LabelTransparency DeclarativeMaps::labelTransparency() { - if (m_shared) - return DeclarativeMaps::LabelTransparency(m_shared->labelTransparency()); - else - return DeclarativeMaps::TransparencyFromTheme; + return DeclarativeMaps::LabelTransparency(m_shared->labelTransparency()); } void DeclarativeMaps::setShadowQuality(DeclarativeMaps::ShadowQuality quality) { - m_cachedState->m_shadowQuality = QtDataVis3D::ShadowQuality(quality); - m_cachedState->m_isShadowQualitySet = true; - update(); + m_shared->setShadowQuality(QtDataVis3D::ShadowQuality(quality)); } DeclarativeMaps::ShadowQuality DeclarativeMaps::shadowQuality() { - if (m_shared) - return DeclarativeMaps::ShadowQuality(m_shared->shadowQuality()); - else - return DeclarativeMaps::ShadowLow; + return DeclarativeMaps::ShadowQuality(m_shared->shadowQuality()); } QItemModelMapDataMapping *DeclarativeMaps::mapping() const { - if (m_cachedState->m_mapping) - return m_cachedState->m_mapping; - else - return static_cast(m_shared->dataProxy())->mapping(); + return static_cast(m_shared->dataProxy())->mapping(); } void DeclarativeMaps::setMapping(QItemModelMapDataMapping *mapping) { - m_cachedState->m_mapping = mapping; + static_cast(m_shared->dataProxy())->setMapping(mapping); } void DeclarativeMaps::mousePressEvent(QMouseEvent *event) @@ -401,80 +249,4 @@ void DeclarativeMaps::wheelEvent(QWheelEvent *event) m_shared->wheelEvent(event); } -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(); -} - - -DeclarativeMapsCachedStatePrivate::DeclarativeMapsCachedStatePrivate() - : m_isImageSet(false), - m_isBarSpecsSet(false), - m_isAreaRectSet(false), - m_isSelectionModeSet(false), - m_isLabelTransparencySet(false), - m_isShadowQualitySet(false), - m_fontsize(0.0f), - m_isBarStyleSet(false), - m_isMeshSet(false), - m_isCameraPresetSet(false), - m_camdistance(0.0f), - m_isThemeSet(false), - m_isColorSet(false), - m_isFontSet(false) -{ -} - -DeclarativeMapsCachedStatePrivate::~DeclarativeMapsCachedStatePrivate() -{ -} - QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3dqml2/declarativemaps.h b/src/datavis3dqml2/declarativemaps.h deleted file mode 100644 index b6c67447..00000000 --- a/src/datavis3dqml2/declarativemaps.h +++ /dev/null @@ -1,203 +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 "datavis3dglobal_p.h" -#include "maps3dcontroller_p.h" -#include "declarativemaps_p.h" -#include "qitemmodelmapdatamapping.h" - -#include -#include -#include -#include - -class QOpenGLFramebufferObject; -class QSGTexture; -class QQuickWindow; - -QT_DATAVIS3D_BEGIN_NAMESPACE - -class DeclarativeMaps : public QQuickItem -{ - Q_OBJECT - Q_PROPERTY(QAbstractItemModel *data READ data WRITE setData) - Q_PROPERTY(SelectionMode selectionMode READ selectionMode WRITE setSelectionMode) - Q_PROPERTY(LabelTransparency labelTransparency READ labelTransparency WRITE setLabelTransparency) - Q_PROPERTY(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(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(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(BarStyle 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(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(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); - - // 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(); - - // Adjust shadow quality - void setShadowQuality(ShadowQuality quality); - ShadowQuality shadowQuality(); - - QItemModelMapDataMapping *mapping() const; - void setMapping(QItemModelMapDataMapping *mapping); - -protected: - Maps3DController *m_shared; - DeclarativeMapsCachedStatePrivate *m_cachedState; - QSize m_initializedSize; - - QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *); - - void mousePressEvent(QMouseEvent *event); - void mouseReleaseEvent(QMouseEvent *event); - void mouseMoveEvent(QMouseEvent *event); - void wheelEvent(QWheelEvent *event); -}; - -// 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 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/declarativemaps_p.h b/src/datavis3dqml2/declarativemaps_p.h index 7c82f723..2c8484aa 100644 --- a/src/datavis3dqml2/declarativemaps_p.h +++ b/src/datavis3dqml2/declarativemaps_p.h @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2013 Digia Plc and/or its subsidiary(ies). +** Contact: http://www.qtproject.org/legal ** ** This file is part of the QtDataVis3D module. ** @@ -12,7 +12,7 @@ ** 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. +** use the contact form at http://qt.digia.com/contactus. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -20,7 +20,7 @@ ** 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. +** will be met: http://www.gnu.org/licenses/oldlicenses/lgpl2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional ** rights. These rights are described in the Digia Qt LGPL Exception @@ -41,7 +41,7 @@ // // 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 @@ -54,71 +54,132 @@ #include "datavis3dglobal_p.h" #include "maps3dcontroller_p.h" +#include "declarativemaps_p.h" #include "qitemmodelmapdatamapping.h" -#include + #include +#include +#include QT_DATAVIS3D_BEGIN_NAMESPACE -class QDataRow; -class QDataItem; - -class DeclarativeMapsCachedStatePrivate +class DeclarativeMaps : public QQuickItem { + Q_OBJECT + Q_PROPERTY(QAbstractItemModel *data READ data WRITE setData) + Q_PROPERTY(SelectionMode selectionMode READ selectionMode WRITE setSelectionMode) + Q_PROPERTY(LabelTransparency labelTransparency READ labelTransparency WRITE setLabelTransparency) + Q_PROPERTY(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(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 DeclarativeMapsCachedStatePrivate(); - ~DeclarativeMapsCachedStatePrivate(); + 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(BarStyle style, bool smooth = false); + + // override bar type with own mesh + Q_INVOKABLE void setMeshFileName(const QString &objFileName); - void appendData(QDataItem *item); + // Select preset camera placement + Q_INVOKABLE void setCameraPreset(CameraPreset preset); - QAbstractItemModel *m_model; - QItemModelMapDataMapping *m_mapping; + // 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); - bool m_isImageSet; - QImage m_image; + // Set theme (bar colors, shaders, window color, background colors, light intensity and text colors are affected) + Q_INVOKABLE void setTheme(ColorTheme theme); - bool m_isBarSpecsSet; - QVector3D m_thickness; - Q3DMaps::AdjustmentDirection m_direction; + // 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); - bool m_isAreaRectSet; - QRect m_arearect; + // Set area specs + Q_INVOKABLE void setAreaSpecs(const QRect &areaRect, const QImage &image); - bool m_isSelectionModeSet; - SelectionMode m_selectionMode; + // Set area image + Q_INVOKABLE void setImage(const QImage &image); + Q_INVOKABLE void setImage(const QString &imageUrl); - bool m_isLabelTransparencySet; - LabelTransparency m_labelTransparency; + // Change selection mode; single bar, bar and row, bar and column, or all + void setSelectionMode(SelectionMode mode); + SelectionMode selectionMode(); - bool m_isShadowQualitySet; - ShadowQuality m_shadowQuality; + // Font size adjustment + void setFontSize(float fontsize); + float fontSize(); - float m_fontsize; + // Set font + void setFont(const QFont &font); + QFont font(); - bool m_isBarStyleSet; - BarStyle m_barstyle; - bool m_barsmooth; + // Label transparency adjustment + void setLabelTransparency(LabelTransparency transparency); + LabelTransparency labelTransparency(); - bool m_isMeshSet; - QString m_meshfilename; + // Adjust shadow quality + void setShadowQuality(ShadowQuality quality); + ShadowQuality shadowQuality(); - bool m_isCameraPresetSet; - CameraPreset m_camerapreset; + QItemModelMapDataMapping *mapping() const; + void setMapping(QItemModelMapDataMapping *mapping); - float m_camhorizontal; - float m_camvertical; - float m_camdistance; +protected: + Maps3DController *m_shared; - bool m_isThemeSet; - ColorTheme m_theme; + QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *); - bool m_isColorSet; - QColor m_basecolor; - QColor m_heightcolor; - bool m_coloruniform; + void mousePressEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void wheelEvent(QWheelEvent *event); - bool m_isFontSet; - QFont m_font; +private: + QSize m_initializedSize; }; QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3dqml2/declarativemapsrenderer.cpp b/src/datavis3dqml2/declarativemapsrenderer.cpp new file mode 100644 index 00000000..412880b7 --- /dev/null +++ b/src/datavis3dqml2/declarativemapsrenderer.cpp @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtDataVis3D module. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "declarativemapsrenderer_p.h" + +#include +#include + +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..4da7111f --- /dev/null +++ b/src/datavis3dqml2/declarativemapsrenderer_p.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtDataVis3D module. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the QtDataVis3D API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. + +#ifndef DECLARATIVEMAPSRENDERER_P_H +#define DECLARATIVEMAPSRENDERER_P_H + +#include "datavis3dglobal_p.h" +#include "maps3dcontroller_p.h" +#include + +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 index 636382c1..2b483b02 100644 --- a/src/datavis3dqml2/declarativescatter.cpp +++ b/src/datavis3dqml2/declarativescatter.cpp @@ -41,7 +41,6 @@ #include "declarativescatter_p.h" #include "declarativescatterrenderer_p.h" -#include "scatter3dcontroller_p.h" #include "qitemmodelscatterdataproxy.h" QT_DATAVIS3D_BEGIN_NAMESPACE diff --git a/src/datavis3dqml2/declarativescatterrenderer.cpp b/src/datavis3dqml2/declarativescatterrenderer.cpp index 5a437758..90bb8a74 100644 --- a/src/datavis3dqml2/declarativescatterrenderer.cpp +++ b/src/datavis3dqml2/declarativescatterrenderer.cpp @@ -40,7 +40,6 @@ ****************************************************************************/ #include "declarativescatterrenderer_p.h" -#include "scatter3dcontroller_p.h" #include #include -- cgit v1.2.3