Skip to content
Permalink
Browse files

Move zoomToFeature to QgsDualView and add checks for null geometries …

…/ geometryless layers
  • Loading branch information
mhugent committed Jan 4, 2016
1 parent 1317220 commit 1519b3e041d73d2ce7b9272d38288463c878b510
@@ -96,6 +96,8 @@ class QgsAttributeTableFilterModel: QSortFilterProxyModel, QgsFeatureModel

virtual QModelIndex mapFromMaster( const QModelIndex &sourceIndex ) const;

QgsMapCanvas* mapCanvas() const;

protected:
/**
* Returns true if the source row will be accepted
@@ -98,16 +98,6 @@ class QgsDualView : QStackedWidget
* @return The master model
*/
QgsAttributeTableModel* masterModel() const;
/**
Returns the filter model
@return the filter model
*/
QgsAttributeTableFilterModel* filterModel() const;
/**
Returns the table view
@return the table view
*/
const QgsAttributeTableView* tableView() const;

void setRequest( const QgsFeatureRequest& request );

@@ -240,8 +240,6 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
mMainView->setView( QgsDualView::AttributeTable );

editingToggled();

QObject::connect( mMainView->tableView(), SIGNAL( willShowContextMenu( QMenu*, QModelIndex ) ), this, SLOT( viewWillShowContextMenu( QMenu*, QModelIndex ) ) );
}

QgsAttributeTableDialog::~QgsAttributeTableDialog()
@@ -353,26 +351,6 @@ void QgsAttributeTableDialog::updateFieldFromExpressionSelected()
runFieldCalculation( mLayer, mFieldCombo->currentText(), mUpdateExpressionText->currentField(), filteredIds );
}

void QgsAttributeTableDialog::viewWillShowContextMenu( QMenu* menu, QModelIndex atIndex )
{
if ( menu )
{
menu->addAction( tr( "Zoom to feature" ), this, SLOT( zoomToFeature() ) );
}
}

void QgsAttributeTableDialog::zoomToFeature()
{
QModelIndex currentIndex = mMainView->tableView()->currentIndex();
if ( !currentIndex.isValid() )
{
return;
}

QgsFeatureId id = mMainView->filterModel()->rowToId( currentIndex );
QgisApp::instance()->mapCanvas()->zoomToFeatureId( mLayer, id );
}

void QgsAttributeTableDialog::runFieldCalculation( QgsVectorLayer* layer, const QString& fieldName, const QString& expression, const QgsFeatureIds& filteredIds )
{
QApplication::setOverrideCursor( Qt::WaitCursor );
@@ -203,13 +203,6 @@ class APP_EXPORT QgsAttributeTableDialog : public QDialog, private Ui::QgsAttrib
void updateFieldFromExpression();
void updateFieldFromExpressionSelected();

/** Add items to the rightclick menu
@menu the context menu
@atIndex the current model index*/
void viewWillShowContextMenu( QMenu* menu, QModelIndex atIndex );
/** Zooms to the active feature*/
void zoomToFeature();

private:
QMenu* mMenuActions;
QAction* mActionToggleEditing;
@@ -151,6 +151,8 @@ class GUI_EXPORT QgsAttributeTableFilterModel: public QSortFilterProxyModel, pub
*/
virtual void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override;

QgsMapCanvas* mapCanvas() const { return mCanvas; }

protected:
/**
* Returns true if the source row will be accepted
@@ -348,6 +348,17 @@ int QgsDualView::filteredFeatureCount()

void QgsDualView::viewWillShowContextMenu( QMenu* menu, const QModelIndex& atIndex )
{
if ( !menu )
{
return;
}

QgsVectorLayer* vl = mFilterModel->layer();
if ( vl && vl->geometryType() != QGis::NoGeometry )
{
menu->addAction( tr( "Zoom to feature" ), this, SLOT( zoomToCurrentFeature() ) );
}

QModelIndex sourceIndex = mFilterModel->mapToSource( atIndex );

//add user-defined actions to context menu
@@ -389,6 +400,22 @@ void QgsDualView::viewWillShowContextMenu( QMenu* menu, const QModelIndex& atInd
menu->addAction( tr( "Open form" ), a, SLOT( featureForm() ) );
}

void QgsDualView::zoomToCurrentFeature()
{
QModelIndex currentIndex = mTableView->currentIndex();
if ( !currentIndex.isValid() )
{
return;
}

QgsFeatureId id = mFilterModel->rowToId( currentIndex );
QgsMapCanvas* canvas = mFilterModel->mapCanvas();
if ( canvas )
{
canvas->zoomToFeatureId( mLayerCache->layer(), id );
}
}

void QgsDualView::previewExpressionChanged( const QString& expression )
{
mLayerCache->layer()->setDisplayExpression( expression );
@@ -136,16 +136,6 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas
* @return The master model
*/
QgsAttributeTableModel* masterModel() const { return mMasterModel; }
/**
Returns the filter model
@return the filter model
*/
QgsAttributeTableFilterModel* filterModel() const { return mFilterModel; }
/**
Returns the table view
@return the table view
*/
const QgsAttributeTableView* tableView() const { return mTableView; }

void setRequest( const QgsFeatureRequest& request );

@@ -227,6 +217,9 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas
*/
virtual void finished();

/** Zooms to the active feature*/
void zoomToCurrentFeature();

private:
void initLayerCache( QgsVectorLayer *layer, bool cacheGeometry );
void initModels( QgsMapCanvas* mapCanvas, const QgsFeatureRequest& request );
@@ -1084,7 +1084,7 @@ void QgsMapCanvas::zoomToFeatureId( QgsVectorLayer* layer, QgsFeatureId id )
}

QgsGeometry* geom = fet.geometry();
if ( !geom )
if ( !geom || !geom->geometry() )
{
return;
}

0 comments on commit 1519b3e

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