LibrePCB Developers Documentation
lengtheditbase.h
Go to the documentation of this file.
1/*
2 * LibrePCB - Professional EDA for everyone!
3 * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4 * https://librepcb.org/
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (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, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef LIBREPCB_EDITOR_LENGTHEDITBASE_H
21#define LIBREPCB_EDITOR_LENGTHEDITBASE_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../widgets/numbereditbase.h"
27
30
31#include <QtCore>
32#include <QtWidgets>
33
34/*******************************************************************************
35 * Namespace / Forward Declarations
36 ******************************************************************************/
37namespace librepcb {
38namespace editor {
39
40/*******************************************************************************
41 * Class LengthEditBase
42 ******************************************************************************/
43
47class LengthEditBase : public QAbstractSpinBox {
48 Q_OBJECT
49
50public:
51 struct Steps {
52 static QVector<PositiveLength> generic() noexcept {
53 return {
54 PositiveLength(10000), // 0.01mm
55 PositiveLength(25400), // 0.0254mm
56 PositiveLength(100000), // 0.1mm
57 PositiveLength(254000), // 0.254mm
58 PositiveLength(1000000), // 1mm
59 PositiveLength(2540000), // 2.54mm
60 };
61 }
62
63 static QVector<PositiveLength> textHeight() noexcept {
64 return {
65 PositiveLength(100000), // 0.1mm
66 PositiveLength(254000), // 0.254mm
67 PositiveLength(500000), // 0.5mm (default)
68 };
69 }
70
71 static QVector<PositiveLength> pinLength() noexcept {
72 return {
73 PositiveLength(2500000), // 2.5mm (for metric symbols)
74 PositiveLength(2540000), // 2.54mm (default)
75 };
76 }
77
78 static QVector<PositiveLength> drillDiameter() noexcept {
79 return {
80 PositiveLength(254000), // 0.254mm (for imperial drills)
81 PositiveLength(100000), // 0.1mm (default, for metric drills)
82 };
83 }
84 };
85
86 enum class StepBehavior {
87 PredefinedSteps,
88 HalfAndDouble,
89 };
90
91 // Constructors / Destructor
92 LengthEditBase() = delete;
93 explicit LengthEditBase(const Length& min, const Length& max,
94 const Length& value,
95 QWidget* parent = nullptr) noexcept;
96 LengthEditBase(const LengthEditBase& other) = delete;
97 virtual ~LengthEditBase() noexcept;
98
99 // Getters
100 const LengthUnit& getDisplayedUnit() const noexcept;
101
102 // Setters
103 void setDefaultValueToolTip(const Length& value) noexcept;
104 void setDefaultUnit(const LengthUnit& unit) noexcept;
105 void setChangeUnitActionVisible(bool visible) noexcept;
106 void setStepBehavior(StepBehavior behavior) noexcept;
107
120 void setSteps(const QVector<PositiveLength>& steps) noexcept;
121
122 // General Methods
123 void resetUnit() noexcept;
124 void configureClientSettings(const QString& uniqueIdentifier) noexcept;
125 void configure(const LengthUnit& defaultUnit,
126 const QVector<PositiveLength>& steps,
127 const QString& uniqueIdentifier) noexcept;
128 virtual void stepBy(int steps) override;
129
130 // Reimplemented Methods
131 QSize minimumSizeHint() const override;
132 QSize sizeHint() const override;
133
134 // Operator Overloadings
135 LengthEditBase& operator=(const LengthEditBase& rhs) = delete;
136
137signals:
139
140protected: // Methods
141 virtual QAbstractSpinBox::StepEnabled stepEnabled() const override;
142 void setValueImpl(Length value) noexcept;
143 void updateValueFromText(QString text) noexcept;
144 void updateSingleStep() noexcept;
145 void updateSingleStepPredefined() noexcept;
146 void updateSingleStepHalfDouble() noexcept;
147 void updateText() noexcept;
148 LengthUnit extractUnitFromExpression(QString& expression) const noexcept;
149 void changeUnitActionTriggered() noexcept;
150 void setSelectedUnit(const LengthUnit& unit) noexcept;
151 void saveSelectedUnit() noexcept;
152 QString getValueStr(const LengthUnit& unit) const noexcept;
153 virtual void valueChangedImpl(const Length& diff) noexcept = 0;
154
155protected: // Data
156 QPointer<QAction> mChangeUnitAction;
167 QString mSettingsKey;
168};
169
170/*******************************************************************************
171 * End of File
172 ******************************************************************************/
173
174} // namespace editor
175} // namespace librepcb
176
177#endif
The Length class is used to represent a length (for example 12.75 millimeters)
Definition: length.h:83
The LengthUnit class represents a length unit (millimeters, inches,...) and provides some useful meth...
Definition: lengthunit.h:60
The LengthEditBase class.
Definition: lengtheditbase.h:47
void updateSingleStepPredefined() noexcept
Definition: lengtheditbase.cpp:268
QSize minimumSizeHint() const override
Definition: lengtheditbase.cpp:179
const LengthUnit & getDisplayedUnit() const noexcept
Definition: lengtheditbase.cpp:93
void configureClientSettings(const QString &uniqueIdentifier) noexcept
Definition: lengtheditbase.cpp:139
Length mMaximum
Definition: lengtheditbase.h:160
void saveSelectedUnit() noexcept
Definition: lengtheditbase.cpp:360
void updateText() noexcept
Definition: lengtheditbase.cpp:307
LengthUnit extractUnitFromExpression(QString &expression) const noexcept
Definition: lengtheditbase.cpp:311
void changeUnitActionTriggered() noexcept
Definition: lengtheditbase.cpp:324
QSize sizeHint() const override
Definition: lengtheditbase.cpp:183
void setDefaultUnit(const LengthUnit &unit) noexcept
Definition: lengtheditbase.cpp:105
void resetUnit() noexcept
Definition: lengtheditbase.cpp:132
virtual void valueChangedImpl(const Length &diff) noexcept=0
LengthUnit mDefaultUnit
Definition: lengtheditbase.h:157
QPointer< QAction > mChangeUnitAction
Definition: lengtheditbase.h:156
QString getValueStr(const LengthUnit &unit) const noexcept
Definition: lengtheditbase.cpp:371
Length mSingleStepDown
Zero means "no step available".
Definition: lengtheditbase.h:165
Length mSingleStepUp
Zero means "no step available".
Definition: lengtheditbase.h:164
void updateSingleStepHalfDouble() noexcept
Definition: lengtheditbase.cpp:297
void configure(const LengthUnit &defaultUnit, const QVector< PositiveLength > &steps, const QString &uniqueIdentifier) noexcept
Definition: lengtheditbase.cpp:159
void setDefaultValueToolTip(const Length &value) noexcept
Definition: lengtheditbase.cpp:101
void setChangeUnitActionVisible(bool visible) noexcept
Definition: lengtheditbase.cpp:112
void setSteps(const QVector< PositiveLength > &steps) noexcept
Set the supported up/down step values.
Definition: lengtheditbase.cpp:122
void setValueImpl(Length value) noexcept
Definition: lengtheditbase.cpp:204
void setSelectedUnit(const LengthUnit &unit) noexcept
Definition: lengtheditbase.cpp:350
void displayedUnitChanged(const LengthUnit &unit)
QSize mAdditionalSize
Definition: lengtheditbase.h:166
virtual void stepBy(int steps) override
Definition: lengtheditbase.cpp:167
virtual QAbstractSpinBox::StepEnabled stepEnabled() const override
Definition: lengtheditbase.cpp:191
void updateValueFromText(QString text) noexcept
Definition: lengtheditbase.cpp:221
QString mSettingsKey
Empty means "do not save".
Definition: lengtheditbase.h:167
QVector< PositiveLength > mSteps
Definition: lengtheditbase.h:163
StepBehavior
Definition: lengtheditbase.h:86
void setStepBehavior(StepBehavior behavior) noexcept
Definition: lengtheditbase.cpp:116
Length mMinimum
Definition: lengtheditbase.h:159
Length mValue
Definition: lengtheditbase.h:161
StepBehavior mStepBehavior
Definition: lengtheditbase.h:162
tl::optional< LengthUnit > mSelectedUnit
Definition: lengtheditbase.h:158
void updateSingleStep() noexcept
Definition: lengtheditbase.cpp:250
Definition: occmodel.cpp:77
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:812
Definition: uuid.h:183
Definition: lengtheditbase.h:51
static QVector< PositiveLength > pinLength() noexcept
Definition: lengtheditbase.h:71
static QVector< PositiveLength > drillDiameter() noexcept
Definition: lengtheditbase.h:78
static QVector< PositiveLength > textHeight() noexcept
Definition: lengtheditbase.h:63