Skip to content

Commit

Permalink
Move zoomToFeature to QgsDualView and add checks for null geometries …
Browse files Browse the repository at this point in the history
…/ geometryless layers
  • Loading branch information
mhugent committed Jan 4, 2016
1 parent 1317220 commit 1519b3e
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 50 deletions.
2 changes: 2 additions & 0 deletions python/gui/attributetable/qgsattributetablefiltermodel.sip
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class QgsAttributeTableFilterModel: QSortFilterProxyModel, QgsFeatureModel


virtual QModelIndex mapFromMaster( const QModelIndex &sourceIndex ) const; virtual QModelIndex mapFromMaster( const QModelIndex &sourceIndex ) const;


QgsMapCanvas* mapCanvas() const;

protected: protected:
/** /**
* Returns true if the source row will be accepted * Returns true if the source row will be accepted
Expand Down
10 changes: 0 additions & 10 deletions python/gui/attributetable/qgsdualview.sip
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -98,16 +98,6 @@ class QgsDualView : QStackedWidget
* @return The master model * @return The master model
*/ */
QgsAttributeTableModel* masterModel() const; 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 ); void setRequest( const QgsFeatureRequest& request );


Expand Down
22 changes: 0 additions & 22 deletions src/app/qgsattributetabledialog.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -240,8 +240,6 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
mMainView->setView( QgsDualView::AttributeTable ); mMainView->setView( QgsDualView::AttributeTable );


editingToggled(); editingToggled();

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


QgsAttributeTableDialog::~QgsAttributeTableDialog() QgsAttributeTableDialog::~QgsAttributeTableDialog()
Expand Down Expand Up @@ -353,26 +351,6 @@ void QgsAttributeTableDialog::updateFieldFromExpressionSelected()
runFieldCalculation( mLayer, mFieldCombo->currentText(), mUpdateExpressionText->currentField(), filteredIds ); 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 ) void QgsAttributeTableDialog::runFieldCalculation( QgsVectorLayer* layer, const QString& fieldName, const QString& expression, const QgsFeatureIds& filteredIds )
{ {
QApplication::setOverrideCursor( Qt::WaitCursor ); QApplication::setOverrideCursor( Qt::WaitCursor );
Expand Down
7 changes: 0 additions & 7 deletions src/app/qgsattributetabledialog.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -203,13 +203,6 @@ class APP_EXPORT QgsAttributeTableDialog : public QDialog, private Ui::QgsAttrib
void updateFieldFromExpression(); void updateFieldFromExpression();
void updateFieldFromExpressionSelected(); 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: private:
QMenu* mMenuActions; QMenu* mMenuActions;
QAction* mActionToggleEditing; QAction* mActionToggleEditing;
Expand Down
2 changes: 2 additions & 0 deletions src/gui/attributetable/qgsattributetablefiltermodel.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ class GUI_EXPORT QgsAttributeTableFilterModel: public QSortFilterProxyModel, pub
*/ */
virtual void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override; virtual void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override;


QgsMapCanvas* mapCanvas() const { return mCanvas; }

protected: protected:
/** /**
* Returns true if the source row will be accepted * Returns true if the source row will be accepted
Expand Down
27 changes: 27 additions & 0 deletions src/gui/attributetable/qgsdualview.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -348,6 +348,17 @@ int QgsDualView::filteredFeatureCount()


void QgsDualView::viewWillShowContextMenu( QMenu* menu, const QModelIndex& atIndex ) 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 ); QModelIndex sourceIndex = mFilterModel->mapToSource( atIndex );


//add user-defined actions to context menu //add user-defined actions to context menu
Expand Down Expand Up @@ -389,6 +400,22 @@ void QgsDualView::viewWillShowContextMenu( QMenu* menu, const QModelIndex& atInd
menu->addAction( tr( "Open form" ), a, SLOT( featureForm() ) ); 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 ) void QgsDualView::previewExpressionChanged( const QString& expression )
{ {
mLayerCache->layer()->setDisplayExpression( expression ); mLayerCache->layer()->setDisplayExpression( expression );
Expand Down
13 changes: 3 additions & 10 deletions src/gui/attributetable/qgsdualview.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -136,16 +136,6 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas
* @return The master model * @return The master model
*/ */
QgsAttributeTableModel* masterModel() const { return mMasterModel; } 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 ); void setRequest( const QgsFeatureRequest& request );


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


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

private: private:
void initLayerCache( QgsVectorLayer *layer, bool cacheGeometry ); void initLayerCache( QgsVectorLayer *layer, bool cacheGeometry );
void initModels( QgsMapCanvas* mapCanvas, const QgsFeatureRequest& request ); void initModels( QgsMapCanvas* mapCanvas, const QgsFeatureRequest& request );
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsmapcanvas.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ void QgsMapCanvas::zoomToFeatureId( QgsVectorLayer* layer, QgsFeatureId id )
} }


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

0 comments on commit 1519b3e

Please sign in to comment.