Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[node editor] Always show node editor panel upon activating the node …
…tool
  • Loading branch information
nirvn committed Jan 23, 2019
1 parent 508817d commit d77596c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
12 changes: 6 additions & 6 deletions src/app/vertextool/qgsvertexeditor.cpp
Expand Up @@ -74,7 +74,7 @@ QgsVertexEditorModel::QgsVertexEditorModel( QgsVectorLayer *layer, QgsSelectedFe

int QgsVertexEditorModel::rowCount( const QModelIndex &parent ) const
{
if ( parent.isValid() )
if ( parent.isValid() || !mSelectedFeature )
return 0;

return mSelectedFeature->vertexMap().count();
Expand All @@ -88,7 +88,7 @@ int QgsVertexEditorModel::columnCount( const QModelIndex &parent ) const

QVariant QgsVertexEditorModel::data( const QModelIndex &index, int role ) const
{
if ( !index.isValid() ||
if ( !index.isValid() || !mSelectedFeature ||
( role != Qt::DisplayRole && role != Qt::EditRole && role != MIN_RADIUS_ROLE && role != Qt::FontRole ) )
return QVariant();

Expand Down Expand Up @@ -206,7 +206,7 @@ bool QgsVertexEditorModel::setData( const QModelIndex &index, const QVariant &va
{
return false;
}
if ( index.row() >= mSelectedFeature->vertexMap().count() )
if ( !mSelectedFeature || index.row() >= mSelectedFeature->vertexMap().count() )
{
return false;
}
Expand Down Expand Up @@ -270,7 +270,7 @@ Qt::ItemFlags QgsVertexEditorModel::flags( const QModelIndex &index ) const

bool QgsVertexEditorModel::calcR( int row, double &r, double &minRadius ) const
{
if ( row <= 0 || row >= mSelectedFeature->vertexMap().count() - 1 )
if ( row <= 0 || !mSelectedFeature || row >= mSelectedFeature->vertexMap().count() - 1 )
return false;

const QgsVertexEntry *entry = mSelectedFeature->vertexMap().at( row );
Expand Down Expand Up @@ -333,7 +333,7 @@ void QgsVertexEditor::updateEditor( QgsVectorLayer *layer, QgsSelectedFeature *s

void QgsVertexEditor::updateTableSelection()
{
if ( mUpdatingVertexSelection )
if ( !mSelectedFeature || mUpdatingVertexSelection )
return;

mUpdatingTableSelection = true;
Expand All @@ -360,7 +360,7 @@ void QgsVertexEditor::updateTableSelection()

void QgsVertexEditor::updateVertexSelection( const QItemSelection &selected, const QItemSelection & )
{
if ( mUpdatingTableSelection )
if ( !mSelectedFeature || mUpdatingTableSelection )
return;

mUpdatingVertexSelection = true;
Expand Down
30 changes: 21 additions & 9 deletions src/app/vertextool/qgsvertextool.cpp
Expand Up @@ -282,6 +282,15 @@ QgsVertexTool::~QgsVertexTool()
delete mEndpointMarker;
}

void QgsVertexTool::activate()
{
if ( QgisApp::instance() )
{
showVertexEditor();
}
QgsMapToolAdvancedDigitizing::activate();
}

void QgsVertexTool::deactivate()
{
setHighlightedVertices( QList<Vertex>() );
Expand Down Expand Up @@ -1047,20 +1056,20 @@ void QgsVertexTool::onCachedGeometryDeleted( QgsFeatureId fid )
void QgsVertexTool::showVertexEditor() //#spellok
{
QgsPointLocator::Match m = mLastMouseMoveMatch;
if ( !m.isValid() || !m.layer() )
return;

mSelectedFeature.reset( new QgsSelectedFeature( m.featureId(), m.layer(), mCanvas ) );
for ( int i = 0; i < mSelectedVertices.length(); ++i )
if ( m.isValid() || m.layer() )
{
if ( mSelectedVertices.at( i ).layer == m.layer() && mSelectedVertices.at( i ).fid == m.featureId() )
mSelectedFeature.reset( new QgsSelectedFeature( m.featureId(), m.layer(), mCanvas ) );
for ( int i = 0; i < mSelectedVertices.length(); ++i )
{
mSelectedFeature->selectVertex( mSelectedVertices.at( i ).vertexId );
if ( mSelectedVertices.at( i ).layer == m.layer() && mSelectedVertices.at( i ).fid == m.featureId() )
{
mSelectedFeature->selectVertex( mSelectedVertices.at( i ).vertexId );
}
}
}
if ( !mVertexEditor )
{
mVertexEditor.reset( new QgsVertexEditor( m.layer(), mSelectedFeature.get(), mCanvas ) );
mVertexEditor.reset( new QgsVertexEditor( m.layer() ? m.layer() : currentVectorLayer(), mSelectedFeature ? mSelectedFeature.get() : nullptr, mCanvas ) );
QgisApp::instance()->addDockWidget( Qt::LeftDockWidgetArea, mVertexEditor.get() );
connect( mVertexEditor.get(), &QgsVertexEditor::deleteSelectedRequested, this, &QgsVertexTool::deleteVertexEditorSelection );
connect( mVertexEditor.get(), &QgsVertexEditor::editorClosed, this, &QgsVertexTool::cleanupVertexEditor );
Expand All @@ -1070,7 +1079,10 @@ void QgsVertexTool::showVertexEditor() //#spellok
mVertexEditor->updateEditor( m.layer(), mSelectedFeature.get() );
}

connect( mSelectedFeature->layer(), &QgsVectorLayer::featureDeleted, this, &QgsVertexTool::cleanEditor );
if ( mSelectedFeature )
{
connect( mSelectedFeature->layer(), &QgsVectorLayer::featureDeleted, this, &QgsVertexTool::cleanEditor );
}
}

void QgsVertexTool::cleanupVertexEditor()
Expand Down
7 changes: 5 additions & 2 deletions src/app/vertextool/qgsvertextool.h
Expand Up @@ -85,12 +85,17 @@ class APP_EXPORT QgsVertexTool : public QgsMapToolAdvancedDigitizing
//! Start addition of a new vertex on double-click
void canvasDoubleClickEvent( QgsMapMouseEvent *e ) override;

void activate() override;

void deactivate() override;

void keyPressEvent( QKeyEvent *e ) override;

QgsGeometry cachedGeometry( const QgsVectorLayer *layer, QgsFeatureId fid );

//! Toggle the vertex editor
void showVertexEditor(); //#spellok

private slots:
//! update geometry of our feature
void onCachedGeometryChanged( QgsFeatureId fid, const QgsGeometry &geom );
Expand All @@ -99,8 +104,6 @@ class APP_EXPORT QgsVertexTool : public QgsMapToolAdvancedDigitizing

void clearGeometryCache();

void showVertexEditor(); //#spellok

void deleteVertexEditorSelection();

void validationErrorFound( const QgsGeometry::Error &e );
Expand Down

0 comments on commit d77596c

Please sign in to comment.