Skip to content

Class QfDeltaFileWrapper

ClassList > QfDeltaFileWrapper

More...

  • #include <qfdeltafilewrapper.h>

Inherits the following classes: QObject

Public Types

Type Name
enum ErrorType

Public Properties

Type Name
property int addedCount
property int count
property int deletedCount
property int editedCount
property QString errorString
property ErrorType errorType
property bool hasError
property bool isPushing

Public Signals

Type Name
signal void countChanged
signal void errorChanged
signal void isPushingChanged
signal void savedToFile

Public Functions

Type Name
QfDeltaFileWrapper (const QString & projectId, const QString & fileName)
void addCreate (const QgsProject * project, const QString & localLayerId, const QString & sourceLayerId, const QString & localPkAttrName, const QString & sourcePkAttrName, const QgsFeature & newFeature)
void addDelete (const QgsProject * project, const QString & localLayerId, const QString & sourceLayerId, const QString & localPkAttrName, const QString & sourcePkAttrName, const QgsFeature & oldFeature)
void addPatch (const QgsProject * project, const QString & localLayerId, const QString & sourceLayerId, const QString & localPkAttrName, const QString & sourcePkAttrName, const QgsFeature & oldFeature, const QgsFeature & newFeature, bool storeSnapshot=true)
int addedCount () const
bool append (const QfDeltaFileWrapper * deltaFileWrapper)
Q_INVOKABLE bool apply (const QgsProject * project)
Q_INVOKABLE bool applyReversed (const QgsProject * project)
QMap< QString, QString > attachmentFileNames () const
Q_INVOKABLE int count () const
int deletedCount () const
QStringList deltaLayerIds () const
QJsonArray deltas () const
int editedCount () const
QString errorString () const
ErrorType errorType () const
QString fileName () const
int getDeltaIndexByUuid (const QString & uuid) const
bool hasError () const
QString id () const
Q_INVOKABLE bool isCreatedFeature (QgsVectorLayer * vl, QgsFeature feature)
bool isDeltaBeingApplied () const
bool isDirty () const
bool isPushing () const
QString projectId () const
Q_INVOKABLE void reset ()
Q_INVOKABLE void resetId ()
void setIsPushing (bool isPushing)
Q_INVOKABLE bool toFile ()
Q_INVOKABLE QString toFileForPush (const QString & outFileName=QString()) const
QByteArray toJson (QJsonDocument::JsonFormat jsonFormat=QJsonDocument::Indented) const
QString toString () const
~QfDeltaFileWrapper ()

Public Static Functions

Type Name
QStringList attachmentFieldNames (const QgsProject * project, const QString & layerId)
QString crsByLayerId (const QgsProject * project, const QString & layerId)
QPair< int, QString > getLocalPkAttribute (const QgsVectorLayer * vl)
Get a pair of the index and the name of the primary key column of given vl layer. We assume there is no multi-column primary key.
QString getSourceLayerId (const QgsVectorLayer * vl)
QPair< int, QString > getSourcePkAttribute (const QgsVectorLayer * vl)
Get a pair of the index and the name of the primary key column of given vl layer, as they are in the original source.
QgsFeatureRequest localPkRequest (const QgsVectorLayer * vl, const QStringList & localPks)
Get a request matching the features of given vl layer whose local primary key is one of__localPks . Returns a request matching nothing when the layer has no usable primary key.
QString nameByLayerId (const QgsProject * project, const QString & layerId)

Detailed Description

A class that wraps the operations with a delta file. All read and write operations to a delta file should go through this class.

Public Types Documentation

enum ErrorType

enum QfDeltaFileWrapper::ErrorType {
    NoError,
    LockError,
    NotCloudProjectError,
    IOError,
    JsonParseError,
    JsonFormatIdError,
    JsonFormatProjectIdError,
    JsonFormatVersionError,
    JsonFormatDeltasError,
    JsonFormatDeltaItemError,
    JsonIncompatibleVersionError
};

Error types


Public Properties Documentation

property addedCount [1/2]

int QfDeltaFileWrapper::addedCount;

property count [1/2]

int QfDeltaFileWrapper::count;

property deletedCount [1/2]

int QfDeltaFileWrapper::deletedCount;

property editedCount [1/2]

int QfDeltaFileWrapper::editedCount;

property errorString [1/2]

QString QfDeltaFileWrapper::errorString;

property errorType [1/2]

ErrorType QfDeltaFileWrapper::errorType;

property hasError [1/2]

bool QfDeltaFileWrapper::hasError;

property isPushing [1/2]

bool QfDeltaFileWrapper::isPushing;

Public Signals Documentation

signal countChanged

void QfDeltaFileWrapper::countChanged;

Emitted when the deltas list has changed.


signal errorChanged

void QfDeltaFileWrapper::errorChanged;

Emmitted when the latest error has changed


signal isPushingChanged

