Skip to content
Permalink
Browse files

[FEATURE] Show symbol as icon for attribute row

  • Loading branch information
NathanW2 committed Jul 8, 2015
1 parent 519d3dc commit e3b2a2daf2a5368c8e5565cd83acc26e706e00c2
@@ -27,6 +27,7 @@
#include "qgsmaplayerregistry.h"
#include "qgsrendererv2.h"
#include "qgsvectorlayer.h"
#include "qgssymbollayerv2utils.h"

#include <QVariant>

@@ -37,6 +38,7 @@ QgsAttributeTableModel::QgsAttributeTableModel( QgsVectorLayerCache *layerCache,
, mLayerCache( layerCache )
, mFieldCount( 0 )
, mCachedField( -1 )
, mIconSize( 16, 16 )
{
QgsDebugMsg( "entered." );

@@ -494,6 +496,27 @@ QVariant QgsAttributeTableModel::headerData( int section, Qt::Orientation orient
return tr( "feature id" );
}
}
else if ( role == Qt::DecorationRole
&& orientation == Qt::Vertical
&& layer()->geometryType() != QGis::NoGeometry )
{
QgsRenderContext ctx;
QgsFeature feature;
mLayerCache->featureAtId( mRowIdMap[section], feature );

layer()->rendererV2()->startRender( ctx, layer()->pendingFields() );
QgsSymbolV2List symbols = layer()->rendererV2()->symbolsForFeature( feature );
if ( symbols.count() == 0 )
{
layer()->rendererV2()->stopRender( ctx );

This comment has been minimized.

Copy link
@NathanW2

NathanW2 Jul 10, 2015

Author Member

Opps forgot to run astyle

This comment has been minimized.

Copy link
@jef-n

jef-n Jul 11, 2015

Member

ln -s ../../scripts/prepare-commit.sh .git/hooks/pre-commit

return 0;
}

QgsSymbolV2* symbol = symbols.first();
QPixmap pix = QgsSymbolLayerV2Utils::symbolPreviewPixmap( symbol, mIconSize );
layer()->rendererV2()->stopRender( ctx );
return pix;
}
else
{
return QVariant();
@@ -315,6 +315,8 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel
/** Allows caching of one specific column (used for sorting) */
QHash<QgsFeatureId, QVariant> mFieldCache;

QSize mIconSize;

/**
* Holds the bounds of changed cells while an update operation is running
* top = min row

6 comments on commit e3b2a2d

@slarosa

This comment has been minimized.

Copy link
Member

@slarosa slarosa replied Jul 10, 2015

hey @NathanW2 great feature! thanks.

I am testing and it works very well but with postgis layer (actually I tried a view with about 7K rows) and categorized symbols it takes age to open the attribute table. Could we add an options to activate/deactivate such a feature?

@slarosa

This comment has been minimized.

Copy link
Member

@slarosa slarosa replied Jul 10, 2015

I also can confirm with shapefile format, in general when you have very much categorized symbols it is slowest to open the attr table. With postgis is amplified.

@nirvn

This comment has been minimized.

Copy link
Contributor

@nirvn nirvn replied Jul 11, 2015

This feature would probably work much better with large datasets if the symbols were drawn only for the rows that are visible in the attribute window (versus preparing all the symbols at once).

@NathanW2

This comment has been minimized.

Copy link
Member Author

@NathanW2 NathanW2 replied Jul 11, 2015

@NathanW2

This comment has been minimized.

Copy link
Member Author

@NathanW2 NathanW2 replied Jul 11, 2015

@NathanW2

This comment has been minimized.

Copy link
Member Author

@NathanW2 NathanW2 replied Jul 11, 2015

Please sign in to comment.
You can’t perform that action at this time.