-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
248 lines (203 loc) · 8.89 KB
/
mainwindow.cpp
File metadata and controls
248 lines (203 loc) · 8.89 KB
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/***************************************************************************
* QGeoView is a Qt / C ++ widget for visualizing geographic data.
* Copyright (C) 2018-2025 Andrey Yaroshenko.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, see https://www.gnu.org/licenses.
****************************************************************************/
#include "mainwindow.h"
#include <QButtonGroup>
#include <QLabel>
#include <QPushButton>
#include <QRadioButton>
#include <QTimer>
#include <QVBoxLayout>
#include <helpers.h>
#include <rectangle.h>
#include <QGeoView/QGVLayerGoogle.h>
#include <QGeoView/QGVWidgetCompass.h>
MainWindow::MainWindow()
{
setWindowTitle("QGeoView Samples - performance profiles");
mMap = new QGVMap(this);
setCentralWidget(mMap);
Helpers::setupCachedNetworkAccessManager(this);
// Background layer
mBackground = new QGVLayerGoogle();
mMap->addItem(mBackground);
// Widgets
mMap->addWidget(new QGVWidgetCompass());
// 10000 layer
mMap->addItem(create10000Layer());
// Options list
centralWidget()->layout()->addWidget(createOptionsList());
// Show whole world
auto target = mMap->getProjection()->boundaryGeoRect();
mMap->cameraTo(QGVCameraActions(mMap).scaleTo(target));
// Enable debug
QGV::setPrintDebug(true);
}
MainWindow::~MainWindow()
{
}
QGV::GeoRect MainWindow::target10000Area() const
{
return mMap->getProjection()->boundaryGeoRect();
}
QGVLayer* MainWindow::create10000Layer() const
{
/*
* Layers will be owned by map.
*/
auto target = target10000Area();
auto layer = new QGVLayer();
layer->setName("10000 elements");
layer->setDescription("Demo for 10000 elements");
/*
* Items will be owned by layer.
*/
const int size = 20000;
for (int i = 0; i < 10000; i++) {
auto item = new Rectangle(Helpers::randRect(mMap, target, size), Qt::red);
layer->addItem(item);
}
return layer;
}
QGroupBox* MainWindow::createOptionsList()
{
/*
* Options in this list is only recommendations and hard-coded values can be mixed or adopted to your application.
*
* Background map has biggest impact to performance because it covers whole map area all the time.
* QGVLayerTiles always calculates needed set of tiles for current camera state and parameters below will adjust
* algorithm.
*
* TilesMarginWithZoomChange, TilesMarginNoZoomChange are defining margin around visible map area.
* First right after zoom change and second after map move/rotate. Bigger margin gives better feedback for user
* when map moved by mouse, but from other side it increases number of tiles loaded to map. Don't use values
* below 1.
*
* AnimationUpdateDelayMs, CameraUpdatesDuringAnimation are defining layer behavior during animation (flyTo method)
* First defines time interval between camera update processing (during animation only!) and second will disable
* any processing during animation completely. This parameter will have large impact to performance in case
* if application performs many "jumps" by flyTo method. When processing is disabled or interval is very large QGV
* will show gray areas on missing tiles during animation.
*
* VisibleZoomLayersBelowCurrent, VisibleZoomLayersAboveCurrent are defining number of zoom levels which layer can
* keep below and above current level. This is most impacting to performance parameters (especially
* VisibleZoomLayersBelowCurrent). By default QGVLayerTiles cleanups tiles based on tiles coverage. For example when
* tile below (bigger one) is fully covered by tiles above (smaller) then big one will be deleted. Or when bigger
* tile of current zoom level is loaded all tiles above it will be deleted. This gives nice user feedback, but can
* lead to high load on scene, especially when network had low latency and tiles from low levels are consistently
* upscaled. VisibleZoomLayersBelowCurrent, VisibleZoomLayersAboveCurrent are limiting QGVLayerTiles to keep only
* given number of zoom levels above or below current one. When is equals to 0 then only current level is allowed.
*/
QGroupBox* groupBox = new QGroupBox(tr("Profiles"));
groupBox->setLayout(new QVBoxLayout);
{
QPushButton* button = new QPushButton("Try it!");
groupBox->layout()->addWidget(button);
connect(button, &QPushButton::clicked, this, [this]() { flyToRandomArea(); });
}
QButtonGroup* group = new QButtonGroup(this);
{
QRadioButton* radioButton = new QRadioButton("Best look");
group->addButton(radioButton);
QLabel* description = new QLabel();
description->setText("Set of parameters which gives best look for user but with price of performance.\nThis is "
"default values for any tile map.");
QWidget* item = new QWidget();
item->setLayout(new QVBoxLayout());
item->layout()->addWidget(radioButton);
item->layout()->addWidget(description);
groupBox->layout()->addWidget(item);
connect(radioButton, &QRadioButton::clicked, this, [this](const bool checked) {
if (checked)
setupProfileLook();
});
}
{
QRadioButton* radioButton = new QRadioButton("Balanced");
group->addButton(radioButton);
QLabel* description = new QLabel();
description->setText("Set of parameters which gives optimal look for user with optimal performance. Can "
"produce 'gray' areas during animation and camera actions.");
QWidget* item = new QWidget();
item->setLayout(new QVBoxLayout());
item->layout()->addWidget(radioButton);
item->layout()->addWidget(description);
groupBox->layout()->addWidget(item);
connect(radioButton, &QRadioButton::clicked, this, [this](const bool checked) {
if (checked)
setupProfileBalance();
});
radioButton->click();
}
{
QRadioButton* radioButton = new QRadioButton("Fast");
group->addButton(radioButton);
QLabel* description = new QLabel();
description->setText("Set of parameters which gives best performance. This setup will produce 'gray' areas "
"every time during animation and camera actions.");
QWidget* item = new QWidget();
item->setLayout(new QVBoxLayout());
item->layout()->addWidget(radioButton);
item->layout()->addWidget(description);
groupBox->layout()->addWidget(item);
connect(radioButton, &QRadioButton::clicked, this, [this](const bool checked) {
if (checked)
setupProfileFast();
});
}
return groupBox;
}
void MainWindow::flyToRandomArea()
{
static int current = 0;
static const std::vector<QGV::GeoRect> areas = {
QGV::GeoRect(QGV::GeoPos(56.316425, 80.670445), QGV::GeoPos(53.280950, 86.641856)),
QGV::GeoRect(QGV::GeoPos(52.131852, 4.989964), QGV::GeoPos(44.071465, 18.708665)),
QGV::GeoRect(QGV::GeoPos(-17.631899, 20.654501), QGV::GeoPos(-29.494330, 35.357840)),
};
QTimer::singleShot(100, this, [&]() {
mMap->flyTo(QGVCameraActions(mMap).scaleTo(areas[current % areas.size()]));
current++;
});
}
void MainWindow::setupProfileLook()
{
mBackground->setTilesMarginWithZoomChange(1);
mBackground->setTilesMarginNoZoomChange(3);
mBackground->setAnimationUpdateDelayMs(200);
mBackground->setVisibleZoomLayersBelowCurrent(10);
mBackground->setVisibleZoomLayersAboveCurrent(10);
mBackground->setCameraUpdatesDuringAnimation(true);
}
void MainWindow::setupProfileBalance()
{
mBackground->setTilesMarginWithZoomChange(1);
mBackground->setTilesMarginNoZoomChange(2);
mBackground->setAnimationUpdateDelayMs(250);
mBackground->setVisibleZoomLayersBelowCurrent(1);
mBackground->setVisibleZoomLayersAboveCurrent(3);
mBackground->setCameraUpdatesDuringAnimation(true);
}
void MainWindow::setupProfileFast()
{
mBackground->setTilesMarginWithZoomChange(1);
mBackground->setTilesMarginNoZoomChange(1);
mBackground->setAnimationUpdateDelayMs(500);
mBackground->setVisibleZoomLayersBelowCurrent(1);
mBackground->setVisibleZoomLayersAboveCurrent(1);
mBackground->setCameraUpdatesDuringAnimation(false);
}