Skip to content

Commit

Permalink
Merge pull request #38658 from suricactus/37847_scroll_to_f
Browse files Browse the repository at this point in the history
FIX 37847 New feature is hidden when created from attribute table
  • Loading branch information
signedav authored and nyalldawson committed Oct 23, 2020
1 parent e5ab8ef commit 0aa2b80
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/app/qgsattributetabledialog.cpp
Expand Up @@ -834,6 +834,7 @@ void QgsAttributeTableDialog::mActionAddFeature_triggered()
if ( action.addFeature() )
{
masterModel->reload( masterModel->index( 0, 0 ), masterModel->index( masterModel->rowCount() - 1, masterModel->columnCount() - 1 ) );
mMainView->setCurrentEditSelection( QgsFeatureIds() << action.feature().id() );
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/app/qgsfeatureaction.cpp
Expand Up @@ -313,4 +313,9 @@ void QgsFeatureAction::onFeatureSaved( const QgsFeature &feature )
}
}

QgsFeature QgsFeatureAction::feature() const
{
return mFeature ? *mFeature : QgsFeature();
}

QHash<QgsVectorLayer *, QgsAttributeMap> QgsFeatureAction::sLastUsedValues;
5 changes: 5 additions & 0 deletions src/app/qgsfeatureaction.h
Expand Up @@ -61,6 +61,11 @@ class APP_EXPORT QgsFeatureAction : public QAction
*/
void setForceSuppressFormPopup( bool force );

/**
* Returns the added feature or invalid feature in case addFeature() was not successful.
*/
QgsFeature feature() const;

signals:

/**
Expand Down
14 changes: 13 additions & 1 deletion src/gui/attributetable/qgsfeaturelistview.cpp
Expand Up @@ -189,18 +189,27 @@ void QgsFeatureListView::selectAll()
void QgsFeatureListView::setEditSelection( const QgsFeatureIds &fids )
{
QItemSelection selection;
QModelIndex firstModelIdx;

const auto constFids = fids;
for ( QgsFeatureId fid : constFids )
{
selection.append( QItemSelectionRange( mModel->mapToMaster( mModel->fidToIdx( fid ) ) ) );
QModelIndex modelIdx = mModel->fidToIdx( fid );

if ( ! firstModelIdx.isValid() )
firstModelIdx = modelIdx;

selection.append( QItemSelectionRange( mModel->mapToMaster( modelIdx ) ) );
}

bool ok = true;
emit aboutToChangeEditSelection( ok );

if ( ok )
{
mCurrentEditSelectionModel->select( selection, QItemSelectionModel::ClearAndSelect );
scrollTo( firstModelIdx );
}
}

void QgsFeatureListView::setEditSelection( const QModelIndex &index, QItemSelectionModel::SelectionFlags command )
Expand All @@ -211,7 +220,10 @@ void QgsFeatureListView::setEditSelection( const QModelIndex &index, QItemSelect
Q_ASSERT( index.model() == mModel->masterModel() || !index.isValid() );

if ( ok )
{
mCurrentEditSelectionModel->select( index, command );
scrollTo( index );
}
}

void QgsFeatureListView::repaintRequested( const QModelIndexList &indexes )
Expand Down

0 comments on commit 0aa2b80

Please sign in to comment.