From 25ed76b86e290df4330654be77aa3013d065aafd Mon Sep 17 00:00:00 2001 From: Martin Dobias Date: Fri, 21 Apr 2017 18:04:09 +0800 Subject: [PATCH] Move labeling engine config to a new class + QgsPalLabeling cleanup Another bit to make core library independent from QgsProject::instance(). Until now labeling engine configuration was taken from project singleton. Removed legacy methods from QgsPalLabeling - the class now does not have any more member variables/methods, it is just a bunch of helper functions. (PR #4384) --- doc/api_break.dox | 9 +- python/core/core.sip | 1 + python/core/qgslabelingenginesettings.sip | 109 ++++++++++++++++++ python/core/qgsmapsettings.sip | 11 ++ python/core/qgspallabeling.sip | 72 ++---------- python/core/qgsproject.sip | 19 +++ python/gui/qgsmapcanvas.sip | 2 + src/app/qgisapp.cpp | 6 + src/app/qgslabelengineconfigdialog.cpp | 36 +++--- src/core/CMakeLists.txt | 2 + src/core/composer/qgscomposermap.cpp | 2 + src/core/dxf/qgsdxfexport.cpp | 1 - src/core/qgslabelingengine.cpp | 81 +++---------- src/core/qgslabelingengine.h | 52 +-------- src/core/qgslabelingenginesettings.cpp | 63 ++++++++++ src/core/qgslabelingenginesettings.h | 80 +++++++++++++ src/core/qgsmaprenderercustompainterjob.cpp | 2 - src/core/qgsmaprendererjob.h | 1 - src/core/qgsmaprendererparalleljob.cpp | 2 - src/core/qgsmapsettings.h | 14 +++ src/core/qgspallabeling.cpp | 96 --------------- src/core/qgspallabeling.h | 58 +--------- src/core/qgsproject.cpp | 22 +++- src/core/qgsproject.h | 21 ++++ src/core/qgsvectorlayerlabelprovider.cpp | 4 +- src/gui/qgsmapcanvas.cpp | 10 ++ src/gui/qgsmapcanvas.h | 12 ++ src/server/qgsserver.cpp | 1 - src/server/qgssldconfigparser.h | 1 + src/server/qgswmsconfigparser.h | 3 +- src/server/qgswmsprojectparser.cpp | 3 +- .../services/wms/qgswmsgetlegendgraphics.cpp | 2 + src/server/services/wms/qgswmsgetmap.cpp | 2 + .../services/wms/qgswmsgetschemaextension.cpp | 2 + src/server/services/wms/qgswmsutils.h | 2 + tests/src/python/test_qgspallabeling_base.py | 25 ++-- .../python/test_qgspallabeling_composer.py | 6 +- .../python/test_qgspallabeling_placement.py | 13 ++- .../src/python/test_qgspallabeling_server.py | 10 -- tests/src/python/test_qgspallabeling_tests.py | 14 +-- 40 files changed, 476 insertions(+), 396 deletions(-) create mode 100644 python/core/qgslabelingenginesettings.sip create mode 100644 src/core/qgslabelingenginesettings.cpp create mode 100644 src/core/qgslabelingenginesettings.h diff --git a/doc/api_break.dox b/doc/api_break.dox index 8c7a7b84ec9..06af182e0e4 100644 --- a/doc/api_break.dox +++ b/doc/api_break.dox @@ -1577,6 +1577,14 @@ QgsPalLabeling {#qgis_api_break_3_0_QgsPalLabeling} -------------- - all methods implemented from QgsLabelingEngineInterface have been removed: init(), willUseLayer(), clearActiveLayers(), clearActiveLayer(), prepareLayer(), prepareDiagramLayer(), registerFeature(), registerDiagramFeature(), drawLabeling(), exit(), clone(). Labeling is now driven by QgsLabelingEngine. +- all methods for global labeling engine configuration have been moved to QgsLabelingEngineSettings: + - searchMethod(), setSearchMethod(), numCandidatePositions(), setNumCandidatePositions() - methods with the same name in QgsLabelingEngineSettings + - isShowingCandidates(), setShowingCandidates() - replaced by DrawCandidates flag + - isShowingAllLabels(), setShowingAllLabels() - replaced by UseAllLabels flag + - isShowingPartialLabels(), setShowingPartialLabels() - replaced by UsePartialCandidates flag + - drawLabelRectOnly(), setDrawLabelRectOnly() - replaced by DrawLabelRectOnly flag + - loadEngineSettings(), saveEngineSettings() - replaced by readSettingsFromProject() and writeSettingsToProject() + - clearEngineSettings() - replaced by clear() that resets the settings instance (rather than immediately writing to project) - init(QgsMapRenderer*) has been removed. Use init(const QgsMapSettings&) instead. - prepareGeometry and geometryRequiresPreparation now take geometry references, not pointers. - layer() was removed. If direct access to QgsPalLayerSettings is necessary, use QgsPalLayerSettings::fromLayer() @@ -1586,7 +1594,6 @@ QgsPalLabeling {#qgis_api_break_3_0_QgsPalLabeling} - labelsWithinRect() was removed. Use takeResults() and methods of QgsLabelingResults instead. - isStoredWithProject() and setStoredWithProject() had no effect and were removed. - staticWillUseLayer(QString) was removed. Use the variant with QgsVectorLayer argument. -- clearEngineSettings() was replaced by QgsLabelingEngine::clearSettingsInProject(). QgsPalLayerSettings {#qgis_api_break_3_0_QgsPalLayerSettings} diff --git a/python/core/core.sip b/python/core/core.sip index 29c1bbafd4d..bb76439d074 100644 --- a/python/core/core.sip +++ b/python/core/core.sip @@ -77,6 +77,7 @@ %Include qgsfieldmodel.sip %Include qgsfieldproxymodel.sip %Include qgsfontutils.sip +%Include qgslabelingenginesettings.sip %Include qgslabelsearchtree.sip %Include qgslegendrenderer.sip %Include qgslegendsettings.sip diff --git a/python/core/qgslabelingenginesettings.sip b/python/core/qgslabelingenginesettings.sip new file mode 100644 index 00000000000..42ecb1501d5 --- /dev/null +++ b/python/core/qgslabelingenginesettings.sip @@ -0,0 +1,109 @@ +/************************************************************************ + * This file has been generated automatically from * + * * + * src/core/qgslabelingenginesettings.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ + + + + +class QgsLabelingEngineSettings +{ +%Docstring + Stores global configuration for labeling engine +.. versionadded:: 3.0 +%End + +%TypeHeaderCode +#include "qgslabelingenginesettings.h" +%End + public: + enum Flag + { + UseAllLabels, + UsePartialCandidates, + RenderOutlineLabels, + DrawLabelRectOnly, + DrawCandidates, + }; + typedef QFlags Flags; + + + enum Search + { + Chain, + Popmusic_Tabu, + Popmusic_Chain, + Popmusic_Tabu_Chain, + Falp + }; + + QgsLabelingEngineSettings(); + + void clear(); +%Docstring +Return the configuration to the defaults +%End + + void setFlags( Flags flags ); +%Docstring +Set flags of the labeling engine +%End + Flags flags() const; +%Docstring +Get flags of the labeling engine + :rtype: Flags +%End + bool testFlag( Flag f ) const; +%Docstring +Test whether a particular flag is enabled + :rtype: bool +%End + void setFlag( Flag f, bool enabled = true ); +%Docstring +Set whether a particual flag is enabled +%End + + void numCandidatePositions( int &candPoint, int &candLine, int &candPolygon ) const; +%Docstring +Get number of candidate positions that will be generated for each label feature (default to 8) +%End + void setNumCandidatePositions( int candPoint, int candLine, int candPolygon ); +%Docstring +Set number of candidate positions that will be generated for each label feature +%End + + void setSearchMethod( Search s ); +%Docstring +Set which search method to use for removal collisions between labels +%End + Search searchMethod() const; +%Docstring +Which search method to use for removal collisions between labels + :rtype: Search +%End + + void readSettingsFromProject( QgsProject *project ); +%Docstring +Read configuration of the labeling engine from a project +%End + void writeSettingsToProject( QgsProject *project ); +%Docstring +Write configuration of the labeling engine to a project +%End + +}; + +QFlags operator|(QgsLabelingEngineSettings::Flag f1, QFlags f2); + + +/************************************************************************ + * This file has been generated automatically from * + * * + * src/core/qgslabelingenginesettings.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ + diff --git a/python/core/qgsmapsettings.sip b/python/core/qgsmapsettings.sip index fd7055442f8..8450b40d0bb 100644 --- a/python/core/qgsmapsettings.sip +++ b/python/core/qgsmapsettings.sip @@ -239,6 +239,17 @@ class QgsMapSettings /** Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation)*/ QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const; + /** + * Sets global configuration of the labeling engine + * \since QGIS 3.0 + */ + void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings ); + + /** + * Returns global configuration of the labeling engine + * \since QGIS 3.0 + */ + const QgsLabelingEngineSettings &labelingEngineSettings() const; protected: diff --git a/python/core/qgspallabeling.sip b/python/core/qgspallabeling.sip index 6fd8e389835..6003fc19d12 100644 --- a/python/core/qgspallabeling.sip +++ b/python/core/qgspallabeling.sip @@ -514,55 +514,9 @@ class QgsPalLabeling public: - QgsPalLabeling(); - ~QgsPalLabeling(); - - void numCandidatePositions( int& candPoint, int& candLine, int& candPolygon ); - void setNumCandidatePositions( int candPoint, int candLine, int candPolygon ); - - enum Search { Chain, Popmusic_Tabu, Popmusic_Chain, Popmusic_Tabu_Chain, Falp }; - - void setSearchMethod( Search s ); - Search searchMethod() const; - - bool isShowingCandidates() const; - void setShowingCandidates( bool showing ); - - bool isShowingAllLabels() const; - void setShowingAllLabels( bool showing ); - - bool isShowingPartialsLabels() const; - void setShowingPartialsLabels( bool showing ); - - //! @note added in 2.4 - bool isDrawingOutlineLabels() const; - void setDrawingOutlineLabels( bool outline ); - - /** Returns whether the engine will only draw the outline rectangles of labels, - * not the label contents themselves. Used for debugging and testing purposes. - * @see setDrawLabelRectOnly - * @note added in QGIS 2.12 - */ - bool drawLabelRectOnly() const; - - /** Sets whether the engine should only draw the outline rectangles of labels, - * not the label contents themselves. Used for debugging and testing purposes. - * @param drawRect set to true to enable rect drawing only - * @see drawLabelRectOnly - * @note added in QGIS 2.12 - */ - void setDrawLabelRectOnly( bool drawRect ); - //! called to find out whether the layer is used for labeling - //! @note added in 2.4 - static bool staticWillUseLayer( QgsVectorLayer* layer ); - - //! @note not available in python bindings - // void drawLabelCandidateRect( pal::LabelPosition* lp, QPainter* painter, const QgsMapToPixel* xform ); - - //! load/save engine settings to project file - void loadEngineSettings(); - void saveEngineSettings(); + //! \since QGIS 2.4 + static bool staticWillUseLayer( QgsVectorLayer *layer ); /** Prepares a geometry for registration with PAL. Handles reprojection, rotation, clipping, etc. * @param geometry geometry to prepare @@ -604,26 +558,24 @@ class QgsPalLabeling protected: // update temporary QgsPalLayerSettings with any data defined text style values - void dataDefinedTextStyle( QgsPalLayerSettings& tmpLyr, - const QMap< QgsPalLayerSettings::Property, QVariant >& ddValues ); + static void dataDefinedTextStyle( QgsPalLayerSettings& tmpLyr, + const QMap< QgsPalLayerSettings::Property, QVariant >& ddValues ); // update temporary QgsPalLayerSettings with any data defined text formatting values - void dataDefinedTextFormatting( QgsPalLayerSettings& tmpLyr, - const QMap< QgsPalLayerSettings::Property, QVariant >& ddValues ); + static void dataDefinedTextFormatting( QgsPalLayerSettings& tmpLyr, + const QMap< QgsPalLayerSettings::Property, QVariant >& ddValues ); // update temporary QgsPalLayerSettings with any data defined text buffer values - void dataDefinedTextBuffer( QgsPalLayerSettings& tmpLyr, - const QMap< QgsPalLayerSettings::Property, QVariant >& ddValues ); + static void dataDefinedTextBuffer( QgsPalLayerSettings& tmpLyr, + const QMap< QgsPalLayerSettings::Property, QVariant >& ddValues ); // update temporary QgsPalLayerSettings with any data defined shape background values - void dataDefinedShapeBackground( QgsPalLayerSettings& tmpLyr, - const QMap< QgsPalLayerSettings::Property, QVariant >& ddValues ); + static void dataDefinedShapeBackground( QgsPalLayerSettings& tmpLyr, + const QMap< QgsPalLayerSettings::Property, QVariant >& ddValues ); // update temporary QgsPalLayerSettings with any data defined drop shadow values - void dataDefinedDropShadow( QgsPalLayerSettings& tmpLyr, - const QMap< QgsPalLayerSettings::Property, QVariant >& ddValues ); - - void deleteTemporaryData(); + static void dataDefinedDropShadow( QgsPalLayerSettings& tmpLyr, + const QMap< QgsPalLayerSettings::Property, QVariant >& ddValues ); /** Checks whether a geometry exceeds the minimum required size for a geometry to be labeled. * @param context render context diff --git a/python/core/qgsproject.sip b/python/core/qgsproject.sip index 33040cea9ec..4df06ffaf06 100644 --- a/python/core/qgsproject.sip +++ b/python/core/qgsproject.sip @@ -409,6 +409,19 @@ class QgsProject : QObject, QgsExpressionContextGenerator void setAvoidIntersectionsLayers( const QList& layers ); QVariantMap customVariables() const; void setCustomVariables( const QVariantMap& customVariables ); + + /** + * Sets project's global labeling engine settings + * \since QGIS 3.0 + */ + void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings ); + + /** + * Returns project's global labeling engine settings + * \since QGIS 3.0 + */ + const QgsLabelingEngineSettings &labelingEngineSettings() const; + int count() const; QgsMapLayer* mapLayer( const QString& layerId ) const; @@ -583,6 +596,12 @@ class QgsProject : QObject, QgsExpressionContextGenerator */ void mapThemeCollectionChanged(); + /** + * Emitted when global configuration of the labeling engine changes. + * \since QGIS 3.0 + */ + void labelingEngineSettingsChanged(); + // // signals from QgsMapLayerRegistry // diff --git a/python/gui/qgsmapcanvas.sip b/python/gui/qgsmapcanvas.sip index 4c7932d1164..b2c7dde386c 100644 --- a/python/gui/qgsmapcanvas.sip +++ b/python/gui/qgsmapcanvas.sip @@ -101,6 +101,8 @@ class QgsMapCanvas : QGraphicsView QList< QgsMapCanvasAnnotationItem *> annotationItems() const; bool annotationsVisible() const; void setAnnotationsVisible( bool visible ); + void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings ); + const QgsLabelingEngineSettings &labelingEngineSettings() const; public slots: diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 0c8dc242b6d..615236b57e8 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -2893,6 +2893,12 @@ void QgisApp::setupConnections() mMapCanvas->setDestinationCrs( QgsProject::instance()->crs() ); } ); + connect( QgsProject::instance(), &QgsProject::labelingEngineSettingsChanged, + this, [ = ] + { + mMapCanvas->setLabelingEngineSettings( QgsProject::instance()->labelingEngineSettings() ); + } ); + // connect legend signals connect( mLayerTreeView, &QgsLayerTreeView::currentLayerChanged, this, &QgisApp::activateDeactivateLayerRelatedActions ); diff --git a/src/app/qgslabelengineconfigdialog.cpp b/src/app/qgslabelengineconfigdialog.cpp index e3096e8a484..aa769153fda 100644 --- a/src/app/qgslabelengineconfigdialog.cpp +++ b/src/app/qgslabelengineconfigdialog.cpp @@ -14,8 +14,7 @@ ***************************************************************************/ #include "qgslabelengineconfigdialog.h" -#include "qgspallabeling.h" -#include "qgslabelingengine.h" +#include "qgslabelingenginesettings.h" #include "qgsproject.h" #include @@ -30,44 +29,41 @@ QgsLabelEngineConfigDialog::QgsLabelEngineConfigDialog( QWidget *parent ) connect( buttonBox->button( QDialogButtonBox::RestoreDefaults ), &QAbstractButton::clicked, this, &QgsLabelEngineConfigDialog::setDefaults ); - QgsLabelingEngine engine; - engine.readSettingsFromProject( QgsProject::instance() ); + QgsLabelingEngineSettings engineSettings = QgsProject::instance()->labelingEngineSettings(); // search method - cboSearchMethod->setCurrentIndex( engine.searchMethod() ); + cboSearchMethod->setCurrentIndex( engineSettings.searchMethod() ); // candidate numbers int candPoint, candLine, candPolygon; - engine.numCandidatePositions( candPoint, candLine, candPolygon ); + engineSettings.numCandidatePositions( candPoint, candLine, candPolygon ); spinCandPoint->setValue( candPoint ); spinCandLine->setValue( candLine ); spinCandPolygon->setValue( candPolygon ); - chkShowCandidates->setChecked( engine.testFlag( QgsLabelingEngine::DrawCandidates ) ); - chkShowAllLabels->setChecked( engine.testFlag( QgsLabelingEngine::UseAllLabels ) ); + chkShowCandidates->setChecked( engineSettings.testFlag( QgsLabelingEngineSettings::DrawCandidates ) ); + chkShowAllLabels->setChecked( engineSettings.testFlag( QgsLabelingEngineSettings::UseAllLabels ) ); - chkShowPartialsLabels->setChecked( engine.testFlag( QgsLabelingEngine::UsePartialCandidates ) ); - mDrawOutlinesChkBox->setChecked( engine.testFlag( QgsLabelingEngine::RenderOutlineLabels ) ); + chkShowPartialsLabels->setChecked( engineSettings.testFlag( QgsLabelingEngineSettings::UsePartialCandidates ) ); + mDrawOutlinesChkBox->setChecked( engineSettings.testFlag( QgsLabelingEngineSettings::RenderOutlineLabels ) ); } void QgsLabelEngineConfigDialog::onOK() { - QgsLabelingEngine engine; + QgsLabelingEngineSettings engineSettings; // save - engine.setSearchMethod( ( QgsPalLabeling::Search ) cboSearchMethod->currentIndex() ); + engineSettings.setSearchMethod( ( QgsLabelingEngineSettings::Search ) cboSearchMethod->currentIndex() ); - engine.setNumCandidatePositions( spinCandPoint->value(), - spinCandLine->value(), - spinCandPolygon->value() ); + engineSettings.setNumCandidatePositions( spinCandPoint->value(), spinCandLine->value(), spinCandPolygon->value() ); - engine.setFlag( QgsLabelingEngine::DrawCandidates, chkShowCandidates->isChecked() ); - engine.setFlag( QgsLabelingEngine::UseAllLabels, chkShowAllLabels->isChecked() ); - engine.setFlag( QgsLabelingEngine::UsePartialCandidates, chkShowPartialsLabels->isChecked() ); - engine.setFlag( QgsLabelingEngine::RenderOutlineLabels, mDrawOutlinesChkBox->isChecked() ); + engineSettings.setFlag( QgsLabelingEngineSettings::DrawCandidates, chkShowCandidates->isChecked() ); + engineSettings.setFlag( QgsLabelingEngineSettings::UseAllLabels, chkShowAllLabels->isChecked() ); + engineSettings.setFlag( QgsLabelingEngineSettings::UsePartialCandidates, chkShowPartialsLabels->isChecked() ); + engineSettings.setFlag( QgsLabelingEngineSettings::RenderOutlineLabels, mDrawOutlinesChkBox->isChecked() ); - engine.writeSettingsToProject( QgsProject::instance() ); + QgsProject::instance()->setLabelingEngineSettings( engineSettings ); accept(); } diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index e16b7f06032..8dda19d1b91 100755 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -155,6 +155,7 @@ SET(QGIS_CORE_SRCS qgsjsonutils.cpp qgslabelfeature.cpp qgslabelingengine.cpp + qgslabelingenginesettings.cpp qgslabelsearchtree.cpp qgslayerdefinition.cpp qgslegendrenderer.cpp @@ -729,6 +730,7 @@ SET(QGIS_CORE_HDRS qgslayerdefinition.h qgslabelfeature.h qgslabelingengine.h + qgslabelingenginesettings.h qgslabelsearchtree.h qgslegendrenderer.h qgslegendsettings.h diff --git a/src/core/composer/qgscomposermap.cpp b/src/core/composer/qgscomposermap.cpp index c844cf91013..5f4243e0f58 100644 --- a/src/core/composer/qgscomposermap.cpp +++ b/src/core/composer/qgscomposermap.cpp @@ -194,6 +194,8 @@ QgsMapSettings QgsComposerMap::mapSettings( const QgsRectangle &extent, QSizeF s jobMapSettings.datumTransformStore().setDestinationCrs( renderCrs ); + jobMapSettings.setLabelingEngineSettings( mComposition->project()->labelingEngineSettings() ); + return jobMapSettings; } diff --git a/src/core/dxf/qgsdxfexport.cpp b/src/core/dxf/qgsdxfexport.cpp index e22d71f9dd8..d639447b8ae 100644 --- a/src/core/dxf/qgsdxfexport.cpp +++ b/src/core/dxf/qgsdxfexport.cpp @@ -966,7 +966,6 @@ void QgsDxfExport::writeEntities() // label engine QgsLabelingEngine engine; - engine.readSettingsFromProject( QgsProject::instance() ); engine.setMapSettings( mMapSettings ); // iterate through the maplayers diff --git a/src/core/qgslabelingengine.cpp b/src/core/qgslabelingengine.cpp index c677cec959d..d80a914e429 100644 --- a/src/core/qgslabelingengine.cpp +++ b/src/core/qgslabelingengine.cpp @@ -17,7 +17,6 @@ #include "qgslabelingengine.h" #include "qgslogger.h" -#include "qgsproject.h" #include "feature.h" #include "labelposition.h" @@ -72,12 +71,7 @@ class QgsLabelSorter QgsLabelingEngine::QgsLabelingEngine() - : mFlags( RenderOutlineLabels | UsePartialCandidates ) - , mSearchMethod( QgsPalLabeling::Chain ) - , mCandPoint( 16 ) - , mCandLine( 50 ) - , mCandPolygon( 30 ) - , mResults( new QgsLabelingResults ) + : mResults( new QgsLabelingResults ) {} QgsLabelingEngine::~QgsLabelingEngine() @@ -192,36 +186,39 @@ void QgsLabelingEngine::processProvider( QgsAbstractLabelProvider *provider, Qgs void QgsLabelingEngine::run( QgsRenderContext &context ) { - pal::Pal p; + const QgsLabelingEngineSettings &settings = mMapSettings.labelingEngineSettings(); + pal::Pal p; pal::SearchMethod s; - switch ( mSearchMethod ) + switch ( settings.searchMethod() ) { default: - case QgsPalLabeling::Chain: + case QgsLabelingEngineSettings::Chain: s = pal::CHAIN; break; - case QgsPalLabeling::Popmusic_Tabu: + case QgsLabelingEngineSettings::Popmusic_Tabu: s = pal::POPMUSIC_TABU; break; - case QgsPalLabeling::Popmusic_Chain: + case QgsLabelingEngineSettings::Popmusic_Chain: s = pal::POPMUSIC_CHAIN; break; - case QgsPalLabeling::Popmusic_Tabu_Chain: + case QgsLabelingEngineSettings::Popmusic_Tabu_Chain: s = pal::POPMUSIC_TABU_CHAIN; break; - case QgsPalLabeling::Falp: + case QgsLabelingEngineSettings::Falp: s = pal::FALP; break; } p.setSearch( s ); // set number of candidates generated per feature - p.setPointP( mCandPoint ); - p.setLineP( mCandLine ); - p.setPolyP( mCandPolygon ); + int candPoint, candLine, candPolygon; + settings.numCandidatePositions( candPoint, candLine, candPolygon ); + p.setPointP( candPoint ); + p.setLineP( candLine ); + p.setPolyP( candPolygon ); - p.setShowPartial( mFlags.testFlag( UsePartialCandidates ) ); + p.setShowPartial( settings.testFlag( QgsLabelingEngineSettings::UsePartialCandidates ) ); // for each provider: get labels and register them in PAL @@ -295,7 +292,7 @@ void QgsLabelingEngine::run( QgsRenderContext &context ) // this is done before actual solution of the problem // before number of candidates gets reduced // TODO mCandidates.clear(); - if ( mFlags.testFlag( DrawCandidates ) && problem ) + if ( settings.testFlag( QgsLabelingEngineSettings::DrawCandidates ) && problem ) { painter->setBrush( Qt::NoBrush ); for ( int i = 0; i < problem->getNumFeatures(); i++ ) @@ -310,7 +307,7 @@ void QgsLabelingEngine::run( QgsRenderContext &context ) } // find the solution - labels = p.solveProblem( problem, mFlags.testFlag( UseAllLabels ) ); + labels = p.solveProblem( problem, settings.testFlag( QgsLabelingEngineSettings::UseAllLabels ) ); QgsDebugMsgLevel( QString( "LABELING work: %1 ms ... labels# %2" ).arg( t.elapsed() ).arg( labels->size() ), 4 ); t.restart(); @@ -359,50 +356,6 @@ QgsLabelingResults *QgsLabelingEngine::takeResults() } -void QgsLabelingEngine::readSettingsFromProject( QgsProject *prj ) -{ - bool saved = false; - mSearchMethod = static_cast< QgsPalLabeling::Search >( prj->readNumEntry( QStringLiteral( "PAL" ), QStringLiteral( "/SearchMethod" ), static_cast< int >( QgsPalLabeling::Chain ), &saved ) ); - mCandPoint = prj->readNumEntry( QStringLiteral( "PAL" ), QStringLiteral( "/CandidatesPoint" ), 16, &saved ); - mCandLine = prj->readNumEntry( QStringLiteral( "PAL" ), QStringLiteral( "/CandidatesLine" ), 50, &saved ); - mCandPolygon = prj->readNumEntry( QStringLiteral( "PAL" ), QStringLiteral( "/CandidatesPolygon" ), 30, &saved ); - - mFlags = 0; - if ( prj->readBoolEntry( QStringLiteral( "PAL" ), QStringLiteral( "/ShowingCandidates" ), false, &saved ) ) mFlags |= DrawCandidates; - if ( prj->readBoolEntry( QStringLiteral( "PAL" ), QStringLiteral( "/DrawRectOnly" ), false, &saved ) ) mFlags |= DrawLabelRectOnly; - if ( prj->readBoolEntry( QStringLiteral( "PAL" ), QStringLiteral( "/ShowingAllLabels" ), false, &saved ) ) mFlags |= UseAllLabels; - if ( prj->readBoolEntry( QStringLiteral( "PAL" ), QStringLiteral( "/ShowingPartialsLabels" ), true, &saved ) ) mFlags |= UsePartialCandidates; - if ( prj->readBoolEntry( QStringLiteral( "PAL" ), QStringLiteral( "/DrawOutlineLabels" ), true, &saved ) ) mFlags |= RenderOutlineLabels; -} - -void QgsLabelingEngine::writeSettingsToProject( QgsProject *project ) -{ - project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/SearchMethod" ), static_cast< int >( mSearchMethod ) ); - project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/CandidatesPoint" ), mCandPoint ); - project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/CandidatesLine" ), mCandLine ); - project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/CandidatesPolygon" ), mCandPolygon ); - - project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/ShowingCandidates" ), mFlags.testFlag( DrawCandidates ) ); - project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/DrawRectOnly" ), mFlags.testFlag( DrawLabelRectOnly ) ); - project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/ShowingAllLabels" ), mFlags.testFlag( UseAllLabels ) ); - project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/ShowingPartialsLabels" ), mFlags.testFlag( UsePartialCandidates ) ); - project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/DrawOutlineLabels" ), mFlags.testFlag( RenderOutlineLabels ) ); -} - -void QgsLabelingEngine::clearSettingsInProject( QgsProject *project ) -{ - project->removeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/SearchMethod" ) ); - project->removeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/CandidatesPoint" ) ); - project->removeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/CandidatesLine" ) ); - project->removeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/CandidatesPolygon" ) ); - project->removeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/ShowingCandidates" ) ); - project->removeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/ShowingAllLabels" ) ); - project->removeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/ShowingPartialsLabels" ) ); - project->removeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/DrawOutlineLabels" ) ); -} - - - //// QgsAbstractLabelProvider *QgsLabelFeature::provider() const diff --git a/src/core/qgslabelingengine.h b/src/core/qgslabelingengine.h index 227a72164b5..5ac17b678cf 100644 --- a/src/core/qgslabelingengine.h +++ b/src/core/qgslabelingengine.h @@ -20,8 +20,7 @@ #include "qgsmapsettings.h" #include "qgspallabeling.h" - -#include +#include "qgslabelingenginesettings.h" class QgsLabelingEngine; @@ -130,7 +129,6 @@ class CORE_EXPORT QgsAbstractLabelProvider Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAbstractLabelProvider::Flags ) - /** \ingroup core * \brief The QgsLabelingEngine class provides map labeling functionality. * The input for the engine is a list of label provider objects and map settings. @@ -176,21 +174,14 @@ class CORE_EXPORT QgsLabelingEngine //! QgsLabelingEngine cannot be copied. QgsLabelingEngine &operator=( const QgsLabelingEngine &rh ) = delete; - enum Flag - { - UseAllLabels = 1 << 1, //!< Whether to draw all labels even if there would be collisions - UsePartialCandidates = 1 << 2, //!< Whether to use also label candidates that are partially outside of the map view - RenderOutlineLabels = 1 << 3, //!< Whether to render labels as text or outlines - DrawLabelRectOnly = 1 << 4, //!< Whether to only draw the label rect and not the actual label text (used for unit tests) - DrawCandidates = 1 << 5, //!< Whether to draw rectangles of generated candidates (good for debugging) - }; - Q_DECLARE_FLAGS( Flags, Flag ) - //! Associate map settings instance void setMapSettings( const QgsMapSettings &mapSettings ) { mMapSettings = mapSettings; } //! Get associated map settings const QgsMapSettings &mapSettings() const { return mMapSettings; } + //! Get associated labeling engine settings + const QgsLabelingEngineSettings &engineSettings() const { return mMapSettings.labelingEngineSettings(); } + /** * Returns a list of layers with providers in the engine. * \since QGIS 3.0 @@ -212,55 +203,22 @@ class CORE_EXPORT QgsLabelingEngine //! For internal use by the providers QgsLabelingResults *results() const { return mResults.get(); } - //! Set flags of the labeling engine - void setFlags( Flags flags ) { mFlags = flags; } - //! Get flags of the labeling engine - Flags flags() const { return mFlags; } - //! Test whether a particular flag is enabled - bool testFlag( Flag f ) const { return mFlags.testFlag( f ); } - //! Set whether a particual flag is enabled - void setFlag( Flag f, bool enabled = true ) { if ( enabled ) mFlags |= f; else mFlags &= ~f; } - - //! Get number of candidate positions that will be generated for each label feature (default to 8) - void numCandidatePositions( int &candPoint, int &candLine, int &candPolygon ) { candPoint = mCandPoint; candLine = mCandLine; candPolygon = mCandPolygon; } - //! Set number of candidate positions that will be generated for each label feature - void setNumCandidatePositions( int candPoint, int candLine, int candPolygon ) { mCandPoint = candPoint; mCandLine = candLine; mCandPolygon = candPolygon; } - - //! Set which search method to use for removal collisions between labels - void setSearchMethod( QgsPalLabeling::Search s ) { mSearchMethod = s; } - //! Which search method to use for removal collisions between labels - QgsPalLabeling::Search searchMethod() const { return mSearchMethod; } - - //! Read configuration of the labeling engine from a project - void readSettingsFromProject( QgsProject *project ); - //! Write configuration of the labeling engine to a project - void writeSettingsToProject( QgsProject *project ); - //! Clear configuration of the labeling engine in a project - static void clearSettingsInProject( QgsProject *project ); - protected: void processProvider( QgsAbstractLabelProvider *provider, QgsRenderContext &context, pal::Pal &p ); //#spellok protected: //! Associated map settings instance QgsMapSettings mMapSettings; + //! List of providers (the are owned by the labeling engine) QList mProviders; QList mSubProviders; - //! Flags - Flags mFlags; - //! search method to use for removal collisions between labels - QgsPalLabeling::Search mSearchMethod; - //! Number of candedate positions that will be generated for features - int mCandPoint, mCandLine, mCandPolygon; //! Resulting labeling layout std::unique_ptr< QgsLabelingResults > mResults; }; -Q_DECLARE_OPERATORS_FOR_FLAGS( QgsLabelingEngine::Flags ) - /** \ingroup core * \class QgsLabelingUtils diff --git a/src/core/qgslabelingenginesettings.cpp b/src/core/qgslabelingenginesettings.cpp new file mode 100644 index 00000000000..eeedba2ed99 --- /dev/null +++ b/src/core/qgslabelingenginesettings.cpp @@ -0,0 +1,63 @@ +/*************************************************************************** + qgslabelingenginesettings.cpp + -------------------------------------- + Date : April 2017 + Copyright : (C) 2017 by Martin Dobias + Email : wonder dot sk at gmail dot com + *************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "qgslabelingenginesettings.h" + +#include "qgsproject.h" + + +QgsLabelingEngineSettings::QgsLabelingEngineSettings() + : mFlags( RenderOutlineLabels | UsePartialCandidates ) + , mSearchMethod( Chain ) + , mCandPoint( 16 ) + , mCandLine( 50 ) + , mCandPolygon( 30 ) +{ +} + +void QgsLabelingEngineSettings::clear() +{ + *this = QgsLabelingEngineSettings(); +} + +void QgsLabelingEngineSettings::readSettingsFromProject( QgsProject *prj ) +{ + bool saved = false; + mSearchMethod = static_cast< Search >( prj->readNumEntry( QStringLiteral( "PAL" ), QStringLiteral( "/SearchMethod" ), static_cast< int >( Chain ), &saved ) ); + mCandPoint = prj->readNumEntry( QStringLiteral( "PAL" ), QStringLiteral( "/CandidatesPoint" ), 16, &saved ); + mCandLine = prj->readNumEntry( QStringLiteral( "PAL" ), QStringLiteral( "/CandidatesLine" ), 50, &saved ); + mCandPolygon = prj->readNumEntry( QStringLiteral( "PAL" ), QStringLiteral( "/CandidatesPolygon" ), 30, &saved ); + + mFlags = 0; + if ( prj->readBoolEntry( QStringLiteral( "PAL" ), QStringLiteral( "/ShowingCandidates" ), false, &saved ) ) mFlags |= DrawCandidates; + if ( prj->readBoolEntry( QStringLiteral( "PAL" ), QStringLiteral( "/DrawRectOnly" ), false, &saved ) ) mFlags |= DrawLabelRectOnly; + if ( prj->readBoolEntry( QStringLiteral( "PAL" ), QStringLiteral( "/ShowingAllLabels" ), false, &saved ) ) mFlags |= UseAllLabels; + if ( prj->readBoolEntry( QStringLiteral( "PAL" ), QStringLiteral( "/ShowingPartialsLabels" ), true, &saved ) ) mFlags |= UsePartialCandidates; + if ( prj->readBoolEntry( QStringLiteral( "PAL" ), QStringLiteral( "/DrawOutlineLabels" ), true, &saved ) ) mFlags |= RenderOutlineLabels; +} + +void QgsLabelingEngineSettings::writeSettingsToProject( QgsProject *project ) +{ + project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/SearchMethod" ), static_cast< int >( mSearchMethod ) ); + project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/CandidatesPoint" ), mCandPoint ); + project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/CandidatesLine" ), mCandLine ); + project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/CandidatesPolygon" ), mCandPolygon ); + + project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/ShowingCandidates" ), mFlags.testFlag( DrawCandidates ) ); + project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/DrawRectOnly" ), mFlags.testFlag( DrawLabelRectOnly ) ); + project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/ShowingAllLabels" ), mFlags.testFlag( UseAllLabels ) ); + project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/ShowingPartialsLabels" ), mFlags.testFlag( UsePartialCandidates ) ); + project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/DrawOutlineLabels" ), mFlags.testFlag( RenderOutlineLabels ) ); +} diff --git a/src/core/qgslabelingenginesettings.h b/src/core/qgslabelingenginesettings.h new file mode 100644 index 00000000000..47df91c71f3 --- /dev/null +++ b/src/core/qgslabelingenginesettings.h @@ -0,0 +1,80 @@ +#ifndef QGSLABELINGENGINESETTINGS_H +#define QGSLABELINGENGINESETTINGS_H + +#include "qgis_core.h" + +#include + +class QgsProject; + +/** \ingroup core + * Stores global configuration for labeling engine + * \since QGIS 3.0 + */ +class CORE_EXPORT QgsLabelingEngineSettings +{ + public: + //! Various flags that affect drawing and placement of labels + enum Flag + { + UseAllLabels = 1 << 1, //!< Whether to draw all labels even if there would be collisions + UsePartialCandidates = 1 << 2, //!< Whether to use also label candidates that are partially outside of the map view + RenderOutlineLabels = 1 << 3, //!< Whether to render labels as text or outlines + DrawLabelRectOnly = 1 << 4, //!< Whether to only draw the label rect and not the actual label text (used for unit tests) + DrawCandidates = 1 << 5, //!< Whether to draw rectangles of generated candidates (good for debugging) + }; + Q_DECLARE_FLAGS( Flags, Flag ) + + //! Search methods in the PAL library to remove colliding labels + //! (methods have different processing speed and number of labels placed) + enum Search + { + Chain, + Popmusic_Tabu, + Popmusic_Chain, + Popmusic_Tabu_Chain, + Falp + }; + + QgsLabelingEngineSettings(); + + //! Return the configuration to the defaults + void clear(); + + //! Set flags of the labeling engine + void setFlags( Flags flags ) { mFlags = flags; } + //! Get flags of the labeling engine + Flags flags() const { return mFlags; } + //! Test whether a particular flag is enabled + bool testFlag( Flag f ) const { return mFlags.testFlag( f ); } + //! Set whether a particual flag is enabled + void setFlag( Flag f, bool enabled = true ) { if ( enabled ) mFlags |= f; else mFlags &= ~f; } + + //! Get number of candidate positions that will be generated for each label feature (default to 8) + void numCandidatePositions( int &candPoint, int &candLine, int &candPolygon ) const { candPoint = mCandPoint; candLine = mCandLine; candPolygon = mCandPolygon; } + //! Set number of candidate positions that will be generated for each label feature + void setNumCandidatePositions( int candPoint, int candLine, int candPolygon ) { mCandPoint = candPoint; mCandLine = candLine; mCandPolygon = candPolygon; } + + //! Set which search method to use for removal collisions between labels + void setSearchMethod( Search s ) { mSearchMethod = s; } + //! Which search method to use for removal collisions between labels + Search searchMethod() const { return mSearchMethod; } + + //! Read configuration of the labeling engine from a project + void readSettingsFromProject( QgsProject *project ); + //! Write configuration of the labeling engine to a project + void writeSettingsToProject( QgsProject *project ); + + private: + //! Flags + Flags mFlags; + //! search method to use for removal collisions between labels + Search mSearchMethod; + //! Number of candedate positions that will be generated for features + int mCandPoint, mCandLine, mCandPolygon; + +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS( QgsLabelingEngineSettings::Flags ) + +#endif // QGSLABELINGENGINESETTINGS_H diff --git a/src/core/qgsmaprenderercustompainterjob.cpp b/src/core/qgsmaprenderercustompainterjob.cpp index 83aed3789f8..7407d53d1de 100644 --- a/src/core/qgsmaprenderercustompainterjob.cpp +++ b/src/core/qgsmaprenderercustompainterjob.cpp @@ -20,7 +20,6 @@ #include "qgslogger.h" #include "qgsproject.h" #include "qgsmaplayerrenderer.h" -#include "qgspallabeling.h" #include "qgsvectorlayer.h" #include "qgsrenderer.h" #include "qgsmaplayerlistutils.h" @@ -74,7 +73,6 @@ void QgsMapRendererCustomPainterJob::start() if ( mSettings.testFlag( QgsMapSettings::DrawLabeling ) ) { mLabelingEngineV2.reset( new QgsLabelingEngine() ); - mLabelingEngineV2->readSettingsFromProject( QgsProject::instance() ); mLabelingEngineV2->setMapSettings( mSettings ); } diff --git a/src/core/qgsmaprendererjob.h b/src/core/qgsmaprendererjob.h index 61140093850..fa3db0f1e0b 100644 --- a/src/core/qgsmaprendererjob.h +++ b/src/core/qgsmaprendererjob.h @@ -34,7 +34,6 @@ class QgsLabelingEngine; class QgsLabelingResults; class QgsMapLayerRenderer; class QgsMapRendererCache; -class QgsPalLabeling; class QgsFeatureFilterProvider; /// @cond PRIVATE diff --git a/src/core/qgsmaprendererparalleljob.cpp b/src/core/qgsmaprendererparalleljob.cpp index cab41ddbb80..820d22f9f80 100644 --- a/src/core/qgsmaprendererparalleljob.cpp +++ b/src/core/qgsmaprendererparalleljob.cpp @@ -19,7 +19,6 @@ #include "qgslabelingengine.h" #include "qgslogger.h" #include "qgsmaplayerrenderer.h" -#include "qgspallabeling.h" #include "qgsproject.h" #include "qgsmaplayer.h" #include "qgsmaplayerlistutils.h" @@ -54,7 +53,6 @@ void QgsMapRendererParallelJob::start() if ( mSettings.testFlag( QgsMapSettings::DrawLabeling ) ) { mLabelingEngineV2.reset( new QgsLabelingEngine() ); - mLabelingEngineV2->readSettingsFromProject( QgsProject::instance() ); mLabelingEngineV2->setMapSettings( mSettings ); } diff --git a/src/core/qgsmapsettings.h b/src/core/qgsmapsettings.h index e7ec1b9fd46..14f83537944 100644 --- a/src/core/qgsmapsettings.h +++ b/src/core/qgsmapsettings.h @@ -26,6 +26,7 @@ #include "qgsabstractgeometry.h" #include "qgscoordinatereferencesystem.h" #include "qgsdatumtransformstore.h" +#include "qgslabelingenginesettings.h" #include "qgsmaptopixel.h" #include "qgsrectangle.h" #include "qgsscalecalculator.h" @@ -291,6 +292,18 @@ class CORE_EXPORT QgsMapSettings //! Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation) QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const { return mSegmentationToleranceType; } + /** + * Sets global configuration of the labeling engine + * \since QGIS 3.0 + */ + void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings ) { mLabelingEngineSettings = settings; } + + /** + * Returns global configuration of the labeling engine + * \since QGIS 3.0 + */ + const QgsLabelingEngineSettings &labelingEngineSettings() const { return mLabelingEngineSettings; } + protected: double mDpi; @@ -321,6 +334,7 @@ class CORE_EXPORT QgsMapSettings double mSegmentationTolerance; QgsAbstractGeometry::SegmentationToleranceType mSegmentationToleranceType; + QgsLabelingEngineSettings mLabelingEngineSettings; // derived properties bool mValid; //!< Whether the actual settings are valid (set in updateDerived()) diff --git a/src/core/qgspallabeling.cpp b/src/core/qgspallabeling.cpp index e6d4b7b641b..6772ade7b9b 100644 --- a/src/core/qgspallabeling.cpp +++ b/src/core/qgspallabeling.cpp @@ -2761,16 +2761,6 @@ void QgsPalLayerSettings::parseDropShadow( QgsRenderContext &context ) // ------------- -QgsPalLabeling::QgsPalLabeling() - : mEngine( new QgsLabelingEngine() ) -{ -} - -QgsPalLabeling::~QgsPalLabeling() -{ - delete mEngine; - mEngine = nullptr; -} bool QgsPalLabeling::staticWillUseLayer( QgsVectorLayer *layer ) { @@ -3375,80 +3365,6 @@ void QgsPalLabeling::dataDefinedDropShadow( QgsPalLayerSettings &tmpLyr, } -void QgsPalLabeling::deleteTemporaryData() -{ -} - -void QgsPalLabeling::numCandidatePositions( int &candPoint, int &candLine, int &candPolygon ) -{ - mEngine->numCandidatePositions( candPoint, candLine, candPolygon ); -} - -void QgsPalLabeling::setNumCandidatePositions( int candPoint, int candLine, int candPolygon ) -{ - mEngine->setNumCandidatePositions( candPoint, candLine, candPolygon ); -} - -void QgsPalLabeling::setSearchMethod( QgsPalLabeling::Search s ) -{ - mEngine->setSearchMethod( s ); -} - -QgsPalLabeling::Search QgsPalLabeling::searchMethod() const -{ - return mEngine->searchMethod(); -} - -bool QgsPalLabeling::isShowingCandidates() const -{ - return mEngine->testFlag( QgsLabelingEngine::DrawCandidates ); -} - -void QgsPalLabeling::setShowingCandidates( bool showing ) -{ - mEngine->setFlag( QgsLabelingEngine::DrawCandidates, showing ); -} - -bool QgsPalLabeling::isShowingAllLabels() const -{ - return mEngine->testFlag( QgsLabelingEngine::UseAllLabels ); -} - -void QgsPalLabeling::setShowingAllLabels( bool showing ) -{ - mEngine->setFlag( QgsLabelingEngine::UseAllLabels, showing ); -} - -bool QgsPalLabeling::isShowingPartialsLabels() const -{ - return mEngine->testFlag( QgsLabelingEngine::UsePartialCandidates ); -} - -void QgsPalLabeling::setShowingPartialsLabels( bool showing ) -{ - mEngine->setFlag( QgsLabelingEngine::UsePartialCandidates, showing ); -} - -bool QgsPalLabeling::isDrawingOutlineLabels() const -{ - return mEngine->testFlag( QgsLabelingEngine::RenderOutlineLabels ); -} - -void QgsPalLabeling::setDrawingOutlineLabels( bool outline ) -{ - mEngine->setFlag( QgsLabelingEngine::RenderOutlineLabels, outline ); -} - -bool QgsPalLabeling::drawLabelRectOnly() const -{ - return mEngine->testFlag( QgsLabelingEngine::DrawLabelRectOnly ); -} - -void QgsPalLabeling::setDrawLabelRectOnly( bool drawRect ) -{ - mEngine->setFlag( QgsLabelingEngine::DrawLabelRectOnly, drawRect ); -} - void QgsPalLabeling::drawLabelCandidateRect( pal::LabelPosition *lp, QPainter *painter, const QgsMapToPixel *xform, QList *candidates ) { QgsPoint outPt = xform->transform( lp->getX(), lp->getY() ); @@ -3508,18 +3424,6 @@ void QgsPalLabeling::drawLabelCandidateRect( pal::LabelPosition *lp, QPainter *p drawLabelCandidateRect( lp->getNextPart(), painter, xform, candidates ); } -// TODO: remove once not used in labeling tests -void QgsPalLabeling::loadEngineSettings() -{ - mEngine->readSettingsFromProject( QgsProject::instance() ); -} - -// TODO: remove once not used in labeling tests -void QgsPalLabeling::saveEngineSettings() -{ - mEngine->writeSettingsToProject( QgsProject::instance() ); -} - QgsLabelingResults::QgsLabelingResults() { mLabelSearchTree = new QgsLabelSearchTree(); diff --git a/src/core/qgspallabeling.h b/src/core/qgspallabeling.h index 224fc98596a..f94e8bf8492 100644 --- a/src/core/qgspallabeling.h +++ b/src/core/qgspallabeling.h @@ -34,6 +34,7 @@ #include "qgsfeature.h" #include "qgsgeometry.h" #include "qgsfields.h" +#include "qgslabelingenginesettings.h" #include "qgspoint.h" #include "qgsmapunitscale.h" #include "qgsstringutils.h" @@ -705,45 +706,6 @@ class CORE_EXPORT QgsPalLabeling { public: - QgsPalLabeling(); - ~QgsPalLabeling(); - - void numCandidatePositions( int &candPoint, int &candLine, int &candPolygon ); - void setNumCandidatePositions( int candPoint, int candLine, int candPolygon ); - - enum Search { Chain, Popmusic_Tabu, Popmusic_Chain, Popmusic_Tabu_Chain, Falp }; - - void setSearchMethod( Search s ); - Search searchMethod() const; - - bool isShowingCandidates() const; - void setShowingCandidates( bool showing ); - - bool isShowingAllLabels() const; - void setShowingAllLabels( bool showing ); - - bool isShowingPartialsLabels() const; - void setShowingPartialsLabels( bool showing ); - - //! \since QGIS 2.4 - bool isDrawingOutlineLabels() const; - void setDrawingOutlineLabels( bool outline ); - - /** Returns whether the engine will only draw the outline rectangles of labels, - * not the label contents themselves. Used for debugging and testing purposes. - * \see setDrawLabelRectOnly - * \since QGIS 2.12 - */ - bool drawLabelRectOnly() const; - - /** Sets whether the engine should only draw the outline rectangles of labels, - * not the label contents themselves. Used for debugging and testing purposes. - * \param drawRect set to true to enable rect drawing only - * \see drawLabelRectOnly - * \since QGIS 2.12 - */ - void setDrawLabelRectOnly( bool drawRect ); - //! called to find out whether the layer is used for labeling //! \since QGIS 2.4 static bool staticWillUseLayer( QgsVectorLayer *layer ); @@ -751,10 +713,6 @@ class CORE_EXPORT QgsPalLabeling //! \note not available in Python bindings static void drawLabelCandidateRect( pal::LabelPosition *lp, QPainter *painter, const QgsMapToPixel *xform, QList *candidates = nullptr ); - //! load/save engine settings to project file - void loadEngineSettings(); - void saveEngineSettings(); - /** Prepares a geometry for registration with PAL. Handles reprojection, rotation, clipping, etc. * \param geometry geometry to prepare * \param context render context @@ -817,8 +775,6 @@ class CORE_EXPORT QgsPalLabeling friend class QgsVectorLayerLabelProvider; // to allow calling the static methods above friend class QgsDxfExport; // to allow calling the static methods above - void deleteTemporaryData(); - /** Checks whether a geometry exceeds the minimum required size for a geometry to be labeled. * \param context render context * \param geom geometry @@ -828,18 +784,6 @@ class CORE_EXPORT QgsPalLabeling */ static bool checkMinimumSizeMM( const QgsRenderContext &context, const QgsGeometry *geom, double minSize ); - //! hashtable of label providers, being filled during labeling (key = layer ID) - QHash mLabelProviders; - //! hashtable of diagram providers (key = layer ID) - QHash mDiagramProviders; - QgsPalLayerSettings mInvalidLayerSettings; - - //! New labeling engine to interface with PAL - QgsLabelingEngine *mEngine = nullptr; - - // list of candidates from last labeling - QList mCandidates; - friend class QgsPalLayerSettings; }; diff --git a/src/core/qgsproject.cpp b/src/core/qgsproject.cpp index e42eafe5f6a..cef77a7ed06 100644 --- a/src/core/qgsproject.cpp +++ b/src/core/qgsproject.cpp @@ -18,7 +18,7 @@ #include "qgsproject.h" #include "qgsdatasourceuri.h" -#include "qgsexception.h" +#include "qgslabelingenginesettings.h" #include "qgslayertree.h" #include "qgslayertreeutils.h" #include "qgslayertreeregistrybridge.h" @@ -328,6 +328,7 @@ QgsProject::QgsProject( QObject *parent ) , mAnnotationManager( new QgsAnnotationManager( this ) ) , mLayoutManager( new QgsLayoutManager( this ) ) , mRootGroup( new QgsLayerTree ) + , mLabelingEngineSettings( new QgsLabelingEngineSettings ) , mAutoTransaction( false ) , mEvaluateDefaultValues( false ) , mDirty( false ) @@ -472,6 +473,9 @@ void QgsProject::clear() mRootGroup->clear(); + mLabelingEngineSettings->clear(); + emit labelingEngineSettingsChanged(); + // reset some default project properties // XXX THESE SHOULD BE MOVED TO STATUSBAR RELATED SOURCE writeEntry( QStringLiteral( "PositionPrecision" ), QStringLiteral( "/Automatic" ), true ); @@ -915,6 +919,9 @@ bool QgsProject::read() emit mapThemeCollectionChanged(); mMapThemeCollection->readXml( *doc ); + mLabelingEngineSettings->readSettingsFromProject( this ); + emit labelingEngineSettingsChanged(); + mAnnotationManager->readXml( doc->documentElement(), *doc ); mLayoutManager->readXml( doc->documentElement(), *doc ); @@ -1031,6 +1038,17 @@ void QgsProject::setCustomVariables( const QVariantMap &variables ) emit customVariablesChanged(); } +void QgsProject::setLabelingEngineSettings( const QgsLabelingEngineSettings &settings ) +{ + *mLabelingEngineSettings = settings; + emit labelingEngineSettingsChanged(); +} + +const QgsLabelingEngineSettings &QgsProject::labelingEngineSettings() const +{ + return *mLabelingEngineSettings; +} + QList QgsProject::avoidIntersectionsLayers() const { QList layers; @@ -1292,6 +1310,8 @@ bool QgsProject::write() mMapThemeCollection->writeXml( *doc ); + mLabelingEngineSettings->writeSettingsToProject( this ); + QDomElement annotationsElem = mAnnotationManager->writeXml( *doc ); qgisNode.appendChild( annotationsElem ); diff --git a/src/core/qgsproject.h b/src/core/qgsproject.h index e3dc93776f1..4b62fd3dacb 100644 --- a/src/core/qgsproject.h +++ b/src/core/qgsproject.h @@ -56,6 +56,7 @@ class QgsVectorLayer; class QgsAnnotationManager; class QgsLayoutManager; class QgsLayerTree; +class QgsLabelingEngineSettings; /** \ingroup core * Reads and writes project states. @@ -510,6 +511,18 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera */ void setCustomVariables( const QVariantMap &customVariables ); + /** + * Sets project's global labeling engine settings + * \since QGIS 3.0 + */ + void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings ); + + /** + * Returns project's global labeling engine settings + * \since QGIS 3.0 + */ + const QgsLabelingEngineSettings &labelingEngineSettings() const; + // // Functionality from QgsMapLayerRegistry // @@ -815,6 +828,12 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera */ void mapThemeCollectionChanged(); + /** + * Emitted when global configuration of the labeling engine changes. + * \since QGIS 3.0 + */ + void labelingEngineSettingsChanged(); + // // signals from QgsMapLayerRegistry // @@ -1001,6 +1020,8 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera std::unique_ptr mMapThemeCollection; + std::unique_ptr mLabelingEngineSettings; + QVariantMap mCustomVariables; QFile mFile; // current physical project file diff --git a/src/core/qgsvectorlayerlabelprovider.cpp b/src/core/qgsvectorlayerlabelprovider.cpp index e6362e68b4b..689a0b28a95 100644 --- a/src/core/qgsvectorlayerlabelprovider.cpp +++ b/src/core/qgsvectorlayerlabelprovider.cpp @@ -458,7 +458,7 @@ void QgsVectorLayerLabelProvider::drawLabelPrivate( pal::LabelPosition *label, Q QPointF outPt = xform.transform( label->getX(), label->getY() ).toQPointF(); - if ( mEngine->testFlag( QgsLabelingEngine::DrawLabelRectOnly ) ) // TODO: this should get directly to labeling engine + if ( mEngine->engineSettings().testFlag( QgsLabelingEngineSettings::DrawLabelRectOnly ) ) // TODO: this should get directly to labeling engine { //debugging rect if ( drawType != QgsTextRenderer::Text ) @@ -596,7 +596,7 @@ void QgsVectorLayerLabelProvider::drawLabelPrivate( pal::LabelPosition *label, Q component.origin = outPt; component.rotation = label->getAlpha(); QgsTextRenderer::drawTextInternal( drawType, context, tmpLyr.format(), component, multiLineList, labelfm, - hAlign, mEngine->testFlag( QgsLabelingEngine::RenderOutlineLabels ), QgsTextRenderer::Label ); + hAlign, mEngine->engineSettings().testFlag( QgsLabelingEngineSettings::RenderOutlineLabels ), QgsTextRenderer::Label ); } diff --git a/src/gui/qgsmapcanvas.cpp b/src/gui/qgsmapcanvas.cpp index d0a2e0250d7..981fd7b2af6 100644 --- a/src/gui/qgsmapcanvas.cpp +++ b/src/gui/qgsmapcanvas.cpp @@ -2124,3 +2124,13 @@ void QgsMapCanvas::setAnnotationsVisible( bool show ) item->setVisible( show ); } } + +void QgsMapCanvas::setLabelingEngineSettings( const QgsLabelingEngineSettings &settings ) +{ + mSettings.setLabelingEngineSettings( settings ); +} + +const QgsLabelingEngineSettings &QgsMapCanvas::labelingEngineSettings() const +{ + return mSettings.labelingEngineSettings(); +} diff --git a/src/gui/qgsmapcanvas.h b/src/gui/qgsmapcanvas.h index df7b3a86806..1201c2f08a9 100644 --- a/src/gui/qgsmapcanvas.h +++ b/src/gui/qgsmapcanvas.h @@ -494,6 +494,18 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView */ void setAnnotationsVisible( bool visible ); + /** + * Sets global labeling engine settings in the internal map settings + * \since QGIS 3.0 + */ + void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings ); + + /** + * Returns global labeling engine settings from the internal map settings + * \since QGIS 3.0 + */ + const QgsLabelingEngineSettings &labelingEngineSettings() const; + public slots: //! Repaints the canvas map diff --git a/src/server/qgsserver.cpp b/src/server/qgsserver.cpp index a1eabfbc53e..4679ead5702 100644 --- a/src/server/qgsserver.cpp +++ b/src/server/qgsserver.cpp @@ -31,7 +31,6 @@ #include "qgsproviderregistry.h" #include "qgslogger.h" #include "qgsmapserviceexception.h" -#include "qgspallabeling.h" #include "qgsnetworkaccessmanager.h" #include "qgsserverlogger.h" #include "qgseditorwidgetregistry.h" diff --git a/src/server/qgssldconfigparser.h b/src/server/qgssldconfigparser.h index 9278e5452dc..deba1fecf3d 100644 --- a/src/server/qgssldconfigparser.h +++ b/src/server/qgssldconfigparser.h @@ -19,6 +19,7 @@ #define QGSSLDCONFIGPARSER_H #include "qgswmsconfigparser.h" +#include class QgsFeatureRenderer; class QgsVectorLayer; diff --git a/src/server/qgswmsconfigparser.h b/src/server/qgswmsconfigparser.h index 256094a5703..160ecae54ee 100644 --- a/src/server/qgswmsconfigparser.h +++ b/src/server/qgswmsconfigparser.h @@ -19,7 +19,6 @@ #define QGSWMSCONFIGPARSER_H #include "qgsunittypes.h" -#include "qgspallabeling.h" #include "qgsdatumtransformstore.h" #include "qgis_server.h" @@ -30,9 +29,11 @@ class QgsComposerLabel; class QgsComposerLegend; class QgsComposerMap; class QgsComposition; +class QgsGeometry; class QgsMapLayer; class QgsLegendModel; class QgsMapSettings; +class QgsVectorLayer; class SERVER_EXPORT QgsWmsConfigParser diff --git a/src/server/qgswmsprojectparser.cpp b/src/server/qgswmsprojectparser.cpp index a5f8572849c..c3f0539e6f0 100644 --- a/src/server/qgswmsprojectparser.cpp +++ b/src/server/qgswmsprojectparser.cpp @@ -23,7 +23,6 @@ #include "qgsproject.h" #include "qgsmaplayerstylemanager.h" #include "qgsmapserviceexception.h" -#include "qgspallabeling.h" #include "qgsrenderer.h" #include "qgsvectorlayer.h" #include "qgsmapsettings.h" @@ -2201,7 +2200,7 @@ void QgsWmsProjectParser::loadLabelSettings() const void QgsWmsProjectParser::readLabelSettings( int &searchMethod, int &nCandPoint, int &nCandLine, int &nCandPoly, bool &showingCandidates, bool &drawRectOnly, bool &showingShadowRects, bool &showingAllLabels, bool &showingPartialsLabels, bool &drawOutlineLabels ) const { - searchMethod = static_cast< int >( QgsPalLabeling::Chain ); + searchMethod = static_cast< int >( QgsLabelingEngineSettings::Chain ); nCandPoint = 8; nCandLine = 8; nCandPoly = 8; diff --git a/src/server/services/wms/qgswmsgetlegendgraphics.cpp b/src/server/services/wms/qgswmsgetlegendgraphics.cpp index cfeab3c81df..fd5f13f7126 100644 --- a/src/server/services/wms/qgswmsgetlegendgraphics.cpp +++ b/src/server/services/wms/qgswmsgetlegendgraphics.cpp @@ -22,6 +22,8 @@ #include "qgswmsgetlegendgraphics.h" #include "qgswmsrenderer.h" +#include + namespace QgsWms { diff --git a/src/server/services/wms/qgswmsgetmap.cpp b/src/server/services/wms/qgswmsgetmap.cpp index 46358b02f98..d885283ea25 100644 --- a/src/server/services/wms/qgswmsgetmap.cpp +++ b/src/server/services/wms/qgswmsgetmap.cpp @@ -22,6 +22,8 @@ #include "qgswmsgetmap.h" #include "qgswmsrenderer.h" +#include + namespace QgsWms { diff --git a/src/server/services/wms/qgswmsgetschemaextension.cpp b/src/server/services/wms/qgswmsgetschemaextension.cpp index 6e8304c1696..43530bf9a3d 100644 --- a/src/server/services/wms/qgswmsgetschemaextension.cpp +++ b/src/server/services/wms/qgswmsgetschemaextension.cpp @@ -21,6 +21,8 @@ #include "qgswmsutils.h" #include "qgswmsgetschemaextension.h" +#include + namespace QgsWms { diff --git a/src/server/services/wms/qgswmsutils.h b/src/server/services/wms/qgswmsutils.h index 9ea52ac68aa..53925e6fca4 100644 --- a/src/server/services/wms/qgswmsutils.h +++ b/src/server/services/wms/qgswmsutils.h @@ -27,6 +27,8 @@ #include "qgswmsconfigparser.h" #include "qgswmsserviceexception.h" +class QgsRectangle; + /** * \ingroup server * WMS implementation diff --git a/tests/src/python/test_qgspallabeling_base.py b/tests/src/python/test_qgspallabeling_base.py index db120d64411..29da8b793b3 100644 --- a/tests/src/python/test_qgspallabeling_base.py +++ b/tests/src/python/test_qgspallabeling_base.py @@ -35,6 +35,7 @@ from qgis.PyQt.QtGui import QFont, QColor from qgis.core import ( QgsCoordinateReferenceSystem, QgsDataSourceUri, + QgsLabelingEngineSettings, QgsProject, QgsMapSettings, QgsPalLabeling, @@ -79,8 +80,6 @@ class TestQgsPalLabeling(unittest.TestCase): """:type: QgsMapSettings""" _Canvas = None """:type: QgsMapCanvas""" - _Pal = None - """:type: QgsPalLabeling""" _BaseSetup = False @classmethod @@ -120,9 +119,6 @@ class TestQgsPalLabeling(unittest.TestCase): cls._Canvas.setCanvasColor(cls._MapSettings.backgroundColor()) cls.setDefaultEngineSettings() - msg = ('\nCould not initialize PAL labeling engine, ' - 'SKIPPING TEST SUITE') - assert cls._Pal, msg cls._BaseSetup = True @@ -138,7 +134,7 @@ class TestQgsPalLabeling(unittest.TestCase): @classmethod def setDefaultEngineSettings(cls): """Restore default settings for pal labeling""" - cls._Pal = QgsPalLabeling() + cls._MapSettings.setLabelingEngineSettings(QgsLabelingEngineSettings()) @classmethod def removeAllLayers(cls): @@ -226,6 +222,7 @@ class TestQgsPalLabeling(unittest.TestCase): ms.setDestinationCrs(oms.destinationCrs()) ms.setExtent(oms.extent()) ms.setOutputImageFormat(oms.outputImageFormat()) + ms.setLabelingEngineSettings(oms.labelingEngineSettings()) ms.setLayers(oms.layers()) return ms @@ -429,20 +426,20 @@ class TestPALConfig(TestQgsPalLabeling): def test_default_partials_labels_enabled(self): # Verify ShowingPartialsLabels is enabled for PAL by default - pal = QgsPalLabeling() - self.assertTrue(pal.isShowingPartialsLabels()) + engine_settings = QgsLabelingEngineSettings() + self.assertTrue(engine_settings.testFlag(QgsLabelingEngineSettings.UsePartialCandidates)) def test_partials_labels_activate(self): - pal = QgsPalLabeling() + engine_settings = QgsLabelingEngineSettings() # Enable partials labels - pal.setShowingPartialsLabels(True) - self.assertTrue(pal.isShowingPartialsLabels()) + engine_settings.setFlag(QgsLabelingEngineSettings.UsePartialCandidates) + self.assertTrue(engine_settings.testFlag(QgsLabelingEngineSettings.UsePartialCandidates)) def test_partials_labels_deactivate(self): - pal = QgsPalLabeling() + engine_settings = QgsLabelingEngineSettings() # Disable partials labels - pal.setShowingPartialsLabels(False) - self.assertFalse(pal.isShowingPartialsLabels()) + engine_settings.setFlag(QgsLabelingEngineSettings.UsePartialCandidates, False) + self.assertFalse(engine_settings.testFlag(QgsLabelingEngineSettings.UsePartialCandidates)) # noinspection PyPep8Naming,PyShadowingNames diff --git a/tests/src/python/test_qgspallabeling_composer.py b/tests/src/python/test_qgspallabeling_composer.py index f1501218bb3..d0b2f3ae4d7 100644 --- a/tests/src/python/test_qgspallabeling_composer.py +++ b/tests/src/python/test_qgspallabeling_composer.py @@ -100,7 +100,7 @@ class TestComposerBase(TestQgsPalLabeling): self._Mismatches.clear() self._ColorTols.clear() - def _set_up_composition(self, width, height, dpi): + def _set_up_composition(self, width, height, dpi, engine_settings): # set up composition and add map self._c = QgsComposition(QgsProject.instance()) """:type: QgsComposition""" @@ -126,6 +126,8 @@ class TestComposerBase(TestQgsPalLabeling): self._cmap.setNewExtent(self.aoiExtent()) # self._cmap.updateCachedImage() self._c.setPlotStyle(QgsComposition.Print) + # composition takes labeling engine settings from project + QgsProject.instance().setLabelingEngineSettings(engine_settings) # noinspection PyUnusedLocal def _get_composer_image(self, width, height, dpi): @@ -271,7 +273,7 @@ class TestComposerBase(TestQgsPalLabeling): ms = self._TestMapSettings osize = ms.outputSize() width, height, dpi = osize.width(), osize.height(), ms.outputDpi() - self._set_up_composition(width, height, dpi) + self._set_up_composition(width, height, dpi, ms.labelingEngineSettings()) if kind == OutputKind.Svg: return self._get_composer_svg_image(width, height, dpi) elif kind == OutputKind.Pdf: diff --git a/tests/src/python/test_qgspallabeling_placement.py b/tests/src/python/test_qgspallabeling_placement.py index a87749c7fa2..bef3739577d 100644 --- a/tests/src/python/test_qgspallabeling_placement.py +++ b/tests/src/python/test_qgspallabeling_placement.py @@ -23,7 +23,8 @@ import sys from qgis.PyQt.QtCore import QThreadPool, qDebug -from qgis.core import (QgsPalLayerSettings, +from qgis.core import (QgsLabelingEngineSettings, + QgsPalLayerSettings, QgsSingleSymbolRenderer, QgsMarkerSymbol, QgsProperty) @@ -39,8 +40,6 @@ class TestPlacementBase(TestQgsPalLabeling): def setUpClass(cls): if not cls._BaseSetup: TestQgsPalLabeling.setUpClass() - cls._Pal.setDrawLabelRectOnly(True) - cls._Pal.saveEngineSettings() @classmethod def tearDownClass(cls): @@ -54,13 +53,17 @@ class TestPlacementBase(TestQgsPalLabeling): self.removeAllLayers() self.configTest('pal_placement', 'sp') self._TestImage = '' - # ensure per test map settings stay encapsulated - self._TestMapSettings = self.cloneMapSettings(self._MapSettings) + self._Mismatch = 0 self._ColorTol = 0 self._Mismatches.clear() self._ColorTols.clear() + # render only rectangles of the placed labels + engine_settings = QgsLabelingEngineSettings() + engine_settings.setFlag(QgsLabelingEngineSettings.DrawLabelRectOnly) + self._MapSettings.setLabelingEngineSettings(engine_settings) + def checkTest(self, **kwargs): self.lyr.writeToLayer(self.layer) diff --git a/tests/src/python/test_qgspallabeling_server.py b/tests/src/python/test_qgspallabeling_server.py index 8c6b9f37ac3..8bb0198573e 100644 --- a/tests/src/python/test_qgspallabeling_server.py +++ b/tests/src/python/test_qgspallabeling_server.py @@ -138,17 +138,7 @@ class TestServerBase(TestQgsPalLabeling): # print params return params - def sync_map_settings(self): - """ - Sync custom test QgsMapSettings to Project file - """ - pal = QgsPalLabeling() - pal.loadEngineSettings() - pal.init(self._TestMapSettings) - pal.saveEngineSettings() - def checkTest(self, **kwargs): - self.sync_map_settings() self.lyr.writeToLayer(self.layer) # save project file self._TestProj.write() diff --git a/tests/src/python/test_qgspallabeling_tests.py b/tests/src/python/test_qgspallabeling_tests.py index f121c752e94..a6267125a98 100644 --- a/tests/src/python/test_qgspallabeling_tests.py +++ b/tests/src/python/test_qgspallabeling_tests.py @@ -23,7 +23,7 @@ import os from qgis.PyQt.QtCore import Qt, QPointF, QSizeF from qgis.PyQt.QtGui import QFont -from qgis.core import QgsPalLayerSettings, QgsUnitTypes, QgsTextBackgroundSettings +from qgis.core import QgsLabelingEngineSettings, QgsPalLayerSettings, QgsUnitTypes, QgsTextBackgroundSettings from utilities import svgSymbolsPath @@ -37,8 +37,6 @@ class TestPointBase(object): """:type: QgsPalLayerSettings""" # noinspection PyArgumentList self._TestFont = QFont() # will become a standard test font - self._Pal = None - """:type: QgsPalLabeling""" self._Canvas = None """:type: QgsMapCanvas""" # custom mismatches per group/test (should not mask any needed anomaly) @@ -175,8 +173,9 @@ class TestPointBase(object): format.setSize(84) self.lyr.setFormat(format) # Enable partials labels - self._Pal.setShowingPartialsLabels(True) - self._Pal.saveEngineSettings() + engine_settings = QgsLabelingEngineSettings() + engine_settings.setFlag(QgsLabelingEngineSettings.UsePartialCandidates, True) + self._TestMapSettings.setLabelingEngineSettings(engine_settings) self._Mismatches['TestCanvasPoint'] = 779 self._ColorTols['TestComposerPdfPoint'] = 2 self.checkTest() @@ -189,8 +188,9 @@ class TestPointBase(object): format.setSize(84) self.lyr.setFormat(format) # Disable partials labels - self._Pal.setShowingPartialsLabels(False) - self._Pal.saveEngineSettings() + engine_settings = QgsLabelingEngineSettings() + engine_settings.setFlag(QgsLabelingEngineSettings.UsePartialCandidates, False) + self._TestMapSettings.setLabelingEngineSettings(engine_settings) self.checkTest() def test_buffer(self):