Fix: Graphs3D series item label visibility

Bars3D and Scatter3D didn't hide the item label according to series'
itemLabelVisible. This was also in the Surface3D but it was fixed
already. However, the fix was not complete since it did not work if the
selection was active.

Fixes: QTBUG-141370
Pick-to: 6.8
Change-Id: I65acfc33e0d41cd4322efe521b7d7ba509ca159a
Reviewed-by: Niko Korkala <niko.korkala@qt.io>
Reviewed-by: Sami Varanka <sami.varanka@qt.io>
(cherry picked from commit 8d8f2ffc91)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Sami Varanka 2025-10-23 14:51:48 +03:00 committed by Qt Cherry-pick Bot
parent c8118a4e58
commit b787f45850
12 changed files with 216 additions and 41 deletions

View File

@ -2,6 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include "q3dscene.h"
#include "qbar3dseries.h"
#include "qbar3dseries_p.h"
#include "qbardataproxy_p.h"
#include "qcategory3daxis_p.h"
@ -650,6 +651,17 @@ void QQuickGraphsBars::handleSeriesVisibilityChangedBySender(QObject *sender)
setSelectedBar(m_selectedBar, m_selectedBarSeries, false);
}
void QQuickGraphsBars::handleItemLabelVisibleChangedBySender(bool visible, QObject *sender)
{
auto series = static_cast<QBar3DSeries *>(sender);
if (series == m_selectedBarSeries)
{
itemLabel()->setVisible(visible);
if (auto label = sliceItemLabel(); label && isSlicingActive())
label->setVisible(visible);
}
}
void QQuickGraphsBars::handleAxisRangeChangedBySender(QObject *sender)
{
// Data window changed
@ -2567,7 +2579,8 @@ void QQuickGraphsBars::updateSelectedBar()
}
updateItemLabel(m_selectedBarPos);
itemLabel()->setVisible(theme()->labelsVisible());
itemLabel()->setVisible(m_selectedBarSeries->isItemLabelVisible()
&& theme()->labelsVisible());
itemLabel()->setProperty("labelText", label);
if (!label.compare(QString(hiddenLabelTag)))
itemLabel()->setVisible(false);
@ -2644,7 +2657,8 @@ void QQuickGraphsBars::updateSliceItemLabel(const QString &label, QVector3D posi
if (!label.compare(QString(hiddenLabelTag)))
sliceItemLabel()->setVisible(false);
sliceItemLabel()->setEulerRotation(QVector3D(0.0f, 0.0f, 90.0f));
sliceItemLabel()->setVisible(theme()->labelsVisible());
sliceItemLabel()->setVisible(m_selectedBarSeries->isItemLabelVisible()
&& theme()->labelsVisible());
}
void QQuickGraphsBars::resetClickedStatus()
@ -2933,7 +2947,8 @@ void QQuickGraphsBars::createBarItemHolders(QBar3DSeries *series,
m_selectedBarPos.setY(m_selectedBarPos.y() + bih->heightValue - 0.2f);
updateItemLabel(m_selectedBarPos);
itemLabel()->setVisible(theme()->labelsVisible());
itemLabel()->setVisible(m_selectedBarSeries->isItemLabelVisible()
&& theme()->labelsVisible());
itemLabel()->setProperty("labelText", label);
if (!label.compare(QString(hiddenLabelTag)))
itemLabel()->setVisible(false);

View File

@ -140,6 +140,7 @@ public:
void handleAxisAutoAdjustRangeChangedInOrientation(QAbstract3DAxis::AxisOrientation orientation,
bool autoAdjust) override;
void handleSeriesVisibilityChangedBySender(QObject *sender) override;
void handleItemLabelVisibleChangedBySender(bool visible, QObject *sender) override;
void handleAxisRangeChangedBySender(QObject *sender) override;
void adjustAxisRanges() override;

View File

@ -1069,6 +1069,11 @@ void QQuickGraphsItem::handleSeriesVisibilityChanged(bool visible)
handleSeriesVisibilityChangedBySender(sender());
}
void QQuickGraphsItem::handleItemLabelVisibleChanged(bool visible)
{
handleItemLabelVisibleChangedBySender(visible, sender());
}
void QQuickGraphsItem::handleRequestShadowQuality(QtGraphs3D::ShadowQuality quality)
{
setShadowQuality(quality);
@ -1619,6 +1624,10 @@ void QQuickGraphsItem::insertSeries(qsizetype index, QAbstract3DSeries *series)
&QAbstract3DSeries::lightingModeChanged,
this,
&QQuickGraphsItem::handleLightingModeChanged);
QObject::connect(series,
&QAbstract3DSeries::itemLabelVisibleChanged,
this,
&QQuickGraphsItem::handleItemLabelVisibleChanged);
series->d_func()->resetToTheme(*theme(), oldSize, false);
qCDebug(lcSeries3D) << __FUNCTION__
<< "insert" << series << "at index of:" << index;

View File

