109 changes: 42 additions & 67 deletions src/gui/qgsmaptip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
***************************************************************************/
// QGIS includes
#include <qgsmapcanvas.h>
#include <qgsmaplayer.h>
#include <qgsvectordataprovider.h>
#include <qgsvectorlayer.h>
#include <qgsfield.h>

// Qt includes
#include <QPoint>
Expand All @@ -37,7 +34,7 @@ QgsMapTip::~QgsMapTip()

}

void QgsMapTip::showMapTip( QgsMapLayer * thepLayer,
void QgsMapTip::showMapTip( QgsMapLayer *thepLayer,
QgsPoint & theMapPosition,
QPoint & thePixelPosition,
QgsMapCanvas *thepMapCanvas )
Expand All @@ -52,79 +49,57 @@ void QgsMapTip::showMapTip( QgsMapLayer * thepLayer,

// Show the maptip on the canvas
QString myTipText = fetchFeature( thepLayer, theMapPosition, thepMapCanvas );
if ( myTipText.length() > 0 )
mMapTipVisible = !myTipText.isEmpty();

if ( mMapTipVisible )
{
mMapTipVisible = true;
QToolTip::showText( thepMapCanvas->mapToGlobal( thePixelPosition ), myTipText, thepMapCanvas );
// store the point so we can use it to clear the maptip later
mLastPosition = thePixelPosition;
}
else
{
mMapTipVisible = false;
}

}

void QgsMapTip::clear( QgsMapCanvas *mpMapCanvas )
{
if ( mMapTipVisible )
{
// set the maptip to blank
QToolTip::showText( mpMapCanvas->mapToGlobal( mLastPosition ), "", mpMapCanvas );
// reset the visible flag
mMapTipVisible = false;
}
if ( !mMapTipVisible )
return;

// set the maptip to blank
QToolTip::showText( mpMapCanvas->mapToGlobal( mLastPosition ), "", mpMapCanvas );
// reset the visible flag
mMapTipVisible = false;
}

QString QgsMapTip::fetchFeature( QgsMapLayer *layer, QgsPoint & mapPosition, QgsMapCanvas *mpMapCanvas )
QString QgsMapTip::fetchFeature( QgsMapLayer *layer, QgsPoint &mapPosition, QgsMapCanvas *mpMapCanvas )
{
// Default return value
QString maptipText = "";
// Protection just in case we get passed a null layer
if ( layer )
{
// Get the setting for the search radius from user preferences, if it exists
QSettings settings;
double identifyValue = settings.value( "/Map/identifyRadius", QGis::DEFAULT_IDENTIFY_RADIUS ).toDouble();

// create the search rectangle
double searchRadius = mpMapCanvas->extent().width() * ( identifyValue / 100.0 );
QgsRectangle r;
r.setXMinimum( mapPosition.x() - searchRadius );
r.setXMaximum( mapPosition.x() + searchRadius );
r.setYMinimum( mapPosition.y() - searchRadius );
r.setYMaximum( mapPosition.y() + searchRadius );

// Get the data provider
QgsVectorDataProvider* dataProvider = qobject_cast<QgsVectorLayer *>( layer )->dataProvider();
// Fetch the attribute list for the layer
QgsAttributeList allAttributes = dataProvider->attributeIndexes();
// Select all attributes within the search radius
dataProvider->select( allAttributes, r, true, true );
// Feature to hold the results of the fetch
QgsFeature feature;
// Get the field list for the layer
const QgsFieldMap& fields = dataProvider->fields();
// Get the label (display) field for the layer
QString fieldIndex = qobject_cast<QgsVectorLayer *>( layer )->displayField();
if ( dataProvider->nextFeature( feature ) )
{
// if we get a feature, pull out the display field and set the maptip text to its value
QgsAttributeMap attributes = feature.attributeMap();
for ( QgsAttributeMap::const_iterator it = attributes.begin(); it != attributes.end(); ++it )
{

if ( fields[it.key()].name() == fieldIndex )
{
maptipText = it->toString();

}

}
}
}
// return the map tip
return maptipText;
}
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
if ( !vlayer )
return "";

// Get the setting for the search radius from user preferences, if it exists
QSettings settings;
double identifyValue = settings.value( "/Map/identifyRadius", QGis::DEFAULT_IDENTIFY_RADIUS ).toDouble();

// create the search rectangle
double searchRadius = mpMapCanvas->extent().width() * ( identifyValue / 100.0 );

QgsRectangle r;
r.setXMinimum( mapPosition.x() - searchRadius );
r.setYMinimum( mapPosition.y() - searchRadius );
r.setXMaximum( mapPosition.x() + searchRadius );
r.setYMaximum( mapPosition.y() + searchRadius );

r = mpMapCanvas->mapRenderer()->mapToLayerCoordinates( layer, r );

int idx = vlayer->fieldNameIndex( vlayer->displayField() );
if ( idx < 0 )
return "";

QgsFeature feature;

vlayer->select( QgsAttributeList() << idx, r, true, true );
if ( !vlayer->nextFeature( feature ) )
return "";

return feature.attributeMap().value( idx, "" ).toString();
}
31 changes: 14 additions & 17 deletions src/gui/qgsquerybuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,26 +181,23 @@ void QgsQueryBuilder::test()

