FOSSredder 0.5.0
Loading...
Searching...
No Matches
ContractViewModel.h
Go to the documentation of this file.
1
5
6#pragma once
7
8#include <QObject>
9#include <QString>
10#include <QVariantList>
11#include <QVariantMap>
12
13namespace ui {
14
18class WorkspaceStore;
19
24class ContractViewModel : public QObject {
25 Q_OBJECT
26 Q_PROPERTY(QString currentId READ currentId NOTIFY changed)
27 Q_PROPERTY(QString name READ name WRITE setName NOTIFY changed)
28 Q_PROPERTY(QString type READ type WRITE setType NOTIFY changed)
29 Q_PROPERTY(QString allocatableMode READ allocatableMode WRITE
31 Q_PROPERTY(QVariantList aliases READ aliases WRITE setAliases NOTIFY changed)
32 Q_PROPERTY(QString aliasInputText READ aliasInputText WRITE setAliasInputText
33 NOTIFY changed)
34 Q_PROPERTY(int aliasIndex READ aliasIndex WRITE setAliasIndex NOTIFY changed)
35 Q_PROPERTY(QVariantList selectedActorIds READ selectedActorIds WRITE
37 Q_PROPERTY(QVariantList selectedPropertyIds READ selectedPropertyIds WRITE
39 Q_PROPERTY(QVariantList actorDisplayRows READ actorDisplayRows NOTIFY changed)
40 Q_PROPERTY(QVariantList contractRows READ contractRows NOTIFY changed)
41 Q_PROPERTY(QVariantList propertyRows READ propertyRows NOTIFY changed)
42 Q_PROPERTY(int selectedActorIndex READ selectedActorIndex NOTIFY changed)
43 Q_PROPERTY(bool isEdit READ isEdit NOTIFY changed)
44 Q_PROPERTY(bool hasChanges READ hasChanges NOTIFY changed)
45 Q_PROPERTY(bool canSubmit READ canSubmit NOTIFY changed)
46
47public:
52 explicit ContractViewModel(WorkspaceStore* store, WorkspaceCommands* commands,
53 WorkspaceSelection* selection,
54 WorkspaceSelectors* selectors,
55 QObject* parent = nullptr);
56
61 QString currentId() const;
66 QString name() const {
67 return name_;
68 }
69
73 void setName(const QString& value);
78 QVariantList aliases() const {
79 return aliases_;
80 }
81
85 void setAliases(const QVariantList& value);
90 QString aliasInputText() const {
91 return aliasInputText_;
92 }
93
97 void setAliasInputText(const QString& value);
102 int aliasIndex() const {
103 return aliasIndex_;
104 }
105
109 void setAliasIndex(int value);
110
115 QString type() const;
116
121 void setType(const QString& value);
122
127 QString allocatableMode() const;
128
133 void setAllocatableMode(const QString& value);
134
139 QVariantList selectedActorIds() const;
140
145 void setSelectedActorIds(const QVariantList& value);
146
151 QVariantList selectedPropertyIds() const;
152
157 void setSelectedPropertyIds(const QVariantList& value);
158
163 QVariantList actorDisplayRows() const;
164
169 QVariantList contractRows() const;
170
175 QVariantList propertyRows() const;
176
181 int selectedActorIndex() const;
182
187 bool isEdit() const;
188
193 bool hasChanges() const;
194
199 bool canSubmit() const;
205 Q_INVOKABLE bool canAddAlias(const QString& value) const;
210 Q_INVOKABLE void addAlias(const QString& value);
214 Q_INVOKABLE void requestRemoveSelectedAlias();
215
219 Q_INVOKABLE void clear();
220
224 Q_INVOKABLE void enterCreateMode();
225
230 Q_INVOKABLE void selectContract(const QString& id);
231
236 Q_INVOKABLE void selectPrimaryActor(const QString& actorId);
237
243 Q_INVOKABLE void setPropertySelected(const QString& propertyId,
244 bool selected);
245
249 Q_INVOKABLE void previous();
250
254 Q_INVOKABLE void next();
255
260 Q_INVOKABLE QString submit();
261
265 Q_INVOKABLE void deleteCurrent();
266
267signals:
268 void changed();
269
270private:
272 void bindSignals();
273
278 QVariantList actorRows() const;
279
284 void reloadFromSelection(bool forceReload);
285
287 void captureSavedState();
288
293 void applyFormState(const QVariantMap& state);
294
296 void clearFormState();
301 bool hasValidAliasSelection() const;
302 WorkspaceStore* store_ = nullptr;
303 WorkspaceCommands* commands_ = nullptr;
304 WorkspaceSelection* selection_ = nullptr;
305 WorkspaceSelectors* selectors_ = nullptr;
306 QString currentOwnerId_;
307 QString name_;
308 QVariantList aliases_;
309 QString aliasInputText_;
310 int aliasIndex_ = -1;
311 QString savedName_;
312 QVariantList savedAliases_;
313 QString type_;
314 QString allocatableMode_ = QStringLiteral("mixed");
315 QVariantList selectedActorIds_;
316 QVariantList selectedPropertyIds_;
317 QString savedType_;
318 QString savedAllocatableMode_ = QStringLiteral("mixed");
319 QVariantList savedSelectedActorIds_;
320 QVariantList savedSelectedPropertyIds_;
321};
322
323} // namespace ui
void setSelectedPropertyIds(const QVariantList &value)
Replaces selected property ids for this contract.
void setName(const QString &value)
Updates the editable contract name.
void setAliasInputText(const QString &value)
Updates the current alias input text.
Q_INVOKABLE void addAlias(const QString &value)
Adds an alias to the contract form.
Q_INVOKABLE void clear()
Clears the current contract form without changing workspace data.
Q_INVOKABLE void requestRemoveSelectedAlias()
Removes the currently selected alias when possible.
void setType(const QString &value)
Updates the editable contract type.
Q_INVOKABLE void setPropertySelected(const QString &propertyId, bool selected)
Toggles a property link in the current form.
void setSelectedActorIds(const QVariantList &value)
Replaces selected actor ids for this contract.
ContractViewModel(WorkspaceStore *store, WorkspaceCommands *commands, WorkspaceSelection *selection, WorkspaceSelectors *selectors, QObject *parent=nullptr)
Creates the contract view model bound to workspace roles.
Q_INVOKABLE void selectPrimaryActor(const QString &actorId)
Selects the primary actor for the contract.
Q_INVOKABLE QString submit()
Creates or updates the current contract through workspace commands.
Q_INVOKABLE void deleteCurrent()
Deletes the selected contract through workspace commands.
Q_INVOKABLE void next()
Selects the next contract row.
QVariantList aliases() const
Returns editable contract aliases.
Q_INVOKABLE void selectContract(const QString &id)
Selects a contract for editing.
void setAliasIndex(int value)
Updates the selected alias index.
void setAliases(const QVariantList &value)
Replaces editable contract aliases.
Q_INVOKABLE bool canAddAlias(const QString &value) const
Checks whether an alias value can be added to the form.
QString aliasInputText() const
Returns the current alias input text.
int aliasIndex() const
Returns the selected alias index.
Q_INVOKABLE void previous()
Selects the previous contract row.
Q_INVOKABLE void enterCreateMode()
Enters create mode and clears the contract form.
QVariantList selectedPropertyIds
void setAllocatableMode(const QString &value)
Updates the editable allocatable mode.
Maps UI intent to core workspace writer commands.
Tracks the currently selected workspace entities.
Projects workspace store data into QML-facing read models.
Owns the current UI-side workspace snapshot and revision lifecycle.