Skip to content
Permalink
Browse files

[node editor] When no feature is selected, offer an hint label to eas…

…e discovery
  • Loading branch information
nirvn committed Jan 23, 2019
1 parent 8845263 commit 2defe21cac027e5a99fc49e6f329a620aa2ddd6f
Showing with 37 additions and 7 deletions.
  1. +33 −7 src/app/vertextool/qgsvertexeditor.cpp
  2. +4 −0 src/app/vertextool/qgsvertexeditor.h
@@ -26,6 +26,7 @@
#include "qgsproject.h"
#include "qgscoordinatetransform.h"

#include <QLabel>
#include <QTableWidget>
#include <QHeaderView>
#include <QVBoxLayout>
@@ -301,17 +302,31 @@ QgsVertexEditor::QgsVertexEditor(
{
setWindowTitle( tr( "Vertex Editor" ) );
setObjectName( QStringLiteral( "VertexEditor" ) );
mTableView = new QTableView( this );

QWidget *content = new QWidget( this );
content->setMinimumHeight( 160 );
QVBoxLayout *layout = new QVBoxLayout( content );
layout->setContentsMargins( 0, 0, 0, 0 );

mHintLabel = new QLabel( this );
mHintLabel->setText( tr( "Right click on the edge of an editable feature to show its table of vertices" ) );
mHintLabel->setWordWrap( true );
mHintLabel->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );

mTableView = new QTableView( this );
mTableView->setSelectionMode( QTableWidget::ExtendedSelection );
mTableView->setSelectionBehavior( QTableWidget::SelectRows );
mTableView->setItemDelegateForColumn( 0, new CoordinateItemDelegate( this ) );
mTableView->setItemDelegateForColumn( 1, new CoordinateItemDelegate( this ) );
mTableView->setItemDelegateForColumn( 2, new CoordinateItemDelegate( this ) );
mTableView->setItemDelegateForColumn( 3, new CoordinateItemDelegate( this ) );
mTableView->setItemDelegateForColumn( 4, new CoordinateItemDelegate( this ) );
mTableView->setVisible( false );

layout->addWidget( mTableView );
layout->addWidget( mHintLabel );

setWidget( mTableView );
setWidget( content );

updateEditor( layer, selectedFeature );
}
@@ -323,12 +338,23 @@ void QgsVertexEditor::updateEditor( QgsVectorLayer *layer, QgsSelectedFeature *s
mLayer = layer;
mSelectedFeature = selectedFeature;

// TODO We really should just update the model itself.
mVertexModel = new QgsVertexEditorModel( mLayer, mSelectedFeature, mCanvas, this );
mTableView->setModel( mVertexModel );
connect( mTableView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &QgsVertexEditor::updateVertexSelection );
if ( mLayer && mSelectedFeature )
{
// TODO We really should just update the model itself.
mVertexModel = new QgsVertexEditorModel( mLayer, mSelectedFeature, mCanvas, this );
mTableView->setModel( mVertexModel );

connect( mSelectedFeature, &QgsSelectedFeature::selectionChanged, this, &QgsVertexEditor::updateTableSelection );
mHintLabel->setVisible( false );
mTableView->setVisible( true );

connect( mTableView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &QgsVertexEditor::updateVertexSelection );
connect( mSelectedFeature, &QgsSelectedFeature::selectionChanged, this, &QgsVertexEditor::updateTableSelection );
}
else
{
mHintLabel->setVisible( true );
mTableView->setVisible( false );
}
}

void QgsVertexEditor::updateTableSelection()
@@ -28,6 +28,8 @@ class QgsMapCanvas;
class QgsRubberBand;
class QgsSelectedFeature;
class QgsVectorLayer;

class QLabel;
class QTableView;

class QgsVertexEditorModel : public QAbstractTableModel
@@ -96,6 +98,8 @@ class QgsVertexEditor : public QgsDockWidget

private:

QLabel *mHintLabel = nullptr;

bool mUpdatingTableSelection = false;
bool mUpdatingVertexSelection = false;
};

0 comments on commit 2defe21

Please sign in to comment.
You can’t perform that action at this time.