@ -563,6 +563,8 @@ public Q_SLOTS:
void handleAxisTitleOffsetChanged(float offset);
void handleInputPositionChanged(QPoint position);
void handleSeriesVisibilityChanged(bool visible);
void handleItemLabelVisibleChanged(bool visible);
virtual void handleItemLabelVisibleChangedBySender(bool visible, QObject *sender) = 0;
void handleThemeColorStyleChanged(QGraphsTheme::ColorStyle style);
void handleThemeBaseColorsChanged(const QList<QColor> &color);

View File

@ -5,6 +5,7 @@
#include "qgraphsinputhandler_p.h"
#include "qquickgraphsscatter_p.h"
#include "qquickgraphstexturedata_p.h"
#include "qscatter3dseries.h"
#include "qscatter3dseries_p.h"
#include "qscatterdataproxy_p.h"
#include "qvalue3daxis_p.h"
@ -595,6 +596,7 @@ void QQuickGraphsScatter::updateScatterGraphItemVisuals(ScatterModel *graphModel
graphModel->selectionIndicator->setRotation(dih.rotation);
graphModel->selectionIndicator->setScale(dih.scale);
graphModel->selectionIndicator->setVisible(true);
itemLabel()->setVisible(graphModel->series->isItemLabelVisible());
graphModel->instancing->hideDataItem(m_selectedItem);
updateItemLabel(graphModel->selectionIndicator->position());
graphModel->instancing->markDataDirty();
@ -1020,7 +1022,7 @@ void QQuickGraphsScatter::setSelectedItem(qsizetype index, QScatter3DSeries *ser
}
if (index != invalidSelectionIndex())
itemLabel()->setVisible(true);
itemLabel()->setVisible(series->isItemLabelVisible());
}
void QQuickGraphsScatter::setSelectionMode(QtGraphs3D::SelectionFlags mode)
@ -1916,6 +1918,13 @@ void QQuickGraphsScatter::clearAllSelectionInstanced()
}
}
void QQuickGraphsScatter::handleItemLabelVisibleChangedBySender(bool visible, QObject *sender)
{
auto series = qobject_cast<QScatter3DSeries *>(sender);
if (series && series == m_selectedItemSeries)
itemLabel()->setVisible(visible);
}
void QQuickGraphsScatter::optimizationChanged(QtGraphs3D::OptimizationHint toOptimization)
{
if (toOptimization == QtGraphs3D::OptimizationHint::Default) {

View File

@ -262,6 +262,8 @@ private:
void clearSelectionModel();
void clearAllSelectionInstanced();
void handleItemLabelVisibleChangedBySender(bool visible, QObject *sender) override;
void optimizationChanged(QtGraphs3D::OptimizationHint toOptimization);
void updateGraph() override;

View File

@ -9,6 +9,7 @@
#include "qgraphsinputhandler_p.h"
#include "qquickgraphssurface_p.h"
#include "qquickgraphstexturedata_p.h"
#include "qsurface3dseries.h"
#include "qsurface3dseries_p.h"
#include "qsurfacedataproxy_p.h"
#include "qvalue3daxis_p.h"
@ -877,6 +878,17 @@ void QQuickGraphsSurface::handleSeriesVisibilityChangedBySender(QObject *sender)
setSelectedPoint(m_selectedPoint, m_selectedSeries, false);
}
void QQuickGraphsSurface::handleItemLabelVisibleChangedBySender(bool visible, QObject *sender)
{
auto series = static_cast<QSurface3DSeries *>(sender);
if (series == m_selectedSeries) {
itemLabel()->setVisible(visible);
if (auto label = sliceItemLabel(); label && isSlicingActive())
label->setVisible(visible);
}
}
void QQuickGraphsSurface::setFlipHorizontalGrid(bool flip)
{
if (m_flipHorizontalGrid != flip) {

View File

@ -142,6 +142,7 @@ public:
bool autoAdjust) override;
void handleAxisRangeChangedBySender(QObject *sender) override;
void handleSeriesVisibilityChangedBySender(QObject *sender) override;
void handleItemLabelVisibleChangedBySender(bool visible, QObject *sender) override;
void adjustAxisRanges() override;
void handleLightingModeChanged() override;

View File

@ -301,6 +301,23 @@ Item {
}
}
Button {
id: itemlabelVisibleToggle
Layout.fillWidth: true
Layout.fillHeight: true
text: "Hide itemlabel"
clip: true
onClicked: {
barSeries.itemLabelVisible = !barSeries.itemLabelVisible
if (barSeries.itemLabelVisible)
text = "Hide itemLabel"
else
text = "Show itemLabel"
}
}
Column {
Label {
text: "ValueAxis Segments"

View File

@ -280,6 +280,9 @@ Item {
RowLayout {
id: buttonLayout
property int buttonCount: 5
Layout.minimumHeight: shadowToggle.height
width: parent.width
anchors.left: parent.left
@ -288,7 +291,7 @@ Item {
Button {
id: shadowToggle
Layout.fillHeight: true
Layout.minimumWidth: parent.width / 4 // 4 buttons divided equally in the layout
Layout.minimumWidth: parent.width / parent.buttonCount // Buttons divided equally in the layout
text: "Hide Shadows"
onClicked: {
if (activeGraph.shadowQuality === Graphs3D.ShadowQuality.None) {
@ -304,7 +307,7 @@ Item {
Button {
id: cameraToggle
Layout.fillHeight: true
Layout.minimumWidth: parent.width / 4
Layout.minimumWidth: parent.width / parent.buttonCount
text: "Pause Camera"
onClicked: {
@ -321,20 +324,55 @@ Item {
Button {
id: graphToggle
Layout.fillHeight: true
Layout.minimumWidth: parent.width / 4
Layout.minimumWidth: parent.width / parent.buttonCount
text: "Switch graph type"
onClicked : {
if (activeGraph == scatterGraph)
if (activeGraph == scatterGraph) {
activeGraph = surfaceGraph
if (surfaceSeries.itemLabelVisible)
seriesVisibilityToggle.text = "Hide surface series itemLabel"
else
seriesVisibilityToggle.text = "Show surface series itemLabel"
}
else {
activeGraph = scatterGraph
if (scatterSeriesTwo.itemLabelVisible)
seriesVisibilityToggle.text = "Hide center series itemLabel"
else
seriesVisibilityToggle.text = "Show center series itemLabel"
}
}
}
Button {
id: seriesVisibilityToggle
Layout.fillHeight: true
Layout.minimumWidth: parent.width / parent.buttonCount
text: "Hide center series itemLabel"
onClicked : {
if (activeGraph == scatterGraph) {
scatterSeriesTwo.itemLabelVisible = !scatterSeriesTwo.itemLabelVisible
if (scatterSeriesTwo.itemLabelVisible)
text = "Hide center series itemLabel"
else
text = "Show center series itemLabel"
}
else if (activeGraph == surfaceGraph) {
surfaceSeries.itemLabelVisible = !surfaceSeries.itemLabelVisible
if (surfaceSeries.itemLabelVisible)
text = "Hide surface series itemLabel"
else
text = "Show surface series itemLabel"
}
}
}
Button {
id: exitButton
Layout.fillHeight: true
Layout.minimumWidth: parent.width / 4
Layout.minimumWidth: parent.width / parent.buttonCount
text: "Quit"
onClicked: Qt.quit();
}

View File

@ -4,10 +4,12 @@
import QtQuick
import QtGraphs
import QtQuick.Controls
import QtQuick.Layouts
import "."
Item {
id: mainView
width: 1280
height: 720
visible: true
@ -199,11 +201,17 @@ Item {
}
}
RowLayout {
id: buttonLayout
anchors.left: parent.left
anchors.right: parent.right
Button {
id: shadowToggle
width: parent.width / 3 // We're adding 3 buttons and want to divide them equally
Layout.fillWidth: true
text: "Hide Shadows"
anchors.left: parent.left
onClicked: {
if (scatterGraph.shadowQuality === Graphs3D.ShadowQuality.None) {
@ -218,9 +226,8 @@ Item {
Button {
id: cameraToggle
width: parent.width / 3
Layout.fillWidth: true
text: "Pause Camera"
anchors.left: shadowToggle.right
onClicked: {
cameraAnimationX.paused = !cameraAnimationX.paused;
@ -233,11 +240,56 @@ Item {
}
}
Button {
id: dynamicDataToggle
Layout.fillWidth: true
text: "Stop dynamic data"
onClicked: {
dataTimer.running = !dataTimer.running
if (dataTimer.running)
text = "Stop dynamic data";
else
text = "Start dynamic data";
}
}
Button {
id: autoSelectionToggle
Layout.fillWidth: true
text: "Stop autoselection"
onClicked: {
reselectTimer.running = !reselectTimer.running
if (reselectTimer.running)
text = "Stop autoselection";
else
text = "Start autoselection";
}
}
Button {
id: seriesItemLabelToggle
Layout.fillWidth: true
text: "Hide series item label"
onClicked: {
scatterSeries.itemLabelVisible = !scatterSeries.itemLabelVisible
if (scatterSeries.itemLabelVisible)
text = "Hide series item label";
else
text = "Show series item label";
}
}
Button {
id: exitButton
width: parent.width / 3
Layout.fillWidth: true
text: "Quit"
anchors.left: cameraToggle.right
onClicked: Qt.quit();
}
}
}

View File

@ -162,6 +162,23 @@ Item {
gradientLabel.text = "Series gradient";
}
}
Button {
id: toggleSeriesItemLabel
Layout.fillWidth: true
Layout.fillHeight: true
text: qsTr("Hide series itemLabel")
onClicked: {
heightSeries.itemLabelVisible = !heightSeries.itemLabelVisible
if (heightSeries.itemLabelVisible)
text = "Hide series itemLabel"
else
text = "Show series itemLabel"
}
}
}
ColumnLayout {