Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #38684 from qgis-bot/backport-38658-to-release-3_14
[Backport release-3_14] FIX 37847 New feature is hidden when created from attribute table
  • Loading branch information
m-kuhn committed Sep 11, 2020
2 parents 7d1db1b + b04da14 commit 2af34bb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/app/qgsattributetabledialog.cpp
Expand Up @@ -623,6 +623,7 @@ void QgsAttributeTableDialog::mActionAddFeatureViaAttributeTable_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 All @@ -643,6 +644,7 @@ void QgsAttributeTableDialog::mActionAddFeatureViaAttributeForm_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 @@ -212,7 +221,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 2af34bb

Please sign in to comment.