Skip to content

Commit c668c5d

Browse files
committedJul 18, 2012
Merge pull request #193 from dakcarto/feature_freeze-thaw-labels_4
[Feature] Freeze-thaw labeling tool, with on-the-fly transformation support.
2 parents cb1e7d3 + 83764a6 commit c668c5d

16 files changed

+755
-10
lines changed
 

‎images/images.qrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
<file>themes/default/mActionFileSmall.png</file>
7878
<file>themes/default/mActionFolder.png</file>
7979
<file>themes/default/mActionFormAnnotation.png</file>
80+
<file>themes/default/mActionFreezeLabels.png</file>
8081
<file>themes/default/mActionFromSelectedFeature.png</file>
8182
<file>themes/default/mActionFullHistogramStretch.png</file>
8283
<file>themes/default/mActionGroupItems.png</file>
@@ -143,6 +144,7 @@
143144
<file>themes/default/mActionSelectRectangle.png</file>
144145
<file>themes/default/mActionShowAllLayers.png</file>
145146
<file>themes/default/mActionShowBookmarks.png</file>
147+
<file>themes/default/mActionShowFrozenLabels.png</file>
146148
<file>themes/default/mActionShowPluginManager.png</file>
147149
<file>themes/default/mActionSimplify.png</file>
148150
<file>themes/default/mActionSplitFeatures.png</file>
1.28 KB
Loading
Loading

