Skip to content

Commit

Permalink
cleaner handling of identify results
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12033 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Nov 8, 2009
1 parent 42b3664 commit 5ab883f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 27 deletions.
41 changes: 17 additions & 24 deletions src/app/qgsmaptoolidentify.cpp
Expand Up @@ -45,8 +45,6 @@ QgsMapToolIdentify::QgsMapToolIdentify( QgsMapCanvas* canvas )
// set cursor
QPixmap myIdentifyQPixmap = QPixmap(( const char ** ) identify_cursor );
mCursor = QCursor( myIdentifyQPixmap, 1, 1 );

mResults = new QgsIdentifyResults( canvas, mCanvas->window() );
}

QgsMapToolIdentify::~QgsMapToolIdentify()
Expand All @@ -57,6 +55,14 @@ QgsMapToolIdentify::~QgsMapToolIdentify()
}
}

QgsIdentifyResults *QgsMapToolIdentify::results()
{
if ( !mResults )
mResults = new QgsIdentifyResults( mCanvas, mCanvas->window() );

return mResults;
}

void QgsMapToolIdentify::canvasMoveEvent( QMouseEvent * e )
{
}
Expand All @@ -72,11 +78,7 @@ void QgsMapToolIdentify::canvasReleaseEvent( QMouseEvent * e )
return;
}

if ( !mResults )
{
mResults = new QgsIdentifyResults( mCanvas, mCanvas->window() );
}
mResults->clear();
results()->clear();

QSettings settings;
int identifyMode = settings.value( "/Map/identifyMode", 0 ).toInt();
Expand Down Expand Up @@ -139,38 +141,34 @@ void QgsMapToolIdentify::canvasReleaseEvent( QMouseEvent * e )

if ( res )
{
mResults->show();
mResults->raise();
results()->show();
results()->raise();
}
else
{
QSettings mySettings;
bool myDockFlag = mySettings.value( "/qgis/dockIdentifyResults", false ).toBool();
if ( !myDockFlag )
{
mResults->hide();
results()->hide();
}
else
{
mResults->clear();
results()->clear();
}
QMessageBox::information( 0, tr( "Identify results" ), tr( "No features at this position found." ) );
}
}

void QgsMapToolIdentify::activate()
{
if ( !mResults )
{
mResults = new QgsIdentifyResults( mCanvas, mCanvas->window() );
}
mResults->activate();
results()->activate();
QgsMapTool::activate();
}

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

Expand Down Expand Up @@ -327,7 +325,7 @@ bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, int x, int

derivedAttributes.insert( tr( "feature id" ), fid < 0 ? tr( "new feature" ) : QString::number( fid ) );

mResults->addFeature( layer, fid, displayField, displayValue, attributes, derivedAttributes );
results()->addFeature( layer, fid, displayField, displayValue, attributes, derivedAttributes );
}

QgsDebugMsg( "Feature count on identify: " + QString::number( featureCount ) );
Expand Down Expand Up @@ -388,18 +386,13 @@ bool QgsMapToolIdentify::identifyRasterLayer( QgsRasterLayer *layer, int x, int
if ( res )
{
derivedAttributes.insert( tr( "(clicked coordinate)" ), idPoint.toString() );
mResults->addFeature( layer, -1, type, "", attributes, derivedAttributes );
results()->addFeature( layer, -1, type, "", attributes, derivedAttributes );
}

return res;
}


void QgsMapToolIdentify::resultsDialogGone()
{
mResults = 0;
}

void QgsMapToolIdentify::convertMeasurement( QgsDistanceArea &calc, double &measure, QGis::UnitType &u, bool isArea )
{
// Helper for converting between meters and feet
Expand Down
4 changes: 1 addition & 3 deletions src/app/qgsmaptoolidentify.h
Expand Up @@ -82,9 +82,7 @@ class QgsMapToolIdentify : public QgsMapTool
const QMap< QString, QString > &attributes,
const QMap< QString, QString > &derivedAttributes );

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

#endif

0 comments on commit 5ab883f

Please sign in to comment.