Skip to content

Commit

Permalink
Merge pull request #32559 from troopa81/revert_waitforfinished
Browse files Browse the repository at this point in the history
Fixes #32545 Revert qgstaskmanager waitforfinished fix
  • Loading branch information
m-kuhn committed Nov 3, 2019
2 parents 9ce55db + cddc10a commit b4225d7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 45 deletions.
6 changes: 0 additions & 6 deletions src/core/qgstaskmanager.cpp
Expand Up @@ -29,7 +29,6 @@ QgsTask::QgsTask( const QString &name, Flags flags )
: mFlags( flags )
, mDescription( name )
{
mNotStartedMutex.lock();
}

QgsTask::~QgsTask()
Expand All @@ -42,7 +41,6 @@ QgsTask::~QgsTask()
delete subTask.task;
}
mNotFinishedMutex.unlock();
mNotStartedMutex.unlock();
}

void QgsTask::setDescription( const QString &description )
Expand All @@ -58,7 +56,6 @@ qint64 QgsTask::elapsedTime() const
void QgsTask::start()
{
mNotFinishedMutex.lock();
mNotStartedMutex.unlock();
mStartCount++;
Q_ASSERT( mStartCount == 1 );

Expand Down Expand Up @@ -155,9 +152,6 @@ QList<QgsMapLayer *> QgsTask::dependentLayers() const

bool QgsTask::waitForFinished( int timeout )
{
// We wait the task to be started
mNotStartedMutex.lock();

bool rv = true;
if ( mOverallStatus == Complete || mOverallStatus == Terminated )
{
Expand Down
1 change: 0 additions & 1 deletion src/core/qgstaskmanager.h
Expand Up @@ -310,7 +310,6 @@ class CORE_EXPORT QgsTask : public QObject
* it's used as a trigger for waitForFinished.
*/
QMutex mNotFinishedMutex;
QMutex mNotStartedMutex;

//! Progress of this (parent) task alone
double mProgress = 0.0;
Expand Down
37 changes: 0 additions & 37 deletions tests/src/core/testqgspointlocator.cpp
Expand Up @@ -437,43 +437,6 @@ class TestQgsPointLocator : public QObject
mVL->rollBack();
}

void testWaitForIndexingFinished()
{
QgsPointLocator loc( mVL, QgsCoordinateReferenceSystem(), QgsCoordinateTransformContext(), nullptr );
QgsPointXY pt( 2, 2 );

// locator is not ready yet
QgsPointLocator::Match m = loc.nearestVertex( pt, 999, nullptr, true );
QVERIFY( !m.isValid() );
QVERIFY( loc.mIsIndexing );

// non relaxed call, this will block until the first indexing is finished
// so the match point has to be valid
m = loc.nearestVertex( pt, 999, nullptr );
QVERIFY( m.isValid() );
QVERIFY( !loc.mIsIndexing );

// now locator is ready
m = loc.nearestVertex( pt, 999 );
QVERIFY( m.isValid() );
QVERIFY( m.hasVertex() );
QCOMPARE( m.layer(), mVL );
QCOMPARE( m.featureId(), ( QgsFeatureId )1 );
QCOMPARE( m.point(), QgsPointXY( 1, 1 ) );
QCOMPARE( m.distance(), std::sqrt( 2.0 ) );
QCOMPARE( m.vertexIndex(), 2 );
}

void testDeleteLocator()
{
QgsPointLocator *loc = new QgsPointLocator( mVL, QgsCoordinateReferenceSystem(), QgsCoordinateTransformContext(), nullptr );
QgsPointXY pt( 2, 2 );

// delete locator while we are indexing (could happen when closing project for instance)
loc->nearestVertex( pt, 999, nullptr, true );
delete loc;
}

};

QGSTEST_MAIN( TestQgsPointLocator )
Expand Down
12 changes: 11 additions & 1 deletion tests/src/python/test_qgslayoutlegend.py
Expand Up @@ -396,6 +396,10 @@ def testSymbolExpressions(self):

counterTask = point_layer.countSymbolFeatures()
counterTask.waitForFinished()
TM = QgsApplication.taskManager()
actask = TM.activeTasks()
print(TM.tasks(), actask)
count = actask[0]
legend.model().refreshLayerLegend(legendlayer)
legendnodes = legend.model().layerLegendNodes(legendlayer)
legendnodes[0].setUserLabel('[% @symbol_id %]')
Expand All @@ -404,6 +408,7 @@ def testSymbolExpressions(self):
label1 = legendnodes[0].evaluateLabel()
label2 = legendnodes[1].evaluateLabel()
label3 = legendnodes[2].evaluateLabel()
count.waitForFinished()
self.assertEqual(label1, '0')
#self.assertEqual(label2, '5')
#self.assertEqual(label3, '12')
Expand Down Expand Up @@ -458,7 +463,7 @@ def testSymbolExpressionRender(self):
group = legend.model().rootGroup().addGroup("Group [% 1 + 5 %] [% @layout_name %]")
layer_tree_layer = group.addLayer(point_layer)
counterTask = point_layer.countSymbolFeatures()
counterTask.waitForFinished()
counterTask.waitForFinished() # does this even work?
layer_tree_layer.setCustomProperty("legend/title-label", 'bbbb [% 1+2 %] xx [% @layout_name %] [% @layer_name %]')
QgsMapLayerLegendUtils.setLegendNodeUserLabel(layer_tree_layer, 0, 'xxxx')
legend.model().refreshLayerLegend(layer_tree_layer)
Expand All @@ -470,6 +475,11 @@ def testSymbolExpressionRender(self):
legend.setLinkedMap(map)
legend.updateLegend()
print(layer_tree_layer.labelExpression())
TM = QgsApplication.taskManager()
actask = TM.activeTasks()
print(TM.tasks(), actask)
count = actask[0]
count.waitForFinished()
map.setExtent(QgsRectangle(-102.51, 41.16, -102.36, 41.30))
checker = QgsLayoutChecker(
'composer_legend_symbol_expression', layout)
Expand Down

0 comments on commit b4225d7

Please sign in to comment.