QgsAuxiliaryStorage class

Class providing some utility methods to manage auxiliary storage.

Public static functions

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

Constructors, destructors, conversion operators

QgsAuxiliaryStorage(const QgsProject& project, bool copy = true)
Constructor.
QgsAuxiliaryStorage(const QString& filename = QString(), bool copy = true)
Constructor.
~QgsAuxiliaryStorage() virtual
Destructor.

Public functions

auto createAuxiliaryLayer(const QgsField& field, QgsVectorLayer* layer) const -> QgsAuxiliaryLayer*
Creates an auxiliary layer for a vector layer.
auto currentFileName() const -> QString
Returns the path of the current database used.
auto errorString() const -> QString
Returns the underlying error string describing potential errors happening in saveAs().
auto fileName() const -> QString
Returns the target filename of the database.
auto isValid() const -> bool
Returns the status of the auxiliary storage currently defined.
auto save() const -> bool
Saves the current database.
auto saveAs(const QString& filename) -> bool
Saves the current database to a new path.
auto saveAs(const QgsProject& project) -> bool
Saves the current database to a new path for a specific project.

Function documentation

static bool QgsAuxiliaryStorage::deleteTable(const QgsDataSourceUri& uri)

Removes a table from the auxiliary storage.

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

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

Duplicates a table and its content.

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

static bool QgsAuxiliaryStorage::exists(const QgsProject& project)

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

Parameters
project The project for which the database is checked

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

Constructor.

Parameters
project The project for which the auxiliary storage has to be used
copy Parameter indicating if a copy of the database has to be used

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

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

Constructor.

Parameters
filename The path of the database
copy Parameter indicating if a copy of the database has to be used

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.

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

Creates an auxiliary layer for a vector layer.

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

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

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.

QString QgsAuxiliaryStorage::errorString() const

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

Empty by default.

bool QgsAuxiliaryStorage::isValid() const

Returns the status of the auxiliary storage currently defined.

Returns true if the auxiliary storage is valid, false otherwise

bool QgsAuxiliaryStorage::save() const

Saves the current database.

Returns true if everything is saved, false otherwise

bool QgsAuxiliaryStorage::saveAs(const QString& filename)

Saves the current database to a new path.

Returns true if everything is saved, false otherwise

bool QgsAuxiliaryStorage::saveAs(const QgsProject& project)

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

Returns true if everything is saved, false otherwise

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