Skip to content

Commit

Permalink
Move QgsLabelingResults out to its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 23, 2021
1 parent a513f5a commit 4f39cf6
Show file tree
Hide file tree
Showing 17 changed files with 205 additions and 136 deletions.
54 changes: 54 additions & 0 deletions python/core/auto_generated/labeling/qgslabelingresults.sip.in
@@ -0,0 +1,54 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/labeling/qgslabelingresults.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



class QgsLabelingResults
{
%Docstring
Class that stores computed placement from labeling engine.

.. versionadded:: 2.4
%End

%TypeHeaderCode
#include "qgslabelingresults.h"
%End
public:
QgsLabelingResults();
~QgsLabelingResults();


QList<QgsLabelPosition> labelsAtPosition( const QgsPointXY &p ) const;
%Docstring
Returns the details of any labels placed at the specifed point (in map coordinates).
%End

QList<QgsLabelPosition> labelsWithinRect( const QgsRectangle &r ) const;
%Docstring
Returns the details of any labels placed within the specifed rectangle (in map coordinates).
%End

void setMapSettings( const QgsMapSettings &settings );
%Docstring
Sets the map ``settings`` associated with the labeling run.

.. versionadded:: 3.4.8
%End

private:
QgsLabelingResults( const QgsLabelingResults & );
};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/labeling/qgslabelingresults.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
39 changes: 0 additions & 39 deletions python/core/auto_generated/labeling/qgspallabeling.sip.in
Expand Up @@ -675,45 +675,6 @@ Represents a label candidate.
double cost;
};




class QgsLabelingResults
{
%Docstring
Class that stores computed placement from labeling engine.

.. versionadded:: 2.4
%End

%TypeHeaderCode
#include "qgspallabeling.h"
%End
public:
QgsLabelingResults();
~QgsLabelingResults();


QList<QgsLabelPosition> labelsAtPosition( const QgsPointXY &p ) const;
%Docstring
Returns infos about labels at a given (map) position
%End
QList<QgsLabelPosition> labelsWithinRect( const QgsRectangle &r ) const;
%Docstring
Returns infos about labels within a given (map) rectangle
%End

void setMapSettings( const QgsMapSettings &settings );
%Docstring
Sets the map ``settings`` associated with the labeling run.

.. versionadded:: 3.4.8
%End

private:
QgsLabelingResults( const QgsLabelingResults & );
};

