Thanks for your reply.
You are right about not needed the Card and Album classes defined since I wouldn't be directly using them in the Front-end.
I have been messing around with different configurations to diagnose the methods and understand what is going on when I instanciate objects. I will post the updated code below.
AbstractCardsModel:
#ifndef ABSTRACTCARDMODEL_H
#define ABSTRACTCARDMODEL_H
#include <QString>
#include <QObject>
#include <QAbstractListModel>
#include "cardsmanager.h"
#include "card.h"
{
Q_OBJECT
public:
// Card roles
enum AlbumRoles { CardIDRole = Qt::UserRole + 1, NameRole, ImageURLRole, SubtypeRole, SupertypeRole, NumberRole, ArtistRole, RarityRole, SeriesRole, SetRole, SetCodeRole, ConditionRole, StatusRole};
// Default Constructor
AbstractCardModel
(QObject* parent
= 0);
// Overloaded Constructor
AbstractCardModel
(CardsManager
*cardsManager,
QObject *parent
= 0);
// Copy Constructor
AbstractCardModel(const AbstractCardModel& source);
// Assignment Operator
AbstractCardModel& operator=(const AbstractCardModel& source);
// this uses cardForIndex to get the card, then uses role to return the actual data
// Default Destructor
~AbstractCardModel();
protected:
QHash<int, QByteArray> roleNames() const;
virtual Card cardForIndex
(const QModelIndex &index
) const = 0;
protected:
CardsManager *m_cardsManager;
};
#endif //ABSTRACTCARDMODEL_H
#ifndef ABSTRACTCARDMODEL_H
#define ABSTRACTCARDMODEL_H
#include <QString>
#include <QObject>
#include <QAbstractListModel>
#include "cardsmanager.h"
#include "card.h"
class AbstractCardModel : public QAbstractListModel
{
Q_OBJECT
public:
// Card roles
enum AlbumRoles { CardIDRole = Qt::UserRole + 1, NameRole, ImageURLRole, SubtypeRole, SupertypeRole, NumberRole, ArtistRole, RarityRole, SeriesRole, SetRole, SetCodeRole, ConditionRole, StatusRole};
// Default Constructor
AbstractCardModel(QObject* parent = 0);
// Overloaded Constructor
AbstractCardModel(CardsManager *cardsManager, QObject *parent = 0);
// Copy Constructor
AbstractCardModel(const AbstractCardModel& source);
// Assignment Operator
AbstractCardModel& operator=(const AbstractCardModel& source);
// this uses cardForIndex to get the card, then uses role to return the actual data
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
// Default Destructor
~AbstractCardModel();
protected:
QHash<int, QByteArray> roleNames() const;
virtual Card cardForIndex(const QModelIndex &index) const = 0;
protected:
CardsManager *m_cardsManager;
};
#endif //ABSTRACTCARDMODEL_H
To copy to clipboard, switch view to plain text mode
#include "abstractcardmodel.h"
// Default Constructor
{
// For debugging purposes
qDebug() << "[AbstractCardModel] [called] [Default constructor]";
this->m_cardsManager = nullptr;
}
// Overloaded Constructor
{
// For debugging purposes
qDebug() << "[AbstractCardModel] [called] [Overloaded constructor]";
this->m_cardsManager = cardsManager;
}
// Copy Constructor
AbstractCardModel::AbstractCardModel(const AbstractCardModel& source)
{
qDebug() << "[AbstractCardModel] [called] [Copy Constructor]";
this->m_cardsManager = source.m_cardsManager;
}
// Assignment Operator
AbstractCardModel& AbstractCardModel::operator=(const AbstractCardModel& source)
{
qDebug() << "[AbstractCardModel] [called] [Assignment Operator]";
if(this != &source)
{
this->m_cardsManager = source.m_cardsManager;
}
return *this;
}
{
// For debugging purposes
qDebug() << "[AbstractCardModel] [called] >> data(const QModelIndex &index, int role)";
if (index.row() < 0 || index.row() >= this->m_cardsManager->count())
const Card &card = cardForIndex(index);
if (role == CardIDRole)
return card.getCardID();
else if (role == NameRole)
return card.getName();
else if (role == ImageURLRole)
return card.getImageURL();
else if (role == SubtypeRole)
return card.getSubtype();
else if (role == SupertypeRole)
return card.getSupertype();
else if (role == NumberRole)
return card.getNumber();
else if (role == ArtistRole)
return card.getArtist();
else if (role == RarityRole)
return card.getRarity();
else if (role == SeriesRole)
return card.getSeries();
else if (role == SetRole)
return card.getSet();
else if (role == SetCodeRole)
return card.getSetCode();
else if (role == ConditionRole)
return card.getCondition();
else if (role == StatusRole)
return card.getStatus();
}
// Role names
QHash<int, QByteArray> AbstractCardModel::roleNames() const
{
// For debugging purposes
qDebug() << "[AbstractCardModel] [called] >> roleNames()";
QHash<int, QByteArray> roles;
roles[CardIDRole] = "cardID";
roles[NameRole] = "name";
roles[ImageURLRole] = "imageURL";
roles[SubtypeRole] = "subtype";
roles[SupertypeRole] = "supertype";
roles[NumberRole] = "number";
roles[ArtistRole] = "artist";
roles[RarityRole] = "rarity";
roles[SeriesRole] = "series";
roles[SetRole] = "set";
roles[SetCodeRole] = "setCode";
roles[ConditionRole] = "condition";
roles[StatusRole] = "status";
return roles;
}
// Default Destructor
AbstractCardModel::~AbstractCardModel()
{
// For debugging purposes
qDebug() << "[AbstractCardModel] [called] [Default Destructor]";
}
#include "abstractcardmodel.h"
// Default Constructor
AbstractCardModel::AbstractCardModel(QObject* parent): QAbstractListModel(parent)
{
// For debugging purposes
qDebug() << "[AbstractCardModel] [called] [Default constructor]";
this->m_cardsManager = nullptr;
}
// Overloaded Constructor
AbstractCardModel::AbstractCardModel(CardsManager *cardsManager, QObject *parent): QAbstractListModel(parent)
{
// For debugging purposes
qDebug() << "[AbstractCardModel] [called] [Overloaded constructor]";
this->m_cardsManager = cardsManager;
}
// Copy Constructor
AbstractCardModel::AbstractCardModel(const AbstractCardModel& source)
{
qDebug() << "[AbstractCardModel] [called] [Copy Constructor]";
this->m_cardsManager = source.m_cardsManager;
}
// Assignment Operator
AbstractCardModel& AbstractCardModel::operator=(const AbstractCardModel& source)
{
qDebug() << "[AbstractCardModel] [called] [Assignment Operator]";
if(this != &source)
{
this->m_cardsManager = source.m_cardsManager;
}
return *this;
}
QVariant AbstractCardModel::data(const QModelIndex &index, int role) const
{
// For debugging purposes
qDebug() << "[AbstractCardModel] [called] >> data(const QModelIndex &index, int role)";
if (index.row() < 0 || index.row() >= this->m_cardsManager->count())
return QVariant();
const Card &card = cardForIndex(index);
if (role == CardIDRole)
return card.getCardID();
else if (role == NameRole)
return card.getName();
else if (role == ImageURLRole)
return card.getImageURL();
else if (role == SubtypeRole)
return card.getSubtype();
else if (role == SupertypeRole)
return card.getSupertype();
else if (role == NumberRole)
return card.getNumber();
else if (role == ArtistRole)
return card.getArtist();
else if (role == RarityRole)
return card.getRarity();
else if (role == SeriesRole)
return card.getSeries();
else if (role == SetRole)
return card.getSet();
else if (role == SetCodeRole)
return card.getSetCode();
else if (role == ConditionRole)
return card.getCondition();
else if (role == StatusRole)
return card.getStatus();
return QVariant();
}
// Role names
QHash<int, QByteArray> AbstractCardModel::roleNames() const
{
// For debugging purposes
qDebug() << "[AbstractCardModel] [called] >> roleNames()";
QHash<int, QByteArray> roles;
roles[CardIDRole] = "cardID";
roles[NameRole] = "name";
roles[ImageURLRole] = "imageURL";
roles[SubtypeRole] = "subtype";
roles[SupertypeRole] = "supertype";
roles[NumberRole] = "number";
roles[ArtistRole] = "artist";
roles[RarityRole] = "rarity";
roles[SeriesRole] = "series";
roles[SetRole] = "set";
roles[SetCodeRole] = "setCode";
roles[ConditionRole] = "condition";
roles[StatusRole] = "status";
return roles;
}
// Default Destructor
AbstractCardModel::~AbstractCardModel()
{
// For debugging purposes
qDebug() << "[AbstractCardModel] [called] [Default Destructor]";
}
To copy to clipboard, switch view to plain text mode
Album:
#ifndef ALBUM_H
#define ALBUM_H
#include <QDebug>
#include <QObject>
#include <QString>
#include <QVariant>
#include <QList>
#include <QAbstractListModel>
#include <QQmlListProperty>
#include <QModelIndex>
#include "card.h"
{
private:
QStringList cardIDs;
// Holds list of all the card IDs that are in the Album int albumId; // Holds a unique Album ID given to it from the AlbumsManager
QString albumName;
// Holds the user specified name for the Album
public:
// Default Constructor
// Overloaded Constructor
// Copy Constructor
Album(const Album& source);
// Assignment Operator
Album& operator=(const Album& source);
// ALBUM GETTERS
int getAlbumId() const;
int getNrOfCards() const;
// ALBUM SETTERS
void setAlbumName
(const QString newAlbumName
);
void setAlbumId(const int newAlbumId);
// CARDS IN ALBUM
void addCard(const QString& cardID);
void removeCard(const QString& cardID);
QString getCardID
(const int index
);
// Destructor
~Album();
};
#endif // ALBUM_H
#ifndef ALBUM_H
#define ALBUM_H
#include <QDebug>
#include <QObject>
#include <QString>
#include <QVariant>
#include <QList>
#include <QAbstractListModel>
#include <QQmlListProperty>
#include <QModelIndex>
#include "card.h"
class Album : public QObject
{
private:
QStringList cardIDs; // Holds list of all the card IDs that are in the Album
int albumId; // Holds a unique Album ID given to it from the AlbumsManager
QString albumName; // Holds the user specified name for the Album
public:
// Default Constructor
Album(QObject* parent = 0);
// Overloaded Constructor
Album(QString newAlbumName, int albumId, QObject* parent = 0);
// Copy Constructor
Album(const Album& source);
// Assignment Operator
Album& operator=(const Album& source);
// ALBUM GETTERS
QString getAlbumName() const;
int getAlbumId() const;
int getNrOfCards() const;
// ALBUM SETTERS
void setAlbumName(const QString newAlbumName);
void setAlbumId(const int newAlbumId);
// CARDS IN ALBUM
void addCard(const QString& cardID);
void removeCard(const QString& cardID);
QString getCardID(const int index);
QStringList getCardIDs() const;
// Destructor
~Album();
};
#endif // ALBUM_H
To copy to clipboard, switch view to plain text mode
#include "album.h"
// Default Constructor
{
// For debugging purposes
qDebug() << "[Album] [called] [albumId:" << albumId << "] [Default constructor]";
}
// Overloaded Constructor
{
qDebug() << "[Album] [called] [albumId:" << albumId << "] [Overloaded constructor] || newAlbumName: " << newAlbumName << ", albumId: " << albumId;
this->albumName = newAlbumName;
this->albumId = albumId;
}
// Copy Constructor
Album::Album(const Album& source)
{
qDebug() << "[Album] [called] [albumId:" << albumId << "] [Copy constructor] || albumId: " << albumId;
this->albumName = source.albumName;
this->albumId = source.albumId;
for(int i = 0; i < source.getNrOfCards(); i++)
{
this->addCard(source.cardIDs[i]);
}
}
// Assignment Operator
Album& Album::operator =(const Album& source)
{
qDebug() << "[Album] [called] [albumId:" << albumId << "] [Assignment opperator] || albumId: " << albumId;
if(this != &source)
{
this->albumName = source.albumName;
this->albumId = source.albumId;
for(int i = 0; i < source.getNrOfCards(); i++)
{
this->addCard(source.cardIDs[i]);
}
}
return *this;
}
// ALBUM GETTERS
QString Album
::getAlbumName() const {
qDebug() << "[Album] [called] [albumId:" << albumId << "] >> getAlbumName() || returned: albumName: " << albumName;
return albumName;
}
int Album::getAlbumId() const
{
qDebug() << "[Album] [called] [albumId:" << albumId << "] >> getAlbumId() || returned: albumId: " << albumId;
return albumId;
}
int Album::getNrOfCards() const
{
qDebug() << "[Album] [called] [albumId:" << albumId << "] >> getNrOfCards() || returned count: " << cardIDs.count();
return this->cardIDs.count();
}
// ALBUM SETTERS
void Album
::setAlbumName(const QString newAlbumName
) {
qDebug() << "[Album] [albumId:" << albumId << "] [called] >> setAlbumName(const QString newAlbumName) || newAlbumName: " << newAlbumName;
this->albumName = newAlbumName;
}
void Album::setAlbumId(const int newAlbumId)
{
qDebug() << "[Album] [called] [albumId:" << albumId << "] >> setAlbumId(const int newAlbumId) || newAlbumId: " << newAlbumId;
this->albumId = newAlbumId;
}
// CARDS IN ALBUM
void Album::addCard(const QString& cardID)
{
qDebug() << "[Album] [called] [albumId:" << albumId << "] >> addCard(const QString& cardID): cardID: " << cardID;
this->cardIDs.append(cardID);
}
void Album::removeCard(const QString& cardID)
{
qDebug() << "[Album] [called] [albumId:" << albumId << "] >> removeCard(const QString& cardID): cardID: " << cardID;
for(int i = 0; i < this->cardIDs.count(); i++)
{
if(cardIDs[i] == cardID)
{
qDebug() << "[Album] [update] [albumId:" << albumId << "] >> removeCard(const QString& cardID) || Card match found at i: " << i;
this->cardIDs.removeAt(i);
return;
}
}
}
QString/*&*/ Album
::getCardID(const int index
) {
qDebug() << "[Album] [called] [albumId:" << albumId << "] >> getCardID(const int index) || index: " << index << ", Returning cardId: " << cardIDs[index];
return this->cardIDs[index];
}
{
qDebug() << "[Album] [called] [albumId:" << albumId << "] >> getCardIDs()";
return this->cardIDs;
}
// Destructor
Album::~Album()
{
qDebug() << "[Album] [called] [albumId:" << albumId << "] [Destructor]";
}
#include "album.h"
// Default Constructor
Album::Album(QObject* parent): QObject(parent)
{
// For debugging purposes
qDebug() << "[Album] [called] [albumId:" << albumId << "] [Default constructor]";
}
// Overloaded Constructor
Album::Album(QString newAlbumName, int albumId, QObject* parent): QObject(parent)
{
qDebug() << "[Album] [called] [albumId:" << albumId << "] [Overloaded constructor] || newAlbumName: " << newAlbumName << ", albumId: " << albumId;
this->albumName = newAlbumName;
this->albumId = albumId;
}
// Copy Constructor
Album::Album(const Album& source)
{
qDebug() << "[Album] [called] [albumId:" << albumId << "] [Copy constructor] || albumId: " << albumId;
this->albumName = source.albumName;
this->albumId = source.albumId;
for(int i = 0; i < source.getNrOfCards(); i++)
{
this->addCard(source.cardIDs[i]);
}
}
// Assignment Operator
Album& Album::operator =(const Album& source)
{
qDebug() << "[Album] [called] [albumId:" << albumId << "] [Assignment opperator] || albumId: " << albumId;
if(this != &source)
{
this->albumName = source.albumName;
this->albumId = source.albumId;
for(int i = 0; i < source.getNrOfCards(); i++)
{
this->addCard(source.cardIDs[i]);
}
}
return *this;
}
// ALBUM GETTERS
QString Album::getAlbumName() const
{
qDebug() << "[Album] [called] [albumId:" << albumId << "] >> getAlbumName() || returned: albumName: " << albumName;
return albumName;
}
int Album::getAlbumId() const
{
qDebug() << "[Album] [called] [albumId:" << albumId << "] >> getAlbumId() || returned: albumId: " << albumId;
return albumId;
}
int Album::getNrOfCards() const
{
qDebug() << "[Album] [called] [albumId:" << albumId << "] >> getNrOfCards() || returned count: " << cardIDs.count();
return this->cardIDs.count();
}
// ALBUM SETTERS
void Album::setAlbumName(const QString newAlbumName)
{
qDebug() << "[Album] [albumId:" << albumId << "] [called] >> setAlbumName(const QString newAlbumName) || newAlbumName: " << newAlbumName;
this->albumName = newAlbumName;
}
void Album::setAlbumId(const int newAlbumId)
{
qDebug() << "[Album] [called] [albumId:" << albumId << "] >> setAlbumId(const int newAlbumId) || newAlbumId: " << newAlbumId;
this->albumId = newAlbumId;
}
// CARDS IN ALBUM
void Album::addCard(const QString& cardID)
{
qDebug() << "[Album] [called] [albumId:" << albumId << "] >> addCard(const QString& cardID): cardID: " << cardID;
this->cardIDs.append(cardID);
}
void Album::removeCard(const QString& cardID)
{
qDebug() << "[Album] [called] [albumId:" << albumId << "] >> removeCard(const QString& cardID): cardID: " << cardID;
for(int i = 0; i < this->cardIDs.count(); i++)
{
if(cardIDs[i] == cardID)
{
qDebug() << "[Album] [update] [albumId:" << albumId << "] >> removeCard(const QString& cardID) || Card match found at i: " << i;
this->cardIDs.removeAt(i);
return;
}
}
}
QString/*&*/ Album::getCardID(const int index)
{
qDebug() << "[Album] [called] [albumId:" << albumId << "] >> getCardID(const int index) || index: " << index << ", Returning cardId: " << cardIDs[index];
return this->cardIDs[index];
}
QStringList Album::getCardIDs() const
{
qDebug() << "[Album] [called] [albumId:" << albumId << "] >> getCardIDs()";
return this->cardIDs;
}
// Destructor
Album::~Album()
{
qDebug() << "[Album] [called] [albumId:" << albumId << "] [Destructor]";
}
To copy to clipboard, switch view to plain text mode
AlbumCardsModel:
#ifndef ALBUMCARDSMODEL_H
#define ALBUMCARDSMODEL_H
#include <QObject>
#include <QString>
#include <QVariant>
#include <QDebug>
#include <QList>
#include <QAbstractListModel>
#include <QQmlListProperty>
#include <QModelIndex>
#include "abstractcardmodel.h"
#include "albumsmanager.h"
class AlbumCardsModel : public AbstractCardModel
{
Q_OBJECT
public:
// Album name role
enum AlbumRoles { AlbumNameRole = Qt::UserRole + 1};
// Default Constructor
AlbumCardsModel
(QObject *parent
= 0);
AlbumCardsModel
(AlbumsManager
*albumsManager, CardsManager
*cardsManager,
QObject *parent
= 0);
// Show a specific Album
Q_INVOKABLE void showAlbum(const int &albumId);
// Get the
protected:
// Get the card object at the specified position in the Album
private slots:
// gets connected to m_albumManager's albumRemoved() signal
void onAlbumRemoved(const int &albumId);
void onCardAdded
(const int &albumId,
const QString &cardId
);
void onCardRemoved
(const int &albumId,
const QString &cardId
);
private:
AlbumsManager *m_albumsManager; // Points to the Album's AlbumsManager
Album m_album; // Holds the Album it provides the View with
};
#endif // ALBUMCARDSMODEL_H
#ifndef ALBUMCARDSMODEL_H
#define ALBUMCARDSMODEL_H
#include <QObject>
#include <QString>
#include <QVariant>
#include <QDebug>
#include <QList>
#include <QAbstractListModel>
#include <QQmlListProperty>
#include <QModelIndex>
#include "abstractcardmodel.h"
#include "albumsmanager.h"
class AlbumCardsModel : public AbstractCardModel
{
Q_OBJECT
public:
// Album name role
enum AlbumRoles { AlbumNameRole = Qt::UserRole + 1};
// Default Constructor
AlbumCardsModel(QObject *parent = 0);
AlbumCardsModel(AlbumsManager *albumsManager, CardsManager *cardsManager, QObject *parent = 0);
// Show a specific Album
Q_INVOKABLE void showAlbum(const int &albumId);
// Get the
int rowCount(const QModelIndex &parent) const;
protected:
// Get the card object at the specified position in the Album
Card cardForIndex(const QModelIndex &index) const;
private slots:
// gets connected to m_albumManager's albumRemoved() signal
void onAlbumRemoved(const int &albumId);
void onCardAdded(const int &albumId, const QString &cardId);
void onCardRemoved(const int &albumId, const QString &cardId);
private:
AlbumsManager *m_albumsManager; // Points to the Album's AlbumsManager
Album m_album; // Holds the Album it provides the View with
};
#endif // ALBUMCARDSMODEL_H
To copy to clipboard, switch view to plain text mode
#include "albumcardsmodel.h"
AlbumCardsModel
::AlbumCardsModel(QObject *parent
) : AbstractCardModel(parent)
{
qDebug() << "[AlbumCardsModel] [called] [Default Constructor]";
this->m_albumsManager = nullptr;
this->m_cardsManager = nullptr;
}
AlbumCardsModel
::AlbumCardsModel( AlbumsManager
* albumsManager, CardsManager
* cardsManager,
QObject *parent
) : AbstractCardModel(cardsManager, parent)
{
qDebug() << "[AlbumCardsModel] [called] [Overloaded Constructor]";
this->m_albumsManager = albumsManager;
this->m_cardsManager = cardsManager;
}
// Show a specific Album
void AlbumCardsModel::showAlbum(const int &albumId)
{
qDebug() << "[AlbumCardsModel] [called] >> showAlbum(const int &albumId) || albumId: " << albumId;
// Get the requested Album from AlbumsManager and set it as the current active one.
beginResetModel();
m_album = m_albumsManager->album(albumId);
endResetModel();
}
// Get the number of Cards in the Active Album
int AlbumCardsModel::rowCount(const QModelIndex&) const
{
qDebug() << "[AlbumCardsModel] [called] >> rowCount(const QModelIndex&)";
return m_album.getCardIDs().count();
}
// Get the card object at the specified position in the Album
Card AlbumCardsModel
::cardForIndex(const QModelIndex &index
) const{
qDebug() << "[AlbumCardsModel] [called] >> cardForIndex(const QModelIndex &index)";
return m_cardsManager->card(m_album.getCardIDs().at(index.row()));
}
// Receives a signal from the AlbumsManager when an Album is removed
void AlbumCardsModel::onAlbumRemoved(const int &albumId)
{
qDebug() << "[AlbumCardsModel] [called] [from signal] >> onAlbumRemoved(const int &albumId) || albumId: " << albumId;
// Do not proceed if the signaled Album change is not the active one
if (albumId != m_album.getAlbumId()) return;
qDebug() << "[AlbumCardsModel] [update] >> onAlbumRemoved(const int &albumId) || albumId from signal matches current albumId.";
// replace the Model's active Album with a Default Album
beginResetModel();
m_album = Album();
endResetModel();
qDebug() << "[AlbumCardsModel] [update] >> onAlbumRemoved(const int &albumId) || Current album replaced with default constructed album.";
}
// Receives a signal from the AlbumsManager when a Card is added to an Album
void AlbumCardsModel
::onCardAdded(const int &albumId,
const QString &cardId
) {
qDebug() << "[AlbumCardsModel] [called] [from signal] >> onCardAdded(const int &albumId, const QString &cardId) || albumId: " << albumId << ", cardId: " << cardId;
// Do not proceed if the signaled Album change is not the active one
if (albumId != m_album.getAlbumId()) return;
qDebug() << "[AlbumCardsModel] [update] >> onCardAdded(const int &albumId, const QString &cardId) || albumId from signal matches current albumId";
// Retreive the updated Album from the AlbumsManager
const Album updatedAlbum = m_albumsManager->album(albumId);
const int row = updatedAlbum.getCardIDs().indexOf(cardId);
// replace the Model's active Album with the updated Album
m_album = updatedAlbum;
endInsertRows();
qDebug() << "[AlbumCardsModel] [update] >> onCardAdded(const int &albumId, const QString &cardId) || current album updated";
}
// Receives a signal from the AlbumsManager when a Card is removed from an Album
void AlbumCardsModel
::onCardRemoved(const int &albumId,
const QString &cardId
) {
qDebug() << "[AlbumCardsModel] [called] [from signal] >> onCardRemoved(const int &albumId, const QString &cardId) || albumId: " << albumId << ", cardId: " << cardId;
// Do not proceed if the signaled Album change is not the active one
if (albumId != m_album.getAlbumId()) return;
qDebug() << "[AlbumCardsModel] [update] >> onCardRemoved(const int &albumId, const QString &cardId): albumId from signal matches current albumId";
// Retreive the updated Album from the AlbumsManager
const Album updatedAlbum = m_albumsManager->album(albumId);
const int row = updatedAlbum.getCardIDs().indexOf(cardId);
// replace the Model's active Album with the updated Album
m_album = updatedAlbum;
endRemoveRows();
qDebug() << "[AlbumCardsModel] [update] >> onCardRemoved(const int &albumId, const QString &cardId): current album updated";
}
#include "albumcardsmodel.h"
AlbumCardsModel::AlbumCardsModel(QObject *parent)
: AbstractCardModel(parent)
{
qDebug() << "[AlbumCardsModel] [called] [Default Constructor]";
this->m_albumsManager = nullptr;
this->m_cardsManager = nullptr;
}
AlbumCardsModel::AlbumCardsModel( AlbumsManager* albumsManager, CardsManager* cardsManager, QObject *parent)
: AbstractCardModel(cardsManager, parent)
{
qDebug() << "[AlbumCardsModel] [called] [Overloaded Constructor]";
this->m_albumsManager = albumsManager;
this->m_cardsManager = cardsManager;
}
// Show a specific Album
void AlbumCardsModel::showAlbum(const int &albumId)
{
qDebug() << "[AlbumCardsModel] [called] >> showAlbum(const int &albumId) || albumId: " << albumId;
// Get the requested Album from AlbumsManager and set it as the current active one.
beginResetModel();
m_album = m_albumsManager->album(albumId);
endResetModel();
}
// Get the number of Cards in the Active Album
int AlbumCardsModel::rowCount(const QModelIndex&) const
{
qDebug() << "[AlbumCardsModel] [called] >> rowCount(const QModelIndex&)";
return m_album.getCardIDs().count();
}
// Get the card object at the specified position in the Album
Card AlbumCardsModel::cardForIndex(const QModelIndex &index) const
{
qDebug() << "[AlbumCardsModel] [called] >> cardForIndex(const QModelIndex &index)";
return m_cardsManager->card(m_album.getCardIDs().at(index.row()));
}
// Receives a signal from the AlbumsManager when an Album is removed
void AlbumCardsModel::onAlbumRemoved(const int &albumId)
{
qDebug() << "[AlbumCardsModel] [called] [from signal] >> onAlbumRemoved(const int &albumId) || albumId: " << albumId;
// Do not proceed if the signaled Album change is not the active one
if (albumId != m_album.getAlbumId()) return;
qDebug() << "[AlbumCardsModel] [update] >> onAlbumRemoved(const int &albumId) || albumId from signal matches current albumId.";
// replace the Model's active Album with a Default Album
beginResetModel();
m_album = Album();
endResetModel();
qDebug() << "[AlbumCardsModel] [update] >> onAlbumRemoved(const int &albumId) || Current album replaced with default constructed album.";
}
// Receives a signal from the AlbumsManager when a Card is added to an Album
void AlbumCardsModel::onCardAdded(const int &albumId, const QString &cardId)
{
qDebug() << "[AlbumCardsModel] [called] [from signal] >> onCardAdded(const int &albumId, const QString &cardId) || albumId: " << albumId << ", cardId: " << cardId;
// Do not proceed if the signaled Album change is not the active one
if (albumId != m_album.getAlbumId()) return;
qDebug() << "[AlbumCardsModel] [update] >> onCardAdded(const int &albumId, const QString &cardId) || albumId from signal matches current albumId";
// Retreive the updated Album from the AlbumsManager
const Album updatedAlbum = m_albumsManager->album(albumId);
const int row = updatedAlbum.getCardIDs().indexOf(cardId);
// replace the Model's active Album with the updated Album
beginInsertRows(QModelIndex(), row, row);
m_album = updatedAlbum;
endInsertRows();
qDebug() << "[AlbumCardsModel] [update] >> onCardAdded(const int &albumId, const QString &cardId) || current album updated";
}
// Receives a signal from the AlbumsManager when a Card is removed from an Album
void AlbumCardsModel::onCardRemoved(const int &albumId, const QString &cardId)
{
qDebug() << "[AlbumCardsModel] [called] [from signal] >> onCardRemoved(const int &albumId, const QString &cardId) || albumId: " << albumId << ", cardId: " << cardId;
// Do not proceed if the signaled Album change is not the active one
if (albumId != m_album.getAlbumId()) return;
qDebug() << "[AlbumCardsModel] [update] >> onCardRemoved(const int &albumId, const QString &cardId): albumId from signal matches current albumId";
// Retreive the updated Album from the AlbumsManager
const Album updatedAlbum = m_albumsManager->album(albumId);
const int row = updatedAlbum.getCardIDs().indexOf(cardId);
// replace the Model's active Album with the updated Album
beginRemoveRows(QModelIndex(), row, row);
m_album = updatedAlbum;
endRemoveRows();
qDebug() << "[AlbumCardsModel] [update] >> onCardRemoved(const int &albumId, const QString &cardId): current album updated";
}
To copy to clipboard, switch view to plain text mode
AlbumsManager:
#ifndef ALBUMSMANAGER_H
#define ALBUMSMANAGER_H
#include "album.h"
#include "card.h"
#include <QObject>
#include <QString>
#include <QVariant>
#include <QList>
#include <QDebug>
#include <QAbstractListModel>
#include <QQmlListProperty>
#include <QModelIndex>
/* This class manages the Albums used by the program.
* It contains all instances of Album objects and provides
* signals to views when a change to any of them has been
* made in order to refresh the views.
* AlbumsManager enherits from QAbstractList model to better manage
* the row insertion & removal in it's list of Albums. */
class AlbumsManager
/* : public QAbstractListModel*/ : public QObject{
Q_OBJECT // Used to register Type
public:
// Default Constructor
AlbumsManager
(QObject* parent
= 0);
// Copy Constructor
AlbumsManager(const AlbumsManager& source);
// Assignment Operator
AlbumsManager& operator=(const AlbumsManager& source);
// Retreives a specific Album from it's list
Album album(const int &id) const;
// Retreives all Albums in it's list
QList<Album> albums() const;
// Gets the nr. of Albums in it's list
Q_INVOKABLE int count() const;
// Creates a new Album and adds it to the list
Q_INVOKABLE
void createAlbum
(const QString &name
);
// Add or remove specific Card to specified Album
Q_INVOKABLE
void addCard
(const int &albumId,
const QString &cardId
);
Q_INVOKABLE
void removeCard
(const int &albumId,
const QString &cardId
);
// Default Destructor
~AlbumsManager();
signals:
// Signals to notify Model classes on changes
void albumAdded(const int &id);
void albumRemoved(const int &id);
void cardAdded
(const int &albumId,
const QStringList &cardIDs
);
void cardRemoved
(const int &albumId,
const QStringList &cardIDs
);
private:
int m_albumId; // Provides unique IDs for Album creation by incrementation
QList<int> m_albumIDs; // Holds list of used Album IDs
QList<Album> m_albums; // Holds instances of Album objects it manages
};
#endif // ALBUMSMANAGER_H
#ifndef ALBUMSMANAGER_H
#define ALBUMSMANAGER_H
#include "album.h"
#include "card.h"
#include <QObject>
#include <QString>
#include <QVariant>
#include <QList>
#include <QDebug>
#include <QAbstractListModel>
#include <QQmlListProperty>
#include <QModelIndex>
/* This class manages the Albums used by the program.
* It contains all instances of Album objects and provides
* signals to views when a change to any of them has been
* made in order to refresh the views.
* AlbumsManager enherits from QAbstractList model to better manage
* the row insertion & removal in it's list of Albums. */
class AlbumsManager/* : public QAbstractListModel*/ : public QObject
{
Q_OBJECT // Used to register Type
public:
// Default Constructor
AlbumsManager(QObject* parent = 0);
// Copy Constructor
AlbumsManager(const AlbumsManager& source);
// Assignment Operator
AlbumsManager& operator=(const AlbumsManager& source);
// Retreives a specific Album from it's list
Album album(const int &id) const;
// Retreives all Albums in it's list
QList<Album> albums() const;
// Gets the nr. of Albums in it's list
Q_INVOKABLE int count() const;
// Creates a new Album and adds it to the list
Q_INVOKABLE void createAlbum(const QString &name);
// Add or remove specific Card to specified Album
Q_INVOKABLE void addCard(const int &albumId, const QString &cardId);
Q_INVOKABLE void removeCard(const int &albumId, const QString &cardId);
// Default Destructor
~AlbumsManager();
signals:
// Signals to notify Model classes on changes
void albumAdded(const int &id);
void albumRemoved(const int &id);
void cardAdded(const int &albumId, const QStringList &cardIDs);
void cardRemoved(const int &albumId, const QStringList &cardIDs);
private:
int m_albumId; // Provides unique IDs for Album creation by incrementation
QList<int> m_albumIDs; // Holds list of used Album IDs
QList<Album> m_albums; // Holds instances of Album objects it manages
};
#endif // ALBUMSMANAGER_H
To copy to clipboard, switch view to plain text mode
#include "albumsmanager.h"
// Default Constructor
AlbumsManager
::AlbumsManager(QObject* parent
): /*QAbstractListModel(parent)*/ QObject(parent
){
// Instanciate variable used for providing unique Album IDs
this->m_albumId = 0;
// For debugging purposes
qDebug() << "[AlbumsManager] [called] [constructor] || m_albumId set to: " << m_albumId;
}
// Copy Constructor
AlbumsManager::AlbumsManager(const AlbumsManager& source)
{
qDebug() << "[AlbumsManager] [called] [Copy Constructor]";
this->m_albumId = source.m_albumId;
this->m_albumIDs = source.m_albumIDs;
this->m_albums = source.m_albums;
}
// Assignment Operator
AlbumsManager& AlbumsManager::operator=(const AlbumsManager& source)
{
qDebug() << "[AlbumsManager] [called] [Assignment Operator]";
if(this != &source)
{
this->m_albumId = source.m_albumId;
this->m_albumIDs = source.m_albumIDs;
this->m_albums = source.m_albums;
}
return *this;
}
// Retreives a specific Album from it's list
Album AlbumsManager::album(const int &id) const
{
// For debugging purposes
qDebug() << "[AlbumsManager] [called] >> album(const int &id) || id: " << id;
// Find if an album in the list matches the provided Album ID
int albumMatch;
bool albumFound = false;
for(int i = 0; i < this->count(); i++)
{
if(m_albums[i].getAlbumId() == id)
{
albumFound = true;
albumMatch = i;
}
}
// If a match has been found, return the matching Album
if(albumFound == true)
{
// For debugging purposes
qDebug() << "[AlbumsManager] [update] >> album(const int &id) || Match found: " << albumMatch;
qDebug() << "[AlbumsManager] [update] >> album(const int &id) || Returning Album Object";
return this->m_albums[albumMatch];
}
// If no match found, return a Default Album instance with no ID
else
{
// For debugging purposes
qDebug() << "[AlbumsManager] [update] >> album(const int &id) || No match found.";
qDebug() << "[AlbumsManager] [update] >> album(const int &id) || Returning New Default Constructed Album() object";
return Album();
}
}
// Retreives an Album Objects list of all the Albums in it's list
QList<Album> AlbumsManager::albums() const
{
// For debugging purposes
qDebug() << "[AlbumsManager] [called] >> albums()";
return this->m_albums;
}
// Gets the nr. of Albums in it's list
int AlbumsManager::count() const
{
// For debugging purposes
qDebug() << "[AlbumsManager] [called] >> count() || returned: " << m_albums.count();
return this->m_albums.count();
}
// Create new Album and Add it to the Album list this class manages
void AlbumsManager
::createAlbum(const QString &name
) {
// For debugging purposes
qDebug() << "[AlbumsManager] [called] >> createAlbum(const QString &name) || name: " + name;
// Create new ID for the new album
this->m_albumId++;
this->m_albumIDs.append(m_albumId);
qDebug() << "[AlbumsManager] [update] >> createAlbum(const QString &name) || Assigning albumId: " << m_albumId << " to newAlbum";
qDebug() << "[AlbumsManager] [update] >> createAlbum(const QString &name) || calling Overloaded Album constructor, name: " << name << ", m_albumId: " << m_albumId;
// Create album using new ID and user specified Album name
Album newAlbum(name,m_albumId);
// Add the new Album to the end of the Albums list
m_albums << newAlbum;
qDebug() << "[AlbumsManager] [update] >> createAlbum(const QString &name) || newAlbum appended to m_albums";
// Send signal to notify views about the change
albumAdded(m_albumId);
// // return the new Album
// return newAlbum;
}
// Add a specific Card to a specified Album
void AlbumsManager
::addCard(const int &albumId,
const QString &cardId
) {
// For debugging purposes
qDebug() << "[AlbumsManager] [called] >> addCard(const int &albumId, const QString &cardId) || albumId: " << albumId << ", cardId: " << cardId;
// Find if an album in the list matches the provided Album ID
bool albumFound = false;
int albumMatch;
for(int i = 0; i < this->count(); i++)
{
if(m_albums[i].getAlbumId() == albumId)
{
albumFound = true;
albumMatch = i;
}
}
// If a match has been found add specified card to it and send a signal to Models about the new change.
if(albumFound == true)
{
qDebug() << "[AlbumsManager] [update] >> addCard(const int &albumId, const QString &cardId) || A matching Album was found.";
this->m_albums[albumMatch].addCard(cardId);
cardAdded(albumId, m_albums[albumMatch].getCardIDs());
}
else
{
qDebug() << "[AlbumsManager] [update] >> addCard(const int &albumId, const QString &cardId) || No matching Albums were found";
}
}
// Remove a specific Card from a specified Album
void AlbumsManager
::removeCard(const int &albumId,
const QString &cardId
) {
// For debugging purposes
qDebug() << "[AlbumsManager] [called] >> removeCard(const int &albumId, const QString &cardId) || albumId: " << albumId << ", cardId: " << cardId;
// Find if an album in the list matches the provided Album ID
bool albumFound = false;
int albumMatch;
for(int i = 0; i < this->count(); i++)
{
if(m_albums[i].getAlbumId() == albumId)
{
albumFound = true;
albumMatch = i;
}
}
// If a match has been found remove specified card from it and send a signal to Models about the new change
if(albumFound == true)
{
qDebug() << "[AlbumsManager] [update] >> removeCard(const int &albumId, const QString &cardId) || A matching Album was found";
this->m_albums[albumMatch].removeCard(cardId);
cardRemoved(albumId, m_albums[albumMatch].getCardIDs());
}
else
{
qDebug() << "[AlbumsManager] [update] >> removeCard(const int &albumId, const QString &cardId) || No matching Albums were found";
}
}
// Default Destructor
AlbumsManager::~AlbumsManager()
{
// For debugging purposes
qDebug() << "[AlbumsManager] [called] [Destructor].";
}
#include "albumsmanager.h"
// Default Constructor
AlbumsManager::AlbumsManager(QObject* parent): /*QAbstractListModel(parent)*/ QObject(parent)
{
// Instanciate variable used for providing unique Album IDs
this->m_albumId = 0;
// For debugging purposes
qDebug() << "[AlbumsManager] [called] [constructor] || m_albumId set to: " << m_albumId;
}
// Copy Constructor
AlbumsManager::AlbumsManager(const AlbumsManager& source)
{
qDebug() << "[AlbumsManager] [called] [Copy Constructor]";
this->m_albumId = source.m_albumId;
this->m_albumIDs = source.m_albumIDs;
this->m_albums = source.m_albums;
}
// Assignment Operator
AlbumsManager& AlbumsManager::operator=(const AlbumsManager& source)
{
qDebug() << "[AlbumsManager] [called] [Assignment Operator]";
if(this != &source)
{
this->m_albumId = source.m_albumId;
this->m_albumIDs = source.m_albumIDs;
this->m_albums = source.m_albums;
}
return *this;
}
// Retreives a specific Album from it's list
Album AlbumsManager::album(const int &id) const
{
// For debugging purposes
qDebug() << "[AlbumsManager] [called] >> album(const int &id) || id: " << id;
// Find if an album in the list matches the provided Album ID
int albumMatch;
bool albumFound = false;
for(int i = 0; i < this->count(); i++)
{
if(m_albums[i].getAlbumId() == id)
{
albumFound = true;
albumMatch = i;
}
}
// If a match has been found, return the matching Album
if(albumFound == true)
{
// For debugging purposes
qDebug() << "[AlbumsManager] [update] >> album(const int &id) || Match found: " << albumMatch;
qDebug() << "[AlbumsManager] [update] >> album(const int &id) || Returning Album Object";
return this->m_albums[albumMatch];
}
// If no match found, return a Default Album instance with no ID
else
{
// For debugging purposes
qDebug() << "[AlbumsManager] [update] >> album(const int &id) || No match found.";
qDebug() << "[AlbumsManager] [update] >> album(const int &id) || Returning New Default Constructed Album() object";
return Album();
}
}
// Retreives an Album Objects list of all the Albums in it's list
QList<Album> AlbumsManager::albums() const
{
// For debugging purposes
qDebug() << "[AlbumsManager] [called] >> albums()";
return this->m_albums;
}
// Gets the nr. of Albums in it's list
int AlbumsManager::count() const
{
// For debugging purposes
qDebug() << "[AlbumsManager] [called] >> count() || returned: " << m_albums.count();
return this->m_albums.count();
}
// Create new Album and Add it to the Album list this class manages
void AlbumsManager::createAlbum(const QString &name)
{
// For debugging purposes
qDebug() << "[AlbumsManager] [called] >> createAlbum(const QString &name) || name: " + name;
// Create new ID for the new album
this->m_albumId++;
this->m_albumIDs.append(m_albumId);
qDebug() << "[AlbumsManager] [update] >> createAlbum(const QString &name) || Assigning albumId: " << m_albumId << " to newAlbum";
qDebug() << "[AlbumsManager] [update] >> createAlbum(const QString &name) || calling Overloaded Album constructor, name: " << name << ", m_albumId: " << m_albumId;
// Create album using new ID and user specified Album name
Album newAlbum(name,m_albumId);
// Add the new Album to the end of the Albums list
m_albums << newAlbum;
qDebug() << "[AlbumsManager] [update] >> createAlbum(const QString &name) || newAlbum appended to m_albums";
// Send signal to notify views about the change
albumAdded(m_albumId);
// // return the new Album
// return newAlbum;
}
// Add a specific Card to a specified Album
void AlbumsManager::addCard(const int &albumId, const QString &cardId)
{
// For debugging purposes
qDebug() << "[AlbumsManager] [called] >> addCard(const int &albumId, const QString &cardId) || albumId: " << albumId << ", cardId: " << cardId;
// Find if an album in the list matches the provided Album ID
bool albumFound = false;
int albumMatch;
for(int i = 0; i < this->count(); i++)
{
if(m_albums[i].getAlbumId() == albumId)
{
albumFound = true;
albumMatch = i;
}
}
// If a match has been found add specified card to it and send a signal to Models about the new change.
if(albumFound == true)
{
qDebug() << "[AlbumsManager] [update] >> addCard(const int &albumId, const QString &cardId) || A matching Album was found.";
this->m_albums[albumMatch].addCard(cardId);
cardAdded(albumId, m_albums[albumMatch].getCardIDs());
}
else
{
qDebug() << "[AlbumsManager] [update] >> addCard(const int &albumId, const QString &cardId) || No matching Albums were found";
}
}
// Remove a specific Card from a specified Album
void AlbumsManager::removeCard(const int &albumId, const QString &cardId)
{
// For debugging purposes
qDebug() << "[AlbumsManager] [called] >> removeCard(const int &albumId, const QString &cardId) || albumId: " << albumId << ", cardId: " << cardId;
// Find if an album in the list matches the provided Album ID
bool albumFound = false;
int albumMatch;
for(int i = 0; i < this->count(); i++)
{
if(m_albums[i].getAlbumId() == albumId)
{
albumFound = true;
albumMatch = i;
}
}
// If a match has been found remove specified card from it and send a signal to Models about the new change
if(albumFound == true)
{
qDebug() << "[AlbumsManager] [update] >> removeCard(const int &albumId, const QString &cardId) || A matching Album was found";
this->m_albums[albumMatch].removeCard(cardId);
cardRemoved(albumId, m_albums[albumMatch].getCardIDs());
}
else
{
qDebug() << "[AlbumsManager] [update] >> removeCard(const int &albumId, const QString &cardId) || No matching Albums were found";
}
}
// Default Destructor
AlbumsManager::~AlbumsManager()
{
// For debugging purposes
qDebug() << "[AlbumsManager] [called] [Destructor].";
}
To copy to clipboard, switch view to plain text mode
App:
#ifndef APP_H
#define APP_H
#include <QObject>
#include <QDebug>
#include <QString>
#include <QVariant>
#include <QList>
#include "album.h"
#include "card.h"
#include "albumsmanager.h"
#include "cardsmanager.h"
#include "albumcardsmodel.h"
#include "abstractcardmodel.h"
{
Q_OBJECT
public:
// Constructor
// Roles
enum AlbumRoles { albumNameRole = Qt::UserRole + 1 };
// Getters
AlbumsManager* getAlbumsManagerPointer();
CardsManager* getCardsManagerPointer();
AlbumCardsModel* getAlbumCardsModelPointer();
// Append
void addAlbum(const Album &album);
// Position
// Data from child items
// Destructor
~App();
protected:
// Role names
QHash<int, QByteArray> roleNames() const;
private:
// Children
QList<Album> m_albums;
// New
AlbumsManager m_albumsManager;
CardsManager m_cardsManager;
AlbumCardsModel m_albumCardsModel;
AlbumsManager* m_albumsManagerPointer;
CardsManager* m_cardsManagerPointer;
AlbumCardsModel* m_albumCardsModelPointer;
};
#endif // APP_H
#ifndef APP_H
#define APP_H
#include <QObject>
#include <QDebug>
#include <QString>
#include <QVariant>
#include <QList>
#include "album.h"
#include "card.h"
#include "albumsmanager.h"
#include "cardsmanager.h"
#include "albumcardsmodel.h"
#include "abstractcardmodel.h"
class App: public QObject
{
Q_OBJECT
public:
// Constructor
explicit App(QObject *parent = 0);
// Roles
enum AlbumRoles { albumNameRole = Qt::UserRole + 1 };
// Getters
AlbumsManager* getAlbumsManagerPointer();
CardsManager* getCardsManagerPointer();
AlbumCardsModel* getAlbumCardsModelPointer();
// Append
void addAlbum(const Album &album);
// Position
int rowCount(const QModelIndex & parent = QModelIndex()) const;
// Data from child items
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
// Destructor
~App();
protected:
// Role names
QHash<int, QByteArray> roleNames() const;
private:
// Children
QList<Album> m_albums;
// New
AlbumsManager m_albumsManager;
CardsManager m_cardsManager;
AlbumCardsModel m_albumCardsModel;
AlbumsManager* m_albumsManagerPointer;
CardsManager* m_cardsManagerPointer;
AlbumCardsModel* m_albumCardsModelPointer;
};
#endif // APP_H
To copy to clipboard, switch view to plain text mode
#include "app.h"
// Default Constructor
{
// For debugging purposes
qDebug() << "[App] [called] [Default Constructor]";
this->m_albumsManager = AlbumsManager();
this->m_albumsManagerPointer = &m_albumsManager;
this->m_cardsManager = CardsManager();
this->m_cardsManagerPointer = &m_cardsManager;
this->m_albumCardsModel = AlbumCardsModel(m_albumsManagerPointer, m_cardsManagerPointer);
this->m_albumCardsModelPointer = &m_albumCardsModel;
}
// Getters
AlbumsManager* App::getAlbumsManagerPointer()
{
return this->m_albumsManagerPointer;
}
CardsManager* App::getCardsManagerPointer()
{
return this->m_cardsManagerPointer;
}
AlbumCardsModel* App::getAlbumCardsModelPointer()
{
return this->m_albumCardsModelPointer;
}
// Append
void App::addAlbum(const Album &album)
{
// For debugging purposes
qDebug() << "[App] [called] >> addAlbum(const Album &album) || albumId: " << album.getAlbumId();
m_albums.append(album);
}
// Position
{
// For debugging purposes
qDebug() << "[App] [called] >> rowCount(const QModelIndex & parent) || Returning count: " << m_albums.count();
Q_UNUSED(parent);
return m_albums.count();
}
// Data
{
// For debugging purposes
qDebug() << "[App] [called] >> data(const QModelIndex & index, int role)";
if (index.row() < 0 || index.row() >= m_albums.count())
const Album &album = m_albums[index.row()];
if (role == albumNameRole)
return album.getAlbumName();
}
QHash<int, QByteArray> App::roleNames() const
{
// For debugging purposes
qDebug() << "[App] [called] >> roleNames()";
QHash<int, QByteArray> roles;
roles[albumNameRole] = "albumName";
return roles;
}
App::~App()
{
// For debugging purposes
qDebug() << "[App] [called] [Default Destructor]";
}
#include "app.h"
// Default Constructor
App::App(QObject *parent): QObject(parent)
{
// For debugging purposes
qDebug() << "[App] [called] [Default Constructor]";
this->m_albumsManager = AlbumsManager();
this->m_albumsManagerPointer = &m_albumsManager;
this->m_cardsManager = CardsManager();
this->m_cardsManagerPointer = &m_cardsManager;
this->m_albumCardsModel = AlbumCardsModel(m_albumsManagerPointer, m_cardsManagerPointer);
this->m_albumCardsModelPointer = &m_albumCardsModel;
}
// Getters
AlbumsManager* App::getAlbumsManagerPointer()
{
return this->m_albumsManagerPointer;
}
CardsManager* App::getCardsManagerPointer()
{
return this->m_cardsManagerPointer;
}
AlbumCardsModel* App::getAlbumCardsModelPointer()
{
return this->m_albumCardsModelPointer;
}
// Append
void App::addAlbum(const Album &album)
{
// For debugging purposes
qDebug() << "[App] [called] >> addAlbum(const Album &album) || albumId: " << album.getAlbumId();
m_albums.append(album);
}
// Position
int App::rowCount(const QModelIndex & parent) const
{
// For debugging purposes
qDebug() << "[App] [called] >> rowCount(const QModelIndex & parent) || Returning count: " << m_albums.count();
Q_UNUSED(parent);
return m_albums.count();
}
// Data
QVariant App::data(const QModelIndex & index, int role) const
{
// For debugging purposes
qDebug() << "[App] [called] >> data(const QModelIndex & index, int role)";
if (index.row() < 0 || index.row() >= m_albums.count())
return QVariant();
const Album &album = m_albums[index.row()];
if (role == albumNameRole)
return album.getAlbumName();
return QVariant();
}
QHash<int, QByteArray> App::roleNames() const
{
// For debugging purposes
qDebug() << "[App] [called] >> roleNames()";
QHash<int, QByteArray> roles;
roles[albumNameRole] = "albumName";
return roles;
}
App::~App()
{
// For debugging purposes
qDebug() << "[App] [called] [Default Destructor]";
}
To copy to clipboard, switch view to plain text mode
Card:
#ifndef CARD_H
#define CARD_H
#include <QString>
#include <QObject>
#include <QDebug>
{
private:
int number;
public:
// Default Constructor
// Overloaded Constructor
Card
(const QString &cardID,
const QString &name,
const QString &imageURL,
const QString &subtype,
const QString &supertype,
const int &number,
const QString &artist,
const QString &rarity,
const QString &series,
const QString &set,
const QString &setCode,
const QString &condition,
const QString &status,
QObject* parent
= 0);
// Copy Constructor
Card(const Card& source);
// Assignment Opperator
Card& operator=(const Card& source);
// GETTERS
int getNumber() const;
// SETTERS
void setCardID
(const QString newCardID
);
void setName
(const QString newName
);
void setImageURL
(const QString newImageURL
);
void setSubtype
(const QString newSubtype
);
void setSupertype
(const QString newSupertype
);
void setNumber(const int newNumber);
void setArtist
(const QString newArtist
);
void setRarity
(const QString newRarity
);
void setSeries
(const QString newSeries
);
void setSetCode
(const QString newSetCode
);
void setCondition
(const QString newCondition
);
void setStatus
(const QString newStatus
);
// Destructor
~Card();
};
#endif // CARD_H
#ifndef CARD_H
#define CARD_H
#include <QString>
#include <QObject>
#include <QDebug>
class Card : public QObject
{
private:
QString cardID;
QString name;
QString imageURL;
QString subtype;
QString supertype;
int number;
QString artist;
QString rarity;
QString series;
QString set;
QString setCode;
QString condition;
QString status;
public:
// Default Constructor
Card(QObject* parent = 0);
// Overloaded Constructor
Card(const QString &cardID, const QString &name, const QString &imageURL, const QString &subtype, const QString &supertype, const int &number, const QString &artist, const QString &rarity, const QString &series, const QString &set, const QString &setCode, const QString &condition, const QString &status, QObject* parent = 0);
// Copy Constructor
Card(const Card& source);
// Assignment Opperator
Card& operator=(const Card& source);
// GETTERS
QString getCardID() const;
QString getName() const;
QString getImageURL() const;
QString getSubtype() const;
QString getSupertype() const;
int getNumber() const;
QString getArtist() const;
QString getRarity() const;
QString getSeries() const;
QString getSet() const;
QString getSetCode() const;
QString getCondition() const;
QString getStatus() const;
// SETTERS
void setCardID(const QString newCardID);
void setName(const QString newName);
void setImageURL(const QString newImageURL);
void setSubtype(const QString newSubtype);
void setSupertype(const QString newSupertype);
void setNumber(const int newNumber);
void setArtist(const QString newArtist);
void setRarity(const QString newRarity);
void setSeries(const QString newSeries);
void setSet(const QString newSet);
void setSetCode(const QString newSetCode);
void setCondition(const QString newCondition);
void setStatus(const QString newStatus);
// Destructor
~Card();
};
#endif // CARD_H
To copy to clipboard, switch view to plain text mode
#include "card.h"
// Default Constructor
{
// For debugging purposes
qDebug() << "[Card] [called] [Default Constructor]";
}
// Overloaded Constructor
Card
::Card(const QString &newCardID,
const QString &newName,
const QString &newImageURL,
const QString &newSubtype,
const QString &newSupertype,
const int &newNumber,
const QString &newArtist,
const QString &newRarity,
const QString &newSeries,
const QString &newSet,
const QString &newSetCode,
const QString &newCondition,
const QString &newStatus,
QObject* parent
): QObject(parent
){
// For debugging purposes
qDebug() << "[Card] [called] [Overloaded Constructor] || newCardID: " << newCardID << ", newName: " << newName << ", newImageURL: " << newImageURL << ", newSubtype: " << newSubtype << ", newSupertype: " << newSupertype << ", newNumber: " << newNumber << ", newArtist: " << newArtist << ", newRarity: " << newRarity << ", newSeries: " << newSeries << ", newSet: " << newSet << ", newSetCode: " << newSetCode << ", newCondition: " << newCondition << ", newStatus: " << newStatus;
this->cardID = newCardID;
this->name = newName;
this->imageURL = newImageURL;
this->subtype = newSubtype;
this->supertype = newSupertype;
this->number = newNumber;
this->artist = newArtist;
this->rarity = newRarity;
this->series = newSeries;
this->set = newSet;
this->setCode = newSetCode;
this->condition = newCondition;
this->status = newStatus;
}
// Copy Constructor
Card::Card(const Card& source)
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] [Copy Constructor]";
this->cardID = source.cardID;
this->name = source.name;
this->imageURL = source.imageURL;
this->subtype = source.subtype;
this->supertype = source.supertype;
this->number = source.number;
this->artist = source.artist;
this->rarity = source.rarity;
this->series = source.series;
this->set = source.set;
this->setCode = source.setCode;
this->condition = source.condition;
this->status = source.status;
}
// Assignment Opperator
Card& Card::operator=(const Card& source)
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] [Assignment opperator] || source.cardID: " << source.cardID << ", source.name: " << source.name << ", source.imageURL: " << source.imageURL << ", source.subtype: " << source.subtype << ", source.supertype: " << source.supertype << ", source.number: " << source.number << ", source.artist: " << source.artist << ", source.rarity: " << source.rarity << ", source.series: " << source.series << ", source.set: " << source.set << ", source.setCode: " << source.setCode << ", source.condition: " << source.condition << ", source.status: " << source.status;
if(this != &source)
{
this->cardID = source.cardID;
this->name = source.name;
this->imageURL = source.imageURL;
this->subtype = source.subtype;
this->supertype = source.supertype;
this->number = source.number;
this->artist = source.artist;
this->rarity = source.artist;
this->series = source.series;
this->set = source.set;
this->setCode = source.setCode;
this->condition = source.condition;
this->status = source.status;
}
return *this;
}
// GETTERS
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> getCardID() || cardID: " << cardID;
return this->cardID;
}
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> getName() || name: " << name;
return this->name;
}
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> getImageURL() || imageURL: " << imageURL;
return this->imageURL;
}
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> getSubtype() || subtype: " << subtype;
return this->subtype;
}
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> getSupertype() || supertype: " << supertype;
return this->supertype;
}
int Card::getNumber() const
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> getNumber() || number: " << number;
return this->number;
}
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> getArtist() || artist: " << artist;
return this->artist;
}
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> getRarity() || rarity: " << rarity;
return this->rarity;
}
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> getSeries() || series: " << series;
return this->series;
}
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> getSet() || set: " << set;
return this->set;
}
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> getSetCode() || setCode: " << setCode;
return this->setCode;
}
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> getCondition() || condition: " << condition;
return this->condition;
}
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> getStatus() || status: " << status;
return this->status;
}
// SETTERS
void Card
::setCardID(const QString newCardID
) {
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> setCardID(const QString newCardID) || newCardID: " << newCardID;
this->cardID = newCardID;
}
void Card
::setName(const QString newName
) {
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> setName(const QString newName) || newName: " << newName;
this->name = newName;
}
void Card
::setImageURL(const QString newImageURL
) {
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> setImageURL(const QString newImageURL) || newImageURL: " << newImageURL;
this->imageURL = newImageURL;
}
void Card
::setSubtype(const QString newSubtype
) {
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> setSubtype(const QString newSubtype) || newSubtype: " << newSubtype;
this->subtype = newSubtype;
}
void Card
::setSupertype(const QString newSupertype
) {
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> setSupertype(const QString newSupertype) || newSupertype: " << newSupertype;
this->supertype = newSupertype;
}
void Card::setNumber(const int newNumber)
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> setNumber(const int newNumber) || newNumber: " << newNumber;
this->number = newNumber;
}
void Card
::setArtist(const QString newArtist
) {
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> setArtist(const QString newArtist) || newArtist: " << newArtist;
this->artist = newArtist;
}
void Card
::setRarity(const QString newRarity
) {
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> setRarity(const QString newRarity) || newRarity: " << newRarity;
this->rarity = newRarity;
}
void Card
::setSeries(const QString newSeries
) {
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> setSeries(const QString newSeries) || newSeries: " << newSeries;
this->series = newSeries;
}
void Card
::setSet(const QString newSet
) {
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> setSet(const QString newSet) || newSet: " << newSet;
this->set = newSet;
}
void Card
::setSetCode(const QString newSetCode
) {
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> setSetCode(const QString newSetCode) || setCode: " << setCode;
this->setCode = newSetCode;
}
void Card
::setCondition(const QString newCondition
) {
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> setCondition(const QString newCondition) || newCondition: " << newCondition;
this->condition = newCondition;
}
void Card
::setStatus(const QString newStatus
) {
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> setStatus(const QString newStatus) || newStatus: " << newStatus;
this->status = newStatus;
}
// Destructor
Card::~Card()
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] [Destructor]";
}
#include "card.h"
// Default Constructor
Card::Card(QObject* parent): QObject(parent)
{
// For debugging purposes
qDebug() << "[Card] [called] [Default Constructor]";
}
// Overloaded Constructor
Card::Card(const QString &newCardID, const QString &newName, const QString &newImageURL, const QString &newSubtype, const QString &newSupertype, const int &newNumber, const QString &newArtist, const QString &newRarity, const QString &newSeries, const QString &newSet, const QString &newSetCode, const QString &newCondition, const QString &newStatus, QObject* parent): QObject(parent)
{
// For debugging purposes
qDebug() << "[Card] [called] [Overloaded Constructor] || newCardID: " << newCardID << ", newName: " << newName << ", newImageURL: " << newImageURL << ", newSubtype: " << newSubtype << ", newSupertype: " << newSupertype << ", newNumber: " << newNumber << ", newArtist: " << newArtist << ", newRarity: " << newRarity << ", newSeries: " << newSeries << ", newSet: " << newSet << ", newSetCode: " << newSetCode << ", newCondition: " << newCondition << ", newStatus: " << newStatus;
this->cardID = newCardID;
this->name = newName;
this->imageURL = newImageURL;
this->subtype = newSubtype;
this->supertype = newSupertype;
this->number = newNumber;
this->artist = newArtist;
this->rarity = newRarity;
this->series = newSeries;
this->set = newSet;
this->setCode = newSetCode;
this->condition = newCondition;
this->status = newStatus;
}
// Copy Constructor
Card::Card(const Card& source)
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] [Copy Constructor]";
this->cardID = source.cardID;
this->name = source.name;
this->imageURL = source.imageURL;
this->subtype = source.subtype;
this->supertype = source.supertype;
this->number = source.number;
this->artist = source.artist;
this->rarity = source.rarity;
this->series = source.series;
this->set = source.set;
this->setCode = source.setCode;
this->condition = source.condition;
this->status = source.status;
}
// Assignment Opperator
Card& Card::operator=(const Card& source)
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] [Assignment opperator] || source.cardID: " << source.cardID << ", source.name: " << source.name << ", source.imageURL: " << source.imageURL << ", source.subtype: " << source.subtype << ", source.supertype: " << source.supertype << ", source.number: " << source.number << ", source.artist: " << source.artist << ", source.rarity: " << source.rarity << ", source.series: " << source.series << ", source.set: " << source.set << ", source.setCode: " << source.setCode << ", source.condition: " << source.condition << ", source.status: " << source.status;
if(this != &source)
{
this->cardID = source.cardID;
this->name = source.name;
this->imageURL = source.imageURL;
this->subtype = source.subtype;
this->supertype = source.supertype;
this->number = source.number;
this->artist = source.artist;
this->rarity = source.artist;
this->series = source.series;
this->set = source.set;
this->setCode = source.setCode;
this->condition = source.condition;
this->status = source.status;
}
return *this;
}
// GETTERS
QString Card::getCardID() const
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> getCardID() || cardID: " << cardID;
return this->cardID;
}
QString Card::getName() const
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> getName() || name: " << name;
return this->name;
}
QString Card::getImageURL() const
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> getImageURL() || imageURL: " << imageURL;
return this->imageURL;
}
QString Card::getSubtype() const
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> getSubtype() || subtype: " << subtype;
return this->subtype;
}
QString Card::getSupertype() const
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> getSupertype() || supertype: " << supertype;
return this->supertype;
}
int Card::getNumber() const
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> getNumber() || number: " << number;
return this->number;
}
QString Card::getArtist() const
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> getArtist() || artist: " << artist;
return this->artist;
}
QString Card::getRarity() const
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> getRarity() || rarity: " << rarity;
return this->rarity;
}
QString Card::getSeries() const
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> getSeries() || series: " << series;
return this->series;
}
QString Card::getSet() const
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> getSet() || set: " << set;
return this->set;
}
QString Card::getSetCode() const
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> getSetCode() || setCode: " << setCode;
return this->setCode;
}
QString Card::getCondition() const
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> getCondition() || condition: " << condition;
return this->condition;
}
QString Card::getStatus() const
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> getStatus() || status: " << status;
return this->status;
}
// SETTERS
void Card::setCardID(const QString newCardID)
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> setCardID(const QString newCardID) || newCardID: " << newCardID;
this->cardID = newCardID;
}
void Card::setName(const QString newName)
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> setName(const QString newName) || newName: " << newName;
this->name = newName;
}
void Card::setImageURL(const QString newImageURL)
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> setImageURL(const QString newImageURL) || newImageURL: " << newImageURL;
this->imageURL = newImageURL;
}
void Card::setSubtype(const QString newSubtype)
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> setSubtype(const QString newSubtype) || newSubtype: " << newSubtype;
this->subtype = newSubtype;
}
void Card::setSupertype(const QString newSupertype)
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> setSupertype(const QString newSupertype) || newSupertype: " << newSupertype;
this->supertype = newSupertype;
}
void Card::setNumber(const int newNumber)
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> setNumber(const int newNumber) || newNumber: " << newNumber;
this->number = newNumber;
}
void Card::setArtist(const QString newArtist)
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> setArtist(const QString newArtist) || newArtist: " << newArtist;
this->artist = newArtist;
}
void Card::setRarity(const QString newRarity)
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> setRarity(const QString newRarity) || newRarity: " << newRarity;
this->rarity = newRarity;
}
void Card::setSeries(const QString newSeries)
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> setSeries(const QString newSeries) || newSeries: " << newSeries;
this->series = newSeries;
}
void Card::setSet(const QString newSet)
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> setSet(const QString newSet) || newSet: " << newSet;
this->set = newSet;
}
void Card::setSetCode(const QString newSetCode)
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> setSetCode(const QString newSetCode) || setCode: " << setCode;
this->setCode = newSetCode;
}
void Card::setCondition(const QString newCondition)
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> setCondition(const QString newCondition) || newCondition: " << newCondition;
this->condition = newCondition;
}
void Card::setStatus(const QString newStatus)
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] >> setStatus(const QString newStatus) || newStatus: " << newStatus;
this->status = newStatus;
}
// Destructor
Card::~Card()
{
// For debugging purposes
qDebug() << "[Card] [called] [cardID:" << cardID << "] [Destructor]";
}
To copy to clipboard, switch view to plain text mode
CardsManager:
#ifndef CARDSMANAGER_H
#define CARDSMANAGER_H
#include <QObject>
#include <QString>
#include <QFile>
#include <QDebug>
#include <QTextStream>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
#include <QAbstractListModel>
#include "card.h"
class CardsManager
/*: public QAbstractListModel*/ : public QObject{
Q_OBJECT
public:
// Default Constructor
// Copy Constructor
CardsManager(const CardsManager& source);
// Assignment Operator
CardsManager& operator=(const CardsManager& source);
// returns an invalid card if ID is not found, e.g. Card object with empty "id"
Card addCardById
(const QString &id
);
Card addCardByName
(const QString &newName
);
Card card
(const QString &id
) const;
QList<Card> cards() const;
int count() const;
signals:
void cardRemoved
(const QString &id
);
protected:
QHash<QString, int> nameToId() const;
private:
QList<Card> m_cards;
};
#endif // CARDSMANAGER_H
#ifndef CARDSMANAGER_H
#define CARDSMANAGER_H
#include <QObject>
#include <QString>
#include <QFile>
#include <QDebug>
#include <QTextStream>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
#include <QAbstractListModel>
#include "card.h"
class CardsManager /*: public QAbstractListModel*/ : public QObject
{
Q_OBJECT
public:
// Default Constructor
CardsManager(QObject* parent = 0);
// Copy Constructor
CardsManager(const CardsManager& source);
// Assignment Operator
CardsManager& operator=(const CardsManager& source);
// returns an invalid card if ID is not found, e.g. Card object with empty "id"
Card addCardById(const QString &id);
Card addCardByName(const QString &newName);
Card card(const QString &id) const;
QList<Card> cards() const;
int count() const;
signals:
void cardAdded(const QString &id);
void cardRemoved(const QString &id);
protected:
QHash<QString, int> nameToId() const;
private:
QList<Card> m_cards;
};
#endif // CARDSMANAGER_H
To copy to clipboard, switch view to plain text mode
#include "cardsmanager.h"
// Default Constructor
{
// For debugging purposes
qDebug() << "[CardsManager] [called] [Default constructor]";
}
// Copy Constructor
CardsManager::CardsManager(const CardsManager& source)
{
qDebug() << "[CardsManager] [called] [Copy Constructor]";
this->m_cards = source.m_cards;
}
// Assignment Operator
CardsManager& CardsManager::operator=(const CardsManager& source)
{
qDebug() << "[CardsManager] [called] [Assignment Operator]";
if(this != &source)
{
this->m_cards = source.m_cards;
}
return *this;
}
Card CardsManager
::addCardById(const QString &id
){
// For debugging purposes
qDebug() << "[CardsManager] [called] >> addCardById(const QString &id) || id: " << id;
// Card info
int number;
QString condition
= "Not specified";
// Build file name
QString fileName
= ":/cards/Resources/JSON/xy7-";
fileName.append(id);
fileName.append(".json");
// Open file
{
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardById(const QString &id) || Error: Could not open file for reading. fileName: " << fileName;
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardById(const QString &id) || Returning Card()";
return Card();
}
// Save file information in fileText
// Close file
file.close();
// Create card jsonObject from fileText
QJsonDocument jsonDocument = QJsonDocument::fromJson(fileText.toUtf8());
QJsonObject rootObject = jsonDocument.object();
QJsonValue value
= rootObject.
value(QString("card"));
QJsonObject cardRootValues = value.toObject();
// Set values for card variables
name = cardRootValues.value("name").toString();
cardId = cardRootValues.value("id").toString();
subtype = cardRootValues.value("subtype").toString();
supertype = cardRootValues.value("supertype").toString();
nrString = cardRootValues.value("number").toString();
number = nrString.toInt();
artist = cardRootValues.value("artist").toString();
rarity = cardRootValues.value("rarity").toString();
series = cardRootValues.value("series").toString();
set = cardRootValues.value("set").toString();
setCode = cardRootValues.value("setCode").toString();
imageUrl = cardRootValues.value("imageURL").toString();
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardById(const QString &id) || Calling Overloaded Card Constructor";
// Create Card instance from variables
Card newCard(cardId, name, imageUrl, subtype, supertype, number, artist, rarity, series, set, setCode, condition, status);
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardById(const QString &id) || newCard created. cardId: " << cardId << ", name: " << name << ", imageUrl: " << imageUrl << ", subtype: " << subtype << ", supertype: " << supertype << ", number: " << number << ", artist: " << artist << ", rarity: " << rarity << ", series: " << series << ", set: " << set << ", setCode: " << setCode << ", condition: " << condition << ", status: " << status;
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardById(const QString &id) || Adding card: " << cardId << " to m_cards.";
// Add newly created Card to Card's list
m_cards << newCard;
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardById(const QString &id) || Card: " << cardId << " added to m_cards.";
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardById(const QString &id) || Calling cardAdded signal for Card: " << cardId << ", returning the card object.";
cardAdded(cardId);
return newCard;
}
#include "cardsmanager.h"
// Default Constructor
CardsManager::CardsManager(QObject* parent): QObject(parent)
{
// For debugging purposes
qDebug() << "[CardsManager] [called] [Default constructor]";
}
// Copy Constructor
CardsManager::CardsManager(const CardsManager& source)
{
qDebug() << "[CardsManager] [called] [Copy Constructor]";
this->m_cards = source.m_cards;
}
// Assignment Operator
CardsManager& CardsManager::operator=(const CardsManager& source)
{
qDebug() << "[CardsManager] [called] [Assignment Operator]";
if(this != &source)
{
this->m_cards = source.m_cards;
}
return *this;
}
Card CardsManager::addCardById(const QString &id)
{
// For debugging purposes
qDebug() << "[CardsManager] [called] >> addCardById(const QString &id) || id: " << id;
// Card info
int number;
QString nrString;
QString name;
QString cardId;
QString subtype;
QString supertype;
QString artist;
QString rarity;
QString series;
QString set;
QString setCode;
QString imageUrl;
QString status = "Not specified";
QString condition = "Not specified";
// Build file name
QString fileName = ":/cards/Resources/JSON/xy7-";
fileName.append(id);
fileName.append(".json");
// Open file
QFile file(fileName);
if(!file.open(QFile::ReadOnly | QFile::Text))
{
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardById(const QString &id) || Error: Could not open file for reading. fileName: " << fileName;
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardById(const QString &id) || Returning Card()";
return Card();
}
// Save file information in fileText
QTextStream in(&file);
QString fileText = in.readAll();
// Close file
file.close();
// Create card jsonObject from fileText
QJsonDocument jsonDocument = QJsonDocument::fromJson(fileText.toUtf8());
QJsonObject rootObject = jsonDocument.object();
QJsonValue value = rootObject.value(QString("card"));
QJsonObject cardRootValues = value.toObject();
// Set values for card variables
name = cardRootValues.value("name").toString();
cardId = cardRootValues.value("id").toString();
subtype = cardRootValues.value("subtype").toString();
supertype = cardRootValues.value("supertype").toString();
nrString = cardRootValues.value("number").toString();
number = nrString.toInt();
artist = cardRootValues.value("artist").toString();
rarity = cardRootValues.value("rarity").toString();
series = cardRootValues.value("series").toString();
set = cardRootValues.value("set").toString();
setCode = cardRootValues.value("setCode").toString();
imageUrl = cardRootValues.value("imageURL").toString();
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardById(const QString &id) || Calling Overloaded Card Constructor";
// Create Card instance from variables
Card newCard(cardId, name, imageUrl, subtype, supertype, number, artist, rarity, series, set, setCode, condition, status);
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardById(const QString &id) || newCard created. cardId: " << cardId << ", name: " << name << ", imageUrl: " << imageUrl << ", subtype: " << subtype << ", supertype: " << supertype << ", number: " << number << ", artist: " << artist << ", rarity: " << rarity << ", series: " << series << ", set: " << set << ", setCode: " << setCode << ", condition: " << condition << ", status: " << status;
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardById(const QString &id) || Adding card: " << cardId << " to m_cards.";
// Add newly created Card to Card's list
m_cards << newCard;
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardById(const QString &id) || Card: " << cardId << " added to m_cards.";
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardById(const QString &id) || Calling cardAdded signal for Card: " << cardId << ", returning the card object.";
cardAdded(cardId);
return newCard;
}
To copy to clipboard, switch view to plain text mode
CardsManager.cpp continuation:
Card CardsManager
::addCardByName(const QString &newName
){
// For debugging purposes
qDebug() << "[CardsManager] [called] >> addCardByName(const QString &newName) || newName: " << newName;
// Card info
int number;
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardByName(const QString &newName) || calling nameToId().value(newName)";
// Build file name
QString fileName
= ":/cards/Resources/JSON/xy7-";
QString id
= nameToId
().
value(newName
);
fileName.append(id);
fileName.append(".json");
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardByName(const QString &newName) || nameToId().value(newName) returned id: " << id;
qDebug() << "[CardsManager] [update] >> addCardByName(const QString &newName) || fileName built, fileName: " << fileName;
// Open file
{
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardByName(const QString &newName) || Error: Could not open file for reading. fileName: " << fileName;
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardByName(const QString &newName) || Returning Card()";
return Card();
}
// Save file information in fileText
// Close file
file.close();
// Create card jsonObject from fileText
QJsonDocument jsonDocument = QJsonDocument::fromJson(fileText.toUtf8());
QJsonObject rootObject = jsonDocument.object();
QJsonValue value
= rootObject.
value(QString("card"));
QJsonObject cardRootValues = value.toObject();
// Set values for card variables
name = cardRootValues.value("name").toString();
cardId = cardRootValues.value("id").toString();
subtype = cardRootValues.value("subtype").toString();
supertype = cardRootValues.value("supertype").toString();
nrString = cardRootValues.value("number").toString();
number = nrString.toInt();
artist = cardRootValues.value("artist").toString();
rarity = cardRootValues.value("rarity").toString();
series = cardRootValues.value("series").toString();
set = cardRootValues.value("set").toString();
setCode = cardRootValues.value("setCode").toString();
imageUrl = cardRootValues.value("imageURL").toString();
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardByName(const QString &newName) || Calling Overloaded Card Constructor";
// Create Card instance from variables
Card newCard(cardId, name, imageUrl, subtype, supertype, number, artist, rarity, series, set, setCode, condition, status);
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardByName(const QString &newName) || newCard created. cardId: " << cardId << ", name: " << name << ", imageUrl: " << imageUrl << ", subtype: " << subtype << ", supertype: " << supertype << ", number: " << number << ", artist: " << artist << ", rarity: " << rarity << ", series: " << series << ", set: " << set << ", setCode: " << setCode << ", condition: " << condition << ", status: " << status;
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardByName(const QString &newName) || Adding card: " << cardId << " to m_cards.";
// Add created Card to Card List
m_cards << newCard;
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardByName(const QString &newName) || Card: " << cardId << " added to m_cards.";
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardByName(const QString &newName) || Calling cardAdded signal for Card: " << cardId << ", returning the card object.";
cardAdded(cardId);
return newCard;
}
Card CardsManager
::card(const QString &id
) const{
// For debugging purposes
qDebug() << "[CardsManager] [called] >> card(const QString &id) || id: " << id;
bool matchFound = false;
int match = -1;
for(int i = 0; i < m_cards.count(); i++)
{
if(m_cards[i].getCardID() == id)
{
matchFound = true;
match = i;
}
}
if(matchFound == true)
{
// For debugging purposes
qDebug() << "[CardsManager] [update] >> card(const QString &id) || Matching card found, returning Card from list m_cards[match], match: " << match;
return m_cards[match];
}
else
{
// For debugging purposes
qDebug() << "[CardsManager] [update] >> card(const QString &id) || No matching card found, returning Card().";
return Card();
}
}
QList<Card> CardsManager::cards() const
{
// For debugging purposes
qDebug() << "[CardsManager] [called] >> cards() || Returning m_cards";
return m_cards;
}
int CardsManager::count() const
{
// For debugging purposes
qDebug() << "[CardsManager] [called] >> count() || Returning count: " << m_cards.count();
return this->m_cards.count();
}
QHash<QString, int> CardsManager::nameToId() const
{
// For debugging purposes
qDebug() << "[CardsManager] [called] >> nameToId()";
QHash<QString, int> name;
name["Oddish"] = 1;
name["Gloom"] = 2;
name["Vileplume"] = 3;
name["Bellossom"] = 4;
name["Spinarak"] = 5;
name["Ariados"] = 6;
name["Sceptile-EX"] = 7;
name["M Sceptile-EX"] = 8;
name["Combee"] = 9;
name["Vespiquen"] = 10;
name["Vespiquen"] = 11;
name["Virizion"] = 12;
name["Flareon"] = 13;
name["Entei"] = 14;
name["Entei"] = 15;
name["Larvesta"] = 16;
name["Volcarona"] = 17;
name["Volcarona"] = 18;
name["Magikarp"] = 19;
name["Gyarados"] = 20;
name["Gyarados"] = 21;
name["Vaporeon"] = 22;
name["Relicanth"] = 23;
name["Regice"] = 24;
name["Kyurem-EX"] = 25;
name["Jolteon"] = 26;
name["Ampharos-EX"] = 27;
name["M Ampharos-EX"] = 28;
name["Rotom"] = 29;
name["Unown"] = 30;
name["Baltoy"] = 31;
name["Baltoy"] = 32;
name["Claydol"] = 33;
name["Golett"] = 34;
name["Golurk"] = 35;
name["Hoopa-EX"] = 36;
name["Machamp-EX"] = 37;
name["Wooper"] = 38;
name["Quagsire"] = 39;
name["Regirock"] = 40;
name["Golurk"] = 41;
name["Tyranitar-EX"] = 42;
name["M Tyranitar-EX"] = 43;
name["Sableye"] = 44;
name["Inkay"] = 45;
name["Malamar"] = 46;
name["Beldum"] = 47;
name["Metang"] = 48;
name["Metagross"] = 49;
name["Metagross"] = 50;
name["Registeel"] = 51;
name["Ralts"] = 52;
name["Kirlia"] = 53;
name["Gardevoir"] = 54;
name["Cottonee"] = 55;
name["Whimsicott"] = 56;
name["Giratina-EX"] = 57;
name["Goomy"] = 58;
name["Sliggoo"] = 59;
name["Goodra"] = 60;
name["Meowth"] = 61;
name["Persian"] = 62;
name["Eevee"] = 63;
name["Porygon"] = 64;
name["Porygon2"] = 65;
name["Porygon-Z"] = 66;
name["Porygon-Z"] = 67;
name["Lugia-EX"] = 68;
name["Ace Trainer"] = 69;
name["Ampharos Spirit Link"] = 70;
name["Eco Arm"] = 71;
name["Energy Recycler"] = 72;
name["Faded Town"] = 73;
name["Forest of Giant Plants"] = 74;
name["Hex Maniac"] = 75;
name["Level Ball"] = 76;
name["Lucky Helmet"] = 77;
name["Lysandre"] = 78;
name["Paint Roller"] = 79;
name["Sceptile Spirit Link"] = 80;
name["Tyranitar Spirit Link"] = 81;
name["Dangerous Energy"] = 82;
name["Flash Energy"] = 83;
name["Sceptile-EX"] = 84;
name["M Sceptile-EX"] = 85;
name["Kyurem-EX"] = 86;
name["Ampharos-EX"] = 87;
name["M Ampharos-EX"] = 88;
name["Hoopa-EX"] = 89;
name["Machamp-EX"] = 90;
name["Tyranitar-EX"] = 91;
name["M Tyranitar-EX"] = 92;
name["Giratina-EX"] = 93;
name["Lugia-EX"] = 94;
name["Steven"] = 95;
name["Primal Kyogre-EX"] = 96;
name["Primal Groudon-EX"] = 97;
name["M Rayquaza-EX"] = 98;
name["Energy Retrieval"] = 99;
name["Trainers' Mail"] = 100;
return name;
}
Card CardsManager::addCardByName(const QString &newName)
{
// For debugging purposes
qDebug() << "[CardsManager] [called] >> addCardByName(const QString &newName) || newName: " << newName;
// Card info
int number;
QString nrString;
QString name;
QString cardId;
QString subtype;
QString supertype;
QString artist;
QString rarity;
QString series;
QString set;
QString setCode;
QString imageUrl;
QString status;
QString condition;
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardByName(const QString &newName) || calling nameToId().value(newName)";
// Build file name
QString fileName = ":/cards/Resources/JSON/xy7-";
QString id = nameToId().value(newName);
fileName.append(id);
fileName.append(".json");
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardByName(const QString &newName) || nameToId().value(newName) returned id: " << id;
qDebug() << "[CardsManager] [update] >> addCardByName(const QString &newName) || fileName built, fileName: " << fileName;
// Open file
QFile file(fileName);
if(!file.open(QFile::ReadOnly | QFile::Text))
{
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardByName(const QString &newName) || Error: Could not open file for reading. fileName: " << fileName;
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardByName(const QString &newName) || Returning Card()";
return Card();
}
// Save file information in fileText
QTextStream in(&file);
QString fileText = in.readAll();
// Close file
file.close();
// Create card jsonObject from fileText
QJsonDocument jsonDocument = QJsonDocument::fromJson(fileText.toUtf8());
QJsonObject rootObject = jsonDocument.object();
QJsonValue value = rootObject.value(QString("card"));
QJsonObject cardRootValues = value.toObject();
// Set values for card variables
name = cardRootValues.value("name").toString();
cardId = cardRootValues.value("id").toString();
subtype = cardRootValues.value("subtype").toString();
supertype = cardRootValues.value("supertype").toString();
nrString = cardRootValues.value("number").toString();
number = nrString.toInt();
artist = cardRootValues.value("artist").toString();
rarity = cardRootValues.value("rarity").toString();
series = cardRootValues.value("series").toString();
set = cardRootValues.value("set").toString();
setCode = cardRootValues.value("setCode").toString();
imageUrl = cardRootValues.value("imageURL").toString();
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardByName(const QString &newName) || Calling Overloaded Card Constructor";
// Create Card instance from variables
Card newCard(cardId, name, imageUrl, subtype, supertype, number, artist, rarity, series, set, setCode, condition, status);
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardByName(const QString &newName) || newCard created. cardId: " << cardId << ", name: " << name << ", imageUrl: " << imageUrl << ", subtype: " << subtype << ", supertype: " << supertype << ", number: " << number << ", artist: " << artist << ", rarity: " << rarity << ", series: " << series << ", set: " << set << ", setCode: " << setCode << ", condition: " << condition << ", status: " << status;
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardByName(const QString &newName) || Adding card: " << cardId << " to m_cards.";
// Add created Card to Card List
m_cards << newCard;
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardByName(const QString &newName) || Card: " << cardId << " added to m_cards.";
// For debugging purposes
qDebug() << "[CardsManager] [update] >> addCardByName(const QString &newName) || Calling cardAdded signal for Card: " << cardId << ", returning the card object.";
cardAdded(cardId);
return newCard;
}
Card CardsManager::card(const QString &id) const
{
// For debugging purposes
qDebug() << "[CardsManager] [called] >> card(const QString &id) || id: " << id;
bool matchFound = false;
int match = -1;
for(int i = 0; i < m_cards.count(); i++)
{
if(m_cards[i].getCardID() == id)
{
matchFound = true;
match = i;
}
}
if(matchFound == true)
{
// For debugging purposes
qDebug() << "[CardsManager] [update] >> card(const QString &id) || Matching card found, returning Card from list m_cards[match], match: " << match;
return m_cards[match];
}
else
{
// For debugging purposes
qDebug() << "[CardsManager] [update] >> card(const QString &id) || No matching card found, returning Card().";
return Card();
}
}
QList<Card> CardsManager::cards() const
{
// For debugging purposes
qDebug() << "[CardsManager] [called] >> cards() || Returning m_cards";
return m_cards;
}
int CardsManager::count() const
{
// For debugging purposes
qDebug() << "[CardsManager] [called] >> count() || Returning count: " << m_cards.count();
return this->m_cards.count();
}
QHash<QString, int> CardsManager::nameToId() const
{
// For debugging purposes
qDebug() << "[CardsManager] [called] >> nameToId()";
QHash<QString, int> name;
name["Oddish"] = 1;
name["Gloom"] = 2;
name["Vileplume"] = 3;
name["Bellossom"] = 4;
name["Spinarak"] = 5;
name["Ariados"] = 6;
name["Sceptile-EX"] = 7;
name["M Sceptile-EX"] = 8;
name["Combee"] = 9;
name["Vespiquen"] = 10;
name["Vespiquen"] = 11;
name["Virizion"] = 12;
name["Flareon"] = 13;
name["Entei"] = 14;
name["Entei"] = 15;
name["Larvesta"] = 16;
name["Volcarona"] = 17;
name["Volcarona"] = 18;
name["Magikarp"] = 19;
name["Gyarados"] = 20;
name["Gyarados"] = 21;
name["Vaporeon"] = 22;
name["Relicanth"] = 23;
name["Regice"] = 24;
name["Kyurem-EX"] = 25;
name["Jolteon"] = 26;
name["Ampharos-EX"] = 27;
name["M Ampharos-EX"] = 28;
name["Rotom"] = 29;
name["Unown"] = 30;
name["Baltoy"] = 31;
name["Baltoy"] = 32;
name["Claydol"] = 33;
name["Golett"] = 34;
name["Golurk"] = 35;
name["Hoopa-EX"] = 36;
name["Machamp-EX"] = 37;
name["Wooper"] = 38;
name["Quagsire"] = 39;
name["Regirock"] = 40;
name["Golurk"] = 41;
name["Tyranitar-EX"] = 42;
name["M Tyranitar-EX"] = 43;
name["Sableye"] = 44;
name["Inkay"] = 45;
name["Malamar"] = 46;
name["Beldum"] = 47;
name["Metang"] = 48;
name["Metagross"] = 49;
name["Metagross"] = 50;
name["Registeel"] = 51;
name["Ralts"] = 52;
name["Kirlia"] = 53;
name["Gardevoir"] = 54;
name["Cottonee"] = 55;
name["Whimsicott"] = 56;
name["Giratina-EX"] = 57;
name["Goomy"] = 58;
name["Sliggoo"] = 59;
name["Goodra"] = 60;
name["Meowth"] = 61;
name["Persian"] = 62;
name["Eevee"] = 63;
name["Porygon"] = 64;
name["Porygon2"] = 65;
name["Porygon-Z"] = 66;
name["Porygon-Z"] = 67;
name["Lugia-EX"] = 68;
name["Ace Trainer"] = 69;
name["Ampharos Spirit Link"] = 70;
name["Eco Arm"] = 71;
name["Energy Recycler"] = 72;
name["Faded Town"] = 73;
name["Forest of Giant Plants"] = 74;
name["Hex Maniac"] = 75;
name["Level Ball"] = 76;
name["Lucky Helmet"] = 77;
name["Lysandre"] = 78;
name["Paint Roller"] = 79;
name["Sceptile Spirit Link"] = 80;
name["Tyranitar Spirit Link"] = 81;
name["Dangerous Energy"] = 82;
name["Flash Energy"] = 83;
name["Sceptile-EX"] = 84;
name["M Sceptile-EX"] = 85;
name["Kyurem-EX"] = 86;
name["Ampharos-EX"] = 87;
name["M Ampharos-EX"] = 88;
name["Hoopa-EX"] = 89;
name["Machamp-EX"] = 90;
name["Tyranitar-EX"] = 91;
name["M Tyranitar-EX"] = 92;
name["Giratina-EX"] = 93;
name["Lugia-EX"] = 94;
name["Steven"] = 95;
name["Primal Kyogre-EX"] = 96;
name["Primal Groudon-EX"] = 97;
name["M Rayquaza-EX"] = 98;
name["Energy Retrieval"] = 99;
name["Trainers' Mail"] = 100;
return name;
}
To copy to clipboard, switch view to plain text mode
main.cpp:
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlEngine>
#include <QQmlContext>
#include "app.h"
#include "album.h"
#include "card.h"
#include "albumsmanager.h"
#include "cardsmanager.h"
#include "abstractcardmodel.h"
#include "albumcardsmodel.h"
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
// Core classes
qmlRegisterType<App>("PokeApp.Classes.Core", 1, 0, "App");
qmlRegisterType<Album>("PokeApp.Classes.Core", 1, 0, "Album");
qmlRegisterType<Card>("PokeApp.Classes.Core", 1, 0, "Card");
// Manager classes
qmlRegisterType<AlbumsManager>("PokeApp.Classes.Core", 1, 0, "AlbumsManager");
qmlRegisterType<CardsManager>("PokeApp.Classes.Core", 1, 0, "CardsManager");
// App engine
QQmlApplicationEngine engine;
App mainApp;
// Context properties
QQmlContext *ctxt1 = engine.rootContext();
ctxt1->setContextProperty("albumCardsModel", mainApp.getAlbumCardsModelPointer());
QQmlContext *ctxt2 = engine.rootContext();
ctxt2->setContextProperty("albumsManager", mainApp.getAlbumsManagerPointer());
QQmlContext *ctxt3 = engine.rootContext();
ctxt3->setContextProperty("cardsManager", mainApp.getCardsManagerPointer());
return app.exec();
}
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlEngine>
#include <QQmlContext>
#include "app.h"
#include "album.h"
#include "card.h"
#include "albumsmanager.h"
#include "cardsmanager.h"
#include "abstractcardmodel.h"
#include "albumcardsmodel.h"
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
// Core classes
qmlRegisterType<App>("PokeApp.Classes.Core", 1, 0, "App");
qmlRegisterType<Album>("PokeApp.Classes.Core", 1, 0, "Album");
qmlRegisterType<Card>("PokeApp.Classes.Core", 1, 0, "Card");
// Manager classes
qmlRegisterType<AlbumsManager>("PokeApp.Classes.Core", 1, 0, "AlbumsManager");
qmlRegisterType<CardsManager>("PokeApp.Classes.Core", 1, 0, "CardsManager");
// App engine
QQmlApplicationEngine engine;
engine.load(QUrl(QLatin1String("qrc:/main.qml")));
App mainApp;
// Context properties
QQmlContext *ctxt1 = engine.rootContext();
ctxt1->setContextProperty("albumCardsModel", mainApp.getAlbumCardsModelPointer());
QQmlContext *ctxt2 = engine.rootContext();
ctxt2->setContextProperty("albumsManager", mainApp.getAlbumsManagerPointer());
QQmlContext *ctxt3 = engine.rootContext();
ctxt3->setContextProperty("cardsManager", mainApp.getCardsManagerPointer());
return app.exec();
}
To copy to clipboard, switch view to plain text mode
main.qml:
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
import PokeApp.Classes.Core 1.0
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Rectangle {
id: rec1
anchors.top: parent.top
height: 50
width: parent.width
color: 'LightBlue'
MouseArea {
anchors.fill: parent
onClicked: albumsManager.createAlbum("My favorites");
}
}
TextInput {
id: text1
width: parent.width
anchors.top: rec1.bottom
anchors.left: parent.left
height: 50
visible: true
color: 'Blue'
}
Button {
id: button1
text: "Add card"
anchors.top: text1.bottom
width: parent.width
height: 50
visible: true
onClicked:
{
albumsManager.addCard(1,text1.text)
}
}
ListView {
id: listview1
model: albumCardsModel
height: 200
width: parent.width
anchors.top: button1.bottom
delegate: Text {
text: "Card\n" +
"Name: " + albumCardsModel.name + ".\n" +
"ID: " + albumCardsModel.cardID + ".\n" +
"Image URL: " + albumCardsModel.imageURL + ".\n" +
"Subtype: " + albumCardsModel.subtype + ".\n" +
"Supertype: " + albumCardsModel.supertype + ".\n" +
"Number: " + albumCardsModel.number + ".\n" +
"Artist: " + albumCardsModel.artist + ".\n" +
"Rarity: " + albumCardsModel.rarity + ".\n" +
"Series: " + albumCardsModel.series + ".\n" +
"Set: " + albumCardsModel.set + ".\n" +
"Set code: " + albumCardsModel.setCode + ".\n" +
"Condition: " + albumCardsModel.condition + ".\n" +
"Status: " + albumCardsModel.status + ".\n"
}
}
}
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
import PokeApp.Classes.Core 1.0
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Rectangle {
id: rec1
anchors.top: parent.top
height: 50
width: parent.width
color: 'LightBlue'
MouseArea {
anchors.fill: parent
onClicked: albumsManager.createAlbum("My favorites");
}
}
TextInput {
id: text1
width: parent.width
anchors.top: rec1.bottom
anchors.left: parent.left
height: 50
visible: true
color: 'Blue'
}
Button {
id: button1
text: "Add card"
anchors.top: text1.bottom
width: parent.width
height: 50
visible: true
onClicked:
{
albumsManager.addCard(1,text1.text)
}
}
ListView {
id: listview1
model: albumCardsModel
height: 200
width: parent.width
anchors.top: button1.bottom
delegate: Text {
text: "Card\n" +
"Name: " + albumCardsModel.name + ".\n" +
"ID: " + albumCardsModel.cardID + ".\n" +
"Image URL: " + albumCardsModel.imageURL + ".\n" +
"Subtype: " + albumCardsModel.subtype + ".\n" +
"Supertype: " + albumCardsModel.supertype + ".\n" +
"Number: " + albumCardsModel.number + ".\n" +
"Artist: " + albumCardsModel.artist + ".\n" +
"Rarity: " + albumCardsModel.rarity + ".\n" +
"Series: " + albumCardsModel.series + ".\n" +
"Set: " + albumCardsModel.set + ".\n" +
"Set code: " + albumCardsModel.setCode + ".\n" +
"Condition: " + albumCardsModel.condition + ".\n" +
"Status: " + albumCardsModel.status + ".\n"
}
}
}
To copy to clipboard, switch view to plain text mode
Added after 6 minutes:
Run time qDebug() output:
Added after 4 minutes:
Clicking the top blue banner adds a new Album to AlbumsManager with the name "My Favorites".
The code used for this is:
MouseArea {
anchors.fill: parent
onClicked: albumsManager.createAlbum("My favorites");
}
MouseArea {
anchors.fill: parent
onClicked: albumsManager.createAlbum("My favorites");
}
To copy to clipboard, switch view to plain text mode
Pressing the button takes the text from the text fields and uses it as the requested Card ID and adds the card to AlbumID 1 in AlbumsManager.
The code used for this is:
onClicked:
{
albumsManager.addCard(1,text1.text)
}
onClicked:
{
albumsManager.addCard(1,text1.text)
}
To copy to clipboard, switch view to plain text mode
I beleive that I have not properly set the ListView model or that the signals aren't connected properly.
Added after 9 minutes:
Application output:
Running the app:
QML debugging is enabled. Only use this in a safe environment.
qrc:/main.qml:48: ReferenceError: albumCardsModel is not defined
[AlbumsManager] [called] [constructor] || m_albumId set to: 0
[CardsManager] [called] [Default constructor]
[AbstractCardModel] [called] [Default constructor]
[Album] [called] [albumId: 0 ] [Default constructor]
[AlbumCardsModel] [called] [Default Constructor]
[App] [called] [Default Constructor]
[AlbumsManager] [called] [constructor] || m_albumId set to: 0
[AlbumsManager] [called] [Assignment Operator]
[AlbumsManager] [called] [Destructor].
[CardsManager] [called] [Default constructor]
[CardsManager] [called] [Assignment Operator]
[AbstractCardModel] [called] [Overloaded constructor]
[Album] [called] [albumId: 1469051904 ] [Default constructor]
[AlbumCardsModel] [called] [Overloaded Constructor]
[AbstractCardModel] [called] [Assignment Operator]
[Album] [called] [albumId: 0 ] [Assignment opperator] || albumId: 0
[Album] [called] [albumId: 1469051904 ] >> getNrOfCards() || returned count: 0
[Album] [called] [albumId: 1469051904 ] [Destructor]
[AbstractCardModel] [called] [Default Destructor]
[AlbumCardsModel] [called] >> rowCount(const QModelIndex&)
[Album] [called] [albumId: 1469051904 ] >> getCardIDs()
QML debugging is enabled. Only use this in a safe environment.
qrc:/main.qml:48: ReferenceError: albumCardsModel is not defined
[AlbumsManager] [called] [constructor] || m_albumId set to: 0
[CardsManager] [called] [Default constructor]
[AbstractCardModel] [called] [Default constructor]
[Album] [called] [albumId: 0 ] [Default constructor]
[AlbumCardsModel] [called] [Default Constructor]
[App] [called] [Default Constructor]
[AlbumsManager] [called] [constructor] || m_albumId set to: 0
[AlbumsManager] [called] [Assignment Operator]
[AlbumsManager] [called] [Destructor].
[CardsManager] [called] [Default constructor]
[CardsManager] [called] [Assignment Operator]
[AbstractCardModel] [called] [Overloaded constructor]
[Album] [called] [albumId: 1469051904 ] [Default constructor]
[AlbumCardsModel] [called] [Overloaded Constructor]
[AbstractCardModel] [called] [Assignment Operator]
[Album] [called] [albumId: 0 ] [Assignment opperator] || albumId: 0
[Album] [called] [albumId: 1469051904 ] >> getNrOfCards() || returned count: 0
[Album] [called] [albumId: 1469051904 ] [Destructor]
[AbstractCardModel] [called] [Default Destructor]
[AlbumCardsModel] [called] >> rowCount(const QModelIndex&)
[Album] [called] [albumId: 1469051904 ] >> getCardIDs()
To copy to clipboard, switch view to plain text mode
Clicking the "Create Album Banner":
"[AlbumsManager] [called] >> createAlbum(const QString &name) || name: My favorites"
[AlbumsManager
] [update
] >> createAlbum
(const QString &name
) || Assigning albumId
: 1 to newAlbum
[AlbumsManager
] [update
] >> createAlbum
(const QString &name
) || calling Overloaded Album constructor, name
: "My favorites" , m_albumId
: 1 [Album] [called] [albumId: 1 ] [Overloaded constructor] || newAlbumName: "My favorites" , albumId: 1
[Album] [called] [albumId: -842150451 ] [Copy constructor] || albumId: -842150451
[Album] [called] [albumId: 1 ] >> getNrOfCards() || returned count: 0
[AlbumsManager
] [update
] >> createAlbum
(const QString &name
) || newAlbum appended to m_albums
[Album] [called] [albumId: 1 ] [Destructor]
"[AlbumsManager] [called] >> createAlbum(const QString &name) || name: My favorites"
[AlbumsManager] [update] >> createAlbum(const QString &name) || Assigning albumId: 1 to newAlbum
[AlbumsManager] [update] >> createAlbum(const QString &name) || calling Overloaded Album constructor, name: "My favorites" , m_albumId: 1
[Album] [called] [albumId: 1 ] [Overloaded constructor] || newAlbumName: "My favorites" , albumId: 1
[Album] [called] [albumId: -842150451 ] [Copy constructor] || albumId: -842150451
[Album] [called] [albumId: 1 ] >> getNrOfCards() || returned count: 0
[AlbumsManager] [update] >> createAlbum(const QString &name) || newAlbum appended to m_albums
[Album] [called] [albumId: 1 ] [Destructor]
To copy to clipboard, switch view to plain text mode
Clicking the "Add Card Button" with "14" in the "Text Field":
[AlbumsManager
] [called
] >> addCard
(const int &albumId,
const QString &cardId
) || albumId
: 1 , cardId
: "14" [AlbumsManager] [called] >> count() || returned: 1
[Album] [called] [albumId: 1 ] >> getAlbumId() || returned: albumId: 1
[AlbumsManager] [called] >> count() || returned: 1
[AlbumsManager
] [update
] >> addCard
(const int &albumId,
const QString &cardId
) || A matching Album was found.
[Album] [called] [albumId: 1 ] >> addCard(const QString& cardID): cardID: "14"
[Album] [called] [albumId: 1 ] >> getCardIDs()
[AlbumsManager] [called] >> addCard(const int &albumId, const QString &cardId) || albumId: 1 , cardId: "14"
[AlbumsManager] [called] >> count() || returned: 1
[Album] [called] [albumId: 1 ] >> getAlbumId() || returned: albumId: 1
[AlbumsManager] [called] >> count() || returned: 1
[AlbumsManager] [update] >> addCard(const int &albumId, const QString &cardId) || A matching Album was found.
[Album] [called] [albumId: 1 ] >> addCard(const QString& cardID): cardID: "14"
[Album] [called] [albumId: 1 ] >> getCardIDs()
To copy to clipboard, switch view to plain text mode
Closing the app:
[App] [called] [Default Destructor]
[Album] [called] [albumId: 1469051904 ] [Destructor]
[AbstractCardModel] [called] [Default Destructor]
[AlbumsManager] [called] [Destructor].
[Album] [called] [albumId: 1 ] [Destructor]
[App] [called] [Default Destructor]
[Album] [called] [albumId: 1469051904 ] [Destructor]
[AbstractCardModel] [called] [Default Destructor]
[AlbumsManager] [called] [Destructor].
[Album] [called] [albumId: 1 ] [Destructor]
To copy to clipboard, switch view to plain text mode
By the way, I am thinking of putting the whole project with the complete UI once it is complete for other people to use it as an example reference if they need one.
Added after 20 minutes:
Me right now:
Bookmarks