Skip to content

Commit

Permalink
Add the ability to use cloud_username and cloud_email in offline
Browse files Browse the repository at this point in the history
So far the `cloud_username` and `cloud_email` variables were only
available if the user successfully logs in. This PR stores the project's
cloud username and email as project info that can be retrieved even when
offline.
  • Loading branch information
suricactus committed Mar 21, 2024
1 parent 7afa1b9 commit 89d4ca2
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 24 deletions.
29 changes: 29 additions & 0 deletions src/core/projectinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void ProjectInfo::setFilePath( const QString &filePath )
emit filePathChanged();
emit stateModeChanged();
emit activeLayerChanged();
emit cloudUserInformationChanged();
}

QString ProjectInfo::filePath() const
Expand Down Expand Up @@ -293,6 +294,34 @@ void ProjectInfo::setSnappingEnabled( bool enabled )
emit snappingEnabledChanged();
}

CloudUserInformation ProjectInfo::cloudUserInformation() const
{
if ( mFilePath.isEmpty() )
return CloudUserInformation( QString(), QString() );

CloudUserInformation userinfo(
mSettings.value( QStringLiteral( "/qgis/projectInfo/%1/cloudUserInfo/json" ).arg( mFilePath ), QStringLiteral( "{}" ) )
.toJsonValue()
.toObject() );

return userinfo;
}

void ProjectInfo::setCloudUserInformation( const CloudUserInformation cloudUserInformation )
{
if ( mFilePath.isEmpty() )
return;

if ( cloudUserInformation.isEmpty() )
return;

mSettings.beginGroup( QStringLiteral( "/qgis/projectInfo/%1/cloudUserInfo" ).arg( mFilePath ) );
mSettings.setValue( QStringLiteral( "json" ), cloudUserInformation.toJson() );
mSettings.endGroup();

emit cloudUserInformationChanged();
}

