Skip to content

Class ProjectUtils

ClassList > ProjectUtils

Inherits the following classes: QObject

Public Functions

Type Name
ProjectUtils (QObject * parent=nullptr)

Public Static Functions

Type Name
Q_INVOKABLE bool addMapLayer (QgsProject * project, QgsMapLayer * layer)
Q_INVOKABLE QString createProject (const QVariantMap & options, const GnssPositionInformation & positionInformation=GnssPositionInformation())
Q_INVOKABLE QVariantMap mapLayers (QgsProject * project)
Q_INVOKABLE void removeMapLayer (QgsProject * project, QgsMapLayer * layer)
Q_INVOKABLE void removeMapLayer (QgsProject * project, const QString & layerId)
Q_INVOKABLE QString title (QgsProject * project=nullptr)
Q_INVOKABLE Qgis::TransactionMode transactionMode (QgsProject * project=nullptr)

Public Functions Documentation

function ProjectUtils

explicit ProjectUtils::ProjectUtils (
    QObject * parent=nullptr
) 

Public Static Functions Documentation

function addMapLayer

static Q_INVOKABLE bool ProjectUtils::addMapLayer (
    QgsProject * project,
    QgsMapLayer * layer
) 

Adds a map layer to a project layers registry.


function createProject

static Q_INVOKABLE QString ProjectUtils::createProject (
    const QVariantMap & options,
    const GnssPositionInformation & positionInformation=GnssPositionInformation ()
) 

Creates a new project and return the local path of the project file.

The available options are: * title: the project title * basemap: the basemap type (color, lightgray, darkgray, custom, blank) * basemap_url: a custom basemap URL (XYZ raster layer or vector tile layer style JSON) * notes: set to TRUE to add a notes layer * camera_capture: set to TRUE to add an image/video capture field to the notes layer * tracks: set to TRUE to add a tracks layer * track_on_launch: set to TRUE to start tracking position on project launch


function mapLayers

static Q_INVOKABLE QVariantMap ProjectUtils::mapLayers (
    QgsProject * project
) 

Returns a map of all registered layers by layer ID.

Note:

This function mimics QgsProject::mapLayers with a return type that is QML compatible.


function removeMapLayer [1/2]

static Q_INVOKABLE void ProjectUtils::removeMapLayer (
    QgsProject * project,
    QgsMapLayer * layer
) 

Removes a map layer from a project layers registry.


function removeMapLayer [2/2]

static Q_INVOKABLE void ProjectUtils::removeMapLayer (
    QgsProject * project,
    const QString & layerId
) 

Removes a map layer from a project layers registry matching a given layer ID.

Parameters:

  • project the project
  • layerId the layer ID

function title

static Q_INVOKABLE QString ProjectUtils::title (
    QgsProject * project=nullptr
) 

Returns the project title.


function transactionMode

static Q_INVOKABLE Qgis::TransactionMode ProjectUtils::transactionMode (
    QgsProject * project=nullptr
) 

Returns the transaction mode for a given project.

Note:

To be removed when QField updates to QGIS 3.38.



The documentation for this class was generated from the following file src/core/utils/projectutils.h