-
Notifications
You must be signed in to change notification settings - Fork 105
/
map_dialog_scale.cpp
158 lines (126 loc) · 5.63 KB
/
map_dialog_scale.cpp
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
/*
* Copyright 2012, 2013 Thomas Schöps
* Copyright 2019 Kai Pastor
*
* This file is part of OpenOrienteering.
*
* OpenOrienteering is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenOrienteering 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 General Public License
* along with OpenOrienteering. If not, see <http://www.gnu.org/licenses/>.
*/
#include "map_dialog_scale.h"
#include <QDoubleSpinBox>
#include <QCheckBox>
#include <QDialogButtonBox>
#include <QFormLayout>
#include <QLabel>
#include <QRadioButton>
#include <QSpinBox>
#include <QVBoxLayout>
#include "core/georeferencing.h"
#include "core/map.h"
#include "templates/template.h"
#include "gui/util_gui.h"
namespace OpenOrienteering {
ScaleMapDialog::ScaleMapDialog(QWidget* parent, Map* map) : QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint), map(map)
{
setWindowTitle(tr("Change map scale"));
QFormLayout* layout = new QFormLayout();
layout->addRow(Util::Headline::create(tr("Scaling parameters")));
scale_edit = Util::SpinBox::create(1, 9999999, {}, 500);
scale_edit->setPrefix(QStringLiteral("1 : "));
scale_edit->setButtonSymbols(QAbstractSpinBox::NoButtons);
scale_edit->setValue(static_cast<int>(map->getScaleDenominator()));
layout->addRow(tr("New scale:"), scale_edit);
layout->addRow(new QLabel(tr("Scaling center:")));
//: Scaling center point
center_origin_radio = new QRadioButton(tr("Map coordinate system origin"));
center_origin_radio->setChecked(true);
layout->addRow(center_origin_radio);
//: Scaling center point
center_georef_radio = new QRadioButton(tr("Georeferencing reference point"));
if (!map->getGeoreferencing().isValid())
center_georef_radio->setEnabled(false);
layout->addRow(center_georef_radio);
//: Scaling center point
center_other_radio = new QRadioButton(tr("Other point,"));
layout->addRow(center_other_radio);
//: x coordinate
other_x_edit = Util::SpinBox::create<MapCoordF>();
layout->addRow(tr("X:"), other_x_edit);
//: y coordinate
other_y_edit = Util::SpinBox::create<MapCoordF>();
layout->addRow(tr("Y:"), other_y_edit);
layout->addItem(Util::SpacerItem::create(this));
layout->addRow(Util::Headline::create(tr("Options")));
adjust_symbols_check = new QCheckBox(tr("Scale symbol sizes"));
if (map->getNumSymbols() > 0)
adjust_symbols_check->setChecked(true);
else
adjust_symbols_check->setEnabled(false);
layout->addRow(adjust_symbols_check);
adjust_objects_check = new QCheckBox(tr("Scale map object positions"));
if (map->getNumObjects() > 0)
adjust_objects_check->setChecked(true);
else
adjust_objects_check->setEnabled(false);
layout->addRow(adjust_objects_check);
adjust_georeferencing_check = new QCheckBox(tr("Adjust georeferencing reference point"));
if (map->getGeoreferencing().isValid())
adjust_georeferencing_check->setChecked(true);
else
adjust_georeferencing_check->setEnabled(false);
layout->addRow(adjust_georeferencing_check);
adjust_templates_check = new QCheckBox(tr("Scale non-georeferenced templates"));
bool have_non_georeferenced_template = false;
for (int i = 0; i < map->getNumTemplates() && !have_non_georeferenced_template; ++i)
have_non_georeferenced_template = !map->getTemplate(i)->isTemplateGeoreferenced();
for (int i = 0; i < map->getNumClosedTemplates() && !have_non_georeferenced_template; ++i)
have_non_georeferenced_template = !map->getClosedTemplate(i)->isTemplateGeoreferenced();
if (have_non_georeferenced_template)
adjust_templates_check->setChecked(true);
else
adjust_templates_check->setEnabled(false);
layout->addRow(adjust_templates_check);
QDialogButtonBox* button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal);
ok_button = button_box->button(QDialogButtonBox::Ok);
auto* box_layout = new QVBoxLayout();
box_layout->addLayout(layout);
box_layout->addItem(Util::SpacerItem::create(this));
box_layout->addStretch();
box_layout->addWidget(button_box);
setLayout(box_layout);
connect(center_origin_radio, &QAbstractButton::clicked, this, &ScaleMapDialog::updateWidgets);
connect(center_georef_radio, &QAbstractButton::clicked, this, &ScaleMapDialog::updateWidgets);
connect(center_other_radio, &QAbstractButton::clicked, this, &ScaleMapDialog::updateWidgets);
connect(button_box, &QDialogButtonBox::accepted, this, &ScaleMapDialog::okClicked);
connect(button_box, &QDialogButtonBox::rejected, this, &QDialog::reject);
updateWidgets();
}
void ScaleMapDialog::updateWidgets()
{
other_x_edit->setEnabled(center_other_radio->isChecked());
other_y_edit->setEnabled(center_other_radio->isChecked());
adjust_georeferencing_check->setEnabled(!center_georef_radio->isChecked());
}
void ScaleMapDialog::okClicked()
{
auto scale = static_cast<unsigned int>(scale_edit->value());
MapCoord center = MapCoord(0, 0);
if (center_georef_radio->isChecked())
center = map->getGeoreferencing().getMapRefPoint();
else if (center_other_radio->isChecked())
center = MapCoord(other_x_edit->value(), -1 * other_y_edit->value());
map->changeScale(scale, center, adjust_symbols_check->isChecked(), adjust_objects_check->isChecked(), adjust_georeferencing_check->isChecked(), adjust_templates_check->isChecked());
accept();
}
} // namespace OpenOrienteering