From 9be122710d1b05d96b846211a3f80abfde5682ed Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 8 Jul 2021 01:25:04 +0300 Subject: [PATCH] Moved SaveState from Editor::BaseItem to Editor::NumberedItem. --- .../editor/scene/scene_item_base.cpp | 19 ++++++++++++++++-- .../editor/scene/scene_item_base.h | 9 +++++++-- .../editor/scene/scene_item_line.cpp | 20 +++++++++++++++++++ .../editor/scene/scene_item_line.h | 6 ++++++ 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/Telegram/SourceFiles/editor/scene/scene_item_base.cpp b/Telegram/SourceFiles/editor/scene/scene_item_base.cpp index 2db73c088a..cceff06896 100644 --- a/Telegram/SourceFiles/editor/scene/scene_item_base.cpp +++ b/Telegram/SourceFiles/editor/scene/scene_item_base.cpp @@ -60,6 +60,16 @@ bool NumberedItem::isUndidStatus() const { return _status == Status::Undid; } +void NumberedItem::save(SaveState state) { +} + +void NumberedItem::restore(SaveState state) { +} + +bool NumberedItem::hasState(SaveState state) const { + return false; +} + void NumberedItem::setStatus(Status status) { if (status != _status) { _status = status; @@ -416,13 +426,18 @@ void ItemBase::save(SaveState state) { } void ItemBase::restore(SaveState state) { - const auto &saved = (state == SaveState::Keep) ? _keeped : _saved; - if (!saved.zValue) { + if (!hasState(state)) { return; } + const auto &saved = (state == SaveState::Keep) ? _keeped : _saved; applyData(saved.data); setZValue(saved.zValue); setVisible(saved.visible); } +bool ItemBase::hasState(SaveState state) const { + const auto &saved = (state == SaveState::Keep) ? _keeped : _saved; + return saved.zValue; +} + } // namespace Editor diff --git a/Telegram/SourceFiles/editor/scene/scene_item_base.h b/Telegram/SourceFiles/editor/scene/scene_item_base.h index 5ea45267aa..bb16a8deaa 100644 --- a/Telegram/SourceFiles/editor/scene/scene_item_base.h +++ b/Telegram/SourceFiles/editor/scene/scene_item_base.h @@ -40,6 +40,10 @@ public: void setStatus(Status status); [[nodiscard]] bool isNormalStatus() const; [[nodiscard]] bool isUndidStatus() const; + + virtual void save(SaveState state); + virtual void restore(SaveState state); + virtual bool hasState(SaveState state) const; private: int _number = 0; Status _status = Status::Normal; @@ -73,8 +77,9 @@ public: void updateZoom(float64 zoom); - void save(SaveState state); - void restore(SaveState state); + bool hasState(SaveState state) const override; + void save(SaveState state) override; + void restore(SaveState state) override; protected: enum HandleType { None, diff --git a/Telegram/SourceFiles/editor/scene/scene_item_line.cpp b/Telegram/SourceFiles/editor/scene/scene_item_line.cpp index f193cd3fc1..9635cc1b0a 100644 --- a/Telegram/SourceFiles/editor/scene/scene_item_line.cpp +++ b/Telegram/SourceFiles/editor/scene/scene_item_line.cpp @@ -38,4 +38,24 @@ bool ItemLine::collidesWithPath( return false; } +void ItemLine::save(SaveState state) { + if (state == SaveState::Keep) { + _keeped = true; + } else if (state == SaveState::Save) { + _saved = true; + } +} + +void ItemLine::restore(SaveState state) { +} + +bool ItemLine::hasState(SaveState state) const { + if (state == SaveState::Keep) { + return _keeped; + } else if (state == SaveState::Save) { + return _saved; + } + return false; +} + } // namespace Editor diff --git a/Telegram/SourceFiles/editor/scene/scene_item_line.h b/Telegram/SourceFiles/editor/scene/scene_item_line.h index f79367786f..da594775de 100644 --- a/Telegram/SourceFiles/editor/scene/scene_item_line.h +++ b/Telegram/SourceFiles/editor/scene/scene_item_line.h @@ -19,6 +19,10 @@ public: QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *widget) override; + + bool hasState(SaveState state) const override; + void save(SaveState state) override; + void restore(SaveState state) override; protected: bool collidesWithItem( const QGraphicsItem *, @@ -30,6 +34,8 @@ private: const QPixmap _pixmap; const QRectF _rect; + bool _saved, _keeped = false; + }; } // namespace Editor