@@ -73,22 +73,24 @@ void QgsDualView::init( QgsVectorLayer *layer, QgsMapCanvas *mapCanvas, const Qg
73
73
if ( !layer )
74
74
return ;
75
75
76
+ mLayer = layer;
77
+
76
78
mEditorContext = context;
77
79
78
80
connect ( mTableView , SIGNAL ( willShowContextMenu ( QMenu *, QModelIndex ) ), this , SLOT ( viewWillShowContextMenu ( QMenu *, QModelIndex ) ) );
79
81
mTableView ->horizontalHeader ()->setContextMenuPolicy ( Qt::CustomContextMenu );
80
82
connect ( mTableView ->horizontalHeader (), SIGNAL ( customContextMenuRequested ( QPoint ) ), this , SLOT ( showViewHeaderMenu ( QPoint ) ) );
81
83
connect ( mTableView , SIGNAL ( columnResized ( int , int ) ), this , SLOT ( tableColumnResized ( int , int ) ) );
82
84
83
- initLayerCache ( layer, !request.filterRect ().isNull () );
85
+ initLayerCache ( !request.filterRect ().isNull () );
84
86
initModels ( mapCanvas, request );
85
87
86
- mConditionalFormatWidget ->setLayer ( layer );
88
+ mConditionalFormatWidget ->setLayer ( mLayer );
87
89
88
90
mTableView ->setModel ( mFilterModel );
89
91
mFeatureList ->setModel ( mFeatureListModel );
90
92
delete mAttributeForm ;
91
- mAttributeForm = new QgsAttributeForm ( layer , QgsFeature (), mEditorContext );
93
+ mAttributeForm = new QgsAttributeForm ( mLayer , QgsFeature (), mEditorContext );
92
94
if ( !context.parentContext () )
93
95
{
94
96
mAttributeEditorScrollArea = new QScrollArea ();
@@ -120,12 +122,12 @@ void QgsDualView::init( QgsVectorLayer *layer, QgsMapCanvas *mapCanvas, const Qg
120
122
void QgsDualView::columnBoxInit ()
121
123
{
122
124
// load fields
123
- QList<QgsField> fields = mLayerCache -> layer () ->fields ().toList ();
125
+ QList<QgsField> fields = mLayer ->fields ().toList ();
124
126
125
127
QString defaultField;
126
128
127
129
// default expression: saved value
128
- QString displayExpression = mLayerCache -> layer () ->displayExpression ();
130
+ QString displayExpression = mLayer ->displayExpression ();
129
131
130
132
if ( displayExpression.isEmpty () )
131
133
{
@@ -138,13 +140,13 @@ void QgsDualView::columnBoxInit()
138
140
139
141
Q_FOREACH ( const QgsField &field, fields )
140
142
{
141
- int fieldIndex = mLayerCache -> layer () ->fields ().lookupField ( field.name () );
143
+ int fieldIndex = mLayer ->fields ().lookupField ( field.name () );
142
144
if ( fieldIndex == -1 )
143
145
continue ;
144
146
145
- if ( QgsEditorWidgetRegistry::instance ()->findBest ( mLayerCache -> layer () , field.name () ).type () != QLatin1String ( " Hidden" ) )
147
+ if ( QgsEditorWidgetRegistry::instance ()->findBest ( mLayer , field.name () ).type () != QLatin1String ( " Hidden" ) )
146
148
{
147
- QIcon icon = mLayerCache -> layer () ->fields ().iconForField ( fieldIndex );
149
+ QIcon icon = mLayer ->fields ().iconForField ( fieldIndex );
148
150
QString text = field.name ();
149
151
150
152
// Generate action for the preview popup button of the feature list
@@ -198,14 +200,14 @@ void QgsDualView::setSelectedOnTop( bool selectedOnTop )
198
200
mFilterModel ->setSelectedOnTop ( selectedOnTop );
199
201
}
200
202
201
- void QgsDualView::initLayerCache ( QgsVectorLayer *layer, bool cacheGeometry )
203
+ void QgsDualView::initLayerCache ( bool cacheGeometry )
202
204
{
203
205
// Initialize the cache
204
206
QgsSettings settings;
205
207
int cacheSize = settings.value ( QStringLiteral ( " /qgis/attributeTableRowCache" ), " 10000" ).toInt ();
206
- mLayerCache = new QgsVectorLayerCache ( layer , cacheSize, this );
208
+ mLayerCache = new QgsVectorLayerCache ( mLayer , cacheSize, this );
207
209
mLayerCache ->setCacheGeometry ( cacheGeometry );
208
- if ( 0 == cacheSize || 0 == ( QgsVectorDataProvider::SelectAtId & mLayerCache -> layer () ->dataProvider ()->capabilities () ) )
210
+ if ( 0 == cacheSize || 0 == ( QgsVectorDataProvider::SelectAtId & mLayer ->dataProvider ()->capabilities () ) )
209
211
{
210
212
connect ( mLayerCache , SIGNAL ( progress ( int , bool & ) ), this , SLOT ( progress ( int , bool & ) ) );
211
213
connect ( mLayerCache , SIGNAL ( finished () ), this , SLOT ( finished () ) );
@@ -241,13 +243,13 @@ void QgsDualView::initModels( QgsMapCanvas *mapCanvas, const QgsFeatureRequest &
241
243
242
244
void QgsDualView::on_mFeatureList_aboutToChangeEditSelection ( bool &ok )
243
245
{
244
- if ( mLayerCache -> layer () ->isEditable () && !mAttributeForm ->save () )
246
+ if ( mLayer ->isEditable () && !mAttributeForm ->save () )
245
247
ok = false ;
246
248
}
247
249
248
250
void QgsDualView::on_mFeatureList_currentEditSelectionChanged ( const QgsFeature &feat )
249
251
{
250
- if ( !mLayerCache -> layer () ->isEditable () || mAttributeForm ->save () )
252
+ if ( !mLayer ->isEditable () || mAttributeForm ->save () )
251
253
{
252
254
mAttributeForm ->setFeature ( feat );
253
255
setCurrentEditSelection ( QgsFeatureIds () << feat.id () );
@@ -299,9 +301,9 @@ void QgsDualView::toggleSearchMode( bool enabled )
299
301
void QgsDualView::previewExpressionBuilder ()
300
302
{
301
303
// Show expression builder
302
- QgsExpressionContext context ( QgsExpressionContextUtils::globalProjectLayerScopes ( mLayerCache -> layer () ) );
304
+ QgsExpressionContext context ( QgsExpressionContextUtils::globalProjectLayerScopes ( mLayer ) );
303
305
304
- QgsExpressionBuilderDialog dlg ( mLayerCache -> layer () , mFeatureList ->displayExpression (), this , QStringLiteral ( " generic" ), context );
306
+ QgsExpressionBuilderDialog dlg ( mLayer , mFeatureList ->displayExpression (), this , QStringLiteral ( " generic" ), context );
305
307
dlg.setWindowTitle ( tr ( " Expression based preview" ) );
306
308
dlg.setExpressionText ( mFeatureList ->displayExpression () );
307
309
@@ -387,7 +389,7 @@ void QgsDualView::viewWillShowContextMenu( QMenu *menu, const QModelIndex &atInd
387
389
}
388
390
389
391
// 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" ) );
391
393
if ( !actions.isEmpty () )
392
394
{
393
395
QAction *a = menu->addAction ( tr ( " Run layer action" ) );
@@ -404,7 +406,7 @@ void QgsDualView::viewWillShowContextMenu( QMenu *menu, const QModelIndex &atInd
404
406
}
405
407
406
408
// add actions from QgsMapLayerActionRegistry to context menu
407
- QList<QgsMapLayerAction *> registeredActions = QgsMapLayerActionRegistry::instance ()->mapLayerActions ( mLayerCache -> layer () );
409
+ QList<QgsMapLayerAction *> registeredActions = QgsMapLayerActionRegistry::instance ()->mapLayerActions ( mLayer );
408
410
if ( !registeredActions.isEmpty () )
409
411
{
410
412
// add a separator between user defined and standard actions
@@ -456,12 +458,12 @@ void QgsDualView::showViewHeaderMenu( QPoint point )
456
458
457
459
void QgsDualView::organizeColumns ()
458
460
{
459
- if ( !mLayerCache -> layer () )
461
+ if ( !mLayer )
460
462
{
461
463
return ;
462
464
}
463
465
464
- QgsOrganizeTableColumnsDialog dialog ( mLayerCache -> layer () , this );
466
+ QgsOrganizeTableColumnsDialog dialog ( mLayer , this );
465
467
if ( dialog.exec () == QDialog::Accepted )
466
468
{
467
469
QgsAttributeTableConfig config = dialog.config ();
@@ -525,8 +527,7 @@ void QgsDualView::autosizeColumn()
525
527
526
528
void QgsDualView::modifySort ()
527
529
{
528
- QgsVectorLayer *layer = mLayerCache ->layer ();
529
- if ( !layer )
530
+ if ( !mLayer )
530
531
return ;
531
532
532
533
QgsAttributeTableConfig config = mConfig ;
@@ -547,12 +548,12 @@ void QgsDualView::modifySort()
547
548
sortingGroupBox->setLayout ( new QGridLayout () );
548
549
549
550
QgsExpressionBuilderWidget *expressionBuilder = new QgsExpressionBuilderWidget ();
550
- QgsExpressionContext context ( QgsExpressionContextUtils::globalProjectLayerScopes ( layer ) );
551
+ QgsExpressionContext context ( QgsExpressionContextUtils::globalProjectLayerScopes ( mLayer ) );
551
552
expressionBuilder->setExpressionContext ( context );
552
- expressionBuilder->setLayer ( layer );
553
+ expressionBuilder->setLayer ( mLayer );
553
554
expressionBuilder->loadFieldNames ();
554
555
expressionBuilder->loadRecent ( QStringLiteral ( " generic" ) );
555
- expressionBuilder->setExpressionText ( sortExpression ().isEmpty () ? layer ->displayExpression () : sortExpression () );
556
+ expressionBuilder->setExpressionText ( sortExpression ().isEmpty () ? mLayer ->displayExpression () : sortExpression () );
556
557
557
558
sortingGroupBox->layout ()->addWidget ( expressionBuilder );
558
559
@@ -593,7 +594,7 @@ void QgsDualView::zoomToCurrentFeature()
593
594
QgsMapCanvas *canvas = mFilterModel ->mapCanvas ();
594
595
if ( canvas )
595
596
{
596
- canvas->zoomToFeatureIds ( mLayerCache -> layer () , ids );
597
+ canvas->zoomToFeatureIds ( mLayer , ids );
597
598
}
598
599
}
599
600
@@ -610,18 +611,18 @@ void QgsDualView::panToCurrentFeature()
610
611
QgsMapCanvas *canvas = mFilterModel ->mapCanvas ();
611
612
if ( canvas )
612
613
{
613
- canvas->panToFeatureIds ( mLayerCache -> layer () , ids );
614
+ canvas->panToFeatureIds ( mLayer , ids );
614
615
}
615
616
}
616
617
617
618
void QgsDualView::previewExpressionChanged ( const QString &expression )
618
619
{
619
- mLayerCache -> layer () ->setDisplayExpression ( expression );
620
+ mLayer ->setDisplayExpression ( expression );
620
621
}
621
622
622
623
void QgsDualView::onSortColumnChanged ()
623
624
{
624
- QgsAttributeTableConfig cfg = mLayerCache -> layer () ->attributeTableConfig ();
625
+ QgsAttributeTableConfig cfg = mLayer ->attributeTableConfig ();
625
626
cfg.setSortExpression ( mFilterModel ->sortExpression () );
626
627
cfg.setSortOrder ( mFilterModel ->sortOrder () );
627
628
setAttributeTableConfig ( cfg );
@@ -665,7 +666,7 @@ void QgsDualView::setFeatureSelectionManager( QgsIFeatureSelectionManager *featu
665
666
666
667
void QgsDualView::setAttributeTableConfig ( const QgsAttributeTableConfig &config )
667
668
{
668
- mLayerCache -> layer () ->setAttributeTableConfig ( config );
669
+ mLayer ->setAttributeTableConfig ( config );
669
670
mFilterModel ->setAttributeTableConfig ( config );
670
671
mTableView ->setAttributeTableConfig ( config );
671
672
mConfig = config;
0 commit comments