• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Stellarium / stellarium / 15291801018

28 May 2025 04:52AM UTC coverage: 11.931% (-0.02%) from 11.951%
15291801018

push

github

alex-w
Added new set of navigational stars (XIX century)

0 of 6 new or added lines in 2 files covered. (0.0%)

14124 existing lines in 74 files now uncovered.

14635 of 122664 relevant lines covered (11.93%)

18291.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/gui/AngleSpinBox.hpp
1
/*
2
 * Stellarium
3
 * Copyright (C) 2008 Matthew Gates
4
 * Copyright (C) 2015 Georg Zotti (min/max limits)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
19
 */
20

21
#ifndef ANGLESPINBOX_HPP
22
#define ANGLESPINBOX_HPP
23

24
#include <QAbstractSpinBox>
25
#include <QString>
26
#include <cmath>
27

28
//! @class AngleSpinBox
29
//! A spin box for displaying/entering angular values.
30
//! This class can accept angles in various formats commonly used in astronomy
31
//! including decimal degrees, DMS and HMS.
32
//! You should set upper and lower limits (maximum, minimum) and
33
//! decide whether the values wrap around or are blocked at the limits (wrapping).
34
class AngleSpinBox : public QAbstractSpinBox
35
{
36
        Q_OBJECT
37

38
public:
39
        //! @enum DisplayFormat
40
        //! Used to decide how to display the angle.
41
        enum DisplayFormat
42
        {
43
                DMSLetters,                //!< Degrees, minutes and seconds, e.g. 180d 4m 8s, with negative values, [-360..360d]
44
                DMSSymbols,                //!< Degrees, minutes and seconds, e.g. 180° 4' 8", with negative values, [-360..360°]
45
                DMSLettersUnsigned,        //!< Degrees, minutes and seconds, e.g. 180d 4m 8s, [0..360d]
46
                DMSSymbolsUnsigned,     //!< Degrees, minutes and seconds, e.g. 180° 4' 8", [0..360°]
47
                HMSLetters,                //!< Hours, minutes and seconds, e.g. 12h 4m 6s
48
                HMSSymbols,                //!< Hours, minutes and seconds, e.g. 12h 4' 6s"
49
                DecimalDeg                //!< Decimal degrees, e.g. 180.06888
50
        };
51
        Q_ENUM(DisplayFormat);
52

53
        //! @enum PrefixType
54
        //! Determines how positive and negative values are indicated.
55
        enum PrefixType
56
        {
57
                Normal,                        //!< negative values have '-' prefix
58
                NormalPlus,                //!< positive values have '+' prefix, negative values have '-' prefix.
59
                Longitude,                //!< positive values have 'E' prefix, negative values have 'W' prefix.
60
                Latitude,                //!< positive values have 'N' prefix, negative values have 'S' prefix.
61
                 Unknown
62
        };
63
        Q_ENUM(PrefixType);
64

65
        AngleSpinBox(QWidget* parent=Q_NULLPTR, DisplayFormat format=DMSSymbols, PrefixType prefix=Normal);
66
        ~AngleSpinBox() override;
67

68
        // QAbstractSpinBox virtual members
69
        void stepBy(int steps) override;
70
        QValidator::State validate(QString& input, int& pos) const override;
71

72
        //! Get the angle held in the AngleSpinBox
73
        //! @return the angle in radians
74
        double valueRadians() const;
75
        //! Get the angle held in the AngleSpinBox
76
        //! @return the angle in degrees
77
        double valueDegrees() const;
78

79
        //! Set the number of decimal places to express float values to (e.g. seconds in DMSLetters format).
80
        //! @param places the number of decimal places to use.
UNCOV
81
        void setDecimals(int places) { decimalPlaces = places; }
×
82

83
        //! Get the number of decimal places to express float values to (e.g. seconds in DMSLetters format).
84
        //! @return the number of decimal places used.
85
        int decimals() const { return decimalPlaces; }
86

87
        //! Set the display format.
88
        //! @param format the new format to use.
UNCOV
89
        void setDisplayFormat(DisplayFormat format) { angleSpinBoxFormat=format; formatText(); }
×
90

91
        //! Get the current display format.
92
        //! @return the current DisplayFormat.
93
        DisplayFormat displayFormat() const { return angleSpinBoxFormat; }
94

95
        //! Set the prefix type.
96
        //! @param prefix the new prefix type to use.
UNCOV
97
        void setPrefixType(PrefixType prefix) { currentPrefixType=prefix; formatText(); }
×
98

99
        //! Get the current display format.
100
        //! @return the current DisplayFormat.
101
        PrefixType prefixType() const { return currentPrefixType; }
102

103
        //! Set the minimum value.
104
        //! @param min the new minimum value
105
        //! @param isDegrees true if the new minimum value is given in degrees, else min is understood as radians.
UNCOV
106
        void setMinimum(const double min, const bool isDegrees=false) {minRad = min * (isDegrees? M_PI/180.0 : 1.); }
×
107
        //! Get the minimum value.
108
        //! @return the current minimum value
109
        //! @param isDegrees true if the minimum value is required in degrees, else min is returned as radians.
UNCOV
110
        double getMinimum(const bool isDegrees) const { return minRad * (isDegrees ? 180.0/M_PI : 1.0); }
×
111

112
        //! Set the maximum value.
113
        //! @param max the new maximum value
114
        //! @param isDegrees true if the new maximum value is given in degrees, else max is understood as radians.
UNCOV
115
        void setMaximum(const double max, const bool isDegrees=false) {maxRad = max * (isDegrees? M_PI/180.0 : 1.); }
×
116
        //! Get the maximum value.
117
        //! @return the current maximum value
118
        //! @param isDegrees true if the maximum value is required in degrees, else max is returned as radians.
UNCOV
119
        double getMaximum(const bool isDegrees) const { return maxRad * (isDegrees ? 180.0/M_PI : 1.0); }
×
120

121
        QSize minimumSizeHint() const override;
122
        
123
public slots:
124
        //! Set the value to default 0 angle.
125
        void clear() override;
126
        
127
        //! Set the value of the spin box in radians.
128
        //! @param radians the value to set, in radians.
129
        void setRadians(double radians);
130
        
131
        //! Set the value of the spin box in decimal degrees.
132
        //! @param degrees the value to set, in decimal degrees.
133
        void setDegrees(double degrees);
134

135
signals:
136
        //! Emitted when the value changes.
137
        void valueChanged();
138
        void valueChangedDeg(double);
139
        void valueChangedRad(double);
140

141
protected:
142
        StepEnabled stepEnabled() const override;
143

144
private slots:
145
        //! Updates radAngle (internal representation of the angle) and calls formatText
146
        void updateValue(void);
147

148
private:
149
        //! Convert a string value to an angle in radians.
150
        //! This function can be used to validate a string as expressing an angle. Accepted
151
        //! are any formats which the AngleSpinBox understands.
152
        //! @param input the string value to be converted / validated.
153
        //! @param state a pointer to a QValidator::State value which is set according to the validation.
154
        //! @param prefix the kind of prefix to use for conversion.
155
        //! @return the value of the angle expressed in input in radians.
156
        double stringToDouble(QString input, QValidator::State* state, PrefixType prefix=Unknown) const;
157
        
158
        //! @enum AngleSpinboxSection
159
        enum AngleSpinboxSection
160
        {
161
                SectionPrefix,                        //! Section of the S/W or E/W or +/-
162
                  SectionDegreesHours,        //! Section of the degree or hours
163
                  SectionMinutes,                        //! Section of the minutes (of degree or of hours)
164
                  SectionSeconds,                        //! Section of the seconds (of degree or of hours)
165
                  SectionNone                                //! No matching section, e.g. between 2 sections
166
        };
167
        
168
        //! Get the current section in which the line edit cursor is.
169
        AngleSpinboxSection getCurrentSection() const;
170
        
171
        //! Reformats the input according to the current value of angleSpinBoxFormat/
172
        //! This is called whenever an editingFinished() signal is emitted, 
173
        //! e.g. when RETURN is pressed.
174
        void formatText(void);
175
                
176
        static const QString positivePrefix(PrefixType prefix);
177
        static const QString negativePrefix(PrefixType prefix);
178

179
        DisplayFormat angleSpinBoxFormat;
180
        PrefixType currentPrefixType;
181
        int decimalPlaces;
182
        double radAngle;
183
        // min/max angles (radians), users should not be able to enter more/less.
184
        // Use together with the wrapping() property!
185
        double minRad;
186
        double maxRad;
187
};
188

189
#endif // ANGLESPINBOX_HPP
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc