summaryrefslogtreecommitdiffstats
path: root/examples/graphs/3d/widgetgraphgallery/scattergraph.cpp
blob: 4193cc09d2adee4c1c0446c14440a12ae48fb502 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#include "scattergraph.h"

#include <QtWidgets/qboxlayout.h>
#include <QtWidgets/qcheckbox.h>
#include <QtWidgets/qcombobox.h>
#include <QtWidgets/qcommandlinkbutton.h>
#include <QtWidgets/qlabel.h>

using namespace Qt::StringLiterals;

ScatterGraph::ScatterGraph(QWidget *parent)
{
    m_scatterWidget = new QWidget(parent);
    initialize();
}

void ScatterGraph::initialize()
{
    m_scatterGraphWidget = new ScatterGraphWidget();
    m_scatterGraphWidget->initialize();
    auto *hLayout = new QHBoxLayout(m_scatterWidget);
    QSize screenSize = m_scatterGraphWidget->screen()->size();
    m_scatterGraphWidget->setMinimumSize(QSize(screenSize.width() / 2, screenSize.height() / 1.75));
    m_scatterGraphWidget->setMaximumSize(screenSize);
    m_scatterGraphWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    m_scatterGraphWidget->setFocusPolicy(Qt::StrongFocus);
    hLayout->addWidget(m_scatterGraphWidget, 1);

    auto *vLayout = new QVBoxLayout();
    hLayout->addLayout(vLayout);

    auto *cameraButton = new QCommandLinkButton(m_scatterWidget);
    cameraButton->setText(u"Change camera preset"_s);
    cameraButton->setDescription(u"Switch between a number of preset camera positions"_s);
    cameraButton->setIconSize(QSize(0, 0));

    auto *itemCountButton = new QCommandLinkButton(m_scatterWidget);
    itemCountButton->setText(u"Toggle item count"_s);
    itemCountButton->setDescription(u"Switch between 900 and 10000 data points"_s);
    itemCountButton->setIconSize(QSize(0, 0));

    auto *rangeButton = new QCommandLinkButton(m_scatterWidget);
    rangeButton->setText(u"Toggle axis ranges"_s);
    rangeButton->setDescription(u"Switch between automatic axis ranges and preset ranges"_s);
    rangeButton->setIconSize(QSize(0, 0));

    auto *rangeMinSlider = new QSlider(m_scatterWidget);
    rangeMinSlider->setOrientation(Qt::Horizontal);
    rangeMinSlider->setMinimum(-10);
    rangeMinSlider->setMaximum(1);
    rangeMinSlider->setValue(-10);

    auto *rangeMaxSlider = new QSlider(m_scatterWidget);
    rangeMaxSlider->setOrientation(Qt::Horizontal);
    rangeMaxSlider->setMinimum(1);
    rangeMaxSlider->setMaximum(10);
    rangeMaxSlider->setValue(10);

    auto *backgroundCheckBox = new QCheckBox(m_scatterWidget);
    backgroundCheckBox->setText(u"Show graph background"_s);
    backgroundCheckBox->setChecked(true);

    auto *gridCheckBox = new QCheckBox(m_scatterWidget);
    gridCheckBox->setText(u"Show grid"_s);
    gridCheckBox->setChecked(true);

    auto *smoothCheckBox = new QCheckBox(m_scatterWidget);
    smoothCheckBox->setText(u"Smooth dots"_s);
    smoothCheckBox->setChecked(true);

    auto *itemStyleList = new QComboBox(m_scatterWidget);
    const QMetaObject &metaObj = QAbstract3DSeries::staticMetaObject;
    int index = metaObj.indexOfEnumerator("Mesh");
    QMetaEnum metaEnum = metaObj.enumerator(index);
    itemStyleList->addItem(u"Sphere"_s,
                           metaEnum.value(static_cast<int>(QAbstract3DSeries::Mesh::Sphere)));
    itemStyleList->addItem(u"Cube"_s,
                           metaEnum.value(static_cast<int>(QAbstract3DSeries::Mesh::Cube)));
    itemStyleList->addItem(u"Minimal"_s,
                           metaEnum.value(static_cast<int>(QAbstract3DSeries::Mesh::Minimal)));
    itemStyleList->addItem(u"Point"_s,
                           metaEnum.value(static_cast<int>(QAbstract3DSeries::Mesh::Point)));
    itemStyleList->setCurrentIndex(0);

    auto *themeList = new QComboBox(m_scatterWidget);
    themeList->addItem(u"QtGreen"_s);
    themeList->addItem(u"QtGreenNeon"_s);
    themeList->addItem(u"MixSeries"_s);
    themeList->addItem(u"OrangeSeries"_s);
    themeList->addItem(u"YellowSeries"_s);
    themeList->addItem(u"BlueSeries"_s);
    themeList->addItem(u"PurpleSeries"_s);
    themeList->addItem(u"GreySeries"_s);
    themeList->addItem(u"UserDefined"_s);
    themeList->setCurrentIndex(2);

    auto *shadowQuality = new QComboBox(m_scatterWidget);
    shadowQuality->addItem(u"None"_s);
    shadowQuality->addItem(u"Low"_s);
    shadowQuality->addItem(u"Medium"_s);
    shadowQuality->addItem(u"High"_s);
    shadowQuality->addItem(u"Low Soft"_s);
    shadowQuality->addItem(u"Medium Soft"_s);
    shadowQuality->addItem(u"High Soft"_s);
    shadowQuality->setCurrentIndex(6);

    vLayout->addWidget(cameraButton);
    vLayout->addWidget(itemCountButton);
    vLayout->addWidget(rangeButton);
    vLayout->addWidget(new QLabel(u"Adjust axis ranges"_s));
    vLayout->addWidget(rangeMinSlider);
    vLayout->addWidget(rangeMaxSlider);
    vLayout->addWidget(backgroundCheckBox);
    vLayout->addWidget(gridCheckBox);
    vLayout->addWidget(smoothCheckBox);
    vLayout->addWidget(new QLabel(u"Change dot style"_s));
    vLayout->addWidget(itemStyleList);
    vLayout->addWidget(new QLabel(u"Change theme"_s));
    vLayout->addWidget(themeList);
    vLayout->addWidget(new QLabel(u"Adjust shadow quality"_s));
    vLayout->addWidget(shadowQuality, 1, Qt::AlignTop);

    // Raise the graph to the top of the widget stack, to hide UI if resized smaller
    m_scatterGraphWidget->raise();

    m_modifier = new ScatterDataModifier(m_scatterGraphWidget->scatterGraph(), this);
    m_modifier->changeTheme(themeList->currentIndex());

    QObject::connect(cameraButton,
                     &QCommandLinkButton::clicked,
                     m_modifier,
                     &ScatterDataModifier::changePresetCamera);
    QObject::connect(itemCountButton,
                     &QCommandLinkButton::clicked,
                     m_modifier,
                     &ScatterDataModifier::toggleItemCount);
    QObject::connect(rangeButton,
                     &QCommandLinkButton::clicked,
                     m_modifier,
                     &ScatterDataModifier::toggleRanges);

    QObject::connect(rangeMinSlider,
                     &QSlider::valueChanged,
                     m_modifier,
                     &ScatterDataModifier::adjustMinimumRange);
    QObject::connect(rangeMaxSlider,
                     &QSlider::valueChanged,
                     m_modifier,
                     &ScatterDataModifier::adjustMaximumRange);

    QObject::connect(backgroundCheckBox,
                     &QCheckBox::checkStateChanged,
                     m_modifier,
                     &ScatterDataModifier::setBackgroundVisible);
    QObject::connect(gridCheckBox,
                     &QCheckBox::checkStateChanged,
                     m_modifier,
                     &ScatterDataModifier::setGridVisible);
    QObject::connect(smoothCheckBox,
                     &QCheckBox::checkStateChanged,
                     m_modifier,
                     &ScatterDataModifier::setSmoothDots);

    QObject::connect(m_modifier,
                     &ScatterDataModifier::backgroundVisibleChanged,
                     backgroundCheckBox,
                     &QCheckBox::setChecked);
    QObject::connect(m_modifier,
                     &ScatterDataModifier::gridVisibleChanged,
                     gridCheckBox,
                     &QCheckBox::setChecked);
    QObject::connect(itemStyleList,
                     &QComboBox::currentIndexChanged,
                     m_modifier,
                     &ScatterDataModifier::changeStyle);

    QObject::connect(themeList,
                     &QComboBox::currentIndexChanged,
                     m_modifier,
                     &ScatterDataModifier::changeTheme);

    QObject::connect(shadowQuality,
                     &QComboBox::currentIndexChanged,
                     m_modifier,
                     &ScatterDataModifier::changeShadowQuality);

    QObject::connect(m_modifier,
                     &ScatterDataModifier::shadowQualityChanged,
                     shadowQuality,
                     &QComboBox::setCurrentIndex);
    QObject::connect(m_scatterGraphWidget->scatterGraph(),
                     &Q3DScatterWidgetItem::shadowQualityChanged,
                     m_modifier,
                     &ScatterDataModifier::shadowQualityUpdatedByVisual);
}