From 679389d80929b754016dbf4ec5be455dfd18317e Mon Sep 17 00:00:00 2001 From: extio1 Date: Tue, 28 May 2024 01:06:46 +0700 Subject: [PATCH] UP-20, UP-21 Copy and Paste commands added. Serialization of Compositor, SimpleCompositor added --- include/compositor/compositor.h | 33 +++++++++++++++++-- .../simple_compositor/simple_compositor.h | 23 +++++++++++-- include/document/document.h | 2 +- include/executor/command/copy.h | 4 ++- include/executor/command/paste.h | 5 +-- main.cpp | 5 +++ src/compositor/compositor.cpp | 3 ++ .../simple_compositor/simple_compositor.cpp | 4 +++ src/executor/CMakeLists.txt | 2 ++ src/executor/command/copy.cpp | 6 ++-- src/executor/command/paste.cpp | 13 ++++---- 11 files changed, 82 insertions(+), 18 deletions(-) diff --git a/include/compositor/compositor.h b/include/compositor/compositor.h index 9e1239e..b91b878 100644 --- a/include/compositor/compositor.h +++ b/include/compositor/compositor.h @@ -2,6 +2,8 @@ #define TEXT_EDITOR_COMPOSITOR_H_ #include +#include +#include #include "document/document.h" @@ -9,9 +11,20 @@ class Compositor { public: enum Alignment { LEFT, CENTER, RIGHT, JUSTIFIED }; - Compositor(int topIndent = 5, int bottomIndent = 10, int leftIndent = 3, - int rightIndent = 6, Alignment alignment = LEFT, - int lineSpacing = 5) { + Compositor() { + document = nullptr; + this->topIndent = 5; + this->bottomIndent = 10; + this->leftIndent = 3; + this->rightIndent = 6; + this->alignment = LEFT; + this->lineSpacing = 3; + } + + Compositor(int topIndent, int bottomIndent, int leftIndent, + int rightIndent, Alignment alignment, + int lineSpacing) { + document = nullptr; this->topIndent = topIndent; this->bottomIndent = bottomIndent; this->leftIndent = leftIndent; @@ -42,6 +55,20 @@ class Compositor { int rightIndent; Alignment alignment; int lineSpacing; + + private: + friend class boost::serialization::access; + template + void serialize(Archive &ar, const unsigned int version) + { + std::cout << "0 Compositor\n"; + ar & document; + ar & topIndent & bottomIndent & leftIndent; + ar & rightIndent & alignment & lineSpacing; + std::cout << "1 Compositor\n"; + } + }; +BOOST_CLASS_EXPORT_KEY(Compositor) #endif // TEXT_EDITOR_COMPOSITOR_H_ \ No newline at end of file diff --git a/include/compositor/simple_compositor/simple_compositor.h b/include/compositor/simple_compositor/simple_compositor.h index 54ca381..2806714 100644 --- a/include/compositor/simple_compositor/simple_compositor.h +++ b/include/compositor/simple_compositor/simple_compositor.h @@ -2,15 +2,22 @@ #define TEXT_EDITOR_SIMPLECOMPOSITOR_H_ #include +#include +#include +#include #include "compositor/compositor.h" #include "document/document.h" class SimpleCompositor : public Compositor { public: - explicit SimpleCompositor(int topIndent = 5, int bottomIndent = 10, - int leftIndent = 3, int rightIndent = 6, - Alignment alignment = LEFT, int lineSpacing = 5) + explicit SimpleCompositor() + : Compositor(5, 10, 3, 6, + LEFT, 5) {} + + explicit SimpleCompositor(int topIndent, int bottomIndent, + int leftIndent, int rightIndent, + Alignment alignment, int lineSpacing) : Compositor(topIndent, bottomIndent, leftIndent, rightIndent, alignment, lineSpacing) {} @@ -31,6 +38,16 @@ class SimpleCompositor : public Compositor { int GetNestedGlyphsHeight(Glyph::GlyphPtr& glyph); GlyphContainer::GlyphList CutAllCharacters(); + + friend class boost::serialization::access; + template + void serialize(Archive &ar, const unsigned int version) + { + std::cout << "0 SimpleCompositor\n"; + ar & boost::serialization::base_object(*this); + std::cout << "1 SimpleCompositor\n"; + } }; +BOOST_CLASS_EXPORT_KEY(SimpleCompositor) #endif // TEXT_EDITOR_SIMPLECOMPOSITOR_H_ \ No newline at end of file diff --git a/include/document/document.h b/include/document/document.h index 07cafa2..ae7c39e 100644 --- a/include/document/document.h +++ b/include/document/document.h @@ -105,7 +105,7 @@ class Document : public IDocument { { std::cout << "0 Document\n"; ar & boost::serialization::base_object(*this); - ar & pages; + ar & pages & currentPage & compositor; std::cout << "1 Document\n"; } }; diff --git a/include/executor/command/copy.h b/include/executor/command/copy.h index 0dbe667..cdaed04 100644 --- a/include/executor/command/copy.h +++ b/include/executor/command/copy.h @@ -8,7 +8,7 @@ class Copy : public Command { public: - explicit Copy(std::shared_ptr doc, Point& from, Point& to); + explicit Copy(std::shared_ptr doc, const Point& from, const Point& to); Copy(Copy&&) = default; Copy& operator=(Copy&&) = default; @@ -21,6 +21,8 @@ class Copy : public Command { private: std::shared_ptr doc; + Point from; + Point to; }; diff --git a/include/executor/command/paste.h b/include/executor/command/paste.h index 3d30588..fb2739d 100644 --- a/include/executor/command/paste.h +++ b/include/executor/command/paste.h @@ -8,7 +8,7 @@ class Paste : public ReversibleCommand { public: - explicit Paste(std::shared_ptr doc, Point& begin_with); + explicit Paste(std::shared_ptr doc, const Point& begin_with); Paste(Paste&&) = default; Paste& operator=(Paste&&) = default; @@ -22,7 +22,8 @@ class Paste : public ReversibleCommand { private: std::shared_ptr doc; - GlyphContainer::GlyphList pasted_glyphs; + Point begin_with; + Glyph::GlyphList pasted_glyphs; }; diff --git a/main.cpp b/main.cpp index cc7b7c1..97eeb39 100644 --- a/main.cpp +++ b/main.cpp @@ -13,6 +13,8 @@ #include "executor/command/remove_character.h" #include "executor/command/save_document.h" #include "executor/command/load_document.h" +#include "executor/command/copy.h" +#include "executor/command/paste.h" int main() { auto d = std::make_shared(std::make_shared()); @@ -40,5 +42,8 @@ int main() { controller->Do(std::make_shared(&document, "doc_save.file")); std::cout << "Loaded: " << document << "\n"; + controller->Do(std::make_shared(document, Point(3, 5), Point(43, 5))); + controller->Do(std::make_shared(document, Point(43, 5))); + return 0; } \ No newline at end of file diff --git a/src/compositor/compositor.cpp b/src/compositor/compositor.cpp index 56f97c1..bf9776d 100644 --- a/src/compositor/compositor.cpp +++ b/src/compositor/compositor.cpp @@ -1,4 +1,7 @@ +#include +#include #include "compositor/compositor.h" +BOOST_CLASS_EXPORT_IMPLEMENT(Compositor) #include diff --git a/src/compositor/simple_compositor/simple_compositor.cpp b/src/compositor/simple_compositor/simple_compositor.cpp index d300690..c631848 100644 --- a/src/compositor/simple_compositor/simple_compositor.cpp +++ b/src/compositor/simple_compositor/simple_compositor.cpp @@ -1,4 +1,8 @@ +#include +#include #include "compositor/simple_compositor/simple_compositor.h" +BOOST_CLASS_EXPORT_IMPLEMENT(SimpleCompositor) + #include diff --git a/src/executor/CMakeLists.txt b/src/executor/CMakeLists.txt index 5e68c94..3f8b009 100644 --- a/src/executor/CMakeLists.txt +++ b/src/executor/CMakeLists.txt @@ -6,6 +6,8 @@ set(sources "command/remove_character.cpp" "command/save_document.cpp" "command/load_document.cpp" + "command/copy.cpp" + "command/paste.cpp" ) add_library(${target} SHARED ${sources}) diff --git a/src/executor/command/copy.cpp b/src/executor/command/copy.cpp index 6799b8a..cef5299 100644 --- a/src/executor/command/copy.cpp +++ b/src/executor/command/copy.cpp @@ -1,9 +1,11 @@ #include "executor/command/copy.h" -Copy::Copy(std::shared_ptr doc, Point& from, Point& to){} +Copy::Copy(std::shared_ptr doc, const Point& from, const Point& to): + doc(doc),from(from), to(to) +{} void Copy::Execute(){ - + doc->SelectGlyphs(from, to); } Copy::~Copy() {} \ No newline at end of file diff --git a/src/executor/command/paste.cpp b/src/executor/command/paste.cpp index 258786e..e5bea25 100644 --- a/src/executor/command/paste.cpp +++ b/src/executor/command/paste.cpp @@ -1,15 +1,16 @@ #include "executor/command/paste.h" -Paste::Paste(std::shared_ptr doc, Point& begin_with){} +Paste::Paste(std::shared_ptr doc, const Point& begin_with): + doc(doc), begin_with(begin_with){} void Paste::Execute(){ - + pasted_glyphs = doc->PasteGlyphs(begin_with); } void Paste::Unexecute(){ - + for(auto gl : pasted_glyphs){ + doc->Remove(gl); + } } -Paste::~Paste(){ - -} +Paste::~Paste(){}