diff options
author | Keränen Pasi <pasi.keranen@digia.com> | 2013-06-14 09:31:51 +0300 |
---|---|---|
committer | Pasi Keränen <pasi.keranen@digia.com> | 2013-06-14 09:46:48 +0300 |
commit | 8129d95e6cd49f36274d3ccdc370b36dc5232161 (patch) | |
tree | 92222ee509a0a6deefd139f452f7635772f3c836 | |
parent | d7ebab1657fe8f1b0992a081ffd4047aad61a8e3 (diff) |
Rendering code placeholder added for 3D Bars.
Change-Id: I23d815dace8298d034c339c90e7bc0a0a4375d77
Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
-rw-r--r-- | examples/qmlbarchart/qml/qmlbarchart/main.qml | 2 | ||||
-rw-r--r-- | src/datavis3d/engine/bars3dcontroller.cpp (renamed from src/datavis3d/engine/bars3dshared.cpp) | 240 | ||||
-rw-r--r-- | src/datavis3d/engine/bars3dcontroller_p.h (renamed from src/datavis3d/engine/bars3dshared_p.h) | 63 | ||||
-rw-r--r-- | src/datavis3d/engine/bars3drenderer.cpp | 95 | ||||
-rw-r--r-- | src/datavis3d/engine/bars3drenderer_p.h | 80 | ||||
-rw-r--r-- | src/datavis3d/engine/engine.pri | 6 | ||||
-rw-r--r-- | src/datavis3d/engine/q3dbars.cpp | 4 | ||||
-rw-r--r-- | src/datavis3d/engine/q3dbars_p.h | 4 | ||||
-rw-r--r-- | src/datavis3d/engine/qdataitem.h | 2 | ||||
-rw-r--r-- | src/datavis3d/engine/qdatarow.h | 2 | ||||
-rw-r--r-- | src/datavis3d/engine/qdataset.h | 2 | ||||
-rw-r--r-- | src/datavis3d/engine/theme_p.h | 2 | ||||
-rw-r--r-- | src/datavis3dqml2/declarativebars.cpp | 6 | ||||
-rw-r--r-- | src/datavis3dqml2/declarativebars.h | 8 |
14 files changed, 310 insertions, 206 deletions
diff --git a/examples/qmlbarchart/qml/qmlbarchart/main.qml b/examples/qmlbarchart/qml/qmlbarchart/main.qml index 526b0262..663589b9 100644 --- a/examples/qmlbarchart/qml/qmlbarchart/main.qml +++ b/examples/qmlbarchart/qml/qmlbarchart/main.qml @@ -87,7 +87,7 @@ Item { //data: testdata1 gridVisible: true - shadowQuality: Bars3D.ShadowLow + shadowQuality: Bars3D.ShadowNone selectionMode: Bars3D.ModeNone labelTransparency: Bars3D.TransparencyNone diff --git a/src/datavis3d/engine/bars3dshared.cpp b/src/datavis3d/engine/bars3dcontroller.cpp index e93c9c4e..14adf3b5 100644 --- a/src/datavis3d/engine/bars3dshared.cpp +++ b/src/datavis3d/engine/bars3dcontroller.cpp @@ -39,7 +39,8 @@ ** ****************************************************************************/ -#include "bars3dshared_p.h" +#include "bars3dcontroller_p.h" +#include "bars3drenderer_p.h" #include "camerahelper_p.h" #include "qdataitem_p.h" #include "qdatarow_p.h" @@ -83,37 +84,7 @@ QT_DATAVIS3D_BEGIN_NAMESPACE const GLfloat gridLineWidth = 0.005f; static QVector3D skipColor = QVector3D(255, 255, 255); // Selection texture's background color -Bars3dModel::Bars3dModel(QRect boundingRect) - : m_mousePressed(MouseNone), - m_mousePos(QPoint(0, 0)), - m_selectionMode(ModeBar), - m_boundingRect(boundingRect), - m_objFile(QStringLiteral(":/defaultMeshes/bar")), - m_theme(new Theme()), - m_labelTransparency(TransparencyFromTheme), - m_font(QFont(QStringLiteral("Arial"))), - m_gridEnabled(true), - m_bgrEnabled(true), - m_shadowQuality(ShadowLow), - m_sampleCount(0, 0), - m_selectedBar(0), - m_dataSet(new QDataSet()), - m_axisLabelX(QStringLiteral("X")), - m_axisLabelZ(QStringLiteral("Z")), - m_axisLabelY(QStringLiteral("Y")), - m_zoomSelection(0), - m_tickCount(0), - m_tickStep(0), - m_negativeValues(false) -{ -} - -Bars3dModel::~Bars3dModel() -{ - delete m_dataSet; -} - -Bars3dRenderer::Bars3dRenderer(QRect rect, GLuint fbohandle) +Bars3dController::Bars3dController(QRect rect, GLuint fbohandle) : m_mousePressed(MouseNone), m_mousePos(QPoint(0, 0)), m_selectionMode(ModeBar), @@ -135,6 +106,7 @@ Bars3dRenderer::Bars3dRenderer(QRect rect, GLuint fbohandle) m_tickCount(0), m_tickStep(0), m_negativeValues(false), + m_renderer(0), m_xFlipped(false), m_zFlipped(false), m_yFlipped(false), @@ -180,10 +152,10 @@ Bars3dRenderer::Bars3dRenderer(QRect rect, GLuint fbohandle) { m_theme = new Theme(); m_dataSet->d_ptr->setDrawer(m_drawer); - QObject::connect(m_drawer, &Drawer::drawerChanged, this, &Bars3dRenderer::updateTextures); + QObject::connect(m_drawer, &Drawer::drawerChanged, this, &Bars3dController::updateTextures); } -Bars3dRenderer::~Bars3dRenderer() +Bars3dController::~Bars3dController() { #ifndef USE_HAX0R_SELECTION glDeleteFramebuffers(1, &m_selectionFrameBuffer); @@ -208,7 +180,7 @@ Bars3dRenderer::~Bars3dRenderer() delete m_drawer; } -void Bars3dRenderer::render() +void Bars3dController::render() { if (!m_isInitialized) return; @@ -238,12 +210,14 @@ void Bars3dRenderer::render() drawScene(); } -void Bars3dRenderer::initializeOpenGL() +void Bars3dController::initializeOpenGL() { // Initialization is called multiple times when Qt Quick components are used if (m_isInitialized) return; + m_renderer = new Bars3dRenderer(this); + initializeOpenGLFunctions(); m_textureHelper = new TextureHelper(); @@ -345,7 +319,7 @@ void Bars3dRenderer::initializeOpenGL() loadBackgroundMesh(); } -void Bars3dRenderer::drawZoomScene() +void Bars3dController::drawZoomScene() { // Set clear color QVector3D clearColor = Utils::vectorFromColor(m_theme->m_windowColor); @@ -562,7 +536,7 @@ void Bars3dRenderer::drawZoomScene() m_labelShader->release(); } -void Bars3dRenderer::drawScene() +void Bars3dController::drawScene() { GLint startBar = 0; GLint stopBar = 0; @@ -872,7 +846,7 @@ void Bars3dRenderer::drawScene() glEnable(GL_DITHER); // Read color under cursor - if (Bars3dRenderer::MouseOnScene == m_mousePressed) + if (Bars3dController::MouseOnScene == m_mousePressed) selection = Utils::getSelection(m_mousePos, height()); #ifndef USE_HAX0R_SELECTION @@ -964,10 +938,10 @@ void Bars3dRenderer::drawScene() GLfloat lightStrength = m_theme->m_lightStrength; if (m_selectionMode > ModeNone) { - Bars3dRenderer::SelectionType selectionType = isSelected(row, bar, - selection); + Bars3dController::SelectionType selectionType = isSelected(row, bar, + selection); switch (selectionType) { - case Bars3dRenderer::SelectionBar: { + case Bars3dController::SelectionBar: { barColor = Utils::vectorFromColor(m_theme->m_highlightBarColor); lightStrength = m_theme->m_highlightLightStrength; // Insert data to QDataItem. We have no ownership, don't delete the previous one @@ -990,7 +964,7 @@ void Bars3dRenderer::drawScene() } break; } - case Bars3dRenderer::SelectionRow: { + case Bars3dController::SelectionRow: { // Current bar is on the same row as the selected bar barColor = Utils::vectorFromColor(m_theme->m_highlightRowColor); lightStrength = m_theme->m_highlightLightStrength; @@ -1006,7 +980,7 @@ void Bars3dRenderer::drawScene() } break; } - case Bars3dRenderer::SelectionColumn: { + case Bars3dController::SelectionColumn: { // Current bar is on the same column as the selected bar barColor = Utils::vectorFromColor(m_theme->m_highlightColumnColor); lightStrength = m_theme->m_highlightLightStrength; @@ -1022,7 +996,7 @@ void Bars3dRenderer::drawScene() } break; } - case Bars3dRenderer::SelectionNone: { + case Bars3dController::SelectionNone: { // Current bar is not selected, nor on a row or column // do nothing break; @@ -1422,12 +1396,12 @@ void Bars3dRenderer::drawScene() if (!barSelectionFound) { // We have no ownership, don't delete. Just NULL the pointer. m_selectedBar = NULL; - if (m_zoomActivated && Bars3dRenderer::MouseOnOverview == m_mousePressed) { + if (m_zoomActivated && Bars3dController::MouseOnOverview == m_mousePressed) { m_sceneViewPort = QRect(0, 0, width(), height()); m_zoomActivated = false; } } else if (m_selectionMode >= ModeZoomRow - && Bars3dRenderer::MouseOnScene == m_mousePressed) { + && Bars3dController::MouseOnScene == m_mousePressed) { // Activate zoom mode m_zoomActivated = true; m_sceneViewPort = QRect(0, height() - height() / 5, width() / 5, height() / 5); @@ -1620,16 +1594,16 @@ void Bars3dRenderer::drawScene() } #if defined(Q_OS_ANDROID) -void Bars3dRenderer::mouseDoubleClickEvent(QMouseEvent *event) +void Bars3dController::mouseDoubleClickEvent(QMouseEvent *event) { if (!m_zoomActivated) { - m_mousePressed = Bars3dRenderer::MouseOnScene; + m_mousePressed = Bars3dController::MouseOnScene; // update mouse positions to prevent jumping when releasing or repressing a button m_mousePos = event->pos(); } } -void Bars3dRenderer::touchEvent(QTouchEvent *event) +void Bars3dController::touchEvent(QTouchEvent *event) { static int prevDistance = 0; @@ -1637,7 +1611,7 @@ void Bars3dRenderer::touchEvent(QTouchEvent *event) points = event->touchPoints(); if (points.count() == 2) { - m_mousePressed = Bars3dRenderer::MouseOnPinch; + m_mousePressed = Bars3dController::MouseOnPinch; QPointF distance = points.at(0).pos() - points.at(1).pos(); int newDistance = distance.manhattanLength(); @@ -1658,23 +1632,23 @@ void Bars3dRenderer::touchEvent(QTouchEvent *event) } #endif -void Bars3dRenderer::mousePressEvent(QMouseEvent *event) +void Bars3dController::mousePressEvent(QMouseEvent *event) { if (Qt::LeftButton == event->button()) { if (m_zoomActivated) { if (event->pos().x() <= m_sceneViewPort.width() && event->pos().y() <= m_sceneViewPort.height()) { - m_mousePressed = Bars3dRenderer::MouseOnOverview; + m_mousePressed = Bars3dController::MouseOnOverview; //qDebug() << "Mouse pressed on overview"; } else { - m_mousePressed = Bars3dRenderer::MouseOnZoom; + m_mousePressed = Bars3dController::MouseOnZoom; //qDebug() << "Mouse pressed on zoom"; } } else { #if !defined(Q_OS_ANDROID) - m_mousePressed = Bars3dRenderer::MouseOnScene; + m_mousePressed = Bars3dController::MouseOnScene; #else - m_mousePressed = Bars3dRenderer::MouseRotating; + m_mousePressed = Bars3dController::MouseRotating; #endif // update mouse positions to prevent jumping when releasing or repressing a button m_mousePos = event->pos(); @@ -1685,9 +1659,9 @@ void Bars3dRenderer::mousePressEvent(QMouseEvent *event) m_mousePos = QPoint(0, 0); } else if (Qt::RightButton == event->button()) { #if !defined(Q_OS_ANDROID) - m_mousePressed = Bars3dRenderer::MouseRotating; + m_mousePressed = Bars3dController::MouseRotating; #else - m_mousePressed = Bars3dRenderer::MouseOnScene; + m_mousePressed = Bars3dController::MouseOnScene; #endif // update mouse positions to prevent jumping when releasing or repressing a button m_mousePos = event->pos(); @@ -1695,23 +1669,23 @@ void Bars3dRenderer::mousePressEvent(QMouseEvent *event) CameraHelper::updateMousePos(m_mousePos); } -void Bars3dRenderer::mouseReleaseEvent(QMouseEvent *event) +void Bars3dController::mouseReleaseEvent(QMouseEvent *event) { - if (Bars3dRenderer::MouseRotating == m_mousePressed) { + if (Bars3dController::MouseRotating == m_mousePressed) { // update mouse positions to prevent jumping when releasing or repressing a button m_mousePos = event->pos(); CameraHelper::updateMousePos(event->pos()); } - m_mousePressed = Bars3dRenderer::MouseNone; + m_mousePressed = Bars3dController::MouseNone; } -void Bars3dRenderer::mouseMoveEvent(QMouseEvent *event) +void Bars3dController::mouseMoveEvent(QMouseEvent *event) { - if (Bars3dRenderer::MouseRotating == m_mousePressed) + if (Bars3dController::MouseRotating == m_mousePressed) m_mousePos = event->pos(); } -void Bars3dRenderer::wheelEvent(QWheelEvent *event) +void Bars3dController::wheelEvent(QWheelEvent *event) { if (m_zoomLevel > 100) m_zoomLevel += event->angleDelta().y() / 12; @@ -1725,12 +1699,12 @@ void Bars3dRenderer::wheelEvent(QWheelEvent *event) m_zoomLevel = 10; } -void Bars3dRenderer::resizeNotify() +void Bars3dController::resizeNotify() { if (!m_isInitialized) return; - qDebug() << "Bars3dRenderer::resizeEvent " << width() << "x" <<height(); + qDebug() << "Bars3dController::resizeEvent " << width() << "x" <<height(); // Set view port if (m_zoomActivated) @@ -1757,7 +1731,7 @@ void Bars3dRenderer::resizeNotify() #endif } -void Bars3dRenderer::setBarSpecs(QSizeF thickness, QSizeF spacing, bool relative) +void Bars3dController::setBarSpecs(QSizeF thickness, QSizeF spacing, bool relative) { m_barThickness = thickness; if (relative) { @@ -1770,7 +1744,7 @@ void Bars3dRenderer::setBarSpecs(QSizeF thickness, QSizeF spacing, bool relative calculateSceneScalingFactors(); } -void Bars3dRenderer::setBarType(BarStyle style, bool smooth) +void Bars3dController::setBarType(BarStyle style, bool smooth) { if (style == Bars) { if (smooth) @@ -1803,13 +1777,13 @@ void Bars3dRenderer::setBarType(BarStyle style, bool smooth) loadBarMesh(); } -void Bars3dRenderer::setMeshFileName(const QString &objFileName) +void Bars3dController::setMeshFileName(const QString &objFileName) { m_objFile = objFileName; } -void Bars3dRenderer::setupSampleSpace(int samplesRow, int samplesColumn, const QString &labelRow, - const QString &labelColumn, const QString &labelHeight) +void Bars3dController::setupSampleSpace(int samplesRow, int samplesColumn, const QString &labelRow, + const QString &labelColumn, const QString &labelHeight) { // Disable zoom mode if we're in it (causes crash if not, as zoom selection is deleted) closeZoomMode(); @@ -1829,12 +1803,12 @@ void Bars3dRenderer::setupSampleSpace(int samplesRow, int samplesColumn, const Q m_axisLabelY = labelHeight; } -void Bars3dRenderer::setCameraPreset(CameraPreset preset) +void Bars3dController::setCameraPreset(CameraPreset preset) { CameraHelper::setCameraPreset(preset); } -void Bars3dRenderer::setCameraPosition(GLfloat horizontal, GLfloat vertical, GLint distance) +void Bars3dController::setCameraPosition(GLfloat horizontal, GLfloat vertical, GLint distance) { m_horizontalRotation = qBound(-180.0f, horizontal, 180.0f); m_verticalRotation = qBound(0.0f, vertical, 90.0f); @@ -1844,7 +1818,7 @@ void Bars3dRenderer::setCameraPosition(GLfloat horizontal, GLfloat vertical, GLi //qDebug() << "camera rotation set to" << m_horizontalRotation << m_verticalRotation; } -void Bars3dRenderer::setTheme(ColorTheme theme) +void Bars3dController::setTheme(ColorTheme theme) { m_theme->useTheme(theme); m_drawer->setTheme(*m_theme); @@ -1878,8 +1852,8 @@ void Bars3dRenderer::setTheme(ColorTheme theme) #endif } -void Bars3dRenderer::setBarColor(QColor baseColor, QColor heightColor, QColor depthColor, - bool uniform) +void Bars3dController::setBarColor(QColor baseColor, QColor heightColor, QColor depthColor, + bool uniform) { m_theme->m_baseColor = baseColor; m_theme->m_heightColor = heightColor; @@ -1917,7 +1891,7 @@ void Bars3dRenderer::setBarColor(QColor baseColor, QColor heightColor, QColor de m_theme->m_uniformColor = uniform; } -void Bars3dRenderer::setSelectionMode(SelectionMode mode) +void Bars3dController::setSelectionMode(SelectionMode mode) { m_selectionMode = mode; // Disable zoom if selection mode changes @@ -1927,55 +1901,55 @@ void Bars3dRenderer::setSelectionMode(SelectionMode mode) m_zoomSelection = new QDataRow(); } -SelectionMode Bars3dRenderer::selectionMode() +SelectionMode Bars3dController::selectionMode() { return m_selectionMode; } -void Bars3dRenderer::setFontSize(float fontsize) +void Bars3dController::setFontSize(float fontsize) { m_font.setPointSizeF(fontsize); m_drawer->setFont(m_font); } -float Bars3dRenderer::fontSize() +float Bars3dController::fontSize() { return m_font.pointSizeF(); } -void Bars3dRenderer::setFont(const QFont &font) +void Bars3dController::setFont(const QFont &font) { m_font = font; m_drawer->setFont(font); } -QFont Bars3dRenderer::font() +QFont Bars3dController::font() { return m_font; } -void Bars3dRenderer::setLabelTransparency(LabelTransparency transparency) +void Bars3dController::setLabelTransparency(LabelTransparency transparency) { m_labelTransparency = transparency; m_drawer->setTransparency(transparency); } -LabelTransparency Bars3dRenderer::labelTransparency() +LabelTransparency Bars3dController::labelTransparency() { return m_labelTransparency; } -void Bars3dRenderer::setGridEnabled(bool enable) +void Bars3dController::setGridEnabled(bool enable) { m_gridEnabled = enable; } -bool Bars3dRenderer::gridEnabled() +bool Bars3dController::gridEnabled() { return m_gridEnabled; } -void Bars3dRenderer::setBackgroundEnabled(bool enable) +void Bars3dController::setBackgroundEnabled(bool enable) { if (m_bgrEnabled != enable) { m_bgrEnabled = enable; @@ -1984,12 +1958,12 @@ void Bars3dRenderer::setBackgroundEnabled(bool enable) } } -bool Bars3dRenderer::backgroundEnabled() +bool Bars3dController::backgroundEnabled() { return m_bgrEnabled; } -void Bars3dRenderer::setShadowQuality(ShadowQuality quality) +void Bars3dController::setShadowQuality(ShadowQuality quality) { m_shadowQuality = quality; switch (quality) { @@ -2047,12 +2021,12 @@ void Bars3dRenderer::setShadowQuality(ShadowQuality quality) } } -ShadowQuality Bars3dRenderer::shadowQuality() +ShadowQuality Bars3dController::shadowQuality() { return m_shadowQuality; } -void Bars3dRenderer::setTickCount(GLint tickCount, GLfloat step, GLfloat minimum) +void Bars3dController::setTickCount(GLint tickCount, GLfloat step, GLfloat minimum) { m_tickCount = tickCount; m_tickStep = step; @@ -2062,8 +2036,8 @@ void Bars3dRenderer::setTickCount(GLint tickCount, GLfloat step, GLfloat minimum } } -void Bars3dRenderer::addDataRow(const QVector<float> &dataRow, const QString &labelRow, - const QVector<QString> &labelsColumn) +void Bars3dController::addDataRow(const QVector<float> &dataRow, const QString &labelRow, + const QVector<QString> &labelsColumn) { // Convert to QDataRow and add to QDataSet QDataRow *row = new QDataRow(labelRow); @@ -2077,8 +2051,8 @@ void Bars3dRenderer::addDataRow(const QVector<float> &dataRow, const QString &la m_dataSet->d_ptr->verifySize(m_sampleCount.second); } -void Bars3dRenderer::addDataRow(const QVector<QDataItem*> &dataRow, const QString &labelRow, - const QVector<QString> &labelsColumn) +void Bars3dController::addDataRow(const QVector<QDataItem*> &dataRow, const QString &labelRow, + const QVector<QString> &labelsColumn) { // Convert to QDataRow and add to QDataSet QDataRow *row = new QDataRow(labelRow); @@ -2092,7 +2066,7 @@ void Bars3dRenderer::addDataRow(const QVector<QDataItem*> &dataRow, const QStrin m_dataSet->d_ptr->verifySize(m_sampleCount.second); } -void Bars3dRenderer::addDataRow(QDataRow *dataRow) +void Bars3dController::addDataRow(QDataRow *dataRow) { QDataRow *row = dataRow; // Check that the input data fits into sample space, and resize if it doesn't @@ -2105,9 +2079,9 @@ void Bars3dRenderer::addDataRow(QDataRow *dataRow) handleLimitChange(); } -void Bars3dRenderer::addDataSet(const QVector< QVector<float> > &data, - const QVector<QString> &labelsRow, - const QVector<QString> &labelsColumn) +void Bars3dController::addDataSet(const QVector< QVector<float> > &data, + const QVector<QString> &labelsRow, + const QVector<QString> &labelsColumn) { // Copy axis labels QString xAxis; @@ -2139,9 +2113,9 @@ void Bars3dRenderer::addDataSet(const QVector< QVector<float> > &data, m_dataSet->d_ptr->verifySize(m_sampleCount.second); } -void Bars3dRenderer::addDataSet(const QVector< QVector<QDataItem*> > &data, - const QVector<QString> &labelsRow, - const QVector<QString> &labelsColumn) +void Bars3dController::addDataSet(const QVector< QVector<QDataItem*> > &data, + const QVector<QString> &labelsRow, + const QVector<QString> &labelsColumn) { // Copy axis labels QString xAxis; @@ -2173,7 +2147,7 @@ void Bars3dRenderer::addDataSet(const QVector< QVector<QDataItem*> > &data, m_dataSet->d_ptr->verifySize(m_sampleCount.second); } -void Bars3dRenderer::addDataSet(QDataSet* dataSet) +void Bars3dController::addDataSet(QDataSet* dataSet) { // Disable zoom mode if we're in it (causes crash if not, as zoom selection is deleted) closeZoomMode(); @@ -2188,62 +2162,62 @@ void Bars3dRenderer::addDataSet(QDataSet* dataSet) m_dataSet->d_ptr->setDrawer(m_drawer); } -const QSize Bars3dRenderer::size() +const QSize Bars3dController::size() { return m_boundingRect.size();; } -const QRect Bars3dRenderer::boundingRect() +const QRect Bars3dController::boundingRect() { return m_boundingRect; } -void Bars3dRenderer::setBoundingRect(const QRect boundingRect) +void Bars3dController::setBoundingRect(const QRect boundingRect) { m_boundingRect = boundingRect; } -void Bars3dRenderer::setWidth(const int width) +void Bars3dController::setWidth(const int width) { m_boundingRect.setWidth(width); } -int Bars3dRenderer::width() +int Bars3dController::width() { return m_boundingRect.width(); } -void Bars3dRenderer::setHeight(const int height) +void Bars3dController::setHeight(const int height) { m_boundingRect.setHeight(height); } -int Bars3dRenderer::height() +int Bars3dController::height() { return m_boundingRect.height(); } -void Bars3dRenderer::setX(const int x) +void Bars3dController::setX(const int x) { m_boundingRect.setX(x); } -int Bars3dRenderer::x() +int Bars3dController::x() { return m_boundingRect.x(); } -void Bars3dRenderer::setY(const int y) +void Bars3dController::setY(const int y) { m_boundingRect.setY(y); } -int Bars3dRenderer::y() +int Bars3dController::y() { return m_boundingRect.y(); } -void Bars3dRenderer::loadBarMesh() +void Bars3dController::loadBarMesh() { QString objectFileName = m_objFile; if (m_barObj) @@ -2255,7 +2229,7 @@ void Bars3dRenderer::loadBarMesh() m_barObj->load(); } -void Bars3dRenderer::loadBackgroundMesh() +void Bars3dController::loadBackgroundMesh() { if (!m_isInitialized) return; @@ -2269,7 +2243,7 @@ void Bars3dRenderer::loadBackgroundMesh() m_backgroundObj->load(); } -void Bars3dRenderer::loadGridLineMesh() +void Bars3dController::loadGridLineMesh() { if (m_gridLineObj) delete m_gridLineObj; @@ -2277,7 +2251,7 @@ void Bars3dRenderer::loadGridLineMesh() m_gridLineObj->load(); } -void Bars3dRenderer::loadLabelMesh() +void Bars3dController::loadLabelMesh() { if (m_labelObj) delete m_labelObj; @@ -2285,7 +2259,7 @@ void Bars3dRenderer::loadLabelMesh() m_labelObj->load(); } -void Bars3dRenderer::initShaders(const QString &vertexShader, const QString &fragmentShader) +void Bars3dController::initShaders(const QString &vertexShader, const QString &fragmentShader) { if (m_barShader) delete m_barShader; @@ -2293,7 +2267,7 @@ void Bars3dRenderer::initShaders(const QString &vertexShader, const QString &fra m_barShader->initialize(); } -void Bars3dRenderer::initSelectionShader() +void Bars3dController::initSelectionShader() { if (m_selectionShader) delete m_selectionShader; @@ -2302,7 +2276,7 @@ void Bars3dRenderer::initSelectionShader() m_selectionShader->initialize(); } -void Bars3dRenderer::initSelectionBuffer() +void Bars3dController::initSelectionBuffer() { #ifndef USE_HAX0R_SELECTION if (m_selectionTexture) { @@ -2317,7 +2291,7 @@ void Bars3dRenderer::initSelectionBuffer() } #if !defined(QT_OPENGL_ES_2) -void Bars3dRenderer::initDepthShader() +void Bars3dController::initDepthShader() { if (m_depthShader) delete m_depthShader; @@ -2326,7 +2300,7 @@ void Bars3dRenderer::initDepthShader() m_depthShader->initialize(); } -void Bars3dRenderer::initDepthBuffer() +void Bars3dController::initDepthBuffer() { if (m_depthTexture) { glDeleteFramebuffers(1, &m_depthFrameBuffer); @@ -2337,8 +2311,8 @@ void Bars3dRenderer::initDepthBuffer() } #endif -void Bars3dRenderer::initBackgroundShaders(const QString &vertexShader, - const QString &fragmentShader) +void Bars3dController::initBackgroundShaders(const QString &vertexShader, + const QString &fragmentShader) { if (m_backgroundShader) delete m_backgroundShader; @@ -2346,7 +2320,7 @@ void Bars3dRenderer::initBackgroundShaders(const QString &vertexShader, m_backgroundShader->initialize(); } -void Bars3dRenderer::initLabelShaders(const QString &vertexShader, const QString &fragmentShader) +void Bars3dController::initLabelShaders(const QString &vertexShader, const QString &fragmentShader) { if (m_labelShader) delete m_labelShader; @@ -2354,13 +2328,13 @@ void Bars3dRenderer::initLabelShaders(const QString &vertexShader, const QString m_labelShader->initialize(); } -void Bars3dRenderer::updateTextures() +void Bars3dController::updateTextures() { // Drawer has changed; this flag needs to be checked when checking if we need to update labels m_updateLabels = true; } -void Bars3dRenderer::calculateSceneScalingFactors() +void Bars3dController::calculateSceneScalingFactors() { // Calculate scene scaling and translation factors m_rowWidth = ((m_sampleCount.first + 1) * m_barSpacing.width()) / 2.0f; @@ -2375,15 +2349,15 @@ void Bars3dRenderer::calculateSceneScalingFactors() //qDebug() << "m_rowWidth:" << m_rowWidth << "m_columnDepth:" << m_columnDepth << "m_maxDimension:" << m_maxDimension; } -void Bars3dRenderer::calculateHeightAdjustment(const QPair<GLfloat, GLfloat> &limits) +void Bars3dController::calculateHeightAdjustment(const QPair<GLfloat, GLfloat> &limits) { // 2.0f = max difference between minimum and maximum value after scaling with m_heightNormalizer m_yAdjustment = 2.0f - ((limits.second - limits.first) / m_heightNormalizer); //qDebug() << m_yAdjustment; } -Bars3dRenderer::SelectionType Bars3dRenderer::isSelected(GLint row, GLint bar, - const QVector3D &selection) +Bars3dController::SelectionType Bars3dController::isSelected(GLint row, GLint bar, + const QVector3D &selection) { //static QVector3D prevSel = selection; // TODO: For debugging SelectionType isSelectedType = SelectionNone; @@ -2419,7 +2393,7 @@ Bars3dRenderer::SelectionType Bars3dRenderer::isSelected(GLint row, GLint bar, return isSelectedType; } -void Bars3dRenderer::handleLimitChange() +void Bars3dController::handleLimitChange() { // Get the limits QPair<GLfloat, GLfloat> limits = m_dataSet->d_ptr->limitValues(); @@ -2444,7 +2418,7 @@ void Bars3dRenderer::handleLimitChange() } } -void Bars3dRenderer::closeZoomMode() +void Bars3dController::closeZoomMode() { m_zoomActivated = false; m_sceneViewPort = QRect(0, 0, this->width(), this->height()); diff --git a/src/datavis3d/engine/bars3dshared_p.h b/src/datavis3d/engine/bars3dcontroller_p.h index 9d797b6c..b02cec34 100644 --- a/src/datavis3d/engine/bars3dshared_p.h +++ b/src/datavis3d/engine/bars3dcontroller_p.h @@ -78,60 +78,10 @@ class TextureHelper; class Theme; class Drawer; class LabelItem; +class Bars3dController; class Bars3dRenderer; -class Bars3dModel : public QObject -{ - Q_OBJECT -public: - enum SelectionType { - SelectionNone = 0, - SelectionBar, - SelectionRow, - SelectionColumn - }; - - enum MousePressType { - MouseNone = 0, - MouseOnScene, - MouseOnOverview, - MouseOnZoom, - MouseRotating, - MouseOnPinch - }; - - // Interaction related parameters - MousePressType m_mousePressed; - QPoint m_mousePos; - SelectionMode m_selectionMode; - - // Visual parameters - QRect m_boundingRect; - QString m_objFile; - Theme *m_theme; - LabelTransparency m_labelTransparency; - QFont m_font; - bool m_gridEnabled; - bool m_bgrEnabled; - ShadowQuality m_shadowQuality; - - // Data parameters - QPair<int, int> m_sampleCount; - QDataItem *m_selectedBar; - QDataSet *m_dataSet; - QString m_axisLabelX; - QString m_axisLabelZ; - QString m_axisLabelY; - QDataRow *m_zoomSelection; - GLint m_tickCount; - GLfloat m_tickStep; - bool m_negativeValues; - - explicit Bars3dModel(QRect boundingRect); - ~Bars3dModel(); -}; - -class QT_DATAVIS3D_EXPORT Bars3dRenderer : public QObject, public QOpenGLFunctions +class QT_DATAVIS3D_EXPORT Bars3dController : public QObject, public QOpenGLFunctions { Q_OBJECT @@ -183,6 +133,8 @@ public: GLfloat m_tickStep; bool m_negativeValues; + Bars3dRenderer *m_renderer; + private: // Internal attributes purely related to how the scene is drawn with GL. @@ -231,8 +183,8 @@ private: GLfloat m_maxSceneSize; public: - explicit Bars3dRenderer(QRect rect, GLuint fbohandle=0); - ~Bars3dRenderer(); + explicit Bars3dController(QRect rect, GLuint fbohandle=0); + ~Bars3dController(); void initializeOpenGL(); void render(); @@ -378,12 +330,13 @@ public: private: void drawZoomScene(); void drawScene(); - Q_DISABLE_COPY(Bars3dRenderer) + Q_DISABLE_COPY(Bars3dController) friend class DeclarativeBars; friend class DeclarativeBarsRenderer; }; + QT_DATAVIS3D_END_NAMESPACE #endif diff --git a/src/datavis3d/engine/bars3drenderer.cpp b/src/datavis3d/engine/bars3drenderer.cpp new file mode 100644 index 00000000..f0bc4c8f --- /dev/null +++ b/src/datavis3d/engine/bars3drenderer.cpp @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** 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 "bars3drenderer_p.h" +#include "bars3dcontroller_p.h" +#include "camerahelper_p.h" +#include "qdataitem_p.h" +#include "qdatarow_p.h" +#include "qdataset_p.h" +#include "shaderhelper_p.h" +#include "objecthelper_p.h" +#include "texturehelper_p.h" +#include "theme_p.h" +#include "utils_p.h" +#include "drawer_p.h" + +#include <QMatrix4x4> +#include <QOpenGLPaintDevice> +#include <QPainter> +#include <QScreen> +#include <QMouseEvent> + +#include <qmath.h> + +#include <QDebug> + +// Uncommenting this draws the shadow map with wider FOV than scene itself, making the light +// seem to be closer to scene than it actually is. This way shadows look slightly better (to me anyway) +#define USE_WIDER_SHADOWS + +// You can verify that depth buffer drawing works correctly by uncommenting this. +// You should see the scene from where the light is +//#define SHOW_DEPTH_TEXTURE_SCENE + +//#define DISPLAY_RENDER_SPEED + +#ifdef DISPLAY_RENDER_SPEED +#include <QTime> +#endif + +QT_DATAVIS3D_BEGIN_NAMESPACE + +//#define USE_HAX0R_SELECTION // keep this defined until the "real" method works +#define DISPLAY_FULL_DATA_ON_SELECTION // Append selection value text with row and column labels + +#include "bars3drenderer_p.h" +#include "bars3dcontroller_p.h" + +Bars3dRenderer::Bars3dRenderer(Bars3dController *controller) : QObject(controller) +{ +} + +Bars3dRenderer::~Bars3dRenderer() +{ +} + +QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3d/engine/bars3drenderer_p.h b/src/datavis3d/engine/bars3drenderer_p.h new file mode 100644 index 00000000..7dfd5d8e --- /dev/null +++ b/src/datavis3d/engine/bars3drenderer_p.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** 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 Qt 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 BARS3DRENDERER_P_H +#define BARS3DRENDERER_P_H + +#include "QtDataVis3D/qdatavis3dglobal.h" +#include "QtDataVis3D/qdatavis3namespace.h" +#include <QtCore/QSize> +#include <QtCore/QObject> +#include <QtGui/QOpenGLFunctions> +#include <QtGui/QFont> +#include <QWindow> +#include <QObject> + +QT_DATAVIS3D_BEGIN_NAMESPACE + +class Bars3dController; + +class QT_DATAVIS3D_EXPORT Bars3dRenderer : public QObject, public QOpenGLFunctions +{ + Q_OBJECT + +public: + explicit Bars3dRenderer(Bars3dController *controller); + ~Bars3dRenderer(); +}; + + +QT_DATAVIS3D_END_NAMESPACE + +#endif // BARS3DRENDERER_P_H diff --git a/src/datavis3d/engine/engine.pri b/src/datavis3d/engine/engine.pri index b220120f..0a45d99a 100644 --- a/src/datavis3d/engine/engine.pri +++ b/src/datavis3d/engine/engine.pri @@ -7,7 +7,8 @@ SOURCES += $$PWD/q3dwindow.cpp \ $$PWD/theme.cpp \ $$PWD/drawer.cpp \ $$PWD/labelitem.cpp \ - $$PWD/bars3dshared.cpp + $$PWD/bars3dcontroller.cpp \ + $$PWD/bars3drenderer.cpp HEADERS += $$PWD/q3dwindow_p.h \ $$PWD/q3dwindow.h \ @@ -24,6 +25,7 @@ HEADERS += $$PWD/q3dwindow_p.h \ $$PWD/theme_p.h \ $$PWD/drawer_p.h \ $$PWD/labelitem_p.h \ - $$PWD/bars3dshared_p.h + $$PWD/bars3dcontroller_p.h \ + $$PWD/bars3drenderer_p.h RESOURCES += engine/engine.qrc diff --git a/src/datavis3d/engine/q3dbars.cpp b/src/datavis3d/engine/q3dbars.cpp index 98a39a15..610ca06e 100644 --- a/src/datavis3d/engine/q3dbars.cpp +++ b/src/datavis3d/engine/q3dbars.cpp @@ -41,7 +41,7 @@ #include "q3dbars.h" #include "q3dbars_p.h" -#include "bars3dshared_p.h" +#include "bars3dcontroller_p.h" #include <QOpenGLPaintDevice> #include <QPainter> @@ -704,7 +704,7 @@ void Q3DBars::addDataSet(QDataSet *dataSet) Q3DBarsPrivate::Q3DBarsPrivate(Q3DBars *q, QRect rect, GLuint fbohandle) : q_ptr(q), - m_shared(new Bars3dRenderer(rect, fbohandle)) + m_shared(new Bars3dController(rect, fbohandle)) { } diff --git a/src/datavis3d/engine/q3dbars_p.h b/src/datavis3d/engine/q3dbars_p.h index 38a9b660..3dd030eb 100644 --- a/src/datavis3d/engine/q3dbars_p.h +++ b/src/datavis3d/engine/q3dbars_p.h @@ -52,7 +52,7 @@ #ifndef Q3DBARS_p_H #define Q3DBARS_p_H -#include "bars3dshared_p.h" +#include "bars3dcontroller_p.h" #include "qdatavis3namespace.h" class QOpenGLPaintDevice; @@ -71,7 +71,7 @@ public: ~Q3DBarsPrivate(); Q3DBars *q_ptr; - Bars3dRenderer *m_shared; + Bars3dController *m_shared; }; QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3d/engine/qdataitem.h b/src/datavis3d/engine/qdataitem.h index ae4a3b6d..166600f1 100644 --- a/src/datavis3d/engine/qdataitem.h +++ b/src/datavis3d/engine/qdataitem.h @@ -80,7 +80,7 @@ public: private: QScopedPointer<QDataItemPrivate> d_ptr; - friend class Bars3dRenderer; + friend class Bars3dController; friend class Q3DMaps; friend class Q3DMapsPrivate; friend class QDataRowPrivate; diff --git a/src/datavis3d/engine/qdatarow.h b/src/datavis3d/engine/qdatarow.h index ca98a47d..07631181 100644 --- a/src/datavis3d/engine/qdatarow.h +++ b/src/datavis3d/engine/qdatarow.h @@ -67,7 +67,7 @@ public: private: QScopedPointer<QDataRowPrivate> d_ptr; - friend class Bars3dRenderer; + friend class Bars3dController; friend class Q3DMaps; friend class Q3DMapsPrivate; friend class QDataSetPrivate; diff --git a/src/datavis3d/engine/qdataset.h b/src/datavis3d/engine/qdataset.h index 336f0200..9f8952ec 100644 --- a/src/datavis3d/engine/qdataset.h +++ b/src/datavis3d/engine/qdataset.h @@ -71,7 +71,7 @@ public: private: QScopedPointer<QDataSetPrivate> d_ptr; - friend class Bars3dRenderer; + friend class Bars3dController; friend class Q3DMaps; friend class Q3DMapsPrivate; }; diff --git a/src/datavis3d/engine/theme_p.h b/src/datavis3d/engine/theme_p.h index 9025fd50..13acc8d9 100644 --- a/src/datavis3d/engine/theme_p.h +++ b/src/datavis3d/engine/theme_p.h @@ -69,7 +69,7 @@ public: void useTheme(ColorTheme theme); private: - friend class Bars3dRenderer; + friend class Bars3dController; friend class Q3DMaps; friend class Q3DMapsPrivate; friend class Drawer; diff --git a/src/datavis3dqml2/declarativebars.cpp b/src/datavis3dqml2/declarativebars.cpp index fb0b5f4f..9e0c2390 100644 --- a/src/datavis3dqml2/declarativebars.cpp +++ b/src/datavis3dqml2/declarativebars.cpp @@ -40,7 +40,7 @@ ****************************************************************************/ #include "declarativebars.h" -#include "bars3dshared_p.h" +#include "bars3dcontroller_p.h" #include "qdataset.h" #include <QtQuick/QQuickWindow> @@ -80,7 +80,7 @@ QSGNode *DeclarativeBars::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData delete oldNode; if (!m_shared) - m_shared = new Bars3dRenderer(boundingRect().toRect()); + m_shared = new Bars3dController(boundingRect().toRect()); // Lazy initialization of shared object on the SGRenderThread m_shared->initializeOpenGL(); @@ -319,7 +319,7 @@ void DeclarativeBars::setMeshFileName(const QString &objFileName) -DeclarativeBarsRenderer::DeclarativeBarsRenderer(QQuickWindow *window, Bars3dRenderer *renderer) +DeclarativeBarsRenderer::DeclarativeBarsRenderer(QQuickWindow *window, Bars3dController *renderer) : m_fbo(0), m_texture(0), m_window(window), diff --git a/src/datavis3dqml2/declarativebars.h b/src/datavis3dqml2/declarativebars.h index 67ae287b..fa33420a 100644 --- a/src/datavis3dqml2/declarativebars.h +++ b/src/datavis3dqml2/declarativebars.h @@ -42,7 +42,7 @@ #ifndef DECLARATIVEBARS_H #define DECLARATIVEBARS_H -#include "bars3dshared_p.h" +#include "bars3dcontroller_p.h" #include "qdatavis3dglobal.h" #include "qdatavis3namespace.h" #include "declarativebars_p.h" @@ -77,7 +77,7 @@ class DeclarativeBars : public QQuickItem Q_ENUMS(LabelTransparency) protected: - Bars3dRenderer *m_shared; + Bars3dController *m_shared; DeclarativeBarsCachedStatePrivate *m_cachedState; public: @@ -226,7 +226,7 @@ class DeclarativeBarsRenderer : public QObject, public QSGSimpleTextureNode Q_OBJECT public: - DeclarativeBarsRenderer(QQuickWindow *window, Bars3dRenderer *shared); + DeclarativeBarsRenderer(QQuickWindow *window, Bars3dController *shared); ~DeclarativeBarsRenderer(); public slots: @@ -236,7 +236,7 @@ private: QOpenGLFramebufferObject *m_fbo; QSGTexture *m_texture; QQuickWindow *m_window; - Bars3dRenderer *m_barsRenderer; + Bars3dController *m_barsRenderer; }; QT_DATAVIS3D_END_NAMESPACE |