Skip to content

Commit 7daeca6

Browse files
committedMar 7, 2017
Small cleanup to QgsDualView - don't use cache to access layer
(cherry-picked from 361399c)
1 parent 307daf1 commit 7daeca6

File tree

2 files changed

+36
-34
lines changed

2 files changed

+36
-34
lines changed
 

‎src/gui/attributetable/qgsdualview.cpp

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

75+
mLayer = layer;
76+
7577
mEditorContext = context;
7678

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

82-
initLayerCache( layer, !request.filterRect().isNull() );
84+
initLayerCache( !request.filterRect().isNull() );
8385
initModels( mapCanvas, request );
8486

85-
mConditionalFormatWidget->setLayer( layer );
87+
mConditionalFormatWidget->setLayer( mLayer );
8688

8789
mTableView->setModel( mFilterModel );
8890
mFeatureList->setModel( mFeatureListModel );
8991
delete mAttributeForm;
90-
mAttributeForm = new QgsAttributeForm( layer, QgsFeature(), mEditorContext );
92+
mAttributeForm = new QgsAttributeForm( mLayer, QgsFeature(), mEditorContext );
9193
if ( !context.parentContext() )
9294
{
9395
mAttributeEditorScrollArea = new QScrollArea();
@@ -119,27 +121,27 @@ void QgsDualView::init( QgsVectorLayer* layer, QgsMapCanvas* mapCanvas, const Qg
119121
void QgsDualView::columnBoxInit()
120122
{
121123
// load fields
122-
QList<QgsField> fields = mLayerCache->layer()->fields().toList();
124+
QList<QgsField> fields = mLayer->fields().toList();
123125

124126
QString defaultField;
125127

126128
// default expression: saved value
127-
QString displayExpression = mLayerCache->layer()->displayExpression();
129+
QString displayExpression = mLayer->displayExpression();
128130

129131
// if no display expression is saved: use display field instead
130132
if ( displayExpression.isEmpty() )
131133
{
132-
if ( !mLayerCache->layer()->displayField().isEmpty() )
134+
if ( !mLayer->displayField().isEmpty() )
133135
{
134-
defaultField = mLayerCache->layer()->displayField();
136+
defaultField = mLayer->displayField();
135137
displayExpression = QString( "COALESCE(\"%1\", '<NULL>')" ).arg( defaultField );
136138
}
137139
}
138140

139141
// if neither display expression nor display field is saved...
140142
if ( displayExpression.isEmpty() )
141143
{
142-
QgsAttributeList pkAttrs = mLayerCache->layer()->pkAttributeList();
144+
QgsAttributeList pkAttrs = mLayer->pkAttributeList();
143145

144146
if ( !pkAttrs.isEmpty() )
145147
{
@@ -182,13 +184,13 @@ void QgsDualView::columnBoxInit()
182184

183185
Q_FOREACH ( const QgsField& field, fields )
184186
{
185-
int fieldIndex = mLayerCache->layer()->fieldNameIndex( field.name() );
187+
int fieldIndex = mLayer->fieldNameIndex( field.name() );
186188
if ( fieldIndex == -1 )
187189
continue;
188190

189-
if ( mLayerCache->layer()->editFormConfig()->widgetType( fieldIndex ) != "Hidden" )
191+
if ( mLayer->editFormConfig()->widgetType( fieldIndex ) != "Hidden" )
190192
{
191-
QIcon icon = mLayerCache->layer()->fields().iconForField( fieldIndex );
193+
QIcon icon = mLayer->fields().iconForField( fieldIndex );
192194
QString text = field.name();
193195

194196
// Generate action for the preview popup button of the feature list
@@ -242,14 +244,14 @@ void QgsDualView::setSelectedOnTop( bool selectedOnTop )
242244
mFilterModel->setSelectedOnTop( selectedOnTop );
243245
}
244246

245-
void QgsDualView::initLayerCache( QgsVectorLayer* layer, bool cacheGeometry )
247+
void QgsDualView::initLayerCache( bool cacheGeometry )
246248
{
247249
// Initialize the cache
248250
QSettings settings;
249251
int cacheSize = settings.value( "/qgis/attributeTableRowCache", "10000" ).toInt();
250-
mLayerCache = new QgsVectorLayerCache( layer, cacheSize, this );
252+
mLayerCache = new QgsVectorLayerCache( mLayer, cacheSize, this );
251253
mLayerCache->setCacheGeometry( cacheGeometry );
252-
if ( 0 == cacheSize || 0 == ( QgsVectorDataProvider::SelectAtId & mLayerCache->layer()->dataProvider()->capabilities() ) )
254+
if ( 0 == cacheSize || 0 == ( QgsVectorDataProvider::SelectAtId & mLayer->dataProvider()->capabilities() ) )
253255
{
254256
connect( mLayerCache, SIGNAL( progress( int, bool & ) ), this, SLOT( progress( int, bool & ) ) );
255257
connect( mLayerCache, SIGNAL( finished() ), this, SLOT( finished() ) );
@@ -285,13 +287,13 @@ void QgsDualView::initModels( QgsMapCanvas* mapCanvas, const QgsFeatureRequest&
285287

286288
void QgsDualView::on_mFeatureList_aboutToChangeEditSelection( bool& ok )
287289
{
288-
if ( mLayerCache->layer()->isEditable() && !mAttributeForm->save() )
290+
if ( mLayer->isEditable() && !mAttributeForm->save() )
289291
ok = false;
290292
}
291293

292294
void QgsDualView::on_mFeatureList_currentEditSelectionChanged( const QgsFeature &feat )
293295
{
294-
if ( !mLayerCache->layer()->isEditable() || mAttributeForm->save() )
296+
if ( !mLayer->isEditable() || mAttributeForm->save() )
295297
{
296298
mAttributeForm->setFeature( feat );
297299
setCurrentEditSelection( QgsFeatureIds() << feat.id() );
@@ -346,9 +348,9 @@ void QgsDualView::previewExpressionBuilder()
346348
QgsExpressionContext context;
347349
context << QgsExpressionContextUtils::globalScope()
348350
<< QgsExpressionContextUtils::projectScope()
349-
<< QgsExpressionContextUtils::layerScope( mLayerCache->layer() );
351+
<< QgsExpressionContextUtils::layerScope( mLayer );
350352

351-
QgsExpressionBuilderDialog dlg( mLayerCache->layer(), mFeatureList->displayExpression(), this, "generic", context );
353+
QgsExpressionBuilderDialog dlg( mLayer, mFeatureList->displayExpression(), this, "generic", context );
352354
dlg.setWindowTitle( tr( "Expression based preview" ) );
353355
dlg.setExpressionText( mFeatureList->displayExpression() );
354356

@@ -433,15 +435,15 @@ void QgsDualView::viewWillShowContextMenu( QMenu* menu, const QModelIndex& atInd
433435
}
434436

435437
//add user-defined actions to context menu
436-
if ( mLayerCache->layer()->actions()->size() != 0 )
438+
if ( mLayer->actions()->size() != 0 )
437439
{
438440

439441
QAction *a = menu->addAction( tr( "Run layer action" ) );
440442
a->setEnabled( false );
441443

442-
for ( int i = 0; i < mLayerCache->layer()->actions()->size(); i++ )
444+
for ( int i = 0; i < mLayer->actions()->size(); i++ )
443445
{
444-
const QgsAction &action = mLayerCache->layer()->actions()->at( i );
446+
const QgsAction &action = mLayer->actions()->at( i );
445447

446448
if ( !action.runable() )
447449
continue;
@@ -452,7 +454,7 @@ void QgsDualView::viewWillShowContextMenu( QMenu* menu, const QModelIndex& atInd
452454
}
453455

454456
//add actions from QgsMapLayerActionRegistry to context menu
455-
QList<QgsMapLayerAction *> registeredActions = QgsMapLayerActionRegistry::instance()->mapLayerActions( mLayerCache->layer() );
457+
QList<QgsMapLayerAction *> registeredActions = QgsMapLayerActionRegistry::instance()->mapLayerActions( mLayer );
456458
if ( !registeredActions.isEmpty() )
457459
{
458460
//add a separator between user defined and standard actions
@@ -504,12 +506,12 @@ void QgsDualView::showViewHeaderMenu( QPoint point )
504506

505507
void QgsDualView::organizeColumns()
506508
{
507-
if ( !mLayerCache->layer() )
509+
if ( !mLayer )
508510
{
509511
return;
510512
}
511513

512-
QgsOrganizeTableColumnsDialog dialog( mLayerCache->layer(), this );
514+
QgsOrganizeTableColumnsDialog dialog( mLayer, this );
513515
if ( dialog.exec() == QDialog::Accepted )
514516
{
515517
QgsAttributeTableConfig config = dialog.config();
@@ -573,8 +575,7 @@ void QgsDualView::autosizeColumn()
573575

574576
void QgsDualView::modifySort()
575577
{
576-
QgsVectorLayer* layer = mLayerCache->layer();
577-
if ( !layer )
578+
if ( !mLayer )
578579
return;
579580

580581
QgsAttributeTableConfig config = mConfig;
@@ -598,12 +599,12 @@ void QgsDualView::modifySort()
598599
QgsExpressionContext context;
599600
context << QgsExpressionContextUtils::globalScope()
600601
<< QgsExpressionContextUtils::projectScope()
601-
<< QgsExpressionContextUtils::layerScope( layer );
602+
<< QgsExpressionContextUtils::layerScope( mLayer );
602603
expressionBuilder->setExpressionContext( context );
603-
expressionBuilder->setLayer( layer );
604+
expressionBuilder->setLayer( mLayer );
604605
expressionBuilder->loadFieldNames();
605606
expressionBuilder->loadRecent( "generic" );
606-
expressionBuilder->setExpressionText( sortExpression().isEmpty() ? layer->displayExpression() : sortExpression() );
607+
expressionBuilder->setExpressionText( sortExpression().isEmpty() ? mLayer->displayExpression() : sortExpression() );
607608

608609
sortingGroupBox->layout()->addWidget( expressionBuilder );
609610

@@ -644,18 +645,18 @@ void QgsDualView::zoomToCurrentFeature()
644645
QgsMapCanvas* canvas = mFilterModel->mapCanvas();
645646
if ( canvas )
646647
{
647-
canvas->zoomToFeatureIds( mLayerCache->layer(), ids );
648+
canvas->zoomToFeatureIds( mLayer, ids );
648649
}
649650
}
650651

651652
void QgsDualView::previewExpressionChanged( const QString& expression )
652653
{
653-
mLayerCache->layer()->setDisplayExpression( expression );
654+
mLayer->setDisplayExpression( expression );
654655
}
655656

656657
void QgsDualView::onSortColumnChanged()
657658
{
658-
QgsAttributeTableConfig cfg = mLayerCache->layer()->attributeTableConfig();
659+
QgsAttributeTableConfig cfg = mLayer->attributeTableConfig();
659660
cfg.setSortExpression( mFilterModel->sortExpression() );
660661
cfg.setSortOrder( mFilterModel->sortOrder() );
661662
setAttributeTableConfig( cfg );
@@ -699,7 +700,7 @@ void QgsDualView::setFeatureSelectionManager( QgsIFeatureSelectionManager* featu
699700

700701
void QgsDualView::setAttributeTableConfig( const QgsAttributeTableConfig& config )
701702
{
702-
mLayerCache->layer()->setAttributeTableConfig( config );
703+
mLayer->setAttributeTableConfig( config );
703704
mFilterModel->setAttributeTableConfig( config );
704705
mTableView->setAttributeTableConfig( config );
705706
mConfig = config;

‎src/gui/attributetable/qgsdualview.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas
319319
void zoomToCurrentFeature();
320320

321321
private:
322-
void initLayerCache( QgsVectorLayer *layer, bool cacheGeometry );
322+
void initLayerCache( bool cacheGeometry );
323323
void initModels( QgsMapCanvas* mapCanvas, const QgsFeatureRequest& request );
324324

325325
QgsAttributeEditorContext mEditorContext;
@@ -331,6 +331,7 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas
331331
QMenu* mPreviewColumnsMenu;
332332
QMenu* mHorizontalHeaderMenu;
333333
QgsVectorLayerCache* mLayerCache;
334+
QgsVectorLayer *mLayer;
334335
QProgressDialog* mProgressDlg;
335336
QgsIFeatureSelectionManager* mFeatureSelectionManager;
336337
QgsDistanceArea mDistanceArea;

0 commit comments

Comments
 (0)
Please sign in to comment.