anpstudio 0.4.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 <QByteArray>
9#include <QObject>
10#include <QString>
11#include <QStringList>
12#include <QUndoStack>
13#include <QVector>
14#include <memory>
15#include <vector>
16
17#include "anpcpp/network.hpp"
18
23 QString command;
24 QString html;
25 bool ok = false;
26};
27
32 QString name;
33 QVector<ResearcherCell> cells;
34};
35
44 QString formId;
45 QString title;
46 QString responderUrl;
47 QString editUrl;
48 QString createdAtIso; // Qt::ISODate
52 QStringList questionTags;
57 QStringList questionIds;
59 QStringList mappedTags;
60};
61
71class Document : public QObject {
72 Q_OBJECT
73public:
74 explicit Document(QObject* parent = nullptr);
75 ~Document() override;
76
77 [[nodiscard]] anpcpp::AnpNetwork& network();
78 [[nodiscard]] const anpcpp::AnpNetwork& network() const;
79 [[nodiscard]] anpcpp::AnpNetwork& root();
80 [[nodiscard]] const anpcpp::AnpNetwork& root() const;
81 [[nodiscard]] anpcpp::AnpNetwork* parentNetwork();
82 [[nodiscard]] const anpcpp::AnpNetwork* parentNetwork() const;
83
84 [[nodiscard]] QUndoStack* undoStack() { return &undo_; }
85
86 [[nodiscard]] QString path() const { return path_; }
87 [[nodiscard]] bool isDirty() const { return dirty_; }
88 void setDirty(bool dirty);
89
90 void newNetwork(bool create_alts = true);
91 bool loadFromFile(const QString& path, QString* error = nullptr);
92 bool saveToFile(const QString& path, QString* error = nullptr);
93 void clearPath();
94
96 [[nodiscard]] const QVector<ResearcherNotebook>& researcherNotebooks() const {
97 return researcherNotebooks_;
98 }
100 [[nodiscard]] int researcherActiveIndex() const {
101 return researcherActiveIndex_;
102 }
108 void setResearcherSession(QVector<ResearcherNotebook> notebooks,
109 int activeIndex);
112
114 [[nodiscard]] const QVector<LinkedGoogleForm>& linkedGoogleForms() const {
115 return linkedGoogleForms_;
116 }
120 void removeLinkedGoogleForm(const QString& formId);
122 [[nodiscard]] const LinkedGoogleForm* latestLinkedGoogleForm() const;
123
124 void pushSubnet(const QString& nodeName);
125 void popSubnet();
126 void popToRoot();
127 void popToDepth(int depth);
128 [[nodiscard]] int subnetDepth() const;
129 [[nodiscard]] QStringList breadcrumb() const;
130 [[nodiscard]] QStringList networkPathOptions() const;
131 [[nodiscard]] QString currentNetworkPath() const;
132 bool navigateToNetworkPath(const QString& path);
139 [[nodiscard]] anpcpp::AnpNetwork* networkAtPath(const QString& path) const;
140
141 void notifyChanged();
142 void flushModelChanged();
143
144 void setSuppressLayoutPersist(bool suppress) {
145 suppressLayoutPersist_ = suppress;
146 }
147 [[nodiscard]] bool suppressLayoutPersist() const {
148 return suppressLayoutPersist_;
149 }
150
151 [[nodiscard]] QString selectedCluster() const { return selectedCluster_; }
152 [[nodiscard]] QString selectedNode() const { return selectedNode_; }
153 void setSelection(const QString& cluster, const QString& node);
154
155 [[nodiscard]] bool hasResults() const { return hasResults_; }
156 [[nodiscard]] bool resultsStale() const {
157 return hasResults_ && resultsStale_;
158 }
159 void markResultsCurrent();
160 void invalidateResults();
161
162 // --- Multi-user judgment session -----------------------------------------
163
165 [[nodiscard]] bool hasParticipants() const {
166 return !root().participants().empty();
167 }
169 [[nodiscard]] const std::vector<anpcpp::JudgmentParticipant>& participants()
170 const {
171 return root().participants();
172 }
174 [[nodiscard]] const std::vector<anpcpp::JudgmentGroup>& judgmentGroups()
175 const {
176 return root().judgment_groups();
177 }
179 [[nodiscard]] anpcpp::JudgmentSession judgmentSession() const {
180 return root().judgment_session();
181 }
186 void setJudgmentSession(const anpcpp::JudgmentSession& session);
187
192 anpcpp::JudgmentParticipant& addParticipant(const QString& id,
193 const QString& name,
194 const QString& email = {});
196 void removeParticipant(const QString& id);
198 anpcpp::JudgmentGroup& setJudgmentGroup(const QString& id,
199 const QString& name,
200 const QStringList& memberIds);
202 void removeJudgmentGroup(const QString& id);
203
209 [[nodiscard]] QByteArray snapshotNetworkJson() const;
216 void applyNetworkJson(const QByteArray& bytes);
217
225
230 [[nodiscard]] QString activeParticipantId() const;
235 [[nodiscard]] bool judgmentReadOnly() const;
236
237signals:
240 void modelChanged();
241 void dirtyChanged(bool dirty);
242 void pathChanged(const QString& path);
243 void viewNetworkChanged();
244 void selectionChanged(const QString& cluster, const QString& node);
245 void resultsFreshnessChanged();
254
255private:
256 struct Frame {
257 anpcpp::AnpNetwork* net = nullptr;
258 QString hostNode;
259 };
260
261 void replaceRoot(std::unique_ptr<anpcpp::AnpNetwork> net);
262 void clearSelectionIfInvalid();
263 void queueModelChanged();
264 void emitViewSwitch();
265
266 struct ResearcherSessionData {
267 QVector<ResearcherNotebook> notebooks;
268 int activeIndex = 0;
269 };
270
271 [[nodiscard]] static ResearcherSessionData parseResearcherSession(
272 const QByteArray& fileBytes);
273 [[nodiscard]] static QVector<LinkedGoogleForm> parseLinkedGoogleForms(
274 const QByteArray& fileBytes);
275 [[nodiscard]] QByteArray buildFileBytes() const;
276 [[nodiscard]] bool researcherSessionIsTrivial() const;
277
278 std::unique_ptr<anpcpp::AnpNetwork> root_;
279 std::vector<Frame> stack_;
280 QUndoStack undo_;
281 QString path_;
282 bool dirty_ = false;
283 bool suppressLayoutPersist_ = false;
284 bool modelChangedQueued_ = false;
285 QString selectedCluster_;
286 QString selectedNode_;
287 bool hasResults_ = false;
288 bool resultsStale_ = false;
289 QVector<ResearcherNotebook> researcherNotebooks_;
290 int researcherActiveIndex_ = 0;
291 QVector<LinkedGoogleForm> linkedGoogleForms_;
292};
Owns the root anpcpp::AnpNetwork, undo stack, file path, and dirty flag.
Definition document.hpp:71
void rebuildEffectiveJudgments()
Rebuilds effective judgments from the root network downward.
const LinkedGoogleForm * latestLinkedGoogleForm() const
const std::vector< anpcpp::JudgmentParticipant > & participants() const
Definition document.hpp:169
void removeLinkedGoogleForm(const QString &formId)
Removes by form id.
bool judgmentReadOnly() const
anpcpp::AnpNetwork * networkAtPath(const QString &path) const
Returns the network at a breadcrumb path without changing the view.
void addLinkedGoogleForm(const LinkedGoogleForm &form)
Appends a linked form and marks dirty.
void sessionChanged()
Emitted when the judgment session scope or roster changes.
void removeParticipant(const QString &id)
Removes a participant and their judgment tables.
void applyNetworkJson(const QByteArray &bytes)
Replaces the root network from snapshotNetworkJson bytes.
void clearResearcherSession()
Clears Researcher notebooks without emitting session changed.
const QVector< ResearcherNotebook > & researcherNotebooks() const
Definition document.hpp:96
anpcpp::JudgmentGroup & setJudgmentGroup(const QString &id, const QString &name, const QStringList &memberIds)
Adds or updates a named group of participant ids.
void setJudgmentSession(const anpcpp::JudgmentSession &session)
Sets the session scope, rebuilds effective judgments on the root network, and marks the document dirt...
anpcpp::JudgmentSession judgmentSession() const
Definition document.hpp:179
void researcherSessionChanged()
Emitted when the Researcher session is replaced (load / new).
const std::vector< anpcpp::JudgmentGroup > & judgmentGroups() const
Definition document.hpp:174
void setResearcherSession(QVector< ResearcherNotebook > notebooks, int activeIndex)
Replaces the Researcher session (does not emit session changed).
void removeJudgmentGroup(const QString &id)
Removes a named group.
int researcherActiveIndex() const
Definition document.hpp:100
anpcpp::JudgmentParticipant & addParticipant(const QString &id, const QString &name, const QString &email={})
Adds (or renames, if id already exists) a participant.
void linkedFormsChanged()
Emitted when the linked Google Forms list changes.
const QVector< LinkedGoogleForm > & linkedGoogleForms() const
Definition document.hpp:114
QByteArray snapshotNetworkJson() const
Serializes the root ANP network only (no researcher / google_forms).
QString activeParticipantId() const
bool hasParticipants() const
Definition document.hpp:165
A Google Form created from this model (Studio extension; for reopen + import).
Definition document.hpp:43
QStringList questionTags
Judgment tags present on the form (for diagnostics / matching).
Definition document.hpp:52
QStringList mappedTags
Tags aligned with questionIds (includes respondent / email tags).
Definition document.hpp:59
QStringList questionIds
Forms questionIds parallel to mappedTags (identity + judgments).
Definition document.hpp:57
QString structureFingerprint
SHA-256 hex of sorted [anp:…] judgment tags at create time.
Definition document.hpp:50
One Researcher notebook cell persisted with the Studio document.
Definition document.hpp:22
One named Researcher notebook (independent cell history).
Definition document.hpp:31