Skip to content

Commit

Permalink
Fix proj search paths are incorrectly set and missing the local profi…
Browse files Browse the repository at this point in the history
…le proj

folder

This is a stupid stupid situation, but because of the mess which is
QGIS application initialization we have to be very careful that nothing
creates a QgsCoordinateReferenceSystem or QgsCoordinateTransform object
between the QgsApplication construction and the call to QgsApplication::init
with the correct profile path.

The QgsApplication constructor creates the members object which contains
singleton-ish things, and this CANNOT POSSIBLY be moved out of the
constructor. And since it's apparently impossible to know the correct profile
path at time of QgsApplication construction, we are left with the only
option of ensuring that NOTHING in the QgsApplication members creates
QgsCoordinateReferenceSystem or QgsCoordinateTransform objects (because if they
do, then the proj search paths can't correctly be set to the actual
profile path -- because until QgsApplication::init is called we don't
know what the profile path is)

Long story short: QgsTaskManager constructor was connecting to the QgsProject
instance, forcing early construction of QgsProject and a QgsCoordinateReferenceSystem
object as a result. F̶i̶x̶ gross hack around this by deferring the connection until
a task is actually created, by which time we e̶x̶p̶e̶c̶t̶ hope that the call to
QgsApplication::init has occurred...

This is all l̶o̶v̶e̶l̶y̶ a pile of s***, and needs to be re-thought for QGIS 4.0
  • Loading branch information
nyalldawson committed Apr 3, 2020
1 parent e8ec44d commit 85b2cf2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/core/qgstaskmanager.cpp
Expand Up @@ -18,6 +18,7 @@
#include "qgstaskmanager.h"
#include "qgsproject.h"
#include "qgsmaplayerlistutils.h"
#include <mutex>
#include <QtConcurrentRun>


Expand Down Expand Up @@ -390,8 +391,7 @@ QgsTaskManager::QgsTaskManager( QObject *parent )
: QObject( parent )
, mTaskMutex( new QMutex( QMutex::Recursive ) )
{
connect( QgsProject::instance(), static_cast < void ( QgsProject::* )( const QList< QgsMapLayer * >& ) > ( &QgsProject::layersWillBeRemoved ),
this, &QgsTaskManager::layersWillBeRemoved );

}

QgsTaskManager::~QgsTaskManager()
Expand Down Expand Up @@ -432,6 +432,15 @@ long QgsTaskManager::addTaskPrivate( QgsTask *task, QgsTaskList dependencies, bo
if ( !task )
return 0;

if ( !mInitialized )
{
mInitialized = true;
// defer connection to project until we actually need it -- we don't want to connect to the project instance in the constructor,
// cos that forces early creation of QgsProject
connect( QgsProject::instance(), static_cast < void ( QgsProject::* )( const QList< QgsMapLayer * >& ) > ( &QgsProject::layersWillBeRemoved ),
this, &QgsTaskManager::layersWillBeRemoved );
}

long taskId = mNextTaskId++;

mTaskMutex->lock();
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgstaskmanager.h
Expand Up @@ -592,6 +592,8 @@ class CORE_EXPORT QgsTaskManager : public QObject
QgsTaskRunnableWrapper *runnable = nullptr;
};

bool mInitialized = false;

mutable QMutex *mTaskMutex;

QMap< long, TaskInfo > mTasks;
Expand Down

0 comments on commit 85b2cf2

Please sign in to comment.