Skip to content

Class DeltaFileWrapper

ClassList > DeltaFileWrapper

More...

  • #include <deltafilewrapper.h>

Inherits the following classes: QObject

Public Types

Type Name
enum ErrorType

Public Properties

Type Name
property int count
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
DeltaFileWrapper (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)
bool append (const DeltaFileWrapper * 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
QStringList deltaLayerIds () const
QJsonArray deltas () 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
~DeltaFileWrapper ()

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.
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 DeltaFileWrapper::ErrorType {
    NoError,
    LockError,
    NotCloudProjectError,
    IOError,
    JsonParseError,
    JsonFormatIdError,
    JsonFormatProjectIdError,
    JsonFormatVersionError,
    JsonFormatDeltasError,
    JsonFormatDeltaItemError,
    JsonIncompatibleVersionError
};

Error types


Public Properties Documentation

property count [1/2]

int DeltaFileWrapper::count;

property errorString [1/2]

QString DeltaFileWrapper::errorString;

property errorType [1/2]

ErrorType DeltaFileWrapper::errorType;

property hasError [1/2]

bool DeltaFileWrapper::hasError;

property isPushing [1/2]

bool DeltaFileWrapper::isPushing;

Public Signals Documentation

signal countChanged

void DeltaFileWrapper::countChanged;

Emitted when the deltas list has changed.


signal errorChanged

void DeltaFileWrapper::errorChanged;

Emmitted when the latest error has changed


signal isPushingChanged

void DeltaFileWrapper::isPushingChanged;

Emmitted when the pushing state has changed.


signal savedToFile

void DeltaFileWrapper::savedToFile;

Emmitted when the deltas have been written to a file


Public Functions Documentation

function DeltaFileWrapper

DeltaFileWrapper::DeltaFileWrapper (
    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 DeltaFileWrapper::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 DeltaFileWrapper::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 DeltaFileWrapper::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 append

bool DeltaFileWrapper::append (
    const DeltaFileWrapper * deltaFileWrapper
) 

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


function apply

Q_INVOKABLE bool DeltaFileWrapper::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 DeltaFileWrapper::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 > DeltaFileWrapper::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 DeltaFileWrapper::count () const

Returns the number of delta elements

Returns:

int number of delta elements


function deltaLayerIds

QStringList DeltaFileWrapper::deltaLayerIds () const

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

Returns:

list of layers ids

Todo

TEST


function deltas

QJsonArray DeltaFileWrapper::deltas () const

Returns the deltas as a JSON array of delta elements

Returns:

QJsonArray deltas JSON array


function errorString [2/2]

QString DeltaFileWrapper::errorString () const

Human readable error description why the class has an error.

Returns:

QString human readable error reason


function errorType [2/2]

ErrorType DeltaFileWrapper::errorType () const

Error type why the class has an error.

Returns:

ErrorType error type


function fileName

QString DeltaFileWrapper::fileName () const

Returns deltas file name.

Returns:

QString file name


function getDeltaIndexByUuid

int DeltaFileWrapper::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 DeltaFileWrapper::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 DeltaFileWrapper::id () const

Returns deltas file id.

Returns:

QString id


function isCreatedFeature

Q_INVOKABLE bool DeltaFileWrapper::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 DeltaFileWrapper::isDeltaBeingApplied () const

Whether or not the current delta file is being applied.

Todo

TEST


function isDirty

bool DeltaFileWrapper::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 DeltaFileWrapper::isPushing () const

Returns TRUE if the pushing state is active.


function projectId

QString DeltaFileWrapper::projectId () const

Returns deltas file project id.

Returns:

QString project id


function reset

Q_INVOKABLE void DeltaFileWrapper::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 DeltaFileWrapper::resetId () 

Assigns a new unique delta file id.


function setIsPushing

void DeltaFileWrapper::setIsPushing (
    bool isPushing
) 

Sets the pushing state.

Parameters:

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

function toFile

Q_INVOKABLE bool DeltaFileWrapper::toFile () 

Writes deltas file to the permanent storage.

Returns:

bool whether write has been successful


function toFileForPush

Q_INVOKABLE QString DeltaFileWrapper::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 DeltaFileWrapper::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 DeltaFileWrapper::toString () const

Returns deltas as JSON string.

Returns:

QString JSON representation


function ~DeltaFileWrapper

DeltaFileWrapper::~DeltaFileWrapper () 

Destroy the Delta File Wrapper object


Public Static Functions Documentation

function attachmentFieldNames

static QStringList DeltaFileWrapper::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 DeltaFileWrapper::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 > DeltaFileWrapper::getLocalPkAttribute (
    const QgsVectorLayer * vl
) 

function getSourceLayerId

static QString DeltaFileWrapper::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 > DeltaFileWrapper::getSourcePkAttribute (
    const QgsVectorLayer * vl
) 

function nameByLayerId

static QString DeltaFileWrapper::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/deltafilewrapper.h