Skip to content

Commit

Permalink
FIX 37847 New feature is hidden when created from attribute table
Browse files Browse the repository at this point in the history
  • Loading branch information
suricactus committed Sep 9, 2020
1 parent a51c201 commit 3f67897
Show file tree
Hide file tree
Showing 3 changed files with 21 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
6 changes: 6 additions & 0 deletions src/app/qgsfeatureaction.h
Expand Up @@ -61,6 +61,12 @@ class APP_EXPORT QgsFeatureAction : public QAction
*/
void setForceSuppressFormPopup( bool force );

/**
* Returns the current feature. It might be nullptr feature, so it's safe to use this method only
* right after`addFeature()` returned true.
*/
QgsFeature *feature() const { return mFeature; }

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( firstModelIdx ) ) );
}

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 3f67897

Please sign in to comment.