QGIS API Documentation  3.6.0-Noosa (5873452)
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 <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 
81  QgsAuxiliaryLayer &operator=( QgsAuxiliaryLayer const &rhs ) = delete;
82 
91 
98  QgsVectorLayer *toSpatialLayer() const;
99 
106  bool clear();
107 
111  QgsVectorLayerJoinInfo joinInfo() const;
112 
121  bool exists( const QgsPropertyDefinition &definition ) const;
122 
132  bool addAuxiliaryField( const QgsPropertyDefinition &definition );
133 
137  QgsFields auxiliaryFields() const;
138 
144  bool save();
145 
154  bool deleteAttribute( int attr ) override;
155 
162  bool isHiddenProperty( int index ) const;
163 
172  int indexOfPropertyDefinition( const QgsPropertyDefinition &definition ) const;
173 
182  int propertyFromIndex( int index ) const;
183 
189  QgsPropertyDefinition propertyDefinitionFromIndex( int index ) const;
190 
200  static int createProperty( QgsPalLayerSettings::Property property, QgsVectorLayer *vlayer );
201 
211  static int createProperty( QgsDiagramLayerSettings::Property property, QgsVectorLayer *vlayer );
212 
218  static QgsField createAuxiliaryField( const QgsPropertyDefinition &definition );
219 
225  static QgsField createAuxiliaryField( const QgsField &field );
226 
233  static QString nameFromProperty( const QgsPropertyDefinition &def, bool joined = false );
234 
240  static QgsPropertyDefinition propertyDefinitionFromField( const QgsField &field );
241 
242  private:
243  QgsVectorLayerJoinInfo mJoinInfo;
244  QString mFileName;
245  QString mTable;
246  QgsVectorLayer *mLayer = nullptr;
247 };
248 
249 
259 class CORE_EXPORT QgsAuxiliaryStorage
260 {
261  public:
262 
274  QgsAuxiliaryStorage( const QgsProject &project, bool copy = true );
275 
297  QgsAuxiliaryStorage( const QString &filename = QString(), bool copy = true );
298 
302  virtual ~QgsAuxiliaryStorage();
303 
309  bool isValid() const;
310 
314  QString fileName() const;
315 
320  QString currentFileName() const;
321 
328  QString errorString() const;
329 
335  bool saveAs( const QString &filename );
336 
344  bool saveAs( const QgsProject &project );
345 
351  bool save() const;
352 
363  QgsAuxiliaryLayer *createAuxiliaryLayer( const QgsField &field, QgsVectorLayer *layer ) const SIP_FACTORY;
364 
372  static bool deleteTable( const QgsDataSourceUri &uri );
373 
382  static bool duplicateTable( const QgsDataSourceUri &uri, const QString &newTable );
383 
387  static QString extension();
388 
396  static bool exists( const QgsProject &project );
397 
398  private:
399  spatialite_database_unique_ptr open( const QString &filename = QString() );
400  spatialite_database_unique_ptr open( const QgsProject &project );
401 
402  void initTmpFileName();
403 
404  static QString filenameForProject( const QgsProject &project );
405  static spatialite_database_unique_ptr createDB( const QString &filename );
406  static spatialite_database_unique_ptr openDB( const QString &filename );
407  static bool tableExists( const QString &table, sqlite3 *handler );
408  static bool createTable( const QString &type, const QString &table, sqlite3 *handler );
409 
410  static bool exec( const QString &sql, sqlite3 *handler );
411  static void debugMsg( const QString &sql, sqlite3 *handler );
412 
413  static QgsDataSourceUri parseOgrUri( const QgsDataSourceUri &uri );
414 
415  bool mValid = false;
416  QString mFileName; // original filename
417  QString mTmpFileName; // temporary filename used in copy mode
418  bool mCopy = false;
419  QString mErrorString;
420 };
421 
422 #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:89
#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.