QGIS API Documentation  3.0.2-Girona (307d082)
qgsauxiliarystorage.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsauxiliarystorage.h - description
3  -------------------
4  begin : Aug 28, 2017
5  copyright : (C) 2017 by Paul Blottiere
6  email : [email protected]
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSAUXILIARYSTORAGE_H
19 #define QGSAUXILIARYSTORAGE_H
20 
21 #include "qgis_core.h"
22 #include "qgsdatasourceuri.h"
23 #include "qgspallabeling.h"
24 #include "qgsdiagramrenderer.h"
25 #include "qgsvectorlayerjoininfo.h"
26 #include "qgsproperty.h"
27 #include "qgsspatialiteutils.h"
28 #include <QString>
29 
30 class QgsProject;
31 
59 class CORE_EXPORT QgsAuxiliaryLayer : public QgsVectorLayer
60 {
61  Q_OBJECT
62 
63  public:
64 
73  QgsAuxiliaryLayer( const QString &pkField, const QString &filename, const QString &table, QgsVectorLayer *vlayer );
74 
78  QgsAuxiliaryLayer( const QgsAuxiliaryLayer &rhs ) = delete;
79 
80  QgsAuxiliaryLayer &operator=( QgsAuxiliaryLayer const &rhs ) = delete;
81 
90 
97  QgsVectorLayer *toSpatialLayer() const;
98 
105  bool clear();
106 
110  QgsVectorLayerJoinInfo joinInfo() const;
111 
120  bool exists( const QgsPropertyDefinition &definition ) const;
121 
131  bool addAuxiliaryField( const QgsPropertyDefinition &definition );
132 
136  QgsFields auxiliaryFields() const;
137 
143  bool save();
144 
153  bool deleteAttribute( int attr ) override;
154 
161  bool isHiddenProperty( int index ) const;
162 
171  int indexOfPropertyDefinition( const QgsPropertyDefinition &definition ) const;
172 
181  int propertyFromIndex( int index ) const;
182 
188  QgsPropertyDefinition propertyDefinitionFromIndex( int index ) const;
189 
199  static int createProperty( QgsPalLayerSettings::Property property, QgsVectorLayer *vlayer );
200 
210  static int createProperty( QgsDiagramLayerSettings::Property property, QgsVectorLayer *vlayer );
211 
217  static QgsField createAuxiliaryField( const QgsPropertyDefinition &definition );
218 
224  static QgsField createAuxiliaryField( const QgsField &field );
225 
232  static QString nameFromProperty( const QgsPropertyDefinition &def, bool joined = false );
233 
239  static QgsPropertyDefinition propertyDefinitionFromField( const QgsField &field );
240 
241  private:
242  QgsVectorLayerJoinInfo mJoinInfo;
243  QString mFileName;
244  QString mTable;
245  QgsVectorLayer *mLayer = nullptr;
246 };
247 
248 
258 class CORE_EXPORT QgsAuxiliaryStorage
259 {
260  public:
261 
273  QgsAuxiliaryStorage( const QgsProject &project, bool copy = true );
274 
296  QgsAuxiliaryStorage( const QString &filename = QString(), bool copy = true );
297 
301  virtual ~QgsAuxiliaryStorage();
302 
308  bool isValid() const;
309 
313  QString fileName() const;
314 
319  QString currentFileName() const;
320 
326  bool saveAs( const QString &filename ) const;
327 
335  bool saveAs( const QgsProject &project ) const;
336 
342  bool save() const;
343 
354  QgsAuxiliaryLayer *createAuxiliaryLayer( const QgsField &field, QgsVectorLayer *layer ) const SIP_FACTORY;
355 
363  static bool deleteTable( const QgsDataSourceUri &uri );
364 
373  static bool duplicateTable( const QgsDataSourceUri &uri, const QString &newTable );
374 
378  static QString extension();
379 
380  private:
381  spatialite_database_unique_ptr open( const QString &filename = QString() );
382  spatialite_database_unique_ptr open( const QgsProject &project );
383 
384  void initTmpFileName();
385 
386  static QString filenameForProject( const QgsProject &project );
387  static spatialite_database_unique_ptr createDB( const QString &filename );
388  static spatialite_database_unique_ptr openDB( const QString &filename );
389  static bool tableExists( const QString &table, sqlite3 *handler );
390  static bool createTable( const QString &type, const QString &table, sqlite3 *handler );
391 
392  static bool exec( const QString &sql, sqlite3 *handler );
393  static void debugMsg( const QString &sql, sqlite3 *handler );
394 
395  static QgsDataSourceUri parseOgrUri( const QgsDataSourceUri &uri );
396 
397  bool mValid = false;
398  QString mFileName; // original filename
399  QString mTmpFileName; // temporary filename used in copy mode
400  bool mCopy = false;
401 };
402 
403 #endif
Property
Data definable properties.
Class allowing to manage the auxiliary storage for a vector layer.
Class providing some utility methods to manage auxiliary storage.
Container of fields for a vector layer.
Definition: qgsfields.h:42
Property
Data definable properties.
Unique pointer for spatialite databases, which automatically closes the database when the pointer goe...
Defines left outer join from our vector layer to some other vector layer.
virtual bool deleteAttribute(int attr)
Deletes an attribute field (but does not commit it).
Reads and writes project states.
Definition: qgsproject.h:82
#define SIP_FACTORY
Definition: qgis_sip.h:69
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:48
Definition for a property.
Definition: qgsproperty.h:46
struct sqlite3 sqlite3
QgsVectorLayer & operator=(QgsVectorLayer const &rhs)=delete
QgsVectorLayer cannot be copied.
Class for storing the component parts of a PostgreSQL/RDBMS datasource URI.
Represents a vector layer which manages a vector based data sets.
QgsVectorLayer * clone() const override
Returns a new instance equivalent to this one.