1 /***************************************************************************
2   qgs3dmeasuredialog.h
3   --------------------------------------
4   Date                 : Jun 2019
5   Copyright            : (C) 2019 by Ismail Sunni
6   Email                : imajimatika at gmail dot com
7  ***************************************************************************
8  *                                                                         *
9  *   This program is free software; you can redistribute it and/or modify  *
10  *   it under the terms of the GNU General Public License as published by  *
11  *   the Free Software Foundation; either version 2 of the License, or     *
12  *   (at your option) any later version.                                   *
13  *                                                                         *
14  ***************************************************************************/
15 
16 
17 #ifndef QGS3DMEASUREDIALOG_H
18 #define QGS3DMEASUREDIALOG_H
19 
20 #include <QCloseEvent>
21 
22 #include "ui_qgsmeasurebase.h"
23 #include "qgs3dmaptoolmeasureline.h"
24 #include "qgs3dmapcanvas.h"
25 #include "qgsunittypes.h"
26 
27 
28 class Qgs3DMeasureDialog : public QDialog, private Ui::QgsMeasureBase
29 {
30     Q_OBJECT
31 
32   public:
33     // Constructor
34     Qgs3DMeasureDialog( Qgs3DMapToolMeasureLine *tool, Qt::WindowFlags f = Qt::WindowFlags() );
35 
36     //! Save position
37     void saveWindowLocation();
38 
39     //! Restore last window position/size
40     void restorePosition();
41 
42     //! Add new point
43     void addPoint();
44 
45     //! Get last distance in map distance unit
46     double lastDistance();
47 
48     //! Get last Z value distance in map distance unit
49     double lastVerticalDistance();
50 
51     //! Get last horizontal value distance in map distance unit
52     double lastHorizontalDistance();
53 
54     //! Populating unit combo box
55     void repopulateComboBoxUnits();
56 
57     //! Remove last point
58     void removeLastPoint();
59 
60     // Clear the content of the table
61     void resetTable();
62 
63   public slots:
64     void reject() override;
65 
66     void restart();
67 
68     //! Close event
69     void closeEvent( QCloseEvent *e ) override;
70 
71     //! When any external settings change
72     void updateSettings();
73 
74   private slots:
75     void unitsChanged( int index );
76 
77   private:
78     Qgs3DMapToolMeasureLine *mTool;
79 
80     //! Total length in map distance unit
81     double mTotal = 0.0;
82 
83     //! Total horizontal length in map distance unit
84     double mHorizontalTotal = 0.0;
85 
86     //! Number of decimal places we want.
87     int mDecimalPlaces = 3;
88 
89     //! Distance unit of the map
90     QgsUnitTypes::DistanceUnit mMapDistanceUnit  = QgsUnitTypes::DistanceUnknownUnit;
91 
92     //! Distance unit of the displayed value
93     QgsUnitTypes::DistanceUnit mDisplayedDistanceUnit  = QgsUnitTypes::DistanceUnknownUnit;
94 
95     //! Convert from mMapDistanceUnit to mDisplayedDistanceUnit
96     double convertLength( double length, QgsUnitTypes::DistanceUnit toUnit ) const;
97 
98     //! formats distance to most appropriate units
99     QString formatDistance( double distance ) const;
100 
101     //! Show the help page of the 3D measurement tool
102     void showHelp();
103 
104     //! Open configuration tab
105     void openConfigTab();
106 
107     //! Setup the header of the table
108     void setupTableHeader();
109 
110     //! Add measurement (3d-distance, vertical distance, horizontal distance) to the table
111     void addMeasurement( double distance, double verticalDistance, double horizontalDistance );
112 
113     //! Update total value
114     void updateTotal();
115 
116     //! Update table based on current setting
117     void updateTable();
118 };
119 
120 #endif // QGS3DMEASUREDIALOG_H
121