summaryrefslogtreecommitdiffstats
path: root/src/datavisualization/engine/surface3drenderer.cpp
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2014-06-25 13:00:55 +0300
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2014-06-26 10:43:39 +0300
commit36417dd3660f75c34328c3420bdd512436da86ff (patch)
treeb940d98d8df6a8a64adc1a638c57f20a4a955c5b /src/datavisualization/engine/surface3drenderer.cpp
parentec195a34594dea6145af5e8f2fedc2f9401d0f14 (diff)
Add flipHorizontalGrid property for surface
This property allows drawind the horizontal grid and axis labels on top of the graph rather than on the bottom. This is useful when surface graph is used for 2D spectrograms in orthographic mode, as otherwise the grid is covered by the surface itself. Particularly relevant for polar plots of the same. Task-number: QTRD-3184 Change-Id: I9dbcdbfc754e13af52d2cf31a1d9991ef4b241f7 Reviewed-by: Mika Salmela <mika.salmela@digia.com>
Diffstat (limited to 'src/datavisualization/engine/surface3drenderer.cpp')
-rw-r--r--src/datavisualization/engine/surface3drenderer.cpp41
1 files changed, 30 insertions, 11 deletions
diff --git a/src/datavisualization/engine/surface3drenderer.cpp b/src/datavisualization/engine/surface3drenderer.cpp
index 60e501f1..5fd59e5e 100644
--- a/src/datavisualization/engine/surface3drenderer.cpp
+++ b/src/datavisualization/engine/surface3drenderer.cpp
@@ -1050,6 +1050,17 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle)
else
m_xFlipped = true;
+ if (m_flipHorizontalGrid) {
+ // Need to determine if camera is below graph top
+ float distanceToCenter = activeCamera->position().length()
+ / 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;
+ } else {
+ m_yFlippedForGrid = m_yFlipped;
+ }
+
// calculate background rotation based on view matrix rotation
if (viewMatrix.row(0).x() > 0 && viewMatrix.row(0).z() <= 0)
backgroundRotation = 270.0f;
@@ -1467,13 +1478,13 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle)
else
lineYRotation = m_yRightAngleRotation;
- if (m_yFlipped)
+ if (m_yFlippedForGrid)
lineXRotation = m_xRightAngleRotation;
else
lineXRotation = m_xRightAngleRotationNeg;
float yFloorLinePosition = -backgroundMargin + gridLineOffset;
- if (m_yFlipped)
+ if (m_yFlipped != m_flipHorizontalGrid)
yFloorLinePosition = -yFloorLinePosition;
// Rows (= Z)
@@ -1844,7 +1855,7 @@ void Surface3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCa
if (m_axisCacheZ.segmentCount() > 0) {
int labelCount = m_axisCacheZ.labelCount();
float labelXTrans = 0.0f;
- float labelYTrans = -backgroundMargin;
+ float labelYTrans = m_flipHorizontalGrid ? backgroundMargin : -backgroundMargin;
if (m_polarGraph) {
// TODO optional placement of radial labels - YTrans up only if over background
labelXTrans = m_scaleXWithBackground + labelMargin;
@@ -1861,7 +1872,7 @@ void Surface3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCa
if (labelAutoAngle == 0.0f) {
if (m_zFlipped)
labelRotation.setY(180.0f);
- if (m_yFlipped) {
+ if (m_yFlippedForGrid) {
if (m_zFlipped)
labelRotation.setY(180.0f);
else
@@ -1873,7 +1884,7 @@ void Surface3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCa
} else {
if (m_zFlipped)
labelRotation.setY(180.0f);
- if (m_yFlipped) {
+ if (m_yFlippedForGrid) {
if (m_zFlipped) {
if (m_xFlipped) {
labelRotation.setX(90.0f - (labelAutoAngle - fractionCamX)
@@ -1978,7 +1989,7 @@ void Surface3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCa
int labelCount = m_axisCacheX.labelCount();
GLfloat labelZTrans = 0.0f;
- GLfloat labelYTrans = -backgroundMargin;
+ float labelYTrans = m_flipHorizontalGrid ? backgroundMargin : -backgroundMargin;
if (m_polarGraph)
labelYTrans += gridLineOffset + gridLineWidth;
else
@@ -1994,7 +2005,7 @@ void Surface3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCa
labelRotation = QVector3D(-90.0f, 90.0f, 0.0f);
if (m_xFlipped)
labelRotation.setY(-90.0f);
- if (m_yFlipped) {
+ if (m_yFlippedForGrid) {
if (m_xFlipped)
labelRotation.setY(-90.0f);
else
@@ -2006,7 +2017,7 @@ void Surface3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCa
labelRotation.setY(-90.0f);
else
labelRotation.setY(90.0f);
- if (m_yFlipped) {
+ if (m_yFlippedForGrid) {
if (m_zFlipped) {
if (m_xFlipped) {
labelRotation.setX(90.0f - (2.0f * labelAutoAngle - fractionCamX)
@@ -2055,10 +2066,12 @@ void Surface3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCa
QQuaternion totalRotation = Utils::calculateRotation(labelRotation);
if (m_polarGraph) {
- if (m_zFlipped != m_xFlipped)
+ if (!m_yFlippedForGrid && (m_zFlipped != m_xFlipped)
+ || m_yFlippedForGrid && (m_zFlipped == m_xFlipped)) {
totalRotation *= m_zRightAngleRotation;
- else
+ } else {
totalRotation *= m_zRightAngleRotationNeg;
+ }
}
QVector3D labelTrans = QVector3D(0.0f,
@@ -2108,7 +2121,8 @@ void Surface3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCa
hAlignment = m_zFlipped ? Qt::AlignRight : Qt::AlignLeft;
else if (gridPosition < 1.0f - centerMargin && gridPosition > 0.5f + centerMargin)
hAlignment = m_zFlipped ? Qt::AlignLeft : Qt::AlignRight;
-
+ if (m_yFlippedForGrid && vAlignment != Qt::AlignCenter)
+ vAlignment = (vAlignment == Qt::AlignTop) ? Qt::AlignBottom : Qt::AlignTop;
alignment = Qt::AlignmentFlag(vAlignment | hAlignment);
} else {
labelTrans.setX(m_axisCacheX.labelPosition(label));
@@ -2417,6 +2431,11 @@ void Surface3DRenderer::updateSelectedPoint(const QPoint &position, QSurface3DSe
m_selectionDirty = true;
}
+void Surface3DRenderer::updateFlipHorizontalGrid(bool flip)
+{
+ m_flipHorizontalGrid = flip;
+}
+
void Surface3DRenderer::resetClickedStatus()
{
m_clickedPosition = Surface3DController::invalidSelectionPosition();