Skip to content
Permalink
Browse files

fix #926

git-svn-id: http://svn.osgeo.org/qgis/trunk@15315 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Mar 3, 2011
1 parent 9cb502e commit 949d9fab426ad0d9e491f6b4d357dc684e91b41c
@@ -91,6 +91,7 @@ SET(QGIS_APP_SRCS
qgsuniquevaluedialog.cpp
qgsvectorlayerproperties.cpp
qgsquerybuilder.cpp
qgshighlight.cpp

qgsmanageconnectionsdialog.cpp

@@ -24,7 +24,7 @@
#include "qgsuniquevaluerenderer.h"
#include "qgssymbol.h"
#include "qgsattributeeditor.h"
#include "qgsrubberband.h"
#include "qgshighlight.h"
#include "qgssearchstring.h"
#include "qgssearchtreenode.h"

@@ -52,7 +52,7 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
, mLayer( vl )
, mFeature( thepFeature )
, mFeatureOwner( featureOwner )
, mRubberBand( 0 )
, mHighlight( 0 )
, mFormNr( -1 )
{
if ( !mFeature || !vl->dataProvider() )
@@ -299,10 +299,10 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat

QgsAttributeDialog::~QgsAttributeDialog()
{
if ( mRubberBand )
if ( mHighlight )
{
mRubberBand->hide();
delete mRubberBand;
mHighlight->hide();
delete mHighlight;
}

if ( mFeatureOwner )
@@ -381,14 +381,14 @@ void QgsAttributeDialog::restoreGeometry()
}
}

void QgsAttributeDialog::setHighlight( QgsRubberBand *rb )
void QgsAttributeDialog::setHighlight( QgsHighlight *h )
{
if ( mRubberBand )
if ( mHighlight )
{
delete mRubberBand;
delete mHighlight;
}

mRubberBand = rb;
mHighlight = h;
}


@@ -410,15 +410,15 @@ void QgsAttributeDialog::dialogDestroyed()

bool QgsAttributeDialog::eventFilter( QObject *obj, QEvent *e )
{
if ( mRubberBand && obj == mDialog )
if ( mHighlight && obj == mDialog )
{
switch ( e->type() )
{
case QEvent::WindowActivate:
mRubberBand->show();
mHighlight->show();
break;
case QEvent::WindowDeactivate:
mRubberBand->hide();
mHighlight->hide();
break;
default:
break;
@@ -25,7 +25,7 @@ class QgsFeature;
class QLayout;
class QgsField;
class QgsVectorLayer;
class QgsRubberBand;
class QgsHighlight;

class QgsAttributeDialog : public QObject
{
@@ -46,7 +46,7 @@ class QgsAttributeDialog : public QObject
*/
void restoreGeometry();

void setHighlight( QgsRubberBand *rb );
void setHighlight( QgsHighlight *h );

QDialog *dialog() { return mDialog; }

@@ -68,7 +68,7 @@ class QgsAttributeDialog : public QObject
QgsVectorLayer *mLayer;
QgsFeature *mFeature;
bool mFeatureOwner;
QgsRubberBand *mRubberBand;
QgsHighlight *mHighlight;
int mFormNr;
static int smFormCounter;
};
@@ -72,13 +72,13 @@ QgsAttributeDialog *QgsFeatureAction::newDialog( bool cloneFeature )
return dialog;
}

bool QgsFeatureAction::viewFeatureForm( QgsRubberBand *rb )
bool QgsFeatureAction::viewFeatureForm( QgsHighlight *h )
{
if ( !mLayer )
return false;

QgsAttributeDialog *dialog = newDialog( true );
dialog->setHighlight( rb );
dialog->setHighlight( h );
dialog->show();

return true;
@@ -26,7 +26,7 @@

class QgsIdentifyResults;
class QgsVectorLayer;
class QgsRubberBand;
class QgsHighlight;
class QgsAttributeDialog;

class QgsFeatureAction : public QAction
@@ -38,7 +38,7 @@ class QgsFeatureAction : public QAction

public slots:
void execute();
bool viewFeatureForm( QgsRubberBand *rb = 0 );
bool viewFeatureForm( QgsHighlight *h = 0 );
bool editFeature();
bool addFeature();

@@ -0,0 +1,244 @@
/***************************************************************************
qgshighlight.cpp - widget to highlight features on the map
--------------------------------------
Date : 02-03-2011
Copyright : (C) 2011 by Juergen E. Fischer, norBIT GmbH
Email : jef at norbit dot de
***************************************************************************
* *
* 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. *
* *
***************************************************************************/
/* $Id$ */

#include "qgshighlight.h"
#include "qgsgeometry.h"
#include "qgslogger.h"
#include "qgsmapcanvas.h"
#include "qgsmaprenderer.h"
#include "qgsvectorlayer.h"
#include <QPainter>

/*!
\class QgsHighlight
\brief The QgsHighlight class provides a transparent overlay widget
for highlightng features on the map.
*/
QgsHighlight::QgsHighlight( QgsMapCanvas* mapCanvas, QgsGeometry *geom, QgsVectorLayer *layer )
: QgsMapCanvasItem( mapCanvas )
, mLayer( layer )
{
QgsDebugMsg( geom ? "geometry!" : "no geometry" );
mGeometry = geom ? new QgsGeometry( *geom ) : 0;
updateRect();
update();
setColor( QColor( Qt::lightGray ) );
}

QgsHighlight::~QgsHighlight()
{
delete mGeometry;
}

/*!
Set the outline and fill color.
*/
void QgsHighlight::setColor( const QColor & color )
{
mPen.setColor( color );
QColor fillColor( color.red(), color.green(), color.blue(), 63 );
mBrush.setColor( fillColor );
mBrush.setStyle( Qt::SolidPattern );
}

/*!
Set the outline width.
*/
void QgsHighlight::setWidth( int width )
{
mPen.setWidth( width );
}

void QgsHighlight::paintPoint( QPainter *p, QgsPoint point )
{
QPolygonF r( 5 );

double d = mMapCanvas->extent().width() * 0.005;

if ( mLayer )
{
point = mMapCanvas->mapRenderer()->layerToMapCoordinates( mLayer, point );
}

r[0] = toCanvasCoordinates( point + QgsVector( -d, -d ) ) - pos();
r[1] = toCanvasCoordinates( point + QgsVector( d, -d ) ) - pos();
r[2] = toCanvasCoordinates( point + QgsVector( d, d ) ) - pos();
r[3] = toCanvasCoordinates( point + QgsVector( -d, d ) ) - pos();
r[4] = r[0];

p->drawPolygon( r );
}

void QgsHighlight::paintLine( QPainter *p, QgsPolyline line )
{
QPolygonF polygon( line.size() );

for ( int i = 0; i < line.size(); i++ )
{
if ( mLayer )
{
line[i] = mMapCanvas->mapRenderer()->layerToMapCoordinates( mLayer, line[i] );
}

polygon[i] = toCanvasCoordinates( line[i] ) - pos();
}

p->drawPolyline( polygon );
}

void QgsHighlight::paintPolygon( QPainter *p, QgsPolygon polygon )
{
QPolygonF poly;

// just ring outlines, no fill
p->setPen( mPen );
p->setBrush( Qt::NoBrush );

for ( int i = 0; i < polygon.size(); i++ )
{
QPolygonF ring( polygon[i].size() + 1 );

for ( int j = 0; j < polygon[i].size(); j++ )
{
if ( mLayer )
{
polygon[i][j] = mMapCanvas->mapRenderer()->layerToMapCoordinates( mLayer, polygon[i][j] );
}

ring[ j ] = toCanvasCoordinates( polygon[i][j] ) - pos();
}

ring[ polygon[i].size()] = ring[ 0 ];

p->drawPolygon( ring );

if ( i == 0 )
poly = ring;
else
poly = poly.subtracted( ring );

}

// just fill, no outline
p->setPen( Qt::NoPen );
p->setBrush( mBrush );
p->drawPolygon( poly );
}

/*!
Draw the shape in response to an update event.
*/
void QgsHighlight::paint( QPainter* p )
{
QgsDebugMsg( "entered." );

if ( !mGeometry )
{
QgsDebugMsg( "no geometry." );
return;
}

p->setPen( mPen );
p->setBrush( mBrush );

switch ( mGeometry->wkbType() )
{
case QGis::WKBPoint:
case QGis::WKBPoint25D:
{
paintPoint( p, mGeometry->asPoint() );
}
break;

case QGis::WKBMultiPoint:
case QGis::WKBMultiPoint25D:
{
QgsMultiPoint m = mGeometry->asMultiPoint();
for ( int i = 0; i < m.size(); i++ )
{
paintPoint( p, m[i] );
}
}
break;

case QGis::WKBLineString:
case QGis::WKBLineString25D:
{
paintLine( p, mGeometry->asPolyline() );
}
break;

case QGis::WKBMultiLineString:
case QGis::WKBMultiLineString25D:
{
QgsMultiPolyline m = mGeometry->asMultiPolyline();

for ( int i = 0; i < m.size(); i++ )
{
paintLine( p, m[i] );
}
}
break;

case QGis::WKBPolygon:
case QGis::WKBPolygon25D:
{
paintPolygon( p, mGeometry->asPolygon() );
}
break;

case QGis::WKBMultiPolygon:
case QGis::WKBMultiPolygon25D:
{
QgsMultiPolygon m = mGeometry->asMultiPolygon();
for ( int i = 0; i < m.size(); i++ )
{
paintPolygon( p, m[i] );
}
}
break;

case QGis::WKBUnknown:
default:
return;
}
}

void QgsHighlight::updateRect()
{
if ( mGeometry )
{
QgsRectangle r = mGeometry->boundingBox();

if ( r.isEmpty() )
{
double d = mMapCanvas->extent().width() * 0.005;
r.setXMinimum( r.xMinimum() - d );
r.setYMinimum( r.yMinimum() - d );
r.setXMaximum( r.xMaximum() + d );
r.setXMaximum( r.yMaximum() + d );
}

setRect( r );
setVisible( mGeometry );
}
else
{
setRect( QgsRectangle() );
}

}

0 comments on commit 949d9fa

Please sign in to comment.
You can’t perform that action at this time.