Routing the received biddings to the model. Just debug outputs there yet.
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "../model/metadata.h"
|
||||
#include "../structs.h"
|
||||
|
||||
QList<ModelItemValues> JsonParser::toItemValuesList(const QByteArray& jsonData,
|
||||
const QString& rootValueName) {
|
||||
@ -106,6 +107,29 @@ ModelItemValues JsonParser::serverUserCredentialsToItemValues(const QJsonDocumen
|
||||
return values;
|
||||
}
|
||||
|
||||
QList<bidding> JsonParser::extractBiddings(const QJsonDocument& jsonDoc) {
|
||||
QList<bidding> result;
|
||||
|
||||
if (jsonDoc.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
QJsonArray itemArray = JsonParser::extractItemArray(jsonDoc, "data");
|
||||
|
||||
foreach (QJsonValue value, itemArray) {
|
||||
// REFACTOR implement & use "JsonParser::parseServerResponse(const QJsonObject& object,
|
||||
// QHash<QString, int> entries)"
|
||||
QJsonObject itemJsonObject = value.toObject();
|
||||
bidding values{.userId = QUuid(itemJsonObject.value("user_id").toString()),
|
||||
.biddingRound = itemJsonObject.value("bidding_round").toInt(),
|
||||
.amount = itemJsonObject.value("amount").toInt(),
|
||||
.depotWishOne = itemJsonObject.value("depot_wish_one").toString(),
|
||||
.depotWishTwo = itemJsonObject.value("depot_wish_two").toString()};
|
||||
result.append(values);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QJsonArray JsonParser::extractItemArray(const QJsonDocument& doc, const QString& objectName) {
|
||||
QJsonArray itemArray;
|
||||
if (objectName.isEmpty()) {
|
||||
|
||||
@ -9,6 +9,7 @@ class QByteArray;
|
||||
class QJsonArray;
|
||||
|
||||
typedef QMap<int, QVariant> ModelItemValues;
|
||||
class bidding;
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -22,7 +23,7 @@ class JsonParser {
|
||||
const QString& objectName = "");
|
||||
|
||||
static ModelItemValues serverUserCredentialsToItemValues(const QJsonDocument& jsonDoc);
|
||||
|
||||
static QList<bidding> extractBiddings(const QJsonDocument& jsonDoc);
|
||||
// static ModelItemValues parseServerResponse(const QJsonDocument& jsonDoc,
|
||||
// QHash<QString, int> entries);
|
||||
// static ModelItemValues parseServerResponse(const QJsonObject& object,
|
||||
|
||||
@ -156,9 +156,10 @@ bool GenericCore::isSyncServerSetup() const {
|
||||
}
|
||||
}
|
||||
|
||||
void GenericCore::onBiddingsChanged(int round, QList<bidding> biddings) {
|
||||
qInfo() << "onBiddingsChanged: round:" << round << "- biddings:" << biddings.count();
|
||||
void GenericCore::onBiddingsChanged(const QList<bidding> biddings) {
|
||||
qInfo() << "onBiddingsChanged: biddings:" << biddings.count();
|
||||
// NEXT merge biddings into model
|
||||
m_mainModel->updateBiddings(biddings);
|
||||
}
|
||||
|
||||
void GenericCore::onCreateOnlineAccountTriggered(const QString& mailAddress) {
|
||||
|
||||
@ -47,7 +47,7 @@ class GenericCore : public QObject {
|
||||
bool isSyncServerSetup() const;
|
||||
|
||||
public slots:
|
||||
void onBiddingsChanged(int round, QList<bidding> biddings);
|
||||
void onBiddingsChanged(const QList<bidding> biddings);
|
||||
|
||||
void onCreateOnlineAccountTriggered(const QString& mailAddress);
|
||||
void onOnlineUserAccountReceived(const QString mailAddress,
|
||||
|
||||
@ -1,16 +1,17 @@
|
||||
#include "tablemodel.h"
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "../formats/jsonparser.h"
|
||||
#include "../structs.h"
|
||||
#include "commands/edititemcommand.h"
|
||||
#include "commands/insertrowscommand.h"
|
||||
#include "commands/removerowscommand.h"
|
||||
#include "metadata.h"
|
||||
#include "modelitem.h"
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
QByteArray TableModel::generateExampleItems() {
|
||||
QJsonDocument doc = QJsonDocument();
|
||||
QJsonObject rootObject;
|
||||
@ -238,6 +239,20 @@ void TableModel::setOnlineCredentials(const QString& mail,
|
||||
setItemData(itemIndex, {{OnlineIdRole, uuid}, {AccessCodeRole, token}});
|
||||
}
|
||||
|
||||
void TableModel::updateBiddings(const QList<bidding> biddings) {
|
||||
int round = biddings.first().biddingRound;
|
||||
qInfo() << "Updating bidding for round:" << round << "...";
|
||||
QListIterator<bidding> i(biddings);
|
||||
while (i.hasNext()) {
|
||||
const bidding localBidding = i.next();
|
||||
qWarning() << "Processing bidding:";
|
||||
qInfo() << "localBidding.userId:" << localBidding.userId;
|
||||
qDebug() << "localBidding.biddingRound:" << localBidding.biddingRound;
|
||||
qDebug() << "localBidding.amount:" << localBidding.amount;
|
||||
qDebug() << "localBidding.depotWishOne:" << localBidding.depotWishOne;
|
||||
qDebug() << "localBidding.depotWishTwo:" << localBidding.depotWishTwo;
|
||||
}
|
||||
}
|
||||
|
||||
bool TableModel::removeRows(int firstRow, int nRows, const QModelIndex& parentIndex) {
|
||||
if (parentIndex != QModelIndex()) {
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
#include <QAbstractTableModel>
|
||||
#include "metadata.h"
|
||||
|
||||
class bidding;
|
||||
class QUndoStack;
|
||||
class ModelItem;
|
||||
|
||||
@ -45,6 +46,8 @@ class TableModel : public QAbstractTableModel {
|
||||
bool updateItem(const ModelItemValues& itemValues);
|
||||
|
||||
void setOnlineCredentials(const QString& mail, const QString& uuid, const QString& token);
|
||||
void updateBiddings(const QList<bidding> biddings);
|
||||
|
||||
public slots:
|
||||
// bool insertRows(int position, int rows, const QModelIndex& parentIndex = QModelIndex())
|
||||
// override;
|
||||
|
||||
@ -194,6 +194,7 @@ void ServerCommunicator::onPostReplyFailure(const PostRequestTypes type,
|
||||
const QString errorString) {
|
||||
const QString message =
|
||||
QString("Request of type %1 returned: %2").arg(QString::number(type), errorString);
|
||||
// NEXT improve error message to the UI;
|
||||
m_core->displayStatusMessage(message);
|
||||
}
|
||||
|
||||
@ -215,15 +216,9 @@ void ServerCommunicator::currentBiddingRoundChangedReply(const QJsonDocument jso
|
||||
void ServerCommunicator::currentBiddingsReply(const QJsonDocument jsonDoc) {
|
||||
qCritical() << "currentBiddingsReply:" << jsonDoc;
|
||||
|
||||
// NEXT extract biddings from jsonDoc
|
||||
const int roundNumber = 0;
|
||||
const bidding dummyBidding{.userId = QUuid(),
|
||||
.biddingRound = 0,
|
||||
.amount = 123,
|
||||
.depotWishOne = "one",
|
||||
.depotWishTwo = "two"};
|
||||
const QList<bidding> biddings{dummyBidding};
|
||||
emit biddingsChanged(roundNumber, biddings);
|
||||
const QList<bidding> biddings = JsonParser::extractBiddings(jsonDoc);
|
||||
|
||||
emit biddingsChanged(biddings);
|
||||
}
|
||||
|
||||
void ServerCommunicator::onlineUserAccountReply(const QJsonDocument jsonDoc) {
|
||||
|
||||
@ -44,7 +44,7 @@ class ServerCommunicator : public QObject {
|
||||
void deleteRequestFailure(const QString errorString);
|
||||
|
||||
void currentBiddingRoundChanged(int round, bool isRunning);
|
||||
void biddingsChanged(int round, QList<bidding> biddings);
|
||||
void biddingsChanged(QList<bidding> biddings);
|
||||
void onlineUserAccountReceived(const QString mailAddress,
|
||||
const QString uuid,
|
||||
const QString accessToken);
|
||||
|
||||
Reference in New Issue
Block a user