Skip to content
Permalink
Browse files
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)
  • Loading branch information
wonder-sk committed Apr 21, 2017
1 parent bcf1ef5 commit 25ed76b86e290df4330654be77aa3013d065aafd
Showing with 476 additions and 396 deletions.
  1. +8 −1 doc/api_break.dox
  2. +1 −0 python/core/core.sip
  3. +109 −0 python/core/qgslabelingenginesettings.sip
  4. +11 −0 python/core/qgsmapsettings.sip
  5. +12 −60 python/core/qgspallabeling.sip
  6. +19 −0 python/core/qgsproject.sip
  7. +2 −0 python/gui/qgsmapcanvas.sip
  8. +6 −0 src/app/qgisapp.cpp
  9. +16 −20 src/app/qgslabelengineconfigdialog.cpp
  10. +2 −0 src/core/CMakeLists.txt
  11. +2 −0 src/core/composer/qgscomposermap.cpp
  12. +0 −1 src/core/dxf/qgsdxfexport.cpp
  13. +17 −64 src/core/qgslabelingengine.cpp
  14. +5 −47 src/core/qgslabelingengine.h
  15. +63 −0 src/core/qgslabelingenginesettings.cpp
  16. +80 −0 src/core/qgslabelingenginesettings.h
  17. +0 −2 src/core/qgsmaprenderercustompainterjob.cpp
  18. +0 −1 src/core/qgsmaprendererjob.h
  19. +0 −2 src/core/qgsmaprendererparalleljob.cpp
  20. +14 −0 src/core/qgsmapsettings.h
  21. +0 −96 src/core/qgspallabeling.cpp
  22. +1 −57 src/core/qgspallabeling.h
  23. +21 −1 src/core/qgsproject.cpp
  24. +21 −0 src/core/qgsproject.h
  25. +2 −2 src/core/qgsvectorlayerlabelprovider.cpp
  26. +10 −0 src/gui/qgsmapcanvas.cpp
  27. +12 −0 src/gui/qgsmapcanvas.h
  28. +0 −1 src/server/qgsserver.cpp
  29. +1 −0 src/server/qgssldconfigparser.h
  30. +2 −1 src/server/qgswmsconfigparser.h
  31. +1 −2 src/server/qgswmsprojectparser.cpp
  32. +2 −0 src/server/services/wms/qgswmsgetlegendgraphics.cpp
  33. +2 −0 src/server/services/wms/qgswmsgetmap.cpp
  34. +2 −0 src/server/services/wms/qgswmsgetschemaextension.cpp
  35. +2 −0 src/server/services/wms/qgswmsutils.h
  36. +11 −14 tests/src/python/test_qgspallabeling_base.py
  37. +4 −2 tests/src/python/test_qgspallabeling_composer.py
  38. +8 −5 tests/src/python/test_qgspallabeling_placement.py
  39. +0 −10 tests/src/python/test_qgspallabeling_server.py
  40. +7 −7 tests/src/python/test_qgspallabeling_tests.py
@@ -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}
@@ -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
@@ -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<QgsLabelingEngineSettings::Flag> 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<QgsLabelingEngineSettings::Flag> operator|(QgsLabelingEngineSettings::Flag f1, QFlags<QgsLabelingEngineSettings::Flag> f2);


/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgslabelingenginesettings.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

@@ -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:

@@ -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
@@ -409,6 +409,19 @@ class QgsProject : QObject, QgsExpressionContextGenerator
void setAvoidIntersectionsLayers( const QList<QgsVectorLayer*>& 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
//
@@ -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:

@@ -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 );
@@ -14,8 +14,7 @@
***************************************************************************/
#include "qgslabelengineconfigdialog.h"

#include "qgspallabeling.h"
#include "qgslabelingengine.h"
#include "qgslabelingenginesettings.h"
#include "qgsproject.h"
#include <pal/pal.h>

@@ -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();
}
@@ -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
Loading

0 comments on commit 25ed76b

Please sign in to comment.