-
Notifications
You must be signed in to change notification settings - Fork 105
/
crs_selector.h
194 lines (154 loc) · 4.83 KB
/
crs_selector.h
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
/*
* Copyright 2012, 2013 Thomas Schöps
* Copyright 2012-2015 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/>.
*/
#ifndef OPENORIENTEERING_CRS_SELECTOR_H
#define OPENORIENTEERING_CRS_SELECTOR_H
#include <vector>
#include <QComboBox>
#include <QObject>
#include <QString>
#include "core/crs_template.h"
class QEvent;
class QFormLayout;
class QWidget;
namespace OpenOrienteering {
class Georeferencing;
/**
* Combobox for selecting projected coordinate reference system (CRS).
*
* It operates on the list of CRS templates in the CRSTemplateRegistry.
* However, it accepts custom items which are prepended to and separated from
* the default items.
*
* This is more than just a simple widget. CRSSelector is meant to be inserted
* into a QFormLayout. Upon CRS selection changes it will add and remove extra
* lines below itself, for editing CRS parameters.
*
* \todo Consider making this a QWidget which has got a QCombobox - the public
* QComboBox API should better not be exposed. The combobox' signals could
* no longer be block from clients.
*/
class CRSSelector : public QComboBox, public CRSParameterWidgetObserver
{
Q_OBJECT
public:
/**
* Constructor.
*
* The dialog parameter must not be nullptr. It is passed to parameter widgets.
* Ownership is taken only by the parent widget if given.
*/
CRSSelector(const Georeferencing& georef, QWidget* parent = nullptr);
/**
* Destructor.
*/
~CRSSelector() override;
/**
* Sets the QFormLayout which this field is part of.
*
* When the selected CRS is changed, or when configureParameterFields()
* is called explicitly, CRSSelector will add extra lines below its own row
* for editing CRS parameters.
*
* This is to be called once. However, it will not create the parameter
* fields for the current selection.
*/
void setDialogLayout(QFormLayout* dialog_layout);
/**
* Adds a custom item with the given text and id at the top of the list.
*/
void addCustomItem(const QString& text, unsigned short id);
/**
* Returns the selected CRS template, or nullptr if a custom item is selected.
*/
const CRSTemplate* currentCRSTemplate() const;
/**
* Returns the selected CRS specification string,
* or an empty string if a custom item is selected.
*/
QString currentCRSSpec() const;
/**
* Returns the id of the selected custom item,
* or -1 if a normal item is selected.
*/
int currentCustomItem() const;
/**
* Selects the given standard item, and sets the parameters.
*/
void setCurrentCRS(const CRSTemplate* crs, const std::vector<QString>& values);
/**
* Selects the given custom item.
*/
void setCurrentItem(unsigned short id);
/**
* Returns the list of CRS configuration parameter values.
*/
std::vector<QString> parameters() const;
/**
* Provides the current georeferencing.
*/
const Georeferencing& georeferencing() const override;
signals:
/**
* Emitted when the user changes the CRS or its parameters.
*/
void crsChanged();
protected:
/**
* Listens to changes of the selected CRS.
*/
void crsSelectionChanged();
/**
* Listens to changes of CRS parameters.
*/
void crsParameterEdited() override;
/**
* Updates the parameter fields in the dialog_layout,
* according to the selected CRS.
*/
void configureParameterFields();
/**
* Updates the parameter fields in the dialog_layout,
* according to the given CRS and values.
*/
void configureParameterFields(const CRSTemplate* crs, const std::vector<QString>& values);
/**
* Adds parameter fields to the dialog_layout,
* according to the given crs.
*
* There must be no other parameter fields in the dialog,
* i.e. removeParameterFields() needs to be called before.
*/
void addParameterFields(const CRSTemplate* crs);
/**
* Removes all parameter fields from the dialog_layout.
*/
void removeParameterFields();
/**
* Propagates enabling/disabling to the parameter widgets.
*/
void changeEvent(QEvent* event) override;
private:
const Georeferencing& georef;
QFormLayout* dialog_layout;
int num_custom_items;
const CRSTemplate* configured_crs;
};
} // namespace OpenOrienteering
#endif