QGIS API Documentation  3.4.15-Madeira (e83d02e274)
Public Member Functions | Static Public Member Functions | List of all members
QgsAuxiliaryStorage Class Reference

Class providing some utility methods to manage auxiliary storage. More...

#include <qgsauxiliarystorage.h>

Public Member Functions

 QgsAuxiliaryStorage (const QgsProject &project, bool copy=true)
 Constructor. More...
 
 QgsAuxiliaryStorage (const QString &filename=QString(), bool copy=true)
 Constructor. More...
 
virtual ~QgsAuxiliaryStorage ()
 Destructor. More...
 
QgsAuxiliaryLayercreateAuxiliaryLayer (const QgsField &field, QgsVectorLayer *layer) const
 Creates an auxiliary layer for a vector layer. More...
 
QString currentFileName () const
 Returns the path of the current database used. More...
 
QString errorString () const
 Returns the underlying error string describing potential errors happening in saveAs(). More...
 
QString fileName () const
 Returns the target filename of the database. More...
 
bool isValid () const
 Returns the status of the auxiliary storage currently defined. More...
 
bool save () const
 Saves the current database. More...
 
bool saveAs (const QString &filename)
 Saves the current database to a new path. More...
 
bool saveAs (const QgsProject &project)
 Saves the current database to a new path for a specific project. More...
 

Static Public Member Functions

static bool deleteTable (const QgsDataSourceUri &uri)
 Removes a table from the auxiliary storage. More...
 
static bool duplicateTable (const QgsDataSourceUri &uri, const QString &newTable)
 Duplicates a table and its content. More...
 
static bool exists (const QgsProject &project)
 Returns true if the auxiliary database yet exists for a project, false otherwise. More...
 
static QString extension ()
 Returns the extension used for auxiliary databases. More...
 

Detailed Description

Class providing some utility methods to manage auxiliary storage.

Since
QGIS 3.0

Definition at line 259 of file qgsauxiliarystorage.h.

Constructor & Destructor Documentation

QgsAuxiliaryStorage::QgsAuxiliaryStorage ( const QgsProject project,
bool  copy = true 
)

Constructor.

The project filename is used to build a database path at the same location, but with a different extension. Then, it's the same logic as described for

See also
QgsAuxiliaryStorage(const QString &, bool copy).
Parameters
projectThe project for which the auxiliary storage has to be used
copyParameter indicating if a copy of the database has to be used

Definition at line 516 of file qgsauxiliarystorage.cpp.

QgsAuxiliaryStorage::QgsAuxiliaryStorage ( const QString &  filename = QString(),
bool  copy = true 
)

Constructor.

If a valid database path is given in parameter and copy mode is deactivated, then every changes is directly committed on the original database. But if the copy mode is activated, then changes are committed on a copy of the database (a temporary file) and a save action is therefore necessary to keep modifications in the original file.

If an empty string for the database path is given in parameter, then a database is created in a temporary file whatever the copy mode.

If the database path given in parameter is not empty but does not exist, then a database is created at this location when copy mode is deactivated. When copy mode is activated, a temporary database is used instead and a save action will be necessary to create the database at the original location given in parameter.

Parameters
filenameThe path of the database
copyParameter indicating if a copy of the database has to be used

Definition at line 529 of file qgsauxiliarystorage.cpp.

QgsAuxiliaryStorage::~QgsAuxiliaryStorage ( )
virtual

Destructor.

Definition at line 538 of file qgsauxiliarystorage.cpp.

Member Function Documentation

QgsAuxiliaryLayer * QgsAuxiliaryStorage::createAuxiliaryLayer ( const QgsField field,
QgsVectorLayer layer 
) const

Creates an auxiliary layer for a vector layer.

A new table is created if necessary. The primary key to use to construct the auxiliary layer is given in parameter.

Parameters
fieldThe primary key to join
layerThe vector layer for which the auxiliary layer has to be created
Returns
A new auxiliary layer or a nullptr if an error happened.

Definition at line 576 of file qgsauxiliarystorage.cpp.

QString QgsAuxiliaryStorage::currentFileName ( ) const

Returns the path of the current database used.

It may be different from the target filename if the auxiliary storage is opened in copy mode.

Definition at line 822 of file qgsauxiliarystorage.cpp.

bool QgsAuxiliaryStorage::deleteTable ( const QgsDataSourceUri uri)
static

Removes a table from the auxiliary storage.

Parameters
uriThe uri of the table to remove
Returns
true if the table is well deleted, false otherwise

Definition at line 601 of file qgsauxiliarystorage.cpp.

bool QgsAuxiliaryStorage::duplicateTable ( const QgsDataSourceUri uri,
const QString &  newTable 
)
static

Duplicates a table and its content.

Parameters
uriThe uri of the table to duplicate
newTableThe name of the new table
Returns
true if the table is well duplicated, false otherwise

Definition at line 624 of file qgsauxiliarystorage.cpp.

QString QgsAuxiliaryStorage::errorString ( ) const

Returns the underlying error string describing potential errors happening in saveAs().

Empty by default.

Since
QGIS 3.4

Definition at line 644 of file qgsauxiliarystorage.cpp.

bool QgsAuxiliaryStorage::exists ( const QgsProject project)
static

Returns true if the auxiliary database yet exists for a project, false otherwise.

Parameters
projectThe project for which the database is checked
Since
QGIS 3.2

Definition at line 680 of file qgsauxiliarystorage.cpp.

QString QgsAuxiliaryStorage::extension ( )
static

Returns the extension used for auxiliary databases.

Definition at line 675 of file qgsauxiliarystorage.cpp.

QString QgsAuxiliaryStorage::fileName ( ) const

Returns the target filename of the database.

Definition at line 548 of file qgsauxiliarystorage.cpp.

bool QgsAuxiliaryStorage::isValid ( ) const

Returns the status of the auxiliary storage currently defined.

Returns
true if the auxiliary storage is valid, false otherwise

Definition at line 543 of file qgsauxiliarystorage.cpp.

bool QgsAuxiliaryStorage::save ( ) const

Saves the current database.

Returns
true if everything is saved, false otherwise

Definition at line 553 of file qgsauxiliarystorage.cpp.

bool QgsAuxiliaryStorage::saveAs ( const QString &  filename)

Saves the current database to a new path.

Returns
true if everything is saved, false otherwise

Definition at line 649 of file qgsauxiliarystorage.cpp.

bool QgsAuxiliaryStorage::saveAs ( const QgsProject project)

Saves the current database to a new path for a specific project.

Actually, the current filename of the project is used to deduce the path of the database to save.

Returns
true if everything is saved, false otherwise

Definition at line 670 of file qgsauxiliarystorage.cpp.


The documentation for this class was generated from the following files: