Skip to content

Commit 361399c

Browse files
committed
Small cleanup to QgsDualView - don't use cache to access layer
1 parent 11c4444 commit 361399c

File tree

2 files changed

+32
-30
lines changed

2 files changed

+32
-30
lines changed

src/gui/attributetable/qgsdualview.cpp

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,24 @@ void QgsDualView::init( QgsVectorLayer *layer, QgsMapCanvas *mapCanvas, const Qg
7373
if ( !layer )
7474
return;
7575

76+
mLayer = layer;
77+
7678
mEditorContext = context;
7779

7880
connect( mTableView, SIGNAL( willShowContextMenu( QMenu *, QModelIndex ) ), this, SLOT( viewWillShowContextMenu( QMenu *, QModelIndex ) ) );
7981
mTableView->horizontalHeader()->setContextMenuPolicy( Qt::CustomContextMenu );
8082
connect( mTableView->horizontalHeader(), SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( showViewHeaderMenu( QPoint ) ) );
8183
connect( mTableView, SIGNAL( columnResized( int, int ) ), this, SLOT( tableColumnResized( int, int ) ) );
8284

83-
initLayerCache( layer, !request.filterRect().isNull() );
85+
initLayerCache( !request.filterRect().isNull() );
8486
initModels( mapCanvas, request );
8587

86-
mConditionalFormatWidget->setLayer( layer );
88+
mConditionalFormatWidget->setLayer( mLayer );
8789

8890
mTableView->setModel( mFilterModel );
8991
mFeatureList->setModel( mFeatureListModel );
9092
delete mAttributeForm;
91-
mAttributeForm = new QgsAttributeForm( layer, QgsFeature(), mEditorContext );
93+
mAttributeForm = new QgsAttributeForm( mLayer, QgsFeature(), mEditorContext );
9294
if ( !context.parentContext() )
9395
{
9496
mAttributeEditorScrollArea = new QScrollArea();
@@ -120,12 +122,12 @@ void QgsDualView::init( QgsVectorLayer *layer, QgsMapCanvas *mapCanvas, const Qg
120122
void QgsDualView::columnBoxInit()
121123
{
122124
// load fields
123-
QList<QgsField> fields = mLayerCache->layer()->fields().toList();
125+
QList<QgsField> fields = mLayer->fields().toList();
124126

125127
QString defaultField;
126128

127129
// default expression: saved value
128-
QString displayExpression = mLayerCache->layer()->displayExpression();
130+
QString displayExpression = mLayer->displayExpression();
129131

130132
if ( displayExpression.isEmpty() )
131133
{
@@ -138,13 +140,13 @@ void QgsDualView::columnBoxInit()
138140

139141
Q_FOREACH ( const QgsField &field, fields )
140142
{
141-
int fieldIndex = mLayerCache->layer()->fields().lookupField( field.name() );
143+
int fieldIndex = mLayer->fields().lookupField( field.name() );
142144
if ( fieldIndex == -1 )
143145
continue;
144146

145-
if ( QgsEditorWidgetRegistry::instance()->findBest( mLayerCache->layer(), field.name() ).type() != QLatin1String( "Hidden" ) )
147+
if ( QgsEditorWidgetRegistry::instance()->findBest( mLayer, field.name() ).type() != QLatin1String( "Hidden" ) )
146148
{
147-
QIcon icon = mLayerCache->layer()->fields().iconForField( fieldIndex );
149+
QIcon icon = mLayer->fields().iconForField( fieldIndex );
148150
QString text = field.name();
149151

150152
// Generate action for the preview popup button of the feature list
@@ -198,14 +200,14 @@ void QgsDualView::setSelectedOnTop( bool selectedOnTop )
198200
mFilterModel->setSelectedOnTop( selectedOnTop );
199201
}
200202

201-
void QgsDualView::initLayerCache( QgsVectorLayer *layer, bool cacheGeometry )
203+
void QgsDualView::initLayerCache( bool cacheGeometry )
202204
{
203205
// Initialize the cache
204206
QgsSettings settings;
205207
int cacheSize = settings.value( QStringLiteral( "/qgis/attributeTableRowCache" ), "10000" ).toInt();
206-
mLayerCache = new QgsVectorLayerCache( layer, cacheSize, this );
208+
mLayerCache = new QgsVectorLayerCache( mLayer, cacheSize, this );
207209
mLayerCache->setCacheGeometry( cacheGeometry );
208-
if ( 0 == cacheSize || 0 == ( QgsVectorDataProvider::SelectAtId & mLayerCache->layer()->dataProvider()->capabilities() ) )
210+
if ( 0 == cacheSize || 0 == ( QgsVectorDataProvider::SelectAtId & mLayer->dataProvider()->capabilities() ) )
209211
{
210212
connect( mLayerCache, SIGNAL( progress( int, bool & ) ), this, SLOT( progress( int, bool & ) ) );
211213
connect( mLayerCache, SIGNAL( finished() ), this, SLOT( finished() ) );
@@ -241,13 +243,13 @@ void QgsDualView::initModels( QgsMapCanvas *mapCanvas, const QgsFeatureRequest &
241243

242244
void QgsDualView::on_mFeatureList_aboutToChangeEditSelection( bool &ok )
243245
{
244-
if ( mLayerCache->layer()->isEditable() && !mAttributeForm->save() )
246+
if ( mLayer->isEditable() && !mAttributeForm->save() )
245247
ok = false;
246248
}
247249

248250
void QgsDualView::on_mFeatureList_currentEditSelectionChanged( const QgsFeature &feat )
249251
{
250-
if ( !mLayerCache->layer()->isEditable() || mAttributeForm->save() )
252+
if ( !mLayer->isEditable() || mAttributeForm->save() )
251253
{
252254
mAttributeForm->setFeature( feat );
253255
setCurrentEditSelection( QgsFeatureIds() << feat.id() );
@@ -299,9 +301,9 @@ void QgsDualView::toggleSearchMode( bool enabled )
299301
void QgsDualView::previewExpressionBuilder()
300302
{
301303
// Show expression builder
302-
QgsExpressionContext context( QgsExpressionContextUtils::globalProjectLayerScopes( mLayerCache->layer() ) );
304+
QgsExpressionContext context( QgsExpressionContextUtils::globalProjectLayerScopes( mLayer ) );
303305

304-
QgsExpressionBuilderDialog dlg( mLayerCache->layer(), mFeatureList->displayExpression(), this, QStringLiteral( "generic" ), context );
306+
QgsExpressionBuilderDialog dlg( mLayer, mFeatureList->displayExpression(), this, QStringLiteral( "generic" ), context );
305307
dlg.setWindowTitle( tr( "Expression based preview" ) );
306308
dlg.setExpressionText( mFeatureList->displayExpression() );
307309

@@ -387,7 +389,7 @@ void QgsDualView::viewWillShowContextMenu( QMenu *menu, const QModelIndex &atInd
387389
}
388390

389391
//add user-defined actions to context menu
390-
QList<QgsAction> actions = mLayerCache->layer()->actions()->actions( QStringLiteral( "Field" ) );
392+
QList<QgsAction> actions = mLayer->actions()->actions( QStringLiteral( "Field" ) );
391393
if ( !actions.isEmpty() )
392394
{
393395
QAction *a = menu->addAction( tr( "Run layer action" ) );
@@ -404,7 +406,7 @@ void QgsDualView::viewWillShowContextMenu( QMenu *menu, const QModelIndex &atInd
404406
}
405407

406408
//add actions from QgsMapLayerActionRegistry to context menu
407-
QList<QgsMapLayerAction *> registeredActions = QgsMapLayerActionRegistry::instance()->mapLayerActions( mLayerCache->layer() );
409+
QList<QgsMapLayerAction *> registeredActions = QgsMapLayerActionRegistry::instance()->mapLayerActions( mLayer );
408410
if ( !registeredActions.isEmpty() )
409411
{
410412
//add a separator between user defined and standard actions
@@ -456,12 +458,12 @@ void QgsDualView::showViewHeaderMenu( QPoint point )
456458

457459
void QgsDualView::organizeColumns()
458460
{
459-
if ( !mLayerCache->layer() )
461+
if ( !mLayer )
460462
{
461463
return;
462464
}
463465

464-
QgsOrganizeTableColumnsDialog dialog( mLayerCache->layer(), this );
466+
QgsOrganizeTableColumnsDialog dialog( mLayer, this );
465467
if ( dialog.exec() == QDialog::Accepted )
466468
{
467469
QgsAttributeTableConfig config = dialog.config();
@@ -525,8 +527,7 @@ void QgsDualView::autosizeColumn()
525527

526528
void QgsDualView::modifySort()
527529
{
528-
QgsVectorLayer *layer = mLayerCache->layer();
529-
if ( !layer )
530+
if ( !mLayer )
530531
return;
531532

532533
QgsAttributeTableConfig config = mConfig;
@@ -547,12 +548,12 @@ void QgsDualView::modifySort()
547548
sortingGroupBox->setLayout( new QGridLayout() );
548549

549550
QgsExpressionBuilderWidget *expressionBuilder = new QgsExpressionBuilderWidget();
550-
QgsExpressionContext context( QgsExpressionContextUtils::globalProjectLayerScopes( layer ) );
551+
QgsExpressionContext context( QgsExpressionContextUtils::globalProjectLayerScopes( mLayer ) );
551552
expressionBuilder->setExpressionContext( context );
552-
expressionBuilder->setLayer( layer );
553+
expressionBuilder->setLayer( mLayer );
553554
expressionBuilder->loadFieldNames();
554555
expressionBuilder->loadRecent( QStringLiteral( "generic" ) );
555-
expressionBuilder->setExpressionText( sortExpression().isEmpty() ? layer->displayExpression() : sortExpression() );
556+
expressionBuilder->setExpressionText( sortExpression().isEmpty() ? mLayer->displayExpression() : sortExpression() );
556557

557558
sortingGroupBox->layout()->addWidget( expressionBuilder );
558559

@@ -593,7 +594,7 @@ void QgsDualView::zoomToCurrentFeature()
593594
QgsMapCanvas *canvas = mFilterModel->mapCanvas();
594595
if ( canvas )
595596
{
596-
canvas->zoomToFeatureIds( mLayerCache->layer(), ids );
597+
canvas->zoomToFeatureIds( mLayer, ids );
597598
}
598599
}
599600

@@ -610,18 +611,18 @@ void QgsDualView::panToCurrentFeature()
610611
QgsMapCanvas *canvas = mFilterModel->mapCanvas();
611612
if ( canvas )
612613
{
613-
canvas->panToFeatureIds( mLayerCache->layer(), ids );
614+
canvas->panToFeatureIds( mLayer, ids );
614615
}
615616
}
616617

617618
void QgsDualView::previewExpressionChanged( const QString &expression )
618619
{
619-
mLayerCache->layer()->setDisplayExpression( expression );
620+
mLayer->setDisplayExpression( expression );
620621
}
621622

622623
void QgsDualView::onSortColumnChanged()
623624
{
624-
QgsAttributeTableConfig cfg = mLayerCache->layer()->attributeTableConfig();
625+
QgsAttributeTableConfig cfg = mLayer->attributeTableConfig();
625626
cfg.setSortExpression( mFilterModel->sortExpression() );
626627
cfg.setSortOrder( mFilterModel->sortOrder() );
627628
setAttributeTableConfig( cfg );
@@ -665,7 +666,7 @@ void QgsDualView::setFeatureSelectionManager( QgsIFeatureSelectionManager *featu
665666

666667
void QgsDualView::setAttributeTableConfig( const QgsAttributeTableConfig &config )
667668
{
668-
mLayerCache->layer()->setAttributeTableConfig( config );
669+
mLayer->setAttributeTableConfig( config );
669670
mFilterModel->setAttributeTableConfig( config );
670671
mTableView->setAttributeTableConfig( config );
671672
mConfig = config;

src/gui/attributetable/qgsdualview.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas
324324
void panToCurrentFeature();
325325

326326
private:
327-
void initLayerCache( QgsVectorLayer *layer, bool cacheGeometry );
327+
void initLayerCache( bool cacheGeometry );
328328
void initModels( QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request );
329329

330330
QgsAttributeEditorContext mEditorContext;
@@ -336,6 +336,7 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas
336336
QMenu *mPreviewColumnsMenu = nullptr;
337337
QMenu *mHorizontalHeaderMenu = nullptr;
338338
QgsVectorLayerCache *mLayerCache = nullptr;
339+
QgsVectorLayer *mLayer = nullptr;
339340
QProgressDialog *mProgressDlg = nullptr;
340341
QgsIFeatureSelectionManager *mFeatureSelectionManager = nullptr;
341342
QgsDistanceArea mDistanceArea;

0 commit comments

Comments
 (0)