66 lines
1.4 KiB
C++
66 lines
1.4 KiB
C++
#ifndef DOCUMENT_H
|
|
#define DOCUMENT_H
|
|
|
|
#include <QObject>
|
|
#include <QJsonObject>
|
|
|
|
class DesignerScene;
|
|
class QGraphicsItem;
|
|
class QUndoCommand;
|
|
class QUndoStack;
|
|
|
|
class Document : public QObject
|
|
{
|
|
Q_OBJECT
|
|
Q_PROPERTY(bool modified READ isModified NOTIFY modifiedChanged)
|
|
|
|
public:
|
|
explicit Document(QObject *parent = nullptr);
|
|
~Document();
|
|
|
|
// Serialization
|
|
bool save();
|
|
bool saveAs(const QString &filePath);
|
|
bool load(const QString &filePath);
|
|
|
|
// State
|
|
bool isModified() const;
|
|
QString filePath() const;
|
|
|
|
// Unified command entry point
|
|
void execute(QUndoCommand *cmd);
|
|
|
|
// Accessors (read-only, no ownership transfer)
|
|
DesignerScene *scene() const;
|
|
QUndoStack *undoStack() const;
|
|
|
|
// Reset to empty document
|
|
void clear();
|
|
|
|
// Called by selectors to mark dirty for non-undo operations
|
|
// (move, scale, rotate, edit-shape)
|
|
void markDirty();
|
|
|
|
signals:
|
|
void modifiedChanged(bool modified);
|
|
void filePathChanged(const QString &filePath);
|
|
void saved();
|
|
void loaded();
|
|
|
|
private:
|
|
void setModified(bool modified);
|
|
void setupNewScene();
|
|
|
|
// Serialization helpers
|
|
QJsonObject serializeItem(QGraphicsItem *item) const;
|
|
QGraphicsItem *deserializeItem(const QJsonObject &obj);
|
|
|
|
DesignerScene *m_pScene;
|
|
QUndoStack *m_pUndoStack;
|
|
bool m_bModified;
|
|
int m_nSavedIndex;
|
|
QString m_sFilePath;
|
|
};
|
|
|
|
#endif // DOCUMENT_H
|