Skip to content
Permalink
Browse files

Scroll to newly added feature in the attribute table view

Refs #37847
  • Loading branch information
suricactus committed Oct 16, 2020
1 parent b00d6fa commit b7ff23aa33a31a1d260e5a893f3da38e204e3ec5
@@ -70,6 +70,16 @@ Returns the selected features in the attribute table in table sorted order.
%End


void scrollToFeature( const QgsFeatureId &fid, int column = -1 );
%Docstring
Scroll to a feature with a given ``fid``.

Optionally a ``column`` can be specified, which will also bring that column into view.

.. versionadded:: 3.16
%End


protected:

virtual void mousePressEvent( QMouseEvent *event );
@@ -627,6 +627,7 @@ void QgsAttributeTableDialog::mActionAddFeatureViaAttributeTable_triggered()
{
masterModel->reload( masterModel->index( 0, 0 ), masterModel->index( masterModel->rowCount() - 1, masterModel->columnCount() - 1 ) );
mMainView->setCurrentEditSelection( QgsFeatureIds() << action.feature().id() );
mMainView->tableView()->scrollToFeature( action.feature().id(), 0 );
}
}

@@ -648,6 +649,7 @@ void QgsAttributeTableDialog::mActionAddFeatureViaAttributeForm_triggered()
{
masterModel->reload( masterModel->index( 0, 0 ), masterModel->index( masterModel->rowCount() - 1, masterModel->columnCount() - 1 ) );
mMainView->setCurrentEditSelection( QgsFeatureIds() << action.feature().id() );
mMainView->tableView()->scrollToFeature( action.feature().id(), 0 );
}
}

@@ -497,3 +497,20 @@ void QgsAttributeTableView::recreateActionWidgets()
}
mActionWidgets.clear();
}

void QgsAttributeTableView::scrollToFeature( const QgsFeatureId &fid, int col )
{
QModelIndex index = mFilterModel->fidToIndex( fid );

if ( !index.isValid() )
return;

scrollTo( index );

QModelIndex selectionIndex = index.sibling( index.row(), col );

if ( !selectionIndex.isValid() )
return;

selectionModel()->setCurrentIndex( index, QItemSelectionModel::SelectCurrent );
}
@@ -89,6 +89,16 @@ class GUI_EXPORT QgsAttributeTableView : public QTableView
QList<QgsFeatureId> selectedFeaturesIds() const;


/**
* Scroll to a feature with a given \a fid.
Optionally a \a column can be specified, which will also bring that column into view.
* \since QGIS 3.16
*/
void scrollToFeature( const QgsFeatureId &fid, int column = -1 );


protected:

/**

0 comments on commit b7ff23a

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