Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d17f591

Browse files
authoredJun 18, 2021
Revert "Forward declare"
This reverts commit 2abf1ca.
1 parent 3b78ee6 commit d17f591

File tree

7 files changed

+45
-50
lines changed

7 files changed

+45
-50
lines changed
 

‎src/gui/attributetable/qgsattributetablefiltermodel.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "qgsvectorlayereditbuffer.h"
2929
#include "qgsexpressioncontextutils.h"
3030
#include "qgsapplication.h"
31-
#include "qgsvectorlayercache.h"
3231

3332
//////////////////
3433
// Filter Model //

‎src/gui/attributetable/qgsattributetablemodel.cpp

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
#include "qgstexteditwidgetfactory.h"
4242
#include "qgsexpressioncontextutils.h"
4343
#include "qgsvectorlayerutils.h"
44-
#include "qgsvectorlayercache.h"
4544

4645
#include <QVariant>
4746
#include <QUuid>
@@ -50,35 +49,35 @@
5049

5150
QgsAttributeTableModel::QgsAttributeTableModel( QgsVectorLayerCache *layerCache, QObject *parent )
5251
: QAbstractTableModel( parent )
53-
, mLayer( layerCache->layer() )
5452
, mLayerCache( layerCache )
5553
{
5654
mExpressionContext.appendScopes( QgsExpressionContextUtils::globalProjectLayerScopes( layerCache->layer() ) );
5755

58-
if ( mLayer->geometryType() == QgsWkbTypes::NullGeometry )
56+
if ( layerCache->layer()->geometryType() == QgsWkbTypes::NullGeometry )
5957
{
6058
mFeatureRequest.setFlags( QgsFeatureRequest::NoGeometry );
6159
}
6260

6361
mFeat.setId( std::numeric_limits<int>::min() );
6462

65-
if ( !mLayer->isSpatial() )
63+
if ( !layer()->isSpatial() )
6664
mFeatureRequest.setFlags( QgsFeatureRequest::NoGeometry );
6765

6866
loadAttributes();
6967

70-
connect( mLayer, &QgsVectorLayer::featuresDeleted, this, &QgsAttributeTableModel::featuresDeleted );
71-
connect( mLayer, &QgsVectorLayer::attributeDeleted, this, &QgsAttributeTableModel::attributeDeleted );
72-
connect( mLayer, &QgsVectorLayer::updatedFields, this, &QgsAttributeTableModel::updatedFields );
68+
connect( layer(), &QgsVectorLayer::featuresDeleted, this, &QgsAttributeTableModel::featuresDeleted );
69+
connect( layer(), &QgsVectorLayer::attributeDeleted, this, &QgsAttributeTableModel::attributeDeleted );
70+
connect( layer(), &QgsVectorLayer::updatedFields, this, &QgsAttributeTableModel::updatedFields );
7371

74-
connect( mLayer, &QgsVectorLayer::editCommandStarted, this, &QgsAttributeTableModel::bulkEditCommandStarted );
75-
connect( mLayer, &QgsVectorLayer::beforeRollBack, this, &QgsAttributeTableModel::bulkEditCommandStarted );
76-
connect( mLayer, &QgsVectorLayer::afterRollBack, this, &QgsAttributeTableModel::bulkEditCommandEnded );
72+
connect( layer(), &QgsVectorLayer::editCommandStarted, this, &QgsAttributeTableModel::bulkEditCommandStarted );
73+
connect( layer(), &QgsVectorLayer::beforeRollBack, this, &QgsAttributeTableModel::bulkEditCommandStarted );
74+
connect( layer(), &QgsVectorLayer::afterRollBack, this, &QgsAttributeTableModel::bulkEditCommandEnded );
7775

78-
connect( mLayer, &QgsVectorLayer::editCommandEnded, this, &QgsAttributeTableModel::editCommandEnded );
76+
connect( layer(), &QgsVectorLayer::editCommandEnded, this, &QgsAttributeTableModel::editCommandEnded );
7977
connect( mLayerCache, &QgsVectorLayerCache::attributeValueChanged, this, &QgsAttributeTableModel::attributeValueChanged );
8078
connect( mLayerCache, &QgsVectorLayerCache::featureAdded, this, [ = ]( QgsFeatureId id ) { featureAdded( id ); } );
8179
connect( mLayerCache, &QgsVectorLayerCache::cachedLayerDeleted, this, &QgsAttributeTableModel::layerDeleted );
80+
8281
}
8382

