Maki
Formally verfied low-code orchestration
Loading...
Searching...
No Matches
widget_factory.h
1#pragma once
2
3#include <QComboBox>
4#include <QWidget>
5
6#include "mission_parameter.h"
7#include "oclero/qlementine/widgets/ColorEditor.hpp"
8#include "style_helpers.h"
9#include "typing/type_definition.h"
10#include "typing/type_reference.h"
11
12class QLineEdit;
13class QToolButton;
14class QSpinBox;
15class QPushButton;
16class QLabel;
17class QCheckBox;
18class QFormLayout;
21class QTableWidget;
22
23namespace oclero::qlementine
24{
25class Label;
26class LineEdit;
27class ColorEditor;
28} // namespace oclero::qlementine
29
34namespace maki
35{
36class WidgetGroup;
37class ClickableLabel;
38
39void addCompleter(const QStringList& items, QWidget* parent);
40
46{
51 enum class Type
52 {
54 UNKNOWN = 0,
56 INLINE,
58 VERTICAL,
60 FORM
61 } type;
62
63 enum class Direction
64 {
66 UNKNOWN = 0,
67 LEFT,
68 RIGHT,
69 CENTER,
70 SPREAD,
71 ABOVE
73
75 int labelWidth = 0;
76
77 static WidgetAlignment Inline()
78 {
80 };
81
82 static WidgetAlignment Vertical()
83 {
85 };
86
87 static WidgetAlignment Form(maki::WidgetGroup* widgetGroup, int width = 0, Direction dir = Direction::SPREAD)
88 {
89 return maki::WidgetAlignment{
91 .direction = dir,
92 .group = widgetGroup,
93 .labelWidth = width,
94 };
95 };
96};
97
102class GridGroup : public QWidget
103{
104public:
112 GridGroup(const QString& label, int rows, int cols, QWidget* parent);
113
118 void addWidget(QWidget* widget);
119
124 void addLayout(QLayout* layout);
125
130 QWidget* widget() const;
131
132private:
133 QWidget* mContent;
134 const int mRows;
135 const int mCols;
136
139};
140
145class WidgetGroup : public QWidget
146{
147 Q_OBJECT
148public:
154 WidgetGroup(const QString& label, QWidget* parent);
155 WidgetGroup(const QString& label, oclero::qlementine::TextRole role, QWidget* parent);
156
161 virtual void addWidget(QWidget* widget);
162
167 virtual void addLayout(QLayout* layout);
168
173 virtual void addSpacing(int spacing);
174
178 virtual void addStretch();
179
180 virtual void removeWidget(QWidget* widget);
181 virtual void clear();
182 virtual void setPadding(int padding);
183
184protected:
185 int mPadding;
186 QWidget* mContentWidget = nullptr;
187 QVBoxLayout* mContentLayout = nullptr;
188};
189
191{
192public:
198 WidgetScrollGroup(const QString& label, QWidget* parent);
199 WidgetScrollGroup(const QString& label, oclero::qlementine::TextRole role, QWidget* parent);
200};
201
202class InputWidget : public QWidget
203{
204 Q_OBJECT
205public:
206 InputWidget(const QString& label, QWidget* inputField, WidgetAlignment alignment, QWidget* parent = nullptr);
207 virtual ~InputWidget() = default;
208
209 void addDescription(const QString& text);
210 void setToolTip(const QString& text);
211
212 void setType(const koda::types::TypeReference& type);
213 void setValue(const Value& value);
214 Value getValue() const;
215
216 virtual void writeValueToWidget(const Value& value) = 0;
217
218 virtual QList<QWidget*> focusWidgets() const
219 {
220 return {mInputField};
221 }
222
223 bool isReference() const;
224 void setReference(const QString& id);
225 void clearReference();
226 void setSupportedReferences(const QVector<MissionParameter>& parameters);
227
228signals:
229 void valueChanged();
230 void openParameter(const QString& parameter);
231
232protected:
233 koda::types::TypeReference mType;
234 Value mValue{};
235 QWidget* mInputField = nullptr;
236 QMenu* mParameterMenu;
237 ClickableLabel* mParameterLabel = nullptr;
238 QToolButton* mParameterButton = nullptr;
239 QHBoxLayout* mContainerLayout = nullptr;
240
241 void createReferenceWidgets();
242 QWidget* createLayout(oclero::qlementine::Label* label, WidgetAlignment alignment);
243};
244
245template <typename W>
246class TypedInputWidget : public InputWidget
247{
248public:
249 TypedInputWidget(const QString& label, W* inputField, WidgetAlignment alignment, QWidget* parent = nullptr)
250 : InputWidget(label, inputField, alignment, parent)
251 {
252 }
253
254 W* widget() const
255 {
256 return qobject_cast<W*>(mInputField);
257 }
258};
259
264class BooleanWidget : public TypedInputWidget<QCheckBox>
265{
266 Q_OBJECT
267public:
275 BooleanWidget(const QString& label, bool value, WidgetAlignment alignment, QWidget* parent);
276
277 bool getValue() const;
278 void setValue(bool value);
279
280 void writeValueToWidget(const Value& value) override;
281
282signals:
287 void valueChanged(const bool value);
288};
289
294class StringWidget : public TypedInputWidget<oclero::qlementine::LineEdit>
295{
296 Q_OBJECT
297public:
305 StringWidget(const QString& label, const QString& placeholder, WidgetAlignment alignment, QWidget* parent);
306 StringWidget(const QString& label, const QString& placeholder, WidgetAlignment alignment, const QString& tooltip, QWidget* parent);
307
308 QString getValue() const;
309 void setValue(const QString& value);
310
311 void writeValueToWidget(const Value& value) override;
312
313signals:
318 void valueChanged(const QString& value);
319
320private:
321 QTimer* mUpdateTimer = nullptr;
322};
323
328class IntegerWidget : public TypedInputWidget<oclero::qlementine::LineEdit>
329{
330 Q_OBJECT
331public:
341 IntegerWidget(const QString& label, const QString& placeholder, WidgetAlignment alignment, QWidget* parent, int min = INT32_MIN, int max = INT32_MAX);
342
347 void setAcceptVariable(bool accept);
348
349 void writeValueToWidget(const Value& value) override;
350
351 int getValue() const;
352 void setValue(int value);
353 void setValue(const QString& value);
354
355signals:
360 void valueChanged(const QString& value);
361
362private:
363 IntegerOrVariableValidator* mValidator;
364};
365
370class FloatWidget : public TypedInputWidget<oclero::qlementine::LineEdit>
371{
372 Q_OBJECT
373public:
383 FloatWidget(const QString& label, const QString& placeholder, WidgetAlignment alignment, QWidget* parent, qreal min = std::numeric_limits<qreal>::min(),
384 qreal max = std::numeric_limits<qreal>::max());
385
390 void setAcceptVariable(bool accept);
391
392 void writeValueToWidget(const Value& value) override;
393
394 double getValue() const;
395 void setValue(double value);
396 void setValue(const QString& value);
397
398signals:
403 void valueChanged(const QString& value);
404
405private:
406 DoubleOrVariableValidator* mValidator;
407};
408
413class SpinWidget : public TypedInputWidget<QSpinBox>
414{
415 Q_OBJECT
416public:
425 SpinWidget(const QString& label, int placeholder, QWidget* parent, WidgetAlignment alignment, int min = INT32_MIN, int max = INT32_MAX);
426
427 int getValue() const;
428 void setValue(int value);
429
430 void writeValueToWidget(const Value& value) override;
431
436 void setSuffix(const QString& suffix);
437
438signals:
443 void valueChanged(const int value);
444};
445
450class SelectorWidget : public TypedInputWidget<QComboBox>
451{
452 Q_OBJECT
453public:
459 SelectorWidget(const QString& label, WidgetAlignment alignment, QWidget* parent);
460
467 SelectorWidget(const QString& label, QComboBox* comboBox, WidgetAlignment alignment, QWidget* parent);
468
469 QVariant getData() const;
470 void setData(const QString& value);
471
472 QString getValue() const;
473 void setValue(const QString& value);
474
480 void addItem(const QString& name, const QVariant& value);
481
482 void writeValueToWidget(const Value& value) override;
483
484signals:
489 void valueChanged(const QString& value);
490 void dataChanged(const QString& text, const QVariant& value);
491
492private:
493 QVariant mData;
494};
495
500class ButtonWidget : public QWidget
501{
502 Q_OBJECT
503public:
509 ButtonWidget(const QString& label, QWidget* parent);
510
515 void addDescription(const QString& label);
516
521 void setIcon(const QIcon& icon);
522
527 void setToolTip(const QString& tooltip);
528
533 void setText(const QString& text);
534
535signals:
540
541private:
542 QPushButton* mInputField;
543};
544
549class ColorWidget : public TypedInputWidget<oclero::qlementine::ColorEditor>
550{
551 Q_OBJECT
552public:
559 ColorWidget(const QString& label, const QString& placeholder, WidgetAlignment alignment, QWidget* parent);
560
561 QColor getValue() const;
562 void setValue(const QColor& value);
563
564 void writeValueToWidget(const Value& color) override;
565signals:
570 void valueChanged(const QColor& value);
571};
572
577class TypeSelectionWidget : public QComboBox
578{
579 Q_OBJECT
580public:
585 TypeSelectionWidget(QWidget* parent);
586
592 TypeSelectionWidget(const QString& initial, QWidget* parent);
593
600 TypeSelectionWidget(const QString& initial, Types::PropertyTypes last, QWidget* parent);
601};
602
607class ContainerWidget : public TypedInputWidget<QWidget>
608{
609 Q_OBJECT
610public:
617 ContainerWidget(const QString& label, QWidget* widget, WidgetAlignment alignment, QWidget* parent);
618
619 void writeValueToWidget(const Value& value) override;
620};
621
626class SearchWidget : public QWidget
627{
628 Q_OBJECT
629public:
635 SearchWidget(const QString& placeholder, QWidget* parent);
636
641 void addDescription(const QString& label);
642
647 void setValue(const QString& value);
648
653 QString getValue() const;
654
659 QLineEdit* widget() const;
660
661signals:
666 void valueChanged(const QString& value);
667
671 void dismissed();
672
673private:
674 QLineEdit* mInputField;
675 QLabel* mIcon;
676 QString mValue;
677};
678
679class ListWidget : public TypedInputWidget<WidgetGroup>
680{
681 Q_OBJECT
682public:
683 ListWidget(const QString& label, const koda::types::TypeReference& elementType, WidgetAlignment alignment, QWidget* parent = nullptr);
684
685 ListValue getValue() const;
686 void setValue(const ListValue& value);
687
688 void writeValueToWidget(const Value& value) override;
689
690 virtual QList<QWidget*> focusWidgets() const override;
691
692private:
693 koda::types::TypeReference mElementType;
694
695 QWidget* mItems = nullptr;
696 QVBoxLayout* mItemsLayout = nullptr;
697
698 std::vector<InputWidget*> mEditors;
699
700 void addItem(const Value& value);
701 void clear();
702};
703
704class MapWidget : public TypedInputWidget<WidgetGroup>
705{
706 Q_OBJECT
707public:
708 MapWidget(const QString& label, const koda::types::TypeReference& keyType, const koda::types::TypeReference& valueType, WidgetAlignment alignment,
709 QWidget* parent = nullptr);
710
711 MapValue getValue() const;
712 void setValue(const MapValue& value);
713
714 void writeValueToWidget(const Value& value) override;
715
716 virtual QList<QWidget*> focusWidgets() const override;
717
718private:
719 koda::types::TypeReference mKeyType;
720 koda::types::TypeReference mValueType;
721
722 QWidget* mItems = nullptr;
723 QVBoxLayout* mItemsLayout = nullptr;
724
725 struct MapField
726 {
727 InputWidget* keyEditor;
728 InputWidget* valueEditor;
729 };
730
731 std::vector<MapField> mEditors;
732
733 void addItem(const Value& key, const Value& value);
734 void clear();
735};
736
737class RecordWidget : public TypedInputWidget<WidgetGroup>
738{
739 Q_OBJECT
740public:
741 RecordWidget(const QString& containerLabel, const QString& label, const koda::types::TypeDefinition& definition, WidgetAlignment alignment,
742 QWidget* parent = nullptr);
743
744 RecordValue getValue() const;
745 void setValue(const RecordValue& value);
746
747 void writeValueToWidget(const Value& value) override;
748
749 virtual QList<QWidget*> focusWidgets() const override;
750
751private:
753 {
754 QString id;
755 InputWidget* editor;
756 };
757
758 std::vector<RecordField> mEditors;
759 const koda::types::TypeDefinition mDefinition;
760
761 void addItem(const QString& id, const Value& value);
762 void clear();
763};
764
765class EnumWidget : public SelectorWidget
766{
767 Q_OBJECT
768public:
769 EnumWidget(const QString& label, const koda::types::TypeDefinition& definition, WidgetAlignment alignment, QWidget* parent = nullptr);
770
771private:
772 const koda::types::TypeDefinition mDefinition;
773};
774
776{
777public:
778 static InputWidget* create(const QString& label, const koda::types::TypeReference& type, const Value& value, WidgetAlignment alignment, QWidget* parent);
779};
780
781} // namespace maki
Definition double_variable.h:6
Definition int_variable.h:6
BooleanWidget(const QString &label, bool value, WidgetAlignment alignment, QWidget *parent)
Constructs a boolean input widget.
Definition widget_factory.cpp:510
void valueChanged(const bool value)
Emitted when the boolean value changes.
void setIcon(const QIcon &icon)
Sets the button icon.
Definition widget_factory.cpp:949
QPushButton * mInputField
Push button used by this widget.
Definition widget_factory.h:542
ButtonWidget(const QString &label, QWidget *parent)
Constructs a button widget.
Definition widget_factory.cpp:935
void addDescription(const QString &label)
Adds a descriptive label or help text to the widget.
Definition widget_factory.cpp:964
void valueChanged()
Emitted when the button is activated.
void setToolTip(const QString &tooltip)
Sets the tooltip shown for the button.
Definition widget_factory.cpp:954
void setText(const QString &text)
Sets the text shown in the button.
Definition widget_factory.cpp:959
Definition clickable_label.h:8
void valueChanged(const QColor &value)
Emitted when the selected colour changes.
ColorWidget(const QString &label, const QString &placeholder, WidgetAlignment alignment, QWidget *parent)
Constructs a colour selection widget.
Definition widget_factory.cpp:972
ContainerWidget(const QString &label, QWidget *widget, WidgetAlignment alignment, QWidget *parent)
Constructs a selector widget using an existing combo box.
Definition widget_factory.cpp:1039
FloatWidget(const QString &label, const QString &placeholder, WidgetAlignment alignment, QWidget *parent, qreal min=std::numeric_limits< qreal >::min(), qreal max=std::numeric_limits< qreal >::max())
Constructs a floating-point input widget.
Definition widget_factory.cpp:703
void valueChanged(const QString &value)
Emitted when the floating-point value changes.
void setAcceptVariable(bool accept)
Sets the widget to accept variables.
Definition widget_factory.cpp:740
void addLayout(QLayout *layout)
Adds a layout to the next available cell in the grid.
Definition widget_factory.cpp:151
void addWidget(QWidget *widget)
Adds a widget to the next available cell in the grid.
Definition widget_factory.cpp:135
const int mRows
Total number of rows in the grid.
Definition widget_factory.h:134
GridGroup(const QString &label, int rows, int cols, QWidget *parent)
Constructs a grid group with a label and fixed grid dimensions.
Definition widget_factory.cpp:99
int mCurrentRow
Current row where the next item will be inserted.
Definition widget_factory.h:137
QWidget * widget() const
Returns the internal content widget of the group.
Definition widget_factory.cpp:130
QWidget * mContent
Internal content widget that owns the grid contents.
Definition widget_factory.h:133
int mCurrentCol
Current column where the next item will be inserted.
Definition widget_factory.h:138
const int mCols
Total number of columns in the grid.
Definition widget_factory.h:135
Definition widget_factory.h:203
void valueChanged(const QString &value)
Emitted when the integer value changes.
IntegerWidget(const QString &label, const QString &placeholder, WidgetAlignment alignment, QWidget *parent, int min=INT32_MIN, int max=INT32_MAX)
Constructs an integer input widget.
Definition widget_factory.cpp:616
void setAcceptVariable(bool accept)
Sets the widget to accept variables.
Definition widget_factory.cpp:651
QLineEdit * mInputField
Line edit used to enter the search text.
Definition widget_factory.h:674
void setValue(const QString &value)
Sets the current search text.
Definition widget_factory.cpp:1094
void dismissed()
Emitted when the search widget is dismissed or cleared by the user.
void addDescription(const QString &label)
Adds a descriptive label or help text to the widget.
Definition widget_factory.cpp:1082
QLabel * mIcon
Label displaying the search icon.
Definition widget_factory.h:675
QLineEdit * widget() const
Returns the underlying line edit used for text input.
Definition widget_factory.cpp:1077
void valueChanged(const QString &value)
Emitted when the search text changes.
SearchWidget(const QString &placeholder, QWidget *parent)
Constructs a search widget.
Definition widget_factory.cpp:1049
QString getValue() const
Returns the current search text.
Definition widget_factory.cpp:1089
QString mValue
Cached search text.
Definition widget_factory.h:676
void valueChanged(const QString &value)
Emitted when the selected value changes.
SelectorWidget(const QString &label, WidgetAlignment alignment, QWidget *parent)
Constructs a selector widget with an internally created combo box.
Definition widget_factory.cpp:838
void addItem(const QString &name, const QVariant &value)
Adds an item to the selector.
Definition widget_factory.cpp:914
void setSuffix(const QString &suffix)
Sets the suffix displayed by the spin box.
Definition widget_factory.cpp:811
void valueChanged(const int value)
Emitted when the spin box value changes.
SpinWidget(const QString &label, int placeholder, QWidget *parent, WidgetAlignment alignment, int min=INT32_MIN, int max=INT32_MAX)
Constructs a spin box input widget.
Definition widget_factory.cpp:792
void valueChanged(const QString &value)
Emitted when the string value changes.
StringWidget(const QString &label, const QString &placeholder, WidgetAlignment alignment, QWidget *parent)
Constructs a string input widget.
Definition widget_factory.cpp:549
TypeSelectionWidget(QWidget *parent)
Constructs a type selection widget.
Definition widget_factory.cpp:1009
Definition widget_factory.h:776
A labelled container widget that groups widgets in a generic layout.
Definition widget_factory.h:146
virtual void addSpacing(int spacing)
Adds fixed spacing to the group layout.
Definition widget_factory.cpp:221
WidgetGroup(const QString &label, QWidget *parent)
Constructs a widget group with a label.
Definition widget_factory.cpp:168
virtual void addWidget(QWidget *widget)
Adds a widget to the group.
Definition widget_factory.cpp:207
virtual void addStretch()
Adds a stretchable spacer to the group layout.
Definition widget_factory.cpp:226
virtual void addLayout(QLayout *layout)
Adds a layout to the group.
Definition widget_factory.cpp:216
WidgetScrollGroup(const QString &label, QWidget *parent)
Constructs a widget group with a label.
Definition widget_factory.cpp:248
Contains UI helper widgets and layout grouping utilities used by MAKI.
Definition generator.h:10
Definition widget_factory.h:726
Definition widget_factory.h:753
Describes how a widget should be aligned or inserted into a parent layout.
Definition widget_factory.h:46
Direction
Definition widget_factory.h:64
Type
Supported alignment/layout styles for widgets.
Definition widget_factory.h:52
@ FORM
Widget should be placed in a form layout.
Definition widget_factory.h:60
@ VERTICAL
Widget should be placed vertically.
Definition widget_factory.h:58
@ INLINE
Widget should be placed inline with other widgets.
Definition widget_factory.h:56
WidgetGroup * group
Optional form layout associated with this alignment.
Definition widget_factory.h:74
enum maki::WidgetAlignment::Direction direction
The alignment mode to apply.
enum maki::WidgetAlignment::Type type
The alignment mode to apply.