1 /***************************************************************************
2     qgsvectortileconnection.h
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 
16 #ifndef QGSVECTORTILECONNECTION_H
17 #define QGSVECTORTILECONNECTION_H
18 
19 #include "qgis_core.h"
20 
21 ///@cond PRIVATE
22 #define SIP_NO_FILE
23 
24 #include <QStringList>
25 
26 #include "qgsabstractproviderconnection.h"
27 
28 class CORE_EXPORT QgsVectorTileProviderConnection : public QgsAbstractProviderConnection
29 {
30 
31   public:
32     QgsVectorTileProviderConnection( const QString &name );
33     QgsVectorTileProviderConnection( const QString &uri, const QVariantMap &configuration );
34 
35     virtual void store( const QString &name ) const override;
36     virtual void remove( const QString &name ) const override;
37 
38     /**
39      * Vector tile service type.
40      *
41      * \since QGIS 3.16
42      */
43     enum ServiceType
44     {
45       Generic, //!< Generic (XYZ) connection
46       ArcgisVectorTileService, //!< ArcGIS VectorTileServer connection
47     };
48 
49     //! Represents decoded data of a connection
50     struct Data
51     {
52       QString url;
53       int zMin = -1;
54       int zMax = -1;
55 
56       ServiceType serviceType = Generic;
57 
58       //! Authentication configuration id
59       QString authCfg;
60       //! HTTP Basic username
61       QString username;
62       //! HTTP Basic password
63       QString password;
64       //! Referer
65       QString referer;
66 
67       //! Optional style URL (will override any default styles)
68       QString styleUrl;
69 
70     };
71 
72     //! Returns connection data encoded as a string
73     static QString encodedUri( const Data &conn );
74     //! Decodes connection string to a data structure
75     static Data decodedUri( const QString &uri );
76 
77     //! Returns connection data encoded as a string containing URI for QgsVectorTileLayer
78     static QString encodedLayerUri( const Data &conn );
79 
80     //! Returns list of existing connections, unless the hidden ones
81     static QStringList connectionList();
82     //! Returns connection details
83     static Data connection( const QString &name );
84     //! Removes a connection from the list
85     static void deleteConnection( const QString &name );
86     //! Adds a new connection to the list
87     static void addConnection( const QString &name, Data conn );
88     //! Returns last used connection
89     static QString selectedConnection();
90     //! Saves name of the last used connection
91     static void setSelectedConnection( const QString &connName );
92 };
93 
94 ///@endcond
95 
96 #endif // QGSVECTORTILECONNECTION_H
97