‎src/app/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ SET(QGIS_APP_SRCS
5555
qgsmaptooledit.cpp
5656
qgsmaptoolfeatureaction.cpp
5757
qgsmaptoolformannotation.cpp
58+
qgsmaptoolfreezelabels.cpp
5859
qgsmaptoolidentify.cpp
5960
qgsmaptoollabel.cpp
6061
qgsmaptoolmeasureangle.cpp
@@ -203,6 +204,7 @@ SET (QGIS_APP_MOC_HDRS
203204
qgsmaptooldeletering.h
204205
qgsmaptooldeletevertex.h
205206
qgsmaptoolfeatureaction.h
207+
qgsmaptoolfreezelabels.h
206208
qgsmaptoolidentify.h
207209
qgsmaptoolmeasureangle.h
208210
qgsmaptoolmovefeature.h

‎src/app/qgisapp.cpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@
231231
#include "qgsmaptoolzoom.h"
232232
#include "qgsmaptoolsimplify.h"
233233
#include "qgsmeasuretool.h"
234+
#include "qgsmaptoolfreezelabels.h"
234235
#include "qgsmaptoolmovelabel.h"
235236
#include "qgsmaptoolrotatelabel.h"
236237
#include "qgsmaptoolchangelabelproperties.h"
@@ -709,6 +710,7 @@ QgisApp::~QgisApp()
709710
delete mMapTools.mAddPart;
710711
delete mMapTools.mNodeTool;
711712
delete mMapTools.mRotatePointSymbolsTool;
713+
delete mMapTools.mFreezeLabels;
712714
delete mMapTools.mMoveLabel;
713715
delete mMapTools.mRotateLabel;
714716
delete mMapTools.mChangeLabelProperties;
@@ -974,6 +976,8 @@ void QgisApp::createActions()
974976
connect( mActionAbout, SIGNAL( triggered() ), this, SLOT( about() ) );
975977
connect( mActionSponsors, SIGNAL( triggered() ), this, SLOT( sponsors() ) );
976978

979+
connect( mActionShowFrozenLabels, SIGNAL( toggled( bool ) ), this, SLOT( showFrozenLabels( bool ) ) );
980+
connect( mActionFreezeLabels, SIGNAL( triggered() ), this, SLOT( freezeLabels() ) );
977981
connect( mActionMoveLabel, SIGNAL( triggered() ), this, SLOT( moveLabel() ) );
978982
connect( mActionRotateLabel, SIGNAL( triggered() ), this, SLOT( rotateLabel() ) );
979983
connect( mActionChangeLabelProperties, SIGNAL( triggered() ), this, SLOT( changeLabelProperties() ) );
@@ -1083,6 +1087,7 @@ void QgisApp::createActionGroups()
10831087
mMapToolGroup->addAction( mActionMergeFeatureAttributes );
10841088
mMapToolGroup->addAction( mActionNodeTool );
10851089
mMapToolGroup->addAction( mActionRotatePointSymbols );
1090+
mMapToolGroup->addAction( mActionFreezeLabels );
10861091
mMapToolGroup->addAction( mActionMoveLabel );
10871092
mMapToolGroup->addAction( mActionRotateLabel );
10881093
mMapToolGroup->addAction( mActionChangeLabelProperties );
@@ -1612,6 +1617,8 @@ void QgisApp::setTheme( QString theThemeName )
16121617
mActionFormAnnotation->setIcon( QgsApplication::getThemeIcon( "/mActionFormAnnotation.png" ) );
16131618
mActionTextAnnotation->setIcon( QgsApplication::getThemeIcon( "/mActionTextAnnotation.png" ) );
16141619
mActionLabeling->setIcon( QgsApplication::getThemeIcon( "/mActionLabeling.png" ) );
1620+
mActionShowFrozenLabels->setIcon( QgsApplication::getThemeIcon( "/mActionShowFrozenLabels.png" ) );
1621+
mActionFreezeLabels->setIcon( QgsApplication::getThemeIcon( "/mActionFreezeLabels.png" ) );
16151622
mActionMoveLabel->setIcon( QgsApplication::getThemeIcon( "/mActionMoveLabel.png" ) );
16161623
mActionRotateLabel->setIcon( QgsApplication::getThemeIcon( "/mActionRotateLabel.png" ) );
16171624
mActionChangeLabelProperties->setIcon( QgsApplication::getThemeIcon( "/mActionChangeLabelProperties.png" ) );
@@ -1778,6 +1785,8 @@ void QgisApp::createCanvasTools()
17781785
mMapTools.mNodeTool->setAction( mActionNodeTool );
17791786
mMapTools.mRotatePointSymbolsTool = new QgsMapToolRotatePointSymbols( mMapCanvas );
17801787
mMapTools.mRotatePointSymbolsTool->setAction( mActionRotatePointSymbols );
1788+
mMapTools.mFreezeLabels = new QgsMapToolFreezeLabels( mMapCanvas );
1789+
mMapTools.mFreezeLabels->setAction( mActionFreezeLabels );
17811790
mMapTools.mMoveLabel = new QgsMapToolMoveLabel( mMapCanvas );
17821791
mMapTools.mMoveLabel->setAction( mActionMoveLabel );
17831792
mMapTools.mRotateLabel = new QgsMapToolRotateLabel( mMapCanvas );
@@ -4144,6 +4153,17 @@ bool QgisApp::loadAnnotationItemsFromProject( const QDomDocument& doc )
41444153
return true;
41454154
}
41464155

4156+
void QgisApp::showFrozenLabels( bool show )
4157+
{
4158+
qobject_cast<QgsMapToolFreezeLabels*>( mMapTools.mFreezeLabels )->showFrozenLabels( show );
4159+
}
4160+
4161+
void QgisApp::freezeLabels()
4162+
{
4163+
mActionShowFrozenLabels->setChecked( true );
4164+
mMapCanvas->setMapTool( mMapTools.mFreezeLabels );
4165+
}
4166+
41474167
void QgisApp::moveLabel()
41484168
{
41494169
mMapCanvas->setMapTool( mMapTools.mMoveLabel );
@@ -6574,7 +6594,7 @@ void QgisApp::legendLayerSelectionChanged( void )
65746594

65756595
void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
65766596
{
6577-
bool enableMove = false, enableRotate = false, enableChange = false;
6597+
bool enableMove = false, enableRotate = false, enableFreeze = false, enableChange = false;
65786598

65796599
QMap<QString, QgsMapLayer*> layers = QgsMapLayerRegistry::instance()->mapLayers();
65806600
for ( QMap<QString, QgsMapLayer*>::iterator it = layers.begin(); it != layers.end(); it++ )
@@ -6585,6 +6605,11 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
65856605
continue;
65866606

65876607
int colX, colY, colAng;
6608+
enableFreeze =
6609+
enableFreeze ||
6610+
( qobject_cast<QgsMapToolFreezeLabels*>( mMapTools.mFreezeLabels ) &&
6611+
qobject_cast<QgsMapToolFreezeLabels*>( mMapTools.mFreezeLabels )->layerCanFreeze( vlayer, colX, colY ) );
6612+
65886613
enableMove =
65896614
enableMove ||
65906615
( qobject_cast<QgsMapToolMoveLabel*>( mMapTools.mMoveLabel ) &&
@@ -6599,10 +6624,11 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
65996624

66006625
enableChange = true;
66016626

6602-
if ( enableMove && enableRotate && enableChange )
6627+
if ( enableFreeze && enableMove && enableRotate && enableChange )
66036628
break;
66046629
}
66056630

6631+
mActionFreezeLabels->setEnabled( enableFreeze );
66066632
mActionMoveLabel->setEnabled( enableMove );
66076633
mActionRotateLabel->setEnabled( enableRotate );
66086634
mActionChangeLabelProperties->setEnabled( enableChange );
@@ -6649,6 +6675,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
66496675
mActionMergeFeatureAttributes->setEnabled( false );
66506676
mActionRotatePointSymbols->setEnabled( false );
66516677

6678+
mActionFreezeLabels->setEnabled( false );
66526679
mActionMoveLabel->setEnabled( false );
66536680
mActionRotateLabel->setEnabled( false );
66546681
mActionChangeLabelProperties->setEnabled( false );

‎src/app/qgisapp.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,8 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
309309
QAction *actionAbout() { return mActionAbout; }
310310
QAction *actionSponsors() { return mActionSponsors; }
311311

312+
QAction *actionShowFrozenLabels() { return mActionShowFrozenLabels; }
313+
312314
//! Menus
313315
QMenu *fileMenu() { return mFileMenu; }
314316
QMenu *editMenu() { return mEditMenu; }
@@ -852,6 +854,10 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
852854

853855
bool loadAnnotationItemsFromProject( const QDomDocument& doc );
854856

857+
//! Toggles whether to show frozen labels
858+
void showFrozenLabels( bool show );
859+
//! Activates freeze labels tool
860+
void freezeLabels();
855861
//! Activates the move label tool
856862
void moveLabel();
857863
//! Activates rotate label tool
@@ -1056,6 +1062,7 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
10561062
QgsMapTool* mAnnotation;
10571063
QgsMapTool* mFormAnnotation;
10581064
QgsMapTool* mTextAnnotation;
1065+
QgsMapTool* mFreezeLabels;
10591066
QgsMapTool* mMoveLabel;
10601067
QgsMapTool* mRotateLabel;
10611068
QgsMapTool* mChangeLabelProperties;

‎src/app/qgsmaptoolfreezelabels.cpp

Lines changed: 481 additions & 0 deletions
Large diffs are not rendered by default.

‎src/app/qgsmaptoolfreezelabels.h

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/***************************************************************************
2+
qgsmaptoolfreezelabels.h
3+
--------------------
4+
begin : 2012-07-12
5+
copyright : (C) 2012 by Larry Shaffer
6+
email : larrys at dakotacarto dot com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#ifndef QGSMAPTOOLFREEZELABELS_H
19+
#define QGSMAPTOOLFREEZELABELS_H
20+
21+
#include "qgsmaptoollabel.h"
22+
#include "qgsrectangle.h"
23+
#include "qgslegend.h"
24+
#include "qgscoordinatetransform.h"
25+
26+
class QgsHighlight;
27+
class QgsLabelPosition;
28+
29+
/**A map tool for freezing (writing to attribute table) and thawing label positions and rotation*/
30+
class QgsMapToolFreezeLabels: public QgsMapToolLabel
31+
{
32+
Q_OBJECT
33+
34+
public:
35+
QgsMapToolFreezeLabels( QgsMapCanvas *canvas );
36+
~QgsMapToolFreezeLabels();
37+
38+
//! Overridden mouse move event
39+
virtual void canvasMoveEvent( QMouseEvent * e );
40+
41+
//! Overridden mouse press event
42+
virtual void canvasPressEvent( QMouseEvent * e );
43+
44+
//! Overridden mouse release event
45+
virtual void canvasReleaseEvent( QMouseEvent * e );
46+
47+
bool isShowingFrozen() const { return mShowFrozen; }
48+
void setShowingFrozen( bool showing ) { mShowFrozen = showing; }
49+
50+
//! Called when Show Frozen Labels tool is toggled, via its qgisapp.cpp slot
51+
void showFrozenLabels( bool show );
52+
53+
//! Remove rectangles from around frozen labels
54+
void removeFrozenHighlights();
55+
56+
public slots:
57+
58+
//! Update frozen label highlights on layer edit mode change
59+
void updateFrozenLabels();
60+
61+
//! Render highlight rectangles around frozen labels
62+
void highlightFrozenLabels();
63+
64+
protected:
65+
66+
//! Mapping of feature ids of layers that have been highlighted
67+
QMap<QString, QgsHighlight*> mHighlights;
68+
69+
//! Flag to indicate a map canvas drag operation is taking place
70+
bool mDragging;
71+
//! Flag to indicate whether to draw the highlight for frozen labels
72+
bool mShowFrozen;
73+
74+
//! Stores actual select rect
75+
QRect mSelectRect;
76+
77+
//! Stores selection marquee
78+
QgsRubberBand* mRubberBand;
79+
80+
private:
81+
82+
//! Pointer to map renderer
83+
QgsMapRenderer* mRender;
84+
85+
//! Highlights a given label relative to whether its frozen and editable
86+
void highlightLabel( QgsVectorLayer* vlayer,
87+
const QgsLabelPosition& labelpos,
88+
const QString& id,
89+
const QColor& color );
90+
91+
//! Select valid labels to freeze or thaw
92+
void freezeThawLabels( const QgsRectangle& ext, QMouseEvent * e );
93+
94+
//! Freeze or thaw label relative to whether its editable
95+
bool freezeThawLabel( QgsVectorLayer* vlayer,
96+
const QgsLabelPosition& labelpos,
97+
bool freeze );
98+
};
99+
100+
#endif // QGSMAPTOOLFREEZELABELS_H

‎src/app/qgsmaptoollabel.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,3 +449,38 @@ bool QgsMapToolLabel::labelMoveable( const QgsMapLayer* ml, int& xCol, int& yCol
449449

450450
return true;
451451
}
452+
453+
bool QgsMapToolLabel::layerCanFreeze( const QgsMapLayer* ml, int& xCol, int& yCol ) const
454+
{
455+
const QgsVectorLayer* vlayer = dynamic_cast<const QgsVectorLayer*>( ml );
456+
if ( !vlayer || !vlayer->isEditable() )
457+
{
458+
return false;
459+
}
460+
461+
bool xColOk, yColOk;
462+
463+
QVariant xColumn = ml->customProperty( "labeling/dataDefinedProperty9" );
464+
if ( !xColumn.isValid() )
465+
{
466+
return false;
467+
}
468+
xCol = xColumn.toInt( &xColOk );
469+
if ( !xColOk )
470+
{
471+
return false;
472+
}
473+
474+
QVariant yColumn = ml->customProperty( "labeling/dataDefinedProperty10" );
475+
if ( !yColumn.isValid() )
476+
{
477+
return false;
478+
}
479+
yCol = yColumn.toInt( &yColOk );
480+
if ( !yColOk )
481+
{
482+
return false;
483+
}
484+
485+
return true;
486+
}

‎src/app/qgsmaptoollabel.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ class QgsMapToolLabel: public QgsMapTool
4141
@param yCol out: index of the attribute for data defined y coordinate
4242
@return true if labels of layer can be moved*/
4343
bool diagramMoveable( const QgsMapLayer* ml, int& xCol, int& yCol ) const;
44+
/**Returns true if layer has attribute fields set up
45+
@param xCol out: index of the attribute for data defined x coordinate
46+
@param yCol out: index of the attribute for data defined y coordinate
47+
@return true if layer fields set up and exist*/
48+
bool layerCanFreeze( const QgsMapLayer* ml, int& xCol, int& yCol ) const;
4449

4550
protected:
4651
QgsRubberBand* mLabelRubberBand;

‎src/core/qgslabelsearchtree.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,23 @@ void QgsLabelSearchTree::label( const QgsPoint& p, QList<QgsLabelPosition*>& pos
5151
}
5252
}
5353

54-
bool QgsLabelSearchTree::insertLabel( LabelPosition* labelPos, int featureId, const QString& layerName, bool diagram )
54+
void QgsLabelSearchTree::labelsInRect( const QgsRectangle& r, QList<QgsLabelPosition*>& posList )
55+
{
56+
double c_min[2]; c_min[0] = r.xMinimum(); c_min[1] = r.yMinimum();
57+
double c_max[2]; c_max[0] = r.xMaximum(); c_max[1] = r.yMaximum();
58+
59+
QList<QgsLabelPosition*> searchResults;
60+
mSpatialIndex.Search( c_min, c_max, searchCallback, &searchResults );
61+
62+
posList.clear();
63+
QList<QgsLabelPosition*>::const_iterator resultIt = searchResults.constBegin();
64+
for ( ; resultIt != searchResults.constEnd(); ++resultIt )
65+
{
66+
posList.push_back( *resultIt );
67+
}
68+
}
69+
70+
bool QgsLabelSearchTree::insertLabel( LabelPosition* labelPos, int featureId, const QString& layerName, bool diagram, bool frozen )
5571
{
5672
if ( !labelPos )
5773
{
@@ -68,7 +84,7 @@ bool QgsLabelSearchTree::insertLabel( LabelPosition* labelPos, int featureId, co
6884
cornerPoints.push_back( QgsPoint( labelPos->getX( i ), labelPos->getY( i ) ) );
6985
}
7086
QgsLabelPosition* newEntry = new QgsLabelPosition( featureId, labelPos->getAlpha(), cornerPoints, QgsRectangle( c_min[0], c_min[1], c_max[0], c_max[1] ),
71-
labelPos->getWidth(), labelPos->getHeight(), layerName, labelPos->getUpsideDown(), diagram );
87+
labelPos->getWidth(), labelPos->getHeight(), layerName, labelPos->getUpsideDown(), diagram, frozen );
7288
mSpatialIndex.Insert( c_min, c_max, newEntry );
7389
return true;
7490
}

‎src/core/qgslabelsearchtree.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ class CORE_EXPORT QgsLabelSearchTree
4242
/**Returns label position(s) at a given point. QgsLabelSearchTree keeps ownership, don't delete the LabelPositions*/
4343
void label( const QgsPoint& p, QList<QgsLabelPosition*>& posList );
4444

45+
/**Returns label position(s) in given rectangle. QgsLabelSearchTree keeps ownership, don't delete the LabelPositions*/
46+
void labelsInRect( const QgsRectangle& r, QList<QgsLabelPosition*>& posList );
47+
4548
/**Inserts label position. Does not take ownership of labelPos
4649
@return true in case of success*/
47-
bool insertLabel( LabelPosition* labelPos, int featureId, const QString& layerName, bool diagram = false );
50+
bool insertLabel( LabelPosition* labelPos, int featureId, const QString& layerName, bool diagram = false, bool frozen = false );
4851

4952
private:
5053
RTree<QgsLabelPosition*, double, 2, double> mSpatialIndex;

‎src/core/qgsmaprenderer.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ struct QgsDiagramLayerSettings;
4343

4444
struct CORE_EXPORT QgsLabelPosition
4545
{
46-
QgsLabelPosition( int id, double r, const QVector< QgsPoint >& corners, const QgsRectangle& rect, double w, double h, const QString& layer, bool upside_down, bool diagram = false ):
47-
featureId( id ), rotation( r ), cornerPoints( corners ), labelRect( rect ), width( w ), height( h ), layerID( layer ), upsideDown( upside_down ), isDiagram( diagram ) {}
48-
QgsLabelPosition(): featureId( -1 ), rotation( 0 ), labelRect( QgsRectangle() ), width( 0 ), height( 0 ), layerID( "" ), upsideDown( false ), isDiagram( false ) {}
46+
QgsLabelPosition( int id, double r, const QVector< QgsPoint >& corners, const QgsRectangle& rect, double w, double h, const QString& layer, bool upside_down, bool diagram = false, bool frozen = false ):
47+
featureId( id ), rotation( r ), cornerPoints( corners ), labelRect( rect ), width( w ), height( h ), layerID( layer ), upsideDown( upside_down ), isDiagram( diagram ), isFrozen( frozen ) {}
48+
QgsLabelPosition(): featureId( -1 ), rotation( 0 ), labelRect( QgsRectangle() ), width( 0 ), height( 0 ), layerID( "" ), upsideDown( false ), isDiagram( false ), isFrozen( false ) {}
4949
int featureId;
5050
double rotation;
5151
QVector< QgsPoint > cornerPoints;
@@ -55,6 +55,7 @@ struct CORE_EXPORT QgsLabelPosition
5555
QString layerID;
5656
bool upsideDown;
5757
bool isDiagram;
58+
bool isFrozen;
5859
};
5960

6061
/** Labeling engine interface.

‎src/core/qgspallabeling.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class QgsPalGeometry : public PalGeometry
6262
, mId( id )
6363
, mInfo( NULL )
6464
, mIsDiagram( false )
65+
, mIsFrozen( false )
6566
{
6667
mStrId = FID_TO_STRING( id ).toAscii();
6768
}
@@ -112,6 +113,9 @@ class QgsPalGeometry : public PalGeometry
112113
void setIsDiagram( bool d ) { mIsDiagram = d; }
113114
bool isDiagram() const { return mIsDiagram; }
114115

116+
void setIsFrozen( bool f ) { mIsFrozen = f; }
117+
bool isFrozen() const { return mIsFrozen; }
118+
115119
void addDiagramAttribute( int index, QVariant value ) { mDiagramAttributes.insert( index, value ); }
116120
const QgsAttributeMap& diagramAttributes() { return mDiagramAttributes; }
117121

@@ -122,6 +126,7 @@ class QgsPalGeometry : public PalGeometry
122126
QgsFeatureId mId;
123127
LabelInfo* mInfo;
124128
bool mIsDiagram;
129+
bool mIsFrozen;
125130
/**Stores attribute values for data defined properties*/
126131
QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant > mDataDefinedValues;
127132

@@ -706,6 +711,9 @@ void QgsPalLayerSettings::registerFeature( QgsVectorLayer* layer, QgsFeature& f
706711
{
707712
lbl->addDataDefinedValue( dIt.key(), f.attributeMap()[dIt.value()] );
708713
}
714+
715+
// set geometry's frozen property
716+
lbl->setIsFrozen( dataDefinedPosition );
709717
}
710718

711719
int QgsPalLayerSettings::sizeToPixel( double size, const QgsRenderContext& c ) const
@@ -1141,7 +1149,7 @@ void QgsPalLabeling::drawLabeling( QgsRenderContext& context )
11411149
//for diagrams, remove the additional 'd' at the end of the layer id
11421150
QString layerId = layerNameUtf8;
11431151
layerId.chop( 1 );
1144-
mLabelSearchTree->insertLabel( *it, QString( palGeometry->strId() ).toInt(), layerId, true );
1152+
mLabelSearchTree->insertLabel( *it, QString( palGeometry->strId() ).toInt(), layerId, true, false );
11451153
}
11461154
continue;
11471155
}
@@ -1224,7 +1232,7 @@ void QgsPalLabeling::drawLabeling( QgsRenderContext& context )
12241232

