libosmscout 1.1.1
Loading...
Searching...
No Matches
AvailableVoicesModel.h
Go to the documentation of this file.
1#ifndef OSMSCOUT_CLIENT_QT_VAILABLEVOICESMODEL_H
2#define OSMSCOUT_CLIENT_QT_VAILABLEVOICESMODEL_H
3
4/*
5 OSMScout - a Qt backend for libosmscout and libosmscout-map
6 Copyright (C) 2020 Lukas Karas
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21*/
22
24
25#include <osmscoutclient/VoiceProvider.h>
26
29
30#include <QAbstractListModel>
31#include <QNetworkDiskCache>
32#include <QNetworkAccessManager>
33
34namespace osmscout {
35
56class OSMSCOUT_CLIENT_QT_API AvailableVoicesModel : public QAbstractListModel {
57 Q_OBJECT
58
59 Q_PROPERTY(bool loading READ isLoading NOTIFY loadingChanged)
60 Q_PROPERTY(QString fetchError READ getFetchError NOTIFY loadingChanged)
61
62signals:
64
65public slots:
66 void listDownloaded(const VoiceProvider &provider, QNetworkReply*);
67 void reload();
68
70
71public:
73
75
76 enum Roles {
77 NameRole = Qt::UserRole,
78 LangRole = Qt::UserRole + 1,
79 GenderRole = Qt::UserRole + 2,
80 LicenseRole = Qt::UserRole + 3,
81 DirectoryRole = Qt::UserRole + 4,
82 AuthorRole = Qt::UserRole + 5,
83 DescriptionRole = Qt::UserRole + 6,
84 StateRole = Qt::UserRole + 7
85 };
86 Q_ENUM(Roles)
87
93 Q_ENUM(VoiceState)
94
95 Q_INVOKABLE int rowCount(const QModelIndex &parent = QModelIndex()) const override;
96 Q_INVOKABLE QVariant data(const QModelIndex &index, int role) const override;
97 QHash<int, QByteArray> roleNames() const override;
98 Q_INVOKABLE Qt::ItemFlags flags(const QModelIndex &index) const override;
99
100 Q_INVOKABLE void download(const QModelIndex &index);
101 Q_INVOKABLE void remove(const QModelIndex &index);
102
103 Q_INVOKABLE QString stateStr(VoiceState state) const;
104
105 inline bool isLoading(){
106 return requests>0;
107 }
108
109 inline QString getFetchError(){
110 return fetchError;
111 }
112
113private:
114 int findRow(const QString &lang, const QString &name);
115
116private:
117 VoiceManagerRef voiceManager;
118 QNetworkAccessManager webCtrl;
119 QNetworkDiskCache diskCache;
120 QList<VoiceProvider> voiceProviders;
121 size_t requests{0};
122 QList<AvailableVoice*> items;
123 QString fetchError;
124};
125
126}
127
128#endif //OSMSCOUT_CLIENT_QT_VAILABLEVOICESMODEL_H
#define OSMSCOUT_CLIENT_QT_API
Definition ClientQtImportExport.h:45
Definition Voice.h:31
QString getFetchError()
Definition AvailableVoicesModel.h:109
Q_INVOKABLE void remove(const QModelIndex &index)
VoiceState
Definition AvailableVoicesModel.h:88
@ Downloading
Definition AvailableVoicesModel.h:90
@ Downloaded
Definition AvailableVoicesModel.h:91
@ Available
Definition AvailableVoicesModel.h:89
bool loading
Definition AvailableVoicesModel.h:59
Q_INVOKABLE Qt::ItemFlags flags(const QModelIndex &index) const override
void onVoiceStateChanged(const AvailableVoice &voice)
bool isLoading()
Definition AvailableVoicesModel.h:105
QHash< int, QByteArray > roleNames() const override
void listDownloaded(const VoiceProvider &provider, QNetworkReply *)
QString fetchError
Definition AvailableVoicesModel.h:60
Q_INVOKABLE void download(const QModelIndex &index)
Roles
Definition AvailableVoicesModel.h:76
@ LangRole
Definition AvailableVoicesModel.h:78
@ LicenseRole
Definition AvailableVoicesModel.h:80
@ StateRole
Definition AvailableVoicesModel.h:84
@ NameRole
Definition AvailableVoicesModel.h:77
@ AuthorRole
Definition AvailableVoicesModel.h:82
@ DescriptionRole
Definition AvailableVoicesModel.h:83
@ GenderRole
Definition AvailableVoicesModel.h:79
@ DirectoryRole
Definition AvailableVoicesModel.h:81
Q_INVOKABLE QString stateStr(VoiceState state) const
Q_INVOKABLE int rowCount(const QModelIndex &parent=QModelIndex()) const override
Q_INVOKABLE QVariant data(const QModelIndex &index, int role) const override
std::shared_ptr< VoiceManager > VoiceManagerRef
Definition VoiceManager.h:125
Definition Area.h:39