Skip to content
Permalink
Browse files

Use QgsLayerTreeModel as a source of data for legend rendering instea…

…d of QgsLegendModel

This is work in progress, customization of legend is not working yet
  • Loading branch information
wonder-sk committed Aug 11, 2014
1 parent 372b731 commit 6891aae19ab6466bbbdd9ba2fed7a241f7fb6ded
Showing with 731 additions and 656 deletions.
  1. +1 −0 python/core/core.sip
  2. +0 −5 python/core/layertree/qgslayertreelayer.sip
  3. 0 python/{gui → core}/layertree/qgslayertreemodel.sip
  4. +0 −1 python/gui/gui.sip
  5. +3 −0 src/core/CMakeLists.txt
  6. +9 −4 src/core/composer/qgscomposerlegend.cpp
  7. +3 −0 src/core/composer/qgscomposerlegend.h
  8. +0 −258 src/core/composer/qgscomposerlegenditem.cpp
  9. +0 −54 src/core/composer/qgscomposerlegenditem.h
  10. +2 −2 src/core/composer/qgslegendmodel.cpp
  11. +0 −3 src/core/layertree/qgslayertreelayer.cpp
  12. +0 −6 src/core/layertree/qgslayertreelayer.h
  13. +37 −0 src/{gui → core}/layertree/qgslayertreemodel.cpp
  14. +9 −1 src/{gui → core}/layertree/qgslayertreemodel.h
  15. +167 −89 src/core/qgslegendrenderer.cpp
  16. +23 −10 src/core/qgslegendrenderer.h
  17. +308 −125 src/core/qgsmaplayerlegend.cpp
  18. +87 −12 src/core/qgsmaplayerlegend.h
  19. +0 −15 src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp
  20. +4 −0 src/core/symbology-ng/qgscategorizedsymbolrendererv2.h
  21. +0 −15 src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp
  22. +4 −0 src/core/symbology-ng/qgsgraduatedsymbolrendererv2.h
  23. +4 −1 src/core/symbology-ng/qgslegendsymbolitemv2.cpp
  24. +4 −1 src/core/symbology-ng/qgslegendsymbolitemv2.h
  25. +1 −1 src/core/symbology-ng/qgsrendererv2.cpp
  26. +4 −0 src/core/symbology-ng/qgsrendererv2.h
  27. +1 −1 src/core/symbology-ng/qgsrulebasedrendererv2.cpp
  28. +0 −3 src/gui/CMakeLists.txt
  29. +0 −2 src/gui/layertree/qgslayertreeviewdefaultactions.cpp
  30. +1 −0 src/mapserver/CMakeLists.txt
  31. +28 −24 src/mapserver/qgswmsserver.cpp
  32. +31 −23 tests/src/core/testqgslegendrenderer.cpp
@@ -167,6 +167,7 @@
%Include layertree/qgslayertree.sip
%Include layertree/qgslayertreegroup.sip
%Include layertree/qgslayertreelayer.sip
%Include layertree/qgslayertreemodel.sip
%Include layertree/qgslayertreenode.sip
%Include layertree/qgslayertreeregistrybridge.sip
%Include layertree/qgslayertreeutils.sip
@@ -37,11 +37,6 @@ class QgsLayerTreeLayer : QgsLayerTreeNode
Qt::CheckState isVisible() const;
void setVisible( Qt::CheckState visible );

//! @note added in 2.5
bool childrenCheckable() const;
//! @note added in 2.5
void setChildrenCheckable( bool checkable );

static QgsLayerTreeLayer* readXML( QDomElement& element ) /Factory/;
virtual void writeXML( QDomElement& parentElement );

File renamed without changes.
@@ -127,7 +127,6 @@

%Include layertree/qgscustomlayerorderwidget.sip
%Include layertree/qgslayertreemapcanvasbridge.sip
%Include layertree/qgslayertreemodel.sip
%Include layertree/qgslayertreeview.sip
%Include layertree/qgslayertreeviewdefaultactions.sip

