FlightGear next
MPServersModel.h
Go to the documentation of this file.
1#ifndef MPSERVERSMODEL_H
2#define MPSERVERSMODEL_H
3
4#include <QAbstractListModel>
5
7
8
9class MPServersModel : public QAbstractListModel
10{
11 Q_OBJECT
12
13 Q_PROPERTY(bool valid READ valid NOTIFY validChanged)
14
16
17 Q_PROPERTY(QString currentServer READ currentServer NOTIFY currentIndexChanged)
18 Q_PROPERTY(int currentPort READ currentPort NOTIFY currentIndexChanged)
19public:
20 MPServersModel(QObject* parent = nullptr);
21 ~MPServersModel() override;
22
23 int rowCount(const QModelIndex& index) const override;
24
25 QVariant data(const QModelIndex& index, int role) const override;
26
27 QHash<int, QByteArray> roleNames() const override;
28
29 void onRefreshMPServersDone(simgear::HTTP::Request*);
30 void onRefreshMPServersFailed(simgear::HTTP::Request*);
31 int findMPServerPort(const std::string& host);
33
34 void refresh();
35
36 void requestRestore();
37
38 QString currentServer() const;
39 int currentPort() const;
40
41 bool valid() const;
42
43 int currentIndex() const
44 {
45 return m_currentIndex;
46 }
47
48public slots:
50
51signals:
54
55private:
56
57 SGSharedPtr<RemoteXMLRequest> m_mpServerRequest;
58 bool m_doRestoreMPServer = false;
59
60 struct ServerInfo
61 {
62 ServerInfo(QString n, QString l, QString h, int port);
63
64 QString name, location, host;
65 int port = 0;
66 };
67
68 std::vector<ServerInfo> m_servers;
69 int m_currentIndex = 0;
70};
71
72#endif // MPSERVERSMODEL_H
MPServersModel(QObject *parent=nullptr)
void validChanged()
QVariant data(const QModelIndex &index, int role) const override
void onRefreshMPServersDone(simgear::HTTP::Request *)
QString currentServer
QHash< int, QByteArray > roleNames() const override
void setCurrentIndex(int currentIndex)
void onRefreshMPServersFailed(simgear::HTTP::Request *)
void currentIndexChanged(int currentIndex)
void restoreMPServerSelection()
int findMPServerPort(const std::string &host)
int rowCount(const QModelIndex &index) const override
const char * name