FOSSredder 0.5.0
Loading...
Searching...
No Matches
BookingViewModel.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 BookingViewModel : public QObject {
25 Q_OBJECT
26 Q_PROPERTY(bool isCreateMode READ isCreateMode NOTIFY changed)
27 Q_PROPERTY(QString statementName READ statementName WRITE setStatementName
28 NOTIFY changed)
29 Q_PROPERTY(QString transactionName READ transactionName WRITE
31 Q_PROPERTY(QString transactionBookingDate READ transactionBookingDate WRITE
33 Q_PROPERTY(QString transactionValuta READ transactionValuta WRITE
35 Q_PROPERTY(QString transactionAmountText READ transactionAmountText WRITE
41 Q_PROPERTY(QVariantList propertyRows READ propertyRows NOTIFY changed)
42 Q_PROPERTY(
43 QVariantList selectedPropertyIds READ selectedPropertyIds NOTIFY changed)
45 NOTIFY changed)
46 Q_PROPERTY(QVariantList statementRows READ statementRows NOTIFY changed)
47 Q_PROPERTY(
49 Q_PROPERTY(
51 Q_PROPERTY(QVariantList actorDisplayRows READ actorDisplayRows NOTIFY changed)
52 Q_PROPERTY(
53 QVariantList contractDisplayRows READ contractDisplayRows NOTIFY changed)
54 Q_PROPERTY(int selectedActorIndex READ selectedActorIndex NOTIFY changed)
55 Q_PROPERTY(
57 Q_PROPERTY(
59 Q_PROPERTY(bool hasStatements READ hasStatements NOTIFY changed)
60 Q_PROPERTY(
62 Q_PROPERTY(bool canCreate READ canCreate NOTIFY changed)
63 Q_PROPERTY(bool canUpdate READ canUpdate NOTIFY changed)
64 Q_PROPERTY(bool canAddTransaction READ canAddTransaction NOTIFY changed)
66
67public:
72 explicit BookingViewModel(WorkspaceStore* store, WorkspaceCommands* commands,
73 WorkspaceSelection* selection,
74 WorkspaceSelectors* selectors,
75 QObject* parent = nullptr);
76
81 bool isCreateMode() const;
82
87 QString statementName() const;
88
93 void setStatementName(const QString& value);
94
99 QString transactionName() const;
100
105 void setTransactionName(const QString& value);
106
111 QString transactionBookingDate() const;
112
117 void setTransactionBookingDate(const QString& value);
118
123 QString transactionValuta() const;
124
129 void setTransactionValuta(const QString& value);
130
135 QString transactionAmountText() const;
136
141 void setTransactionAmountText(const QString& value);
142
147 int transactionStatusIndex() const;
148
153 void setTransactionStatusIndex(int index);
154
159 bool transactionAllocatable() const;
160
165 void setTransactionAllocatable(bool value);
166
171 QVariantList propertyRows() const;
172
177 QVariantList selectedPropertyIds() const;
178
183 QVariantList transactionStatusOptions() const;
184
189 QVariantList statementRows() const;
190
195 QString selectedStatementId() const;
196
201 QString selectedTransactionId() const;
202
207 QVariantList actorDisplayRows() const;
208
213 QVariantList contractDisplayRows() const;
214
219 int selectedActorIndex() const;
220
225 int selectedContractIndex() const;
226
231 QString transactionInfoText() const;
232
237 bool hasStatements() const;
238
243 bool hasMultipleTransactions() const;
244
249 bool canCreate() const;
250
255 bool canUpdate() const;
256
261 bool canAddTransaction() const;
262
267 bool canDeleteTransaction() const;
268
272 Q_INVOKABLE void resetCreateState();
273
277 Q_INVOKABLE void previousStatement();
278
282 Q_INVOKABLE void nextStatement();
283
287 Q_INVOKABLE void previousTransaction();
288
292 Q_INVOKABLE void nextTransaction();
293
297 Q_INVOKABLE void addTransactionAfterCurrent();
298
302 Q_INVOKABLE void deleteCurrentTransaction();
303
309 Q_INVOKABLE void setPropertySelected(const QString& propertyId,
310 bool selected);
311
316 Q_INVOKABLE void selectActorIndex(int index);
317
322 Q_INVOKABLE void selectContractIndex(int index);
323
328 Q_INVOKABLE void selectStatement(const QString& statementId);
329
335 Q_INVOKABLE void selectTransaction(const QString& statementId,
336 const QString& transactionId);
337
343 Q_INVOKABLE QString submit();
344
348 Q_INVOKABLE void updateCurrent();
349
353 Q_INVOKABLE void deleteCurrentStatement();
354
355signals:
356 void changed();
357
358private:
363 QVariantMap emptyTransaction() const;
364
370 QVariantMap normalizeTransaction(const QVariantMap& tx) const;
371
376 QVariantMap transactionData() const;
377
382 void setTransactionData(const QVariantMap& value);
383
389 QVariant transactionField(const QString& key) const;
390
396 void setTransactionField(const QString& key, const QVariant& value);
397
402 void applyTransactionFormChange(const QVariantMap& changes);
403
410 int selectedIndexFor(const QVariantList& rows, const QString& id) const;
411
416 QVariantMap editTransactionState() const;
417
423 QVariantMap transactionById(const QString& txId) const;
424
430 QVariantList statementTransactionRows(const QString& statementId) const;
431
437 QVariantMap normalizedTransactionState(const QVariantMap& data) const;
438
442 void captureEditState();
443
447 void rememberSelectedTransaction();
448
454 QString transactionIdForStatement(const QString& statementId) const;
455
460 bool ensureSelectedTransactionForStatement();
461
465 void syncCurrentCreateTransaction();
466
470 void syncEditState();
471
475 void bindSignals();
476
477 WorkspaceStore* store_ = nullptr;
478 WorkspaceCommands* commands_ = nullptr;
479 WorkspaceSelection* selection_ = nullptr;
480 WorkspaceSelectors* selectors_ = nullptr;
481 QString createStatementName_;
482 QVariantList createTransactionStates_;
483 int createTransactionIndex_ = 0;
484 QString editStatementName_;
485 QVariantMap editTransactionData_;
486 int editTransactionIndex_ = -1;
487 QVariantList editTransactionOrderIds_;
488 QString savedEditStatementName_;
489 QVariantMap savedEditTransactionState_;
490 QVariantMap currentTransactionFormState_;
491 QVariantMap lastTransactionIdByStatementId_;
492};
493
494} // namespace ui
Q_INVOKABLE void setPropertySelected(const QString &propertyId, bool selected)
Updates whether a property is selected for the current transaction.
QVariantList selectedPropertyIds
void setTransactionAllocatable(bool value)
Updates the current transaction allocatable flag.
BookingViewModel(WorkspaceStore *store, WorkspaceCommands *commands, WorkspaceSelection *selection, WorkspaceSelectors *selectors, QObject *parent=nullptr)
Creates the booking view model backed by workspace roles.
Q_INVOKABLE QString submit()
Creates a statement and its transaction form states through workspace.
Q_INVOKABLE void updateCurrent()
Updates the selected statement and transaction through workspace.
QVariantList actorDisplayRows
Q_INVOKABLE void nextStatement()
Selects the next statement or the create form.
Q_INVOKABLE void addTransactionAfterCurrent()
Adds a transaction after the current transaction.
Q_INVOKABLE void previousTransaction()
Selects the previous transaction in the current statement.
Q_INVOKABLE void selectActorIndex(int index)
Selects an actor from the actor dropdown.
Q_INVOKABLE void deleteCurrentTransaction()
Deletes the current transaction when at least one remains.
void setTransactionName(const QString &value)
Updates the current transaction name field.
Q_INVOKABLE void selectStatement(const QString &statementId)
Selects a statement from the sidebar.
void setTransactionStatusIndex(int index)
Updates the current transaction status from an option index.
Q_INVOKABLE void resetCreateState()
Clears the create form and creates a single empty transaction state.
Q_INVOKABLE void selectContractIndex(int index)
Selects a contract from the contract dropdown.
void setTransactionAmountText(const QString &value)
Updates the current amount field.
Q_INVOKABLE void previousStatement()
Selects the previous statement or the create form.
void setTransactionBookingDate(const QString &value)
Updates the current transaction booking date field.
QVariantList transactionStatusOptions
QVariantList contractDisplayRows
Q_INVOKABLE void nextTransaction()
Selects the next transaction in the current statement.
Q_INVOKABLE void deleteCurrentStatement()
Deletes the selected statement through workspace.
void setStatementName(const QString &value)
Updates the statement name shown in the form.
void setTransactionValuta(const QString &value)
Updates the current transaction valuta field.
Q_INVOKABLE void selectTransaction(const QString &statementId, const QString &transactionId)
Selects a transaction from the sidebar.
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.