Skip to content

Commit

Permalink
Remove single select tool, merge into Select By Rectangle. Fix #10824
Browse files Browse the repository at this point in the history
- New tool named Select Feature(s) does both actions one tool
- select(), selectByRectangle() return SelectFeatures action to maintain
  API
  • Loading branch information
NathanW2 committed Jul 7, 2014
1 parent 1088ba7 commit f4a51c4
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 63 deletions.
48 changes: 16 additions & 32 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -916,11 +916,10 @@ QgisApp::~QgisApp()
delete mMapTools.mRotateFeature;
delete mMapTools.mRotateLabel;
delete mMapTools.mRotatePointSymbolsTool;
delete mMapTools.mSelect;
delete mMapTools.mSelectFreehand;
delete mMapTools.mSelectPolygon;
delete mMapTools.mSelectRadius;
delete mMapTools.mSelectRectangle;
delete mMapTools.mSelectFeatures;
delete mMapTools.mShowHideLabels;
delete mMapTools.mSimplifyFeature;
delete mMapTools.mSplitFeatures;
Expand Down Expand Up @@ -1108,8 +1107,7 @@ void QgisApp::createActions()
connect( mActionPanToSelected, SIGNAL( triggered() ), this, SLOT( panToSelected() ) );
connect( mActionZoomIn, SIGNAL( triggered() ), this, SLOT( zoomIn() ) );
connect( mActionZoomOut, SIGNAL( triggered() ), this, SLOT( zoomOut() ) );
connect( mActionSelect, SIGNAL( triggered() ), this, SLOT( select() ) );
connect( mActionSelectRectangle, SIGNAL( triggered() ), this, SLOT( selectByRectangle() ) );
connect( mActionSelectFeatures, SIGNAL( triggered() ), this, SLOT( selectFeatures() ) );
connect( mActionSelectPolygon, SIGNAL( triggered() ), this, SLOT( selectByPolygon() ) );
connect( mActionSelectFreehand, SIGNAL( triggered() ), this, SLOT( selectByFreehand() ) );
connect( mActionSelectRadius, SIGNAL( triggered() ), this, SLOT( selectByRadius() ) );
Expand Down Expand Up @@ -1340,8 +1338,7 @@ void QgisApp::createActionGroups()
mMapToolGroup->addAction( mActionZoomOut );
mMapToolGroup->addAction( mActionIdentify );
mMapToolGroup->addAction( mActionFeatureAction );
mMapToolGroup->addAction( mActionSelect );
mMapToolGroup->addAction( mActionSelectRectangle );
mMapToolGroup->addAction( mActionSelectFeatures );
mMapToolGroup->addAction( mActionSelectPolygon );
mMapToolGroup->addAction( mActionSelectFreehand );
mMapToolGroup->addAction( mActionSelectRadius );
Expand Down Expand Up @@ -1553,15 +1550,15 @@ void QgisApp::createToolBars()
QToolButton *bt = new QToolButton( mAttributesToolBar );
bt->setPopupMode( QToolButton::MenuButtonPopup );
QList<QAction*> selectActions;
selectActions << mActionSelect << mActionSelectRectangle << mActionSelectPolygon
selectActions << mActionSelectFeatures << mActionSelectPolygon
<< mActionSelectFreehand << mActionSelectRadius;
bt->addActions( selectActions );

QAction* defSelectAction = mActionSelect;
QAction* defSelectAction = mActionSelectFeatures;
switch ( settings.value( "/UI/selectTool", 0 ).toInt() )
{
case 0: defSelectAction = mActionSelect; break;
case 1: defSelectAction = mActionSelectRectangle; break;
case 0: defSelectAction = mActionSelectFeatures; break;
case 1: defSelectAction = mActionSelectFeatures; break;
case 2: defSelectAction = mActionSelectRadius; break;
case 3: defSelectAction = mActionSelectPolygon; break;
case 4: defSelectAction = mActionSelectFreehand; break;
Expand Down Expand Up @@ -1939,8 +1936,7 @@ void QgisApp::setTheme( QString theThemeName )
mActionZoomActualSize->setIcon( QgsApplication::getThemeIcon( "/mActionZoomActual.svg" ) );
mActionIdentify->setIcon( QgsApplication::getThemeIcon( "/mActionIdentify.svg" ) );
mActionFeatureAction->setIcon( QgsApplication::getThemeIcon( "/mAction.svg" ) );
mActionSelect->setIcon( QgsApplication::getThemeIcon( "/mActionSelect.svg" ) );
mActionSelectRectangle->setIcon( QgsApplication::getThemeIcon( "/mActionSelectRectangle.svg" ) );
mActionSelectFeatures->setIcon( QgsApplication::getThemeIcon( "/mActionSelectRectangle.svg" ) );
mActionSelectPolygon->setIcon( QgsApplication::getThemeIcon( "/mActionSelectPolygon.svg" ) );
mActionSelectFreehand->setIcon( QgsApplication::getThemeIcon( "/mActionSelectFreehand.svg" ) );
mActionSelectRadius->setIcon( QgsApplication::getThemeIcon( "/mActionSelectRadius.svg" ) );
Expand Down Expand Up @@ -2148,10 +2144,8 @@ void QgisApp::createCanvasTools()
mMapTools.mSplitFeatures->setAction( mActionSplitFeatures );
mMapTools.mSplitParts = new QgsMapToolSplitParts( mMapCanvas );
mMapTools.mSplitParts->setAction( mActionSplitParts );
mMapTools.mSelect = new QgsMapToolSelect( mMapCanvas );
mMapTools.mSelect->setAction( mActionSelect );
mMapTools.mSelectRectangle = new QgsMapToolSelectRectangle( mMapCanvas );
mMapTools.mSelectRectangle->setAction( mActionSelectRectangle );
mMapTools.mSelectFeatures = new QgsMapToolSelectFeatures( mMapCanvas );
mMapTools.mSelectFeatures->setAction( mActionSelectFeatures );
mMapTools.mSelectPolygon = new QgsMapToolSelectPolygon( mMapCanvas );
mMapTools.mSelectPolygon->setAction( mActionSelectPolygon );
mMapTools.mSelectFreehand = new QgsMapToolSelectFreehand( mMapCanvas );
Expand Down Expand Up @@ -5703,14 +5697,9 @@ void QgisApp::addFeature()
mMapCanvas->setMapTool( mMapTools.mAddFeature );
}

