[Browser] Fix QT warnings

0.6.1
Koncord 8 years ago
parent 9f0ec849a0
commit 8f2ef83be1

@ -9,14 +9,18 @@
QueryUpdate *queryUpdate; QueryUpdate *queryUpdate;
QueryHelper::QueryHelper(QAbstractItemModel *model) QueryHelper::QueryHelper(QAbstractItemModel *model)
{ {
qRegisterMetaType<QueryData>("QueryData");
queryThread = new QThread; queryThread = new QThread;
queryUpdate = new QueryUpdate; queryUpdate = new QueryUpdate;
queryUpdate->_model = model; _model = model;
connect(queryThread, SIGNAL(started()), queryUpdate, SLOT(process())); connect(queryThread, SIGNAL(started()), queryUpdate, SLOT(process()));
connect(queryUpdate, SIGNAL(finished()), queryThread, SLOT(quit())); connect(queryUpdate, SIGNAL(finished()), queryThread, SLOT(quit()));
connect(queryUpdate, &QueryUpdate::finished, [this](){emit finished();}); connect(queryUpdate, &QueryUpdate::finished, [this](){emit finished();});
connect(queryUpdate, SIGNAL(updateModel(QString, unsigned short, QueryData)),
this, SLOT(update(QString, unsigned short, QueryData)));
queryUpdate->moveToThread(queryThread); queryUpdate->moveToThread(queryThread);
} }
@ -31,44 +35,48 @@ void QueryHelper::terminate()
queryThread->terminate(); queryThread->terminate();
} }
void QueryUpdate::process() void QueryHelper::update(QString addr, unsigned short port, QueryData data)
{ {
auto data = QueryClient::Get().Query();
if(QueryClient::Get().Status() != ID_MASTER_QUERY)
return;
ServerModel *model = ((ServerModel*)_model); ServerModel *model = ((ServerModel*)_model);
model->removeRows(0, model->rowCount()); model->insertRow(model->rowCount());
for(auto server : data) int row = model->rowCount() - 1;
{
model->insertRow(model->rowCount());
int row = model->rowCount() - 1;
QModelIndex mi = model->index(row, ServerData::ADDR); QModelIndex mi = model->index(row, ServerData::ADDR);
model->setData(mi, server.first.ToString(true, ':')); model->setData(mi, addr + ":" + QString::number(port));
mi = model->index(row, ServerData::PLAYERS); mi = model->index(row, ServerData::PLAYERS);
model->setData(mi, (int)server.second.players.size()); model->setData(mi, (int)data.players.size());
mi = model->index(row, ServerData::MAX_PLAYERS); mi = model->index(row, ServerData::MAX_PLAYERS);
model->setData(mi, server.second.GetMaxPlayers()); model->setData(mi, data.GetMaxPlayers());
mi = model->index(row, ServerData::HOSTNAME); mi = model->index(row, ServerData::HOSTNAME);
model->setData(mi, server.second.GetName()); model->setData(mi, data.GetName());
mi = model->index(row, ServerData::MODNAME); mi = model->index(row, ServerData::MODNAME);
model->setData(mi, server.second.GetGameMode()); model->setData(mi, data.GetGameMode());
mi = model->index(row, ServerData::VERSION); mi = model->index(row, ServerData::VERSION);
model->setData(mi, server.second.GetVersion()); model->setData(mi, data.GetVersion());
mi = model->index(row, ServerData::PASSW); mi = model->index(row, ServerData::PASSW);
model->setData(mi, server.second.GetPassword() == 1); model->setData(mi, data.GetPassword() == 1);
mi = model->index(row, ServerData::PING); mi = model->index(row, ServerData::PING);
model->setData(mi, PING_UNREACHABLE); model->setData(mi, PING_UNREACHABLE);
PingHelper::Get().Add(row, {addr, port});
}
PingHelper::Get().Add(row, {server.first.ToString(false), server.first.GetPort()}); void QueryUpdate::process()
{
auto data = QueryClient::Get().Query();
if(QueryClient::Get().Status() != ID_MASTER_QUERY)
{
emit finished();
return;
} }
for(auto server : data)
emit updateModel(server.first.ToString(false), server.first.GetPort(), server.second);
emit finished(); emit finished();
} }

@ -8,7 +8,11 @@
#include <QObject> #include <QObject>
#include <vector>
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <components/openmw-mp/Master/MasterData.hpp>
Q_DECLARE_METATYPE(QueryData)
class QueryHelper : public QObject class QueryHelper : public QObject
{ {
@ -18,11 +22,14 @@ public:
public slots: public slots:
void refresh(); void refresh();
void terminate(); void terminate();
private slots:
void update(QString addr, unsigned short port, QueryData data);
signals: signals:
void finished(); void finished();
void started(); void started();
private: private:
QThread *queryThread; QThread *queryThread;
QAbstractItemModel *_model;
}; };
class QueryUpdate : public QObject class QueryUpdate : public QObject
@ -31,10 +38,9 @@ class QueryUpdate : public QObject
Q_OBJECT Q_OBJECT
signals: signals:
void finished(); void finished();
void updateModel(QString addr, unsigned short port, QueryData data);
public slots: public slots:
void process(); void process();
private:
QAbstractItemModel *_model;
}; };
#endif //OPENMW_QUERYHELPER_HPP #endif //OPENMW_QUERYHELPER_HPP
Loading…
Cancel
Save