Skip to content
Open
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
44 changes: 24 additions & 20 deletions app/activeproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include <QDebug>
#include <QStandardPaths>
#include <QTimer>

#include "qgsvectorlayer.h"
#include "qgslayertree.h"
Expand Down Expand Up @@ -91,12 +90,17 @@ QString ActiveProject::projectFullName() const
return mLocalProject.fullName();
}

QString ActiveProject::projectId() const
{
return mLocalProject.id();
}

bool ActiveProject::load( const QString &filePath )
{
return forceLoad( filePath, false );
}

bool ActiveProject::forceLoad( const QString &filePath, bool force )
bool ActiveProject::forceLoad( const QString &filePath, const bool force )
{
CoreUtils::log( QStringLiteral( "Project loading" ), filePath + " " + ( force ? "true" : "false" ) );

Expand Down Expand Up @@ -133,11 +137,11 @@ bool ActiveProject::forceLoad( const QString &filePath, bool force )

mProjectLoadingLog.clear();

QString logFilePath = CoreUtils::logFilename();
const QString logFilePath = CoreUtils::logFilename();
qint64 alreadyAppendedCharsCount = 0;

{
QFile file( logFilePath );
const QFile file( logFilePath );
alreadyAppendedCharsCount = file.size();
}

Expand All @@ -157,13 +161,13 @@ bool ActiveProject::forceLoad( const QString &filePath, bool force )
res = mQgsProject->read( filePath );
if ( !res )
{
QString error = mQgsProject->error();
const QString error = mQgsProject->error();
CoreUtils::log( QStringLiteral( "Project loading" ), QStringLiteral( "Could not read project file: " ) + error );

mLocalProject = LocalProject();
if ( mMapSettings )
{
QList< QgsMapLayer * > layers;
const QList< QgsMapLayer * > layers;
mMapSettings->setLayers( layers );
}
mQgsProject->clear();
Expand All @@ -182,7 +186,7 @@ bool ActiveProject::forceLoad( const QString &filePath, bool force )
CoreUtils::log( QStringLiteral( "Project load" ), QStringLiteral( "Could not find project in local projects: " ) + filePath );
}

QString role = MerginProjectMetadata::fromCachedJson( CoreUtils::getProjectMetadataPath( mLocalProject.projectDir ) ).role;
const QString role = MerginProjectMetadata::fromCachedJson( CoreUtils::getProjectMetadataPath( mLocalProject.projectDir ) ).role;
setProjectRole( role );

updateMapTheme();
Expand All @@ -195,7 +199,7 @@ bool ActiveProject::forceLoad( const QString &filePath, bool force )
emit mapSketchesEnabledChanged();
}

bool foundErrorsInLoadedProject = validateProject();
const bool foundErrorsInLoadedProject = validateProject();

flagFile.remove();
if ( !force )
Expand All @@ -208,7 +212,7 @@ bool ActiveProject::forceLoad( const QString &filePath, bool force )
if ( file.open( QIODevice::ReadOnly ) )
{
file.seek( alreadyAppendedCharsCount );
QByteArray neededLogFileData = file.readAll();
const QByteArray neededLogFileData = file.readAll();
mProjectLoadingLog = QString::fromStdString( neededLogFileData.toStdString() );
file.close();
}
Expand Down Expand Up @@ -266,7 +270,7 @@ bool ActiveProject::validateProject()

// B. Per-Layer validations
QMap<QString, QgsMapLayer *> projectLayers = mQgsProject->mapLayers();
for ( QgsMapLayer *layer : projectLayers )
for ( const QgsMapLayer *layer : projectLayers )
{
// B.1. Layer Validity
if ( !layer->isValid() )
Expand All @@ -290,7 +294,7 @@ bool ActiveProject::validateProject()
return errorsFound;
}

