QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsvectortiledataitems.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectortiledataitems.cpp
3  ---------------------
4  begin : March 2020
5  copyright : (C) 2020 by Martin Dobias
6  email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #include "qgsvectortiledataitems.h"
16 
17 #include "qgssettings.h"
19 
21 
22 QgsVectorTileRootItem::QgsVectorTileRootItem( QgsDataItem *parent, QString name, QString path )
23  : QgsConnectionsRootItem( parent, name, path, QStringLiteral( "vectortile" ) )
24 {
25  mCapabilities |= Fast;
26  mIconName = QStringLiteral( "mIconVectorTileLayer.svg" );
27  populate();
28 }
29 
30 QVector<QgsDataItem *> QgsVectorTileRootItem::createChildren()
31 {
32  QVector<QgsDataItem *> connections;
33  const auto connectionList = QgsVectorTileProviderConnection::connectionList();
34  for ( const QString &connName : connectionList )
35  {
36  QString uri = QgsVectorTileProviderConnection::encodedLayerUri( QgsVectorTileProviderConnection::connection( connName ) );
37  QgsDataItem *conn = new QgsVectorTileLayerItem( this, connName, mPath + '/' + connName, uri );
38  connections.append( conn );
39  }
40  return connections;
41 }
42 
43 
44 // ---------------------------------------------------------------------------
45 
46 
47 QgsVectorTileLayerItem::QgsVectorTileLayerItem( QgsDataItem *parent, QString name, QString path, const QString &encodedUri )
48  : QgsLayerItem( parent, name, path, encodedUri, QgsLayerItem::VectorTile, QString() )
49 {
50  setState( Populated );
51  mIconName = QStringLiteral( "mIconVectorTileLayer.svg" );
52 }
53 
54 
55 // ---------------------------------------------------------------------------
56 
57 QString QgsVectorTileDataItemProvider::name()
58 {
59  return QStringLiteral( "Vector Tiles" );
60 }
61 
62 QString QgsVectorTileDataItemProvider::dataProviderKey() const
63 {
64  return QStringLiteral( "vectortile" );
65 }
66 
67 int QgsVectorTileDataItemProvider::capabilities() const
68 {
69  return QgsDataProvider::Net;
70 }
71 
72 QgsDataItem *QgsVectorTileDataItemProvider::createDataItem( const QString &path, QgsDataItem *parentItem )
73 {
74  if ( path.isEmpty() )
75  return new QgsVectorTileRootItem( parentItem, QStringLiteral( "Vector Tiles" ), QStringLiteral( "vectortile:" ) );
76  return nullptr;
77 }
78 
qgsvectortileconnection.h
qgsvectortiledataitems.h
qgssettings.h
QgsLayerItem
Item that represents a layer that can be opened with one of the providers.
Definition: qgsdataitem.h:507
QgsConnectionsRootItem
A Collection that represents a root group of connections from a single data provider.
Definition: qgsdataitem.h:717
QgsDataItem
Base class for all items in the model.
Definition: qgsdataitem.h:51
QgsDataProvider::Net
@ Net
Definition: qgsdataprovider.h:79