Skip to content

Commit

Permalink
Views: Cleanup LevelCelView a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
tetektoza authored and AJenbo committed Feb 3, 2024
1 parent dbc21c2 commit 166d205
Show file tree
Hide file tree
Showing 7 changed files with 212 additions and 156 deletions.
5 changes: 2 additions & 3 deletions source/undostack/framecmds.cpp
Expand Up @@ -40,10 +40,9 @@ void ReplaceFrameCommand::redo()
emit this->replaced(frameIndexToReplace, imgToReplace);
}

AddFrameCommand::AddFrameCommand(int index, QImage &img, IMAGE_FILE_MODE mode)
AddFrameCommand::AddFrameCommand(int index, QImage &img)
: m_index(index)
, m_image(std::move(img))
, m_mode(mode)
{
}

Expand All @@ -54,5 +53,5 @@ void AddFrameCommand::undo()

void AddFrameCommand::redo()
{
emit this->added(m_index, m_image, m_mode);
emit this->added(m_index, m_image);
}
5 changes: 2 additions & 3 deletions source/undostack/framecmds.h
Expand Up @@ -48,18 +48,17 @@ class AddFrameCommand : public QObject, public Command {
Q_OBJECT

public:
explicit AddFrameCommand(int index, QImage &image, IMAGE_FILE_MODE mode);
explicit AddFrameCommand(int index, QImage &image);
~AddFrameCommand() = default;

void undo() override;
void redo() override;

signals:
void undoAdded(int index);
void added(int index, const QImage &image, IMAGE_FILE_MODE mode);
void added(int index, const QImage &image);

private:
QImage m_image;
int m_index = 0;
IMAGE_FILE_MODE m_mode;
};
12 changes: 12 additions & 0 deletions source/undostack/undomacro.cpp
Expand Up @@ -9,11 +9,23 @@ UserData::UserData(QString labelText, QString cancelButtonText, std::pair<int, i
{
}

UserData::UserData(QString labelText, QString cancelButtonText)
: m_labelText(std::move(labelText))
, m_cancelButtonText(std::move(cancelButtonText))
, m_minMax({ 0, 0 })
{
}

UndoMacroFactory::UndoMacroFactory(UserData &&userData)
: m_userData(std::make_unique<UserData>(userData.labelText(), userData.cancelButtonText(), std::make_pair(userData.min(), userData.max())))
{
}

void UndoMacroFactory::setUserData(const UserData &&userData)
{
m_userData = std::make_unique<UserData>(userData.labelText(), userData.cancelButtonText(), std::make_pair(userData.min(), userData.max()));
}

void UndoMacroFactory::add(std::unique_ptr<Command> cmd)
{
m_commands.push_back(std::move(cmd));
Expand Down
4 changes: 4 additions & 0 deletions source/undostack/undomacro.h
Expand Up @@ -14,6 +14,7 @@ class UserData {

public:
UserData(QString labelText, QString cancelButtonText, std::pair<int, int> &&minMax);
UserData(QString labelText, QString cancelButtonText);
~UserData() = default;

[[nodiscard]] int min() const
Expand Down Expand Up @@ -49,8 +50,11 @@ class UndoMacroFactory {

public:
UndoMacroFactory(UserData &&userData);
UndoMacroFactory() = default;
~UndoMacroFactory() = default;

void setUserData(const UserData &&userData);

void add(std::unique_ptr<Command> cmd);
[[nodiscard]] std::vector<std::unique_ptr<Command>> &cmds()
{
Expand Down
2 changes: 1 addition & 1 deletion source/views/celview.cpp
Expand Up @@ -221,7 +221,7 @@ void CelView::sendAddFrameCmd(IMAGE_FILE_MODE mode, int index, const QString &im
};

auto connectCommand = [&](QImage &img) -> std::unique_ptr<AddFrameCommand> {
auto command = std::make_unique<AddFrameCommand>(index, img, mode);
auto command = std::make_unique<AddFrameCommand>(index, img);

// Connect signals which will be called upon redo/undo operations of the undostack
QObject::connect(command.get(), &AddFrameCommand::added, this, &CelView::insertFrames);
Expand Down

0 comments on commit 166d205

Please sign in to comment.