Moved SaveState from Editor::BaseItem to Editor::NumberedItem.

This commit is contained in:
23rd 2021-07-08 01:25:04 +03:00
parent 1e3044fbf4
commit 9be122710d
4 changed files with 50 additions and 4 deletions

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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