Skip to content
Permalink
Browse files

identify tool improvements

git-svn-id: http://svn.osgeo.org/qgis/trunk@11577 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Sep 6, 2009
1 parent 0f11b58 commit 56e45d6d8f0470f358ae5d54afa3a532daa6db99
Showing with 173 additions and 27 deletions.
  1. +142 −19 src/app/qgsidentifyresults.cpp
  2. +15 −6 src/app/qgsidentifyresults.h
  3. +12 −0 src/app/qgsmaptoolidentify.cpp
  4. +4 −2 src/app/qgsmaptoolidentify.h
@@ -107,6 +107,10 @@ void QgsIdentifyResults::addFeature( QgsMapLayer *layer, int fid,
lstResults->addTopLevelItem( item );

connect( layer, SIGNAL( destroyed() ), this, SLOT( layerDestroyed() ) );

QgsVectorLayer *vlayer = dynamic_cast<QgsVectorLayer*>( layer );
if ( vlayer )
connect( vlayer, SIGNAL( featureDeleted( int ) ), this, SLOT( featureDeleted( int ) ) );
}

QTreeWidgetItem *featItem = new QTreeWidgetItem( QStringList() << displayField << displayValue );
@@ -183,9 +187,13 @@ void QgsIdentifyResults::contextMenuEvent( QContextMenuEvent* event )
{
a = mActionPopup->addAction( tr( "Edit feature" ) );
a->setEnabled( true );
a->setData( QVariant::fromValue( -3 ) );
a->setData( QVariant::fromValue( -4 ) );
}

a = mActionPopup->addAction( tr( "Zoom to feature" ) );
a->setEnabled( true );
a->setData( QVariant::fromValue( -3 ) );

a = mActionPopup->addAction( tr( "Copy attribute value" ) );
a->setEnabled( true );
a->setData( QVariant::fromValue( -2 ) );
@@ -252,30 +260,37 @@ void QgsIdentifyResults::popupItemSelected( QAction* menuAction )