class QgsPalLabeling
{
%Docstring
Expand Down
2 changes: 2 additions & 0 deletions python/core/core_auto.sip
Expand Up @@ -327,6 +327,7 @@
%Include auto_generated/gps/qgsnmeaconnection.sip
%Include auto_generated/labeling/qgslabeling.sip
%Include auto_generated/labeling/qgslabelingenginesettings.sip
%Include auto_generated/labeling/qgslabelingresults.sip
%Include auto_generated/labeling/qgslabellinesettings.sip
%Include auto_generated/labeling/qgslabelobstaclesettings.sip
%Include auto_generated/labeling/qgslabelposition.sip
Expand Down Expand Up @@ -629,4 +630,5 @@
%Include auto_generated/gps/qgsqtlocationconnection.sip
%Include auto_generated/gps/qgsgpsconnectionregistry.sip
%Include auto_generated/symbology/qgsmasksymbollayer.sip
%Include auto_generated/labeling/qgslabelthinningsettings.sip
%Include auto_generated/qgsuserprofile.sip
1 change: 1 addition & 0 deletions src/app/labeling/qgsmaptoolpinlabels.cpp
Expand Up @@ -26,6 +26,7 @@
#include "qgsmaptoolselectutils.h"
#include "qgsrubberband.h"
#include "qgslogger.h"
#include "qgslabelingresults.h"


QgsMapToolPinLabels::QgsMapToolPinLabels( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDock )
Expand Down
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -647,6 +647,7 @@ set(QGIS_CORE_SRCS
labeling/qgslabelfeature.cpp
labeling/qgslabelingengine.cpp
labeling/qgslabelingenginesettings.cpp
labeling/qgslabelingresults.cpp
labeling/qgslabellinesettings.cpp
labeling/qgslabelobstaclesettings.cpp
labeling/qgslabelsearchtree.cpp
Expand Down Expand Up @@ -1215,6 +1216,7 @@ set(QGIS_CORE_HDRS
labeling/qgslabeling.h
labeling/qgslabelingengine.h
labeling/qgslabelingenginesettings.h
labeling/qgslabelingresults.h
labeling/qgslabellinesettings.h
labeling/qgslabelobstaclesettings.h
labeling/qgslabelposition.h
Expand Down
1 change: 1 addition & 0 deletions src/core/labeling/qgslabelingengine.cpp
Expand Up @@ -28,6 +28,7 @@
#include "qgssymbol.h"
#include "qgsexpressioncontextutils.h"
#include "qgsvectorlayerlabelprovider.h"
#include "qgslabelingresults.h"

// helper function for checking for job cancellation within PAL
static bool _palIsCanceled( void *ctx )
Expand Down
1 change: 1 addition & 0 deletions src/core/labeling/qgslabelingengine.h
Expand Up @@ -26,6 +26,7 @@
#include "qgslabeling.h"

class QgsLabelingEngine;
class QgsLabelingResults;

namespace pal
{
Expand Down
65 changes: 65 additions & 0 deletions src/core/labeling/qgslabelingresults.cpp
@@ -0,0 +1,65 @@
/***************************************************************************
qgslabelingresults.cpp
-------------------
begin : February 2021
copyright : (C) Nyall Dawson
email : nyall dot dawson 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 "qgslabelingresults.h"
#include "qgslabelsearchtree.h"

QgsLabelingResults::QgsLabelingResults()
: mLabelSearchTree( qgis::make_unique< QgsLabelSearchTree >() )
{
}

QgsLabelingResults::~QgsLabelingResults() = default;

QList<QgsLabelPosition> QgsLabelingResults::labelsAtPosition( const QgsPointXY &p ) const
{
QList<QgsLabelPosition> positions;

QList<QgsLabelPosition *> positionPointers;
if ( mLabelSearchTree )
{
mLabelSearchTree->label( p, positionPointers );
QList<QgsLabelPosition *>::const_iterator pointerIt = positionPointers.constBegin();
for ( ; pointerIt != positionPointers.constEnd(); ++pointerIt )
{
positions.push_back( QgsLabelPosition( **pointerIt ) );
}
}

return positions;
}

QList<QgsLabelPosition> QgsLabelingResults::labelsWithinRect( const QgsRectangle &r ) const
{
QList<QgsLabelPosition> positions;

QList<QgsLabelPosition *> positionPointers;
if ( mLabelSearchTree )
{
mLabelSearchTree->labelsInRect( r, positionPointers );
QList<QgsLabelPosition *>::const_iterator pointerIt = positionPointers.constBegin();
for ( ; pointerIt != positionPointers.constEnd(); ++pointerIt )
{
positions.push_back( QgsLabelPosition( **pointerIt ) );
}
}

return positions;
}

void QgsLabelingResults::setMapSettings( const QgsMapSettings &settings )
{
mLabelSearchTree->setMapSettings( settings );
}
71 changes: 71 additions & 0 deletions src/core/labeling/qgslabelingresults.h
@@ -0,0 +1,71 @@
/***************************************************************************
qgslabelingresults.h
-------------------
begin : February 2021
copyright : (C) Nyall Dawson
email : nyall dot dawson 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. *
* *
***************************************************************************/

#ifndef QGSLABELINGRESULTS_H
#define QGSLABELINGRESULTS_H

#include "qgis_core.h"
#include "qgis_sip.h"
#include "qgslabelposition.h"

#include <memory>

class QgsLabelSearchTree;

/**
* \ingroup core
* \brief Class that stores computed placement from labeling engine.
* \since QGIS 2.4
*/
class CORE_EXPORT QgsLabelingResults
{
public:
QgsLabelingResults();
~QgsLabelingResults();

//! QgsLabelingResults cannot be copied.
QgsLabelingResults( const QgsLabelingResults & ) = delete;
//! QgsLabelingResults cannot be copied.
QgsLabelingResults &operator=( const QgsLabelingResults &rh ) = delete;

/**
* Returns the details of any labels placed at the specifed point (in map coordinates).
*/
QList<QgsLabelPosition> labelsAtPosition( const QgsPointXY &p ) const;

/**
* Returns the details of any labels placed within the specifed rectangle (in map coordinates).
*/
QList<QgsLabelPosition> labelsWithinRect( const QgsRectangle &r ) const;

/**
* Sets the map \a settings associated with the labeling run.
* \since QGIS 3.4.8
*/
void setMapSettings( const QgsMapSettings &settings );

private:
#ifdef SIP_RUN
QgsLabelingResults( const QgsLabelingResults & );
#endif

std::unique_ptr< QgsLabelSearchTree > mLabelSearchTree;

friend class QgsPalLabeling;
friend class QgsVectorLayerLabelProvider;
friend class QgsVectorLayerDiagramProvider;
};

#endif // QGSLABELINGRESULTS_H
2 changes: 1 addition & 1 deletion src/core/labeling/qgslabelsearchtree.h
Expand Up @@ -23,7 +23,7 @@
#include "qgis_sip.h"
#include <QList>
#include <QVector>
#include "qgspallabeling.h"
#include "qgslabelposition.h"
#include "qgsgenericspatialindex.h"
#include "qgsmapsettings.h"

Expand Down
49 changes: 0 additions & 49 deletions src/core/labeling/qgspallabeling.cpp
Expand Up @@ -4279,7 +4279,6 @@ void QgsPalLabeling::dataDefinedDropShadow( QgsPalLayerSettings &tmpLyr,
}
}


void QgsPalLabeling::drawLabelCandidateRect( pal::LabelPosition *lp, QPainter *painter, const QgsMapToPixel *xform, QList<QgsLabelCandidate> *candidates )
{
QgsPointXY outPt = xform->transform( lp->getX(), lp->getY() );
Expand Down Expand Up @@ -4338,51 +4337,3 @@ void QgsPalLabeling::drawLabelCandidateRect( pal::LabelPosition *lp, QPainter *p
if ( lp->nextPart() )
drawLabelCandidateRect( lp->nextPart(), painter, xform, candidates );
}

QgsLabelingResults::QgsLabelingResults()
: mLabelSearchTree( qgis::make_unique< QgsLabelSearchTree >() )
{
}

QgsLabelingResults::~QgsLabelingResults() = default;

QList<QgsLabelPosition> QgsLabelingResults::labelsAtPosition( const QgsPointXY &p ) const
{
QList<QgsLabelPosition> positions;

QList<QgsLabelPosition *> positionPointers;
if ( mLabelSearchTree )
{
mLabelSearchTree->label( p, positionPointers );
QList<QgsLabelPosition *>::const_iterator pointerIt = positionPointers.constBegin();
for ( ; pointerIt != positionPointers.constEnd(); ++pointerIt )
{
positions.push_back( QgsLabelPosition( **pointerIt ) );
}
}

return positions;
}

QList<QgsLabelPosition> QgsLabelingResults::labelsWithinRect( const QgsRectangle &r ) const
{
QList<QgsLabelPosition> positions;

QList<QgsLabelPosition *> positionPointers;
if ( mLabelSearchTree )
{
mLabelSearchTree->labelsInRect( r, positionPointers );
QList<QgsLabelPosition *>::const_iterator pointerIt = positionPointers.constBegin();
for ( ; pointerIt != positionPointers.constEnd(); ++pointerIt )
{
positions.push_back( QgsLabelPosition( **pointerIt ) );
}
}

return positions;
}

void QgsLabelingResults::setMapSettings( const QgsMapSettings &settings )
{
mLabelSearchTree->setMapSettings( settings );
}

0 comments on commit 4f39cf6

Please sign in to comment.