Skip to content

Commit

Permalink
Revert "Forward declare"
Browse files Browse the repository at this point in the history
This reverts commit 2abf1ca.
  • Loading branch information
3nids committed Jun 18, 2021
1 parent 3b78ee6 commit d17f591
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 50 deletions.
1 change: 0 additions & 1 deletion src/gui/attributetable/qgsattributetablefiltermodel.cpp
Expand Up @@ -28,7 +28,6 @@
#include "qgsvectorlayereditbuffer.h"
#include "qgsexpressioncontextutils.h"
#include "qgsapplication.h"
#include "qgsvectorlayercache.h"

//////////////////
// Filter Model //
Expand Down
82 changes: 40 additions & 42 deletions src/gui/attributetable/qgsattributetablemodel.cpp
Expand Up @@ -41,7 +41,6 @@
#include "qgstexteditwidgetfactory.h"
#include "qgsexpressioncontextutils.h"
#include "qgsvectorlayerutils.h"
#include "qgsvectorlayercache.h"

#include <QVariant>
#include <QUuid>
Expand All @@ -50,35 +49,35 @@

QgsAttributeTableModel::QgsAttributeTableModel( QgsVectorLayerCache *layerCache, QObject *parent )
: QAbstractTableModel( parent )
, mLayer( layerCache->layer() )
, mLayerCache( layerCache )
{
mExpressionContext.appendScopes( QgsExpressionContextUtils::globalProjectLayerScopes( layerCache->layer() ) );

if ( mLayer->geometryType() == QgsWkbTypes::NullGeometry )
if ( layerCache->layer()->geometryType() == QgsWkbTypes::NullGeometry )
{
mFeatureRequest.setFlags( QgsFeatureRequest::NoGeometry );
}

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

if ( !mLayer->isSpatial() )
if ( !layer()->isSpatial() )
mFeatureRequest.setFlags( QgsFeatureRequest::NoGeometry );

loadAttributes();

connect( mLayer, &QgsVectorLayer::featuresDeleted, this, &QgsAttributeTableModel::featuresDeleted );
connect( mLayer, &QgsVectorLayer::attributeDeleted, this, &QgsAttributeTableModel::attributeDeleted );
connect( mLayer, &QgsVectorLayer::updatedFields, this, &QgsAttributeTableModel::updatedFields );
connect( layer(), &QgsVectorLayer::featuresDeleted, this, &QgsAttributeTableModel::featuresDeleted );
connect( layer(), &QgsVectorLayer::attributeDeleted, this, &QgsAttributeTableModel::attributeDeleted );
connect( layer(), &QgsVectorLayer::updatedFields, this, &QgsAttributeTableModel::updatedFields );

connect( mLayer, &QgsVectorLayer::editCommandStarted, this, &QgsAttributeTableModel::bulkEditCommandStarted );
connect( mLayer, &QgsVectorLayer::beforeRollBack, this, &QgsAttributeTableModel::bulkEditCommandStarted );
connect( mLayer, &QgsVectorLayer::afterRollBack, this, &QgsAttributeTableModel::bulkEditCommandEnded );
connect( layer(), &QgsVectorLayer::editCommandStarted, this, &QgsAttributeTableModel::bulkEditCommandStarted );
connect( layer(), &QgsVectorLayer::beforeRollBack, this, &QgsAttributeTableModel::bulkEditCommandStarted );
connect( layer(), &QgsVectorLayer::afterRollBack, this, &QgsAttributeTableModel::bulkEditCommandEnded );

connect( mLayer, &QgsVectorLayer::editCommandEnded, this, &QgsAttributeTableModel::editCommandEnded );
connect( layer(), &QgsVectorLayer::editCommandEnded, this, &QgsAttributeTableModel::editCommandEnded );
connect( mLayerCache, &QgsVectorLayerCache::attributeValueChanged, this, &QgsAttributeTableModel::attributeValueChanged );
connect( mLayerCache, &QgsVectorLayerCache::featureAdded, this, [ = ]( QgsFeatureId id ) { featureAdded( id ); } );
connect( mLayerCache, &QgsVectorLayerCache::cachedLayerDeleted, this, &QgsAttributeTableModel::layerDeleted );

}

