Skip to content

Commit

Permalink
Use QgsLayerTreeModel as a source of data for legend rendering instea…
Browse files Browse the repository at this point in the history
…d of QgsLegendModel

This is work in progress, customization of legend is not working yet
  • Loading branch information
wonder-sk committed Sep 1, 2014
1 parent 372b731 commit 6891aae
Show file tree
Hide file tree
Showing 32 changed files with 731 additions and 656 deletions.
1 change: 1 addition & 0 deletions python/core/core.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions python/core/layertree/qgslayertreelayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion python/gui/gui.sip
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@

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

Expand Down
3 changes: 3 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -407,6 +408,7 @@ SET(QGIS_CORE_MOC_HDRS

layertree/qgslayertreegroup.h
layertree/qgslayertreelayer.h
layertree/qgslayertreemodel.h
layertree/qgslayertreenode.h
layertree/qgslayertreeregistrybridge.h
)
Expand Down Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions src/core/composer/qgscomposerlegend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{

Expand All @@ -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 )
{

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

Expand All @@ -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 );
Expand All @@ -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() )
Expand Down
3 changes: 3 additions & 0 deletions src/core/composer/qgscomposerlegend.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "qgscomposerlegendstyle.h"
#include "qgscomposeritem.h"
#include "qgscomposerlegenditem.h"
#include "qgslayertreemodel.h"
#include "qgslegendmodel.h"
#include "qgslegendsettings.h"

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

QgsLegendModel mLegendModel;

QgsLayerTreeModel mLegendModel2;

QgsLegendSettings mSettings;

const QgsComposerMap* mComposerMap;
Expand Down
Loading

0 comments on commit 6891aae

Please sign in to comment.