[nostalgia/core/studio] Fix delete tile undo to restore pixel data
This commit is contained in:
parent
d7d0690575
commit
95d58d04fb
@ -6,6 +6,8 @@
|
|||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
@ -191,6 +193,7 @@ class InsertTileCommand: public QUndoCommand {
|
|||||||
SheetData *m_sheetData = nullptr;
|
SheetData *m_sheetData = nullptr;
|
||||||
int m_idx = 0;
|
int m_idx = 0;
|
||||||
bool m_delete = false;
|
bool m_delete = false;
|
||||||
|
QVector<int> m_tileRestore;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
InsertTileCommand(SheetData *sheetData, int idx, bool del = false) {
|
InsertTileCommand(SheetData *sheetData, int idx, bool del = false) {
|
||||||
@ -207,17 +210,17 @@ class InsertTileCommand: public QUndoCommand {
|
|||||||
|
|
||||||
void redo() override {
|
void redo() override {
|
||||||
if (m_delete) {
|
if (m_delete) {
|
||||||
m_sheetData->deleteTile(m_idx);
|
m_tileRestore = m_sheetData->deleteTile(m_idx);
|
||||||
} else {
|
} else {
|
||||||
m_sheetData->insertTile(m_idx);
|
m_sheetData->insertTile(m_idx, m_tileRestore);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void undo() override {
|
void undo() override {
|
||||||
if (m_delete) {
|
if (m_delete) {
|
||||||
m_sheetData->insertTile(m_idx);
|
m_sheetData->insertTile(m_idx, m_tileRestore);
|
||||||
} else {
|
} else {
|
||||||
m_sheetData->deleteTile(m_idx);
|
m_tileRestore = m_sheetData->deleteTile(m_idx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,16 +319,24 @@ void SheetData::setPalette(const studio::Context *ctx, QString palPath) {
|
|||||||
emit changeOccurred();
|
emit changeOccurred();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SheetData::insertTile(int tileIdx) {
|
void SheetData::insertTile(int tileIdx, QVector<int> tileData) {
|
||||||
m_pixels.insert(tileIdx * PixelsPerTile, PixelsPerTile, 0);
|
auto pxIdx = tileIdx * PixelsPerTile;
|
||||||
|
m_pixels.insert(pxIdx, PixelsPerTile, 0);
|
||||||
|
std::copy(tileData.begin(), tileData.end(), &m_pixels[pxIdx]);
|
||||||
emit pixelsChanged();
|
emit pixelsChanged();
|
||||||
emit changeOccurred();
|
emit changeOccurred();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SheetData::deleteTile(int tileIdx) {
|
QVector<int> SheetData::deleteTile(int tileIdx) {
|
||||||
m_pixels.remove(tileIdx * PixelsPerTile, PixelsPerTile);
|
QVector<int> out;
|
||||||
|
auto pxIdx = tileIdx * PixelsPerTile;
|
||||||
|
std::copy(m_pixels.begin() + pxIdx,
|
||||||
|
m_pixels.begin() + (pxIdx + PixelsPerTile),
|
||||||
|
std::back_inserter(out));
|
||||||
|
m_pixels.remove(pxIdx, PixelsPerTile);
|
||||||
emit pixelsChanged();
|
emit pixelsChanged();
|
||||||
emit changeOccurred();
|
emit changeOccurred();
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SheetData::setSelectedColor(int index) {
|
void SheetData::setSelectedColor(int index) {
|
||||||
|
@ -65,9 +65,9 @@ class SheetData: public QObject {
|
|||||||
|
|
||||||
void setPalette(const studio::Context *ctx, QString palPath);
|
void setPalette(const studio::Context *ctx, QString palPath);
|
||||||
|
|
||||||
void insertTile(int tileIdx);
|
void insertTile(int tileIdx, QVector<int> tileData = {});
|
||||||
|
|
||||||
void deleteTile(int tileIdx);
|
QVector<int> deleteTile(int tileIdx);
|
||||||
|
|
||||||
void setSelectedColor(int index);
|
void setSelectedColor(int index);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user