Files
o3de/Gems/LyShine/Code/Editor/CommandCanvasSizeToolbarIndex.cpp
T
2021-03-08 14:30:57 -08:00

99 lines
2.5 KiB
C++

/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "UiCanvasEditor_precompiled.h"
#include "EditorCommon.h"
CommandCanvasSizeToolbarIndex::CommandCanvasSizeToolbarIndex(UndoStack* stack,
CanvasSizeToolbarSection* canvasSizeToolbar,
int from,
int to)
: QUndoCommand()
, m_stack(stack)
, m_canvasSizeToolbar(canvasSizeToolbar)
, m_from(from)
, m_to(to)
{
UpdateText();
}
void CommandCanvasSizeToolbarIndex::undo()
{
UndoStackExecutionScope s(m_stack);
SetIndex(m_from);
}
void CommandCanvasSizeToolbarIndex::redo()
{
UndoStackExecutionScope s(m_stack);
SetIndex(m_to);
}
int CommandCanvasSizeToolbarIndex::id() const
{
return (int)FusibleCommand::kCanvasSizeToolbarIndex;
}
bool CommandCanvasSizeToolbarIndex::mergeWith(const QUndoCommand* other)
{
if (other->id() != id())
{
// NOT the same command type.
return false;
}
const CommandCanvasSizeToolbarIndex* subsequent = static_cast<const CommandCanvasSizeToolbarIndex*>(other);
AZ_Assert(subsequent, "There is no command to merge with");
if (!((subsequent->m_stack == m_stack) &&
(subsequent->m_canvasSizeToolbar == m_canvasSizeToolbar)))
{
// NOT the same context.
return false;
}
m_to = subsequent->m_to;
UpdateText();
return true;
}
void CommandCanvasSizeToolbarIndex::UpdateText()
{
setText(QString("canvas size change to %1").arg(m_canvasSizeToolbar->IndexToString(m_to)));
}
void CommandCanvasSizeToolbarIndex::SetIndex(int index) const
{
// IMPORTANT: It's NOT necessary to prevent this from executing on the
// first run. We WON'T get a redundant Qt notification by this point.
m_canvasSizeToolbar->SetIndex(index);
}
void CommandCanvasSizeToolbarIndex::Push(UndoStack* stack,
CanvasSizeToolbarSection* canvasSizeToolbar,
int from,
int to)
{
if (stack->GetIsExecuting())
{
// This is a redundant Qt notification.
// Nothing else to do.
return;
}
stack->push(new CommandCanvasSizeToolbarIndex(stack, canvasSizeToolbar, from, to));
}