15 #include <QDialogButtonBox>
17 #include <QHBoxLayout>
20 #include <QPushButton>
21 #include <QRadioButton>
23 #include <QVBoxLayout>
25 #include <QScrollArea>
54 class DownloadRegionDialog::Private
58 QWidget * createSelectionMethodBox();
59 QLayout * createTilesCounter();
60 QWidget * createOkCancelButtonBox();
62 bool hasRoute()
const;
63 bool hasTextureLayer()
const;
65 QRadioButton * m_visibleRegionMethodButton;
66 QRadioButton * m_specifiedRegionMethodButton;
69 QRadioButton *m_routeDownloadMethodButton;
70 QLabel* m_routeOffsetLabel;
71 QDoubleSpinBox *m_routeOffsetSpinBox;
72 QLabel * m_tilesCountLabel;
73 QLabel * m_tileSizeInfo;
74 QPushButton * m_okButton;
75 QPushButton * m_applyButton;
77 int m_visibleTileLevel;
86 DownloadRegionDialog::Private::Private(
MarbleWidget *
const widget,
89 m_visibleRegionMethodButton( 0 ),
90 m_specifiedRegionMethodButton( 0 ),
91 m_latLonBoxWidget( new LatLonBoxWidget ),
92 m_tileLevelRangeWidget( new TileLevelRangeWidget ),
93 m_routeDownloadMethodButton( 0 ),
94 m_routeOffsetLabel( 0 ),
95 m_routeOffsetSpinBox( 0 ),
96 m_tilesCountLabel( 0 ),
100 m_textureLayer( widget->textureLayer() ),
101 m_visibleTileLevel( m_textureLayer->tileZoomLevel() ),
102 m_model( widget->model() ),
104 m_selectionMethod( VisibleRegionMethod ),
106 m_routingModel( widget->model()->routingManager()->routingModel() )
108 m_latLonBoxWidget->setEnabled(
false );
109 m_latLonBoxWidget->setLatLonBox( m_visibleRegion );
110 m_tileLevelRangeWidget->setDefaultLevel( m_visibleTileLevel );
111 m_downloadRegion.setMarbleModel( widget->
model() );
114 QWidget * DownloadRegionDialog::Private::createSelectionMethodBox()
116 m_visibleRegionMethodButton =
new QRadioButton( tr(
"Visible region" ) );
117 m_specifiedRegionMethodButton =
new QRadioButton( tr(
"Specify region" ) );
119 m_routeDownloadMethodButton =
new QRadioButton( tr(
"Download Route" ) );
120 m_routeDownloadMethodButton->setToolTip( tr(
"Enabled when a route exists" ) );
121 m_routeDownloadMethodButton->setEnabled( hasRoute() );
122 m_routeDownloadMethodButton->setChecked( hasRoute() );
123 m_routeOffsetSpinBox =
new QDoubleSpinBox();
124 m_routeOffsetSpinBox->setEnabled( hasRoute() );
126 int defaultOffset = 500;
127 m_routeOffsetSpinBox->setValue( defaultOffset );
128 m_routeOffsetSpinBox->setSingleStep( 100 );
129 m_routeOffsetSpinBox->setSuffix(
" m" );
130 m_routeOffsetSpinBox->setDecimals( 0 );
131 m_routeOffsetSpinBox->setAlignment( Qt::AlignRight );
133 m_routeOffsetLabel =
new QLabel( tr(
"Offset from route:" ) );
134 m_routeOffsetLabel->setAlignment( Qt::AlignHCenter );
136 connect( m_visibleRegionMethodButton, SIGNAL(toggled(
bool)),
137 m_dialog, SLOT(toggleSelectionMethod()) );
138 connect( m_specifiedRegionMethodButton, SIGNAL(toggled(
bool)),
139 m_dialog, SLOT(toggleSelectionMethod()));
140 connect( m_routeDownloadMethodButton, SIGNAL(toggled(
bool)),
141 m_dialog, SLOT(toggleSelectionMethod()) );
142 connect( m_routingModel, SIGNAL(modelReset()), m_dialog, SLOT(updateRouteDialog()) );
143 connect( m_routingModel, SIGNAL(rowsInserted(QModelIndex,
int,
int)),
144 m_dialog, SLOT(updateRouteDialog()) );
145 connect( m_routingModel, SIGNAL(rowsRemoved(QModelIndex,
int,
int)),
146 m_dialog, SLOT(updateRouteDialog()) );
148 QHBoxLayout *routeOffsetLayout =
new QHBoxLayout;
149 routeOffsetLayout->addWidget( m_routeOffsetLabel );
150 routeOffsetLayout->insertSpacing( 0, 25 );
151 routeOffsetLayout->addWidget( m_routeOffsetSpinBox );
153 QVBoxLayout *
const routeLayout =
new QVBoxLayout;
154 routeLayout->addWidget( m_routeDownloadMethodButton );
155 routeLayout->addLayout( routeOffsetLayout );
157 QVBoxLayout *
const layout =
new QVBoxLayout;
158 layout->addWidget( m_visibleRegionMethodButton );
159 layout->addLayout( routeLayout );
160 layout->addWidget( m_specifiedRegionMethodButton );
161 layout->addWidget( m_latLonBoxWidget );
163 bool const smallScreen = MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen;
164 m_specifiedRegionMethodButton->setVisible( !smallScreen );
165 m_latLonBoxWidget->setVisible( !smallScreen );
169 selectionMethodWidget->setLayout( layout );
170 return selectionMethodWidget;
172 QGroupBox *
const selectionMethodBox =
new QGroupBox( tr(
"Selection Method" ) );
173 selectionMethodBox->setLayout( layout );
174 return selectionMethodBox;
178 QLayout * DownloadRegionDialog::Private::createTilesCounter()
180 QLabel *
const description =
new QLabel( tr(
"Number of tiles to download:" ) );
181 m_tilesCountLabel =
new QLabel;
182 m_tileSizeInfo =
new QLabel;
184 QHBoxLayout *
const tilesCountLayout =
new QHBoxLayout;
185 tilesCountLayout->addWidget( description );
186 tilesCountLayout->addWidget( m_tilesCountLabel );
188 QVBoxLayout *
const layout =
new QVBoxLayout;
189 layout->addLayout( tilesCountLayout );
190 layout->addWidget( m_tileSizeInfo );
194 QWidget * DownloadRegionDialog::Private::createOkCancelButtonBox()
196 QDialogButtonBox *
const buttonBox =
new QDialogButtonBox;
197 m_okButton = buttonBox->addButton( QDialogButtonBox::Ok );
198 m_applyButton = buttonBox->addButton( QDialogButtonBox::Apply );
199 if ( MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen ) {
200 buttonBox->removeButton( m_applyButton );
201 m_applyButton->setVisible(
false );
203 buttonBox->addButton( QDialogButtonBox::Cancel );
204 connect( buttonBox, SIGNAL(accepted()), m_dialog, SLOT(accept()) );
205 connect( buttonBox, SIGNAL(rejected()), m_dialog, SLOT(reject()) );
206 connect( m_applyButton, SIGNAL(clicked()), m_dialog, SIGNAL(applied()) );
210 bool DownloadRegionDialog::Private::hasRoute()
const
212 return !m_routingModel->route().path().isEmpty();
215 bool DownloadRegionDialog::Private::hasTextureLayer()
const
217 return m_model->mapTheme()->map()->hasTextureLayers();
221 Qt::WindowFlags
const f )
223 d( new Private( widget, this ))
225 setWindowTitle( tr(
"Download Region" ));
226 QVBoxLayout *
const layout =
new QVBoxLayout;
227 layout->addWidget( d->createSelectionMethodBox() );
228 layout->addWidget( d->m_tileLevelRangeWidget );
229 layout->addLayout( d->createTilesCounter() );
233 widget->setLayout( layout );
234 QScrollArea* scrollArea =
new QScrollArea(
this );
235 scrollArea->setFrameShape( QFrame::NoFrame );
236 scrollArea->setWidget( widget );
237 QVBoxLayout *
const mainLayout =
new QVBoxLayout;
238 mainLayout->addWidget( scrollArea );
239 mainLayout->addWidget( d->createOkCancelButtonBox() );
240 setLayout( mainLayout );
242 layout->addWidget( d->createOkCancelButtonBox() );
246 connect( d->m_latLonBoxWidget, SIGNAL(valueChanged()), SLOT(updateTilesCount()) );
247 connect( d->m_tileLevelRangeWidget, SIGNAL(topLevelChanged(
int)),
248 SLOT(updateTilesCount()) );
249 connect( d->m_tileLevelRangeWidget, SIGNAL(bottomLevelChanged(
int)),
250 SLOT(updateTilesCount()) );
251 connect( d->m_routeOffsetSpinBox, SIGNAL(valueChanged(
double)), SLOT(updateTilesCount()) );
252 connect( d->m_routeOffsetSpinBox, SIGNAL(valueChanged(
double)), SLOT(setOffsetUnit()) );
253 connect( d->m_model, SIGNAL(themeChanged(QString)), SLOT(updateTilesCount()) );
262 int const maximumTileLevel )
264 d->m_tileLevelRangeWidget->setAllowedLevelRange( minimumTileLevel, maximumTileLevel );
269 d->m_visibleTileLevel = tileLevel;
270 d->m_tileLevelRangeWidget->setDefaultLevel( tileLevel );
271 d->m_downloadRegion.setVisibleTileLevel( tileLevel );
279 d->m_visibleRegionMethodButton->blockSignals(
true );
280 d->m_specifiedRegionMethodButton->blockSignals(
true );
281 d->m_routeDownloadMethodButton->blockSignals(
true );
283 d->m_selectionMethod = selectionMethod;
284 switch ( selectionMethod ) {
286 d->m_visibleRegionMethodButton->setChecked(
true );
287 d->m_routeOffsetLabel->setEnabled(
false );
288 d->m_routeOffsetSpinBox->setEnabled(
false );
289 d->m_latLonBoxWidget->setEnabled(
false );
293 d->m_specifiedRegionMethodButton->setChecked(
true );
294 d->m_routeOffsetLabel->setEnabled(
false );
295 d->m_routeOffsetSpinBox->setEnabled(
false );
296 d->m_latLonBoxWidget->setEnabled(
true );
299 d->m_routeDownloadMethodButton->setChecked(
true );
300 d->m_routeOffsetLabel->setEnabled(
true );
301 d->m_routeOffsetSpinBox->setEnabled(
true );
302 d->m_latLonBoxWidget->setEnabled(
false );
306 d->m_visibleRegionMethodButton->blockSignals(
false );
307 d->m_specifiedRegionMethodButton->blockSignals(
false );
308 d->m_routeDownloadMethodButton->blockSignals(
false );
313 if ( !d->hasTextureLayer() ) {
314 return QVector<TileCoordsPyramid>();
317 d->m_downloadRegion.setTileLevelRange( d->m_tileLevelRangeWidget->topLevel(),
318 d->m_tileLevelRangeWidget->bottomLevel() );
319 d->m_downloadRegion.setVisibleTileLevel( d->m_visibleTileLevel );
322 switch ( d->m_selectionMethod ) {
324 downloadRegion = d->m_visibleRegion;
330 qreal offset = d->m_routeOffsetSpinBox->value();
331 if( d->m_routeOffsetSpinBox->suffix() ==
" km") {
334 return d->m_downloadRegion.routeRegion( d->m_textureLayer, offset );
338 return d->m_downloadRegion.region( d->m_textureLayer, downloadRegion );
343 d->m_latLonBoxWidget->setLatLonBox( region );
348 d->m_visibleRegion =
region;
360 mDebug() <<
"DownloadRegionDialog::updateTextureLayer";
368 disconnect( d->m_widget, SIGNAL(themeChanged(QString)),
379 connect( d->m_widget, SIGNAL(themeChanged(QString)),
386 void DownloadRegionDialog::toggleSelectionMethod()
389 switch ( d->m_selectionMethod ) {
391 if( d->m_specifiedRegionMethodButton->isChecked() ) {
394 else if( d->m_routeDownloadMethodButton->isChecked() ) {
400 if( d->m_visibleRegionMethodButton->isChecked() ) {
403 else if ( d->m_routeDownloadMethodButton->isChecked() ) {
408 if( d->m_specifiedRegionMethodButton->isChecked() ) {
411 else if ( d->m_visibleRegionMethodButton->isChecked() ) {
419 void DownloadRegionDialog::updateTilesCount()
421 if ( !isVisible() || !d->hasTextureLayer() ) {
425 qint64 tilesCount = 0;
426 QString themeId( d->m_model->mapThemeId() );
427 QVector<TileCoordsPyramid>
const pyramid =
region();
428 Q_ASSERT( !pyramid.isEmpty() );
429 if( pyramid.size() == 1 ) {
430 tilesCount = pyramid[0].tilesCount();
433 for(
int level = pyramid[0].bottomLevel(); level>= pyramid[0].topLevel(); --level ) {
434 QSet<TileId> tileIdSet;
435 for(
int i = 0; i < pyramid.size(); ++i ) {
436 QRect
const coords = pyramid[i].coords( level );
438 coords.getCoords( &x1, &y1, &x2, &y2 );
439 for (
int x = x1; x <= x2; ++x ) {
440 for (
int y = y1; y <= y2; ++y ) {
441 TileId
const tileId( 0, level, x, y );
442 tileIdSet.insert( tileId );
446 tilesCount += tileIdSet.count();
451 d->m_tileSizeInfo->setToolTip( QString() );
452 d->m_tileSizeInfo->setText( tr(
"There is a limit of %n tiles to download.",
"",
454 }
else if ( themeId ==
"earth/openstreetmap/openstreetmap.dgml" ) {
457 d->m_tileSizeInfo->setToolTip( tr(
"Approximate size of the tiles to be downloaded" ) );
459 if( tileDownloadSize > 1024 ) {
460 tileDownloadSize = tileDownloadSize / 1024;
461 d->m_tileSizeInfo->setText( tr(
"Estimated download size: %1 MB" ).arg( ceil( tileDownloadSize ) ) );
464 d->m_tileSizeInfo->setText( tr(
"Estimated download size: %1 kB" ).arg( tileDownloadSize ) );
469 d->m_tileSizeInfo->setToolTip( QString() );
470 d->m_tileSizeInfo->clear();
473 d->m_tilesCountLabel->setText( QString::number( tilesCount ) );
474 bool const tilesCountWithinLimits = tilesCount > 0 && tilesCount <=
maxTilesCount;
475 d->m_okButton->setEnabled( tilesCountWithinLimits );
476 d->m_applyButton->setEnabled( tilesCountWithinLimits );
479 void DownloadRegionDialog::updateRouteDialog()
481 d->m_routeDownloadMethodButton->setEnabled( d->hasRoute() );
482 d->m_routeDownloadMethodButton->setChecked( d->hasRoute() );
483 if( !d->hasRoute() ) {
488 void DownloadRegionDialog::setOffsetUnit()
490 qreal offset = d->m_routeOffsetSpinBox->value();
492 if( offset >= 1100 ) {
493 d->m_routeOffsetSpinBox->setSuffix(
" km" );
495 d->m_routeOffsetSpinBox->setDecimals( 1 );
496 d->m_routeOffsetSpinBox->setValue( offset * METER2KM );
497 d->m_routeOffsetSpinBox->setSingleStep( 0.1 );
499 else if( offset <= 1 && d->m_routeOffsetSpinBox->suffix() ==
" km" ) {
500 d->m_routeOffsetSpinBox->setSuffix(
" m" );
502 d->m_routeOffsetSpinBox->setDecimals( 0 );
503 d->m_routeOffsetSpinBox->setValue( offset *
KM2METER );
504 d->m_routeOffsetSpinBox->setSingleStep( 100 );
510 #include "DownloadRegionDialog.moc"
void setVisibleTileLevel(int const tileLevel)
virtual void hideEvent(QHideEvent *event)
void hidden()
This signal is emitted when the dialog receives a QHideEvent.
This file contains the headers for MarbleModel.
int const minimumRouteOffset
void setSpecifiedLatLonAltBox(GeoDataLatLonAltBox const &)
void setVisibleLatLonAltBox(GeoDataLatLonAltBox const &)
QVector< TileCoordsPyramid > region() const
void shown()
This signal is emitted when the dialog receives a QShowEvent.
void updateTextureLayer()
void setAllowedTileLevelRange(int const minimumTileLevel, int const maximumTileLevel)
virtual void showEvent(QShowEvent *event)
static MarbleGlobal * getInstance()
int const maximumRouteOffset
The data model (not based on QAbstractModel) for a MarbleWidget.
Profiles profiles() const
QDebug mDebug()
a function to replace qDebug() in Marble library code
A class that defines a 3D bounding box for geographic data.
void setSelectionMethod(SelectionMethod const )