QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
RMathComboBox.h
Go to the documentation of this file.
1
20#ifndef RMATHCOMBOBOX_H_
21#define RMATHCOMBOBOX_H_
22
23#include "gui_global.h"
24
25#include <QMetaType>
26#include <QComboBox>
27
28#include "RSettings.h"
29#include "RMath.h"
30#include "RMathLineEdit.h"
31
36class QCADGUI_EXPORT RMathComboBox: public QComboBox {
37
38Q_OBJECT
39
40// keep extra ';' in place for the benefit of ecmagenerator:
41Q_PROPERTY(bool angle READ isAngle WRITE setAngle);
42Q_PROPERTY(bool integer READ isInteger WRITE setInteger);
43
44public:
45 RMathComboBox(QWidget* parent = NULL);
46
48 QLineEdit* le = lineEdit();
49 RMathLineEdit* me = dynamic_cast<RMathLineEdit*>(le);
50 Q_ASSERT(me!=NULL);
51 return me;
52 }
53
54 bool isAngle() const {
55 return getMathLineEdit()->isAngle();
56 }
57 void setAngle(bool on) {
58 getMathLineEdit()->setAngle(on);
59 }
60
61 bool isScale() const {
62 return getMathLineEdit()->isScale();
63 }
64 void setScale(bool on, RS::Unit unit) {
65 getMathLineEdit()->setScale(on);
66
67 if (on) {
68 QStringList scales = RSettings::getScaleList(unit);
69 blockSignals(true);
70 addItems(scales);
71 blockSignals(false);
72 }
73 }
74
75 bool isInteger() const {
76 return getMathLineEdit()->isInteger();
77 }
78 void setInteger(bool on) {
79 getMathLineEdit()->setInteger(on);
80 }
81
82 void setValue(double v, int precision=6) {
83 if (isScale()) {
84 // find matching item:
85 for (int i=0; i<count(); i++) {
86 QString text = itemText(i);
87 double val = RMath::parseScale(text);
88 if (RMath::fuzzyCompare(val, v, 0.0001)) {
89 setEditText(text);
90 continue;
91 }
92 }
93 }
94 else {
95 getMathLineEdit()->setValue(v, precision);
96 }
97 }
98 double getValue() {
99 return getMathLineEdit()->getValue();
100 }
101 QString getError() {
102 return getMathLineEdit()->getError();
103 }
104 void clearError() {
105 getMathLineEdit()->clearError();
106 }
107
108 bool isValid() {
109 return getMathLineEdit()->isValid();
110 }
111
112 bool isSane() {
113 return getMathLineEdit()->isSane();
114 }
115
116public slots:
117 void slotTextChanged(const QString& text) {
118 getMathLineEdit()->slotTextChanged(text);
119 }
120 void slotValueChanged(double value, const QString& error) {
121 // forward signal from RMathLineEdit:
122 emit valueChanged(value, error);
123 }
124
125signals:
126 void valueChanged(double value, const QString& error);
127};
128
130
131#endif
Q_DECLARE_METATYPE(RMath *)
int i
Copyright (c) 2011-2018 by Andrew Mustun.
Definition autostart.js:32
Copyright (c) 2011-2019 by Andrew Mustun.
Definition RMathComboBox.h:36
void slotTextChanged(const QString &text)
Definition RMathComboBox.h:117
bool isSane()
Definition RMathComboBox.h:112
bool isAngle() const
Definition RMathComboBox.h:54
void setScale(bool on, RS::Unit unit)
Definition RMathComboBox.h:64
RMathLineEdit * getMathLineEdit() const
Definition RMathComboBox.h:47
void clearError()
Definition RMathComboBox.h:104
void setInteger(bool on)
Definition RMathComboBox.h:78
bool isScale() const
Definition RMathComboBox.h:61
bool isInteger() const
Definition RMathComboBox.h:75
double getValue()
Definition RMathComboBox.h:98
QString getError()
Definition RMathComboBox.h:101
void valueChanged(double value, const QString &error)
void slotValueChanged(double value, const QString &error)
Definition RMathComboBox.h:120
void setValue(double v, int precision=6)
Definition RMathComboBox.h:82
bool isValid()
Definition RMathComboBox.h:108
void setAngle(bool on)
Definition RMathComboBox.h:57
static bool fuzzyCompare(double v1, double v2, double tolerance=RS::PointTolerance)
Definition RMath.cpp:922
static double parseScale(const QString &scaleString)
Definition RMath.cpp:943
Copyright (c) 2011-2018 by Andrew Mustun.
Definition RMathLineEdit.h:34
Unit
Enum of supported units (values correspond to DXF spec).
Definition RS.h:425
static QStringList getScaleList(const RS::Unit unit)
Definition RSettings.cpp:1755
#define QCADGUI_EXPORT
Definition gui_global.h:10
#define NULL
Definition opennurbs_system.h:256