From 3021bdafb0b41e196945c1f0606161b2c4b0b802 Mon Sep 17 00:00:00 2001 From: Martin Dobias Date: Tue, 12 Aug 2014 23:55:56 +0700 Subject: [PATCH] Work in progress: Make composer legend widget work with QgsLayerTreeModel --- src/app/composer/qgscomposerlegendwidget.cpp | 225 ++++++------------- src/app/composer/qgscomposerlegendwidget.h | 13 +- src/core/composer/qgscomposerlegend.cpp | 57 ++++- src/core/composer/qgscomposerlegend.h | 16 +- src/core/qgslegendrenderer.cpp | 10 +- src/core/qgslegendrenderer.h | 1 + src/ui/qgscomposerlegendwidgetbase.ui | 7 +- 7 files changed, 152 insertions(+), 177 deletions(-) diff --git a/src/app/composer/qgscomposerlegendwidget.cpp b/src/app/composer/qgscomposerlegendwidget.cpp index 7148e91738b2..dd4e03dc8d5e 100644 --- a/src/app/composer/qgscomposerlegendwidget.cpp +++ b/src/app/composer/qgscomposerlegendwidget.cpp @@ -25,9 +25,13 @@ #include "qgscomposition.h" #include #include +#include #include "qgisapp.h" #include "qgsapplication.h" +#include "qgslayertree.h" +#include "qgslayertreemodel.h" +#include "qgslegendrenderer.h" #include "qgsmapcanvas.h" #include "qgsmaplayerregistry.h" #include "qgsmaprenderer.h" @@ -36,73 +40,40 @@ #include -QgsComposerLegendWidgetStyleDelegate::QgsComposerLegendWidgetStyleDelegate( QObject *parent ): QItemDelegate( parent ) -{ -} -QWidget *QgsComposerLegendWidgetStyleDelegate::createEditor( QWidget *parent, const QStyleOptionViewItem & item, const QModelIndex & index ) const + +class QgsComposerLegendMenuProvider : public QObject, public QgsLayerTreeViewMenuProvider { - Q_UNUSED( item ); - Q_UNUSED( index ); - QgsDebugMsg( "Entered" ); + public: + QgsComposerLegendMenuProvider( QgsLayerTreeView* view, QgsComposerLegendWidget* w ) : mView( view ), mWidget( w ) {} - QComboBox *editor = new QComboBox( parent ); - QList list; - list << QgsComposerLegendStyle::Group << QgsComposerLegendStyle::Subgroup << QgsComposerLegendStyle::Hidden; - foreach ( QgsComposerLegendStyle::Style s, list ) - { - editor->addItem( QgsComposerLegendStyle::styleLabel( s ), s ); - } + virtual QMenu* createContextMenu() + { + if ( !mView->currentNode() ) + return 0; - return editor; -} + QMenu* menu = new QMenu(); -void QgsComposerLegendWidgetStyleDelegate::setEditorData( QWidget *editor, const QModelIndex &index ) const -{ - QgsDebugMsg( "Entered" ); - //int s = index.model()->data(index, Qt::UserRole).toInt(); - QComboBox *comboBox = static_cast( editor ); + QgsComposerLegendStyle::Style currentStyle = QgsLegendRenderer::nodeLegendStyle( mView->currentNode(), mView->layerTreeModel() ); - const QStandardItemModel * standardModel = dynamic_cast( index.model() ); - if ( standardModel ) - { - QModelIndex firstColumnIndex = standardModel->index( index.row(), 0, index.parent() ); - QStandardItem* firstColumnItem = standardModel->itemFromIndex( firstColumnIndex ); + QList lst; + lst << QgsComposerLegendStyle::Hidden << QgsComposerLegendStyle::Group << QgsComposerLegendStyle::Subgroup; + foreach ( QgsComposerLegendStyle::Style style, lst ) + { + QAction* action = menu->addAction( QgsComposerLegendStyle::styleLabel( style ), mWidget, SLOT( setCurrentNodeStyleFromAction() ) ); + action->setCheckable( true ); + action->setChecked( currentStyle == style ); + action->setData( ( int ) style ); + } - QgsComposerLegendItem* cItem = dynamic_cast( firstColumnItem ); - if ( cItem ) - { - comboBox->setCurrentIndex( comboBox->findData( cItem->style() ) ); + return menu; } - } -} -void QgsComposerLegendWidgetStyleDelegate::setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const -{ - QgsDebugMsg( "Entered" ); - QComboBox *comboBox = static_cast( editor ); - QgsComposerLegendStyle::Style s = ( QgsComposerLegendStyle::Style ) comboBox->itemData( comboBox->currentIndex() ).toInt(); - model->setData( index, s, Qt::UserRole ); - model->setData( index, QgsComposerLegendStyle::styleLabel( s ), Qt::DisplayRole ); - QStandardItemModel * standardModel = dynamic_cast( model ); - if ( standardModel ) - { - QModelIndex firstColumnIndex = standardModel->index( index.row(), 0, index.parent() ); - QStandardItem* firstColumnItem = standardModel->itemFromIndex( firstColumnIndex ); - - QgsComposerLegendItem* cItem = dynamic_cast( firstColumnItem ); - if ( cItem ) - { - cItem->setStyle( s ); - } - } -} + protected: + QgsLayerTreeView* mView; + QgsComposerLegendWidget* mWidget; +}; -void QgsComposerLegendWidgetStyleDelegate::updateEditorGeometry( QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex & index ) const -{ - Q_UNUSED( index ); - editor->setGeometry( option.rect ); -} QgsComposerLegendWidget::QgsComposerLegendWidget( QgsComposerLegend* legend ): QgsComposerItemBaseWidget( 0, legend ), mLegend( legend ) @@ -124,22 +95,15 @@ QgsComposerLegendWidget::QgsComposerLegendWidget( QgsComposerLegend* legend ): Q QgsComposerItemWidget* itemPropertiesWidget = new QgsComposerItemWidget( this, legend ); mainLayout->addWidget( itemPropertiesWidget ); + mItemTreeView->setHeaderHidden( true ); + mItemTreeView->setModel( legend->modelV2() ); + mItemTreeView->setMenuProvider( new QgsComposerLegendMenuProvider( mItemTreeView, this ) ); + if ( legend ) { - legend->model()->setHorizontalHeaderLabels( QStringList() << tr( "Item" ) << tr( "Title style" ) ); - mItemTreeView->setModel( legend->model() ); connect( legend, SIGNAL( itemChanged() ), this, SLOT( setGuiElements() ) ); } - QgsComposerLegendWidgetStyleDelegate* styleDelegate = new QgsComposerLegendWidgetStyleDelegate(); - mItemTreeView->setItemDelegateForColumn( 0, styleDelegate ); - mItemTreeView->setItemDelegateForColumn( 1, styleDelegate ); - mItemTreeView->setEditTriggers( QAbstractItemView::AllEditTriggers ); - - mItemTreeView->setDragEnabled( true ); - mItemTreeView->setAcceptDrops( true ); - mItemTreeView->setDropIndicatorShown( true ); - mItemTreeView->setDragDropMode( QAbstractItemView::InternalMove ); mWrapCharLineEdit->setText( legend->wrapChar() ); setGuiElements(); @@ -185,10 +149,7 @@ void QgsComposerLegendWidget::setGuiElements() mIconLabelSpaceSpinBox->setValue( mLegend->style( QgsComposerLegendStyle::SymbolLabel ).margin( QgsComposerLegendStyle::Left ) ); mBoxSpaceSpinBox->setValue( mLegend->boxSpace() ); mColumnSpaceSpinBox->setValue( mLegend->columnSpace() ); - if ( mLegend->model() ) - { - mCheckBoxAutoUpdate->setChecked( mLegend->model()->autoUpdate() ); - } + mCheckBoxAutoUpdate->setChecked( mLegend->autoUpdateModel() ); refreshMapComboBox(); const QgsComposerMap* map = mLegend->composerMap(); @@ -624,19 +585,7 @@ void QgsComposerLegendWidget::on_mMoveUpToolButton_clicked() void QgsComposerLegendWidget::on_mCheckBoxAutoUpdate_stateChanged( int state ) { - if ( !mLegend->model() ) - { - return; - } - - if ( state == Qt::Checked ) - { - mLegend->model()->setAutoUpdate( true ); - } - else - { - mLegend->model()->setAutoUpdate( false ); - } + mLegend->setAutoUpdateModel( state == Qt::Checked ); } void QgsComposerLegendWidget::on_mMapComboBox_currentIndexChanged( int index ) @@ -683,12 +632,6 @@ void QgsComposerLegendWidget::on_mAddToolButton_clicked() return; } - QStandardItemModel* itemModel = qobject_cast( mItemTreeView->model() ); - if ( !itemModel ) - { - return; - } - QgisApp* app = QgisApp::instance(); if ( !app ) { @@ -707,7 +650,7 @@ void QgsComposerLegendWidget::on_mAddToolButton_clicked() if ( layer ) { mLegend->beginCommand( "Legend item added" ); - mLegend->model()->addLayer( layer ); + mLegend->modelV2()->rootGroup()->addLayer( layer ); mLegend->endCommand(); } } @@ -721,12 +664,6 @@ void QgsComposerLegendWidget::on_mRemoveToolButton_clicked() return; } - QStandardItemModel* itemModel = qobject_cast( mItemTreeView->model() ); - if ( !itemModel ) - { - return; - } - QItemSelectionModel* selectionModel = mItemTreeView->selectionModel(); if ( !selectionModel ) { @@ -741,7 +678,7 @@ void QgsComposerLegendWidget::on_mRemoveToolButton_clicked() foreach ( const QPersistentModelIndex index, indexes ) { - itemModel->removeRow( index.row(), index.parent() ); + mLegend->modelV2()->removeRow( index.row(), index.parent() ); } mLegend->adjustBoxSize(); @@ -756,34 +693,23 @@ void QgsComposerLegendWidget::on_mEditPushButton_clicked() return; } - QStandardItemModel* itemModel = qobject_cast( mItemTreeView->model() ); - if ( !itemModel ) - { - return; - } + QgsLayerTreeNode* currentNode = mItemTreeView->currentNode(); - //get current item - QModelIndex currentIndex = mItemTreeView->currentIndex(); - if ( !currentIndex.isValid() ) - { - return; - } + // TODO: support layer node, legend node - QgsComposerLegendItem* currentItem = dynamic_cast( itemModel->itemFromIndex( currentIndex ) ); - if ( !currentItem ) - { + if ( !QgsLayerTree::isGroup( currentNode ) ) return; - } - QgsComposerLegendItemDialog itemDialog( currentItem ); - if ( itemDialog.exec() != QDialog::Accepted ) - { + QString currentText = QgsLayerTree::toGroup( currentNode )->name(); + + bool ok; + QString newText = QInputDialog::getText( this, tr( "Legend item properties" ), tr( "Item text" ), + QLineEdit::Normal, currentText, &ok ); + if ( !ok ) return; - } mLegend->beginCommand( tr( "Legend item edited" ) ); - currentItem->setUserText( itemDialog.itemText() ); - mLegend->model()->updateItemText( currentItem ); + QgsLayerTree::toGroup( currentNode )->setName( newText ); mLegend->adjustBoxSize(); mLegend->update(); mLegend->endCommand(); @@ -834,13 +760,6 @@ void QgsComposerLegendWidget::on_mCountToolButton_clicked( bool checked ) return; } - //get current item - QStandardItemModel* itemModel = qobject_cast( mItemTreeView->model() ); - if ( !itemModel ) - { - return; - } - //get current item QModelIndex currentIndex = mItemTreeView->currentIndex(); if ( !currentIndex.isValid() ) @@ -848,25 +767,12 @@ void QgsComposerLegendWidget::on_mCountToolButton_clicked( bool checked ) return; } - QStandardItem* currentItem = itemModel->itemFromIndex( currentIndex ); - if ( !currentItem ) - { - return; - } - - QgsComposerLayerItem* layerItem = dynamic_cast( currentItem ); - - if ( !layerItem ) - { + QgsLayerTreeNode* currentNode = mItemTreeView->currentNode(); + if ( !QgsLayerTree::isLayer( currentNode ) ) return; - } mLegend->beginCommand( tr( "Legend updated" ) ); - layerItem->setShowFeatureCount( checked ); - if ( mLegend->model() ) - { - mLegend->model()->updateItem( currentItem ); - } + currentNode->setCustomProperty( "showFeatureCount", checked ? 1 : 0 ); mLegend->update(); mLegend->adjustBoxSize(); mLegend->endCommand(); @@ -879,10 +785,10 @@ void QgsComposerLegendWidget::on_mUpdateAllPushButton_clicked() void QgsComposerLegendWidget::on_mAddGroupToolButton_clicked() { - if ( mLegend && mLegend->model() ) + if ( mLegend ) { mLegend->beginCommand( tr( "Legend group added" ) ); - mLegend->model()->addGroup(); + mLegend->modelV2()->rootGroup()->addGroup( tr( "Group" ) ); mLegend->update(); mLegend->endCommand(); } @@ -989,25 +895,32 @@ void QgsComposerLegendWidget::showEvent( QShowEvent * event ) void QgsComposerLegendWidget::selectedChanged( const QModelIndex & current, const QModelIndex & previous ) { + Q_UNUSED( current ); Q_UNUSED( previous ); QgsDebugMsg( "Entered" ); mCountToolButton->setChecked( false ); mCountToolButton->setEnabled( false ); - QStandardItemModel* itemModel = qobject_cast( mItemTreeView->model() ); - if ( !itemModel ) return; - - QStandardItem* currentItem = itemModel->itemFromIndex( current ); - if ( !currentItem ) return; - - QgsComposerLayerItem* layerItem = dynamic_cast( currentItem ); - if ( !layerItem ) return; + QgsLayerTreeNode* currentNode = mItemTreeView->currentNode(); + if ( !QgsLayerTree::isLayer( currentNode ) ) + return; - QgsVectorLayer* vectorLayer = dynamic_cast( QgsMapLayerRegistry::instance()->mapLayer( layerItem->layerID() ) ); - if ( !vectorLayer ) return; + QgsLayerTreeLayer* currentLayerNode = QgsLayerTree::toLayer( currentNode ); + QgsVectorLayer* vl = qobject_cast( currentLayerNode->layer() ); + if ( !vl ) + return; - mCountToolButton->setChecked( layerItem->showFeatureCount() ); + mCountToolButton->setChecked( currentNode->customProperty( "showFeatureCount", 0 ).toInt() ); mCountToolButton->setEnabled( true ); } +void QgsComposerLegendWidget::setCurrentNodeStyleFromAction() +{ + QAction* a = qobject_cast( sender() ); + if ( !a || !mItemTreeView->currentNode() ) + return; + + QgsLegendRenderer::setNodeLegendStyle( mItemTreeView->currentNode(), ( QgsComposerLegendStyle::Style ) a->data().toInt() ); + mLegend->update(); +} diff --git a/src/app/composer/qgscomposerlegendwidget.h b/src/app/composer/qgscomposerlegendwidget.h index 3b9f36566673..e060f50a7e43 100644 --- a/src/app/composer/qgscomposerlegendwidget.h +++ b/src/app/composer/qgscomposerlegendwidget.h @@ -25,17 +25,6 @@ class QgsComposerLegend; -class QgsComposerLegendWidgetStyleDelegate : public QItemDelegate -{ - Q_OBJECT - - public: - QgsComposerLegendWidgetStyleDelegate( QObject *parent = 0 ); - QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const; - void setEditorData( QWidget *editor, const QModelIndex &index ) const; - void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const; - void updateEditorGeometry( QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index ) const; -}; /** \ingroup MapComposer * A widget for setting properties relating to a composer legend. @@ -91,6 +80,8 @@ class QgsComposerLegendWidget: public QgsComposerItemBaseWidget, private Ui::Qgs void selectedChanged( const QModelIndex & current, const QModelIndex & previous ); + void setCurrentNodeStyleFromAction(); + protected: void showEvent( QShowEvent * event ); diff --git a/src/core/composer/qgscomposerlegend.cpp b/src/core/composer/qgscomposerlegend.cpp index fc1256f843db..df5fed55a062 100644 --- a/src/core/composer/qgscomposerlegend.cpp +++ b/src/core/composer/qgscomposerlegend.cpp @@ -22,6 +22,8 @@ #include "qgscomposermap.h" #include "qgscomposition.h" #include "qgscomposermodel.h" +#include "qgslayertree.h" +#include "qgslayertreemodel.h" #include "qgslegendrenderer.h" #include "qgslogger.h" #include "qgsproject.h" @@ -31,9 +33,12 @@ QgsComposerLegend::QgsComposerLegend( QgsComposition* composition ) : QgsComposerItem( composition ) - , mLegendModel2( QgsProject::instance()->layerTreeRoot() ) + , mCustomLayerTree( 0 ) , mComposerMap( 0 ) { + mLegendModel2 = new QgsLayerTreeModel( QgsProject::instance()->layerTreeRoot() ); + mLegendModel2->setFlag( QgsLayerTreeModel::AllowSymbologyChangeState, false ); + mLegendModel2->setFlag( QgsLayerTreeModel::AllowNodeReorder, true ); adjustBoxSize(); @@ -42,7 +47,8 @@ QgsComposerLegend::QgsComposerLegend( QgsComposition* composition ) QgsComposerLegend::QgsComposerLegend() : QgsComposerItem( 0 ) - , mLegendModel2( QgsProject::instance()->layerTreeRoot() ) + , mLegendModel2( 0 ) + , mCustomLayerTree( 0 ) , mComposerMap( 0 ) { @@ -50,6 +56,8 @@ QgsComposerLegend::QgsComposerLegend() QgsComposerLegend::~QgsComposerLegend() { + delete mLegendModel2; + delete mCustomLayerTree; } void QgsComposerLegend::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ) @@ -72,7 +80,7 @@ void QgsComposerLegend::paint( QPainter* painter, const QStyleOptionGraphicsItem painter->setRenderHint( QPainter::Antialiasing, true ); painter->setPen( QPen( QColor( 0, 0, 0 ) ) ); - QgsLegendRenderer legendRenderer( &mLegendModel2, mSettings ); + QgsLegendRenderer legendRenderer( mLegendModel2, mSettings ); legendRenderer.setLegendSize( rect().size() ); legendRenderer.drawLegend( painter ); @@ -88,7 +96,7 @@ void QgsComposerLegend::paint( QPainter* painter, const QStyleOptionGraphicsItem QSizeF QgsComposerLegend::paintAndDetermineSize( QPainter* painter ) { - QgsLegendRenderer legendRenderer( &mLegendModel2, mSettings ); + QgsLegendRenderer legendRenderer( mLegendModel2, mSettings ); QSizeF size = legendRenderer.minimumSize(); if ( !painter ) legendRenderer.drawLegend( painter ); @@ -98,7 +106,7 @@ QSizeF QgsComposerLegend::paintAndDetermineSize( QPainter* painter ) void QgsComposerLegend::adjustBoxSize() { - QgsLegendRenderer legendRenderer( &mLegendModel2, mSettings ); + QgsLegendRenderer legendRenderer( mLegendModel2, mSettings ); QSizeF size = legendRenderer.minimumSize(); QgsDebugMsg( QString( "width = %1 height = %2" ).arg( size.width() ).arg( size.height() ) ); if ( size.isValid() ) @@ -107,6 +115,29 @@ void QgsComposerLegend::adjustBoxSize() } } + +void QgsComposerLegend::setCustomLayerTree( QgsLayerTreeGroup* rootGroup ) +{ + mLegendModel2->setRootGroup( rootGroup ? rootGroup : QgsProject::instance()->layerTreeRoot() ); + + delete mCustomLayerTree; + mCustomLayerTree = rootGroup; +} + + +void QgsComposerLegend::setAutoUpdateModel( bool autoUpdate ) +{ + if ( autoUpdate == autoUpdateModel() ) + return; + + setCustomLayerTree( autoUpdate ? 0 : QgsLayerTree::toGroup( QgsProject::instance()->layerTreeRoot()->clone() ) ); +} + +bool QgsComposerLegend::autoUpdateModel() const +{ + return !mCustomLayerTree; +} + void QgsComposerLegend::setTitle( const QString& t ) { mSettings.setTitle( t ); @@ -222,8 +253,16 @@ bool QgsComposerLegend::writeXML( QDomElement& elem, QDomDocument & doc ) const style( QgsComposerLegendStyle::Symbol ).writeXML( "symbol", composerLegendStyles, doc ); style( QgsComposerLegendStyle::SymbolLabel ).writeXML( "symbolLabel", composerLegendStyles, doc ); +#if 0 //write model properties mLegendModel.writeXML( composerLegendElem, doc ); +#endif + + if ( mCustomLayerTree ) + { + // if not using auto-update - store the custom layer tree + mCustomLayerTree->writeXML( composerLegendElem ); + } return _writeXML( composerLegendElem, doc ); } @@ -288,6 +327,7 @@ bool QgsComposerLegend::readXML( const QDomElement& itemElem, const QDomDocument mComposerMap = mComposition->getComposerMapById( itemElem.attribute( "map" ).toInt() ); } +#if 0 //read model properties QDomNodeList modelNodeList = itemElem.elementsByTagName( "Model" ); if ( modelNodeList.size() > 0 ) @@ -295,6 +335,13 @@ bool QgsComposerLegend::readXML( const QDomElement& itemElem, const QDomDocument QDomElement modelElem = modelNodeList.at( 0 ).toElement(); mLegendModel.readXML( modelElem, doc ); } +#endif + + QDomElement layerTreeElem = itemElem.firstChildElement( "layer-tree-group" ); + if ( layerTreeElem.isNull() ) + { + setCustomLayerTree( QgsLayerTreeGroup::readXML( layerTreeElem ) ); + } //restore general composer item properties QDomNodeList composerItemList = itemElem.elementsByTagName( "ComposerItem" ); diff --git a/src/core/composer/qgscomposerlegend.h b/src/core/composer/qgscomposerlegend.h index a916f082da86..b8c4acf877e1 100644 --- a/src/core/composer/qgscomposerlegend.h +++ b/src/core/composer/qgscomposerlegend.h @@ -21,10 +21,10 @@ #include "qgscomposerlegendstyle.h" #include "qgscomposeritem.h" #include "qgscomposerlegenditem.h" -#include "qgslayertreemodel.h" #include "qgslegendmodel.h" #include "qgslegendsettings.h" +class QgsLayerTreeModel; class QgsSymbolV2; class QgsComposerGroupItem; class QgsComposerLayerItem; @@ -58,6 +58,14 @@ class CORE_EXPORT QgsComposerLegend : public QgsComposerItem /**Returns pointer to the legend model*/ QgsLegendModel* model() {return &mLegendModel;} + //! @note added in 2.6 + QgsLayerTreeModel* modelV2() { return mLegendModel2; } + + //! @note added in 2.6 + void setAutoUpdateModel( bool autoUpdate ); + //! @note added in 2.6 + bool autoUpdateModel() const; + //setters and getters void setTitle( const QString& t ); QString title() const; @@ -152,9 +160,13 @@ class CORE_EXPORT QgsComposerLegend : public QgsComposerItem private: QgsComposerLegend(); //forbidden + //! use new custom layer tree and update model. if new root is null pointer, will use project's tree + void setCustomLayerTree( QgsLayerTreeGroup* rootGroup ); + QgsLegendModel mLegendModel; - QgsLayerTreeModel mLegendModel2; + QgsLayerTreeModel* mLegendModel2; + QgsLayerTreeGroup* mCustomLayerTree; QgsLegendSettings mSettings; diff --git a/src/core/qgslegendrenderer.cpp b/src/core/qgslegendrenderer.cpp index 2778e840e42d..096e836f96b8 100644 --- a/src/core/qgslegendrenderer.cpp +++ b/src/core/qgslegendrenderer.cpp @@ -555,7 +555,8 @@ QSizeF QgsLegendRenderer::drawGroupTitle( QgsLayerTreeGroup* nodeGroup, QPainter } -QgsComposerLegendStyle::Style QgsLegendRenderer::nodeLegendStyle( QgsLayerTreeNode* node ) + +QgsComposerLegendStyle::Style QgsLegendRenderer::nodeLegendStyle( QgsLayerTreeNode* node, QgsLayerTreeModel* model ) { QString style = node->customProperty( "legendStyle" ).toString(); if ( style == "hidden" ) @@ -570,7 +571,7 @@ QgsComposerLegendStyle::Style QgsLegendRenderer::nodeLegendStyle( QgsLayerTreeNo return QgsComposerLegendStyle::Group; else if ( QgsLayerTree::isLayer( node ) ) { - QList legendNodes = mLegendModel->layerLegendNodes( QgsLayerTree::toLayer( node ) ); + QList legendNodes = model->layerLegendNodes( QgsLayerTree::toLayer( node ) ); if ( legendNodes.count() == 1 && legendNodes[0]->isEmbeddedInParent() ) return QgsComposerLegendStyle::Hidden; return QgsComposerLegendStyle::Subgroup; @@ -579,6 +580,11 @@ QgsComposerLegendStyle::Style QgsLegendRenderer::nodeLegendStyle( QgsLayerTreeNo return QgsComposerLegendStyle::Undefined; // should not happen, only if corrupted project file } +QgsComposerLegendStyle::Style QgsLegendRenderer::nodeLegendStyle( QgsLayerTreeNode* node ) +{ + return nodeLegendStyle( node, mLegendModel ); +} + void QgsLegendRenderer::setNodeLegendStyle( QgsLayerTreeNode* node, QgsComposerLegendStyle::Style style ) { QString str; diff --git a/src/core/qgslegendrenderer.h b/src/core/qgslegendrenderer.h index c21e3efa30a5..8f238ede2f18 100644 --- a/src/core/qgslegendrenderer.h +++ b/src/core/qgslegendrenderer.h @@ -46,6 +46,7 @@ class CORE_EXPORT QgsLegendRenderer static void setNodeLegendStyle( QgsLayerTreeNode* node, QgsComposerLegendStyle::Style style ); + static QgsComposerLegendStyle::Style nodeLegendStyle( QgsLayerTreeNode* node, QgsLayerTreeModel* model ); private: diff --git a/src/ui/qgscomposerlegendwidgetbase.ui b/src/ui/qgscomposerlegendwidgetbase.ui index 619fb0f5565c..9cc4414ee940 100644 --- a/src/ui/qgscomposerlegendwidgetbase.ui +++ b/src/ui/qgscomposerlegendwidgetbase.ui @@ -209,7 +209,7 @@ - + QAbstractItemView::ContiguousSelection @@ -855,6 +855,11 @@ QToolButton
qgscolorbuttonv2.h
+ + QgsLayerTreeView + QTreeView +
qgslayertreeview.h
+