QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
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
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 "qgscallout.h"
23#include "qgsdatasourceuri.h"
24#include "qgsdiagramrenderer.h"
25#include "qgspallabeling.h"
26#include "qgsproperty.h"
27#include "qgssqliteutils.h"
28#include "qgsvectorlayer.h"
30
31#include <QString>
32
33using namespace Qt::StringLiterals;
34
35class QgsProject;
36
63class CORE_EXPORT QgsAuxiliaryLayer : public QgsVectorLayer
64{
65 Q_OBJECT
66
67 public:
68
77 QgsAuxiliaryLayer( const QString &pkField, const QString &filename, const QString &table, QgsVectorLayer *vlayer );
78
79 QgsAuxiliaryLayer( const QgsAuxiliaryLayer &rhs ) = delete;
80
82
83#ifdef SIP_RUN
84 SIP_PYOBJECT __repr__();
85 % MethodCode
86 QString str = u"<QgsAuxiliaryLayer: '%1'>"_s.arg( sipCpp->name() );
87 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
88 % End
89#endif
90
91#ifndef SIP_RUN
93#endif
94
103
111
118 bool clear();
119
124
133 bool exists( const QgsPropertyDefinition &definition ) const;
134
144 bool addAuxiliaryField( const QgsPropertyDefinition &definition );
145
150
156 bool save();
157
166 bool deleteAttribute( int attr ) override;
167
174 bool isHiddenProperty( int index ) const;
175
184 int indexOfPropertyDefinition( const QgsPropertyDefinition &definition ) const;
185
194 int propertyFromIndex( int index ) const;
195
202
213 static int createProperty( QgsPalLayerSettings::Property property, QgsVectorLayer *vlayer, bool overwriteExisting = true );
214
225 static int createProperty( QgsDiagramLayerSettings::Property property, QgsVectorLayer *vlayer, bool overwriteExisting = true );
226
238 static int createProperty( QgsCallout::Property property, QgsVectorLayer *vlayer, bool overwriteExisting = true );
239
246
252 static QgsField createAuxiliaryField( const QgsField &field );
253
260 static QString nameFromProperty( const QgsPropertyDefinition &def, bool joined = false );
261
268
269 private:
270 QgsVectorLayerJoinInfo mJoinInfo;
271 QString mFileName;
272 QString mTable;
273 QgsVectorLayer *mLayer = nullptr;
274};
275
276
285class CORE_EXPORT QgsAuxiliaryStorage
286{
287 public:
288
300 QgsAuxiliaryStorage( const QgsProject &project, bool copy = true );
301
323 QgsAuxiliaryStorage( const QString &filename = QString(), bool copy = true );
324
326
332 bool isValid() const;
333
337 QString fileName() const;
338
343 QString currentFileName() const;
344
351 QString errorString() const;
352
358 bool saveAs( const QString &filename );
359
367 bool saveAs( const QgsProject &project );
368
374 bool save() const;
375
387
395 static bool deleteTable( const QgsDataSourceUri &uri );
396
405 static bool duplicateTable( const QgsDataSourceUri &uri, const QString &newTable );
406
410 static QString extension();
411
419 static bool exists( const QgsProject &project );
420
421 private:
422 sqlite3_database_unique_ptr open( const QString &filename = QString() );
423 sqlite3_database_unique_ptr open( const QgsProject &project );
424
425 void initTmpFileName();
426
427 static QString filenameForProject( const QgsProject &project );
428 static sqlite3_database_unique_ptr createDB( const QString &filename );
429 static sqlite3_database_unique_ptr openDB( const QString &filename );
430 static bool tableExists( const QString &table, sqlite3 *handler );
431 static bool createTable( const QString &type, const QString &table, sqlite3 *handler, QString &errorMsg );
432
433 static bool exec( const QString &sql, sqlite3 *handler );
434 static QString debugMsg( const QString &sql, sqlite3 *handler );
435
436 static QgsDataSourceUri parseOgrUri( const QgsDataSourceUri &uri );
437
438 bool mValid = false;
439 QString mFileName; // original filename
440 QString mTmpFileName; // temporary filename used in copy mode
441 bool mCopy = false;
442 mutable QString mErrorString;
443};
444
445#endif
Allows managing the auxiliary storage for a vector layer.
static QString nameFromProperty(const QgsPropertyDefinition &def, bool joined=false)
Returns the name of the auxiliary field for a property definition.
static QgsField createAuxiliaryField(const QgsPropertyDefinition &definition)
Creates a new auxiliary field from a property definition.
static QgsPropertyDefinition propertyDefinitionFromField(const QgsField &field)
Returns the property definition from an auxiliary field.
bool clear()
Deletes all features from the layer.
bool addAuxiliaryField(const QgsPropertyDefinition &definition)
Adds an auxiliary field for the given property.
bool isHiddenProperty(int index) const
Returns true if the underlying field has to be hidden from editing tools like attribute table,...
QgsVectorLayer * toSpatialLayer() const
An auxiliary layer is not spatial.
bool deleteAttribute(int attr) override
Removes attribute from the layer and commits changes.
QgsFields auxiliaryFields() const
Returns a list of all auxiliary fields currently managed by the layer.
QgsAuxiliaryLayer(const QString &pkField, const QString &filename, const QString &table, QgsVectorLayer *vlayer)
Constructor.
bool save()
Commits changes and starts editing then.
int propertyFromIndex(int index) const
Returns the underlying property key for the field index.
static int createProperty(QgsDiagramLayerSettings::Property property, QgsVectorLayer *vlayer, bool overwriteExisting=true)
Creates if necessary a new auxiliary field for a diagram's property and activates this property in se...
QgsVectorLayerJoinInfo joinInfo() const
Returns information to use for joining with primary key and so on.
QgsPropertyDefinition propertyDefinitionFromIndex(int index) const
Returns the property definition for the underlying field index.
bool exists(const QgsPropertyDefinition &definition) const
Returns true if the property is stored in the layer already, false otherwise.
static int createProperty(QgsCallout::Property property, QgsVectorLayer *vlayer, bool overwriteExisting=true)
Creates if necessary a new auxiliary field for a callout's property and activates this property in se...
static int createProperty(QgsPalLayerSettings::Property property, QgsVectorLayer *vlayer, bool overwriteExisting=true)
Creates if necessary a new auxiliary field for a PAL property and activates this property in settings...
QgsAuxiliaryLayer & operator=(QgsAuxiliaryLayer const &rhs)=delete
QgsAuxiliaryLayer * clone(QgsVectorLayer *layer) const
Returns a new instance equivalent to this one.
static QgsField createAuxiliaryField(const QgsField &field)
Creates a new auxiliary field from a field.
int indexOfPropertyDefinition(const QgsPropertyDefinition &definition) const
Returns the index of the auxiliary field for a specific property definition.
QgsAuxiliaryLayer(const QgsAuxiliaryLayer &rhs)=delete
QgsAuxiliaryStorage(const QString &filename=QString(), bool copy=true)
Constructor.
static QString extension()
Returns the extension used for auxiliary databases.
QString errorString() const
Returns the underlying error string describing potential errors happening in saveAs().
bool save() const
Saves the current database.
static bool exists(const QgsProject &project)
Returns true if the auxiliary database yet exists for a project, false otherwise.
QgsAuxiliaryLayer * createAuxiliaryLayer(const QgsField &field, QgsVectorLayer *layer) const
Creates an auxiliary layer for a vector layer.
virtual ~QgsAuxiliaryStorage()
bool saveAs(const QString &filename)
Saves the current database to a new path.
bool isValid() const
Returns the status of the auxiliary storage currently defined.
QString currentFileName() const
Returns the path of the current database used.
QgsAuxiliaryStorage(const QgsProject &project, bool copy=true)
Constructor.
QString fileName() const
Returns the target filename of the database.
static bool deleteTable(const QgsDataSourceUri &uri)
Removes a table from the auxiliary storage.
bool saveAs(const QgsProject &project)
Saves the current database to a new path for a specific project.
static bool duplicateTable(const QgsDataSourceUri &uri, const QString &newTable)
Duplicates a table and its content.
Property
Data definable properties.
Definition qgscallout.h:87
Stores the component parts of a data source URI (e.g.
Property
Data definable properties.
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:56
Container of fields for a vector layer.
Definition qgsfields.h:46
Property
Data definable properties.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:112
Definition for a property.
Definition qgsproperty.h:47
Defines left outer join from our vector layer to some other vector layer.
Represents a vector layer which manages a vector based dataset.
QgsVectorLayer(const QString &path=QString(), const QString &baseName=QString(), const QString &providerLib="ogr", const QgsVectorLayer::LayerOptions &options=QgsVectorLayer::LayerOptions())
Constructor - creates a vector layer.
QgsVectorLayer * clone() const override
Returns a new instance equivalent to this one.
Unique pointer for sqlite3 databases, which automatically closes the database when the pointer goes o...
#define SIP_FACTORY
Definition qgis_sip.h:84
struct sqlite3 sqlite3