QGIS API Documentation  3.21.0-Master (2d5a580dfc)
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 "qgsvectorlayer.h"
29 #include "qgscallout.h"
30 #include <QString>
31 
32 class QgsProject;
33 
61 class CORE_EXPORT QgsAuxiliaryLayer : public QgsVectorLayer
62 {
63  Q_OBJECT
64 
65  public:
66 
75  QgsAuxiliaryLayer( const QString &pkField, const QString &filename, const QString &table, QgsVectorLayer *vlayer );
76 
80  QgsAuxiliaryLayer( const QgsAuxiliaryLayer &rhs ) = delete;
81 
83 
84 #ifdef SIP_RUN
85  SIP_PYOBJECT __repr__();
86  % MethodCode
87  QString str = QStringLiteral( "<QgsAuxiliaryLayer: '%1'>" ).arg( sipCpp->name() );
88  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
89  % End
90 #endif
91 
92 #ifdef __clang__
93 #pragma clang diagnostic push
94 #pragma clang diagnostic ignored "-Woverloaded-virtual"
95 #endif
96 
105 #ifdef __clang__
106 #pragma clang diagnostic pop
107 #endif
108 
115  QgsVectorLayer *toSpatialLayer() const;
116 
123  bool clear();
124 
128  QgsVectorLayerJoinInfo joinInfo() const;
129 
138  bool exists( const QgsPropertyDefinition &definition ) const;
139 
149  bool addAuxiliaryField( const QgsPropertyDefinition &definition );
150 
154  QgsFields auxiliaryFields() const;
155 
161  bool save();
162 
171  bool deleteAttribute( int attr ) override;
172 
179  bool isHiddenProperty( int index ) const;
180 
189  int indexOfPropertyDefinition( const QgsPropertyDefinition &definition ) const;
190 
199  int propertyFromIndex( int index ) const;
200 
206  QgsPropertyDefinition propertyDefinitionFromIndex( int index ) const;
207 
217  static int createProperty( QgsPalLayerSettings::Property property, QgsVectorLayer *vlayer );
218 
228  static int createProperty( QgsDiagramLayerSettings::Property property, QgsVectorLayer *vlayer );
229 
240  static int createProperty( QgsCallout::Property property, QgsVectorLayer *vlayer );
241 
247  static QgsField createAuxiliaryField( const QgsPropertyDefinition &definition );
248 
254  static QgsField createAuxiliaryField( const QgsField &field );
255 
262  static QString nameFromProperty( const QgsPropertyDefinition &def, bool joined = false );
263 
269  static QgsPropertyDefinition propertyDefinitionFromField( const QgsField &field );
270 
271  private:
272  QgsVectorLayerJoinInfo mJoinInfo;
273  QString mFileName;
274  QString mTable;
275  QgsVectorLayer *mLayer = nullptr;
276 };
277 
278 
288 class CORE_EXPORT QgsAuxiliaryStorage
289 {
290  public:
291 
303  QgsAuxiliaryStorage( const QgsProject &project, bool copy = true );
304 
326  QgsAuxiliaryStorage( const QString &filename = QString(), bool copy = true );
327 
331  virtual ~QgsAuxiliaryStorage();
332 
338  bool isValid() const;
339 
343  QString fileName() const;
344 
349  QString currentFileName() const;
350 
357  QString errorString() const;
358 
364  bool saveAs( const QString &filename );
365 
373  bool saveAs( const QgsProject &project );
374 
380  bool save() const;
381 
392  QgsAuxiliaryLayer *createAuxiliaryLayer( const QgsField &field, QgsVectorLayer *layer ) const SIP_FACTORY;
393 
401  static bool deleteTable( const QgsDataSourceUri &uri );
402 
411  static bool duplicateTable( const QgsDataSourceUri &uri, const QString &newTable );
412 
416  static QString extension();
417 
425  static bool exists( const QgsProject &project );
426 
427  private:
428  spatialite_database_unique_ptr open( const QString &filename = QString() );
429  spatialite_database_unique_ptr open( const QgsProject &project );
430 
431  void initTmpFileName();
432 
433  static QString filenameForProject( const QgsProject &project );
434  static spatialite_database_unique_ptr createDB( const QString &filename );
435  static spatialite_database_unique_ptr openDB( const QString &filename );
436  static bool tableExists( const QString &table, sqlite3 *handler );
437  static bool createTable( const QString &type, const QString &table, sqlite3 *handler, QString &errorMsg );
438 
439  static bool exec( const QString &sql, sqlite3 *handler );
440  static QString debugMsg( const QString &sql, sqlite3 *handler );
441 
442  static QgsDataSourceUri parseOgrUri( const QgsDataSourceUri &uri );
443 
444  bool mValid = false;
445  QString mFileName; // original filename
446  QString mTmpFileName; // temporary filename used in copy mode
447  bool mCopy = false;
448  mutable QString mErrorString;
449 };
450 
451 #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.
Property
Data definable properties.
Definition: qgscallout.h:83
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:79
Property
Data definable properties.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:101
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 str(x)
Definition: qgis.cpp:37
#define SIP_FACTORY
Definition: qgis_sip.h:76
struct sqlite3 sqlite3
const QgsField & field
Definition: qgsfield.h:463