Skip to content

Commit 51d1f82

Browse files
Removed mergin api passing in active project
Implemented code findings
1 parent a26f78f commit 51d1f82

6 files changed

Lines changed: 17 additions & 20 deletions

File tree

app/activeproject.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
#include "activeproject.h"
2323
#include "coreutils.h"
24-
#include "merginapi.h"
2524

2625
#ifdef ANDROID
2726
#include "position/tracking/androidtrackingbroadcast.h"
@@ -33,15 +32,13 @@ const int ActiveProject::LOADING_FLAG_FILE_EXPIRATION_MS = 5000;
3332
ActiveProject::ActiveProject( AppSettings &appSettings
3433
, ActiveLayer &activeLayer
3534
, LocalProjectsManager &localProjectsManager
36-
, MerginApi *merginApi
3735
, QObject *parent ) :
3836

3937
QObject( parent )
4038
, mAppSettings( appSettings )
4139
, mActiveLayer( activeLayer )
4240
, mAuthManager( QgsApplication::authManager() )
4341
, mLocalProjectsManager( localProjectsManager )
44-
, mMerginApi( merginApi )
4542
, mProjectLoadingLog( "" )
4643
{
4744
// we used to have our own QgsProject instance, but unfortunately few pieces of qgis_core
@@ -215,9 +212,9 @@ bool ActiveProject::forceLoad( const QString &filePath, bool force )
215212
emit positionTrackingSupportedChanged();
216213
emit mapSketchesEnabledChanged();
217214

218-
if ( mLocalProject.isValid() && mMerginApi )
215+
if ( mLocalProject.isValid() )
219216
{
220-
mMerginApi->isProjectSyncNeeded( mLocalProject.fullName(), true );
217+
emit projectSyncCheckRequested( mLocalProject.fullName(), true );
221218
}
222219
}
223220

@@ -679,8 +676,8 @@ bool ActiveProject::photoSketchingEnabled() const
679676

680677
void ActiveProject::checkForProjectUpdate()
681678
{
682-
if ( isProjectLoaded() && mMerginApi )
679+
if ( isProjectLoaded() )
683680
{
684-
mMerginApi->isProjectSyncNeeded( projectFullName(), true );
681+
emit projectSyncCheckRequested( projectFullName(), true );
685682
}
686683
}

app/activeproject.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
#include "merginprojectmetadata.h"
2626
#include "synchronizationoptions.h"
2727

28-
class MerginApi;
29-
3028
/**
3129
* \brief The ActiveProject class can load a QGIS project and holds its data.
3230
*/
@@ -49,7 +47,6 @@ class ActiveProject: public QObject
4947
AppSettings &appSettings
5048
, ActiveLayer &activeLayer
5149
, LocalProjectsManager &localProjectsManager
52-
, MerginApi *merginApi
5350
, QObject *parent = nullptr );
5451

5552
virtual ~ActiveProject();
@@ -172,6 +169,8 @@ class ActiveProject: public QObject
172169

173170
void syncActiveProject( const LocalProject &project, SyncOptions::RequestOrigin requestOrigin );
174171

172+
void projectSyncCheckRequested( const QString &projectFullName, bool withAuth );
173+
175174
void mapThemeChanged( const QString &mapTheme );
176175

177176
void positionTrackingSupportedChanged();
@@ -226,7 +225,6 @@ class ActiveProject: public QObject
226225
LocalProject mLocalProject;
227226

228227
AppSettings &mAppSettings;
229-
MerginApi *mMerginApi = nullptr;
230228
ActiveLayer &mActiveLayer;
231229
QgsAuthManager *mAuthManager = nullptr;
232230
LocalProjectsManager &mLocalProjectsManager;

app/main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ int main( int argc, char *argv[] )
532532
NotificationModel notificationModel;
533533

534534
ActiveLayer al;
535-
ActiveProject activeProject( *as, al, localProjectsManager, ma.get() );
535+
ActiveProject activeProject( *as, al, localProjectsManager );
536536
std::unique_ptr<VariablesManager> vm( new VariablesManager( ma.get() ) );
537537
vm->registerInputExpressionFunctions();
538538

@@ -646,6 +646,8 @@ int main( int argc, char *argv[] )
646646
merginApi->reloadProjectRole( activeProject.projectFullName() );
647647
} );
648648

