Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce auto-push settings coming from the project file #5060

Merged
merged 3 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/core/appinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ double AppInterface::readProjectDoubleEntry( const QString &scope, const QString
return mApp->readProjectDoubleEntry( scope, key, def );
}

bool AppInterface::readProjectBoolEntry( const QString &scope, const QString &key, bool def ) const
{
return mApp->readProjectBoolEntry( scope, key, def );
}

bool AppInterface::print( const QString &layoutName )
{
return mApp->print( layoutName );
Expand Down
1 change: 1 addition & 0 deletions src/core/appinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class AppInterface : public QObject
Q_INVOKABLE QString readProjectEntry( const QString &scope, const QString &key, const QString &def = QString() ) const;
Q_INVOKABLE int readProjectNumEntry( const QString &scope, const QString &key, int def = 0 ) const;
Q_INVOKABLE double readProjectDoubleEntry( const QString &scope, const QString &key, double def = 0.0 ) const;
Q_INVOKABLE bool readProjectBoolEntry( const QString &scope, const QString &key, bool def = false ) const;

Q_INVOKABLE bool print( const QString &layoutName );
Q_INVOKABLE bool printAtlasFeatures( const QString &layoutName, const QList<long long> &featureIds );
Expand Down
45 changes: 44 additions & 1 deletion src/core/qfieldcloudprojectsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,21 @@ void QFieldCloudProjectsModel::setCurrentProjectId( const QString &currentProjec

mCurrentProjectId = currentProjectId;

if ( mCurrentProjectId != QString() )
{
const bool forceAutoPush = mProject->readBoolEntry( QStringLiteral( "qfieldsync" ), QStringLiteral( "forceAutoPush" ), false );
if ( forceAutoPush )
{
projectSetForceAutoPush( mCurrentProjectId, true );
projectSetAutoPushEnabled( mCurrentProjectId, true );
projectSetAutoPushIntervalMins( mCurrentProjectId, mProject->readNumEntry( QStringLiteral( "qfieldsync" ), QStringLiteral( "forceAutoPushIntervalMins" ) ) );
}
else
{
projectSetForceAutoPush( mCurrentProjectId, false );
}
}

emit currentProjectIdChanged();
emit currentProjectDataChanged();
}
Expand Down Expand Up @@ -1948,25 +1963,51 @@ QHash<int, QByteArray> QFieldCloudProjectsModel::roleNames() const
roles[UserRoleRole] = "UserRole";
roles[UserRoleOriginRole] = "UserRoleOrigin";
roles[DeltaListRole] = "DeltaList";
roles[ForceAutoPushRole] = "ForceAutoPush";
roles[AutoPushEnabledRole] = "AutoPushEnabled";
roles[AutoPushIntervalMinsRole] = "AutoPushIntervalMins";

return roles;
}

void QFieldCloudProjectsModel::projectSetForceAutoPush( const QString &projectId, bool force )
{
const QModelIndex projectIndex = findProjectIndex( projectId );

if ( projectIndex.isValid() )
{
CloudProject *project = mProjects[projectIndex.row()];
project->forceAutoPush = force;
emit dataChanged( projectIndex, projectIndex, QVector<int>() << ForceAutoPushRole );
}
}

void QFieldCloudProjectsModel::projectSetAutoPushEnabled( const QString &projectId, bool enabled )
{
const QModelIndex projectIndex = findProjectIndex( projectId );

if ( projectIndex.isValid() )
{
CloudProject *project = mProjects[projectIndex.row()];
project->autoPushEnabled = !project->autoPushEnabled;
project->autoPushEnabled = enabled;
QFieldCloudUtils::setProjectSetting( project->id, QStringLiteral( "autoPushEnabled" ), project->autoPushEnabled );
emit dataChanged( projectIndex, projectIndex, QVector<int>() << AutoPushEnabledRole );
}
}

void QFieldCloudProjectsModel::projectSetAutoPushIntervalMins( const QString &projectId, int minutes )
{
const QModelIndex projectIndex = findProjectIndex( projectId );

if ( projectIndex.isValid() )
{
CloudProject *project = mProjects[projectIndex.row()];
project->autoPushIntervalMins = minutes;
QFieldCloudUtils::setProjectSetting( project->id, QStringLiteral( "autoPushIntervalMins" ), project->autoPushIntervalMins );
emit dataChanged( projectIndex, projectIndex, QVector<int>() << AutoPushIntervalMinsRole );
}
}

