6#include "CloudRouteModel.h"
10#include "MarbleDirs.h"
14#include <QNetworkAccessManager>
15#include <QNetworkReply>
16#include <QNetworkRequest>
23class Q_DECL_HIDDEN CloudRouteModel::Private
32 qint64 m_downloadedSize;
39CloudRouteModel::Private::Private()
43 m_cacheDir = MarbleDirs::localPath() +
QLatin1StringView(
"/cloudsync/cache/routes/");
46CloudRouteModel::CloudRouteModel(
QObject *parent)
53CloudRouteModel::~CloudRouteModel() =
default;
57 Q_ASSERT(checkIndex(index, QAbstractItemModel::CheckIndexOption::IndexIsValid));
60 return preview(index);
62 return d->m_items.at(index.
row()).identifier();
64 return d->m_items.at(index.
row()).name();
66 return d->m_items.at(index.
row()).previewUrl();
68 return d->m_items.at(index.
row()).distance();
70 return d->m_items.at(index.
row()).duration();
72 return isCached(index);
74 return isDownloading(index);
76 return d->m_items.at(index.
row()).onCloud();
82int CloudRouteModel::rowCount(
const QModelIndex &parent)
const
84 return parent.
isValid() ? 0 : d->m_items.count();
91 roles[Timestamp] =
"identifier";
92 roles[PreviewUrl] =
"previewUrl";
93 roles[Distance] =
"distance";
95 roles[IsCached] =
"isCached";
96 roles[IsDownloading] =
"isDownloading";
97 roles[IsOnCloud] =
"isOnCloud";
105 d->m_previewQueue.
clear();
106 d->m_requestedPreviews.clear();
110bool CloudRouteModel::isCached(
const QModelIndex &index)
const
117 return d->m_downloading;
122 d->m_downloading = index;
125bool CloudRouteModel::isDownloading(
const QModelIndex &index)
const
127 return d->m_downloading == index;
130qint64 CloudRouteModel::totalSize()
const
132 return d->m_totalSize;
135qint64 CloudRouteModel::downloadedSize()
const
137 return d->m_downloadedSize;
142 QString timestamp = d->m_items.
at(index.
row()).identifier();
143 if (d->m_items.at(index.
row()).preview().isNull() && !d->m_requestedPreviews.contains(timestamp)) {
144 QUrl url(d->m_items.at(index.
row()).previewUrl());
147 d->m_previewQueue.insert(reply, index.
row());
148 d->m_requestedPreviews.insert(timestamp);
151 return d->m_items.at(index.
row()).preview();
156 int position = d->m_previewQueue.take(reply);
158 if (position >= d->m_items.count()) {
162 RouteItem &route = d->m_items[position];
164 route.setPreview(icon);
165 d->m_requestedPreviews.remove(route.identifier());
168void CloudRouteModel::updateProgress(qint64 currentSize, qint64 totalSize)
170 d->m_totalSize = totalSize;
171 d->m_downloadedSize = currentSize;
172 dataChanged(d->m_downloading, d->m_downloading);
173 if (currentSize == totalSize) {
176 d->m_downloadedSize = 0;
182#include "moc_CloudRouteModel.cpp"
Binds a QML item to a specific geodetic location in screen coordinates.
virtual QHash< int, QByteArray > roleNames() const const
bool exists() const const
QImage fromData(QByteArrayView data, const char *format)
QVariant data(int role) const const
bool isValid() const const
void finished(QNetworkReply *reply)
QPixmap fromImage(QImage &&image, Qt::ImageConversionFlags flags)
const QChar at(qsizetype position) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QString toString() const const