bool ActiveProject::reloadProject( QString projectDir )
bool ActiveProject::reloadProject( const QString &projectDir )
{
if ( mQgsProject->homePath() == projectDir )
{
Expand All @@ -299,7 +303,7 @@ bool ActiveProject::reloadProject( QString projectDir )
if ( mMapSettings )
extent = mMapSettings->extent();

bool result = forceLoad( mQgsProject->fileName(), true );
const bool result = forceLoad( mQgsProject->fileName(), true );

// restore extent
if ( mMapSettings && !extent.isNull() )
Expand All @@ -310,7 +314,7 @@ bool ActiveProject::reloadProject( QString projectDir )
return false;
}

void ActiveProject::setAutosyncEnabled( bool enabled )
void ActiveProject::setAutosyncEnabled( const bool enabled )
{
if ( enabled )
{
Expand Down Expand Up @@ -354,7 +358,7 @@ void ActiveProject::updateMapSettingsLayers() const
{
if ( !mQgsProject || !mMapSettings ) return;

QList<QgsMapLayer *> visibleLayers = getVisibleLayers();
const QList<QgsMapLayer *> visibleLayers = getVisibleLayers();
mMapSettings->setLayers( visibleLayers );
mMapSettings->setTransformContext( mQgsProject->transformContext() );
}
Expand Down Expand Up @@ -387,7 +391,7 @@ void ActiveProject::updateMapTheme()
}

QgsLayerTree *root = mQgsProject->layerTreeRoot();
QgsMapThemeCollection *collection = mQgsProject->mapThemeCollection();
const QgsMapThemeCollection *collection = mQgsProject->mapThemeCollection();

if ( !root || !collection )
{
Expand All @@ -399,7 +403,7 @@ void ActiveProject::updateMapTheme()
QString themeCandidateName;
QStringList mapThemes = collection->mapThemes();

QgsMapThemeCollection::MapThemeRecord themeCandidate = collection->createThemeFromCurrentState( root, &model );
const QgsMapThemeCollection::MapThemeRecord themeCandidate = collection->createThemeFromCurrentState( root, &model );

for ( const QString &themeName : mapThemes )
{
Expand Down Expand Up @@ -449,7 +453,7 @@ void ActiveProject::setMapTheme( const QString &themeName )
updateMapSettingsLayers();
}

void ActiveProject::updateActiveLayer()
void ActiveProject::updateActiveLayer() const
{
QList< QgsMapLayer * > visibleLayers = getVisibleLayers();

Expand Down Expand Up @@ -554,7 +558,7 @@ void ActiveProject::setProjectRole( const QString &role )
}
}

bool ActiveProject::recordingAllowed( QgsMapLayer *layer ) const
bool ActiveProject::recordingAllowed( const QgsMapLayer *layer ) const
{
if ( !layer )
return false;
Expand All @@ -580,7 +584,7 @@ QList<QgsMapLayer *> ActiveProject::getVisibleLayers() const
if ( !mQgsProject )
return QList<QgsMapLayer *>();

QgsLayerTree *root = mQgsProject->layerTreeRoot();
const QgsLayerTree *root = mQgsProject->layerTreeRoot();

if ( !root )
return QList<QgsMapLayer *>();
Expand All @@ -589,7 +593,7 @@ QList<QgsMapLayer *> ActiveProject::getVisibleLayers() const
QList<QgsMapLayer *> visibleLayers;
const QList<QgsLayerTreeLayer *> nodeLayers = root->findLayers();

for ( QgsLayerTreeLayer *nodeLayer : nodeLayers )
for ( const QgsLayerTreeLayer *nodeLayer : nodeLayers )
{
if ( nodeLayer && nodeLayer->isVisible() )
{
Expand Down
21 changes: 9 additions & 12 deletions app/activeproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@

#include "qgsproject.h"

#include "inputconfig.h"
#include "appsettings.h"
#include "activelayer.h"
#include "recordinglayersproxymodel.h"
#include "localprojectsmanager.h"
#include "autosynccontroller.h"
#include "inputmapsettings.h"
#include "merginprojectmetadata.h"

/**
* \brief The ActiveProject class can load a QGIS project and holds its data.
Expand All @@ -47,7 +45,7 @@ class ActiveProject: public QObject
, LocalProjectsManager &localProjectsManager
, QObject *parent = nullptr );

virtual ~ActiveProject();
~ActiveProject() override;

//! Returns active project's QgsProject instance to do QGIS API magic
QgsProject *qgsProject() const;
Expand All @@ -57,17 +55,19 @@ class ActiveProject: public QObject

Q_INVOKABLE QString projectFullName() const;

Q_INVOKABLE QString projectId() const;

/**
* Loads a .qgz/.qgs project file specified by filePath.
* \param filePath Path to project file.
*/
Q_INVOKABLE bool load( const QString &filePath );

/**
* Applies map theme with 'name' to currently loaded QGIS project
* Applies map theme with 'themeName' to currently loaded QGIS project
* Invalidates active layer if it is no longer visible
*/
Q_INVOKABLE void setMapTheme( const QString &name );
Q_INVOKABLE void setMapTheme( const QString &themeName );

/**
* setActiveLayer sets active layer from layer
Expand Down Expand Up @@ -128,7 +128,7 @@ class ActiveProject: public QObject
* Returns if project layer allows recording (has geometry, editable, not position tracking layer, not map
* sketching layer) regardless of visibility
*/
bool recordingAllowed( QgsMapLayer *layer ) const ;
bool recordingAllowed( const QgsMapLayer *layer ) const ;

//! Returns position tracking layer ID if exists
Q_INVOKABLE QString positionTrackingLayerId() const;
Expand Down Expand Up @@ -165,7 +165,7 @@ class ActiveProject: public QObject

void positionTrackingSupportedChanged();

// Emited when the app (UI) should show tracking because there is a running tracking service
// Emitted when the app (UI) should show tracking because there is a running tracking service
void startPositionTracking();

void projectRoleChanged();
Expand All @@ -174,7 +174,7 @@ class ActiveProject: public QObject

public slots:
// Reloads project if current project path matches given path (its the same project)
bool reloadProject( QString projectDir );
bool reloadProject( const QString &projectDir );

void setAutosyncEnabled( bool enabled );

Expand All @@ -196,10 +196,7 @@ class ActiveProject: public QObject
* if not, sets first available layer as active;
* sets nullptr if there are no other available layers
*/
void updateActiveLayer();

//! Reloads layers in 'recoring layers model'
void updateRecordingLayers();
void updateActiveLayer() const;

QgsProject *mQgsProject = nullptr;
LocalProject mLocalProject;
Expand Down
14 changes: 7 additions & 7 deletions app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,20 +586,20 @@ int main( int argc, char *argv[] )

QObject::connect( &activeProject, &ActiveProject::projectReloaded, &lambdaContext, [merginApi = ma.get(), &activeProject]()
{
merginApi->reloadProjectRole( activeProject.projectFullName() );
merginApi->reloadProjectRole( activeProject.projectId() );
} );

QObject::connect( ma.get(), &MerginApi::authChanged, &lambdaContext, [merginApi = ma.get(), &activeProject]()
{
if ( activeProject.isProjectLoaded() )
{
merginApi->reloadProjectRole( activeProject.projectFullName() );
merginApi->reloadProjectRole( activeProject.projectId() );
}
} );

QObject::connect( ma.get(), &MerginApi::projectRoleUpdated, &activeProject, [&activeProject]( const QString & projectFullName, const QString & role )
QObject::connect( ma.get(), &MerginApi::projectRoleUpdated, &activeProject, [&activeProject]( const QString & projectId, const QString & role )
{
if ( projectFullName == activeProject.projectFullName() )
if ( projectId == activeProject.projectId() )
{
activeProject.setProjectRole( role );
}
Expand All @@ -624,11 +624,11 @@ int main( int argc, char *argv[] )
QObject::connect( &pw, &ProjectWizard::projectCreated, &localProjectsManager, &LocalProjectsManager::addLocalProject );
QObject::connect( &activeProject, &ActiveProject::projectReloaded, vm.get(), &VariablesManager::merginProjectChanged );
QObject::connect( &activeProject, &ActiveProject::projectWillBeReloaded, &inputProjUtils, &InputProjUtils::resetHandlers );
QObject::connect( &syncManager, &SynchronizationManager::syncFinished, &activeProject, [&activeProject]( const QString & projectFullName, bool successfully, int version, bool reloadNeeded )
QObject::connect( &syncManager, &SynchronizationManager::syncFinished, &activeProject, [&activeProject]( const QString & projectId, const bool successfully, const int version, const bool reloadNeeded )
{
Q_UNUSED( successfully );
Q_UNUSED( version );
if ( reloadNeeded && activeProject.projectFullName() == projectFullName )
if ( reloadNeeded && activeProject.projectId() == projectId )
{
activeProject.reloadProject( activeProject.qgsProject()->homePath() );
}
Expand Down Expand Up @@ -680,7 +680,7 @@ int main( int argc, char *argv[] )
// and properly close connection after writting changes to gpkg.
qputenv( "OGR_SQLITE_JOURNAL", "DELETE" );


// TODO: rework to singletons instead (check Qt docs why)
// Register to QQmlEngine
engine.rootContext()->setContextProperty( "__notificationModel", &notificationModel );
engine.rootContext()->setContextProperty( "__androidUtils", &androidUtils );
Expand Down
Loading
Loading