void QgisApp::select()
void QgisApp::selectFeatures()
{
mMapCanvas->setMapTool( mMapTools.mSelect );
}

void QgisApp::selectByRectangle()
{
mMapCanvas->setMapTool( mMapTools.mSelectRectangle );
mMapCanvas->setMapTool( mMapTools.mSelectFeatures );
}

void QgisApp::selectByPolygon()
Expand Down Expand Up @@ -8800,8 +8789,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )

if ( !layer )
{
mActionSelect->setEnabled( false );
mActionSelectRectangle->setEnabled( false );
mActionSelectFeatures->setEnabled( false );
mActionSelectPolygon->setEnabled( false );
mActionSelectFreehand->setEnabled( false );
mActionSelectRadius->setEnabled( false );
Expand Down Expand Up @@ -8902,8 +8890,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
mActionZoomActualSize->setEnabled( false );
mActionLabeling->setEnabled( true );

mActionSelect->setEnabled( true );
mActionSelectRectangle->setEnabled( true );
mActionSelectFeatures->setEnabled( true );
mActionSelectPolygon->setEnabled( true );
mActionSelectFreehand->setEnabled( true );
mActionSelectRadius->setEnabled( true );
Expand Down Expand Up @@ -9065,8 +9052,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )

mActionLayerSubsetString->setEnabled( false );
mActionFeatureAction->setEnabled( false );
mActionSelect->setEnabled( false );
mActionSelectRectangle->setEnabled( false );
mActionSelectFeatures->setEnabled( false );
mActionSelectPolygon->setEnabled( false );
mActionSelectFreehand->setEnabled( false );
mActionSelectRadius->setEnabled( false );
Expand Down Expand Up @@ -9939,9 +9925,7 @@ void QgisApp::toolButtonActionTriggered( QAction *action )
return;

QSettings settings;
if ( action == mActionSelect )
settings.setValue( "/UI/selectTool", 0 );
else if ( action == mActionSelectRectangle )
if ( action == mActionSelectFeatures )
settings.setValue( "/UI/selectTool", 1 );
else if ( action == mActionSelectRadius )
settings.setValue( "/UI/selectTool", 2 );
Expand Down
11 changes: 4 additions & 7 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QAction *actionPanToSelected() { return mActionPanToSelected; }
QAction *actionZoomIn() { return mActionZoomIn; }
QAction *actionZoomOut() { return mActionZoomOut; }
QAction *actionSelect() { return mActionSelect; }
QAction *actionSelectRectangle() { return mActionSelectRectangle; }
QAction *actionSelect() { return mActionSelectFeatures; }
QAction *actionSelectRectangle() { return mActionSelectFeatures; }
QAction *actionSelectPolygon() { return mActionSelectPolygon; }
QAction *actionSelectFreehand() { return mActionSelectFreehand; }
QAction *actionSelectRadius() { return mActionSelectRadius; }
Expand Down Expand Up @@ -996,11 +996,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! shows the snapping Options
void snappingOptions();

//! activates the selection tool
void select();

//! activates the rectangle selection tool
void selectByRectangle();
void selectFeatures();

//! activates the polygon selection tool
void selectByPolygon();
Expand Down Expand Up @@ -1433,7 +1430,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QgsMapTool* mSplitFeatures;
QgsMapTool* mSplitParts;
QgsMapTool* mSelect;
QgsMapTool* mSelectRectangle;
QgsMapTool* mSelectFeatures;
QgsMapTool* mSelectPolygon;
QgsMapTool* mSelectFreehand;
QgsMapTool* mSelectRadius;
Expand Down
17 changes: 12 additions & 5 deletions src/app/qgsmaptoolselectrectangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <QRect>


