[nostalgia/core/studio] Make TileSheetClipboards that are passed around use heap

This commit is contained in:
Gary Talent 2020-10-21 00:58:41 -05:00
parent b960539e5f
commit 3430e228c8

View File

@ -322,13 +322,13 @@ class InsertTileCommand: public QUndoCommand {
class PasteClipboardCommand: public QUndoCommand { class PasteClipboardCommand: public QUndoCommand {
private: private:
SheetData *m_sheetData = nullptr; SheetData *m_sheetData = nullptr;
TileSheetClipboard m_restore; std::unique_ptr<TileSheetClipboard> m_restore;
TileSheetClipboard m_apply; std::unique_ptr<TileSheetClipboard> m_apply;
public: public:
PasteClipboardCommand(SheetData *sheetData, PasteClipboardCommand(SheetData *sheetData,
const TileSheetClipboard &restore, std::unique_ptr<TileSheetClipboard> &&restore,
const TileSheetClipboard &apply): m_sheetData(sheetData), m_restore(restore), m_apply(apply) { std::unique_ptr<TileSheetClipboard> &&apply): m_sheetData(sheetData), m_restore(std::move(restore)), m_apply(std::move(apply)) {
} }
virtual ~PasteClipboardCommand() = default; virtual ~PasteClipboardCommand() = default;
@ -338,11 +338,11 @@ class PasteClipboardCommand: public QUndoCommand {
} }
void redo() override { void redo() override {
m_sheetData->applyClipboard(m_apply); m_sheetData->applyClipboard(*m_apply);
} }
void undo() override { void undo() override {
m_sheetData->applyClipboard(m_restore); m_sheetData->applyClipboard(*m_restore);
} }
}; };
@ -618,16 +618,16 @@ void SheetData::cutToClipboard() {
void SheetData::cutToClipboard(TileSheetClipboard *cb) { void SheetData::cutToClipboard(TileSheetClipboard *cb) {
const auto start = ptToIdx(cb->point1(), m_columns); const auto start = ptToIdx(cb->point1(), m_columns);
const auto end = ptToIdx(cb->point2(), m_columns); const auto end = ptToIdx(cb->point2(), m_columns);
TileSheetClipboard apply; auto apply = std::make_unique<TileSheetClipboard>();
for (int i = start; i <= end; ++i) { for (int i = start; i <= end; ++i) {
const auto s = m_pixelSelected[i]; const auto s = m_pixelSelected[i];
if (s) { if (s) {
cb->add(i, m_pixels[i]); cb->add(i, m_pixels[i]);
apply.add(i, 0); apply->add(i, 0);
} }
} }
apply.setPoints(cb->point1(), cb->point2()); apply->setPoints(cb->point1(), cb->point2());
m_cmdStack->push(new PasteClipboardCommand(this, *cb, apply)); m_cmdStack->push(new PasteClipboardCommand(this, std::make_unique<TileSheetClipboard>(*cb), std::move(apply)));
} }
void SheetData::copyToClipboard() { void SheetData::copyToClipboard() {
@ -647,14 +647,14 @@ void SheetData::copyToClipboard(TileSheetClipboard *cb) {
} }
void SheetData::pasteClipboard() { void SheetData::pasteClipboard() {
TileSheetClipboard apply = m_clipboard; auto apply = std::make_unique<TileSheetClipboard>(m_clipboard);
TileSheetClipboard restore; auto restore = std::make_unique<TileSheetClipboard>();
const auto p2 = m_selectionStart + (apply.point2() - apply.point1()); const auto p2 = m_selectionStart + (apply->point2() - apply->point1());
apply.setPoints(m_selectionStart, p2); apply->setPoints(m_selectionStart, p2);
restore.setPoints(m_selectionStart, p2); restore->setPoints(m_selectionStart, p2);
markSelection(p2); markSelection(p2);
copyToClipboard(&restore); copyToClipboard(restore.get());
m_cmdStack->push(new PasteClipboardCommand(this, restore, apply)); m_cmdStack->push(new PasteClipboardCommand(this, std::move(restore), std::move(apply)));
} }
void SheetData::applyClipboard(const TileSheetClipboard &cb) { void SheetData::applyClipboard(const TileSheetClipboard &cb) {