Skip to content
Permalink
Browse files
Revert "Forward declare"
This reverts commit 2abf1ca.
  • Loading branch information
3nids committed Jun 18, 2021
1 parent 3b78ee6 commit d17f5912bcf78019da906c9778ddc9967a4f706a
@@ -28,7 +28,6 @@
#include "qgsvectorlayereditbuffer.h"
#include "qgsexpressioncontextutils.h"
#include "qgsapplication.h"
#include "qgsvectorlayercache.h"

//////////////////
// Filter Model //
@@ -41,7 +41,6 @@
#include "qgstexteditwidgetfactory.h"
#include "qgsexpressioncontextutils.h"
#include "qgsvectorlayerutils.h"
#include "qgsvectorlayercache.h"

#include <QVariant>
#include <QUuid>
@@ -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
@@ -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() )
@@ -288,7 +287,6 @@ void QgsAttributeTableModel::attributeDeleted( int idx )
void QgsAttributeTableModel::layerDeleted()
{
mLayerCache = nullptr;
mLayer = nullptr;
removeRows( 0, rowCount() );

mAttributeWidgetCaches.clear();
@@ -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 );
}
}
@@ -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;
@@ -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;

@@ -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 )
@@ -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
@@ -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
@@ -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
@@ -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() )
@@ -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() ),
@@ -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 );
@@ -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;
@@ -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;
@@ -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
@@ -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++ )
@@ -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() ) );
}
}

@@ -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 )
@@ -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
@@ -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 );
}
}
@@ -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 );
}

@@ -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
@@ -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.
@@ -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;

@@ -19,7 +19,6 @@
#include "qgsvectorlayereditbuffer.h"
#include "qgsattributetablefiltermodel.h"
#include "qgsapplication.h"
#include "qgsvectorlayercache.h"

#include <QItemSelection>
#include <QSettings>
@@ -31,7 +31,6 @@
#include "qgsvectordataprovider.h"
#include "qgsvectorlayer.h"
#include "qgsvectorlayerselectionmanager.h"
#include "qgsvectorlayercache.h"

QgsFeatureListView::QgsFeatureListView( QWidget *parent )
: QListView( parent )
@@ -29,7 +29,8 @@
#include "qgsvectorfilewriter.h"
#include "qgsfeaturelistmodel.h"
#include "qgsclipboard.h"
#include "qgsvectorlayercache.h"

#include "qgstest.h"

/**
* \ingroup UnitTests
@@ -27,7 +27,7 @@
#include <qgsmapcanvas.h>
#include <qgsfeature.h>
#include "qgsgui.h"
#include "qgsvectorlayercache.h"

#include "qgstest.h"

class TestQgsDualView : public QObject

0 comments on commit d17f591

Please sign in to comment.