diff options
author | Tomi Korpipää <tomi.korpipaa@digia.com> | 2014-04-01 10:04:51 +0300 |
---|---|---|
committer | Tomi Korpipää <tomi.korpipaa@digia.com> | 2014-04-01 10:27:13 +0300 |
commit | e076fa05488bb9f58393f0e636c97d07b6fb446d (patch) | |
tree | eefb7b1aed40640d7eb1f673c2fd63b2f7181027 /src/datavisualization/engine/scatter3drenderer.cpp | |
parent | fe3c9ec0a9fb734e83eb70bc725c303a9d36cd6d (diff) |
Axis label dragging support, part 1
Task-number: QTRD-2367
+ Added label selection support to surface & scatter
+ Added Y-label selection support to bars
Change-Id: I3153f1e38019604be763492feba66c3af084de14
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
Diffstat (limited to 'src/datavisualization/engine/scatter3drenderer.cpp')
-rw-r--r-- | src/datavisualization/engine/scatter3drenderer.cpp | 219 |
1 files changed, 135 insertions, 84 deletions
diff --git a/src/datavisualization/engine/scatter3drenderer.cpp b/src/datavisualization/engine/scatter3drenderer.cpp index 9a2522d4..a6633183 100644 --- a/src/datavisualization/engine/scatter3drenderer.cpp +++ b/src/datavisualization/engine/scatter3drenderer.cpp @@ -547,6 +547,9 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) dotNo++; } } + + drawLabels(true, activeCamera, viewMatrix, projectionMatrix); + glEnable(GL_DITHER); // Read color under cursor @@ -1234,12 +1237,97 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) } } - // Draw axis labels - m_labelShader->bind(); + drawLabels(false, activeCamera, viewMatrix, projectionMatrix); + + // Handle selection clearing and selection label drawing + if (!dotSelectionFound) { + // We have no ownership, don't delete. Just NULL the pointer. + m_selectedItem = NULL; + } else { + glDisable(GL_DEPTH_TEST); + // Draw the selection label + LabelItem &labelItem = selectionLabelItem(); + if (m_selectedItem != selectedItem || m_updateLabels + || !labelItem.textureId() || m_selectionLabelDirty) { + QString labelText = selectionLabel(); + if (labelText.isNull() || m_selectionLabelDirty) { + static const QString xTitleTag(QStringLiteral("@xTitle")); + static const QString yTitleTag(QStringLiteral("@yTitle")); + static const QString zTitleTag(QStringLiteral("@zTitle")); + static const QString xLabelTag(QStringLiteral("@xLabel")); + static const QString yLabelTag(QStringLiteral("@yLabel")); + static const QString zLabelTag(QStringLiteral("@zLabel")); + static const QString seriesNameTag(QStringLiteral("@seriesName")); + + labelText = m_visibleSeriesList[m_selectedItemSeriesIndex].itemLabelFormat(); + + labelText.replace(xTitleTag, m_axisCacheX.title()); + labelText.replace(yTitleTag, m_axisCacheY.title()); + labelText.replace(zTitleTag, m_axisCacheZ.title()); + + if (labelText.contains(xLabelTag)) { + QString valueLabelText = m_axisCacheX.formatter()->stringForValue( + qreal(selectedItem->position().x()), m_axisCacheX.labelFormat()); + labelText.replace(xLabelTag, valueLabelText); + } + if (labelText.contains(yLabelTag)) { + QString valueLabelText = m_axisCacheY.formatter()->stringForValue( + qreal(selectedItem->position().y()), m_axisCacheY.labelFormat()); + labelText.replace(yLabelTag, valueLabelText); + } + if (labelText.contains(zLabelTag)) { + QString valueLabelText = m_axisCacheZ.formatter()->stringForValue( + qreal(selectedItem->position().z()), m_axisCacheZ.labelFormat()); + labelText.replace(zLabelTag, valueLabelText); + } + labelText.replace(seriesNameTag, + m_visibleSeriesList[m_selectedItemSeriesIndex].name()); + + setSelectionLabel(labelText); + m_selectionLabelDirty = false; + } + m_drawer->generateLabelItem(labelItem, labelText); + m_selectedItem = selectedItem; + } + + m_drawer->drawLabel(*selectedItem, labelItem, viewMatrix, projectionMatrix, + zeroVector, zeroVector, selectedItemSize, m_cachedSelectionMode, + m_labelShader, m_labelObj, activeCamera, true, false, + Drawer::LabelOver); + + // Reset label update flag; they should have been updated when we get here + m_updateLabels = false; + glEnable(GL_DEPTH_TEST); + } + + glDisable(GL_TEXTURE_2D); + glDisable(GL_BLEND); + + // Release shader + glUseProgram(0); + + m_selectionDirty = false; +} + +void Scatter3DRenderer::drawLabels(bool drawSelection, const Q3DCamera *activeCamera, + const QMatrix4x4 &viewMatrix, + const QMatrix4x4 &projectionMatrix) { + ShaderHelper *shader = 0; + GLfloat alphaForValueSelection = labelValueAlpha / 255.0f; + GLfloat alphaForRowSelection = labelRowAlpha / 255.0f; + GLfloat alphaForColumnSelection = labelColumnAlpha / 255.0f; + if (drawSelection) { + shader = m_selectionShader; + // m_selectionShader is already bound + } else { + shader = m_labelShader; + shader->bind(); + + glEnable(GL_TEXTURE_2D); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } - glEnable(GL_TEXTURE_2D); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_POLYGON_OFFSET_FILL); // Z Labels @@ -1282,6 +1370,12 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) m_dummyRenderItem.setTranslation(labelTrans); const LabelItem &axisLabelItem = *m_axisCacheZ.labelItems().at(labelNbr); + if (drawSelection) { + QVector4D labelColor = QVector4D(label / 255.0f, 0.0f, 0.0f, + alphaForRowSelection); + shader->setUniformValue(shader->color(), labelColor); + } + m_drawer->drawLabel(m_dummyRenderItem, axisLabelItem, viewMatrix, projectionMatrix, zeroVector, labelRotateVector, 0, m_cachedSelectionMode, m_labelShader, m_labelObj, activeCamera, true, true, @@ -1330,6 +1424,12 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) m_dummyRenderItem.setTranslation(labelTrans); const LabelItem &axisLabelItem = *m_axisCacheX.labelItems().at(labelNbr); + if (drawSelection) { + QVector4D labelColor = QVector4D(0.0f, label / 255.0f, 0.0f, + alphaForColumnSelection); + shader->setUniformValue(shader->color(), labelColor); + } + m_drawer->drawLabel(m_dummyRenderItem, axisLabelItem, viewMatrix, projectionMatrix, zeroVector, labelRotateVector, 0, m_cachedSelectionMode, m_labelShader, m_labelObj, activeCamera, true, true, @@ -1396,6 +1496,12 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) glPolygonOffset(GLfloat(label) / -10.0f, 1.0f); + if (drawSelection) { + QVector4D labelColor = QVector4D(0.0f, 0.0f, label / 255.0f, + alphaForValueSelection); + shader->setUniformValue(shader->color(), labelColor); + } + // Back wall labelTransBack.setY(labelYTrans); m_dummyRenderItem.setTranslation(labelTransBack); @@ -1416,75 +1522,6 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) } } glDisable(GL_POLYGON_OFFSET_FILL); - - // Handle selection clearing and selection label drawing - if (!dotSelectionFound) { - // We have no ownership, don't delete. Just NULL the pointer. - m_selectedItem = NULL; - } else { - glDisable(GL_DEPTH_TEST); - // Draw the selection label - LabelItem &labelItem = selectionLabelItem(); - if (m_selectedItem != selectedItem || m_updateLabels - || !labelItem.textureId() || m_selectionLabelDirty) { - QString labelText = selectionLabel(); - if (labelText.isNull() || m_selectionLabelDirty) { - static const QString xTitleTag(QStringLiteral("@xTitle")); - static const QString yTitleTag(QStringLiteral("@yTitle")); - static const QString zTitleTag(QStringLiteral("@zTitle")); - static const QString xLabelTag(QStringLiteral("@xLabel")); - static const QString yLabelTag(QStringLiteral("@yLabel")); - static const QString zLabelTag(QStringLiteral("@zLabel")); - static const QString seriesNameTag(QStringLiteral("@seriesName")); - - labelText = m_visibleSeriesList[m_selectedItemSeriesIndex].itemLabelFormat(); - - labelText.replace(xTitleTag, m_axisCacheX.title()); - labelText.replace(yTitleTag, m_axisCacheY.title()); - labelText.replace(zTitleTag, m_axisCacheZ.title()); - - if (labelText.contains(xLabelTag)) { - QString valueLabelText = m_axisCacheX.formatter()->stringForValue( - qreal(selectedItem->position().x()), m_axisCacheX.labelFormat()); - labelText.replace(xLabelTag, valueLabelText); - } - if (labelText.contains(yLabelTag)) { - QString valueLabelText = m_axisCacheY.formatter()->stringForValue( - qreal(selectedItem->position().y()), m_axisCacheY.labelFormat()); - labelText.replace(yLabelTag, valueLabelText); - } - if (labelText.contains(zLabelTag)) { - QString valueLabelText = m_axisCacheZ.formatter()->stringForValue( - qreal(selectedItem->position().z()), m_axisCacheZ.labelFormat()); - labelText.replace(zLabelTag, valueLabelText); - } - labelText.replace(seriesNameTag, - m_visibleSeriesList[m_selectedItemSeriesIndex].name()); - - setSelectionLabel(labelText); - m_selectionLabelDirty = false; - } - m_drawer->generateLabelItem(labelItem, labelText); - m_selectedItem = selectedItem; - } - - m_drawer->drawLabel(*selectedItem, labelItem, viewMatrix, projectionMatrix, - zeroVector, zeroVector, selectedItemSize, m_cachedSelectionMode, - m_labelShader, m_labelObj, activeCamera, true, false, - Drawer::LabelOver); - - // Reset label update flag; they should have been updated when we get here - m_updateLabels = false; - glEnable(GL_DEPTH_TEST); - } - - glDisable(GL_TEXTURE_2D); - glDisable(GL_BLEND); - - // Release shader - glUseProgram(0); - - m_selectionDirty = false; } void Scatter3DRenderer::updateSelectedItem(int index, const QScatter3DSeries *series) @@ -1735,16 +1772,30 @@ void Scatter3DRenderer::selectionColorToSeriesAndIndex(const QVector4D &color, QAbstract3DSeries *&series) { if (color != selectionSkipColor) { - index = int(color.x()) - + (int(color.y()) << 8) - + (int(color.z()) << 16); - // Find the series and adjust the index accordingly - for (int i = 0; i < m_renderingArrays.size(); i++) { - if (index < m_renderingArrays.at(i).size()) { - series = m_visibleSeriesList.at(i).series(); - return; // Valid found and already set to return parameters, so we can return - } else { - index -= m_renderingArrays.at(i).size(); + if (color.w() == labelRowAlpha) { + // Row selection + index = Scatter3DController::invalidSelectionIndex(); + // TODO: Pass label clicked info to input handler (implement in part 2) + } else if (color.w() == labelColumnAlpha) { + // Column selection + index = Scatter3DController::invalidSelectionIndex(); + // TODO: Pass label clicked info to input handler (implement in part 2) + } else if (color.w() == labelValueAlpha) { + // Value selection + index = Scatter3DController::invalidSelectionIndex(); + // TODO: Pass label clicked info to input handler (implement in part 2) + } else { + index = int(color.x()) + + (int(color.y()) << 8) + + (int(color.z()) << 16); + // Find the series and adjust the index accordingly + for (int i = 0; i < m_renderingArrays.size(); i++) { + if (index < m_renderingArrays.at(i).size()) { + series = m_visibleSeriesList.at(i).series(); + return; // Valid found and already set to return parameters, so we can return + } else { + index -= m_renderingArrays.at(i).size(); + } } } } |