QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 : paul.blottiere@oslandia.com
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 "qgsvectorlayer.h"
29 #include <QString>
30 
31 class QgsProject;
32 
60 class CORE_EXPORT QgsAuxiliaryLayer : public QgsVectorLayer
61 {
62  Q_OBJECT
63 
64  public:
65 
74  QgsAuxiliaryLayer( const QString &pkField, const QString &filename, const QString &table, QgsVectorLayer *vlayer );
75 
79  QgsAuxiliaryLayer( const QgsAuxiliaryLayer &rhs ) = delete;
80 
82 
83 #ifdef SIP_RUN
84  SIP_PYOBJECT __repr__();
85  % MethodCode
86  QString str = QStringLiteral( "<QgsAuxiliaryLayer: '%1'>" ).arg( sipCpp->name() );
87  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
88  % End
89 #endif
90 
99 
106  QgsVectorLayer *toSpatialLayer() const;
107 
114  bool clear();
115 
119  QgsVectorLayerJoinInfo joinInfo() const;
120 
129  bool exists( const QgsPropertyDefinition &definition ) const;
130 
140  bool addAuxiliaryField( const QgsPropertyDefinition &definition );
141 
145  QgsFields auxiliaryFields() const;
146 
152  bool save();
153 
162  bool deleteAttribute( int attr ) override;
163 
170  bool isHiddenProperty( int index ) const;
171 
180  int indexOfPropertyDefinition( const QgsPropertyDefinition &definition ) const;
181 
190  int propertyFromIndex( int index ) const;
191 
197  QgsPropertyDefinition propertyDefinitionFromIndex( int index ) const;
198 
208  static int createProperty( QgsPalLayerSettings::Property property, QgsVectorLayer *vlayer );
209 
219  static int createProperty( QgsDiagramLayerSettings::Property property, QgsVectorLayer *vlayer );
220 
226  static QgsField createAuxiliaryField( const QgsPropertyDefinition &definition );
227 
233  static QgsField createAuxiliaryField( const QgsField &field );
234 
241  static QString nameFromProperty( const QgsPropertyDefinition &def, bool joined = false );
242 
248  static QgsPropertyDefinition propertyDefinitionFromField( const QgsField &field );
249 
250  private:
251  QgsVectorLayerJoinInfo mJoinInfo;
252  QString mFileName;
253  QString mTable;
254  QgsVectorLayer *mLayer = nullptr;
255 };
256 
257 
267 class CORE_EXPORT QgsAuxiliaryStorage
268 {
269  public:
270 
282  QgsAuxiliaryStorage( const QgsProject &project, bool copy = true );
283 
305  QgsAuxiliaryStorage( const QString &filename = QString(), bool copy = true );
306 
310  virtual ~QgsAuxiliaryStorage();
311 
317  bool isValid() const;
318 
322  QString fileName() const;
323 
328  QString currentFileName() const;
329 
336  QString errorString() const;
337 
343  bool saveAs( const QString &filename );
344 
352  bool saveAs( const QgsProject &project );
353 
359  bool save() const;
360 
371  QgsAuxiliaryLayer *createAuxiliaryLayer( const QgsField &field, QgsVectorLayer *layer ) const SIP_FACTORY;
372 
380  static bool deleteTable( const QgsDataSourceUri &uri );
381 
390  static bool duplicateTable( const QgsDataSourceUri &uri, const QString &newTable );
391 
395  static QString extension();
396 
404  static bool exists( const QgsProject &project );
405 
406  private:
407  spatialite_database_unique_ptr open( const QString &filename = QString() );
408  spatialite_database_unique_ptr open( const QgsProject &project );
409 
410  void initTmpFileName();
411 
412  static QString filenameForProject( const QgsProject &project );
413  static spatialite_database_unique_ptr createDB( const QString &filename );
414  static spatialite_database_unique_ptr openDB( const QString &filename );
415  static bool tableExists( const QString &table, sqlite3 *handler );
416  static bool createTable( const QString &type, const QString &table, sqlite3 *handler );
417 
418  static bool exec( const QString &sql, sqlite3 *handler );
419  static void debugMsg( const QString &sql, sqlite3 *handler );
420 
421  static QgsDataSourceUri parseOgrUri( const QgsDataSourceUri &uri );
422 
423  bool mValid = false;
424  QString mFileName; // original filename
425  QString mTmpFileName; // temporary filename used in copy mode
426  bool mCopy = false;
427  QString mErrorString;
428 };
429 
430 #endif
Class allowing to manage the auxiliary storage for a vector layer.
QgsAuxiliaryLayer & operator=(QgsAuxiliaryLayer const &rhs)=delete
QgsAuxiliaryLayer(const QString &pkField, const QString &filename, const QString &table, QgsVectorLayer *vlayer)
Constructor.
QgsAuxiliaryLayer(const QgsAuxiliaryLayer &rhs)=delete
Copy constructor deactivated.
Class providing some utility methods to manage auxiliary storage.
Class for storing the component parts of a RDBMS data source URI (e.g.
Property
Data definable properties.
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:51
Container of fields for a vector layer.
Definition: qgsfields.h:45
bool isValid
Definition: qgsmaplayer.h:93
Property
Data definable properties.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:99
Definition for a property.
Definition: qgsproperty.h:48
Defines left outer join from our vector layer to some other vector layer.
Represents a vector layer which manages a vector based data sets.
virtual bool deleteAttribute(int attr)
Deletes an attribute field (but does not commit it).
QgsVectorLayer * clone() const override
Returns a new instance equivalent to this one.
Unique pointer for spatialite databases, which automatically closes the database when the pointer goe...
#define SIP_FACTORY
Definition: qgis_sip.h:76
struct sqlite3 sqlite3
const QgsField & field
Definition: qgsfield.h:472