Kstars

dmsbox.h
1/*
2 SPDX-FileCopyrightText: 2001-2002 Pablo de Vicente <vicente@oan.es>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "dms.h"
10
11#include <QFocusEvent>
12#include <QLineEdit>
13
14/**
15 * @class dmsBox
16 *
17 * A QLineEdit which is capable of displaying and parsing angle values
18 * flexibly and robustly. Angle values can be displayed and parsed as
19 * Degrees or Hours. When displaying a value, it uses a space-delimited
20 * triplet of integers representing the degrees, arcminutes, and arcseconds
21 * of the angle (or hours, minutes, seconds). For example, "-34 45 57".
22 * When parsing a value input by the user, it can also understand
23 * a number of other formats:
24 * @li colon-delimited fields ("-34:45:57")
25 * @li one or two fields ("-35"; "-34 46")
26 * @li fields with unit-labels ("-34d 45m 57s")
27 * @li floating-point numbers ("-34.76583")
28 *
29 * @note Inherits QLineEdit.
30 * @author Pablo de Vicente
31 * @version 1.0
32 */
33class dmsBox : public QLineEdit
34{
36 Q_PROPERTY(Unit units READ getUnits WRITE setUnits)
37
38 public:
39
40 typedef enum
41 {
42 HOURS,
43 DEGREES
44 } Unit;
45 /**
46 * Constructor for the dmsBox object.
47 *
48 * @param parent Pointer to the parent QWidget
49 * @param unit Units to use (Degree/Arcmin/Arcsec or Hour/Min/Sec)
50 */
51 explicit dmsBox(QWidget *parent, Unit unit);
52
53 /**
54 * Deprecated delegating constructor for backwards compatibility
55 *
56 * @param parent Pointer to the parent QWidget
57 * @param isDegree If true, use Unit::DEGREES; if false, use Unit::HOURS
58 */
59 explicit dmsBox(QWidget *parent, bool isDegree = true)
60 : dmsBox(parent, isDegree ? Unit::DEGREES : Unit::HOURS) {}
61
62 virtual ~dmsBox() override = default;
63
64 /**
65 * Display an angle.
66 *
67 * @param d the dms object which is to be displayed.
68 */
69 void show(const dms &d);
70
71 /**
72 * Display an angle.This behaves essentially like the above
73 * function. It differs only in the data type of its argument.
74 *
75 * @param t the dms object which is to be displayed.
76 */
77 inline void show(const dms *t)
78 {
79 show(*t);
80 }
81
82 /**
83 * Parse the text in the dmsBox as an angle. The text may be an integer
84 * or double value, or it may be a triplet of integer values (separated by spaces
85 * or colons) representing deg/hrs, min, sec. It is also possible to have two
86 * fields. In this case, if the second field is a double, it is converted
87 * to decimal min and double sec.
88 *
89 * @param ok set to true if a dms object was successfully created.
90 * @return a dms object constructed from the fields of the dmsbox
91 */
92 dms createDms(bool *ok = nullptr);
93
94 /**
95 * @return the unit being used (DEGREES or HOURS)
96 */
97 inline Unit getUnits() const
98 {
99 return m_unit;
100 }
101
102 /**
103 * @short set the dmsBox to Degrees or Hours
104 *
105 * @param unit If Unit::DEGREES, then the display and
106 * interpretation of text is in degrees, if Unit::HOURS then in
107 * hours.
108 */
109 void setUnits(Unit unit);
110
111 /** Clears the QLineEdit */
112 inline void clearFields(void)
113 {
114 setText(QString());
115 }
116
117 inline bool isEmpty() const
118 {
119 return text().isEmpty();
120 }
121
122 private:
123
124 void setPlaceholderText();
125
126 Unit m_unit;
127};
A QLineEdit which is capable of displaying and parsing angle values flexibly and robustly.
Definition dmsbox.h:34
dmsBox(QWidget *parent, Unit unit)
Constructor for the dmsBox object.
Definition dmsbox.cpp:19
void setUnits(Unit unit)
set the dmsBox to Degrees or Hours
Definition dmsbox.cpp:34
void clearFields(void)
Clears the QLineEdit.
Definition dmsbox.h:112
Unit getUnits() const
Definition dmsbox.h:97
void show(const dms *t)
Display an angle.This behaves essentially like the above function.
Definition dmsbox.h:77
dmsBox(QWidget *parent, bool isDegree=true)
Deprecated delegating constructor for backwards compatibility.
Definition dmsbox.h:59
dms createDms(bool *ok=nullptr)
Parse the text in the dmsBox as an angle.
Definition dmsbox.cpp:110
An angle, stored as degrees, but expressible in many ways.
Definition dms.h:38
void setText(const QString &)
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
QObject * parent() const const
void show()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:16:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.