1 /**********************************************************************************************
2 Copyright (C) 2014 Oliver Eichler <oliver.eichler@gmx.de>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 **********************************************************************************************/
18
19 #include "CMainWindow.h"
20 #include "gis/proj_x.h"
21 #include "helpers/CElevationDialog.h"
22 #include "units/IUnit.h"
23
24 #include <QtWidgets>
25
CElevationDialog(QWidget * parent,QVariant & val,const QVariant & reset,const QPointF & pos)26 CElevationDialog::CElevationDialog(QWidget* parent, QVariant& val, const QVariant& reset, const QPointF& pos)
27 : QDialog(parent)
28 , val(val)
29 , reset(reset)
30 , pos(pos)
31 {
32 setupUi(this);
33
34 QPushButton* pushReset = buttonBox->addButton(QDialogButtonBox::Reset);
35 connect(pushReset, &QPushButton::clicked, this, &CElevationDialog::slotReset);
36 connect(toolGetEle, &QToolButton::clicked, this, &CElevationDialog::slotGetEle);
37
38 labelUnit->setText(IUnit::self().elevationUnit);
39 if(val != NOINT)
40 {
41 QString unit;
42 QString value;
43 IUnit::self().meter2elevation(val.toDouble(), value, unit);
44 lineValue->setText(value);
45 }
46 }
47
~CElevationDialog()48 CElevationDialog::~CElevationDialog()
49 {
50 }
51
accept()52 void CElevationDialog::accept()
53 {
54 if(lineValue->text().isEmpty())
55 {
56 val = reset;
57 }
58 else
59 {
60 val.setValue(lineValue->text().toDouble() / IUnit::self().elevationFactor);
61 }
62
63 QDialog::accept();
64 }
65
slotReset()66 void CElevationDialog::slotReset()
67 {
68 if(reset == NOINT)
69 {
70 lineValue->clear();
71 }
72 else
73 {
74 QString str, unit;
75 IUnit::self().meter2elevation(val.toDouble(), str, unit);
76 lineValue->setText(str);
77 }
78 }
79
slotGetEle()80 void CElevationDialog::slotGetEle()
81 {
82 QVariant ele = CMainWindow::self().getElevationAt(pos * DEG_TO_RAD);
83 if(ele != NOFLOAT)
84 {
85 QString str, unit;
86 IUnit::self().meter2elevation(ele.toDouble(), str, unit);
87 lineValue->setText(str);
88 }
89 else
90 {
91 labelMessage->setText(tr("No DEM data found for that point."));
92 }
93 }
94