Return QVariantList objects instead of QList
QML doesn't have a proper type-safe generic list type, returning QList instances does technically work, however, qmlls (LSP) complains about using this as it isn't a proper QML type. Instead, return QVarianList objects, that are meant for QML.
This commit is contained in:
parent
84a8aa57d6
commit
4692ce356b
|
@ -1,5 +1,6 @@
|
|||
#include "gamestate.h"
|
||||
#include <QDebug>
|
||||
#include <qqmllist.h>
|
||||
#include <random>
|
||||
|
||||
GameState::GameState(QObject* parent, bool preDealCards) : QObject{parent} {
|
||||
|
@ -525,20 +526,36 @@ void GameState::ensureColumnRevealed(int columnId) {
|
|||
qDebug() << "Revealed card " << col->card()->toString() << " in column " << columnId;
|
||||
}
|
||||
|
||||
QList<PlayingCard*> GameState::drawPile() const {
|
||||
return m_drawPile;
|
||||
QVariantList GameState::drawPile() const {
|
||||
QVariantList lst;
|
||||
for (auto& card : m_drawPile) {
|
||||
lst.append(QVariant::fromValue(card));
|
||||
}
|
||||
return lst;
|
||||
}
|
||||
|
||||
QList<PlayingCard*> GameState::throwawayPile() const {
|
||||
return m_throwawayPile;
|
||||
QVariantList GameState::throwawayPile() const {
|
||||
QVariantList lst;
|
||||
for (auto& card : m_throwawayPile) {
|
||||
lst.append(QVariant::fromValue(card));
|
||||
}
|
||||
return lst;
|
||||
}
|
||||
|
||||
QList<QList<ColumnSlot*> > GameState::columns() const {
|
||||
return m_columns;
|
||||
QVariantList GameState::columns() const {
|
||||
QVariantList lst;
|
||||
for (auto& columnStack : m_columns) {
|
||||
lst.append(QVariant::fromValue(columnStack));
|
||||
}
|
||||
return lst;
|
||||
}
|
||||
|
||||
QList<QList<PlayingCard*> > GameState::foundation() const {
|
||||
return m_foundation;
|
||||
QVariantList GameState::foundation() const {
|
||||
QVariantList lst;
|
||||
for (auto& foundationStack : m_foundation) {
|
||||
lst.append(QVariant::fromValue(foundationStack));
|
||||
}
|
||||
return lst;
|
||||
}
|
||||
|
||||
bool GameState::gameWon() const {
|
||||
|
|
|
@ -5,25 +5,26 @@
|
|||
#include "playingcard.h"
|
||||
#include <QObject>
|
||||
#include <qqmlintegration.h>
|
||||
#include <qqmllist.h>
|
||||
|
||||
class GameState : public QObject {
|
||||
Q_OBJECT
|
||||
QML_ELEMENT
|
||||
QML_SINGLETON
|
||||
Q_PROPERTY(QList<PlayingCard*> drawPile READ drawPile NOTIFY drawPileChanged)
|
||||
Q_PROPERTY(QList<PlayingCard*> throwawayPile READ throwawayPile NOTIFY throwawayPileChanged)
|
||||
Q_PROPERTY(QList<QList<ColumnSlot*>> columns READ columns NOTIFY columnsChanged)
|
||||
Q_PROPERTY(QList<QList<PlayingCard*>> foundation READ foundation NOTIFY foundationChanged)
|
||||
Q_PROPERTY(QVariantList drawPile READ drawPile NOTIFY drawPileChanged)
|
||||
Q_PROPERTY(QVariantList throwawayPile READ throwawayPile NOTIFY throwawayPileChanged)
|
||||
Q_PROPERTY(QVariantList columns READ columns NOTIFY columnsChanged)
|
||||
Q_PROPERTY(QVariantList foundation READ foundation NOTIFY foundationChanged)
|
||||
Q_PROPERTY(bool gameWon READ gameWon NOTIFY gameWonChanged)
|
||||
|
||||
public:
|
||||
explicit GameState(QObject* parent = nullptr);
|
||||
|
||||
// Getters
|
||||
QList<PlayingCard*> drawPile() const;
|
||||
QList<PlayingCard*> throwawayPile() const;
|
||||
QList<QList<ColumnSlot*>> columns() const;
|
||||
QList<QList<PlayingCard*>> foundation() const;
|
||||
QVariantList drawPile() const;
|
||||
QVariantList throwawayPile() const;
|
||||
QVariantList columns() const;
|
||||
QVariantList foundation() const;
|
||||
bool gameWon() const;
|
||||
|
||||
// General functions
|
||||
|
|
Loading…
Reference in a new issue