12251233
if ( mLabelSearchTree )
12261234
{
1227-
mLabelSearchTree->insertLabel( *it, QString( palGeometry->strId() ).toInt(), ( *it )->getLayerName() );
1235+
mLabelSearchTree->insertLabel( *it, QString( palGeometry->strId() ).toInt(), ( *it )->getLayerName(), false, palGeometry->isFrozen() );
12281236
}
12291237
}
12301238

@@ -1274,6 +1282,24 @@ QList<QgsLabelPosition> QgsPalLabeling::labelsAtPosition( const QgsPoint& p )
12741282
return positions;
12751283
}
12761284

1285+
QList<QgsLabelPosition> QgsPalLabeling::labelsWithinRect( const QgsRectangle& r )
1286+
{
1287+
QList<QgsLabelPosition> positions;
1288+
1289+
QList<QgsLabelPosition*> positionPointers;
1290+
if ( mLabelSearchTree )
1291+
{
1292+
mLabelSearchTree->labelsInRect( r, positionPointers );
1293+
QList<QgsLabelPosition*>::const_iterator pointerIt = positionPointers.constBegin();
1294+
for ( ; pointerIt != positionPointers.constEnd(); ++pointerIt )
1295+
{
1296+
positions.push_back( QgsLabelPosition( **pointerIt ) );
1297+
}
1298+
}
1299+
1300+
return positions;
1301+
}
1302+
12771303
void QgsPalLabeling::numCandidatePositions( int& candPoint, int& candLine, int& candPolygon )
12781304
{
12791305
candPoint = mCandPoint;

‎src/core/qgspallabeling.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class QgsMapToPixel;
4848
class QgsFeature;
4949

5050
#include "qgspoint.h"
51+
#include "qgsrectangle.h"
5152
#include "qgsmaprenderer.h" // definition of QgsLabelingEngineInterface
5253
#include "qgsexpression.h"
5354

@@ -224,6 +225,8 @@ class CORE_EXPORT QgsPalLabeling : public QgsLabelingEngineInterface
224225
virtual void exit();
225226
//! return infos about labels at a given (map) position
226227
virtual QList<QgsLabelPosition> labelsAtPosition( const QgsPoint& p );
228+
//! return infos about labels within a given (map) rectangle
229+
virtual QList<QgsLabelPosition> labelsWithinRect( const QgsRectangle& r );
227230

228231
//! called when passing engine among map renderers
229232
virtual QgsLabelingEngineInterface* clone();

‎src/ui/qgisapp.ui

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@
394394
<bool>false</bool>
395395
</attribute>
396396
<addaction name="mActionLabeling"/>
397+
<addaction name="mActionShowFrozenLabels"/>
398+
<addaction name="mActionFreezeLabels"/>
397399
<addaction name="mActionMoveLabel"/>
398400
<addaction name="mActionRotateLabel"/>
399401
<addaction name="mActionChangeLabelProperties"/>
@@ -1698,6 +1700,41 @@
16981700
<string>Creates a scale bar that is displayed on the map canvas</string>
16991701
</property>
17001702
</action>
1703+
<action name="mActionFreezeLabels">
1704+
<property name="checkable">
1705+
<bool>true</bool>
1706+
</property>
1707+
<property name="icon">
1708+
<iconset resource="../../images/images.qrc">
1709+
<normaloff>:/images/themes/default/mActionFreezeLabels.png</normaloff>:/images/themes/default/mActionFreezeLabels.png</iconset>
1710+
</property>
1711+
<property name="text">
1712+
<string>Freeze or Thaw Labels</string>
1713+
</property>
1714+
<property name="whatsThis">
1715+
<string>Freeze (write label location and optionally rotation) to attribute table.
1716+
1717+
Click on individual labels, or draw a marquee (labels touching will be included). Actions on in-memory attribute table fields are immediate.
1718+
1719+
Hold Shift key down to Thaw (write NULLs to attribute table), reverting label to dynamic.
1720+
Hold Alt key down to toggle selected labels between Frozen and Thawed states.</string>
1721+
</property>
1722+
</action>
1723+
<action name="mActionShowFrozenLabels">
1724+
<property name="checkable">
1725+
<bool>true</bool>
1726+
</property>
1727+
<property name="icon">
1728+
<iconset resource="../../images/images.qrc">
1729+
<normaloff>:/images/themes/default/mActionShowFrozenLabels.png</normaloff>:/images/themes/default/mActionShowFrozenLabels.png</iconset>
1730+
</property>
1731+
<property name="text">
1732+
<string>Show Frozen Labels</string>
1733+
</property>
1734+
<property name="toolTip">
1735+
<string>Show Frozen Labels</string>
1736+
</property>
1737+
</action>
17011738
<action name="mActionNewBlankProject">
17021739
<property name="icon">
17031740
<iconset resource="../../images/images.qrc">

0 commit comments

Comments
 (0)
Please sign in to comment.