void QgsQueryBuilder::accept()
{
// if user hits Ok and there is no query, skip the validation
if ( !txtSQL->toPlainText().trimmed().isEmpty() )
if ( !mLayer->setSubsetString( txtSQL->toPlainText() ) )
{
if ( !mLayer->setSubsetString( txtSQL->toPlainText() ) )
//error in query - show the problem
if ( mLayer->dataProvider()->hasErrors() )
{
//error in query - show the problem
if ( mLayer->dataProvider()->hasErrors() )
{
QMessageBox::warning( this,
tr( "Query Failed" ),
tr( "An error occurred when executing the query." )
+ tr( "\nThe data provider said:\n%1" ).arg( mLayer->dataProvider()->errors().join( "\n" ) ) );
mLayer->dataProvider()->clearErrors();
}
else
{
QMessageBox::warning( this, tr( "Error in Query" ), tr( "The subset string could not be set" ) );
}
return;
QMessageBox::warning( this,
tr( "Query Failed" ),
tr( "An error occurred when executing the query." )
+ tr( "\nThe data provider said:\n%1" ).arg( mLayer->dataProvider()->errors().join( "\n" ) ) );
mLayer->dataProvider()->clearErrors();
}
else
{
QMessageBox::warning( this, tr( "Error in Query" ), tr( "The subset string could not be set" ) );
}

return;
}

QDialog::accept();
Expand Down
11 changes: 10 additions & 1 deletion src/mapserver/qgswmsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,16 @@ int QgsWMSServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
//info point could be 0 in case there is only an attribute filter
if ( infoPoint )
{
double searchRadius = ( layerRect.xMaximum() - layerRect.xMinimum() ) / 100;
double searchRadius = 0;
if ( layer->geometryType() == QGis::Polygon )
{
searchRadius = layerRect.width() / 400;
}
else
{
searchRadius = layerRect.width() / 200;
}

searchRect.set( infoPoint->x() - searchRadius, infoPoint->y() - searchRadius,
infoPoint->x() + searchRadius, infoPoint->y() + searchRadius );
}
Expand Down
3 changes: 0 additions & 3 deletions src/plugins/sqlanywhere/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ SET (sqlanywhere_SRCS
sasourceselect.cpp
sanewconnection.cpp
sadbtablemodel.cpp
sadbfilterproxymodel.cpp
saquerybuilder.cpp
)

SET (sqlanywhere_UIS
Expand All @@ -21,7 +19,6 @@ SET (sqlanywhere_MOC_HDRS
sanewconnection.h
salayer.h
sadbtablemodel.h
saquerybuilder.h
)

SET (sqlanywhere_RCCS sqlanywhere.qrc)
Expand Down
63 changes: 0 additions & 63 deletions src/plugins/sqlanywhere/sadbfilterproxymodel.cpp

This file was deleted.

47 changes: 0 additions & 47 deletions src/plugins/sqlanywhere/sadbfilterproxymodel.h

This file was deleted.

331 changes: 0 additions & 331 deletions src/plugins/sqlanywhere/saquerybuilder.cpp

This file was deleted.

148 changes: 0 additions & 148 deletions src/plugins/sqlanywhere/saquerybuilder.h

This file was deleted.

4 changes: 2 additions & 2 deletions src/plugins/sqlanywhere/sasourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#include "sasourceselect.h"
#include "sanewconnection.h"
#include "saquerybuilder.h"
#include "qgsquerybuilder.h"

#include "qgisapp.h"
#include "qgslogger.h"
Expand Down Expand Up @@ -464,7 +464,7 @@ void SaSourceSelect::setSql( const QModelIndex &index )
}

// create a query builder object
SaQueryBuilder *qb = new SaQueryBuilder( vlayer, this );
QgsQueryBuilder *qb = new QgsQueryBuilder( vlayer, this );
if ( qb->exec() )
{
mTableModel.setSql( mProxyModel.mapToSource( index ), qb->sql() );
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/sqlanywhere/sasourceselect.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#define SASOURCESELECT_H

#include "ui_sasourceselectbase.h"
#include "sadbfilterproxymodel.h"
#include "qgsdbfilterproxymodel.h"
#include "sadbtablemodel.h"
#include "sqlanyconnection.h"
#include "sqlanystatement.h"
Expand Down Expand Up @@ -181,7 +181,7 @@ class SaSourceSelect : public QDialog, private Ui::SaSourceSelectBase

//! Model that acts as datasource for mTableTreeWidget
SaDbTableModel mTableModel;
SaDbFilterProxyModel mProxyModel;
QgsDbFilterProxyModel mProxyModel;

// button for building queries
QPushButton *mBuildQueryButton;
Expand Down
53 changes: 0 additions & 53 deletions src/providers/postgres/qgsdbfilterproxymodel.cpp

This file was deleted.

39 changes: 0 additions & 39 deletions src/providers/postgres/qgsdbfilterproxymodel.h

This file was deleted.