File indexing completed on 2025-01-05 03:59:35

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2010 Jens-Michael Hoffmann <jmho@c-xx.com>
0004 //
0005 
0006 #include "DownloadRegionDialog.h"
0007 
0008 #include <cmath>
0009 
0010 #include <QDialogButtonBox>
0011 #include <QGroupBox>
0012 #include <QHBoxLayout>
0013 #include <QHideEvent>
0014 #include <QLabel>
0015 #include <QComboBox>
0016 #include <QPushButton>
0017 #include <QButtonGroup>
0018 #include <QRadioButton>
0019 #include <QShowEvent>
0020 #include <QVBoxLayout>
0021 #include <QSpinBox>
0022 #include <QScrollArea>
0023 #include <QSet>
0024 #include <QStandardItemModel>
0025 #include <QTimer>
0026 
0027 #include <klocalizedstring.h>
0028 
0029 #include "GeoDataLatLonAltBox.h"
0030 #include "MarbleModel.h"
0031 #include "MarbleWidget.h"
0032 #include "LatLonBoxWidget.h"
0033 #include "TileLayer.h"
0034 #include "TextureLayer.h"
0035 #include "VectorTileLayer.h"
0036 #include "TileId.h"
0037 #include "TileCoordsPyramid.h"
0038 #include "TileLevelRangeWidget.h"
0039 #include "TileLoaderHelper.h"
0040 #include "GeoDataCoordinates.h"
0041 #include "GeoDataLineString.h"
0042 #include "DownloadRegion.h"
0043 #include "GeoSceneDocument.h"
0044 #include "GeoSceneMap.h"
0045 
0046 #include "digikam_debug.h"
0047 
0048 namespace Marble
0049 {
0050 
0051 int const maxTilesCount = 100000;
0052 int const minimumRouteOffset = 0;
0053 int const maximumRouteOffset = 10000;
0054 int averageTextureTileSize = 13; //The average size of a tile in kilobytes
0055 int averageVectorTileSize = 30; // The average size of a vector tile in kilobytes
0056 
0057 class Q_DECL_HIDDEN DownloadRegionDialog::Private
0058 {
0059 public:
0060     Private( MarbleWidget *const widget, QDialog * const dialog );
0061     QWidget * createSelectionMethodBox();
0062     QLayout * createTilesCounter();
0063     QWidget * createOkCancelButtonBox();
0064 
0065     bool hasRoute() const;
0066     bool hasTextureLayers() const;
0067     bool hasVectorLayers() const;
0068     QDialog * m_dialog;
0069     QLabel * m_layerLabel;
0070     QComboBox * m_layerComboBox;
0071     QButtonGroup * m_buttonGroup;
0072     QRadioButton * m_visibleRegionMethodButton;
0073     QRadioButton * m_specifiedRegionMethodButton;
0074     LatLonBoxWidget * m_latLonBoxWidget;
0075     TileLevelRangeWidget * m_tileLevelRangeWidget;
0076     QRadioButton *m_routeDownloadMethodButton;
0077     QLabel* m_routeOffsetLabel;
0078     QDoubleSpinBox *m_routeOffsetSpinBox;
0079     QLabel * m_tilesCountLabel;
0080     QLabel * m_tileSizeInfo;
0081     QPushButton * m_okButton;
0082     QPushButton * m_applyButton;
0083     TextureLayer const * m_textureLayer;
0084     VectorTileLayer const * m_vectorTileLayer;
0085     int m_visibleTileLevel;
0086     MarbleModel const*const m_model;
0087     MarbleWidget *const m_widget;
0088     SelectionMethod m_selectionMethod;
0089     GeoDataLatLonAltBox m_visibleRegion;
0090     DownloadRegion m_downloadRegion;
0091     TileType m_tileType;
0092 };
0093 
0094 DownloadRegionDialog::Private::Private( MarbleWidget * const widget,
0095                                         QDialog * const dialog )
0096     : m_dialog( dialog ),
0097       m_layerLabel( nullptr ),
0098       m_layerComboBox( nullptr ),
0099       m_buttonGroup(nullptr),
0100       m_visibleRegionMethodButton( nullptr ),
0101       m_specifiedRegionMethodButton( nullptr ),
0102       m_latLonBoxWidget( new LatLonBoxWidget ),
0103       m_tileLevelRangeWidget( new TileLevelRangeWidget ),
0104       m_routeDownloadMethodButton( nullptr ),
0105       m_routeOffsetLabel( nullptr ),
0106       m_routeOffsetSpinBox( nullptr ),
0107       m_tilesCountLabel( nullptr ),
0108       m_tileSizeInfo( nullptr ),
0109       m_okButton( nullptr ),
0110       m_applyButton( nullptr ),
0111       m_textureLayer( widget->textureLayer() ),
0112       m_vectorTileLayer( widget->vectorTileLayer() ),
0113       m_visibleTileLevel( 0 ),
0114       m_model( widget->model() ),
0115       m_widget( widget ),
0116       m_selectionMethod( VisibleRegionMethod ),
0117       m_visibleRegion()
0118 {
0119     m_latLonBoxWidget->setEnabled( false );
0120     m_latLonBoxWidget->setLatLonBox( m_visibleRegion );
0121     m_tileLevelRangeWidget->setDefaultLevel( m_visibleTileLevel );
0122     m_downloadRegion.setMarbleModel( widget->model() );
0123 }
0124 
0125 
0126 
0127 QWidget * DownloadRegionDialog::Private::createSelectionMethodBox()
0128 {
0129     m_buttonGroup = new QButtonGroup(m_dialog);
0130     m_buttonGroup->setExclusive(true);
0131     m_visibleRegionMethodButton = new QRadioButton( i18n( "Visible region" ) );
0132     m_buttonGroup->addButton(m_visibleRegionMethodButton);
0133     m_specifiedRegionMethodButton = new QRadioButton( i18n( "Specify region" ) );
0134     m_buttonGroup->addButton(m_specifiedRegionMethodButton);
0135     m_routeDownloadMethodButton = new QRadioButton( i18n( "Download Route" ) );
0136     m_buttonGroup->addButton(m_routeDownloadMethodButton);
0137     m_routeDownloadMethodButton->setToolTip( i18n( "Enabled when a route exists" ) );
0138     m_routeDownloadMethodButton->setEnabled( hasRoute() );
0139     m_routeDownloadMethodButton->setChecked( hasRoute() );
0140     m_routeOffsetSpinBox = new QDoubleSpinBox();
0141     m_routeOffsetSpinBox->setEnabled( hasRoute() );
0142     m_routeOffsetSpinBox->setRange( minimumRouteOffset, maximumRouteOffset );
0143     int defaultOffset = 500;
0144     m_routeOffsetSpinBox->setValue( defaultOffset );
0145     m_routeOffsetSpinBox->setSingleStep( 100 );
0146     m_routeOffsetSpinBox->setSuffix( QString::fromUtf8(" m") );
0147     m_routeOffsetSpinBox->setDecimals( 0 );
0148     m_routeOffsetSpinBox->setAlignment( Qt::AlignRight );
0149 
0150     m_routeOffsetLabel = new QLabel( i18n( "Offset from route:" ) );
0151     m_routeOffsetLabel->setAlignment( Qt::AlignHCenter );
0152 
0153     connect( m_buttonGroup, SIGNAL(buttonToggled(QAbstractButton*,bool)),
0154              m_dialog, SLOT(toggleSelectionMethod()) );
0155 
0156     QHBoxLayout *routeOffsetLayout = new QHBoxLayout;
0157     routeOffsetLayout->addWidget( m_routeOffsetLabel );
0158     routeOffsetLayout->insertSpacing( 0, 25 );
0159     routeOffsetLayout->addWidget( m_routeOffsetSpinBox );
0160 
0161     QVBoxLayout * const routeLayout = new QVBoxLayout;
0162     routeLayout->addWidget( m_routeDownloadMethodButton );
0163     routeLayout->addLayout( routeOffsetLayout );
0164 
0165     QVBoxLayout * const layout = new QVBoxLayout;
0166     layout->addWidget( m_visibleRegionMethodButton );
0167     layout->addLayout( routeLayout );
0168     layout->addWidget( m_specifiedRegionMethodButton );
0169     layout->addWidget( m_latLonBoxWidget );
0170 
0171     bool const smallScreen = MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen;
0172     m_specifiedRegionMethodButton->setVisible( !smallScreen );
0173     m_latLonBoxWidget->setVisible( !smallScreen );
0174 
0175     if ( smallScreen ) {
0176         QWidget * const selectionMethodWidget = new QWidget;
0177         selectionMethodWidget->setLayout( layout );
0178         return selectionMethodWidget;
0179     } else {
0180         QGroupBox * const selectionMethodBox = new QGroupBox( i18n( "Selection Method" ) );
0181         selectionMethodBox->setLayout( layout );
0182         return selectionMethodBox;
0183     }
0184 }
0185 
0186 QLayout * DownloadRegionDialog::Private::createTilesCounter()
0187 {
0188     QLabel * const description = new QLabel( i18n( "Number of tiles to download:" ) );
0189     m_tilesCountLabel = new QLabel;
0190     m_tileSizeInfo = new QLabel;
0191 
0192     QHBoxLayout * const tilesCountLayout = new QHBoxLayout;
0193     tilesCountLayout->addWidget( description );
0194     tilesCountLayout->addWidget( m_tilesCountLabel );
0195     //tilesCountLayout->insertSpacing( 0, 5 );
0196     QVBoxLayout * const layout = new QVBoxLayout;
0197     layout->addLayout( tilesCountLayout );
0198     layout->addWidget( m_tileSizeInfo );
0199     return layout;
0200 }
0201 
0202 QWidget * DownloadRegionDialog::Private::createOkCancelButtonBox()
0203 {
0204     QDialogButtonBox * const buttonBox = new QDialogButtonBox;
0205     m_okButton = buttonBox->addButton( QDialogButtonBox::Ok );
0206     m_applyButton = buttonBox->addButton( QDialogButtonBox::Apply );
0207     if ( MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen ) {
0208         buttonBox->removeButton( m_applyButton );
0209         m_applyButton->setVisible( false );
0210     }
0211     buttonBox->addButton( QDialogButtonBox::Cancel );
0212     connect( buttonBox, SIGNAL(accepted()), m_dialog, SLOT(accept()) );
0213     connect( buttonBox, SIGNAL(rejected()), m_dialog, SLOT(reject()) );
0214     connect( m_applyButton, SIGNAL(clicked()), m_dialog, SIGNAL(applied()) );
0215     return buttonBox;
0216 }
0217 
0218 bool DownloadRegionDialog::Private::hasRoute() const
0219 {
0220     return false;
0221 }
0222 
0223 bool DownloadRegionDialog::Private::hasTextureLayers() const
0224 {
0225     return m_model->mapTheme()->map()->hasTextureLayers();
0226 }
0227 
0228 bool DownloadRegionDialog::Private::hasVectorLayers() const
0229 {
0230     return m_model->mapTheme()->map()->hasVectorLayers();
0231 }
0232 
0233 DownloadRegionDialog::DownloadRegionDialog( MarbleWidget *const widget, QWidget * const parent,
0234                                             Qt::WindowFlags const f )
0235     : QDialog( parent, f ),
0236       d( new Private( widget, this ))
0237 {
0238     setWindowTitle( i18n( "Download Region" ));
0239     QVBoxLayout * const layout = new QVBoxLayout;
0240     d->m_layerLabel = new QLabel( i18n( "Tile type to be downloaded:" ));
0241     d->m_layerComboBox = new QComboBox();
0242     d->m_layerComboBox->addItem(i18n("Texture tiles"));
0243     d->m_layerComboBox->addItem(i18n("Vector tiles"));
0244     d->m_layerComboBox->setToolTip(i18n("Allows selection between layer types that are visibly being rendered."));
0245     updateTileLayer();
0246 
0247     layout->addWidget( d->m_layerLabel );
0248     layout->addWidget( d->m_layerComboBox );
0249     layout->addWidget( d->createSelectionMethodBox() );
0250     layout->addWidget( d->m_tileLevelRangeWidget );
0251     layout->addStretch();
0252     layout->addLayout( d->createTilesCounter() );
0253 
0254     if ( MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen ) {
0255         QWidget* widget = new QWidget( this );
0256         widget->setLayout( layout );
0257         QScrollArea* scrollArea = new QScrollArea( this );
0258         scrollArea->setFrameShape( QFrame::NoFrame );
0259         scrollArea->setWidget( widget );
0260         QVBoxLayout * const mainLayout = new QVBoxLayout;
0261         mainLayout->addWidget( scrollArea );
0262         mainLayout->addWidget( d->createOkCancelButtonBox() );
0263         setLayout( mainLayout );
0264     } else {
0265         layout->addWidget( d->createOkCancelButtonBox() );
0266         setLayout( layout );
0267     }
0268 
0269     connect( d->m_layerComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
0270              this, &DownloadRegionDialog::updateTileCount );
0271     connect( d->m_latLonBoxWidget, &Marble::LatLonBoxWidget::valueChanged,
0272              this, &DownloadRegionDialog::updateTileCount );
0273     connect( d->m_tileLevelRangeWidget, &TileLevelRangeWidget::topLevelChanged,
0274              this, &DownloadRegionDialog::updateTileCount );
0275     connect( d->m_tileLevelRangeWidget, &TileLevelRangeWidget::bottomLevelChanged,
0276              this, &DownloadRegionDialog::updateTileCount );
0277     connect( d->m_routeOffsetSpinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
0278              this, &DownloadRegionDialog::updateTileCount );
0279     connect( d->m_routeOffsetSpinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
0280              this, &DownloadRegionDialog::setOffsetUnit );
0281     connect( d->m_model, &MarbleModel::themeChanged,
0282              this, &DownloadRegionDialog::delayUpdateTileLayer);
0283 }
0284 
0285 DownloadRegionDialog::~DownloadRegionDialog()
0286 {
0287     delete d;
0288 }
0289 
0290 void DownloadRegionDialog::setAllowedTileLevelRange( int const minimumTileLevel,
0291                                                      int const maximumTileLevel )
0292 {
0293     d->m_tileLevelRangeWidget->setAllowedLevelRange( minimumTileLevel, maximumTileLevel );
0294 }
0295 
0296 void DownloadRegionDialog::setVisibleTileLevel( int const tileLevel )
0297 {
0298     d->m_visibleTileLevel = tileLevel;
0299     d->m_tileLevelRangeWidget->setDefaultLevel( tileLevel );
0300     d->m_downloadRegion.setVisibleTileLevel( tileLevel );
0301 }
0302 
0303 void DownloadRegionDialog::setSelectionMethod( SelectionMethod const selectionMethod )
0304 {
0305     d->m_selectionMethod = selectionMethod;
0306     switch ( selectionMethod ) {
0307     case VisibleRegionMethod:
0308         d->m_visibleRegionMethodButton->setChecked( true );
0309         d->m_routeOffsetLabel->setEnabled( false );
0310         d->m_routeOffsetSpinBox->setEnabled( false );
0311         d->m_latLonBoxWidget->setEnabled( false );
0312         setSpecifiedLatLonAltBox( d->m_visibleRegion );
0313         break;
0314     case SpecifiedRegionMethod:
0315         d->m_specifiedRegionMethodButton->setChecked( true );
0316         d->m_routeOffsetLabel->setEnabled( false );
0317         d->m_routeOffsetSpinBox->setEnabled( false );
0318         d->m_latLonBoxWidget->setEnabled( true );
0319         break;
0320     case RouteDownloadMethod:
0321         d->m_routeDownloadMethodButton->setChecked( true );
0322         d->m_routeOffsetLabel->setEnabled( true );
0323         d->m_routeOffsetSpinBox->setEnabled( true );
0324         d->m_latLonBoxWidget->setEnabled( false );
0325     }
0326 
0327     updateTileCount();
0328 }
0329 
0330 QVector<TileCoordsPyramid> DownloadRegionDialog::region() const
0331 {
0332     if ( !d->hasTextureLayers() && !d->hasVectorLayers() ) {
0333         return QVector<TileCoordsPyramid>();
0334     }
0335 
0336     d->m_visibleTileLevel = (tileType() == TextureTileType && d->m_textureLayer->tileZoomLevel() != -1)
0337             ? d->m_textureLayer->tileZoomLevel() : d->m_vectorTileLayer->tileZoomLevel();
0338 
0339     const TileLayer * tileLayer = (tileType() == TextureTileType && d->m_textureLayer->layerCount() > 0)
0340             ? dynamic_cast<const TileLayer *>(d->m_textureLayer)
0341             : dynamic_cast<const TileLayer *>(d->m_vectorTileLayer);
0342 
0343     d->m_downloadRegion.setTileLevelRange( d->m_tileLevelRangeWidget->topLevel(),
0344                                            d->m_tileLevelRangeWidget->bottomLevel() );
0345     d->m_downloadRegion.setVisibleTileLevel( d->m_visibleTileLevel );
0346 
0347     // check whether "visible region" or "lat/lon region" is selection method
0348     GeoDataLatLonAltBox downloadRegion;
0349     switch ( d->m_selectionMethod ) {
0350     case VisibleRegionMethod:
0351         downloadRegion = d->m_visibleRegion;
0352         break;
0353     case SpecifiedRegionMethod:
0354         downloadRegion = GeoDataLatLonAltBox( d->m_latLonBoxWidget->latLonBox(), 0, 0 );
0355         break;
0356     case RouteDownloadMethod:
0357         qreal offset = d->m_routeOffsetSpinBox->value();
0358         if (d->m_routeOffsetSpinBox->suffix() == QLatin1String(" km")) {
0359             offset *= KM2METER;
0360         }
0361         const GeoDataLineString waypoints;// = d->m_model->routingManager()->routingModel()->route().path();
0362         return d->m_downloadRegion.fromPath( tileLayer, offset, waypoints );
0363     }
0364 
0365     // For Mercator tiles limit the LatLonBox to the valid tile range.
0366     if (tileLayer->tileProjection()->type() == GeoSceneAbstractTileProjection::Mercator) {
0367         downloadRegion.setNorth(qMin(downloadRegion.north(), +1.4835));
0368         downloadRegion.setSouth(qMax(downloadRegion.south(), -1.4835));
0369     }
0370 
0371     return d->m_downloadRegion.region( tileLayer, downloadRegion );
0372 }
0373 
0374 TileType DownloadRegionDialog::tileType() const
0375 {
0376     return d->m_layerComboBox->currentIndex() == 0 ? TextureTileType : VectorTileType;
0377 }
0378 
0379 void DownloadRegionDialog::setSpecifiedLatLonAltBox( GeoDataLatLonAltBox const & region )
0380 {
0381     d->m_latLonBoxWidget->setLatLonBox( region );
0382 }
0383 
0384 void DownloadRegionDialog::setVisibleLatLonAltBox( GeoDataLatLonAltBox const & region )
0385 {
0386     d->m_visibleRegion = region;
0387 
0388     // update lat/lon widget only if not active to prevent that users unintentionally loose
0389     // entered values
0390     if ( d->m_selectionMethod == VisibleRegionMethod ) {
0391         setSpecifiedLatLonAltBox( region );
0392     }
0393     updateTileCount();
0394 }
0395 
0396 void DownloadRegionDialog::updateTileLayer()
0397 {
0398     updateTileType();
0399     updateTileCount();
0400 }
0401 
0402 void DownloadRegionDialog::delayUpdateTileLayer()
0403 {
0404     QTimer::singleShot(500, this, &DownloadRegionDialog::updateTileLayer);
0405 }
0406 
0407 void DownloadRegionDialog::hideEvent( QHideEvent * event )
0408 {
0409     disconnect( d->m_widget, SIGNAL(visibleLatLonAltBoxChanged(GeoDataLatLonAltBox)),
0410                 this, SLOT(setVisibleLatLonAltBox(GeoDataLatLonAltBox)) );
0411     disconnect( d->m_widget, SIGNAL(themeChanged(QString)),
0412                 this, SLOT(delayUpdateTileLayer()) );
0413     disconnect( d->m_widget, SIGNAL(propertyValueChanged(QString,bool)),
0414                 this, SLOT(delayUpdateTileLayer()) );
0415 
0416     Q_EMIT hidden();
0417     event->accept();
0418 }
0419 
0420 void DownloadRegionDialog::showEvent( QShowEvent * event )
0421 {
0422     connect( d->m_widget, SIGNAL(visibleLatLonAltBoxChanged(GeoDataLatLonAltBox)),
0423              this, SLOT(setVisibleLatLonAltBox(GeoDataLatLonAltBox)) );
0424     connect( d->m_widget, SIGNAL(themeChanged(QString)),
0425              this, SLOT(delayUpdateTileLayer()) );
0426     connect( d->m_widget, SIGNAL(propertyValueChanged(QString,bool)),
0427              this, SLOT(delayUpdateTileLayer()) );
0428 
0429     setVisibleTileLevel(d->m_widget->tileZoomLevel());
0430 
0431     updateTileCount();
0432 
0433     Q_EMIT shown();
0434     event->accept();
0435 }
0436 
0437 void DownloadRegionDialog::toggleSelectionMethod()
0438 {
0439     if( d->m_specifiedRegionMethodButton->isChecked() ) {
0440         setSelectionMethod( SpecifiedRegionMethod );
0441     }
0442     else if( d->m_routeDownloadMethodButton->isChecked() ) {
0443         setSelectionMethod( RouteDownloadMethod );
0444     }
0445     else if( d->m_specifiedRegionMethodButton->isChecked() ) {
0446         setSelectionMethod( SpecifiedRegionMethod );
0447     }
0448 }
0449 
0450 void DownloadRegionDialog::updateTileType()
0451 {
0452     bool hasVisibleTextureLayers = d->hasTextureLayers() && d->m_textureLayer->layerCount() > 0;
0453     bool hasVisibleVectorLayers = d->hasVectorLayers() && d->m_vectorTileLayer->layerCount() > 0;
0454 
0455     QStandardItemModel *model = qobject_cast<QStandardItemModel *>(d->m_layerComboBox->model());
0456     Q_ASSERT(model != nullptr);
0457     QStandardItem *item = nullptr;
0458     item = model->item(0);
0459     item->setFlags(hasVisibleTextureLayers ? item->flags() | Qt::ItemIsEnabled
0460                                            : item->flags() & ~Qt::ItemIsEnabled);
0461     item = model->item(1);
0462     item->setFlags(hasVisibleVectorLayers ? item->flags() | Qt::ItemIsEnabled
0463                                           : item->flags() & ~Qt::ItemIsEnabled);
0464 
0465     bool allTileTypesAvailable = hasVisibleTextureLayers && hasVisibleVectorLayers;
0466 
0467     d->m_layerComboBox->setEnabled(allTileTypesAvailable);
0468     if (hasVisibleVectorLayers) {
0469         d->m_layerComboBox->setCurrentIndex(1);
0470     }
0471     else if (hasVisibleTextureLayers && !hasVisibleVectorLayers) {
0472         d->m_layerComboBox->setCurrentIndex(0);
0473     }
0474 }
0475 
0476 void DownloadRegionDialog::updateTileCount()
0477 {
0478     if ( !isVisible() ) {
0479         return;
0480     }
0481 
0482     qint64 tilesCount = 0;
0483     QString themeId( d->m_model->mapThemeId() );
0484     QVector<TileCoordsPyramid> const pyramid = region();
0485     Q_ASSERT( !pyramid.isEmpty() );
0486     if( pyramid.size() == 1 ) {
0487         tilesCount = pyramid[0].tilesCount();
0488     }
0489     else {
0490         for( int level = pyramid[0].bottomLevel(); level>= pyramid[0].topLevel(); --level ) {
0491             QSet<TileId> tileIdSet;
0492             for( int i = 0; i < pyramid.size(); ++i ) {
0493                 QRect const coords = pyramid[i].coords( level );
0494                 int x1, y1, x2, y2;
0495                 coords.getCoords( &x1, &y1, &x2, &y2 );
0496                 for ( int x = x1; x <= x2; ++x ) {
0497                     for ( int y = y1; y <= y2; ++y ) {
0498                         TileId const tileId( 0, level, x, y );
0499                         tileIdSet.insert( tileId );
0500                     }
0501                 }
0502             }
0503             tilesCount += tileIdSet.count();
0504         }
0505     }
0506 
0507     qreal tileDownloadSize = 0;
0508 
0509     if ( tilesCount > maxTilesCount ) {
0510         d->m_tileSizeInfo->setToolTip( QString() );
0511         //~ singular There is a limit of %n tile to download.
0512         //~ plural There is a limit of %n tiles to download.
0513         d->m_tileSizeInfo->setText( i18n( "There is a limit of %1 tile(s) to download.", maxTilesCount ) );
0514     } else {
0515         if (themeId == QLatin1String("earth/openstreetmap/openstreetmap.dgml") ||
0516             themeId == QLatin1String("earth/openstreetmap/openseamap.dgml") ||
0517             themeId == QLatin1String("earth/vectorosm/vectorosm.dgml") ) {
0518 
0519             tileDownloadSize = tileType() == TextureTileType
0520                     ? tilesCount * averageTextureTileSize
0521                     : tilesCount * averageVectorTileSize;
0522 
0523             d->m_tileSizeInfo->setToolTip( i18n( "Approximate size of the tiles to be downloaded" ) );
0524 
0525             if( tileDownloadSize > 1024 ) {
0526                 tileDownloadSize = tileDownloadSize / 1024;
0527                 d->m_tileSizeInfo->setText( i18n( "Estimated download size: %1 MB", ceil( tileDownloadSize ) ) );
0528             }
0529             else {
0530                 d->m_tileSizeInfo->setText( i18n( "Estimated download size: %1 kB", tileDownloadSize ) );
0531             }
0532         }
0533         else {
0534             d->m_tileSizeInfo->setToolTip( QString() );
0535             d->m_tileSizeInfo->clear();
0536         }
0537     }
0538 
0539     d->m_tilesCountLabel->setText( QString::number( tilesCount ) );
0540     bool const tilesCountWithinLimits = tilesCount > 0 && tilesCount <= maxTilesCount;
0541     d->m_okButton->setEnabled( tilesCountWithinLimits );
0542     d->m_applyButton->setEnabled( tilesCountWithinLimits );
0543 }
0544 
0545 void DownloadRegionDialog::updateRouteDialog()
0546 {
0547     d->m_routeDownloadMethodButton->setEnabled( d->hasRoute() );
0548     d->m_routeDownloadMethodButton->setChecked( d->hasRoute() );
0549     if( !d->hasRoute() ) {
0550         setSelectionMethod( VisibleRegionMethod );
0551     }
0552 }
0553 
0554 void DownloadRegionDialog::setOffsetUnit()
0555 {
0556     qreal offset = d->m_routeOffsetSpinBox->value();
0557 
0558     if( offset >= 1100 ) {
0559         d->m_routeOffsetSpinBox->setSuffix( QString::fromUtf8(" km") );
0560         d->m_routeOffsetSpinBox->setRange( minimumRouteOffset * METER2KM, maximumRouteOffset * METER2KM );
0561         d->m_routeOffsetSpinBox->setDecimals( 1 );
0562         d->m_routeOffsetSpinBox->setValue( offset * METER2KM );
0563         d->m_routeOffsetSpinBox->setSingleStep( 0.1 );
0564     }
0565     else if (offset <= 1 && d->m_routeOffsetSpinBox->suffix() == QLatin1String(" km")) {
0566         d->m_routeOffsetSpinBox->setSuffix( QString::fromUtf8(" m") );
0567         d->m_routeOffsetSpinBox->setRange( minimumRouteOffset, maximumRouteOffset );
0568         d->m_routeOffsetSpinBox->setDecimals( 0 );
0569         d->m_routeOffsetSpinBox->setValue( offset * KM2METER );
0570         d->m_routeOffsetSpinBox->setSingleStep( 100 );
0571     }
0572 }
0573 
0574 }
0575 
0576 #include "moc_DownloadRegionDialog.cpp"