Maki
Formally verfied low-code orchestration
Loading...
Searching...
No Matches
type_editor.h
1#pragma once
2
3#include <QCompleter>
4#include <QWidget>
5
6#include "typing/types.h"
7
8class QAction;
9class QComboBox;
10class QLineEdit;
11class QPushButton;
12class QStackedWidget;
13class QTableWidget;
14class QTreeWidget;
15class QTreeWidgetItem;
16class QMouseEvent;
17
18namespace koda::types
19{
20struct QualifiedName;
21class TypeDefinition;
22class TypeReference;
23class FieldDefinition;
24} // namespace koda::types
25
26namespace maki
27{
28
29class StringWidget;
30struct WidgetAlignment;
31
32class TypeEditor : public QWidget
33{
34 Q_OBJECT
35
36public:
37 TypeEditor(QWidget* parent = nullptr);
38
39 void focusCurrentEditor();
40
41public slots:
42 // Type management
43 void createRecord();
44 void createEnum();
45 void createAlias();
46
47private slots:
48 void removeCurrentType();
49 void applyChanges();
50
51 // Selection
52 void currentTypeChanged(QTreeWidgetItem* current, QTreeWidgetItem* previous);
53
54 // Record editor
55 void addField(const QString& defaultName, const koda::types::FieldDefinition& field);
56 void removeField();
57
58 // Enum editor
59 void addEnumValue(const QString& defaultName, const QString& defaultValue);
60 void removeEnumValue();
61
62 // Registry
63 void reloadTypes();
64
65 void exportAsJson();
66 void importFromJson();
67
68protected:
69 bool eventFilter(QObject* object, QEvent* event);
70
71private:
72 enum class EditorPage
73 {
74 None = 0,
75 Builtin,
76 Record,
77 Enum,
78 Alias
79 };
80
81 enum TreeRole
82 {
83 QualifiedNameRole = Qt::UserRole,
84 IdRole = Qt::UserRole + 1,
85 RootIdRole = Qt::UserRole + 2,
86 };
87
88 QTreeWidget* mTypeTree = nullptr;
89
90 QPushButton* mAddButton = nullptr;
91 QPushButton* mDeleteButton = nullptr;
92 QPushButton* mApplyButton = nullptr;
93 QPushButton* mExportButton = nullptr;
94 QPushButton* mImportButton = nullptr;
95
96 QStackedWidget* mEditorStack = nullptr;
97
98 QTableWidget* mFieldsTable = nullptr;
99 QPushButton* mAddFieldButton = nullptr;
100 QPushButton* mRemoveFieldButton = nullptr;
101
102 QComboBox* mEnumBackingCombo = nullptr;
103 QTableWidget* mEnumTable = nullptr;
104 QPushButton* mAddEnumValueButton = nullptr;
105 QPushButton* mRemoveEnumValueButton = nullptr;
106
107 QString mSelectedId;
108 bool mSelectedBuiltin = false;
109 bool mReloading = false;
110
111 void buildUi();
112 QWidget* createBuiltinPage();
113 QWidget* createRecordPage();
114 QWidget* createEnumPage();
115 QWidget* createAliasPage();
116
117 void clearEditor();
118 void showDefinition(const koda::types::TypeDefinition& definition);
119 koda::types::TypeDefinition readDefinitionFromUi() const;
120
121 std::string createUniqueTypeName(const std::string& baseName) const;
122
123 QTreeWidgetItem* findTreeItemById(const QString& id) const;
124 QTreeWidgetItem* findTreeItemByName(const QString& qualifiedName) const;
125 QTreeWidgetItem* findItemByRole(QTreeWidgetItem* parent, int role, const QVariant& value) const;
126
127 void selectType(const QString& qualifiedName);
128
129 QTableWidget* createTable(QWidget* parent, const QStringList& headers);
130 void createDefinition(const koda::types::TypeDefinition& definition);
131 maki::StringWidget* createNamespaceEdit(maki::WidgetAlignment& alignment, QWidget* parent) const;
132 QIcon typeToIcon(const koda::types::TypeDefinition& type) const;
133
134 void populateEnumKind(QComboBox* widget) const;
135 void populateExtentKind(QComboBox* widget, const koda::types::QualifiedName* currentName = nullptr) const;
136
137 void validateEnumValues();
138 bool validateEnumValue(int row);
139 bool isValidEnumValue(const QString& value, koda::types::EnumUnderlyingKind type) const;
140};
141
142} // namespace maki
A widget for displaying and editing string values.
Definition widget_factory.h:295
Contains UI helper widgets and layout grouping utilities used by MAKI.
Definition generator.h:10
Describes how a widget should be aligned or inserted into a parent layout.
Definition widget_factory.h:46