Skip to content

Commit 3f67897

Browse files
committedSep 9, 2020
FIX 37847 New feature is hidden when created from attribute table
1 parent a51c201 commit 3f67897

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed
 

‎src/app/qgsattributetabledialog.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ void QgsAttributeTableDialog::mActionAddFeatureViaAttributeTable_triggered()
623623
if ( action.addFeature() )
624624
{
625625
masterModel->reload( masterModel->index( 0, 0 ), masterModel->index( masterModel->rowCount() - 1, masterModel->columnCount() - 1 ) );
626+
mMainView->setCurrentEditSelection( QgsFeatureIds() << action.feature()->id() );
626627
}
627628
}
628629

@@ -643,6 +644,7 @@ void QgsAttributeTableDialog::mActionAddFeatureViaAttributeForm_triggered()
643644
if ( action.addFeature() )
644645
{
645646
masterModel->reload( masterModel->index( 0, 0 ), masterModel->index( masterModel->rowCount() - 1, masterModel->columnCount() - 1 ) );
647+
mMainView->setCurrentEditSelection( QgsFeatureIds() << action.feature()->id() );
646648
}
647649
}
648650

‎src/app/qgsfeatureaction.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ class APP_EXPORT QgsFeatureAction : public QAction
6161
*/
6262
void setForceSuppressFormPopup( bool force );
6363

64+
/**
65+
* Returns the current feature. It might be nullptr feature, so it's safe to use this method only
66+
* right after`addFeature()` returned true.
67+
*/
68+
QgsFeature *feature() const { return mFeature; }
69+
6470
signals:
6571

6672
/**

‎src/gui/attributetable/qgsfeaturelistview.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,18 +189,27 @@ void QgsFeatureListView::selectAll()
189189
void QgsFeatureListView::setEditSelection( const QgsFeatureIds &fids )
190190
{
191191
QItemSelection selection;
192+
QModelIndex firstModelIdx;
192193

193194
const auto constFids = fids;
194195
for ( QgsFeatureId fid : constFids )
195196
{
196-
selection.append( QItemSelectionRange( mModel->mapToMaster( mModel->fidToIdx( fid ) ) ) );
197+
QModelIndex modelIdx = mModel->fidToIdx( fid );
198+
199+
if ( ! firstModelIdx.isValid() )
200+
firstModelIdx = modelIdx;
201+
202+
selection.append( QItemSelectionRange( mModel->mapToMaster( firstModelIdx ) ) );
197203
}
198204

199205
bool ok = true;
200206
emit aboutToChangeEditSelection( ok );
201207

202208
if ( ok )
209+
{
203210
mCurrentEditSelectionModel->select( selection, QItemSelectionModel::ClearAndSelect );
211+
scrollTo( firstModelIdx );
212+
}
204213
}
205214

206215
void QgsFeatureListView::setEditSelection( const QModelIndex &index, QItemSelectionModel::SelectionFlags command )
@@ -212,7 +221,10 @@ void QgsFeatureListView::setEditSelection( const QModelIndex &index, QItemSelect
212221
Q_ASSERT( index.model() == mModel->masterModel() || !index.isValid() );
213222

214223
if ( ok )
224+
{
215225
mCurrentEditSelectionModel->select( index, command );
226+
scrollTo( index );
227+
}
216228
}
217229

218230
void QgsFeatureListView::repaintRequested( const QModelIndexList &indexes )

0 commit comments

Comments
 (0)
Please sign in to comment.