diff options
Diffstat (limited to 'src')
9 files changed, 177 insertions, 64 deletions
diff --git a/src/datavisualization/engine/abstract3drenderer.cpp b/src/datavisualization/engine/abstract3drenderer.cpp index 026795e9..19fdf53b 100644 --- a/src/datavisualization/engine/abstract3drenderer.cpp +++ b/src/datavisualization/engine/abstract3drenderer.cpp @@ -75,7 +75,9 @@ Abstract3DRenderer::Abstract3DRenderer(Abstract3DController *controller) m_yRightAngleRotationNeg(QQuaternion::fromAxisAndAngle(0.0f, 1.0f, 0.0f, -90.0f)), m_zRightAngleRotationNeg(QQuaternion::fromAxisAndAngle(0.0f, 0.0f, 1.0f, -90.0f)), m_xFlipRotation(QQuaternion::fromAxisAndAngle(1.0f, 0.0f, 0.0f, -180.0f)), - m_zFlipRotation(QQuaternion::fromAxisAndAngle(0.0f, 0.0f, 1.0f, -180.0f)) + m_zFlipRotation(QQuaternion::fromAxisAndAngle(0.0f, 0.0f, 1.0f, -180.0f)), + m_vBackgroundMargin(0.1f), + m_hBackgroundMargin(0.1f) { QObject::connect(m_drawer, &Drawer::drawerChanged, this, &Abstract3DRenderer::updateTextures); QObject::connect(this, &Abstract3DRenderer::needRender, controller, @@ -247,6 +249,13 @@ void Abstract3DRenderer::updateScene(Q3DScene *scene) } } +void Abstract3DRenderer::updateTextures() +{ + m_axisCacheX.updateTextures(); + m_axisCacheY.updateTextures(); + m_axisCacheZ.updateTextures(); +} + void Abstract3DRenderer::reInitShaders() { #if !defined(QT_OPENGL_ES_2) @@ -1302,4 +1311,32 @@ void Abstract3DRenderer::drawAngularGrid(ShaderHelper *shader, float yFloorLineP } } +float Abstract3DRenderer::calculatePolarBackgroundMargin() +{ + // Check each extents of each angular label + // Calculate angular position + QVector<float> &labelPositions = m_axisCacheX.formatter()->labelPositions(); + float actualLabelHeight = m_drawer->scaledFontSize() * 2.0f; // All labels are same height + float maxNeededMargin = 0.0f; + + // Axis title needs to be accounted for + if (m_axisCacheX.isTitleVisible()) + maxNeededMargin = 2.0f * actualLabelHeight + 3.0f * labelMargin; + + for (int label = 0; label < labelPositions.size(); label++) { + QSize labelSize = m_axisCacheX.labelItems().at(label)->size(); + float actualLabelWidth = actualLabelHeight / labelSize.height() * labelSize.width(); + float labelPosition = labelPositions.at(label); + qreal angle = labelPosition * M_PI * 2.0; + float x = qAbs((m_graphAspectRatio + labelMargin) * float(qSin(angle))) + + actualLabelWidth - m_graphAspectRatio + labelMargin; + float z = qAbs(-(m_graphAspectRatio + labelMargin) * float(qCos(angle))) + + actualLabelHeight - m_graphAspectRatio + labelMargin; + float neededMargin = qMax(x, z); + maxNeededMargin = qMax(maxNeededMargin, neededMargin); + } + + return maxNeededMargin; +} + QT_END_NAMESPACE_DATAVISUALIZATION diff --git a/src/datavisualization/engine/abstract3drenderer_p.h b/src/datavisualization/engine/abstract3drenderer_p.h index 254d61ca..0c24c41e 100644 --- a/src/datavisualization/engine/abstract3drenderer_p.h +++ b/src/datavisualization/engine/abstract3drenderer_p.h @@ -79,7 +79,7 @@ public: virtual void updateSelectionMode(QAbstract3DGraph::SelectionFlags newMode); virtual void updateOptimizationHint(QAbstract3DGraph::OptimizationHints hint); virtual void updateScene(Q3DScene *scene); - virtual void updateTextures() = 0; + virtual void updateTextures(); virtual void initSelectionBuffer() = 0; virtual void updateSelectionState(SelectionState state); virtual void updateInputPosition(const QPoint &position); @@ -205,6 +205,8 @@ protected: void drawAngularGrid(ShaderHelper *shader, float yFloorLinePos, const QMatrix4x4 &projectionViewMatrix, const QMatrix4x4 &depthMatrix); + float calculatePolarBackgroundMargin(); + bool m_hasNegativeValues; Q3DTheme *m_cachedTheme; Drawer *m_drawer; @@ -266,6 +268,9 @@ protected: QQuaternion m_xFlipRotation; QQuaternion m_zFlipRotation; + float m_vBackgroundMargin; + float m_hBackgroundMargin; + private: friend class Abstract3DController; }; diff --git a/src/datavisualization/engine/axisrendercache.cpp b/src/datavisualization/engine/axisrendercache.cpp index 6fdb84c6..2448483e 100644 --- a/src/datavisualization/engine/axisrendercache.cpp +++ b/src/datavisualization/engine/axisrendercache.cpp @@ -54,10 +54,8 @@ void AxisRenderCache::setDrawer(Drawer *drawer) { m_drawer = drawer; m_font = m_drawer->font(); - if (m_drawer) { - QObject::connect(m_drawer, &Drawer::drawerChanged, this, &AxisRenderCache::updateTextures); + if (m_drawer) updateTextures(); - } } void AxisRenderCache::setType(QAbstract3DAxis::AxisType type) diff --git a/src/datavisualization/engine/axisrendercache_p.h b/src/datavisualization/engine/axisrendercache_p.h index 90321740..9fb04837 100644 --- a/src/datavisualization/engine/axisrendercache_p.h +++ b/src/datavisualization/engine/axisrendercache_p.h @@ -107,7 +107,6 @@ public: inline bool isTitleFixed() const { return m_titleFixed; } inline void setTitleFixed(bool fixed) { m_titleFixed = fixed; } -public slots: void updateTextures(); private: diff --git a/src/datavisualization/engine/bars3drenderer.cpp b/src/datavisualization/engine/bars3drenderer.cpp index 70310c23..0b4d5b25 100644 --- a/src/datavisualization/engine/bars3drenderer.cpp +++ b/src/datavisualization/engine/bars3drenderer.cpp @@ -2553,6 +2553,8 @@ void Bars3DRenderer::loadBackgroundMesh() void Bars3DRenderer::updateTextures() { + Abstract3DRenderer::updateTextures(); + // Drawer has changed; this flag needs to be checked when checking if we need to update labels m_updateLabels = true; } diff --git a/src/datavisualization/engine/scatter3drenderer.cpp b/src/datavisualization/engine/scatter3drenderer.cpp index 86faca96..075f252f 100644 --- a/src/datavisualization/engine/scatter3drenderer.cpp +++ b/src/datavisualization/engine/scatter3drenderer.cpp @@ -63,13 +63,13 @@ Scatter3DRenderer::Scatter3DRenderer(Scatter3DController *controller) m_scaleX(0.0f), m_scaleZ(0.0f), m_scaleXWithBackground(0.0f), + m_scaleYWithBackground(0.0f), m_scaleZWithBackground(0.0f), m_selectedItemIndex(Scatter3DController::invalidSelectionIndex()), m_selectedSeriesCache(0), m_oldSelectedSeriesCache(0), m_dotSizeScale(1.0f), m_hasHeightAdjustmentChanged(true), - m_backgroundMargin(defaultMaxSize), m_maxItemSize(0.0f), m_clickedIndex(Scatter3DController::invalidSelectionIndex()), m_havePointSeries(false), @@ -162,7 +162,8 @@ void Scatter3DRenderer::updateData() } if (totalDataSize) { - m_dotSizeScale = GLfloat(qBound(defaultMinSize, 2.0f / float(qSqrt(qreal(totalDataSize))), + m_dotSizeScale = GLfloat(qBound(defaultMinSize, + 2.0f / float(qSqrt(qreal(totalDataSize))), defaultMaxSize)); } @@ -246,10 +247,6 @@ void Scatter3DRenderer::updateSeries(const QList<QAbstract3DSeries *> &seriesLis } } m_maxItemSize = maxItemSize; - if (maxItemSize > defaultMaxSize) - m_backgroundMargin = maxItemSize / itemScaler; - else - m_backgroundMargin = defaultMaxSize; calculateSceneScalingFactors(); if (noSelection) { @@ -302,6 +299,26 @@ void Scatter3DRenderer::updateScene(Q3DScene *scene) Abstract3DRenderer::updateScene(scene); } +void Scatter3DRenderer::updateAxisLabels(QAbstract3DAxis::AxisOrientation orientation, + const QStringList &labels) +{ + Abstract3DRenderer::updateAxisLabels(orientation, labels); + + // Angular axis label dimensions affect the chart dimensions + if (m_polarGraph && orientation == QAbstract3DAxis::AxisOrientationX) + calculateSceneScalingFactors(); +} + +void Scatter3DRenderer::updateAxisTitleVisibility(QAbstract3DAxis::AxisOrientation orientation, + bool visible) +{ + Abstract3DRenderer::updateAxisTitleVisibility(orientation, visible); + + // Angular axis title existence affects the chart dimensions + if (m_polarGraph && orientation == QAbstract3DAxis::AxisOrientationX) + calculateSceneScalingFactors(); +} + void Scatter3DRenderer::resetClickedStatus() { m_clickedIndex = Scatter3DController::invalidSelectionIndex(); @@ -989,7 +1006,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) QMatrix4x4 MVPMatrix; QMatrix4x4 itModelMatrix; - QVector3D bgScale(m_scaleXWithBackground, 1.0f + m_backgroundMargin, + QVector3D bgScale(m_scaleXWithBackground, m_scaleYWithBackground, m_scaleZWithBackground); modelMatrix.scale(bgScale); // If we're viewing from below, background object must be flipped @@ -1047,7 +1064,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) // Draw grid lines QVector3D gridLineScaleX(m_scaleXWithBackground, gridLineWidth, gridLineWidth); QVector3D gridLineScaleZ(gridLineWidth, gridLineWidth, m_scaleZWithBackground); - QVector3D gridLineScaleY(gridLineWidth, 1.0f + m_backgroundMargin, gridLineWidth); + QVector3D gridLineScaleY(gridLineWidth, m_scaleYWithBackground, gridLineWidth); if (m_cachedTheme->isGridEnabled()) { #if !(defined QT_OPENGL_ES_2) @@ -1093,7 +1110,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) else lineXRotation = m_xRightAngleRotationNeg; - GLfloat yFloorLinePosition = -1.0f - m_backgroundMargin + gridLineOffset; + GLfloat yFloorLinePosition = -m_scaleYWithBackground + gridLineOffset; if (m_yFlippedForGrid) yFloorLinePosition = -yFloorLinePosition; @@ -1467,7 +1484,7 @@ void Scatter3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCa if (m_axisCacheZ.segmentCount() > 0) { int labelCount = m_axisCacheZ.labelCount(); float labelXTrans = m_scaleXWithBackground + labelMargin; - float labelYTrans = -1.0f - m_backgroundMargin; + float labelYTrans = -m_scaleYWithBackground; if (m_polarGraph) { labelXTrans *= m_radialLabelOffset; // YTrans up only if over background @@ -1602,7 +1619,7 @@ void Scatter3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCa fractionCamX = activeCamera->xRotation() * labelAngleFraction; int labelCount = m_axisCacheX.labelCount(); float labelZTrans = 0.0f; - float labelYTrans = -1.0f - m_backgroundMargin; + float labelYTrans = -m_scaleYWithBackground; if (m_polarGraph) labelYTrans += gridLineOffset + gridLineWidth; else @@ -1698,10 +1715,10 @@ void Scatter3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCa } float offsetValue = 0.0f; bool showLastLabel = false; - QVector<float> &gridPositions = m_axisCacheX.formatter()->gridPositions(); - int lastGridPosIndex = gridPositions.size() - 1; - if (gridPositions.size() - && (gridPositions.at(lastGridPosIndex) != 1.0f || gridPositions.at(0) != 0.0f)) { + QVector<float> &labelPositions = m_axisCacheX.formatter()->labelPositions(); + int lastLabelPosIndex = labelPositions.size() - 1; + if (labelPositions.size() + && (labelPositions.at(lastLabelPosIndex) != 1.0f || labelPositions.at(0) != 0.0f)) { // Avoid overlapping first and last label if they would get on same position showLastLabel = true; } @@ -1711,24 +1728,24 @@ void Scatter3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCa // Draw the label here if (m_polarGraph) { // Calculate angular position - if (label == lastGridPosIndex && !showLastLabel) + if (label == lastLabelPosIndex && !showLastLabel) continue; - float gridPosition = gridPositions.at(label); - qreal angle = gridPosition * M_PI * 2.0; - labelTrans.setX((m_graphAspectRatio + labelMargin)* float(qSin(angle))); + float labelPosition = labelPositions.at(label); + qreal angle = labelPosition * M_PI * 2.0; + labelTrans.setX((m_graphAspectRatio + labelMargin) * float(qSin(angle))); labelTrans.setZ(-(m_graphAspectRatio + labelMargin) * float(qCos(angle))); // Alignment depends on label angular position, as well as flips Qt::AlignmentFlag vAlignment = Qt::AlignCenter; Qt::AlignmentFlag hAlignment = Qt::AlignCenter; const float centerMargin = 0.005f; - if (gridPosition < 0.25f - centerMargin || gridPosition > 0.75f + centerMargin) + if (labelPosition < 0.25f - centerMargin || labelPosition > 0.75f + centerMargin) vAlignment = m_zFlipped ? Qt::AlignTop : Qt::AlignBottom; - else if (gridPosition > 0.25f + centerMargin && gridPosition < 0.75f - centerMargin) + else if (labelPosition > 0.25f + centerMargin && labelPosition < 0.75f - centerMargin) vAlignment = m_zFlipped ? Qt::AlignBottom : Qt::AlignTop; - if (gridPosition < 0.50f - centerMargin && gridPosition > centerMargin) + if (labelPosition < 0.50f - centerMargin && labelPosition > centerMargin) hAlignment = m_zFlipped ? Qt::AlignRight : Qt::AlignLeft; - else if (gridPosition < 1.0f - centerMargin && gridPosition > 0.5f + centerMargin) + else if (labelPosition < 1.0f - centerMargin && labelPosition > 0.5f + centerMargin) hAlignment = m_zFlipped ? Qt::AlignLeft : Qt::AlignRight; if (m_yFlippedForGrid && vAlignment != Qt::AlignCenter) vAlignment = (vAlignment == Qt::AlignTop) ? Qt::AlignBottom : Qt::AlignTop; @@ -1959,8 +1976,13 @@ void Scatter3DRenderer::loadBackgroundMesh() void Scatter3DRenderer::updateTextures() { + Abstract3DRenderer::updateTextures(); + // Drawer has changed; this flag needs to be checked when checking if we need to update labels m_updateLabels = true; + + if (m_polarGraph) + calculateSceneScalingFactors(); } void Scatter3DRenderer::fixMeshFileName(QString &fileName, QAbstract3DSeries::Mesh mesh) @@ -1992,6 +2014,16 @@ void Scatter3DRenderer::calculateTranslation(ScatterRenderItem &item) void Scatter3DRenderer::calculateSceneScalingFactors() { + if (m_maxItemSize > defaultMaxSize) + m_hBackgroundMargin = m_maxItemSize / itemScaler; + else + m_hBackgroundMargin = defaultMaxSize; + m_vBackgroundMargin = m_hBackgroundMargin; + if (m_polarGraph) { + float polarMargin = calculatePolarBackgroundMargin(); + m_hBackgroundMargin = qMax(m_hBackgroundMargin, polarMargin); + } + m_heightNormalizer = GLfloat(m_axisCacheY.max() - m_axisCacheY.min()) / 2.0f; #ifndef USE_UNIFORM_SCALING // Use this if we want to use autoscaling for x and z QSizeF areaSize; @@ -2014,8 +2046,9 @@ void Scatter3DRenderer::calculateSceneScalingFactors() m_axisCacheX.setScale(2.0f * m_graphAspectRatio); m_axisCacheZ.setScale(-m_axisCacheX.scale()); #endif - m_scaleXWithBackground = m_scaleX + m_backgroundMargin; - m_scaleZWithBackground = m_scaleZ + m_backgroundMargin; + m_scaleXWithBackground = m_scaleX + m_hBackgroundMargin; + m_scaleZWithBackground = m_scaleZ + m_hBackgroundMargin; + m_scaleYWithBackground = m_vBackgroundMargin + 1.0f; m_axisCacheX.setTranslate(-m_axisCacheX.scale() / 2.0f); m_axisCacheZ.setTranslate(-m_axisCacheZ.scale() / 2.0f); } diff --git a/src/datavisualization/engine/scatter3drenderer_p.h b/src/datavisualization/engine/scatter3drenderer_p.h index b5d188e1..645a2a8e 100644 --- a/src/datavisualization/engine/scatter3drenderer_p.h +++ b/src/datavisualization/engine/scatter3drenderer_p.h @@ -67,10 +67,11 @@ private: GLuint m_selectionDepthBuffer; GLfloat m_shadowQualityToShader; GLint m_shadowQualityMultiplier; - GLfloat m_heightNormalizer; + float m_heightNormalizer; float m_scaleX; float m_scaleZ; float m_scaleXWithBackground; + float m_scaleYWithBackground; float m_scaleZWithBackground; int m_selectedItemIndex; ScatterSeriesRenderCache *m_selectedSeriesCache; @@ -78,7 +79,6 @@ private: GLfloat m_dotSizeScale; bool m_hasHeightAdjustmentChanged; ScatterRenderItem m_dummyRenderItem; - GLfloat m_backgroundMargin; GLfloat m_maxItemSize; int m_clickedIndex; bool m_havePointSeries; @@ -95,6 +95,10 @@ public: SeriesRenderCache *createNewCache(QAbstract3DSeries *series); void updateItems(const QVector<Scatter3DController::ChangeItem> &items); void updateScene(Q3DScene *scene); + void updateAxisLabels(QAbstract3DAxis::AxisOrientation orientation, + const QStringList &labels); + void updateAxisTitleVisibility(QAbstract3DAxis::AxisOrientation orientation, + bool visible); QVector3D convertPositionToTranslation(const QVector3D &position, bool isAbsolute); diff --git a/src/datavisualization/engine/surface3drenderer.cpp b/src/datavisualization/engine/surface3drenderer.cpp index 91aeb77f..58c0e245 100644 --- a/src/datavisualization/engine/surface3drenderer.cpp +++ b/src/datavisualization/engine/surface3drenderer.cpp @@ -30,9 +30,6 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION //#define SHOW_DEPTH_TEXTURE_SCENE -// Margin for background (1.10 make it 10% larger to avoid -// selection ball being drawn inside background) -const GLfloat backgroundMargin = 1.1f; const GLfloat sliceZScale = 0.1f; const GLfloat sliceUnits = 2.5f; const uint greenMultiplier = 256; @@ -55,6 +52,7 @@ Surface3DRenderer::Surface3DRenderer(Surface3DController *controller) m_scaleX(0.0f), m_scaleZ(0.0f), m_scaleXWithBackground(0.0f), + m_scaleYWithBackground(0.0f), m_scaleZWithBackground(0.0f), m_depthModelTexture(0), m_depthFrameBuffer(0), @@ -889,7 +887,7 @@ void Surface3DRenderer::drawSlicedScene() } // Vertical lines - QVector3D gridLineScaleY(gridLineWidth, backgroundMargin, gridLineWidth); + QVector3D gridLineScaleY(gridLineWidth, m_scaleYWithBackground, gridLineWidth); gridLineCount = sliceCache.gridLineCount(); for (int line = 0; line < gridLineCount; line++) { @@ -957,7 +955,7 @@ void Surface3DRenderer::drawSlicedScene() labelNbr = 0; positionComp.setY(-0.1f); - labelTrans.setY(-backgroundMargin); + labelTrans.setY(-m_scaleYWithBackground); labelCount = sliceCache.labelCount(); for (int label = 0; label < labelCount; label++) { if (countLabelItems > labelNbr) { @@ -1053,7 +1051,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) / activeCamera->zoomLevel() / m_autoScaleAdjustment * 100.0f; qreal cameraAngle = qreal(activeCamera->yRotation()) / 180.0 * M_PI; float cameraYPos = float(qSin(cameraAngle)) * distanceToCenter; - m_yFlippedForGrid = cameraYPos < backgroundMargin; + m_yFlippedForGrid = cameraYPos < (m_scaleYWithBackground); } else if (m_useOrthoProjection && activeCamera->yRotation() == 0.0f) { // With ortho we only need to flip at angle zero, to fix label autorotation angles m_yFlippedForGrid = !m_yFlipped; @@ -1369,7 +1367,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) QMatrix4x4 MVPMatrix; QMatrix4x4 itModelMatrix; - QVector3D bgScale(m_scaleXWithBackground, backgroundMargin, m_scaleZWithBackground); + QVector3D bgScale(m_scaleXWithBackground, m_scaleYWithBackground, m_scaleZWithBackground); modelMatrix.scale(bgScale); // If we're viewing from below, background object must be flipped @@ -1433,7 +1431,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) // Draw grid lines QVector3D gridLineScaleX(m_scaleXWithBackground, gridLineWidth, gridLineWidth); QVector3D gridLineScaleZ(gridLineWidth, gridLineWidth, m_scaleZWithBackground); - QVector3D gridLineScaleY(gridLineWidth, backgroundMargin, gridLineWidth); + QVector3D gridLineScaleY(gridLineWidth, m_scaleYWithBackground, gridLineWidth); if (m_cachedTheme->isGridEnabled() && m_heightNormalizer) { #if !(defined QT_OPENGL_ES_2) @@ -1479,7 +1477,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) else lineXRotation = m_xRightAngleRotationNeg; - float yFloorLinePosition = -backgroundMargin + gridLineOffset; + float yFloorLinePosition = -m_scaleYWithBackground + gridLineOffset; if (m_yFlipped != m_flipHorizontalGrid) yFloorLinePosition = -yFloorLinePosition; @@ -1851,7 +1849,7 @@ void Surface3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCa if (m_axisCacheZ.segmentCount() > 0) { int labelCount = m_axisCacheZ.labelCount(); float labelXTrans = m_scaleXWithBackground + labelMargin; - float labelYTrans = m_flipHorizontalGrid ? backgroundMargin : -backgroundMargin; + float labelYTrans = m_flipHorizontalGrid ? m_scaleYWithBackground : -m_scaleYWithBackground; if (m_polarGraph) { labelXTrans *= m_radialLabelOffset; // YTrans up only if over background @@ -1991,7 +1989,7 @@ void Surface3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCa int labelCount = m_axisCacheX.labelCount(); float labelZTrans = 0.0f; - float labelYTrans = m_flipHorizontalGrid ? backgroundMargin : -backgroundMargin; + float labelYTrans = m_flipHorizontalGrid ? m_scaleYWithBackground : -m_scaleYWithBackground; if (m_polarGraph) labelYTrans += gridLineOffset + gridLineWidth; else @@ -2091,10 +2089,10 @@ void Surface3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCa } float offsetValue = 0.0f; bool showLastLabel = false; - QVector<float> &gridPositions = m_axisCacheX.formatter()->gridPositions(); - int lastGridPosIndex = gridPositions.size() - 1; - if (gridPositions.size() - && (gridPositions.at(lastGridPosIndex) != 1.0f || gridPositions.at(0) != 0.0f)) { + QVector<float> &labelPositions = m_axisCacheX.formatter()->labelPositions(); + int lastLabelPosIndex = labelPositions.size() - 1; + if (labelPositions.size() + && (labelPositions.at(lastLabelPosIndex) != 1.0f || labelPositions.at(0) != 0.0f)) { // Avoid overlapping first and last label if they would get on same position showLastLabel = true; } @@ -2104,24 +2102,24 @@ void Surface3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCa // Draw the label here if (m_polarGraph) { // Calculate angular position - if (label == lastGridPosIndex && !showLastLabel) + if (label == lastLabelPosIndex && !showLastLabel) continue; - float gridPosition = gridPositions.at(label); - qreal angle = gridPosition * M_PI * 2.0; - labelTrans.setX((m_graphAspectRatio + labelMargin)* float(qSin(angle))); + float labelPosition = labelPositions.at(label); + qreal angle = labelPosition * M_PI * 2.0; + labelTrans.setX((m_graphAspectRatio + labelMargin) * float(qSin(angle))); labelTrans.setZ(-(m_graphAspectRatio + labelMargin) * float(qCos(angle))); // Alignment depends on label angular position, as well as flips Qt::AlignmentFlag vAlignment = Qt::AlignCenter; Qt::AlignmentFlag hAlignment = Qt::AlignCenter; const float centerMargin = 0.005f; - if (gridPosition < 0.25f - centerMargin || gridPosition > 0.75f + centerMargin) + if (labelPosition < 0.25f - centerMargin || labelPosition > 0.75f + centerMargin) vAlignment = m_zFlipped ? Qt::AlignTop : Qt::AlignBottom; - else if (gridPosition > 0.25f + centerMargin && gridPosition < 0.75f - centerMargin) + else if (labelPosition > 0.25f + centerMargin && labelPosition < 0.75f - centerMargin) vAlignment = m_zFlipped ? Qt::AlignBottom : Qt::AlignTop; - if (gridPosition < 0.50f - centerMargin && gridPosition > centerMargin) + if (labelPosition < 0.50f - centerMargin && labelPosition > centerMargin) hAlignment = m_zFlipped ? Qt::AlignRight : Qt::AlignLeft; - else if (gridPosition < 1.0f - centerMargin && gridPosition > 0.5f + centerMargin) + else if (labelPosition < 1.0f - centerMargin && labelPosition > 0.5f + centerMargin) hAlignment = m_zFlipped ? Qt::AlignLeft : Qt::AlignRight; if (m_yFlippedForGrid && vAlignment != Qt::AlignCenter) vAlignment = (vAlignment == Qt::AlignTop) ? Qt::AlignBottom : Qt::AlignTop; @@ -2390,6 +2388,15 @@ void Surface3DRenderer::idToRGBA(uint id, uchar *r, uchar *g, uchar *b, uchar *a void Surface3DRenderer::calculateSceneScalingFactors() { + if (m_polarGraph) { + float polarMargin = calculatePolarBackgroundMargin(); + m_hBackgroundMargin = qMax(m_hBackgroundMargin, polarMargin); + } else { + // Margin for background (0.10 make it 10% larger to avoid + // selection ball being drawn inside background) + m_hBackgroundMargin = 0.1f; + } + // Calculate scene scaling and translation factors m_heightNormalizer = GLfloat(m_axisCacheY.max() - m_axisCacheY.min()); QSizeF areaSize; @@ -2403,8 +2410,9 @@ void Surface3DRenderer::calculateSceneScalingFactors() m_scaleX = m_graphAspectRatio * areaSize.width() / scaleFactor; m_scaleZ = m_graphAspectRatio * areaSize.height() / scaleFactor; } - m_scaleXWithBackground = m_scaleX + backgroundMargin - 1.0f; - m_scaleZWithBackground = m_scaleZ + backgroundMargin - 1.0f; + m_scaleXWithBackground = m_scaleX + m_hBackgroundMargin; + m_scaleZWithBackground = m_scaleZ + m_hBackgroundMargin; + m_scaleYWithBackground = m_vBackgroundMargin + 1.0f; float factorScaler = 2.0f * m_graphAspectRatio / scaleFactor; m_axisCacheX.setScale(factorScaler * areaSize.width()); @@ -2656,7 +2664,10 @@ void Surface3DRenderer::updateShadowQuality(QAbstract3DGraph::ShadowQuality qual void Surface3DRenderer::updateTextures() { - // Do nothing, but required as it is pure virtual on parent + Abstract3DRenderer::updateTextures(); + + if (m_polarGraph) + calculateSceneScalingFactors(); } void Surface3DRenderer::updateSlicingActive(bool isSlicing) @@ -2830,4 +2841,23 @@ QVector3D Surface3DRenderer::convertPositionToTranslation(const QVector3D &posit return QVector3D(xTrans, yTrans, zTrans); } +void Surface3DRenderer::updateAxisLabels(QAbstract3DAxis::AxisOrientation orientation, + const QStringList &labels) +{ + Abstract3DRenderer::updateAxisLabels(orientation, labels); + + // Angular axis label dimensions affect the chart dimensions + if (m_polarGraph && orientation == QAbstract3DAxis::AxisOrientationX) + calculateSceneScalingFactors(); +} + +void Surface3DRenderer::updateAxisTitleVisibility(QAbstract3DAxis::AxisOrientation orientation, bool visible) +{ + Abstract3DRenderer::updateAxisTitleVisibility(orientation, visible); + + // Angular axis title existence affects the chart dimensions + if (m_polarGraph && orientation == QAbstract3DAxis::AxisOrientationX) + calculateSceneScalingFactors(); +} + QT_END_NAMESPACE_DATAVISUALIZATION diff --git a/src/datavisualization/engine/surface3drenderer_p.h b/src/datavisualization/engine/surface3drenderer_p.h index db174a0d..7a547042 100644 --- a/src/datavisualization/engine/surface3drenderer_p.h +++ b/src/datavisualization/engine/surface3drenderer_p.h @@ -56,11 +56,12 @@ private: ShaderHelper *m_surfaceSliceSmoothShader; ShaderHelper *m_selectionShader; ShaderHelper *m_labelShader; - GLfloat m_heightNormalizer; - GLfloat m_scaleX; - GLfloat m_scaleZ; - GLfloat m_scaleXWithBackground; - GLfloat m_scaleZWithBackground; + float m_heightNormalizer; + float m_scaleX; + float m_scaleZ; + float m_scaleXWithBackground; + float m_scaleYWithBackground; + float m_scaleZWithBackground; GLuint m_depthModelTexture; GLuint m_depthFrameBuffer; GLuint m_selectionFrameBuffer; @@ -97,6 +98,10 @@ public: inline QPoint clickedPosition() const { return m_clickedPosition; } void resetClickedStatus(); QVector3D convertPositionToTranslation(const QVector3D &position, bool isAbsolute); + void updateAxisLabels(QAbstract3DAxis::AxisOrientation orientation, + const QStringList &labels); + void updateAxisTitleVisibility(QAbstract3DAxis::AxisOrientation orientation, + bool visible); void render(GLuint defaultFboHandle = 0); |