[QGIS Commit] r12307 - trunk/qgis/src/app
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Tue Dec 1 18:25:22 EST 2009
Author: jef
Date: 2009-12-01 18:25:20 -0500 (Tue, 01 Dec 2009)
New Revision: 12307
Modified:
trunk/qgis/src/app/qgsidentifyresults.cpp
trunk/qgis/src/app/qgsidentifyresults.h
Log:
[FEATURE] identify tool highlighting changed
- identified features are highlighted by default [fixed #2169]
- clicking on a feature or attribute highlights the feature
- clicking on a layer highlights all identified features on that layer
- context menu now also has "highlight all" and "highlight layer"
Modified: trunk/qgis/src/app/qgsidentifyresults.cpp
===================================================================
--- trunk/qgis/src/app/qgsidentifyresults.cpp 2009-12-01 21:08:39 UTC (rev 12306)
+++ trunk/qgis/src/app/qgsidentifyresults.cpp 2009-12-01 23:25:20 UTC (rev 12307)
@@ -92,7 +92,6 @@
QgsIdentifyResults::QgsIdentifyResults( QgsMapCanvas *canvas, QWidget *parent, Qt::WFlags f )
: QDialog( parent, f ),
mActionPopup( 0 ),
- mRubberBand( 0 ),
mCanvas( canvas ),
mDock( NULL )
{
@@ -215,6 +214,8 @@
}
layItem->addChild( featItem );
+
+ highlightFeature( featItem );
}
void QgsIdentifyResults::editingToggled()
@@ -263,13 +264,11 @@
QTreeWidgetItem *layItem = lstResults->topLevelItem( 0 );
QTreeWidgetItem *featItem = layItem->child( 0 );
- if ( layItem->childCount() == 1 && QSettings().value( "/Map/identifyAutoFeatureForm", false ).toBool() )
+ if ( lstResults->topLevelItemCount() == 1 && layItem->childCount() == 1 && QSettings().value( "/Map/identifyAutoFeatureForm", false ).toBool() )
{
QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( layItem->data( 0, Qt::UserRole ).value<QObject *>() );
if ( layer )
{
- highlightFeature( featItem );
-
// if this is the only feature and it's on a vector layer
// don't show the form dialog instead of the results window
lstResults->setCurrentItem( featItem );
@@ -341,6 +340,8 @@
mActionPopup->addAction( tr( "Copy attribute value" ), this, SLOT( copyAttributeValue() ) );
mActionPopup->addAction( tr( "Copy feature attributes" ), this, SLOT( copyFeatureAttributes() ) );
mActionPopup->addSeparator();
+ mActionPopup->addAction( tr( "Highlight all" ), this, SLOT( highlightAll() ) );
+ mActionPopup->addAction( tr( "Highlight layer" ), this, SLOT( highlightLayer() ) );
mActionPopup->addAction( tr( "Expand all" ), this, SLOT( expandAll() ) );
mActionPopup->addAction( tr( "Collapse all" ), this, SLOT( collapseAll() ) );
@@ -405,14 +406,14 @@
}
lstResults->clear();
- clearRubberBand();
+ mRubberBands.clear();
}
void QgsIdentifyResults::activate()
{
- if ( mRubberBand )
+ foreach( QSharedPointer<QgsRubberBand> rb, mRubberBands )
{
- mRubberBand->show();
+ rb->show();
}
if ( lstResults->topLevelItemCount() > 0 )
@@ -424,23 +425,12 @@
void QgsIdentifyResults::deactivate()
{
- if ( mRubberBand )
+ foreach( QSharedPointer<QgsRubberBand> rb, mRubberBands )
{
- mRubberBand->hide();
+ rb->hide();
}
}
-void QgsIdentifyResults::clearRubberBand()
-{
- if ( !mRubberBand )
- return;
-
- delete mRubberBand;
- mRubberBand = 0;
- mRubberBandLayer = 0;
- mRubberBandFid = 0;
-}
-
void QgsIdentifyResults::doAction( QTreeWidgetItem *item, int action )
{
int idx;
@@ -507,13 +497,22 @@
return featItem;
}
-QgsVectorLayer *QgsIdentifyResults::vectorLayer( QTreeWidgetItem *item )
+QTreeWidgetItem *QgsIdentifyResults::layerItem( QTreeWidgetItem *item )
{
- if ( item->parent() )
+ if ( item && item->parent() )
{
item = featureItem( item )->parent();
}
+ return item;
+}
+
+
+QgsVectorLayer *QgsIdentifyResults::vectorLayer( QTreeWidgetItem *item )
+{
+ item = layerItem( item );
+ if ( !item )
+ return NULL;
return qobject_cast<QgsVectorLayer *>( item->data( 0, Qt::UserRole ).value<QObject *>() );
}
@@ -543,7 +542,7 @@
expandColumnsToFit();
}
-void QgsIdentifyResults::handleCurrentItemChanged( QTreeWidgetItem* current, QTreeWidgetItem* previous )
+void QgsIdentifyResults::handleCurrentItemChanged( QTreeWidgetItem *current, QTreeWidgetItem *previous )
{
if ( current == NULL )
{
@@ -551,16 +550,34 @@
return;
}
- highlightFeature( current );
+ QTreeWidgetItem *layItem = layerItem( current );
+
+ if ( current == layItem )
+ {
+ highlightLayer( layItem );
+ }
+ else
+ {
+ mRubberBands.clear();
+ highlightFeature( current );
+ }
}
void QgsIdentifyResults::layerDestroyed()
{
QObject *theSender = sender();
- if ( mRubberBandLayer == theSender )
+ for ( int i = 0; i < lstResults->topLevelItemCount(); i++ )
{
- clearRubberBand();
+ QTreeWidgetItem *layItem = lstResults->topLevelItem( i );
+
+ if ( layItem->data( 0, Qt::UserRole ).value<QObject *>() == sender() )
+ {
+ for ( int j = 0; j < layItem->childCount(); j++ )
+ {
+ mRubberBands.remove( layItem->child( i ) );
+ }
+ }
}
disconnectLayer( theSender );
@@ -604,17 +621,13 @@
if ( featItem && featItem->data( 0, Qt::UserRole ).toInt() == fid )
{
- if ( mRubberBandLayer == sender() && mRubberBandFid == fid )
- clearRubberBand();
- delete featItem;
+ mRubberBands.remove( featItem );
break;
}
}
if ( layItem->childCount() == 0 )
{
- if ( mRubberBandLayer == sender() )
- clearRubberBand();
delete layItem;
}
@@ -634,10 +647,11 @@
if ( !featItem )
return;
+ if ( mRubberBands.contains( featItem ) )
+ return;
+
int fid = featItem->data( 0, Qt::UserRole ).toInt();
- clearRubberBand();
-
QgsFeature feat;
if ( ! layer->featureAtId( fid, feat, true, false ) )
{
@@ -649,15 +663,14 @@
return;
}
- mRubberBand = new QgsRubberBand( mCanvas, feat.geometry()->type() == QGis::Polygon );
- if ( mRubberBand )
+ QgsRubberBand *rb = new QgsRubberBand( mCanvas, feat.geometry()->type() == QGis::Polygon );
+ if ( rb )
{
- mRubberBandLayer = layer;
- mRubberBandFid = fid;
- mRubberBand->setToGeometry( feat.geometry(), layer );
- mRubberBand->setWidth( 2 );
- mRubberBand->setColor( Qt::red );
- mRubberBand->show();
+ rb->setToGeometry( feat.geometry(), layer );
+ rb->setWidth( 2 );
+ rb->setColor( Qt::red );
+ rb->show();
+ mRubberBands.insert( featItem, QSharedPointer<QgsRubberBand>( rb ) );
}
}
@@ -768,6 +781,39 @@
mCanvas->refresh();
}
+void QgsIdentifyResults::highlightAll()
+{
+ for ( int i = 0; i < lstResults->topLevelItemCount(); i++ )
+ {
+ QTreeWidgetItem *layItem = lstResults->topLevelItem( i );
+
+ for ( int j = 0; j < layItem->childCount(); j++ )
+ {
+ highlightFeature( layItem->child( j ) );
+ }
+ }
+}
+
+void QgsIdentifyResults::highlightLayer()
+{
+ highlightLayer( lstResults->currentItem() );
+}
+
+void QgsIdentifyResults::highlightLayer( QTreeWidgetItem *item )
+{
+ QTreeWidgetItem *layItem = layerItem( item );
+ if ( !layItem )
+ return;
+
+ mRubberBands.clear();
+
+ for ( int i = 0; i < layItem->childCount(); i++ )
+ {
+ highlightFeature( layItem->child( i ) );
+ }
+}
+
+
void QgsIdentifyResults::expandAll()
{
lstResults->expandAll();
Modified: trunk/qgis/src/app/qgsidentifyresults.h
===================================================================
--- trunk/qgis/src/app/qgsidentifyresults.h 2009-12-01 21:08:39 UTC (rev 12306)
+++ trunk/qgis/src/app/qgsidentifyresults.h 2009-12-01 23:25:20 UTC (rev 12307)
@@ -25,6 +25,7 @@
#include <QWidget>
#include <QList>
+#include <QSharedPointer>
class QCloseEvent;
class QTreeWidgetItem;
@@ -88,6 +89,8 @@
void zoomToFeature();
void copyAttributeValue();
void copyFeatureAttributes();
+ void highlightAll();
+ void highlightLayer();
void expandAll();
void collapseAll();
@@ -107,16 +110,15 @@
private:
QMenu *mActionPopup;
- QgsVectorLayer *mRubberBandLayer;
- int mRubberBandFid;
- QgsRubberBand *mRubberBand;
+ QMap<QTreeWidgetItem *, QSharedPointer<QgsRubberBand> > mRubberBands;
QgsMapCanvas *mCanvas;
QgsVectorLayer *vectorLayer( QTreeWidgetItem *item );
QTreeWidgetItem *featureItem( QTreeWidgetItem *item );
+ QTreeWidgetItem *layerItem( QTreeWidgetItem *item );
QTreeWidgetItem *layerItem( QObject *layer );
- void clearRubberBand();
+ void highlightLayer( QTreeWidgetItem *object );
void disconnectLayer( QObject *object );
void setColumnText( int column, const QString & label );
More information about the QGIS-commit
mailing list