-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcombatroundmodel.cpp
More file actions
55 lines (51 loc) · 1.65 KB
/
combatroundmodel.cpp
File metadata and controls
55 lines (51 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "combatroundmodel.h"
#include <QDebug>
#include <QJsonObject>
#include <QJsonArray>
#include <QNetworkConfigurationManager>
#include <QNetworkConfiguration>
#include <QList>
void CombatRoundModel::fetchData()
{
qDebug() << "Fetchdata";
QNetworkConfigurationManager mgr;
//QNetworkConfiguration conf = mgr.defaultConfiguration();
//qDebug() << conf.name() << ":" << conf.identifier() << ":" << conf.state() << ":" << conf.type();
/*QList<QNetworkConfiguration> confs = mgr.allConfigurations();
for (int i = 0 ; i < confs.size(); i++)
{
conf = confs[i];
qDebug() << conf.name() << ":" << conf.identifier() << ":" << conf.state();
}*/
if (mgr.isOnline()&&false)
{
QJsonObject query;
query["objectType"] = QString::fromUtf8("objects.weapons");
EnginioReply *reply = _client->query(query);
connect(reply,SIGNAL(finished(EnginioReply*)),this,SLOT(processReply(EnginioReply*)));
}
else
{
qDebug() << "System seems to be offline. Creating local data";
Weapon *w = new Weapon();
_weapons[w->toString()] = w;
w = new Weapon("Bow","D6",4);
_weapons[w->toString()] = w;
emit finished();
}
}
void CombatRoundModel::processReply(EnginioReply* reply)
{
QJsonObject results = reply->data();
qDebug() << "fetch done:"<< results;
QJsonArray weapons = results["results"].toArray();
for (int i = 0 ; i < weapons.count(); i++)
{
QJsonObject wJson = weapons[i].toObject();
Weapon *w = new Weapon(wJson);
qDebug() << w->toString();
_weapons[w->toString()] = w;
}
reply->deleteLater();
emit finished();
}