QgsMapToolSelectRectangle::QgsMapToolSelectRectangle( QgsMapCanvas* canvas )
QgsMapToolSelectFeatures::QgsMapToolSelectFeatures( QgsMapCanvas* canvas )
: QgsMapTool( canvas ), mDragging( false )
{
QPixmap mySelectQPixmap = QPixmap(( const char ** ) select_cursor );
Expand All @@ -40,7 +40,7 @@ QgsMapToolSelectRectangle::QgsMapToolSelectRectangle( QgsMapCanvas* canvas )
}


void QgsMapToolSelectRectangle::canvasPressEvent( QMouseEvent *e )
void QgsMapToolSelectFeatures::canvasPressEvent( QMouseEvent *e )
{
Q_UNUSED( e );
mSelectRect.setRect( 0, 0, 0, 0 );
Expand All @@ -50,7 +50,7 @@ void QgsMapToolSelectRectangle::canvasPressEvent( QMouseEvent *e )
}


void QgsMapToolSelectRectangle::canvasMoveEvent( QMouseEvent *e )
void QgsMapToolSelectFeatures::canvasMoveEvent( QMouseEvent *e )
{
if ( e->buttons() != Qt::LeftButton )
return;
Expand All @@ -65,7 +65,7 @@ void QgsMapToolSelectRectangle::canvasMoveEvent( QMouseEvent *e )
}


void QgsMapToolSelectRectangle::canvasReleaseEvent( QMouseEvent *e )
void QgsMapToolSelectFeatures::canvasReleaseEvent( QMouseEvent *e )
{
QgsVectorLayer* vlayer = QgsMapToolSelectUtils::getCurrentVectorLayer( mCanvas );
if ( vlayer == NULL )
Expand Down Expand Up @@ -105,7 +105,14 @@ void QgsMapToolSelectRectangle::canvasReleaseEvent( QMouseEvent *e )
QgsMapToolSelectUtils::setRubberBand( mCanvas, mSelectRect, mRubberBand );

QgsGeometry* selectGeom = mRubberBand->asGeometry();
QgsMapToolSelectUtils::setSelectFeatures( mCanvas, selectGeom, e );
if ( !mDragging )
{
bool doDifference = e->modifiers() & Qt::ControlModifier ? true : false;
QgsMapToolSelectUtils::setSelectFeatures( mCanvas, selectGeom, false, doDifference, true );
}
else
QgsMapToolSelectUtils::setSelectFeatures( mCanvas, selectGeom, e );

delete selectGeom;

mRubberBand->reset( QGis::Polygon );
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsmaptoolselectrectangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ class QgsGeometry;
class QgsRubberBand;


class APP_EXPORT QgsMapToolSelectRectangle : public QgsMapTool
class APP_EXPORT QgsMapToolSelectFeatures : public QgsMapTool
{
Q_OBJECT
public:
QgsMapToolSelectRectangle( QgsMapCanvas* canvas );
QgsMapToolSelectFeatures( QgsMapCanvas* canvas );

//! Overridden mouse move event
virtual void canvasMoveEvent( QMouseEvent * e );
Expand Down
24 changes: 7 additions & 17 deletions src/ui/qgisapp.ui
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<x>0</x>
<y>0</y>
<width>1050</width>
<height>25</height>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="mProjectMenu">
Expand Down Expand Up @@ -63,8 +63,7 @@
<property name="title">
<string>Select</string>
</property>
<addaction name="mActionSelect"/>
<addaction name="mActionSelectRectangle"/>
<addaction name="mActionSelectFeatures"/>
<addaction name="mActionSelectPolygon"/>
<addaction name="mActionSelectFreehand"/>
<addaction name="mActionSelectRadius"/>
Expand Down Expand Up @@ -874,19 +873,7 @@
<string>Ctrl+-</string>
</property>
</action>
<action name="mActionSelect">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionSelect.svg</normaloff>:/images/themes/default/mActionSelect.svg</iconset>
</property>
<property name="text">
<string>Select Single Feature</string>
</property>
</action>
<action name="mActionSelectRectangle">
<action name="mActionSelectFeatures">
<property name="checkable">
<bool>true</bool>
</property>
Expand All @@ -895,7 +882,10 @@
<normaloff>:/images/themes/default/mActionSelectRectangle.svg</normaloff>:/images/themes/default/mActionSelectRectangle.svg</iconset>
</property>
<property name="text">
<string>Select Features by Rectangle</string>
<string>Select Feature(s)</string>
</property>
<property name="toolTip">
<string>Select Features by area or single click</string>
</property>
</action>
<action name="mActionSelectPolygon">
Expand Down

0 comments on commit f4a51c4

Please sign in to comment.