void ProjectInfo::saveLayerSnappingConfiguration( QgsMapLayer *layer )
{
if ( mFilePath.isEmpty() )
Expand Down
17 changes: 17 additions & 0 deletions src/core/projectinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define PROJECTINFO_H

#include "layertreemodel.h"
#include "qfieldcloudutils.h"
#include "qgsquickmapcanvasmap.h"
#include "qgsquickmapsettings.h"
#include "trackingmodel.h"
Expand Down Expand Up @@ -73,6 +74,11 @@ class ProjectInfo : public QObject
*/
Q_PROPERTY( bool snappingEnabled READ snappingEnabled WRITE setSnappingEnabled NOTIFY snappingEnabledChanged )

/**
* Set cloud user information for offline usage.
*/
Q_PROPERTY( CloudUserInformation cloudUserInformation READ cloudUserInformation WRITE setCloudUserInformation NOTIFY cloudUserInformationChanged )

public:
explicit ProjectInfo( QObject *parent = nullptr );

Expand Down Expand Up @@ -148,6 +154,16 @@ class ProjectInfo : public QObject
*/
void setSnappingEnabled( bool enabled );

/**
* Returns the saved cloud user infomation for offline usage
*/
CloudUserInformation cloudUserInformation() const;

/**
* Saves the cloud user infomation for offline usage
*/
void setCloudUserInformation( const CloudUserInformation cloudUserInformation );

//! Save an ongoing vector \a layer tracking session details
Q_INVOKABLE void saveTracker( QgsVectorLayer *layer );

Expand All @@ -170,6 +186,7 @@ class ProjectInfo : public QObject
void activeLayerChanged();
void trackingModelChanged();
void snappingEnabledChanged();
void cloudUserInformationChanged();

private slots:

Expand Down
16 changes: 1 addition & 15 deletions src/core/qfieldcloudconnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "networkmanager.h"
#include "networkreply.h"
#include "qfieldcloudutils.h"

#include <QJsonDocument>
#include <QObject>
Expand All @@ -26,21 +27,6 @@

class QNetworkRequest;

struct CloudUserInformation
{
Q_GADGET

public:
CloudUserInformation() = default;

CloudUserInformation( const QString &username, const QString &email )
: username( username )
, email( email )
{}

QString username;
QString email;
};

class QFieldCloudConnection : public QObject
{
Expand Down
1 change: 1 addition & 0 deletions src/core/utils/qfieldcloudutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

static QString sLocalCloudDirectory;


void QFieldCloudUtils::setLocalCloudDirectory( const QString &path )
{
sLocalCloudDirectory = path;
Expand Down
34 changes: 34 additions & 0 deletions src/core/utils/qfieldcloudutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,40 @@ class QFieldCloudProjectsModel;
class DeltaFileWrapperTest;
class TestLayerObserver;

struct CloudUserInformation
{
Q_GADGET

public:
CloudUserInformation() = default;

CloudUserInformation( const QString &username, const QString &email )
{}

explicit CloudUserInformation( const QJsonObject cloudUserInformation )
: username( cloudUserInformation.value( QStringLiteral( "username" ) ).toString() )
, email( cloudUserInformation.value( QStringLiteral( "email" ) ).toString() )
{}

QJsonObject toJson() const
{
QJsonObject cloudUserInformation;

cloudUserInformation.insert( "username", username );
cloudUserInformation.insert( "email", email );

return cloudUserInformation;
}

bool isEmpty() const
{
return username.isEmpty() && email.isEmpty();
}

QString username;
QString email;
};

class QFieldCloudUtils : public QObject
{
Q_OBJECT
Expand Down
2 changes: 1 addition & 1 deletion src/qml/DigitizingToolbar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ VisibilityFadingRow {
positionInformation: positionSource.positionInformation
positionLocked: gnssLockButton.checked
topSnappingResult: coordinateLocator.topSnappingResult
cloudUserInformation: cloudConnection.userInformation
cloudUserInformation: projectInfo.cloudUserInformation
}

QfToolButton {
Expand Down
2 changes: 1 addition & 1 deletion src/qml/EmbeddedFeatureForm.qml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Popup {
positionInformation: coordinateLocator.positionInformation
positionLocked: coordinateLocator.overrideLocation !== undefined
topSnappingResult: coordinateLocator.topSnappingResult
cloudUserInformation: cloudConnection.userInformation
cloudUserInformation: projectInfo.cloudUserInformation
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/qml/FeatureListForm.qml
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ Rectangle {
currentLayer: featureForm.selection.focusedLayer
feature: featureForm.selection.focusedFeature
features: featureForm.selection.model.selectedFeatures
cloudUserInformation: cloudConnection.userInformation
cloudUserInformation: projectInfo.cloudUserInformation
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/qml/OverlayFeatureFormDrawer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Drawer {
positionInformation: coordinateLocator.positionInformation
positionLocked: coordinateLocator.overrideLocation !== undefined
topSnappingResult: coordinateLocator.topSnappingResult
cloudUserInformation: cloudConnection.userInformation
cloudUserInformation: projectInfo.cloudUserInformation
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/qml/TrackerSettings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ Popup {

positionInformation: coordinateLocator.positionInformation
positionLocked: true
cloudUserInformation: cloudConnection.userInformation
cloudUserInformation: projectInfo.cloudUserInformation
}

AttributeFormModel {
Expand Down
2 changes: 1 addition & 1 deletion src/qml/TrackingSession.qml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,6 @@ Item {

positionInformation: coordinateLocator.positionInformation
positionLocked: true
cloudUserInformation: cloudConnection.userInformation
cloudUserInformation: projectInfo.cloudUserInformation
}
}
2 changes: 1 addition & 1 deletion src/qml/geometryeditors/VertexEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ VisibilityFadingRow {
positionInformation: positionSource.positionInformation
positionLocked: gnssLockButton.checked
topSnappingResult: coordinateLocator.topSnappingResult
cloudUserInformation: cloudConnection.userInformation
cloudUserInformation: projectInfo.cloudUserInformation
}

Connections {
Expand Down
5 changes: 3 additions & 2 deletions src/qml/qgismobileapp.qml
Original file line number Diff line number Diff line change
Expand Up @@ -2002,7 +2002,7 @@ ApplicationWindow {
positionInformation: positionSource.positionInformation
topSnappingResult: coordinateLocator.topSnappingResult
positionLocked: positionSource.active && positioningSettings.positioningCoordinateLock
cloudUserInformation: cloudConnection.userInformation
cloudUserInformation: projectInfo.cloudUserInformation
geometry: Geometry {
id: digitizingGeometry
rubberbandModel: digitizingRubberband.model
Expand Down Expand Up @@ -3457,6 +3457,7 @@ ApplicationWindow {
mapSettings: mapCanvas.mapSettings
layerTree: dashBoard.layerTree
trackingModel: trackings.model
cloudUserInformation: cloudConnection.userInformation

property var distanceUnits: Qgis.DistanceUnit.Meters
property var areaUnits: Qgis.AreaUnit.SquareMeters
Expand Down Expand Up @@ -3951,7 +3952,7 @@ ApplicationWindow {
positionInformation: positionSource.positionInformation
positionLocked: positionSource.active && positioningSettings.positioningCoordinateLock
vertexModel: geometryEditingVertexModel
cloudUserInformation: cloudConnection.userInformation
cloudUserInformation: projectInfo.cloudUserInformation
}

VertexModel {
Expand Down

0 comments on commit 89d4ca2

Please sign in to comment.