@@ -72,22 +72,24 @@ void QgsDualView::init( QgsVectorLayer* layer, QgsMapCanvas* mapCanvas, const Qg
72
72
if ( !layer )
73
73
return ;
74
74
75
+ mLayer = layer;
76
+
75
77
mEditorContext = context;
76
78
77
79
connect ( mTableView , SIGNAL ( willShowContextMenu ( QMenu*, QModelIndex ) ), this , SLOT ( viewWillShowContextMenu ( QMenu*, QModelIndex ) ) );
78
80
mTableView ->horizontalHeader ()->setContextMenuPolicy ( Qt::CustomContextMenu );
79
81
connect ( mTableView ->horizontalHeader (), SIGNAL ( customContextMenuRequested ( QPoint ) ), this , SLOT ( showViewHeaderMenu ( QPoint ) ) );
80
82
connect ( mTableView , SIGNAL ( columnResized ( int , int ) ), this , SLOT ( tableColumnResized ( int , int ) ) );
81
83
82
- initLayerCache ( layer, !request.filterRect ().isNull () );
84
+ initLayerCache ( !request.filterRect ().isNull () );
83
85
initModels ( mapCanvas, request );
84
86
85
- mConditionalFormatWidget ->setLayer ( layer );
87
+ mConditionalFormatWidget ->setLayer ( mLayer );
86
88
87
89
mTableView ->setModel ( mFilterModel );
88
90
mFeatureList ->setModel ( mFeatureListModel );
89
91
delete mAttributeForm ;
90
- mAttributeForm = new QgsAttributeForm ( layer , QgsFeature (), mEditorContext );
92
+ mAttributeForm = new QgsAttributeForm ( mLayer , QgsFeature (), mEditorContext );
91
93
if ( !context.parentContext () )
92
94
{
93
95
mAttributeEditorScrollArea = new QScrollArea ();
@@ -119,27 +121,27 @@ void QgsDualView::init( QgsVectorLayer* layer, QgsMapCanvas* mapCanvas, const Qg
119
121
void QgsDualView::columnBoxInit ()
120
122
{
121
123
// load fields
122
- QList<QgsField> fields = mLayerCache -> layer () ->fields ().toList ();
124
+ QList<QgsField> fields = mLayer ->fields ().toList ();
123
125
124
126
QString defaultField;
125
127
126
128
// default expression: saved value
127
- QString displayExpression = mLayerCache -> layer () ->displayExpression ();
129
+ QString displayExpression = mLayer ->displayExpression ();
128
130
129
131
// if no display expression is saved: use display field instead
130
132
if ( displayExpression.isEmpty () )
131
133
{
132
- if ( !mLayerCache -> layer () ->displayField ().isEmpty () )
134
+ if ( !mLayer ->displayField ().isEmpty () )
133
135
{
134
- defaultField = mLayerCache -> layer () ->displayField ();
136
+ defaultField = mLayer ->displayField ();
135
137
displayExpression = QString ( " COALESCE(\" %1\" , '<NULL>')" ).arg ( defaultField );
136
138
}
137
139
}
138
140
139
141
// if neither display expression nor display field is saved...
140
142
if ( displayExpression.isEmpty () )
141
143
{
142
- QgsAttributeList pkAttrs = mLayerCache -> layer () ->pkAttributeList ();
144
+ QgsAttributeList pkAttrs = mLayer ->pkAttributeList ();
143
145
144
146
if ( !pkAttrs.isEmpty () )
145
147
{
@@ -182,13 +184,13 @@ void QgsDualView::columnBoxInit()
182
184
183
185
Q_FOREACH ( const QgsField& field, fields )
184
186
{
185
- int fieldIndex = mLayerCache -> layer () ->fieldNameIndex ( field.name () );
187
+ int fieldIndex = mLayer ->fieldNameIndex ( field.name () );
186
188
if ( fieldIndex == -1 )
187
189
continue ;
188
190
189
- if ( mLayerCache -> layer () ->editFormConfig ()->widgetType ( fieldIndex ) != " Hidden" )
191
+ if ( mLayer ->editFormConfig ()->widgetType ( fieldIndex ) != " Hidden" )
190
192
{
191
- QIcon icon = mLayerCache -> layer () ->fields ().iconForField ( fieldIndex );
193
+ QIcon icon = mLayer ->fields ().iconForField ( fieldIndex );
192
194
QString text = field.name ();
193
195
194
196
// Generate action for the preview popup button of the feature list
@@ -242,14 +244,14 @@ void QgsDualView::setSelectedOnTop( bool selectedOnTop )
242
244
mFilterModel ->setSelectedOnTop ( selectedOnTop );
243
245
}
244
246
245
- void QgsDualView::initLayerCache ( QgsVectorLayer* layer, bool cacheGeometry )
247
+ void QgsDualView::initLayerCache ( bool cacheGeometry )
246
248
{
247
249
// Initialize the cache
248
250
QSettings settings;
249
251
int cacheSize = settings.value ( " /qgis/attributeTableRowCache" , " 10000" ).toInt ();
250
- mLayerCache = new QgsVectorLayerCache ( layer , cacheSize, this );
252
+ mLayerCache = new QgsVectorLayerCache ( mLayer , cacheSize, this );
251
253
mLayerCache ->setCacheGeometry ( cacheGeometry );
252
- if ( 0 == cacheSize || 0 == ( QgsVectorDataProvider::SelectAtId & mLayerCache -> layer () ->dataProvider ()->capabilities () ) )
254
+ if ( 0 == cacheSize || 0 == ( QgsVectorDataProvider::SelectAtId & mLayer ->dataProvider ()->capabilities () ) )
253
255
{
254
256
connect ( mLayerCache , SIGNAL ( progress ( int , bool & ) ), this , SLOT ( progress ( int , bool & ) ) );
255
257
connect ( mLayerCache , SIGNAL ( finished () ), this , SLOT ( finished () ) );
@@ -285,13 +287,13 @@ void QgsDualView::initModels( QgsMapCanvas* mapCanvas, const QgsFeatureRequest&
285
287
286
288
void QgsDualView::on_mFeatureList_aboutToChangeEditSelection ( bool & ok )
287
289
{
288
- if ( mLayerCache -> layer () ->isEditable () && !mAttributeForm ->save () )
290
+ if ( mLayer ->isEditable () && !mAttributeForm ->save () )
289
291
ok = false ;
290
292
}
291
293
292
294
void QgsDualView::on_mFeatureList_currentEditSelectionChanged ( const QgsFeature &feat )
293
295
{
294
- if ( !mLayerCache -> layer () ->isEditable () || mAttributeForm ->save () )
296
+ if ( !mLayer ->isEditable () || mAttributeForm ->save () )
295
297
{
296
298
mAttributeForm ->setFeature ( feat );
297
299
setCurrentEditSelection ( QgsFeatureIds () << feat.id () );
@@ -346,9 +348,9 @@ void QgsDualView::previewExpressionBuilder()
346
348
QgsExpressionContext context;
347
349
context << QgsExpressionContextUtils::globalScope ()
348
350
<< QgsExpressionContextUtils::projectScope ()
349
- << QgsExpressionContextUtils::layerScope ( mLayerCache -> layer () );
351
+ << QgsExpressionContextUtils::layerScope ( mLayer );
350
352
351
- QgsExpressionBuilderDialog dlg ( mLayerCache -> layer () , mFeatureList ->displayExpression (), this , " generic" , context );
353
+ QgsExpressionBuilderDialog dlg ( mLayer , mFeatureList ->displayExpression (), this , " generic" , context );
352
354
dlg.setWindowTitle ( tr ( " Expression based preview" ) );
353
355
dlg.setExpressionText ( mFeatureList ->displayExpression () );
354
356
@@ -433,15 +435,15 @@ void QgsDualView::viewWillShowContextMenu( QMenu* menu, const QModelIndex& atInd
433
435
}
434
436
435
437
// add user-defined actions to context menu
436
- if ( mLayerCache -> layer () ->actions ()->size () != 0 )
438
+ if ( mLayer ->actions ()->size () != 0 )
437
439
{
438
440
439
441
QAction *a = menu->addAction ( tr ( " Run layer action" ) );
440
442
a->setEnabled ( false );
441
443
442
- for ( int i = 0 ; i < mLayerCache -> layer () ->actions ()->size (); i++ )
444
+ for ( int i = 0 ; i < mLayer ->actions ()->size (); i++ )
443
445
{
444
- const QgsAction &action = mLayerCache -> layer () ->actions ()->at ( i );
446
+ const QgsAction &action = mLayer ->actions ()->at ( i );
445
447
446
448
if ( !action.runable () )
447
449
continue ;
@@ -452,7 +454,7 @@ void QgsDualView::viewWillShowContextMenu( QMenu* menu, const QModelIndex& atInd
452
454
}
453
455
454
456
// add actions from QgsMapLayerActionRegistry to context menu
455
- QList<QgsMapLayerAction *> registeredActions = QgsMapLayerActionRegistry::instance ()->mapLayerActions ( mLayerCache -> layer () );
457
+ QList<QgsMapLayerAction *> registeredActions = QgsMapLayerActionRegistry::instance ()->mapLayerActions ( mLayer );
456
458
if ( !registeredActions.isEmpty () )
457
459
{
458
460
// add a separator between user defined and standard actions
@@ -504,12 +506,12 @@ void QgsDualView::showViewHeaderMenu( QPoint point )
504
506
505
507
void QgsDualView::organizeColumns ()
506
508
{
507
- if ( !mLayerCache -> layer () )
509
+ if ( !mLayer )
508
510
{
509
511
return ;
510
512
}
511
513
512
- QgsOrganizeTableColumnsDialog dialog ( mLayerCache -> layer () , this );
514
+ QgsOrganizeTableColumnsDialog dialog ( mLayer , this );
513
515
if ( dialog.exec () == QDialog::Accepted )
514
516
{
515
517
QgsAttributeTableConfig config = dialog.config ();
@@ -573,8 +575,7 @@ void QgsDualView::autosizeColumn()
573
575
574
576
void QgsDualView::modifySort ()
575
577
{
576
- QgsVectorLayer* layer = mLayerCache ->layer ();
577
- if ( !layer )
578
+ if ( !mLayer )
578
579
return ;
579
580
580
581
QgsAttributeTableConfig config = mConfig ;
@@ -598,12 +599,12 @@ void QgsDualView::modifySort()
598
599
QgsExpressionContext context;
599
600
context << QgsExpressionContextUtils::globalScope ()
600
601
<< QgsExpressionContextUtils::projectScope ()
601
- << QgsExpressionContextUtils::layerScope ( layer );
602
+ << QgsExpressionContextUtils::layerScope ( mLayer );
602
603
expressionBuilder->setExpressionContext ( context );
603
- expressionBuilder->setLayer ( layer );
604
+ expressionBuilder->setLayer ( mLayer );
604
605
expressionBuilder->loadFieldNames ();
605
606
expressionBuilder->loadRecent ( " generic" );
606
- expressionBuilder->setExpressionText ( sortExpression ().isEmpty () ? layer ->displayExpression () : sortExpression () );
607
+ expressionBuilder->setExpressionText ( sortExpression ().isEmpty () ? mLayer ->displayExpression () : sortExpression () );
607
608
608
609
sortingGroupBox->layout ()->addWidget ( expressionBuilder );
609
610
@@ -644,18 +645,18 @@ void QgsDualView::zoomToCurrentFeature()
644
645
QgsMapCanvas* canvas = mFilterModel ->mapCanvas ();
645
646
if ( canvas )
646
647
{
647
- canvas->zoomToFeatureIds ( mLayerCache -> layer () , ids );
648
+ canvas->zoomToFeatureIds ( mLayer , ids );
648
649
}
649
650
}
650
651
651
652
void QgsDualView::previewExpressionChanged ( const QString& expression )
652
653
{
653
- mLayerCache -> layer () ->setDisplayExpression ( expression );
654
+ mLayer ->setDisplayExpression ( expression );
654
655
}
655
656
656
657
void QgsDualView::onSortColumnChanged ()
657
658
{
658
- QgsAttributeTableConfig cfg = mLayerCache -> layer () ->attributeTableConfig ();
659
+ QgsAttributeTableConfig cfg = mLayer ->attributeTableConfig ();
659
660
cfg.setSortExpression ( mFilterModel ->sortExpression () );
660
661
cfg.setSortOrder ( mFilterModel ->sortOrder () );
661
662
setAttributeTableConfig ( cfg );
@@ -699,7 +700,7 @@ void QgsDualView::setFeatureSelectionManager( QgsIFeatureSelectionManager* featu
699
700
700
701
void QgsDualView::setAttributeTableConfig ( const QgsAttributeTableConfig& config )
701
702
{
702
- mLayerCache -> layer () ->setAttributeTableConfig ( config );
703
+ mLayer ->setAttributeTableConfig ( config );
703
704
mFilterModel ->setAttributeTableConfig ( config );
704
705
mTableView ->setAttributeTableConfig ( config );
705
706
mConfig = config;
0 commit comments