libdrmconf 0.15.1
A library to program DMR radios.
Loading...
Searching...
No Matches
talkgroupdatabase.hh
1#ifndef TALKGROUPDATABASE_HH
2#define TALKGROUPDATABASE_HH
3
4#include <QAbstractTableModel>
5#include <QNetworkAccessManager>
6
10class TalkGroupDatabase : public QAbstractTableModel
11{
12 Q_OBJECT
13
15 class TalkGroup {
16 public:
18 TalkGroup();
20 TalkGroup(const QString &name, unsigned number);
22 unsigned id;
24 QString name;
25 };
26
27public:
31 TalkGroupDatabase(unsigned updatePeriodDays=30, QObject *parent=nullptr);
32
34 qint64 count() const;
36 unsigned dbAge() const;
37
39 TalkGroup talkgroup(int index) const;
40
42 bool load();
44 bool load(const QString &filename);
45
47 int rowCount(const QModelIndex &parent=QModelIndex()) const;
49 int columnCount(const QModelIndex &parent=QModelIndex()) const;
51 QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const;
52
53signals:
55 void loaded();
57 void error(const QString &msg);
59 void downloadProgress(qint64 loaded, qint64 total);
60
61public slots:
63 void download();
64
65private slots:
67 void downloadFinished(QNetworkReply *reply);
68
69protected:
71 QVector<TalkGroup> _talkgroups;
73 QNetworkAccessManager _network;
74};
75
76#endif // TALKGROUPDATABASE_HH
TalkGroup talkgroup(int index) const
Returns the talk group entry at the given index.
Definition talkgroupdatabase.cc:55
void download()
Starts the download of the talk group database.
Definition talkgroupdatabase.cc:62
unsigned dbAge() const
Returns the age of the database in days.
Definition talkgroupdatabase.cc:46
bool load()
Loads all entries from the downloaded talk group db.
Definition talkgroupdatabase.cc:105
int columnCount(const QModelIndex &parent=QModelIndex()) const
Implements the QAbstractTableModel interface, returns the number of columns.
Definition talkgroupdatabase.cc:158
qint64 count() const
Returns the number of talk groups.
Definition talkgroupdatabase.cc:41
QNetworkAccessManager _network
The network access used for downloading.
Definition talkgroupdatabase.hh:73
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Implements the QAbstractTableModel interface, return the entry data.
Definition talkgroupdatabase.cc:164
void loaded()
Gets emitted once the talk group database has been loaded.
void error(const QString &msg)
Gets emitted if the loading of the talk group database fails.
QVector< TalkGroup > _talkgroups
Holds all talk groups as id->name table.
Definition talkgroupdatabase.hh:71
void downloadProgress(qint64 loaded, qint64 total)
Gets emitted on download progress.
TalkGroupDatabase(unsigned updatePeriodDays=30, QObject *parent=nullptr)
Constructs a talk group database.
Definition talkgroupdatabase.cc:30
int rowCount(const QModelIndex &parent=QModelIndex()) const
Implements the QAbstractTableModel interface, returns the number of rows (number of entries).
Definition talkgroupdatabase.cc:152