feat: initial commit
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
#pragma once
|
||||
|
||||
#include "model/Annotation.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QImage>
|
||||
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
namespace ws::model {
|
||||
|
||||
class EditorDocument : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit EditorDocument(QObject* parent = nullptr);
|
||||
|
||||
void set_base_image(const QImage& image);
|
||||
[[nodiscard]] const QImage& base_image() const;
|
||||
|
||||
void add_annotation(const Annotation& annotation);
|
||||
bool select_at(const QPointF& point);
|
||||
void clear_selection();
|
||||
bool move_selected_by(const QPointF& delta);
|
||||
bool update_annotation(const Annotation& annotation);
|
||||
bool delete_selected();
|
||||
|
||||
[[nodiscard]] const std::vector<Annotation>& annotations() const;
|
||||
[[nodiscard]] const Annotation* selected_annotation() const;
|
||||
[[nodiscard]] AnnotationStyle current_style() const;
|
||||
void set_current_style(const AnnotationStyle& style);
|
||||
|
||||
[[nodiscard]] bool can_undo() const;
|
||||
[[nodiscard]] bool can_redo() const;
|
||||
bool undo();
|
||||
bool redo();
|
||||
|
||||
[[nodiscard]] QImage render_to_image() const;
|
||||
[[nodiscard]] bool is_dirty() const;
|
||||
void mark_clean();
|
||||
|
||||
signals:
|
||||
void document_changed();
|
||||
void selection_changed();
|
||||
void history_changed();
|
||||
void dirty_changed(bool dirty);
|
||||
|
||||
private:
|
||||
struct Snapshot {
|
||||
std::vector<Annotation> annotations;
|
||||
std::optional<QUuid> selected;
|
||||
};
|
||||
|
||||
void push_undo_state();
|
||||
void emit_dirty_if_changed(bool previous_dirty);
|
||||
|
||||
[[nodiscard]] Annotation* find_annotation(const QUuid& id);
|
||||
[[nodiscard]] const Annotation* find_annotation(const QUuid& id) const;
|
||||
|
||||
QImage base_image_;
|
||||
std::vector<Annotation> annotations_;
|
||||
std::optional<QUuid> selected_id_;
|
||||
AnnotationStyle current_style_;
|
||||
std::vector<Snapshot> undo_stack_;
|
||||
std::vector<Snapshot> redo_stack_;
|
||||
bool dirty_ = false;
|
||||
};
|
||||
|
||||
} // namespace ws::model
|
||||
Reference in New Issue
Block a user