// CardsManager
int CardsManager
::addCard(const QString id
) {
// Request JSON for Card
QString requestURL
= "https://api.pokemontcg.io/v1/cards/";
requestURL.append(id);
m_networkManager.makeRequest(requestURL);
// Wait for response
connect(&m_networkManager, SIGNAL(qnamFinished()),&loop, SLOT(quit()));
loop.exec();
// Open JSON document
QJsonDocument jsonDocument = QJsonDocument::fromJson(val.toUtf8());
QJsonObject rootObject = jsonDocument.object();
QJsonValue value
= rootObject.
value(QString("card"));
QJsonObject cardRootValues = value.toObject();
// Set values for card variables
m_cardMID++;
int cardMID = m_cardMID;
QString name
= cardRootValues.
value("name").
toString();
QString cardId
= cardRootValues.
value("id").
toString();
QString subtype
= cardRootValues.
value("subtype").
toString();
QString supertype
= cardRootValues.
value("supertype").
toString();
QString nrString
= cardRootValues.
value("number").
toString();
int number = nrString.toInt();
QString artist
= cardRootValues.
value("artist").
toString();
QString rarity
= cardRootValues.
value("rarity").
toString();
QString series
= cardRootValues.
value("series").
toString();
QString set
= cardRootValues.
value("set").
toString();
QString setCode
= cardRootValues.
value("setCode").
toString();
QString imageUrl
= cardRootValues.
value("imageUrl").
toString();
QString condition
= "Not specified";
Card newCard(cardMID, cardId, name, imageUrl, subtype, supertype, number, artist, rarity, series, set, setCode, condition, status);
this->m_cards << newCard;
// For debugging purposes
qDebug() << "[CardsManager] Card: " << cardMID << cardId << name << imageUrl << subtype << supertype << number << artist << rarity << series << set << setCode << condition << status;
cardAdded
(QString::number(cardMID
));
return cardMID;
}
// CardsManager
int CardsManager::addCard(const QString id)
{
// Request JSON for Card
QString requestURL = "https://api.pokemontcg.io/v1/cards/";
requestURL.append(id);
m_networkManager.makeRequest(requestURL);
// Wait for response
QEventLoop loop;
connect(&m_networkManager, SIGNAL(qnamFinished()),&loop, SLOT(quit()));
loop.exec();
// Open JSON document
QString val = m_data;
QJsonDocument jsonDocument = QJsonDocument::fromJson(val.toUtf8());
QJsonObject rootObject = jsonDocument.object();
QJsonValue value = rootObject.value(QString("card"));
QJsonObject cardRootValues = value.toObject();
// Set values for card variables
m_cardMID++;
int cardMID = m_cardMID;
QString name = cardRootValues.value("name").toString();
QString cardId = cardRootValues.value("id").toString();
QString subtype = cardRootValues.value("subtype").toString();
QString supertype = cardRootValues.value("supertype").toString();
QString nrString = cardRootValues.value("number").toString();
int number = nrString.toInt();
QString artist = cardRootValues.value("artist").toString();
QString rarity = cardRootValues.value("rarity").toString();
QString series = cardRootValues.value("series").toString();
QString set = cardRootValues.value("set").toString();
QString setCode = cardRootValues.value("setCode").toString();
QString imageUrl = cardRootValues.value("imageUrl").toString();
QString status = "Not specified";
QString condition = "Not specified";
Card newCard(cardMID, cardId, name, imageUrl, subtype, supertype, number, artist, rarity, series, set, setCode, condition, status);
this->m_cards << newCard;
// For debugging purposes
qDebug() << "[CardsManager] Card: " << cardMID << cardId << name << imageUrl << subtype << supertype << number << artist << rarity << series << set << setCode << condition << status;
cardAdded(QString::number(cardMID));
return cardMID;
}
To copy to clipboard, switch view to plain text mode
// MainNetworkManager
class MainNetworkManager
: public QObject{
Q_OBJECT
public:
explicit MainNetworkManager
(QObject *parent
= 0);
void makeRequest
(QString endpointRequest
);
signals:
void qnamFinished();
public slots:
void readReply(QNetworkReply *reply);
private:
QNetworkAccessManager *qnam = new QNetworkAccessManager(this);
};
// MainNetworkManager
class MainNetworkManager: public QObject
{
Q_OBJECT
public:
explicit MainNetworkManager(QObject *parent = 0);
void makeRequest(QString endpointRequest);
signals:
void readyData(QByteArray);
void qnamFinished();
public slots:
void readReply(QNetworkReply *reply);
private:
QNetworkAccessManager *qnam = new QNetworkAccessManager(this);
};
To copy to clipboard, switch view to plain text mode
Bookmarks