Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE] Show symbol as icon for attribute row
  • Loading branch information
NathanW2 committed Jul 10, 2015
1 parent 519d3dc commit e3b2a2d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/gui/attributetable/qgsattributetablemodel.cpp
Expand Up @@ -27,6 +27,7 @@
#include "qgsmaplayerregistry.h"
#include "qgsrendererv2.h"
#include "qgsvectorlayer.h"
#include "qgssymbollayerv2utils.h"

#include <QVariant>

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

Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/gui/attributetable/qgsattributetablemodel.h
Expand Up @@ -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
Expand Down

6 comments on commit e3b2a2d

@slarosa
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

@nirvn nirvn commented on e3b2a2d Jul 11, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member Author

@NathanW2 NathanW2 commented on e3b2a2d Jul 11, 2015 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NathanW2
Copy link
Member Author

@NathanW2 NathanW2 commented on e3b2a2d Jul 11, 2015 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NathanW2
Copy link
Member Author

@NathanW2 NathanW2 commented on e3b2a2d Jul 11, 2015 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.