FOSSredder 0.5.0
Loading...
Searching...
No Matches
AnnualViewModel.h
Go to the documentation of this file.
1
5
6#pragma once
7
8#include <QObject>
9#include <QString>
10#include <QStringList>
11#include <QVariantList>
12#include <QVariantMap>
13#include <qqmlintegration.h>
14
15namespace ui {
16
17class AnnualWorkflow;
21class WorkspaceStore;
22
27class AnnualViewModel : public QObject {
28 Q_OBJECT
29 QML_NAMED_ELEMENT(AnnualViewModel)
30
31 Q_PROPERTY(bool isEdit READ isEdit NOTIFY changed)
32 Q_PROPERTY(QVariantList annualRows READ annualRows NOTIFY changed)
33 Q_PROPERTY(QString selectedAnnualId READ selectedAnnualId NOTIFY changed)
34 Q_PROPERTY(QString name READ name WRITE setName NOTIFY changed)
35 Q_PROPERTY(int year READ year WRITE setYear NOTIFY changed)
36 Q_PROPERTY(QVariantList availableAnalysisRows READ availableAnalysisRows
37 NOTIFY changed)
38 Q_PROPERTY(QVariantList assignedAnalysisRows READ assignedAnalysisRows NOTIFY
39 changed)
40 Q_PROPERTY(int contentIndex READ contentIndex NOTIFY changed)
41 Q_PROPERTY(
42 QVariantList annualTransactions READ annualTransactions NOTIFY changed)
43 Q_PROPERTY(
44 QVariantList transactionSections READ transactionSections NOTIFY changed)
45 Q_PROPERTY(QVariantList verificationRows READ verificationRows NOTIFY changed)
46 Q_PROPERTY(QString statusSummaryText READ statusSummaryText NOTIFY changed)
47 Q_PROPERTY(bool canSubmit READ canSubmit NOTIFY changed)
48 Q_PROPERTY(bool hasRows READ hasRows NOTIFY changed)
49 Q_PROPERTY(bool hasChanges READ hasChanges NOTIFY changed)
50
51public:
56 explicit AnnualViewModel(QObject* parent = nullptr);
57
62 WorkspaceSelection* selection,
63 WorkspaceSelectors* selectors);
64
70
75 bool isEdit() const;
76
81 QVariantList annualRows() const;
82
87 QString selectedAnnualId() const;
88
93 QString name() const {
94 return name_;
95 }
96
101 void setName(const QString& value);
102
107 int year() const noexcept {
108 return year_;
109 }
110
115 void setYear(int value);
116
121 QVariantList analysisIds() const;
122
127 QVariantList availableAnalysisRows() const {
128 return availableAnalysisRows_;
129 }
130
135 QVariantList assignedAnalysisRows() const {
136 return assignedAnalysisRows_;
137 }
138
143 int contentIndex() const noexcept {
144 return contentIndex_;
145 }
146
151 QVariantList annualTransactions() const {
152 return annualTransactions_;
153 }
154
159 QVariantList transactionSections() const;
160
165 QVariantList verificationRows() const;
166
171 QString statusSummaryText() const;
172
177 bool canSubmit() const noexcept {
178 return year_ > 0;
179 }
180
185 bool hasRows() const;
186
191 bool hasChanges() const;
192
196 Q_INVOKABLE void refreshFromSelection();
197
201 Q_INVOKABLE void resetCreateState();
202
206 Q_INVOKABLE void submitCreate();
207
211 Q_INVOKABLE void submitUpdate();
212
216 Q_INVOKABLE void deleteCurrent();
217
222 Q_INVOKABLE void navigate(int delta);
223
228 Q_INVOKABLE void selectAnnual(const QString& id);
229
233 Q_INVOKABLE void toggleContent();
234
239 Q_INVOKABLE void stepYear(int delta);
240
245 Q_INVOKABLE void addAvailableAnalysisAtIndex(int index);
246
251 Q_INVOKABLE void removeAnalysis(const QString& id);
252
258 Q_INVOKABLE void setAnalysisExportFormat(const QString& id,
259 const QString& exportFormat);
260
265 Q_INVOKABLE void toggleTransactionSection(const QString& key);
266
267signals:
268 void changed();
269
270private:
276 QStringList normalizedAnalysisIds(const QVariant& values) const;
282 QString analysisIdFromVariant(const QVariant& value) const;
288 QVariantMap annualRowById(const QString& id) const;
294 QVariantMap analysisRowById(const QString& id) const;
300 QVariantMap normalizeAnalysisRow(const QVariant& value) const;
305 QVariantList normalizedAnalysisRows() const;
310 QVariantList buildAssignedAnalysisRows() const;
315 QVariantList buildAvailableAnalysisRows() const;
321 QVariantMap augmentAnalysisRow(const QVariantMap& row) const;
327 QVariantList exportOptionsForType(const QString& type) const;
334 int exportFormatIndex(const QVariantList& options,
335 const QString& exportFormat) const;
342 QString normalizedExportFormat(const QString& value,
343 const QString& type) const;
348 int defaultYear() const;
352 void loadCreateState();
356 void loadSelectedAnnual();
360 void refreshAnalysisSelectionRows();
364 void rebuildAnnualResultState();
369 void applyAnnualResult(const QVariantMap& result);
373 void captureSavedState();
378 void setAnalysisIds(const QStringList& ids);
383 QVariantMap emptyIssues() const;
388 QVariantMap emptyStatusMetrics() const;
394 QVariantList rowsFromResultBucket(const QVariantList& rows) const;
400 QVariantMap transactionRow(const QVariantMap& source) const;
408 QVariantMap transactionSection(const QString& key, const QString& title,
409 const QVariantList& rows) const;
415 bool isTransactionSectionExpanded(const QString& key) const;
420 int workspaceRevision() const;
424 void bindWorkspaceRoles(WorkspaceStore* store, WorkspaceCommands* commands,
425 WorkspaceSelection* selection,
426 WorkspaceSelectors* selectors);
430 void emitChanged();
431
432 WorkspaceStore* store_ = nullptr;
433 WorkspaceCommands* commands_ = nullptr;
434 WorkspaceSelection* selection_ = nullptr;
435 WorkspaceSelectors* selectors_ = nullptr;
436 AnnualWorkflow* annualWorkflow_ = nullptr;
437 QString name_;
438 int year_ = 0;
439 QStringList analysisIds_;
440 QVariantList availableAnalysisRows_;
441 QVariantList assignedAnalysisRows_;
442 int contentIndex_ = 0;
443 QVariantMap verificationIssues_;
444 QVariantMap statusMetrics_;
445 QVariantList annualTransactions_;
446 QVariantMap annualTransactionGroups_;
447 QVariantMap sectionExpanded_;
448 QString savedName_;
449 int savedYear_ = 0;
450 QStringList savedAnalysisIds_;
451 QString lastPreviewAnnualId_;
452 int lastPreviewYear_ = 0;
453 QStringList lastPreviewAnalysisIds_;
454 int lastPreviewRevision_ = -1;
455 bool analysisMetadataDirty_ = false;
456};
457
458} // namespace ui
void setYear(int value)
Updates the selected annual year.
void setAnnualWorkflow(AnnualWorkflow *value)
Sets the workflow used for annual computation.
Q_INVOKABLE void submitCreate()
Creates an annual through workspace.
QVariantList annualRows
Q_INVOKABLE void submitUpdate()
Updates the selected annual through workspace.
Q_INVOKABLE void setAnalysisExportFormat(const QString &id, const QString &exportFormat)
Updates export format for an assigned analysis.
QVariantList assignedAnalysisRows
QVariantList availableAnalysisRows
Q_INVOKABLE void navigate(int delta)
Navigates between annual rows.
Q_INVOKABLE void stepYear(int delta)
Steps the selected year by a relative delta.
bool canSubmit() const noexcept
Returns whether the current annual can be submitted.
QVariantList analysisIds() const
Returns ids of analyses assigned to the annual.
Q_INVOKABLE void selectAnnual(const QString &id)
Selects an annual row.
int contentIndex() const noexcept
Returns the active annual content stack index.
QVariantList assignedAnalysisRows() const
Returns analyses assigned to the annual.
QVariantList verificationRows
Q_INVOKABLE void addAvailableAnalysisAtIndex(int index)
Adds an available analysis by row index.
Q_INVOKABLE void removeAnalysis(const QString &id)
Removes an analysis from the annual.
Q_INVOKABLE void toggleTransactionSection(const QString &key)
Toggles expansion state for a transaction section.
AnnualViewModel(QObject *parent=nullptr)
Creates the annual view model.
QVariantList availableAnalysisRows() const
Returns analyses available for assignment.
int year() const noexcept
Returns the selected annual year.
void setName(const QString &value)
Updates the annual name field.
QVariantList annualTransactions() const
Returns annual transaction preview rows.
Q_INVOKABLE void refreshFromSelection()
Reloads create or edit state from the workspace selection.
Q_INVOKABLE void toggleContent()
Toggles between annual analysis assignment and transaction preview.
QVariantList transactionSections
void setWorkspaceRoles(WorkspaceStore *store, WorkspaceCommands *commands, WorkspaceSelection *selection, WorkspaceSelectors *selectors)
Sets workspace roles used for annual rows, selection and mutations.
QVariantList annualTransactions
Q_INVOKABLE void deleteCurrent()
Deletes the selected annual through workspace.
Q_INVOKABLE void resetCreateState()
Resets the create form to defaults.
Coordinates annual computation for UI states.
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.