8483
bool QgsAttributeTableModel::loadFeatureAtId( QgsFeatureId fid ) const
@@ -234,7 +233,7 @@ void QgsAttributeTableModel::featureAdded( QgsFeatureId fid )
234233
QgsFieldFormatter *fieldFormatter = mFieldFormatters.at( cache.sortFieldIndex );
235234
const QVariant &widgetCache = mAttributeWidgetCaches.at( cache.sortFieldIndex );
236235
const QVariantMap &widgetConfig = mWidgetConfigs.at( cache.sortFieldIndex );
237-
QVariant sortValue = fieldFormatter->representValue( mLayer, cache.sortFieldIndex, widgetConfig, widgetCache, mFeat.attribute( cache.sortFieldIndex ) );
236+
QVariant sortValue = fieldFormatter->representValue( layer(), cache.sortFieldIndex, widgetConfig, widgetCache, mFeat.attribute( cache.sortFieldIndex ) );
238237
cache.sortCache.insert( mFeat.id(), sortValue );
239238
}
240239
else if ( cache.sortCacheExpression.isValid() )
@@ -288,7 +287,6 @@ void QgsAttributeTableModel::attributeDeleted( int idx )
288287
void QgsAttributeTableModel::layerDeleted()
289288
{
290289
mLayerCache = nullptr;
291-
mLayer = nullptr;
292290
removeRows( 0, rowCount() );
293291

294292
mAttributeWidgetCaches.clear();
@@ -334,7 +332,7 @@ void QgsAttributeTableModel::attributeValueChanged( QgsFeatureId fid, int idx, c
334332
QgsFieldFormatter *fieldFormatter = mFieldFormatters.at( cache.sortFieldIndex );
335333
const QVariant &widgetCache = mAttributeWidgetCaches.at( cache.sortFieldIndex );
336334
const QVariantMap &widgetConfig = mWidgetConfigs.at( cache.sortFieldIndex );
337-
QVariant sortValue = fieldFormatter->representValue( mLayer, cache.sortFieldIndex, widgetConfig, widgetCache, value );
335+
QVariant sortValue = fieldFormatter->representValue( layer(), cache.sortFieldIndex, widgetConfig, widgetCache, value );
338336
cache.sortCache.insert( fid, sortValue );
339337
}
340338
}
@@ -377,29 +375,29 @@ void QgsAttributeTableModel::attributeValueChanged( QgsFeatureId fid, int idx, c
377375

378376
void QgsAttributeTableModel::loadAttributes()
379377
{
380-
if ( !mLayer )
378+
if ( !layer() )
381379
{
382380
return;
383381
}
384382

385383
bool ins = false, rm = false;
386384

387385
QgsAttributeList attributes;
388-
const QgsFields &fields = mLayer->fields();
386+
const QgsFields &fields = layer()->fields();
389387

390388
mWidgetFactories.clear();
391389
mAttributeWidgetCaches.clear();
392390
mWidgetConfigs.clear();
393391

394392
for ( int idx = 0; idx < fields.count(); ++idx )
395393
{
396-
const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( mLayer, fields[idx].name() );
394+
const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( layer(), fields[idx].name() );
397395
QgsEditorWidgetFactory *widgetFactory = QgsGui::editorWidgetRegistry()->factory( setup.type() );
398396
QgsFieldFormatter *fieldFormatter = QgsApplication::fieldFormatterRegistry()->fieldFormatter( setup.type() );
399397

400398
mWidgetFactories.append( widgetFactory );
401399
mWidgetConfigs.append( setup.config() );
402-
mAttributeWidgetCaches.append( fieldFormatter->createCache( mLayer, idx, setup.config() ) );
400+
mAttributeWidgetCaches.append( fieldFormatter->createCache( layer(), idx, setup.config() ) );
403401
mFieldFormatters.append( fieldFormatter );
404402

405403
attributes << idx;
@@ -497,7 +495,7 @@ void QgsAttributeTableModel::fieldConditionalStyleChanged( const QString &fieldN
497495
return;
498496
}
499497

500-
int fieldIndex = mLayer->fields().lookupField( fieldName );
498+
int fieldIndex = mLayerCache->layer()->fields().lookupField( fieldName );
501499
if ( fieldIndex == -1 )
502500
return;
503501

@@ -598,7 +596,7 @@ int QgsAttributeTableModel::columnCount( const QModelIndex &parent ) const
598596

599597
QVariant QgsAttributeTableModel::headerData( int section, Qt::Orientation orientation, int role ) const
600598
{
601-
if ( !mLayer )
599+
if ( !layer() )
602600
return QVariant();
603601

604602
if ( role == Qt::DisplayRole )
@@ -609,7 +607,7 @@ QVariant QgsAttributeTableModel::headerData( int section, Qt::Orientation orient
609607
}
610608
else if ( section >= 0 && section < mFieldCount )
611609
{
612-
QString attributeName = mLayer->fields().at( mAttributes.at( section ) ).displayName();
610+
QString attributeName = layer()->fields().at( mAttributes.at( section ) ).displayName();
613611
return QVariant( attributeName );
614612
}
615613
else
@@ -626,8 +624,8 @@ QVariant QgsAttributeTableModel::headerData( int section, Qt::Orientation orient
626624
}
627625
else
628626
{
629-
const QgsField field = mLayer->fields().at( mAttributes.at( section ) );
630-
return QgsFieldModel::fieldToolTipExtended( field, mLayer );
627+
const QgsField field = layer()->fields().at( mAttributes.at( section ) );
628+
return QgsFieldModel::fieldToolTipExtended( field, layer() );
631629
}
632630
}
633631
else
@@ -638,7 +636,7 @@ QVariant QgsAttributeTableModel::headerData( int section, Qt::Orientation orient
638636

639637
QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) const
640638
{
641-
if ( !index.isValid() || !mLayer ||
639+
if ( !index.isValid() || !layer() ||
642640
( role != Qt::TextAlignmentRole
643641
&& role != Qt::DisplayRole
644642
&& role != Qt::ToolTipRole
@@ -681,11 +679,11 @@ QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) cons
681679
return QVariant();
682680
}
683681

684-
QgsField field = mLayer->fields().at( fieldId );
682+
QgsField field = layer()->fields().at( fieldId );
685683

686684
if ( role == Qt::TextAlignmentRole )
687685
{
688-
return QVariant( mFieldFormatters.at( index.column() )->alignmentFlag( mLayer, fieldId, mWidgetConfigs.at( index.column() ) ) | Qt::AlignVCenter );
686+
return QVariant( mFieldFormatters.at( index.column() )->alignmentFlag( layer(), fieldId, mWidgetConfigs.at( index.column() ) ) | Qt::AlignVCenter );
689687
}
690688

691689
if ( mFeat.id() != rowId || !mFeat.isValid() )
@@ -703,7 +701,7 @@ QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) cons
703701
{
704702
case Qt::DisplayRole:
705703
case Qt::ToolTipRole:
706-
return mFieldFormatters.at( index.column() )->representValue( mLayer,
704+
return mFieldFormatters.at( index.column() )->representValue( layer(),
707705
fieldId,
708706
mWidgetConfigs.at( index.column() ),
709707
mAttributeWidgetCaches.at( index.column() ),
@@ -729,12 +727,12 @@ QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) cons
729727
}
730728
else
731729
{
732-
styles = QgsConditionalStyle::matchingConditionalStyles( mLayer->conditionalStyles()->rowStyles(), QVariant(), mExpressionContext );
730+
styles = QgsConditionalStyle::matchingConditionalStyles( layer()->conditionalStyles()->rowStyles(), QVariant(), mExpressionContext );
733731
mRowStylesMap.insert( mFeat.id(), styles );
734732
}
735733

736734
QgsConditionalStyle rowstyle = QgsConditionalStyle::compressStyles( styles );
737-
styles = mLayer->conditionalStyles()->fieldStyles( field.name() );
735+
styles = layer()->conditionalStyles()->fieldStyles( field.name() );
738736
styles = QgsConditionalStyle::matchingConditionalStyles( styles, val, mExpressionContext );
739737
styles.insert( 0, rowstyle );
740738
QgsConditionalStyle style = QgsConditionalStyle::compressStyles( styles );
@@ -766,12 +764,12 @@ bool QgsAttributeTableModel::setData( const QModelIndex &index, const QVariant &
766764
{
767765
Q_UNUSED( value )
768766

769-
if ( !index.isValid() || index.column() >= mFieldCount || role != Qt::EditRole || !mLayer->isEditable() )
767+
if ( !index.isValid() || index.column() >= mFieldCount || role != Qt::EditRole || !layer()->isEditable() )
770768
return false;
771769

772770
mRowStylesMap.remove( mFeat.id() );
773771

774-
if ( !mLayer->isModified() )
772+
if ( !layer()->isModified() )
775773
return false;
776774

777775
return true;
@@ -782,15 +780,15 @@ Qt::ItemFlags QgsAttributeTableModel::flags( const QModelIndex &index ) const
782780
if ( !index.isValid() )
783781
return Qt::ItemIsEnabled;
784782

785-
if ( index.column() >= mFieldCount || !mLayer )
783+
if ( index.column() >= mFieldCount || !layer() )
786784
return Qt::NoItemFlags;
787785

788786
Qt::ItemFlags flags = QAbstractTableModel::flags( index );
789787

790788
const int fieldIndex = mAttributes[index.column()];
791789
const QgsFeatureId fid = rowToId( index.row() );
792790

793-
if ( QgsVectorLayerUtils::fieldIsEditable( mLayer, fieldIndex, fid ) )
791+
if ( QgsVectorLayerUtils::fieldIsEditable( layer(), fieldIndex, fid ) )
794792
flags |= Qt::ItemIsEditable;
795793

796794
return flags;
@@ -821,7 +819,7 @@ void QgsAttributeTableModel::bulkEditCommandEnded()
821819
if ( fullModelUpdate )
822820
{
823821
// Invalidates the cache (there is no API for doing this directly)
824-
emit mLayer->dataChanged();
822+
emit mLayerCache->layer()->dataChanged();
825823
emit dataChanged( createIndex( 0, 0 ), createIndex( rowCount() - 1, columnCount() - 1 ) );
826824
}
827825
else
@@ -856,18 +854,18 @@ void QgsAttributeTableModel::reload( const QModelIndex &index1, const QModelInde
856854
void QgsAttributeTableModel::executeAction( QUuid action, const QModelIndex &idx ) const
857855
{
858856
QgsFeature f = feature( idx );
859-
mLayer->actions()->doAction( action, f, fieldIdx( idx.column() ) );
857+
layer()->actions()->doAction( action, f, fieldIdx( idx.column() ) );
860858
}
861859

862860
void QgsAttributeTableModel::executeMapLayerAction( QgsMapLayerAction *action, const QModelIndex &idx ) const
863861
{
864862
QgsFeature f = feature( idx );
865-
action->triggerForFeature( mLayer, f );
863+
action->triggerForFeature( layer(), f );
866864
}
867865

868866
QgsFeature QgsAttributeTableModel::feature( const QModelIndex &idx ) const
869867
{
870-
QgsFeature f( mLayer->fields() );
868+
QgsFeature f( mLayerCache->layer()->fields() );
871869
f.initAttributes( mAttributes.size() );
872870
f.setId( rowToId( idx.row() ) );
873871
for ( int i = 0; i < mAttributes.size(); i++ )
@@ -886,7 +884,7 @@ void QgsAttributeTableModel::prefetchColumnData( int column )
886884
}
887885
else
888886
{
889-
prefetchSortData( QgsExpression::quotedColumnRef( mLayer->fields().at( mAttributes.at( column ) ).name() ) );
887+
prefetchSortData( QgsExpression::quotedColumnRef( mLayerCache->layer()->fields().at( mAttributes.at( column ) ).name() ) );
890888
}
891889
}
892890

@@ -916,7 +914,7 @@ void QgsAttributeTableModel::prefetchSortData( const QString &expressionString,
916914
if ( cache.sortCacheExpression.isField() )
917915
{
918916
QString fieldName = static_cast<const QgsExpressionNodeColumnRef *>( cache.sortCacheExpression.rootNode() )->name();
919-
cache.sortFieldIndex = mLayer->fields().lookupField( fieldName );
917+
cache.sortFieldIndex = mLayerCache->layer()->fields().lookupField( fieldName );
920918
}
921919

922920
if ( cache.sortFieldIndex == -1 )
@@ -927,7 +925,7 @@ void QgsAttributeTableModel::prefetchSortData( const QString &expressionString,
927925

928926
for ( const QString &col : referencedColumns )
929927
{
930-
cache.sortCacheAttributes.append( mLayer->fields().lookupField( col ) );
928+
cache.sortCacheAttributes.append( mLayerCache->layer()->fields().lookupField( col ) );
931929
}
932930
}
933931
else
@@ -955,7 +953,7 @@ void QgsAttributeTableModel::prefetchSortData( const QString &expressionString,
955953
}
956954
else
957955
{
958-
QVariant sortValue = fieldFormatter->sortValue( mLayer, cache.sortFieldIndex, widgetConfig, widgetCache, f.attribute( cache.sortFieldIndex ) );
956+
QVariant sortValue = fieldFormatter->sortValue( layer(), cache.sortFieldIndex, widgetConfig, widgetCache, f.attribute( cache.sortFieldIndex ) );
959957
cache.sortCache.insert( f.id(), sortValue );
960958
}
961959
}
@@ -981,7 +979,7 @@ QString QgsAttributeTableModel::sortCacheExpression( unsigned long cacheIndex )
981979
void QgsAttributeTableModel::setRequest( const QgsFeatureRequest &request )
982980
{
983981
mFeatureRequest = request;
984-
if ( mLayer && !mLayer->isSpatial() )
982+
if ( layer() && !layer()->isSpatial() )
985983
mFeatureRequest.setFlags( mFeatureRequest.flags() | QgsFeatureRequest::NoGeometry );
986984
}
987985

‎src/gui/attributetable/qgsattributetablemodel.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727

2828
#include "qgsconditionalstyle.h"
2929
#include "qgsattributeeditorcontext.h"
30+
#include "qgsvectorlayercache.h"
3031
#include "qgis_gui.h"
3132

3233
class QgsMapCanvas;
3334
class QgsMapLayerAction;
3435
class QgsEditorWidgetFactory;
3536
class QgsFieldFormatter;
36-
class QgsVectorLayerCache;
3737

3838
/**
3939
* \ingroup gui
@@ -165,7 +165,7 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel
165165
/**
166166
* Returns the layer this model uses as backend. Retrieved from the layer cache.
167167
*/
168-
inline QgsVectorLayer *layer() const { return mLayer; }
168+
inline QgsVectorLayer *layer() const { return mLayerCache ? mLayerCache->layer() : nullptr; }
169169

170170
/**
171171
* Returns the layer cache this model uses as backend.
@@ -329,7 +329,6 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel
329329
virtual void fieldFormatterRemoved( QgsFieldFormatter *fieldFormatter );
330330

331331
private:
332-
QgsVectorLayer *mLayer = nullptr;
333332
QgsVectorLayerCache *mLayerCache = nullptr;
334333
int mFieldCount = 0;
335334

‎src/gui/attributetable/qgsfeaturelistmodel.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "qgsvectorlayereditbuffer.h"
2020
#include "qgsattributetablefiltermodel.h"
2121
#include "qgsapplication.h"
22-
#include "qgsvectorlayercache.h"
2322

2423
#include <QItemSelection>
2524
#include <QSettings>

‎src/gui/attributetable/qgsfeaturelistview.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include "qgsvectordataprovider.h"
3232
#include "qgsvectorlayer.h"
3333
#include "qgsvectorlayerselectionmanager.h"
34-
#include "qgsvectorlayercache.h"
3534

3635
QgsFeatureListView::QgsFeatureListView( QWidget *parent )
3736
: QListView( parent )

‎tests/src/app/testqgsattributetable.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
#include "qgsvectorfilewriter.h"
3030
#include "qgsfeaturelistmodel.h"
3131
#include "qgsclipboard.h"
32-
#include "qgsvectorlayercache.h"
32+
33+
#include "qgstest.h"
3334

3435
/**
3536
* \ingroup UnitTests

‎tests/src/gui/testqgsdualview.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <qgsmapcanvas.h>
2828
#include <qgsfeature.h>
2929
#include "qgsgui.h"
30-
#include "qgsvectorlayercache.h"
30+
3131
#include "qgstest.h"
3232

3333
class TestQgsDualView : public QObject

0 commit comments

Comments
 (0)
Please sign in to comment.