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();
60 QWidget * createOkCancelButtonBox();
62 bool hasRoute()
const;
63 bool hasTextureLayer()
const;
70 QLabel* m_routeOffsetLabel;
72 QLabel * m_tilesCountLabel;
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() );
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()) );
149 routeOffsetLayout->
addWidget( m_routeOffsetLabel );
151 routeOffsetLayout->
addWidget( m_routeOffsetSpinBox );
154 routeLayout->
addWidget( m_routeDownloadMethodButton );
155 routeLayout->
addLayout( routeOffsetLayout );
158 layout->
addWidget( m_visibleRegionMethodButton );
160 layout->
addWidget( m_specifiedRegionMethodButton );
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;
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;
185 tilesCountLayout->
addWidget( description );
186 tilesCountLayout->
addWidget( m_tilesCountLabel );
194 QWidget * DownloadRegionDialog::Private::createOkCancelButtonBox()
197 m_okButton = buttonBox->
addButton( QDialogButtonBox::Ok );
198 m_applyButton = buttonBox->
addButton( QDialogButtonBox::Apply );
199 if ( MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen ) {
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();
223 d( new Private( widget, this ))
227 layout->
addWidget( d->createSelectionMethodBox() );
228 layout->
addWidget( d->m_tileLevelRangeWidget );
229 layout->
addLayout( d->createTilesCounter() );
239 mainLayout->
addWidget( d->createOkCancelButtonBox() );
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() ) {
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 const GeoDataLineString waypoints = d->m_model->routingManager()->routingModel()->route().path();
335 return d->m_downloadRegion.fromPath( d->m_textureLayer, offset, waypoints );
339 return d->m_downloadRegion.region( d->m_textureLayer, downloadRegion );
344 d->m_latLonBoxWidget->setLatLonBox( region );
349 d->m_visibleRegion =
region;
361 mDebug() <<
"DownloadRegionDialog::updateTextureLayer";
387 void DownloadRegionDialog::toggleSelectionMethod()
390 switch ( d->m_selectionMethod ) {
392 if( d->m_specifiedRegionMethodButton->isChecked() ) {
395 else if( d->m_routeDownloadMethodButton->isChecked() ) {
401 if( d->m_visibleRegionMethodButton->isChecked() ) {
404 else if ( d->m_routeDownloadMethodButton->isChecked() ) {
409 if( d->m_specifiedRegionMethodButton->isChecked() ) {
412 else if ( d->m_visibleRegionMethodButton->isChecked() ) {
420 void DownloadRegionDialog::updateTilesCount()
422 if ( !
isVisible() || !d->hasTextureLayer() ) {
426 qint64 tilesCount = 0;
427 QString themeId( d->m_model->mapThemeId() );
429 Q_ASSERT( !pyramid.isEmpty() );
430 if( pyramid.size() == 1 ) {
431 tilesCount = pyramid[0].tilesCount();
434 for(
int level = pyramid[0].bottomLevel(); level>= pyramid[0].topLevel(); --level ) {
436 for(
int i = 0; i < pyramid.size(); ++i ) {
440 for (
int x = x1;
x <= x2; ++
x ) {
441 for (
int y = y1;
y <= y2; ++
y ) {
442 TileId
const tileId( 0, level,
x,
y );
443 tileIdSet.
insert( tileId );
447 tilesCount += tileIdSet.
count();
452 d->m_tileSizeInfo->setToolTip(
QString() );
453 d->m_tileSizeInfo->setText(
tr(
"There is a limit of %n tiles to download.",
"",
455 }
else if ( themeId ==
"earth/openstreetmap/openstreetmap.dgml" ) {
458 d->m_tileSizeInfo->setToolTip(
tr(
"Approximate size of the tiles to be downloaded" ) );
460 if( tileDownloadSize > 1024 ) {
461 tileDownloadSize = tileDownloadSize / 1024;
462 d->m_tileSizeInfo->setText(
tr(
"Estimated download size: %1 MB" ).arg( ceil( tileDownloadSize ) ) );
465 d->m_tileSizeInfo->setText(
tr(
"Estimated download size: %1 kB" ).arg( tileDownloadSize ) );
470 d->m_tileSizeInfo->setToolTip(
QString() );
471 d->m_tileSizeInfo->clear();
475 bool const tilesCountWithinLimits = tilesCount > 0 && tilesCount <=
maxTilesCount;
476 d->m_okButton->setEnabled( tilesCountWithinLimits );
477 d->m_applyButton->setEnabled( tilesCountWithinLimits );
480 void DownloadRegionDialog::updateRouteDialog()
482 d->m_routeDownloadMethodButton->setEnabled( d->hasRoute() );
483 d->m_routeDownloadMethodButton->setChecked( d->hasRoute() );
484 if( !d->hasRoute() ) {
489 void DownloadRegionDialog::setOffsetUnit()
491 qreal offset = d->m_routeOffsetSpinBox->value();
493 if( offset >= 1100 ) {
494 d->m_routeOffsetSpinBox->setSuffix(
" km" );
496 d->m_routeOffsetSpinBox->setDecimals( 1 );
497 d->m_routeOffsetSpinBox->setValue( offset * METER2KM );
498 d->m_routeOffsetSpinBox->setSingleStep( 0.1 );
500 else if( offset <= 1 && d->m_routeOffsetSpinBox->suffix() ==
" km" ) {
501 d->m_routeOffsetSpinBox->setSuffix(
" m" );
503 d->m_routeOffsetSpinBox->setDecimals( 0 );
504 d->m_routeOffsetSpinBox->setValue( offset *
KM2METER );
505 d->m_routeOffsetSpinBox->setSingleStep( 100 );
511 #include "DownloadRegionDialog.moc"
void setVisibleTileLevel(int const tileLevel)
virtual void hideEvent(QHideEvent *event)
void insertSpacing(int index, int size)
void hidden()
This signal is emitted when the dialog receives a QHideEvent.
void setFrameShape(Shape)
This file contains the headers for MarbleModel.
int const minimumRouteOffset
void getCoords(int *x1, int *y1, int *x2, int *y2) const
void setSpecifiedLatLonAltBox(GeoDataLatLonAltBox const &)
const_iterator insert(const T &value)
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QString tr(const char *sourceText, const char *disambiguation, int n)
void setVisibleLatLonAltBox(GeoDataLatLonAltBox const &)
QVector< TileCoordsPyramid > region() const
QString number(int n, int base)
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)
A LineString that allows to store a contiguous set of line segments.
static MarbleGlobal * getInstance()
int const maximumRouteOffset
The data model (not based on QAbstractModel) for a MarbleWidget.
Profiles profiles() const
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QDebug mDebug()
a function to replace qDebug() in Marble library code
A class that defines a 3D bounding box for geographic data.
void coords(int *x1, int *y1, int *x2, int *y2) const
void addLayout(QLayout *layout, int stretch)
void setSelectionMethod(SelectionMethod const )