mirror of
git://projects.qi-hardware.com/nanomap.git
synced 2024-12-18 08:24:04 +02:00
let the user select a subdirectory to mass download tiles into. Use this for tiles you want to delete after usage. Just delete the subdirectory in $HOME/Maps.
This commit is contained in:
parent
8daff2686c
commit
c4d718f8d4
@ -35,12 +35,14 @@ DownloadWidget::DownloadWidget(QWidget *parent)
|
|||||||
m_startLevel(0),
|
m_startLevel(0),
|
||||||
m_dlRect(),
|
m_dlRect(),
|
||||||
m_dlList(),
|
m_dlList(),
|
||||||
|
m_prefix("OSM"),
|
||||||
m_up(new QLabel("N 0", this)),
|
m_up(new QLabel("N 0", this)),
|
||||||
m_left(new QLabel("E 0", this)),
|
m_left(new QLabel("E 0", this)),
|
||||||
m_right(new QLabel("E 0", this)),
|
m_right(new QLabel("E 0", this)),
|
||||||
m_bottom(new QLabel("N 0", this)),
|
m_bottom(new QLabel("N 0", this)),
|
||||||
m_levelSpinBox(new QSpinBox(this)),
|
m_levelSpinBox(new QSpinBox(this)),
|
||||||
m_dlProgress(new QProgressBar(this)),
|
m_dlProgress(new QProgressBar(this)),
|
||||||
|
m_prefixInput(new QLineEdit(this)),
|
||||||
m_skipExisting(new QCheckBox("S&kip already downloaded tiles", this))
|
m_skipExisting(new QCheckBox("S&kip already downloaded tiles", this))
|
||||||
{
|
{
|
||||||
QGridLayout *layout = new QGridLayout(this);
|
QGridLayout *layout = new QGridLayout(this);
|
||||||
@ -66,19 +68,25 @@ DownloadWidget::DownloadWidget(QWidget *parent)
|
|||||||
m_levelSpinBox->setRange(0, 18);
|
m_levelSpinBox->setRange(0, 18);
|
||||||
layout->addWidget(m_levelSpinBox, 3, 2, 1, 2);
|
layout->addWidget(m_levelSpinBox, 3, 2, 1, 2);
|
||||||
|
|
||||||
|
label = new QLabel("Download into directory", this);
|
||||||
|
layout->addWidget(label, 4, 0);
|
||||||
|
|
||||||
|
m_prefixInput->setText(m_prefix);
|
||||||
|
layout->addWidget(m_prefixInput, 4, 2, 1, 2);
|
||||||
|
|
||||||
m_skipExisting->setChecked(false);
|
m_skipExisting->setChecked(false);
|
||||||
layout->addWidget(m_skipExisting, 4, 0, 1, 0);
|
layout->addWidget(m_skipExisting, 5, 0, 1, 0);
|
||||||
|
|
||||||
m_dlProgress->setFormat("%v / %m");
|
m_dlProgress->setFormat("%v / %m");
|
||||||
layout->addWidget(m_dlProgress, 5, 0, 1, 4);
|
layout->addWidget(m_dlProgress, 6, 0, 1, 4);
|
||||||
|
|
||||||
QPushButton *start = new QPushButton("&Start", this);
|
QPushButton *start = new QPushButton("&Start", this);
|
||||||
connect(start, SIGNAL(clicked()), this, SLOT(startDownload()));
|
connect(start, SIGNAL(clicked()), this, SLOT(startDownload()));
|
||||||
layout->addWidget(start, 6, 0, 1, 2);
|
layout->addWidget(start, 7, 0, 1, 2);
|
||||||
|
|
||||||
QPushButton *back = new QPushButton("&Back", this);
|
QPushButton *back = new QPushButton("&Back", this);
|
||||||
connect(back, SIGNAL(clicked()), this, SIGNAL(back()));
|
connect(back, SIGNAL(clicked()), this, SIGNAL(back()));
|
||||||
layout->addWidget(back, 6, 2, 1, 2);
|
layout->addWidget(back, 7, 2, 1, 2);
|
||||||
|
|
||||||
connect(m_manager, SIGNAL(finished(QNetworkReply*)),
|
connect(m_manager, SIGNAL(finished(QNetworkReply*)),
|
||||||
this, SLOT(replyFinished(QNetworkReply*)));
|
this, SLOT(replyFinished(QNetworkReply*)));
|
||||||
@ -111,6 +119,7 @@ void DownloadWidget::setDownloadRect(const QRectF &rect)
|
|||||||
|
|
||||||
void DownloadWidget::startDownload()
|
void DownloadWidget::startDownload()
|
||||||
{
|
{
|
||||||
|
m_prefix = m_prefixInput->text();
|
||||||
m_dlProgress->setValue(0);
|
m_dlProgress->setValue(0);
|
||||||
for (int level = m_startLevel; level <= m_levelSpinBox->value(); ++level) {
|
for (int level = m_startLevel; level <= m_levelSpinBox->value(); ++level) {
|
||||||
int max = pow(2, level) - 1;
|
int max = pow(2, level) - 1;
|
||||||
@ -138,19 +147,19 @@ void DownloadWidget::replyFinished(QNetworkReply *reply)
|
|||||||
int level = path.section('/', 1, 1).toInt();
|
int level = path.section('/', 1, 1).toInt();
|
||||||
int x = path.section('/', 2, 2).toInt();
|
int x = path.section('/', 2, 2).toInt();
|
||||||
|
|
||||||
QDir base(QDir::homePath()+"/Maps/OSM");
|
QDir base(QDir::homePath()+"/Maps/"+m_prefix);
|
||||||
base.mkpath(QString("%1/%2").arg(level).arg(x));
|
base.mkpath(QString("%1/%2").arg(level).arg(x));
|
||||||
|
|
||||||
QByteArray data = reply->readAll();
|
QByteArray data = reply->readAll();
|
||||||
if (!data.isEmpty()) {
|
if (!data.isEmpty()) {
|
||||||
QFile file(QDir::homePath()+"/Maps/OSM"+path);
|
QFile file(QDir::homePath()+"/Maps/"+m_prefix+path);
|
||||||
if (file.open(QFile::WriteOnly)) {
|
if (file.open(QFile::WriteOnly)) {
|
||||||
file.write(data);
|
file.write(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (!m_dlList.isEmpty()) {
|
while (!m_dlList.isEmpty()) {
|
||||||
QUrl url(m_dlList.takeFirst());
|
QUrl url(m_dlList.takeFirst());
|
||||||
if (QFile::exists(QDir::homePath()+"/Maps/OSM"+url.path()) &&
|
if (QFile::exists(QDir::homePath()+"/Maps/"+m_prefix+url.path()) &&
|
||||||
m_skipExisting->isChecked()) {
|
m_skipExisting->isChecked()) {
|
||||||
int n = m_dlProgress->value();
|
int n = m_dlProgress->value();
|
||||||
m_dlProgress->setValue(n+1);
|
m_dlProgress->setValue(n+1);
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include <QtGui/QCheckBox>
|
#include <QtGui/QCheckBox>
|
||||||
#include <QtGui/QLabel>
|
#include <QtGui/QLabel>
|
||||||
|
#include <QtGui/QLineEdit>
|
||||||
#include <QtGui/QProgressBar>
|
#include <QtGui/QProgressBar>
|
||||||
#include <QtGui/QSpinBox>
|
#include <QtGui/QSpinBox>
|
||||||
#include <QtGui/QWidget>
|
#include <QtGui/QWidget>
|
||||||
@ -54,9 +55,11 @@ private:
|
|||||||
int m_startLevel;
|
int m_startLevel;
|
||||||
QRectF m_dlRect;
|
QRectF m_dlRect;
|
||||||
QStringList m_dlList;
|
QStringList m_dlList;
|
||||||
|
QString m_prefix;
|
||||||
QLabel *m_up, *m_left, *m_right, *m_bottom;
|
QLabel *m_up, *m_left, *m_right, *m_bottom;
|
||||||
QSpinBox *m_levelSpinBox;
|
QSpinBox *m_levelSpinBox;
|
||||||
QProgressBar *m_dlProgress;
|
QProgressBar *m_dlProgress;
|
||||||
|
QLineEdit *m_prefixInput;
|
||||||
QCheckBox *m_skipExisting;
|
QCheckBox *m_skipExisting;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -115,7 +115,7 @@ MapWidget::MapWidget(QWidget *parent)
|
|||||||
m_minIndexYList << 0;
|
m_minIndexYList << 0;
|
||||||
m_maxIndexYList << (1 << i) - 1;
|
m_maxIndexYList << (1 << i) - 1;
|
||||||
}
|
}
|
||||||
m_baseName = QDir::homePath()+"/Maps/OSM/%z/%x/%y.png";
|
m_baseName = QDir::homePath()+"/Maps/%p/%z/%x/%y.png";
|
||||||
QTimer::singleShot(100, this, SLOT(loadConfig()));
|
QTimer::singleShot(100, this, SLOT(loadConfig()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -597,6 +597,16 @@ QString MapWidget::filename(int x, int y)
|
|||||||
sy.prepend(QString(m_yPadding-sy.length(), '0'));
|
sy.prepend(QString(m_yPadding-sy.length(), '0'));
|
||||||
result = m_baseName;
|
result = m_baseName;
|
||||||
result.replace("%z", level).replace("%x", sx).replace("%y", sy);
|
result.replace("%z", level).replace("%x", sx).replace("%y", sy);
|
||||||
|
if (result.contains("%p")) {
|
||||||
|
QStringList dirs = QDir(QDir::homePath()+"/Maps/").entryList(QDir::AllDirs|QDir::NoDotAndDotDot);
|
||||||
|
foreach (const QString &dir, dirs) {
|
||||||
|
QString tmp = result;
|
||||||
|
tmp.replace("%p", dir);
|
||||||
|
if (QFile::exists(tmp)) {
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user