@@ -48,6 +48,7 @@ SET(QGIS_CORE_SRCS

layertree/qgslayertreegroup.cpp
layertree/qgslayertreelayer.cpp
layertree/qgslayertreemodel.cpp
layertree/qgslayertreenode.cpp
layertree/qgslayertreeregistrybridge.cpp
layertree/qgslayertreeutils.cpp
@@ -407,6 +408,7 @@ SET(QGIS_CORE_MOC_HDRS

layertree/qgslayertreegroup.h
layertree/qgslayertreelayer.h
layertree/qgslayertreemodel.h
layertree/qgslayertreenode.h
layertree/qgslayertreeregistrybridge.h
)
@@ -636,6 +638,7 @@ SET(QGIS_CORE_HDRS
layertree/qgslayertree.h
layertree/qgslayertreegroup.h
layertree/qgslayertreelayer.h
layertree/qgslayertreemodel.h
layertree/qgslayertreenode.h
layertree/qgslayertreeregistrybridge.h
layertree/qgslayertreeutils.h
@@ -24,12 +24,14 @@
#include "qgscomposermodel.h"
#include "qgslegendrenderer.h"
#include "qgslogger.h"
#include "qgsproject.h"
#include <QDomDocument>
#include <QDomElement>
#include <QPainter>

QgsComposerLegend::QgsComposerLegend( QgsComposition* composition )
: QgsComposerItem( composition )
, mLegendModel2( QgsProject::instance()->layerTreeRoot() )
, mComposerMap( 0 )
{

@@ -38,7 +40,10 @@ QgsComposerLegend::QgsComposerLegend( QgsComposition* composition )
connect( &mLegendModel, SIGNAL( layersChanged() ), this, SLOT( synchronizeWithModel() ) );
}

QgsComposerLegend::QgsComposerLegend(): QgsComposerItem( 0 ), mComposerMap( 0 )
QgsComposerLegend::QgsComposerLegend()
: QgsComposerItem( 0 )
, mLegendModel2( QgsProject::instance()->layerTreeRoot() )
, mComposerMap( 0 )
{

}
@@ -67,7 +72,7 @@ void QgsComposerLegend::paint( QPainter* painter, const QStyleOptionGraphicsItem
painter->setRenderHint( QPainter::Antialiasing, true );
painter->setPen( QPen( QColor( 0, 0, 0 ) ) );

QgsLegendRenderer legendRenderer( &mLegendModel, mSettings );
QgsLegendRenderer legendRenderer( &mLegendModel2, mSettings );
legendRenderer.setLegendSize( rect().size() );
legendRenderer.drawLegend( painter );

@@ -83,7 +88,7 @@ void QgsComposerLegend::paint( QPainter* painter, const QStyleOptionGraphicsItem

QSizeF QgsComposerLegend::paintAndDetermineSize( QPainter* painter )
{
QgsLegendRenderer legendRenderer( &mLegendModel, mSettings );
QgsLegendRenderer legendRenderer( &mLegendModel2, mSettings );
QSizeF size = legendRenderer.minimumSize();
if ( !painter )
legendRenderer.drawLegend( painter );
@@ -93,7 +98,7 @@ QSizeF QgsComposerLegend::paintAndDetermineSize( QPainter* painter )

void QgsComposerLegend::adjustBoxSize()
{
QgsLegendRenderer legendRenderer( &mLegendModel, mSettings );
QgsLegendRenderer legendRenderer( &mLegendModel2, mSettings );
QSizeF size = legendRenderer.minimumSize();
QgsDebugMsg( QString( "width = %1 height = %2" ).arg( size.width() ).arg( size.height() ) );
if ( size.isValid() )
@@ -21,6 +21,7 @@
#include "qgscomposerlegendstyle.h"
#include "qgscomposeritem.h"
#include "qgscomposerlegenditem.h"
#include "qgslayertreemodel.h"
#include "qgslegendmodel.h"
#include "qgslegendsettings.h"

@@ -153,6 +154,8 @@ class CORE_EXPORT QgsComposerLegend : public QgsComposerItem

QgsLegendModel mLegendModel;

QgsLayerTreeModel mLegendModel2;

QgsLegendSettings mSettings;

const QgsComposerMap* mComposerMap;

0 comments on commit 6891aae

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