Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to fetch MapToolNodeTool's currently selected feature from within python #34

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ ADD_SIP_PYTHON_MODULE(qgis.core core/core.sip qgis_core)
# additional gui includes
INCLUDE_DIRECTORIES(
../src/gui
../src/app
../src/app/nodetool/
../src/gui/symbology-ng
../src/plugins
${CMAKE_BINARY_DIR}/src/gui
Expand Down
3 changes: 3 additions & 0 deletions python/gui/gui.sip
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
%Include qgsmaptoolemitpoint.sip
%Include qgsmaptoolpan.sip
%Include qgsmaptoolzoom.sip
%Include qgsmaptooledit.sip
%Include qgsmaptoolvertexedit.sip
%Include qgsmaptoolnodetool.sip
%Include qgsmapoverviewcanvas.sip
%Include qgsmessageviewer.sip
%Include qgsprojectbadlayerguihandler.sip
Expand Down
9 changes: 9 additions & 0 deletions python/gui/qgsmaptool.sip
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include <qgsmaptoolzoom.h>
#include <qgsmaptoolpan.h>
#include <qgsmaptoolemitpoint.h>
#include <qgsmaptooledit.h>
#include <qgsmaptoolvertexedit.h>
#include <qgsmaptoolnodetool.h>
%End

class QgsMapTool : QObject
Expand All @@ -21,6 +24,12 @@ class QgsMapTool : QObject
sipClass = sipClass_QgsMapToolPan;
else if (dynamic_cast<QgsMapToolEmitPoint*>(sipCpp) != NULL)
sipClass = sipClass_QgsMapToolEmitPoint;
else if (dynamic_cast<QgsMapToolEdit*>(sipCpp) != NULL)
sipClass = sipClass_QgsMapToolEdit;
else if (dynamic_cast<QgsMapToolVertexEdit*>(sipCpp) != NULL)
sipClass = sipClass_QgsMapToolVertexEdit;
else if (dynamic_cast<QgsMapToolNodeTool*>(sipCpp) != NULL)
sipClass = sipClass_QgsMapToolNodeTool;
else
sipClass = NULL;
%End
Expand Down
26 changes: 26 additions & 0 deletions python/gui/qgsmaptooledit.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

class QgsMapToolEdit : QgsMapTool
{
%TypeHeaderCode
#include <qgsmaptooledit.h>
%End

%ConvertToSubClassCode
if (dynamic_cast<QgsMapToolVertexEdit*>(sipCpp) != NULL)
sipClass = sipClass_QgsMapToolVertexEdit;
else if (dynamic_cast<QgsMapToolNodeTool*>(sipCpp) != NULL)
sipClass = sipClass_QgsMapToolNodeTool;
else
sipClass = NULL;
%End

public:
//! constructor
QgsMapToolEdit(QgsMapCanvas* canvas);

virtual ~QgsMapToolEdit();

virtual bool isEditTool();

};

20 changes: 20 additions & 0 deletions python/gui/qgsmaptoolnodetool.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class QgsMapToolNodeTool : QgsMapToolVertexEdit
{
%TypeHeaderCode
#include <qgsmaptoolnodetool.h>
%End

public:
//! constructor
QgsMapToolNodeTool(QgsMapCanvas* canvas);

virtual ~QgsMapToolNodeTool();

virtual bool isEditTool();

// SelectionFeature* selectionFeature();

int featureId();

};

13 changes: 13 additions & 0 deletions python/gui/qgsmaptoolvertexedit.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class QgsMapToolVertexEdit : QgsMapToolEdit
{
%TypeHeaderCode
#include <qgsmaptoolvertexedit.h>
%End

public:
//! constructor
QgsMapToolVertexEdit(QgsMapCanvas* canvas);

virtual ~QgsMapToolVertexEdit();
};

14 changes: 14 additions & 0 deletions src/app/nodetool/qgsmaptoolnodetool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ QgsMapToolNodeTool::~QgsMapToolNodeTool()
removeRubberBands();
}

QgsSelectedFeature* QgsMapToolNodeTool::selectedFeature()
{
return mSelectedFeature;
}

QgsFeatureId QgsMapToolNodeTool::featureId()
{
if ( mSelectedFeature != NULL ) {
return mSelectedFeature->featureId();
}
return NULL;
}

void QgsMapToolNodeTool::createMovingRubberBands()
{
int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );
Expand Down Expand Up @@ -595,6 +608,7 @@ void QgsMapToolNodeTool::canvasReleaseEvent( QMouseEvent * e )
mExcludePoint.clear();
}


void QgsMapToolNodeTool::deactivate()
{
removeRubberBands();
Expand Down
4 changes: 4 additions & 0 deletions src/app/nodetool/qgsmaptoolnodetool.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class QgsMapToolNodeTool: public QgsMapToolVertexEdit
*/
QgsPoint closestVertex( QgsPoint point );

QgsSelectedFeature* selectedFeature();

QgsFeatureId featureId();

public slots:
void selectedFeatureDestroyed();

Expand Down