void QfDeltaFileWrapper::isPushingChanged;

Emmitted when the pushing state has changed.


signal savedToFile

void QfDeltaFileWrapper::savedToFile;

Emmitted when the deltas have been written to a file


Public Functions Documentation

function QfDeltaFileWrapper

QfDeltaFileWrapper::QfDeltaFileWrapper (
    const QString & projectId,
    const QString & fileName
) 

Construct a new Feature Deltas object.

Parameters:

  • project the current project
  • fileName complete file name with path where the object should be stored

function addCreate

void QfDeltaFileWrapper::addCreate (
    const QgsProject * project,
    const QString & localLayerId,
    const QString & sourceLayerId,
    const QString & localPkAttrName,
    const QString & sourcePkAttrName,
    const QgsFeature & newFeature
) 

Adds create delta.

Parameters:

  • localLayerId layer ID where the old feature belongs to
  • sourceLayerId layer ID where the old feature belongs to
  • localPkAttrName attribute name of the primary key
  • sourcePkAttrName attribute name of the primary key
  • newFeature the feature that has been created

function addDelete

void QfDeltaFileWrapper::addDelete (
    const QgsProject * project,
    const QString & localLayerId,
    const QString & sourceLayerId,
    const QString & localPkAttrName,
    const QString & sourcePkAttrName,
    const QgsFeature & oldFeature
) 

Adds delete delta.

Parameters:

  • localLayerId layer ID where the old feature belongs to
  • sourceLayerId layer ID where the old feature belongs to
  • localPkAttrName attribute name of the primary key
  • sourcePkAttrName attribute name of the primary key
  • oldFeature the feature that has been deleted

function addPatch

void QfDeltaFileWrapper::addPatch (
    const QgsProject * project,
    const QString & localLayerId,
    const QString & sourceLayerId,
    const QString & localPkAttrName,
    const QString & sourcePkAttrName,
    const QgsFeature & oldFeature,
    const QgsFeature & newFeature,
    bool storeSnapshot=true
) 

Adds patch delta.

Parameters:

  • localLayerId layer ID where the old feature belongs to
  • sourceLayerId layer ID where the old feature belongs to
  • localPkAttrName attribute name of the primary key
  • sourcePkAttrName attribute name of the primary key
  • oldFeature the old version of the feature that has been modified
  • newFeature the new version of the feature that has been modified
  • storeSnapshot store a complete snapshot of the feature

function addedCount [2/2]

int QfDeltaFileWrapper::addedCount () const

Returns the number of delta elements creating a feature

Returns:

int number of created features


function append

bool QfDeltaFileWrapper::append (
    const QfDeltaFileWrapper * deltaFileWrapper
) 

Appends the provided deltas JSON array at the end of the current file.


function apply

Q_INVOKABLE bool QfDeltaFileWrapper::apply (
    const QgsProject * project
) 

Attempts to apply a delta file. The list of deltas is not being reset after successfull application and should be handled by the caller.

Note:

it is not guaranteed that the project layers have not changed in case of failure

Returns:

whether the attempt was successful

Todo

TEST


function applyReversed

Q_INVOKABLE bool QfDeltaFileWrapper::applyReversed (
    const QgsProject * project
) 

Attempts to apply a delta file in reverse order (resulting in local changes being discarded). The list of deltas is not being reset after successfull application and should be handled by the caller.

Note:

it is not guaranteed that the project layers have not changed in case of failure

Returns:

whether the attempt was successful.

Todo

TEST


function attachmentFileNames

QMap< QString, QString > QfDeltaFileWrapper::attachmentFileNames () const

Returns a set of file names to be uploaded

Returns:

QMap<QString, QString> unique file names


function count [2/2]

Q_INVOKABLE int QfDeltaFileWrapper::count () const

Returns the number of delta elements

Returns:

int number of delta elements


function deletedCount [2/2]

int QfDeltaFileWrapper::deletedCount () const

Returns the number of delta elements removing a feature

Returns:

int number of deleted features


function deltaLayerIds

QStringList QfDeltaFileWrapper::deltaLayerIds () const

Returns the list of layers that have applied deltas on them.

Returns:

list of layers ids

Todo

TEST


function deltas

QJsonArray QfDeltaFileWrapper::deltas () const

Returns the deltas as a JSON array of delta elements

Returns:

QJsonArray deltas JSON array


function editedCount [2/2]

int QfDeltaFileWrapper::editedCount () const

Returns the number of delta elements modifying a feature

Returns:

int number of edited features


function errorString [2/2]

QString QfDeltaFileWrapper::errorString () const

Human readable error description why the class has an error.

Returns:

QString human readable error reason


function errorType [2/2]

ErrorType QfDeltaFileWrapper::errorType () const

Error type why the class has an error.

Returns:

ErrorType error type


function fileName

QString QfDeltaFileWrapper::fileName () const

