|
16 | 16 |
|
17 | 17 | #include "qgslogger.h"
|
18 | 18 |
|
| 19 | +#include "qgsdataitemproviderregistry.h" |
19 | 20 | #include "qgsdatasourceuri.h"
|
20 | 21 | #include "qgswmscapabilities.h"
|
21 | 22 | #include "qgswmsconnection.h"
|
22 | 23 | #include "qgswmssourceselect.h"
|
23 | 24 | #include "qgsnewhttpconnection.h"
|
24 | 25 | #include "qgstilescalewidget.h"
|
| 26 | +#include "qgsxyzconnection.h" |
| 27 | + |
| 28 | +#include <QInputDialog> |
25 | 29 |
|
26 | 30 | // ---------------------------------------------------------------------------
|
27 | 31 | QgsWMSConnectionItem::QgsWMSConnectionItem( QgsDataItem* parent, QString name, QString path, QString uri )
|
@@ -416,6 +420,10 @@ void QgsWMSRootItem::newConnection()
|
416 | 420 | QGISEXTERN void registerGui( QMainWindow *mainWindow )
|
417 | 421 | {
|
418 | 422 | QgsTileScaleWidget::showTileScale( mainWindow );
|
| 423 | + |
| 424 | + // with dataItem(...) at provider level we can only have one root item, |
| 425 | + // so we have a data item provider for XYZ tile layers |
| 426 | + QgsDataItemProviderRegistry::instance()->addProvider( new QgsXyzTileDataItemProvider ); |
419 | 427 | }
|
420 | 428 |
|
421 | 429 | QGISEXTERN QgsWMSSourceSelect * selectWidget( QWidget * parent, Qt::WindowFlags fl )
|
@@ -450,3 +458,81 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
|
450 | 458 | return nullptr;
|
451 | 459 | }
|
452 | 460 |
|
| 461 | + |
| 462 | +// --------------------------------------------------------------------------- |
| 463 | + |
| 464 | + |
| 465 | +QgsXyzTileRootItem::QgsXyzTileRootItem( QgsDataItem *parent, QString name, QString path ) |
| 466 | + : QgsDataCollectionItem( parent, name, path ) |
| 467 | +{ |
| 468 | + mCapabilities |= Fast; |
| 469 | + mIconName = "mIconWms.svg"; |
| 470 | + populate(); |
| 471 | +} |
| 472 | + |
| 473 | +QVector<QgsDataItem *> QgsXyzTileRootItem::createChildren() |
| 474 | +{ |
| 475 | + QVector<QgsDataItem*> connections; |
| 476 | + Q_FOREACH ( const QString& connName, QgsXyzConnectionUtils::connectionList() ) |
| 477 | + { |
| 478 | + QgsXyzConnection connection( QgsXyzConnectionUtils::connection( connName ) ); |
| 479 | + QgsDataItem * conn = new QgsXyzLayerItem( this, connName, mPath + '/' + connName, connection.encodedUri() ); |
| 480 | + connections.append( conn ); |
| 481 | + } |
| 482 | + return connections; |
| 483 | +} |
| 484 | + |
| 485 | +QList<QAction *> QgsXyzTileRootItem::actions() |
| 486 | +{ |
| 487 | + QAction* actionNew = new QAction( tr( "New Connection..." ), this ); |
| 488 | + connect( actionNew, SIGNAL( triggered() ), this, SLOT( newConnection() ) ); |
| 489 | + return QList<QAction*>() << actionNew; |
| 490 | +} |
| 491 | + |
| 492 | +void QgsXyzTileRootItem::newConnection() |
| 493 | +{ |
| 494 | + QString url = QInputDialog::getText( nullptr, tr( "New XYZ tile layer" ), |
| 495 | + tr( "Please enter XYZ tile layer URL. {x}, {y}, {z} will be replaced by actual tile coordinates." ) ); |
| 496 | + if ( url.isEmpty() ) |
| 497 | + return; |
| 498 | + |
| 499 | + QString name = QInputDialog::getText( nullptr, tr( "New XYZ tile layer" ), |
| 500 | + tr( "Please enter name of the tile layer:" ) ); |
| 501 | + if ( name.isEmpty() ) |
| 502 | + return; |
| 503 | + |
| 504 | + QgsXyzConnection conn; |
| 505 | + conn.name = name; |
| 506 | + conn.url = url; |
| 507 | + QgsXyzConnectionUtils::addConnection( conn ); |
| 508 | + |
| 509 | + refresh(); |
| 510 | +} |
| 511 | + |
| 512 | + |
| 513 | +// --------------------------------------------------------------------------- |
| 514 | + |
| 515 | + |
| 516 | +QgsXyzLayerItem::QgsXyzLayerItem( QgsDataItem *parent, QString name, QString path, const QString &encodedUri ) |
| 517 | + : QgsLayerItem( parent, name, path, encodedUri, QgsLayerItem::Raster, "wms" ) |
| 518 | +{ |
| 519 | + setState( Populated ); |
| 520 | +} |
| 521 | + |
| 522 | +QList<QAction *> QgsXyzLayerItem::actions() |
| 523 | +{ |
| 524 | + QList<QAction*> lst = QgsLayerItem::actions(); |
| 525 | + |
| 526 | + QAction* actionDelete = new QAction( tr( "Delete" ), this ); |
| 527 | + connect( actionDelete, SIGNAL( triggered() ), this, SLOT( deleteConnection() ) ); |
| 528 | + lst << actionDelete; |
| 529 | + |
| 530 | + return lst; |
| 531 | +} |
| 532 | + |
| 533 | +void QgsXyzLayerItem::deleteConnection() |
| 534 | +{ |
| 535 | + QgsXyzConnectionUtils::deleteConnection( mName ); |
| 536 | + |
| 537 | + mParent->refresh(); |
| 538 | +} |
0 commit comments