if ( id < 0 )
{
QClipboard *clipboard = QApplication::clipboard();
QString text;

if ( id == -3 )
if ( id == -4 )
{
editFeature( item );
}
else if ( id == -2 )
else if ( id == -3 )
{
text = item->data( 1, Qt::DisplayRole ).toString();
zoomToFeature( item );
}
else
{
std::vector< std::pair<QString, QString> > attributes;
retrieveAttributes( item, attributes );
QClipboard *clipboard = QApplication::clipboard();
QString text;

for ( std::vector< std::pair<QString, QString> >::iterator it = attributes.begin(); it != attributes.end(); it++ )
if ( id == -2 )
{
text += QString( "%1: %2\n" ).arg( it->first ).arg( it->second );
text = item->data( 1, Qt::DisplayRole ).toString();
}
}
else
{
std::vector< std::pair<QString, QString> > attributes;
retrieveAttributes( item, attributes );

QgsDebugMsg( QString( "set clipboard: %1" ).arg( text ) );
clipboard->setText( text );
for ( std::vector< std::pair<QString, QString> >::iterator it = attributes.begin(); it != attributes.end(); it++ )
{
text += QString( "%1: %2\n" ).arg( it->first ).arg( it->second );
}
}

QgsDebugMsg( QString( "set clipboard: %1" ).arg( text ) );
clipboard->setText( text );
}
}
else
{
@@ -292,14 +307,42 @@ void QgsIdentifyResults::expandColumnsToFit()
void QgsIdentifyResults::clear()
{
lstResults->clear();
clearRubberBand();
}

void QgsIdentifyResults::activate()
{
if ( mRubberBand )
{
mRubberBand->show();
}

if ( lstResults->topLevelItemCount() > 0 )
{
show();
raise();
}
}

void QgsIdentifyResults::deactivate()
{
if ( mRubberBand )
{
delete mRubberBand;
mRubberBand = 0;
mRubberBand->hide();
}
}

void QgsIdentifyResults::clearRubberBand()
{
if ( !mRubberBand )
return;

delete mRubberBand;
mRubberBand = 0;
mRubberBandLayer = 0;
mRubberBandFid = 0;
}

void QgsIdentifyResults::doAction( QTreeWidgetItem *item )
{
std::vector< std::pair<QString, QString> > attributes;
@@ -394,7 +437,50 @@ void QgsIdentifyResults::handleCurrentItemChanged( QTreeWidgetItem* current, QTr

void QgsIdentifyResults::layerDestroyed()
{
if ( mRubberBandLayer == sender() )
{
clearRubberBand();
}

delete layerItem( sender() );

if ( lstResults->topLevelItemCount() == 0 )
{
hide();
}
}

void QgsIdentifyResults::featureDeleted( int fid )
{
QTreeWidgetItem *layItem = layerItem( sender() );

if ( !layItem )
return;

for ( int i = 0; i < layItem->childCount(); i++ )
{
QTreeWidgetItem *featItem = layItem->child( i );

if ( featItem && featItem->data( 0, Qt::UserRole ).toInt() == fid )
{
if ( mRubberBandLayer == sender() && mRubberBandFid == fid )
clearRubberBand();
delete featItem;
break;
}
}

if ( layItem->childCount() == 0 )
{
if ( mRubberBandLayer == sender() )
clearRubberBand();
delete layItem;
}

if ( lstResults->topLevelItemCount() == 0 )
{
hide();
}
}

void QgsIdentifyResults::highlightFeature( QTreeWidgetItem *item )
@@ -409,8 +495,7 @@ void QgsIdentifyResults::highlightFeature( QTreeWidgetItem *item )

int fid = featItem->data( 0, Qt::UserRole ).toInt();

delete mRubberBand;
mRubberBand = 0;
clearRubberBand();

QgsFeature feat;
if ( ! layer->featureAtId( fid, feat, true, false ) )
@@ -424,16 +509,54 @@ void QgsIdentifyResults::highlightFeature( QTreeWidgetItem *item )
}

mRubberBand = new QgsRubberBand( mCanvas, feat.geometry()->type() == QGis::Polygon );

if ( mRubberBand )
{
mRubberBandLayer = layer;
mRubberBandFid = fid;
mRubberBand->setToGeometry( feat.geometry(), layer );
mRubberBand->setWidth( 2 );
mRubberBand->setColor( Qt::red );
mRubberBand->show();
}
}

void QgsIdentifyResults::zoomToFeature( QTreeWidgetItem *item )
{
QgsVectorLayer *layer = vectorLayer( item );
if ( !layer )
return;

QTreeWidgetItem *featItem = featureItem( item );
if ( !featItem )
return;

int fid = featItem->data( 0, Qt::UserRole ).toInt();

QgsFeature feat;
if ( ! layer->featureAtId( fid, feat, true, false ) )
{
return;
}

if ( !feat.geometry() )
{
return;
}

QgsRectangle rect = mCanvas->mapRenderer()->layerExtentToOutputExtent( layer, feat.geometry()->boundingBox() );

if ( rect.isEmpty() )
{
QgsPoint c = rect.center();
rect = mCanvas->extent();
rect.expand( 0.25, &c );
}

mCanvas->setExtent( rect );
mCanvas->refresh();
}


void QgsIdentifyResults::editFeature( QTreeWidgetItem *item )
{
QgsVectorLayer *layer = vectorLayer( item );
@@ -50,19 +50,22 @@ class QgsIdentifyResults: public QDialog, private Ui::QgsIdentifyResultsBase

~QgsIdentifyResults();

/** Remove results */
void clear();

/** Add add feature */
void addFeature( QgsMapLayer *layer, int fid,
QString displayField, QString displayValue,
const QMap< QString, QString > &attributes,
const QMap< QString, QString > &derivedAttributes );

void closeEvent( QCloseEvent *e );
/** Remove results */
void clear();

/** map tool was deactivated */
void deactivate();

/** Set "No features ... " */
void setMessage( QString shortMsg, QString longMsg );
/** map tool was activated */
void activate();

void closeEvent( QCloseEvent *e );

signals:
void selectedFeatureChanged( QgsVectorLayer *, int featureId );
@@ -77,6 +80,8 @@ class QgsIdentifyResults: public QDialog, private Ui::QgsIdentifyResultsBase

void layerDestroyed();

void featureDeleted( int fid );

//! Context help
void on_buttonHelp_clicked();

@@ -89,6 +94,8 @@ class QgsIdentifyResults: public QDialog, private Ui::QgsIdentifyResultsBase

private:
QMenu *mActionPopup;
QgsVectorLayer *mRubberBandLayer;
int mRubberBandFid;
QgsRubberBand *mRubberBand;
QgsMapCanvas *mCanvas;

@@ -98,13 +105,15 @@ class QgsIdentifyResults: public QDialog, private Ui::QgsIdentifyResultsBase
QTreeWidgetItem *featureItem( QTreeWidgetItem *item );
QTreeWidgetItem *layerItem( QObject *layer );
QTreeWidgetItem *retrieveAttributes( QTreeWidgetItem *item, std::vector< std::pair<QString, QString> > &attributes );
void clearRubberBand();

void setColumnText( int column, const QString & label );
void expandColumnsToFit();
void saveWindowLocation();
void restorePosition();

void highlightFeature( QTreeWidgetItem *item );
void zoomToFeature( QTreeWidgetItem *item );
void editFeature( QTreeWidgetItem *item );

void doAction( QTreeWidgetItem *item );
@@ -124,6 +124,18 @@ void QgsMapToolIdentify::canvasReleaseEvent( QMouseEvent * e )
}
}

void QgsMapToolIdentify::activate()
{
mResults->activate();
QgsMapTool::activate();
}

void QgsMapToolIdentify::deactivate()
{
mResults->deactivate();
QgsMapTool::deactivate();
}

bool QgsMapToolIdentify::identifyLayer( QgsMapLayer *layer, int x, int y )
{
bool res = false;
@@ -57,6 +57,10 @@ class QgsMapToolIdentify : public QgsMapTool
//! Overridden mouse release event
virtual void canvasReleaseEvent( QMouseEvent * e );

virtual void activate();

virtual void deactivate();

private:
bool identifyLayer( QgsMapLayer *layer, int x, int y );
bool identifyRasterLayer( QgsRasterLayer *layer, int x, int y );
@@ -73,8 +77,6 @@ class QgsMapToolIdentify : public QgsMapTool
const QMap< QString, QString > &attributes,
const QMap< QString, QString > &derivedAttributes );

/** Add an action to the feature display node */

private slots:
// Let us know when the QgsIdentifyResults dialog box has been closed
void resultsDialogGone();

0 comments on commit 56e45d6

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