649+
QObject::connect( &activeProject, &ActiveProject::projectSyncCheckRequested, ma.get(), &MerginApi::isProjectSyncNeeded );
650+
649651
QObject::connect( ma.get(), &MerginApi::authChanged, &lambdaContext, [merginApi = ma.get(), &activeProject]()
650652
{
651653
if ( activeProject.isProjectLoaded() )

app/test/testactiveproject.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void TestActiveProject::testProjectValidations()
3838

3939
AppSettings as;
4040
ActiveLayer activeLayer;
41-
ActiveProject activeProject( as, activeLayer, mApi->localProjectsManager(), mApi );
41+
ActiveProject activeProject( as, activeLayer, mApi->localProjectsManager() );
4242

4343
QSignalSpy spyReportIssues( &activeProject, &ActiveProject::reportIssue );
4444
QSignalSpy spyErrorsFound( &activeProject, &ActiveProject::loadingErrorFound );
@@ -63,7 +63,7 @@ void TestActiveProject::testProjectLoadFailure()
6363

6464
AppSettings as;
6565
ActiveLayer activeLayer;
66-
ActiveProject activeProject( as, activeLayer, mApi->localProjectsManager(), mApi );
66+
ActiveProject activeProject( as, activeLayer, mApi->localProjectsManager() );
6767

6868
mApi->localProjectsManager().addLocalProject( projectdir, projectname );
6969

@@ -83,7 +83,7 @@ void TestActiveProject::testPositionTrackingFlag()
8383

8484
AppSettings as;
8585
ActiveLayer activeLayer;
86-
ActiveProject activeProject( as, activeLayer, mApi->localProjectsManager(), mApi );
86+
ActiveProject activeProject( as, activeLayer, mApi->localProjectsManager() );
8787

8888
// project "planes" - tracking not enabled
8989
QString projectDir = TestUtils::testDataDir() + "/planes/";
@@ -123,7 +123,7 @@ void TestActiveProject::testRecordingAllowed()
123123

124124
AppSettings as;
125125
ActiveLayer activeLayer;
126-
ActiveProject activeProject( as, activeLayer, mApi->localProjectsManager(), mApi );
126+
ActiveProject activeProject( as, activeLayer, mApi->localProjectsManager() );
127127

128128
mApi->localProjectsManager().addLocalProject( projectDir, projectFilename );
129129
QVERIFY( activeProject.load( projectDir + "/" + projectFilename ) );
@@ -171,7 +171,7 @@ void TestActiveProject::testLoadingFlagFileExpiration()
171171
{
172172
AppSettings as;
173173
ActiveLayer activeLayer;
174-
ActiveProject activeProject( as, activeLayer, mApi->localProjectsManager(), mApi );
174+
ActiveProject activeProject( as, activeLayer, mApi->localProjectsManager() );
175175

176176
// project "planes" - tracking not enabled
177177
QString projectDir = TestUtils::testDataDir() + "/planes/";
@@ -197,7 +197,7 @@ void TestActiveProject::testLoadingAuthFileFromConfiguration()
197197
{
198198
AppSettings appSettings;
199199
ActiveLayer activeLayer;
200-
ActiveProject activeProject( appSettings, activeLayer, mApi->localProjectsManager(), mApi );
200+
ActiveProject activeProject( appSettings, activeLayer, mApi->localProjectsManager() );
201201
QString projectDir = TestUtils::testDataDir() + QStringLiteral( "/project_auth_file/" );
202202
QString projectName = QStringLiteral( "auth-test.qgz" );
203203
QString authFile = QDir( projectDir ).filePath( CoreUtils::AUTH_CONFIG_FILENAME );

app/test/testmerginapi.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2377,7 +2377,8 @@ void TestMerginApi::testAutosync()
23772377
MapThemesModel mtm;
23782378
AppSettings as;
23792379
ActiveLayer al;
2380-
ActiveProject activeProject( as, al, mApi->localProjectsManager(), mApi );
2380+
ActiveProject activeProject( as, al, mApi->localProjectsManager() );
2381+
QObject::connect( &activeProject, &ActiveProject::projectSyncCheckRequested, mApi, &MerginApi::isProjectSyncNeeded );
23812382

23822383
mApi->localProjectsManager().addLocalProject( projectDir, projectName );
23832384

core/merginapi.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,6 @@ class MerginApi: public QObject
984984
MerginServerType::ServerType mServerType = MerginServerType::ServerType::OLD;
985985
QString mServerDiagnosticLogsUrl = MerginApi::sDefaultReportLogUrl;
986986

987-
988987
QOAuth2AuthorizationCodeFlow mOauth2Flow;
989988
#ifdef MOBILE_OS
990989
QOAuthUriSchemeReplyHandler *mOauth2ReplyHandler = nullptr; // parented by mOauth2Flow

0 commit comments

Comments
 (0)