Returns deltas file name.

Returns:

QString file name


function getDeltaIndexByUuid

int QfDeltaFileWrapper::getDeltaIndexByUuid (
    const QString & uuid
) const

Retuns the index position of a delta with given uuid in the deltas list or -1 if missing.

Parameters:

  • uuid the uuid we are looking for

function hasError [2/2]

bool QfDeltaFileWrapper::hasError () const

Returns whether the class has encountered I/O error regarding the delta file. If true is returned, the behaviour of the class instance is no more defined.

Returns:

bool whether an error has been encountered


function id

QString QfDeltaFileWrapper::id () const

Returns deltas file id.

Returns:

QString id


function isCreatedFeature

Q_INVOKABLE bool QfDeltaFileWrapper::isCreatedFeature (
    QgsVectorLayer * vl,
    QgsFeature feature
) 

Returns TRUE if a feature from a given vector layer is recorded as being created in the deltas file.

Parameters:

  • vl the vector layer
  • feature the feature

function isDeltaBeingApplied

bool QfDeltaFileWrapper::isDeltaBeingApplied () const

Whether or not the current delta file is being applied.

Todo

TEST


function isDirty

bool QfDeltaFileWrapper::isDirty () const

Returns whether the instance contents differs from the data saved on the disk.

Returns:

bool whether there is a difference with the data saved on the disk


function isPushing [2/2]

inline bool QfDeltaFileWrapper::isPushing () const

Returns TRUE if the pushing state is active.


function projectId

QString QfDeltaFileWrapper::projectId () const

Returns deltas file project id.

Returns:

QString project id


function reset

Q_INVOKABLE void QfDeltaFileWrapper::reset () 

Clears the deltas from memory as there are no deltas at all. Does not affect the permanent storage until toFile() is called.


function resetId

Q_INVOKABLE void QfDeltaFileWrapper::resetId () 

Assigns a new unique delta file id.


function setIsPushing

void QfDeltaFileWrapper::setIsPushing (
    bool isPushing
) 

Sets the pushing state.

Parameters:

  • isPushing set to TRUE to reflect an ongoing pushing state.

function toFile

Q_INVOKABLE bool QfDeltaFileWrapper::toFile () 

Writes deltas file to the permanent storage.

Returns:

bool whether write has been successful


function toFileForPush

Q_INVOKABLE QString QfDeltaFileWrapper::toFileForPush (
    const QString & outFileName=QString()
) const

Writes deltas file to the permanent storage with replaced layerIds, ready for upload.

Returns:

QString an empty string


function toJson

QByteArray QfDeltaFileWrapper::toJson (
    QJsonDocument::JsonFormat jsonFormat=QJsonDocument::Indented
) const

Returns deltas as JSON QByteArray, ready for I/O operations.

Parameters:

  • jsonFormat formatting of the output JSON. Default: QJsonDocument::Indented

Returns:

QByteArray JSON representation


function toString

QString QfDeltaFileWrapper::toString () const

Returns deltas as JSON string.

Returns:

QString JSON representation


function ~QfDeltaFileWrapper

QfDeltaFileWrapper::~QfDeltaFileWrapper () 

Destroy the Delta File Wrapper object


Public Static Functions Documentation

function attachmentFieldNames

static QStringList QfDeltaFileWrapper::attachmentFieldNames (
    const QgsProject * project,
    const QString & layerId
) 

Returns a list of field names that have edit form as attachments

Parameters:

  • project current project instance
  • layerId layer ID

Returns:

QStringList list of field names


function crsByLayerId

static QString QfDeltaFileWrapper::crsByLayerId (
    const QgsProject * project,
    const QString & layerId
) 

Returns the CRS as WKT for given layerId in the project


function getLocalPkAttribute

Get a pair of the index and the name of the primary key column of given vl layer. We assume there is no multi-column primary key.

static QPair< int, QString > QfDeltaFileWrapper::getLocalPkAttribute (
    const QgsVectorLayer * vl
) 


function getSourceLayerId

static QString QfDeltaFileWrapper::getSourceLayerId (
    const QgsVectorLayer * vl
) 

Get the layer id as it is in the original source.


function getSourcePkAttribute

Get a pair of the index and the name of the primary key column of given vl layer, as they are in the original source.

static QPair< int, QString > QfDeltaFileWrapper::getSourcePkAttribute (
    const QgsVectorLayer * vl
) 


function localPkRequest

Get a request matching the features of given vl layer whose local primary key is one of__localPks . Returns a request matching nothing when the layer has no usable primary key.

static QgsFeatureRequest QfDeltaFileWrapper::localPkRequest (
    const QgsVectorLayer * vl,
    const QStringList & localPks
) 


function nameByLayerId

static QString QfDeltaFileWrapper::nameByLayerId (
    const QgsProject * project,
    const QString & layerId
) 

Returns the name for given layerId in the project



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