libosmscout
1.1.1
Toggle main menu visibility
Loading...
Searching...
No Matches
libosmscout-client-qt
include
osmscoutclientqt
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
23
#include <
osmscoutclientqt/ClientQtImportExport.h
>
24
25
#include <osmscoutclient/VoiceProvider.h>
26
27
#include <
osmscoutclientqt/VoiceManager.h
>
28
#include <
osmscoutclientqt/Voice.h
>
29
30
#include <QAbstractListModel>
31
#include <QNetworkDiskCache>
32
#include <QNetworkAccessManager>
33
34
namespace
osmscout
{
35
56
class
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
62
signals:
63
void
loadingChanged
();
64
65
public slots:
66
void
listDownloaded
(const VoiceProvider &provider, QNetworkReply*);
67
void
reload
();
68
69
void
onVoiceStateChanged
(const
AvailableVoice
&voice);
70
71
public:
72
AvailableVoicesModel
();
73
74
virtual ~
AvailableVoicesModel
();
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
88
enum
VoiceState
{
89
Available
,
90
Downloading
,
91
Downloaded
92
};
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
113
private
:
114
int
findRow(
const
QString &lang,
const
QString &name);
115
116
private
:
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
ClientQtImportExport.h
OSMSCOUT_CLIENT_QT_API
#define OSMSCOUT_CLIENT_QT_API
Definition
ClientQtImportExport.h:45
Voice.h
VoiceManager.h
osmscout::AvailableVoice
Definition
Voice.h:31
osmscout::AvailableVoicesModel::getFetchError
QString getFetchError()
Definition
AvailableVoicesModel.h:109
osmscout::AvailableVoicesModel::remove
Q_INVOKABLE void remove(const QModelIndex &index)
osmscout::AvailableVoicesModel::VoiceState
VoiceState
Definition
AvailableVoicesModel.h:88
osmscout::AvailableVoicesModel::Downloading
@ Downloading
Definition
AvailableVoicesModel.h:90
osmscout::AvailableVoicesModel::Downloaded
@ Downloaded
Definition
AvailableVoicesModel.h:91
osmscout::AvailableVoicesModel::Available
@ Available
Definition
AvailableVoicesModel.h:89
osmscout::AvailableVoicesModel::loading
bool loading
Definition
AvailableVoicesModel.h:59
osmscout::AvailableVoicesModel::AvailableVoicesModel
AvailableVoicesModel()
osmscout::AvailableVoicesModel::flags
Q_INVOKABLE Qt::ItemFlags flags(const QModelIndex &index) const override
osmscout::AvailableVoicesModel::onVoiceStateChanged
void onVoiceStateChanged(const AvailableVoice &voice)
osmscout::AvailableVoicesModel::isLoading
bool isLoading()
Definition
AvailableVoicesModel.h:105
osmscout::AvailableVoicesModel::roleNames
QHash< int, QByteArray > roleNames() const override
osmscout::AvailableVoicesModel::listDownloaded
void listDownloaded(const VoiceProvider &provider, QNetworkReply *)
osmscout::AvailableVoicesModel::reload
void reload()
osmscout::AvailableVoicesModel::fetchError
QString fetchError
Definition
AvailableVoicesModel.h:60
osmscout::AvailableVoicesModel::download
Q_INVOKABLE void download(const QModelIndex &index)
osmscout::AvailableVoicesModel::loadingChanged
void loadingChanged()
osmscout::AvailableVoicesModel::Roles
Roles
Definition
AvailableVoicesModel.h:76
osmscout::AvailableVoicesModel::LangRole
@ LangRole
Definition
AvailableVoicesModel.h:78
osmscout::AvailableVoicesModel::LicenseRole
@ LicenseRole
Definition
AvailableVoicesModel.h:80
osmscout::AvailableVoicesModel::StateRole
@ StateRole
Definition
AvailableVoicesModel.h:84
osmscout::AvailableVoicesModel::NameRole
@ NameRole
Definition
AvailableVoicesModel.h:77
osmscout::AvailableVoicesModel::AuthorRole
@ AuthorRole
Definition
AvailableVoicesModel.h:82
osmscout::AvailableVoicesModel::DescriptionRole
@ DescriptionRole
Definition
AvailableVoicesModel.h:83
osmscout::AvailableVoicesModel::GenderRole
@ GenderRole
Definition
AvailableVoicesModel.h:79
osmscout::AvailableVoicesModel::DirectoryRole
@ DirectoryRole
Definition
AvailableVoicesModel.h:81
osmscout::AvailableVoicesModel::stateStr
Q_INVOKABLE QString stateStr(VoiceState state) const
osmscout::AvailableVoicesModel::rowCount
Q_INVOKABLE int rowCount(const QModelIndex &parent=QModelIndex()) const override
osmscout::AvailableVoicesModel::data
Q_INVOKABLE QVariant data(const QModelIndex &index, int role) const override
osmscout::VoiceManagerRef
std::shared_ptr< VoiceManager > VoiceManagerRef
Definition
VoiceManager.h:125
osmscout
Definition
Area.h:39
Generated by
1.17.0