LibrePCB Developers Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
slinthelpers.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_SLINTHELPERS_H
21#define LIBREPCB_EDITOR_SLINTHELPERS_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
29
30#include <QtCore>
31#include <QtGui>
32
33#include <optional>
34#include <slint.h>
35
36/*******************************************************************************
37 * Namespace / Forward Declarations
38 ******************************************************************************/
39namespace librepcb {
40namespace editor {
41
42// q2s(): Qt to Slint conversion (only built-in types, not LibrePCB specific)
43// s2q(): Slint to Qt conversion (only built-in types, not LibrePCB specific)
44
45/*******************************************************************************
46 * Non-Member Functions
47 ******************************************************************************/
48
49slint::LogicalPosition q2s(const QPointF& p) noexcept;
50QPointF s2q(const slint::LogicalPosition& p) noexcept;
51
52slint::PhysicalPosition q2s(const QPoint& p) noexcept;
53QPoint s2q(const slint::PhysicalPosition& p) noexcept;
54
55slint::PhysicalSize q2s(const QSize& s) noexcept;
56QSize s2q(const slint::PhysicalSize& s) noexcept;
57
58slint::SharedString q2s(const QString& s) noexcept;
59QString s2q(const slint::SharedString& s) noexcept;
60bool operator==(const QString& s1, const slint::SharedString& s2) noexcept;
61bool operator!=(const QString& s1, const slint::SharedString& s2) noexcept;
62bool operator==(const slint::SharedString& s1, const QString& s2) noexcept;
63bool operator!=(const slint::SharedString& s1, const QString& s2) noexcept;
64
65slint::Image q2s(const QPixmap& p) noexcept;
66
67slint::Color q2s(const QColor& c) noexcept;
68
69slint::private_api::MouseCursor q2s(Qt::CursorShape s) noexcept;
70
71Qt::MouseButton s2q(const slint::private_api::PointerEventButton& b) noexcept;
72
73slint::private_api::KeyboardModifiers q2s(Qt::KeyboardModifiers m) noexcept;
74Qt::KeyboardModifiers s2q(
75 const slint::private_api::KeyboardModifiers& m) noexcept;
76
77slint::SharedString q2s(Qt::Key k) noexcept;
78
79// Bind property without type conversion
80template <typename TTarget, typename TClass, typename T>
81inline void bind(QObject* context, const TTarget& target,
82 void (TTarget::*setter)(const T&) const, TClass* source,
83 void (TClass::*signal)(T), const T& defaultValue) noexcept {
84 QObject::connect(source, signal, context, [&target, setter](const T& value) {
85 (target.*setter)(value);
86 });
87 (target.*setter)(defaultValue);
88}
89
90// Bind property with type conversion
91template <typename TTarget, typename TSlint, typename TClass, typename TQt>
92inline void bind(
93 QObject* context, const TTarget& target,
94 void (TTarget::*setter)(const TSlint&) const, TClass* source,
95 void (TClass::*signal)(TQt), const TQt& defaultValue,
96 std::function<TSlint(const TQt&)> convert = [](const TQt& value) {
97 return q2s(value);
98 }) noexcept {
99 QObject::connect(source, signal, context,
100 [&target, setter, convert](const TQt& value) {
101 (target.*setter)(convert(value));
102 });
103 (target.*setter)(convert(defaultValue));
104}
105
106std::optional<ElementName> validateElementName(
107 const QString& input, slint::SharedString& error) noexcept;
108
109std::optional<Version> validateVersion(const QString& input,
110 slint::SharedString& error) noexcept;
111
112std::optional<FileProofName> validateFileProofName(
113 const QString& input, slint::SharedString& error,
114 const QString& requiredSuffix = QString()) noexcept;
115
116std::optional<QUrl> validateUrl(const QString& input,
117 slint::SharedString& error,
118 bool allowEmpty = false) noexcept;
119
120/*******************************************************************************
121 * End of File
122 ******************************************************************************/
123
124} // namespace editor
125} // namespace librepcb
126
127#endif
std::optional< Version > validateVersion(const QString &input, slint::SharedString &error) noexcept
Definition slinthelpers.cpp:288
std::optional< FileProofName > validateFileProofName(const QString &input, slint::SharedString &error, const QString &requiredSuffix) noexcept
Definition slinthelpers.cpp:299
QPointF s2q(const slint::LogicalPosition &p) noexcept
Definition slinthelpers.cpp:43
slint::LogicalPosition q2s(const QPointF &p) noexcept
Definition slinthelpers.cpp:38
bool operator==(const QString &s1, const slint::SharedString &s2) noexcept
Definition slinthelpers.cpp:73
void bind(QObject *context, const TTarget &target, void(TTarget::*setter)(const T &) const, TClass *source, void(TClass::*signal)(T), const T &defaultValue) noexcept
Definition slinthelpers.h:81
std::optional< ElementName > validateElementName(const QString &input, slint::SharedString &error) noexcept
Definition slinthelpers.cpp:277
bool operator!=(const QString &s1, const slint::SharedString &s2) noexcept
Definition slinthelpers.cpp:77
Definition occmodel.cpp:77
Definition uuid.h:186