bool QgsAttributeTableModel::loadFeatureAtId( QgsFeatureId fid ) const
Expand Down Expand Up @@ -234,7 +233,7 @@ void QgsAttributeTableModel::featureAdded( QgsFeatureId fid )
QgsFieldFormatter *fieldFormatter = mFieldFormatters.at( cache.sortFieldIndex );
const QVariant &widgetCache = mAttributeWidgetCaches.at( cache.sortFieldIndex );
const QVariantMap &widgetConfig = mWidgetConfigs.at( cache.sortFieldIndex );
QVariant sortValue = fieldFormatter->representValue( mLayer, cache.sortFieldIndex, widgetConfig, widgetCache, mFeat.attribute( cache.sortFieldIndex ) );
QVariant sortValue = fieldFormatter->representValue( layer(), cache.sortFieldIndex, widgetConfig, widgetCache, mFeat.attribute( cache.sortFieldIndex ) );
cache.sortCache.insert( mFeat.id(), sortValue );
}
else if ( cache.sortCacheExpression.isValid() )
Expand Down Expand Up @@ -288,7 +287,6 @@ void QgsAttributeTableModel::attributeDeleted( int idx )
void QgsAttributeTableModel::layerDeleted()
{
mLayerCache = nullptr;
mLayer = nullptr;
removeRows( 0, rowCount() );

mAttributeWidgetCaches.clear();
Expand Down Expand Up @@ -334,7 +332,7 @@ void QgsAttributeTableModel::attributeValueChanged( QgsFeatureId fid, int idx, c
QgsFieldFormatter *fieldFormatter = mFieldFormatters.at( cache.sortFieldIndex );
const QVariant &widgetCache = mAttributeWidgetCaches.at( cache.sortFieldIndex );
const QVariantMap &widgetConfig = mWidgetConfigs.at( cache.sortFieldIndex );
QVariant sortValue = fieldFormatter->representValue( mLayer, cache.sortFieldIndex, widgetConfig, widgetCache, value );
QVariant sortValue = fieldFormatter->representValue( layer(), cache.sortFieldIndex, widgetConfig, widgetCache, value );
cache.sortCache.insert( fid, sortValue );
}
}
Expand Down Expand Up @@ -377,29 +375,29 @@ void QgsAttributeTableModel::attributeValueChanged( QgsFeatureId fid, int idx, c

void QgsAttributeTableModel::loadAttributes()
{
if ( !mLayer )
if ( !layer() )
{
return;
}

bool ins = false, rm = false;

QgsAttributeList attributes;
const QgsFields &fields = mLayer->fields();
const QgsFields &fields = layer()->fields();

mWidgetFactories.clear();
mAttributeWidgetCaches.clear();
mWidgetConfigs.clear();

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

mWidgetFactories.append( widgetFactory );
mWidgetConfigs.append( setup.config() );
mAttributeWidgetCaches.append( fieldFormatter->createCache( mLayer, idx, setup.config() ) );
mAttributeWidgetCaches.append( fieldFormatter->createCache( layer(), idx, setup.config() ) );
mFieldFormatters.append( fieldFormatter );

attributes << idx;
Expand Down Expand Up @@ -497,7 +495,7 @@ void QgsAttributeTableModel::fieldConditionalStyleChanged( const QString &fieldN
return;
}

int fieldIndex = mLayer->fields().lookupField( fieldName );
int fieldIndex = mLayerCache->layer()->fields().lookupField( fieldName );
if ( fieldIndex == -1 )
return;

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

QVariant QgsAttributeTableModel::headerData( int section, Qt::Orientation orientation, int role ) const
{
if ( !mLayer )
if ( !layer() )
return QVariant();

if ( role == Qt::DisplayRole )
Expand All @@ -609,7 +607,7 @@ QVariant QgsAttributeTableModel::headerData( int section, Qt::Orientation orient
}
else if ( section >= 0 && section < mFieldCount )
{
QString attributeName = mLayer->fields().at( mAttributes.at( section ) ).displayName();
QString attributeName = layer()->fields().at( mAttributes.at( section ) ).displayName();
return QVariant( attributeName );
}
else
Expand All @@ -626,8 +624,8 @@ QVariant QgsAttributeTableModel::headerData( int section, Qt::Orientation orient
}
else
{
const QgsField field = mLayer->fields().at( mAttributes.at( section ) );
return QgsFieldModel::fieldToolTipExtended( field, mLayer );
const QgsField field = layer()->fields().at( mAttributes.at( section ) );
return QgsFieldModel::fieldToolTipExtended( field, layer() );
}
}
else
Expand All @@ -638,7 +636,7 @@ QVariant QgsAttributeTableModel::headerData( int section, Qt::Orientation orient

QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) const
{
if ( !index.isValid() || !mLayer ||
if ( !index.isValid() || !layer() ||
( role != Qt::TextAlignmentRole
&& role != Qt::DisplayRole
&& role != Qt::ToolTipRole
Expand Down Expand Up @@ -681,11 +679,11 @@ QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) cons
return QVariant();
}

QgsField field = mLayer->fields().at( fieldId );
QgsField field = layer()->fields().at( fieldId );

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

if ( mFeat.id() != rowId || !mFeat.isValid() )
Expand All @@ -703,7 +701,7 @@ QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) cons
{
case Qt::DisplayRole:
case Qt::ToolTipRole:
return mFieldFormatters.at( index.column() )->representValue( mLayer,
return mFieldFormatters.at( index.column() )->representValue( layer(),
fieldId,
mWidgetConfigs.at( index.column() ),
mAttributeWidgetCaches.at( index.column() ),
Expand All @@ -729,12 +727,12 @@ QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) cons
}
else
{
styles = QgsConditionalStyle::matchingConditionalStyles( mLayer->conditionalStyles()->rowStyles(), QVariant(), mExpressionContext );
styles = QgsConditionalStyle::matchingConditionalStyles( layer()->conditionalStyles()->rowStyles(), QVariant(), mExpressionContext );
mRowStylesMap.insert( mFeat.id(), styles );
}

QgsConditionalStyle rowstyle = QgsConditionalStyle::compressStyles( styles );
styles = mLayer->conditionalStyles()->fieldStyles( field.name() );
styles = layer()->conditionalStyles()->fieldStyles( field.name() );
styles = QgsConditionalStyle::matchingConditionalStyles( styles, val, mExpressionContext );
styles.insert( 0, rowstyle );
QgsConditionalStyle style = QgsConditionalStyle::compressStyles( styles );
Expand Down Expand Up @@ -766,12 +764,12 @@ bool QgsAttributeTableModel::setData( const QModelIndex &index, const QVariant &
{
Q_UNUSED( value )

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

mRowStylesMap.remove( mFeat.id() );

if ( !mLayer->isModified() )
if ( !layer()->isModified() )
return false;

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

if ( index.column() >= mFieldCount || !mLayer )
if ( index.column() >= mFieldCount || !layer() )
return Qt::NoItemFlags;

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

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

if ( QgsVectorLayerUtils::fieldIsEditable( mLayer, fieldIndex, fid ) )
if ( QgsVectorLayerUtils::fieldIsEditable( layer(), fieldIndex, fid ) )
flags |= Qt::ItemIsEditable;

return flags;
Expand Down Expand Up @@ -821,7 +819,7 @@ void QgsAttributeTableModel::bulkEditCommandEnded()
if ( fullModelUpdate )
{
// Invalidates the cache (there is no API for doing this directly)
emit mLayer->dataChanged();
emit mLayerCache->layer()->dataChanged();
emit dataChanged( createIndex( 0, 0 ), createIndex( rowCount() - 1, columnCount() - 1 ) );
}
else
Expand Down Expand Up @@ -856,18 +854,18 @@ void QgsAttributeTableModel::reload( const QModelIndex &index1, const QModelInde
void QgsAttributeTableModel::executeAction( QUuid action, const QModelIndex &idx ) const
{
QgsFeature f = feature( idx );
mLayer->actions()->doAction( action, f, fieldIdx( idx.column() ) );
layer()->actions()->doAction( action, f, fieldIdx( idx.column() ) );
}

void QgsAttributeTableModel::executeMapLayerAction( QgsMapLayerAction *action, const QModelIndex &idx ) const
{
QgsFeature f = feature( idx );
action->triggerForFeature( mLayer, f );
action->triggerForFeature( layer(), f );
}

QgsFeature QgsAttributeTableModel::feature( const QModelIndex &idx ) const
{
QgsFeature f( mLayer->fields() );
QgsFeature f( mLayerCache->layer()->fields() );
f.initAttributes( mAttributes.size() );
f.setId( rowToId( idx.row() ) );
for ( int i = 0; i < mAttributes.size(); i++ )
Expand All @@ -886,7 +884,7 @@ void QgsAttributeTableModel::prefetchColumnData( int column )
}
else
{
prefetchSortData( QgsExpression::quotedColumnRef( mLayer->fields().at( mAttributes.at( column ) ).name() ) );
prefetchSortData( QgsExpression::quotedColumnRef( mLayerCache->layer()->fields().at( mAttributes.at( column ) ).name() ) );
}
}

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

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

for ( const QString &col : referencedColumns )
{
cache.sortCacheAttributes.append( mLayer->fields().lookupField( col ) );
cache.sortCacheAttributes.append( mLayerCache->layer()->fields().lookupField( col ) );
}
}
else
Expand Down Expand Up @@ -955,7 +953,7 @@ void QgsAttributeTableModel::prefetchSortData( const QString &expressionString,
}
else
{
QVariant sortValue = fieldFormatter->sortValue( mLayer, cache.sortFieldIndex, widgetConfig, widgetCache, f.attribute( cache.sortFieldIndex ) );
QVariant sortValue = fieldFormatter->sortValue( layer(), cache.sortFieldIndex, widgetConfig, widgetCache, f.attribute( cache.sortFieldIndex ) );
cache.sortCache.insert( f.id(), sortValue );
}
}
Expand All @@ -981,7 +979,7 @@ QString QgsAttributeTableModel::sortCacheExpression( unsigned long cacheIndex )
void QgsAttributeTableModel::setRequest( const QgsFeatureRequest &request )
{
mFeatureRequest = request;
if ( mLayer && !mLayer->isSpatial() )
if ( layer() && !layer()->isSpatial() )
mFeatureRequest.setFlags( mFeatureRequest.flags() | QgsFeatureRequest::NoGeometry );
}

Expand Down
5 changes: 2 additions & 3 deletions src/gui/attributetable/qgsattributetablemodel.h
Expand Up @@ -27,13 +27,13 @@

#include "qgsconditionalstyle.h"
#include "qgsattributeeditorcontext.h"
#include "qgsvectorlayercache.h"
#include "qgis_gui.h"

class QgsMapCanvas;
class QgsMapLayerAction;
class QgsEditorWidgetFactory;
class QgsFieldFormatter;
class QgsVectorLayerCache;

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

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

private:
QgsVectorLayer *mLayer = nullptr;
QgsVectorLayerCache *mLayerCache = nullptr;
int mFieldCount = 0;

Expand Down
1 change: 0 additions & 1 deletion src/gui/attributetable/qgsfeaturelistmodel.cpp
Expand Up @@ -19,7 +19,6 @@
#include "qgsvectorlayereditbuffer.h"
#include "qgsattributetablefiltermodel.h"
#include "qgsapplication.h"
#include "qgsvectorlayercache.h"

#include <QItemSelection>
#include <QSettings>
Expand Down
1 change: 0 additions & 1 deletion src/gui/attributetable/qgsfeaturelistview.cpp
Expand Up @@ -31,7 +31,6 @@
#include "qgsvectordataprovider.h"
#include "qgsvectorlayer.h"
#include "qgsvectorlayerselectionmanager.h"
#include "qgsvectorlayercache.h"

QgsFeatureListView::QgsFeatureListView( QWidget *parent )
: QListView( parent )
Expand Down
3 changes: 2 additions & 1 deletion tests/src/app/testqgsattributetable.cpp
Expand Up @@ -29,7 +29,8 @@
#include "qgsvectorfilewriter.h"
#include "qgsfeaturelistmodel.h"
#include "qgsclipboard.h"
#include "qgsvectorlayercache.h"

#include "qgstest.h"

/**
* \ingroup UnitTests
Expand Down
2 changes: 1 addition & 1 deletion tests/src/gui/testqgsdualview.cpp
Expand Up @@ -27,7 +27,7 @@
#include <qgsmapcanvas.h>
#include <qgsfeature.h>
#include "qgsgui.h"
#include "qgsvectorlayercache.h"

#include "qgstest.h"

class TestQgsDualView : public QObject
Expand Down

0 comments on commit d17f591

Please sign in to comment.