mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Fix pinned labels highlight causing forward transformation error by using QgsRubberBand instead
This commit is contained in:
parent
621dcce4d9
commit
551648f3a6
@ -25,7 +25,6 @@
|
||||
#include "qgsvectorlayer.h"
|
||||
|
||||
#include "qgsmaptoolselectutils.h"
|
||||
#include "qgshighlight.h"
|
||||
#include "qgsrubberband.h"
|
||||
#include <qgslogger.h>
|
||||
#include <QMouseEvent>
|
||||
@ -137,35 +136,22 @@ void QgsMapToolPinLabels::updatePinnedLabels()
|
||||
}
|
||||
}
|
||||
|
||||
void QgsMapToolPinLabels::highlightLabel( QgsVectorLayer* vlayer,
|
||||
const QgsLabelPosition& labelpos,
|
||||
void QgsMapToolPinLabels::highlightLabel( const QgsLabelPosition& labelpos,
|
||||
const QString& id,
|
||||
const QColor& color )
|
||||
{
|
||||
QgsRectangle rect = labelpos.labelRect;
|
||||
QgsRubberBand *rb = new QgsRubberBand( mCanvas, QGis::Polygon );
|
||||
rb->addPoint( QgsPoint( rect.xMinimum(), rect.yMinimum() ) );
|
||||
rb->addPoint( QgsPoint( rect.xMinimum(), rect.yMaximum() ) );
|
||||
rb->addPoint( QgsPoint( rect.xMaximum(), rect.yMaximum() ) );
|
||||
rb->addPoint( QgsPoint( rect.xMaximum(), rect.yMinimum() ) );
|
||||
rb->addPoint( QgsPoint( rect.xMinimum(), rect.yMinimum() ) );
|
||||
rb->setColor( color );
|
||||
rb->setWidth( 0 );
|
||||
rb->show();
|
||||
|
||||
const QgsMapSettings& ms = mCanvas->mapSettings();
|
||||
if ( vlayer->crs().isValid() && ms.destinationCrs().isValid() )
|
||||
{
|
||||
// if label's layer is on-fly transformed, reverse-transform label rect
|
||||
// QgsHighlight will convert it, yet again, to the correct map coords
|
||||
if ( vlayer->crs() != ms.destinationCrs() )
|
||||
{
|
||||
rect = ms.mapToLayerCoordinates( vlayer, rect );
|
||||
QgsDebugMsg( QString( "Reverse transform needed for highlight rectangle" ) );
|
||||
}
|
||||
}
|
||||
|
||||
QgsGeometry* highlightgeom = QgsGeometry::fromRect( rect );
|
||||
|
||||
QgsHighlight *h = new QgsHighlight( mCanvas, highlightgeom, vlayer );
|
||||
if ( h )
|
||||
{
|
||||
h->setWidth( 0 );
|
||||
h->setColor( color );
|
||||
h->show();
|
||||
mHighlights.insert( id, h );
|
||||
}
|
||||
mHighlights.insert( id, rb );
|
||||
}
|
||||
|
||||
// public slot to render highlight rectangles around pinned labels
|
||||
@ -209,7 +195,7 @@ void QgsMapToolPinLabels::highlightPinnedLabels()
|
||||
continue;
|
||||
}
|
||||
|
||||
QColor lblcolor = QColor( 54, 129, 255, 255 );
|
||||
QColor lblcolor = QColor( 54, 129, 255, 63 );
|
||||
QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( mCurrentLabelPos.layerID );
|
||||
if ( !layer )
|
||||
{
|
||||
@ -223,10 +209,10 @@ void QgsMapToolPinLabels::highlightPinnedLabels()
|
||||
}
|
||||
if ( vlayer->isEditable() )
|
||||
{
|
||||
lblcolor = QColor( 54, 129, 0, 255 );
|
||||
lblcolor = QColor( 54, 129, 0, 63 );
|
||||
}
|
||||
|
||||
highlightLabel( vlayer, ( *it ), labelStringID, lblcolor );
|
||||
highlightLabel(( *it ), labelStringID, lblcolor );
|
||||
}
|
||||
}
|
||||
QApplication::restoreOverrideCursor();
|
||||
@ -235,9 +221,9 @@ void QgsMapToolPinLabels::highlightPinnedLabels()
|
||||
void QgsMapToolPinLabels::removePinnedHighlights()
|
||||
{
|
||||
QApplication::setOverrideCursor( Qt::BusyCursor );
|
||||
foreach ( QgsHighlight *h, mHighlights )
|
||||
foreach ( QgsRubberBand *rb, mHighlights )
|
||||
{
|
||||
delete h;
|
||||
delete rb;
|
||||
}
|
||||
mHighlights.clear();
|
||||
QApplication::restoreOverrideCursor();
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include "qgslegend.h"
|
||||
#include "qgscoordinatetransform.h"
|
||||
|
||||
class QgsHighlight;
|
||||
class QgsRubberBand;
|
||||
class QgsLabelPosition;
|
||||
|
||||
/**A map tool for pinning (writing to attribute table) and unpinning labelpositions and rotation*/
|
||||
@ -64,7 +64,7 @@ class APP_EXPORT QgsMapToolPinLabels: public QgsMapToolLabel
|
||||
protected:
|
||||
|
||||
//! Mapping of feature ids of layers that have been highlighted
|
||||
QMap<QString, QgsHighlight*> mHighlights;
|
||||
QMap<QString, QgsRubberBand*> mHighlights;
|
||||
|
||||
//! Flag to indicate a map canvas drag operation is taking place
|
||||
bool mDragging;
|
||||
@ -80,8 +80,7 @@ class APP_EXPORT QgsMapToolPinLabels: public QgsMapToolLabel
|
||||
private:
|
||||
|
||||
//! Highlights a given label relative to whether its pinned and editable
|
||||
void highlightLabel( QgsVectorLayer* vlayer,
|
||||
const QgsLabelPosition& labelpos,
|
||||
void highlightLabel( const QgsLabelPosition& labelpos,
|
||||
const QString& id,
|
||||
const QColor& color );
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user