FOSSredder 0.5.0
Loading...
Searching...
No Matches
AnalysisViewModel.h
Go to the documentation of this file.
1
5
6#pragma once
7
8#include <QObject>
9#include <QString>
10#include <QTimer>
11#include <QVariantList>
12#include <QVariantMap>
13#include <qqmlintegration.h>
14
15namespace ui {
16
18class Settings;
22class WorkspaceStore;
23
28class AnalysisViewModel : public QObject {
29 Q_OBJECT
30 QML_NAMED_ELEMENT(AnalysisViewModel)
31
32 Q_PROPERTY(bool isEdit READ isEdit NOTIFY changed)
33 Q_PROPERTY(QVariantList analysisRows READ analysisRows NOTIFY changed)
34 Q_PROPERTY(QString selectedAnalysisId READ selectedAnalysisId NOTIFY changed)
35 Q_PROPERTY(QString name READ name WRITE setName NOTIFY changed)
36 Q_PROPERTY(int mainTypeIndex READ mainTypeIndex WRITE setMainTypeIndex NOTIFY
37 changed)
38 Q_PROPERTY(int plotSubtypeIndex READ plotSubtypeIndex WRITE
40 Q_PROPERTY(QVariantList plotTypeOptions READ plotTypeOptions CONSTANT)
41 Q_PROPERTY(
42 QVariantList exportFormatOptions READ exportFormatOptions NOTIFY changed)
43 Q_PROPERTY(int exportFormatIndex READ exportFormatIndex WRITE
45 Q_PROPERTY(bool includeAdjustments READ includeAdjustments WRITE
48 NOTIFY changed)
49 Q_PROPERTY(int filterContentIndex READ filterContentIndex NOTIFY changed)
51 NOTIFY changed)
52 Q_PROPERTY(int dateModeIndex READ dateModeIndex WRITE setDateModeIndex NOTIFY
53 changed)
54 Q_PROPERTY(QString yearValue READ yearValue WRITE setYearValue NOTIFY changed)
55 Q_PROPERTY(QString dateFromValue READ dateFromValue WRITE setDateFromValue
56 NOTIFY changed)
57 Q_PROPERTY(
58 QString dateToValue READ dateToValue WRITE setDateToValue NOTIFY changed)
59 Q_PROPERTY(
60 QVariantList propertyFilterRows READ propertyFilterRows NOTIFY changed)
61 Q_PROPERTY(QVariantList contractTypeRows READ contractTypeRows NOTIFY changed)
62 Q_PROPERTY(QVariantList selectedPropertyIds READ selectedPropertyIds WRITE
64 Q_PROPERTY(QVariantList selectedContractTypes READ selectedContractTypes WRITE
66 Q_PROPERTY(QString allocatableMode READ allocatableMode WRITE
69 NOTIFY changed)
71 NOTIFY changed)
72 Q_PROPERTY(QString previewTransactionCountText READ
74 Q_PROPERTY(
78 Q_PROPERTY(QString adjustmentName READ adjustmentName WRITE setAdjustmentName
79 NOTIFY changed)
80 Q_PROPERTY(QString adjustmentPercentText READ adjustmentPercentText WRITE
83 Q_PROPERTY(
85 Q_PROPERTY(
86 QVariantList tableContractTypes READ tableContractTypes NOTIFY changed)
87 Q_PROPERTY(
88 QVariantList tablePropertyRows READ tablePropertyRows NOTIFY changed)
89 Q_PROPERTY(double tableGrandTotal READ tableGrandTotal NOTIFY changed)
90 Q_PROPERTY(bool canSubmit READ canSubmit NOTIFY changed)
91 Q_PROPERTY(bool hasRows READ hasRows NOTIFY changed)
92
93public:
98 explicit AnalysisViewModel(QObject* parent = nullptr);
99
104 WorkspaceSelection* selection,
105 WorkspaceSelectors* selectors);
106
112
117 void setSettings(Settings* value);
118
123 bool isEdit() const;
124
129 QString name() const {
130 return name_;
131 }
132
137 void setName(const QString& value);
138
143 int mainTypeIndex() const noexcept {
144 return mainTypeIndex_;
145 }
146
151 void setMainTypeIndex(int value);
152
157 int plotSubtypeIndex() const noexcept {
158 return plotSubtypeIndex_;
159 }
160
165 void setPlotSubtypeIndex(int value);
166
171 QVariantList plotTypeOptions() const;
172
177 QVariantList exportFormatOptions() const;
178
183 int exportFormatIndex() const;
184
189 void setExportFormatIndex(int value);
190
195 bool includeAdjustments() const noexcept {
196 return includeAdjustments_;
197 }
198
203 void setIncludeAdjustments(bool value);
204
209 bool filterEditMode() const noexcept {
210 return filterEditMode_;
211 }
212
217 void setFilterEditMode(bool value);
218
223 int filterContentIndex() const noexcept {
224 return filterContentIndex_;
225 }
226
231 int dateFieldIndex() const noexcept {
232 return dateFieldIndex_;
233 }
234
239 void setDateFieldIndex(int value);
240
245 int dateModeIndex() const noexcept {
246 return dateModeIndex_;
247 }
248
253 void setDateModeIndex(int value);
254
259 QString yearValue() const {
260 return yearValue_;
261 }
262
267 void setYearValue(const QString& value);
268
273 QString dateFromValue() const {
274 return dateFromValue_;
275 }
276
281 void setDateFromValue(const QString& value);
282
287 QString dateToValue() const {
288 return dateToValue_;
289 }
290
295 void setDateToValue(const QString& value);
296
301 QVariantList propertyFilterRows() const {
302 return propertyFilterRows_;
303 }
304
309 QVariantList contractTypeRows() const {
310 return contractTypeRows_;
311 }
312
317 QVariantList selectedPropertyIds() const {
318 return selectedPropertyIds_;
319 }
320
325 void setSelectedPropertyIds(const QVariantList& value);
326
331 QVariantList selectedContractTypes() const {
332 return selectedContractTypes_;
333 }
334
339 void setSelectedContractTypes(const QVariantList& value);
340
345 QString allocatableMode() const {
346 return allocatableMode_;
347 }
348
353 void setAllocatableMode(const QString& value);
354
359 QVariantList previewTransactionRows() const;
360
365 QString previewStatementCountText() const;
366
371 QString previewTransactionCountText() const;
372
377 QString previewAmountSumText() const;
378
383 QVariantList selectedAdjustmentTxIds() const {
384 return selectedAdjustmentTxIds_;
385 }
386
391 void setSelectedAdjustmentTxIds(const QVariantList& value);
392
397 QString adjustmentName() const {
398 return adjustmentName_;
399 }
400
405 void setAdjustmentName(const QString& value);
406
411 QString adjustmentPercentText() const {
412 return adjustmentPercentText_;
413 }
414
419 void setAdjustmentPercentText(const QString& value);
420
425 bool currentResultIsTable() const;
426
431 QString renderedPreviewSource() const {
432 return renderedPreviewSource_;
433 }
434
439 QVariantList tableContractTypes() const {
440 return tableContractTypes_;
441 }
442
447 QVariantList tablePropertyRows() const {
448 return tablePropertyRows_;
449 }
450
455 double tableGrandTotal() const noexcept {
456 return tableGrandTotal_;
457 }
458
463 bool canSubmit() const;
464
469 bool hasRows() const;
470
474 Q_INVOKABLE void refreshFromSelection();
475
479 Q_INVOKABLE void applySelectedAdjustment();
480
486 Q_INVOKABLE void setPropertySelected(const QString& id, bool selected);
487
491 Q_INVOKABLE void selectAllProperties();
492
496 Q_INVOKABLE void selectNoProperties();
497
503 Q_INVOKABLE void setContractTypeSelected(const QString& type, bool selected);
504
508 Q_INVOKABLE void selectAllContractTypes();
509
513 Q_INVOKABLE void selectNoContractTypes();
514
520 Q_INVOKABLE void setAdjustmentTransactionSelected(const QString& id,
521 bool selected);
522
527 Q_INVOKABLE void setAllocatableModeIndex(int index);
528
532 Q_INVOKABLE void toggleFilterContent();
533
537 Q_INVOKABLE void clearFilters();
538
542 Q_INVOKABLE void submitCreate();
543
547 Q_INVOKABLE void submitUpdate();
548
552 Q_INVOKABLE void deleteCurrent();
553
558 Q_INVOKABLE void navigate(int delta);
559
564 Q_INVOKABLE void selectAnalysis(const QString& id);
565
566signals:
567 void changed();
568
569private:
574 QString selectedAnalysisId() const;
579 QVariantList analysisRows() const;
585 QVariantMap analysisRowById(const QString& id) const;
590 QString uiType() const;
595 QString strategyType() const;
600 QString currentDateField() const;
605 QString currentDateMode() const;
610 QString defaultAnalysisDateMode() const;
615 QString defaultAnalysisYear() const;
621 QStringList stringList(const QVariantList& values) const;
626 QVariantList allPropertyIds() const;
631 QVariantList allContractTypes() const;
639 QVariantList pruneSelection(const QVariantList& values,
640 const QVariantList& availableRows,
641 const QString& idField = {}) const;
649 bool isAllSelected(const QVariantList& selectedIds,
650 const QVariantList& availableRows,
651 const QString& idField = {}) const;
656 QStringList effectiveSelectedPropertyIds() const;
662 QStringList effectiveSelectedContractTypes() const;
667 QString currentFilterSpec() const;
672 QVariantMap currentAnalysisConfig() const;
677 QVariantMap currentAnalysisFilter() const;
684 QString normalizedExportFormat(const QString& value,
685 const QString& uiType) const;
690 void setExportFormat(const QString& value);
695 QString currentResultType() const;
701 QString
702 renderedPreviewSourceFromResult(const QVariantMap& analysisResult) const;
706 void refreshFilterRows();
710 void resetAdjustments();
714 void refreshAdjustmentAmountsFromSelection();
718 void refreshAnalysisResult();
722 void refreshPreview();
726 void requestPreviewRefresh();
730 void loadSelectedAnalysis();
734 void loadCreateState();
738 void updateResultState();
742 void emitChanged();
746 void bindWorkspaceRoles(WorkspaceStore* store, WorkspaceCommands* commands,
747 WorkspaceSelection* selection,
748 WorkspaceSelectors* selectors);
749
750 WorkspaceStore* store_ = nullptr;
751 WorkspaceCommands* commands_ = nullptr;
752 WorkspaceSelection* selection_ = nullptr;
753 WorkspaceSelectors* selectors_ = nullptr;
754 AnalysisWorkflow* analysisWorkflow_ = nullptr;
755 Settings* settings_ = nullptr;
756 QTimer previewDebounce_;
757
758 QString name_;
759 int mainTypeIndex_ = 0;
760 int plotSubtypeIndex_ = 0;
761 QString exportFormat_;
762 bool includeAdjustments_ = true;
763 QVariantList snapshotTransactions_;
764 bool filterEditMode_ = true;
765 int filterContentIndex_ = 0;
766 int dateFieldIndex_ = 0;
767 int dateModeIndex_ = 0;
768 QString yearValue_;
769 QString dateFromValue_;
770 QString dateToValue_;
771 QVariantList propertyFilterRows_;
772 QVariantList contractTypeRows_;
773 QVariantList selectedPropertyIds_;
774 QVariantList selectedContractTypes_;
775 QString allocatableMode_ = QStringLiteral("all");
776 QVariantList previewTransactions_;
777 QVariantMap previewMetrics_;
778 QVariantList selectedAdjustmentTxIds_;
779 QVariantMap adjustmentAmountsById_;
780 QString adjustmentName_;
781 QString adjustmentPercentText_;
782 QString activeResultType_ = QStringLiteral("plot");
783 QVariantMap currentAnalysisResult_;
784 QString renderedPreviewSource_;
785 int renderedPreviewRevision_ = 0;
786 QVariantList tableContractTypes_;
787 QVariantList tablePropertyRows_;
788 double tableGrandTotal_ = 0.0;
789};
790
791} // namespace ui
void setYearValue(const QString &value)
Updates the year filter field.
QString adjustmentPercentText() const
Returns the adjustment percent field.
Q_INVOKABLE void selectAnalysis(const QString &id)
Selects an analysis row.
QVariantList selectedContractTypes() const
Returns selected contract type keys for filtering.
void setAdjustmentName(const QString &value)
Updates the adjustment name field.
QVariantList exportFormatOptions
void setDateFromValue(const QString &value)
Updates the start date filter field.
Q_INVOKABLE void selectAllContractTypes()
Selects all available contract types.
void setIncludeAdjustments(bool value)
Updates whether adjustment amounts are included.
int dateModeIndex() const noexcept
Returns the selected date mode index.
void setDateModeIndex(int value)
Updates the selected date mode index.
void setAdjustmentPercentText(const QString &value)
Updates the adjustment percent field.
void setSelectedPropertyIds(const QVariantList &value)
Updates selected property ids for filtering.
void setSelectedContractTypes(const QVariantList &value)
Updates selected contract type keys for filtering.
int filterContentIndex() const noexcept
Returns the active filter content stack index.
Q_INVOKABLE void selectAllProperties()
Selects all available properties.
void setAllocatableMode(const QString &value)
Updates the selected allocatable filter mode.
QVariantList contractTypeRows() const
Returns contract type rows for the contract type filter.
QString dateToValue() const
Returns the end date filter field.
Q_INVOKABLE void selectNoProperties()
Clears the property selection.
QVariantList selectedPropertyIds
Q_INVOKABLE void navigate(int delta)
Navigates between analyses.
void setFilterEditMode(bool value)
Updates whether filter editing is shown in create mode.
bool includeAdjustments() const noexcept
Returns whether adjustment amounts are included.
QVariantList tableContractTypes
int plotSubtypeIndex() const noexcept
Returns the selected plot subtype index.
void setName(const QString &value)
Updates the analysis name field.
Q_INVOKABLE void submitCreate()
Creates an analysis through workspace.
QVariantList selectedContractTypes
Q_INVOKABLE void setAllocatableModeIndex(int index)
Updates allocatable mode from a segmented control index.
QVariantList selectedAdjustmentTxIds
QVariantList propertyFilterRows
QString allocatableMode() const
Returns the selected allocatable filter mode.
QVariantList selectedAdjustmentTxIds() const
Returns transaction ids selected for adjustment.
void setSelectedAdjustmentTxIds(const QVariantList &value)
Updates transaction ids selected for adjustment.
void setPlotSubtypeIndex(int value)
Updates the selected plot subtype index.
void setDateFieldIndex(int value)
Updates the selected date field index.
void setSettings(Settings *value)
Sets the settings source used for analysis defaults.
Q_INVOKABLE void applySelectedAdjustment()
Applies the entered adjustment to selected preview transactions.
Q_INVOKABLE void setAdjustmentTransactionSelected(const QString &id, bool selected)
Updates whether a preview transaction is selected for adjustment.
QVariantList propertyFilterRows() const
Returns property rows for the analysis property filter.
void setExportFormatIndex(int value)
Updates the selected export format index.
bool filterEditMode() const noexcept
Returns whether filter editing is shown in create mode.
double tableGrandTotal() const noexcept
Returns the table grand total.
int dateFieldIndex() const noexcept
Returns the selected date field index.
QString previewTransactionCountText READ previewTransactionCountText
Q_INVOKABLE void setPropertySelected(const QString &id, bool selected)
Updates whether a property is selected for filtering.
AnalysisViewModel(QObject *parent=nullptr)
Creates the analysis view model.
QString adjustmentName() const
Returns the adjustment name field.
QString renderedPreviewSource() const
Returns the rendered plot preview image source.
void setAnalysisWorkflow(AnalysisWorkflow *value)
Sets the workflow used for analysis computation and rendering.
void setDateToValue(const QString &value)
Updates the end date filter field.
QVariantList tablePropertyRows() const
Returns table property rows.
Q_INVOKABLE void submitUpdate()
Updates the selected analysis through workspace.
QVariantList previewTransactionRows
Q_INVOKABLE void clearFilters()
Resets all filter fields and refreshes the preview.
Q_INVOKABLE void setContractTypeSelected(const QString &type, bool selected)
Updates whether a contract type is selected for filtering.
QVariantList selectedPropertyIds() const
Returns selected property ids for filtering.
Q_INVOKABLE void selectNoContractTypes()
Clears the contract type selection.
QVariantList tableContractTypes() const
Returns table column contract types.
int mainTypeIndex() const noexcept
Returns the selected main analysis type index.
Q_INVOKABLE void deleteCurrent()
Deletes the selected analysis through workspace.
QString dateFromValue() const
Returns the start date filter field.
Q_INVOKABLE void refreshFromSelection()
Reloads create or edit state from the workspace selection.
void setMainTypeIndex(int value)
Updates the selected main analysis type index.
QString yearValue() const
Returns the year filter field.
void setWorkspaceRoles(WorkspaceStore *store, WorkspaceCommands *commands, WorkspaceSelection *selection, WorkspaceSelectors *selectors)
Sets workspace roles used for analysis CRUD, rows and selection.
Q_INVOKABLE void toggleFilterContent()
Toggles between filter fields and transaction preview.
Coordinates analysis preview and computation use cases for UI state.
Stores and exposes globally persisted UI settings for settings-related views.
Definition Settings.h:19
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.