LibrePCB Developers Documentation
Loading...
Searching...
No Matches
lengtheditcontext.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_LENGTHEDITCONTEXT_H
21#define LIBREPCB_EDITOR_LENGTHEDITCONTEXT_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "appwindow.h"
27
30
31#include <QtCore>
32
33/*******************************************************************************
34 * Namespace / Forward Declarations
35 ******************************************************************************/
36namespace librepcb {
37
38class WorkspaceSettings;
39
40namespace editor {
41
42/*******************************************************************************
43 * Class LengthEditContext
44 ******************************************************************************/
45
49class LengthEditContext final : public QObject {
50 Q_OBJECT
51
52public:
63 struct Steps {
64 static QVector<PositiveLength> generic() noexcept {
65 return {
66 PositiveLength(10000), // 0.01mm
67 PositiveLength(25400), // 0.0254mm
68 PositiveLength(100000), // 0.1mm
69 PositiveLength(254000), // 0.254mm
70 PositiveLength(1000000), // 1mm
71 PositiveLength(2540000), // 2.54mm
72 };
73 }
74
75 static QVector<PositiveLength> textHeight() noexcept {
76 return {
77 PositiveLength(100000), // 0.1mm
78 PositiveLength(254000), // 0.254mm
79 PositiveLength(500000), // 0.5mm (default)
80 };
81 }
82
83 static QVector<PositiveLength> pinLength() noexcept {
84 return {
85 PositiveLength(2500000), // 2.5mm (for metric symbols)
86 PositiveLength(2540000), // 2.54mm (default)
87 };
88 }
89
90 static QVector<PositiveLength> drillDiameter() noexcept {
91 return {
92 PositiveLength(254000), // 0.254mm (for imperial drills)
93 PositiveLength(100000), // 0.1mm (default, for metric drills)
94 };
95 }
96 };
97
98 enum class StepBehavior {
101 };
102
103 // Constructors / Destructor
105 LengthEditContext(const LengthEditContext& other) = delete;
106 explicit LengthEditContext(const WorkspaceSettings& ws,
107 QObject* parent = nullptr) noexcept;
108 virtual ~LengthEditContext() noexcept;
109
110 // General Methods
111 ui::LengthEditData getUiData() const noexcept;
112 void setUiData(const ui::LengthEditData& data) noexcept;
113 void configure(const Length& value, const QVector<PositiveLength>& steps,
114 const QString& uniqueIdentifier) noexcept;
115 void configure(const UnsignedLength& value,
116 const QVector<PositiveLength>& steps,
117 const QString& uniqueIdentifier) noexcept;
118 void configure(const PositiveLength& value,
119 const QVector<PositiveLength>& steps,
120 const QString& uniqueIdentifier) noexcept;
121 void setValue(const Length& value) noexcept;
122 void setValueUnsigned(const UnsignedLength& value) noexcept;
123 void setValuePositive(const PositiveLength& value) noexcept;
124 void setUnit(const LengthUnit& unit) noexcept;
125 void setStepBehavior(StepBehavior behavior) noexcept;
126 void stepBy(int steps) noexcept;
127
128 // Operator Overloadings
129 LengthEditContext& operator=(const LengthEditContext& rhs) = delete;
130
131signals:
133 void valueChanged(const Length& value);
136
137protected: // Methods
138 LengthEditContext(const WorkspaceSettings& ws, const Length& min,
139 const Length& value, QObject* parent = nullptr) noexcept;
140 void configureSettings(const QString& uniqueIdentifier) noexcept;
141 void updateSingleStep() noexcept;
142 void updateSingleStepPredefined() noexcept;
143 void updateSingleStepHalfDouble() noexcept;
144 void setValueImpl(const Length& value, bool emitValueChanged) noexcept;
145
146protected: // Data
155 QString mSettingsKey;
156};
157
158/*******************************************************************************
159 * End of File
160 ******************************************************************************/
161
162} // namespace editor
163} // namespace librepcb
164
165#endif
The Length class is used to represent a length (for example 12.75 millimeters)
Definition length.h:82
The LengthUnit class represents a length unit (millimeters, inches,...) and provides some useful meth...
Definition lengthunit.h:62
Container for all workspace related settings.
Definition workspacesettings.h:60
Backend configuration for the LengthEdit UI element.
Definition lengtheditcontext.h:49
void updateSingleStepPredefined() noexcept
Definition lengtheditcontext.cpp:204
ui::LengthEditData getUiData() const noexcept
Definition lengtheditcontext.cpp:69
void configure(const Length &value, const QVector< PositiveLength > &steps, const QString &uniqueIdentifier) noexcept
Definition lengtheditcontext.cpp:92
LengthUnit mUnit
Definition lengtheditcontext.h:151
void stepBy(int steps) noexcept
Definition lengtheditcontext.cpp:150
void configureSettings(const QString &uniqueIdentifier) noexcept
Definition lengtheditcontext.cpp:162
void setUnit(const LengthUnit &unit) noexcept
Definition lengtheditcontext.cpp:128
void setValueUnsigned(const UnsignedLength &value) noexcept
Definition lengtheditcontext.cpp:120
Length mSingleStepDown
Zero means "no step available".
Definition lengtheditcontext.h:154
Length mSingleStepUp
Zero means "no step available".
Definition lengtheditcontext.h:153
void updateSingleStepHalfDouble() noexcept
Definition lengtheditcontext.cpp:233
void setValueImpl(const Length &value, bool emitValueChanged) noexcept
Definition lengtheditcontext.cpp:243
void setValuePositive(const PositiveLength &value) noexcept
Definition lengtheditcontext.cpp:124
void valueChanged(const Length &value)
const WorkspaceSettings & mSettings
Definition lengtheditcontext.h:147
void valueChangedPositive(const PositiveLength &value)
LengthEditContext(const LengthEditContext &other)=delete
void setUiData(const ui::LengthEditData &data) noexcept
Definition lengtheditcontext.cpp:81
void setValue(const Length &value) noexcept
Definition lengtheditcontext.cpp:116
QString mSettingsKey
Empty means "do not save".
Definition lengtheditcontext.h:155
QVector< PositiveLength > mSteps
Definition lengtheditcontext.h:150
StepBehavior
Definition lengtheditcontext.h:98
void setStepBehavior(StepBehavior behavior) noexcept
Definition lengtheditcontext.cpp:145
Length mMinimum
Definition lengtheditcontext.h:148
Length mValue
Definition lengtheditcontext.h:152
void valueChangedUnsigned(const UnsignedLength &value)
StepBehavior mStepBehavior
Definition lengtheditcontext.h:149
void updateSingleStep() noexcept
Definition lengtheditcontext.cpp:186
Definition occmodel.cpp:77
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition length.h:810
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition length.h:694
Up/down step values.
Definition lengtheditcontext.h:63
static QVector< PositiveLength > pinLength() noexcept
Definition lengtheditcontext.h:83
static QVector< PositiveLength > drillDiameter() noexcept
Definition lengtheditcontext.h:90
static QVector< PositiveLength > textHeight() noexcept
Definition lengtheditcontext.h:75