anpstudio 0.1.0
ANP Studio — Analytic Network Process desktop application
Loading...
Searching...
No Matches
document.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include <QObject>
9#include <QString>
10#include <QStringList>
11#include <QUndoStack>
12#include <memory>
13#include <vector>
14
15#include "anpcpp/network.hpp"
16
23class Document : public QObject {
24 Q_OBJECT
25public:
29 explicit Document(QObject* parent = nullptr);
30
32 [[nodiscard]] anpcpp::AnpNetwork& network();
34 [[nodiscard]] const anpcpp::AnpNetwork& network() const;
36 [[nodiscard]] anpcpp::AnpNetwork& root();
38 [[nodiscard]] const anpcpp::AnpNetwork& root() const;
39
41 [[nodiscard]] QUndoStack* undoStack() { return &undo_; }
42
44 [[nodiscard]] QString path() const { return path_; }
46 [[nodiscard]] bool isDirty() const { return dirty_; }
48 void setDirty(bool dirty);
49
51 void newNetwork(bool create_alts = true);
58 bool loadFromFile(const QString& path, QString* error = nullptr);
65 bool saveToFile(const QString& path, QString* error = nullptr);
66
68 void pushSubnet(const QString& nodeName);
70 void popSubnet();
72 void popToRoot();
77 void popToDepth(int depth);
79 [[nodiscard]] int subnetDepth() const;
81 [[nodiscard]] QStringList breadcrumb() const;
82
85
87 [[nodiscard]] QString selectedCluster() const { return selectedCluster_; }
89 [[nodiscard]] QString selectedNode() const { return selectedNode_; }
95 void setSelection(const QString& cluster, const QString& node);
96
98 [[nodiscard]] bool hasResults() const { return hasResults_; }
100 [[nodiscard]] bool resultsStale() const {
101 return hasResults_ && resultsStale_;
102 }
107
108signals:
112 void dirtyChanged(bool dirty);
114 void pathChanged(const QString& path);
118 void selectionChanged(const QString& cluster, const QString& node);
121
122private:
123 struct Frame {
124 anpcpp::AnpNetwork* net = nullptr;
125 QString hostNode;
126 };
127
128 void replaceRoot(std::unique_ptr<anpcpp::AnpNetwork> net);
129 void clearSelectionIfInvalid();
130
131 std::unique_ptr<anpcpp::AnpNetwork> root_;
132 std::vector<Frame> stack_;
133 QUndoStack undo_;
134 QString path_;
135 bool dirty_ = false;
136 QString selectedCluster_;
137 QString selectedNode_;
138 bool hasResults_ = false;
139 bool resultsStale_ = false;
140};
Owns the root anpcpp::AnpNetwork, undo stack, file path, and dirty flag.
Definition document.hpp:23
void setSelection(const QString &cluster, const QString &node)
Soft-persists structure selection across stages.
bool loadFromFile(const QString &path, QString *error=nullptr)
Loads a network from JSON file.
const anpcpp::AnpNetwork & root() const
Const overload of root.
void viewNetworkChanged()
Emitted when the active network view changes (subnet navigation).
int subnetDepth() const
void popToRoot()
Clears the subnet stack back to the root network.
void invalidateResults()
Marks results stale (or clears hasResults if never calculated).
void selectionChanged(const QString &cluster, const QString &node)
Emitted when soft selection changes.
void dirtyChanged(bool dirty)
Emitted when the dirty flag changes.
anpcpp::AnpNetwork & root()
bool saveToFile(const QString &path, QString *error=nullptr)
Saves the root network to JSON.
QUndoStack * undoStack()
Definition document.hpp:41
QString path() const
Definition document.hpp:44
void pushSubnet(const QString &nodeName)
Descends into a node's subnetwork for editing.
const anpcpp::AnpNetwork & network() const
Const overload of network.
void modelChanged()
Emitted when the model structure or data changes.
QString selectedCluster() const
Definition document.hpp:87
bool hasResults() const
Definition document.hpp:98
void setDirty(bool dirty)
Sets the dirty flag and emits dirtyChanged when it changes.
void popToDepth(int depth)
Pops the subnet stack to depth frames (1 = root only).
QString selectedNode() const
Definition document.hpp:89
void pathChanged(const QString &path)
Emitted when the file path changes.
void popSubnet()
Returns to the parent network in the subnet stack.
anpcpp::AnpNetwork & network()
void notifyChanged()
Marks the document dirty and emits modelChanged.
void resultsFreshnessChanged()
Emitted when calc freshness changes.
QStringList breadcrumb() const
void newNetwork(bool create_alts=true)
Replaces the model with a new empty network.
bool isDirty() const
Definition document.hpp:46
Document(QObject *parent=nullptr)
bool resultsStale() const
Definition document.hpp:100
void markResultsCurrent()
Marks results current after a successful Calculate.