Date:2010-10-11 14:24:36 (13 years 5 months ago)
Author:nielsk
Commit:c4d718f8d47854398091a599e64ae8bb5f4a91a3
Message: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.

Files: downloadwidget.cpp (4 diffs)
downloadwidget.h (2 diffs)
mapwidget.cpp (2 diffs)

Change Details

downloadwidget.cpp
3535    m_startLevel(0),
3636    m_dlRect(),
3737    m_dlList(),
38    m_prefix("OSM"),
3839    m_up(new QLabel("N 0", this)),
3940    m_left(new QLabel("E 0", this)),
4041    m_right(new QLabel("E 0", this)),
4142    m_bottom(new QLabel("N 0", this)),
4243    m_levelSpinBox(new QSpinBox(this)),
4344    m_dlProgress(new QProgressBar(this)),
45    m_prefixInput(new QLineEdit(this)),
4446    m_skipExisting(new QCheckBox("S&kip already downloaded tiles", this))
4547{
4648    QGridLayout *layout = new QGridLayout(this);
...... 
6668    m_levelSpinBox->setRange(0, 18);
6769    layout->addWidget(m_levelSpinBox, 3, 2, 1, 2);
6870
71    label = new QLabel("Download into directory", this);
72    layout->addWidget(label, 4, 0);
73
74    m_prefixInput->setText(m_prefix);
75    layout->addWidget(m_prefixInput, 4, 2, 1, 2);
76
6977    m_skipExisting->setChecked(false);
70    layout->addWidget(m_skipExisting, 4, 0, 1, 0);
78    layout->addWidget(m_skipExisting, 5, 0, 1, 0);
7179
7280    m_dlProgress->setFormat("%v / %m");
73    layout->addWidget(m_dlProgress, 5, 0, 1, 4);
81    layout->addWidget(m_dlProgress, 6, 0, 1, 4);
7482
7583    QPushButton *start = new QPushButton("&Start", this);
7684    connect(start, SIGNAL(clicked()), this, SLOT(startDownload()));
77    layout->addWidget(start, 6, 0, 1, 2);
85    layout->addWidget(start, 7, 0, 1, 2);
7886
7987    QPushButton *back = new QPushButton("&Back", this);
8088    connect(back, SIGNAL(clicked()), this, SIGNAL(back()));
81    layout->addWidget(back, 6, 2, 1, 2);
89    layout->addWidget(back, 7, 2, 1, 2);
8290
8391    connect(m_manager, SIGNAL(finished(QNetworkReply*)),
8492            this, SLOT(replyFinished(QNetworkReply*)));
...... 
111119
112120void DownloadWidget::startDownload()
113121{
122    m_prefix = m_prefixInput->text();
114123    m_dlProgress->setValue(0);
115124    for (int level = m_startLevel; level <= m_levelSpinBox->value(); ++level) {
116125        int max = pow(2, level) - 1;
...... 
138147        int level = path.section('/', 1, 1).toInt();
139148        int x = path.section('/', 2, 2).toInt();
140149
141        QDir base(QDir::homePath()+"/Maps/OSM");
150        QDir base(QDir::homePath()+"/Maps/"+m_prefix);
142151        base.mkpath(QString("%1/%2").arg(level).arg(x));
143152
144153        QByteArray data = reply->readAll();
145154        if (!data.isEmpty()) {
146            QFile file(QDir::homePath()+"/Maps/OSM"+path);
155            QFile file(QDir::homePath()+"/Maps/"+m_prefix+path);
147156            if (file.open(QFile::WriteOnly)) {
148157                file.write(data);
149158            }
150159        }
151160        while (!m_dlList.isEmpty()) {
152161            QUrl url(m_dlList.takeFirst());
153            if (QFile::exists(QDir::homePath()+"/Maps/OSM"+url.path()) &&
162            if (QFile::exists(QDir::homePath()+"/Maps/"+m_prefix+url.path()) &&
154163                m_skipExisting->isChecked()) {
155164                int n = m_dlProgress->value();
156165                m_dlProgress->setValue(n+1);
downloadwidget.h
2222
2323#include <QtGui/QCheckBox>
2424#include <QtGui/QLabel>
25#include <QtGui/QLineEdit>
2526#include <QtGui/QProgressBar>
2627#include <QtGui/QSpinBox>
2728#include <QtGui/QWidget>
...... 
5455    int m_startLevel;
5556    QRectF m_dlRect;
5657    QStringList m_dlList;
58    QString m_prefix;
5759    QLabel *m_up, *m_left, *m_right, *m_bottom;
5860    QSpinBox *m_levelSpinBox;
5961    QProgressBar *m_dlProgress;
62    QLineEdit *m_prefixInput;
6063    QCheckBox *m_skipExisting;
6164
6265};
mapwidget.cpp
115115            m_minIndexYList << 0;
116116            m_maxIndexYList << (1 << i) - 1;
117117        }
118        m_baseName = QDir::homePath()+"/Maps/OSM/%z/%x/%y.png";
118        m_baseName = QDir::homePath()+"/Maps/%p/%z/%x/%y.png";
119119        QTimer::singleShot(100, this, SLOT(loadConfig()));
120120    }
121121
...... 
597597        sy.prepend(QString(m_yPadding-sy.length(), '0'));
598598        result = m_baseName;
599599        result.replace("%z", level).replace("%x", sx).replace("%y", sy);
600        if (result.contains("%p")) {
601            QStringList dirs = QDir(QDir::homePath()+"/Maps/").entryList(QDir::AllDirs|QDir::NoDotAndDotDot);
602            foreach (const QString &dir, dirs) {
603                QString tmp = result;
604                tmp.replace("%p", dir);
605                if (QFile::exists(tmp)) {
606                    return tmp;
607                }
608            }
609        }
600610    }
601611    return result;
602612}

Archive Download the corresponding diff file

Branches:
master



interactive