From 1499f42361d7fe9751f28d317a76a71882bb201e Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 15 Dec 2019 00:37:06 -0600 Subject: [PATCH] [nostalgia/core/studio] Cleanup pixel data QML exposure --- src/nostalgia/core/studio/Pixel.qml | 2 +- src/nostalgia/core/studio/tilesheeteditor.cpp | 14 ++++++++------ src/nostalgia/core/studio/tilesheeteditor.hpp | 12 +++++++++--- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/nostalgia/core/studio/Pixel.qml b/src/nostalgia/core/studio/Pixel.qml index 40daa807..41fa465e 100644 --- a/src/nostalgia/core/studio/Pixel.qml +++ b/src/nostalgia/core/studio/Pixel.qml @@ -11,7 +11,7 @@ import QtQuick 2.0 Rectangle { id: pixel; property int pixelNumber: index - color: sheetData.pixel(pixelNumber) + color: sheetData.palette[sheetData.pixels[pixelNumber]] width: parent.width / 8 height: parent.height / 8 border.color: '#717d7e' diff --git a/src/nostalgia/core/studio/tilesheeteditor.cpp b/src/nostalgia/core/studio/tilesheeteditor.cpp index 30cb413b..b4e86234 100644 --- a/src/nostalgia/core/studio/tilesheeteditor.cpp +++ b/src/nostalgia/core/studio/tilesheeteditor.cpp @@ -52,11 +52,11 @@ class UpdatePixelsCommand: public QUndoCommand { uint64_t m_cmdIdx = 0; int m_newColorId = 0; const QStringList &m_palette; - QVector &m_pixels; + QVector &m_pixels; QSet m_pixelUpdates; public: - UpdatePixelsCommand(QVector &pixels, const QStringList &palette, QQuickItem *pixelItem, int newColorId, uint64_t cmdIdx): m_palette(palette), m_pixels(pixels) { + UpdatePixelsCommand(QVector &pixels, const QStringList &palette, QQuickItem *pixelItem, int newColorId, uint64_t cmdIdx): m_palette(palette), m_pixels(pixels) { m_newColorId = newColorId; m_cmdIdx = cmdIdx; PixelUpdate pu; @@ -96,10 +96,6 @@ class UpdatePixelsCommand: public QUndoCommand { }; -QString SheetData::pixel(int index) { - return m_palette[m_pixels[index]]; -} - void SheetData::updatePixel(QVariant pixelItem) { auto p = qobject_cast(pixelItem.value()); if (p && p != m_prevPixelUpdated) { @@ -126,6 +122,10 @@ void SheetData::setRows(int rows) { emit rowsChanged(); } +const QVector &SheetData::pixels() { + return m_pixels; +} + QStringList SheetData::palette() { return m_palette; } @@ -180,6 +180,8 @@ void SheetData::updatePixels(const NostalgiaGraphic *ng, const NostalgiaPalette m_pixels.push_back(p); } } + emit pixelsChanged(); + emit paletteChanged(); } void SheetData::beginCmd() { diff --git a/src/nostalgia/core/studio/tilesheeteditor.hpp b/src/nostalgia/core/studio/tilesheeteditor.hpp index a50cfe34..a786c0f0 100644 --- a/src/nostalgia/core/studio/tilesheeteditor.hpp +++ b/src/nostalgia/core/studio/tilesheeteditor.hpp @@ -26,20 +26,20 @@ class SheetData: public QObject { Q_OBJECT Q_PROPERTY(int columns READ columns WRITE setColumns NOTIFY columnsChanged) Q_PROPERTY(int rows READ rows WRITE setRows NOTIFY rowsChanged) + Q_PROPERTY(QVector pixels READ pixels NOTIFY pixelsChanged) + Q_PROPERTY(QStringList palette READ palette NOTIFY paletteChanged) private: QQuickItem *m_prevPixelUpdated = nullptr; uint64_t m_cmdIdx = 0; QUndoStack m_cmdStack; QStringList m_palette; - QVector m_pixels; + QVector m_pixels; int m_columns = 2; int m_rows = 2; int m_selectedColor = 0; public: - Q_INVOKABLE QString pixel(int index); - Q_INVOKABLE void updatePixel(QVariant pixel); Q_INVOKABLE void beginCmd(); @@ -54,6 +54,8 @@ class SheetData: public QObject { void setRows(int rows); + const QVector &pixels(); + QStringList palette(); void updatePixels(const studio::Context *ctx, QString ngPath, QString palPath = ""); @@ -70,6 +72,10 @@ class SheetData: public QObject { void rowsChanged(); + void pixelsChanged(); + + void paletteChanged(); + };