void QFieldCloudProjectsModel::reload( const QJsonArray &remoteProjects )
{
beginResetModel();
Expand Down Expand Up @@ -2161,6 +2202,8 @@ QVariant QFieldCloudProjectsModel::data( const QModelIndex &index, int role ) co
return mProjects.at( index.row() )->userRoleOrigin;
case DeltaListRole:
return QVariant::fromValue<DeltaListModel *>( mProjects.at( index.row() )->deltaListModel );
case ForceAutoPushRole:
return mProjects.at( index.row() )->forceAutoPush;
case AutoPushEnabledRole:
return mProjects.at( index.row() )->autoPushEnabled;
case AutoPushIntervalMinsRole:
Expand Down
8 changes: 8 additions & 0 deletions src/core/qfieldcloudprojectsmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class QFieldCloudProjectsModel : public QAbstractListModel
UserRoleRole,
UserRoleOriginRole,
DeltaListRole,
ForceAutoPushRole,
AutoPushEnabledRole,
AutoPushIntervalMinsRole,
};
Expand Down Expand Up @@ -276,9 +277,15 @@ class QFieldCloudProjectsModel : public QAbstractListModel
//! Cancels ongoing cloud project download with \a projectId.
Q_INVOKABLE void projectCancelDownload( const QString &projectId );

//! Forces the cloud project auto-push enabled state to be TRUE
Q_INVOKABLE void projectSetForceAutoPush( const QString &projectId, bool force );

//! Toggles the cloud project auto-push enabled state
Q_INVOKABLE void projectSetAutoPushEnabled( const QString &projectId, bool enabled );

//! Sets the interval in \a minutes between which the project will auto-push changes
Q_INVOKABLE void projectSetAutoPushIntervalMins( const QString &projectId, int minutes );

signals:
void cloudConnectionChanged();
void layerObserverChanged();
Expand Down Expand Up @@ -434,6 +441,7 @@ class QFieldCloudProjectsModel : public QAbstractListModel
QDateTime lastLocalDataLastUpdatedAt;
QDateTime lastRefreshedAt;

bool forceAutoPush = false;
bool autoPushEnabled = false;
int autoPushIntervalMins = 30;

Expand Down
8 changes: 8 additions & 0 deletions src/core/qgismobileapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,14 @@ double QgisMobileapp::readProjectDoubleEntry( const QString &scope, const QStrin
return mProject->readDoubleEntry( scope, key, def );
}

bool QgisMobileapp::readProjectBoolEntry( const QString &scope, const QString &key, bool def ) const
{
if ( !mProject )
return def;

return mProject->readBoolEntry( scope, key, def );
}

bool QgisMobileapp::print( const QString &layoutName )
{
const QList<QgsPrintLayout *> printLayouts = mProject->layoutManager()->printLayouts();
Expand Down
11 changes: 11 additions & 0 deletions src/core/qgismobileapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,17 @@ class QFIELD_CORE_EXPORT QgisMobileapp : public QQmlApplicationEngine
*/
double readProjectDoubleEntry( const QString &scope, const QString &key, double def = 0.0 ) const;

/**
* Reads a boolean from the specified \a scope and \a key from the currently opened project
*
* \param scope entry scope (group) name
* \param key entry key name. Keys are '/'-delimited entries, implying a hierarchy of keys and corresponding values
* \param def default value to return if the specified \a key does not exist within the \a scope
*
* \returns entry value as boolean from \a scope given its \a key
*/
bool readProjectBoolEntry( const QString &scope, const QString &key, bool def = false ) const;
nirvn marked this conversation as resolved.
Show resolved Hide resolved

/**
* Prints a given layout from the currently opened project to a PDF file
* \param layoutName the layout name that will be printed
Expand Down
11 changes: 9 additions & 2 deletions src/qml/QFieldCloudPopup.qml
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,13 @@ Popup {

MouseArea {
anchors.fill: parent
onClicked: cloudProjectsModel.projectSetAutoPushEnabled(cloudProjectsModel.currentProjectId, !autoPush.checked)
onClicked: {
if (!!cloudProjectsModel.currentProjectData.ForceAutoPush) {
displayToast(qsTr('The current project does not allow for auto-push to be turned off'))
} else {
cloudProjectsModel.projectSetAutoPushEnabled(cloudProjectsModel.currentProjectId, !autoPush.checked)
}
}
}
}

Expand All @@ -492,8 +498,9 @@ Popup {
Layout.alignment: Qt.AlignVCenter
width: implicitContentWidth
small: true

enabled: !cloudProjectsModel.currentProjectData.ForceAutoPush
checked: !!cloudProjectsModel.currentProjectData.AutoPushEnabled

onClicked: {
cloudProjectsModel.projectSetAutoPushEnabled(cloudProjectsModel.currentProjectId, checked)
}
Expand Down
2 changes: 1 addition & 1 deletion src/qml/qgismobileapp.qml
Original file line number Diff line number Diff line change
Expand Up @@ -3377,7 +3377,7 @@ ApplicationWindow {

recentProjectListModel.reloadModel()

var cloudProjectId = QFieldCloudUtils.getProjectId(qgisProject.fileName)
const cloudProjectId = QFieldCloudUtils.getProjectId(qgisProject.fileName)
cloudProjectsModel.currentProjectId = cloudProjectId
cloudProjectsModel.refreshProjectModification(cloudProjectId)
if (cloudProjectId !== '') {
Expand Down
Loading