Remove legacy QgsLegendInterface, move still valid methods to QgisInterface

This commit is contained in:
Martin Dobias 2016-11-21 23:43:30 +08:00
parent 188033a6af
commit e5f62e49ce
16 changed files with 96 additions and 820 deletions

View File

@ -240,6 +240,11 @@ so there is no longer a need for the separate cache class. Code which previously
should now call QgsCoordinateReferenceSystem::invalidateCache() and QgsCoordinateTransformCache::instance()->invalidateCrs( authid ).
- QgsHttpTransaction. This class was outdated and code should be ported to native Qt or Python implementations.
- QgsLabel and QgsLabelAttributes. Replaced by labeling based on PAL library, see QgsLabelingEngineV2.
- QgsLegendInterface was removed. It was replaced by layer tree API (QgsLayerTreeNode class and others).
Methods that deal with custom actions in main window's layer tree context menu were moved to QgisInterface:
- addLegendLayerAction() moved to QgisInterface::addCustomActionForLayerType()
- addLegendLayerActionForLayer() moved to QgisInterface::addCustomActionForLayer()
- removeLegendLayerAction() moved to QgisInterface::removeCustomActionForLayerType()
- QgsLegendModel was removed.
- QgsMapCanvasMap. It is an internal class used by map canvas.
- QgsMapRenderer. It has been replaced by QgsMapRendererJob with subclasses and QgsMapSettings.

View File

@ -93,7 +93,6 @@
%Include qgskeyvaluewidget.sip
%Include qgslistwidget.sip
%Include qgslegendfilterbutton.sip
%Include qgslegendinterface.sip
%Include qgslimitedrandomcolorrampdialog.sip
%Include qgslonglongvalidator.sip
%Include qgsludialog.sip

View File

@ -24,13 +24,36 @@ class QgisInterface : QObject
/** Virtual destructor */
virtual ~QgisInterface();
/** Get pointer to legend interface */
virtual QgsLegendInterface* legendInterface() = 0;
virtual QgsPluginManagerInterface* pluginManagerInterface() = 0;
virtual QgsLayerTreeView* layerTreeView() = 0;
/** Add action to context menu for layers in the layer tree.
* If allLayers is true, then the action will be available for all layers of given type,
* otherwise the action will be available only for specific layers added with addCustomActionForLayer()
* after this call.
*
* If menu argument is not empty, the action will be also added to a menu within the main window,
* creating menu with the given name if it does not exist yet.
*
* @see removeCustomActionForLayerType()
* @see addCustomActionForLayer()
*/
virtual void addCustomActionForLayerType( QAction* action, QString menu,
QgsMapLayer::LayerType type, bool allLayers ) = 0;
/** Add action to context menu for a specific layer in the layer tree.
* It is necessary to first call addCustomActionForLayerType() with allLayers=false
* in order for this method to have any effect.
* @see addCustomActionForLayerType()
*/
virtual void addCustomActionForLayer( QAction* action, QgsMapLayer* layer ) = 0;
/** Remove action for layers in the layer tree previously added with addCustomActionForLayerType()
* @see addCustomActionForLayerType()
*/
virtual bool removeCustomActionForLayerType( QAction* action ) = 0;
public slots: // TODO: do these functions really need to be slots?
/* Exposed functions */

View File

@ -1,118 +0,0 @@
/**
* \class QgsLegendInterface
* \brief Abstract base class to make QgsLegend available to plugins.
*/
class QgsLegendInterface : QObject
{
%TypeHeaderCode
#include <qgslegendinterface.h>
%End
public:
/** Constructor */
QgsLegendInterface();
/** Virtual destructor */
~QgsLegendInterface();
//! Return a string list of groups
virtual QStringList groups() = 0;
//! Return the relationship between groups and layers in the legend
virtual QList< QPair< QString, QList<QString> > > groupLayerRelationship();
//! Returns the currently selected layers of QgsLegendLayers.
//! @param inDrawOrder return layers in drawing order
//! @returns list of layers, else an empty list
virtual QList<QgsMapLayer *> selectedLayers( bool inDrawOrder = false ) const = 0;
//! Return all layers in the project in drawing order
virtual QList< QgsMapLayer * > layers() const = 0;
//! Check if a group exists
virtual bool groupExists( int groupIndex ) = 0;
//! Check if a group is expanded
virtual bool isGroupExpanded( int groupIndex ) = 0;
//! Check if a group is visible
virtual bool isGroupVisible( int groupIndex ) = 0;
//! Check if a layer is expanded
virtual bool isLayerExpanded( QgsMapLayer * ml ) = 0;
//! Check if a layer is visible
virtual bool isLayerVisible( QgsMapLayer * ml ) = 0;
/** Add action for layers in the legend */
virtual void addLegendLayerAction( QAction* action, QString menu, QString id,
QgsMapLayer::LayerType type, bool allLayers ) = 0;
/** Add action for a specific layers in the legend.
* Use this in combination with addLegendLayerAction( allLayers = False )
*/
virtual void addLegendLayerActionForLayer( QAction* action, QgsMapLayer* layer ) = 0;
/** Remove action for layers in the legend */
virtual bool removeLegendLayerAction( QAction* action ) = 0;
//! Returns the current layer if the current item is a QgsLegendLayer.
//! If the current item is a QgsLegendLayer, its first maplayer is returned.
//! Else, 0 is returned.
virtual QgsMapLayer* currentLayer() = 0;
//! set the current layer
//! returns true if the layer exists, false otherwise
virtual bool setCurrentLayer( QgsMapLayer *layer ) = 0;
signals:
//! emitted when a group index has changed
void groupIndexChanged( int oldIndex, int newIndex );
/* //! emitted when group relations have changed */
void groupRelationsChanged();
/* //! emitted when an item (group/layer) is added */
void itemAdded( const QModelIndex& index );
/* //! emitted when an item (group/layer) is removed */
void itemRemoved();
//! Emitted whenever current (selected) layer changes
// the pointer to layer can be null if no layer is selected
void currentLayerChanged( QgsMapLayer * layer );
public slots:
//! Add a new group
//! a parent group can be given to nest the new group in it
virtual int addGroup( const QString& name, bool expand = true, QTreeWidgetItem* parent = 0 ) = 0;
//! Add a new group
//! a parent group index has to be given to nest the new group in it
virtual int addGroup( const QString& name, bool expand, int parentIndex ) = 0;
//! Remove group on index
virtual void removeGroup( int groupIndex ) = 0;
//! Move a layer to a group
virtual void moveLayer( QgsMapLayer * ml, int groupIndex ) = 0;
//! Collapse or expand a group
virtual void setGroupExpanded( int groupIndex, bool expand ) = 0;
//! Collapse or expand a layer
virtual void setLayerExpanded( QgsMapLayer * ml, bool expand ) = 0;
//! Set the visibility of a group
virtual void setGroupVisible( int groupIndex, bool visible ) = 0;
//! Set the visibility of a layer
virtual void setLayerVisible( QgsMapLayer * ml, bool visible ) = 0;
//! Refresh layer symbology
virtual void refreshLayerSymbology( QgsMapLayer *ml ) = 0;
};

View File

@ -151,8 +151,6 @@ SET(QGIS_APP_SRCS
composer/qgscompositionwidget.cpp
composer/qgsatlascompositionwidget.cpp
legend/qgsapplegendinterface.cpp
ogr/qgsogrhelperfunctions.cpp
ogr/qgsopenvectorlayerdialog.cpp
ogr/qgsnewogrconnection.cpp
@ -324,8 +322,6 @@ SET (QGIS_APP_MOC_HDRS
composer/qgscompositionwidget.h
composer/qgsatlascompositionwidget.h
legend/qgsapplegendinterface.h
ogr/qgsopenvectorlayerdialog.h
ogr/qgsnewogrconnection.h
ogr/qgsvectorlayersaveasdialog.h

View File

@ -1,369 +0,0 @@
/***************************************************************************
qgsapplegendinterface.cpp
--------------------------------------
Date : 19-Nov-2009
Copyright : (C) 2009 by Andres Manz
Email : manz dot andres at gmail dot com
****************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsapplegendinterface.h"
#include "qgsapplayertreeviewmenuprovider.h"
#include "qgslayertree.h"
#include "qgslayertreemodel.h"
#include "qgslayertreeview.h"
#include "qgsmaplayer.h"
#include "qgsproject.h"
#include "qgslayertreeregistrybridge.h"
QgsAppLegendInterface::QgsAppLegendInterface( QgsLayerTreeView * layerTreeView )
: mLayerTreeView( layerTreeView )
{
connect( layerTreeView->layerTreeModel()->rootGroup(), SIGNAL( addedChildren( QgsLayerTreeNode*, int, int ) ), this, SLOT( onAddedChildren( QgsLayerTreeNode*, int, int ) ) );
connect( layerTreeView->layerTreeModel()->rootGroup(), SIGNAL( removedChildren( QgsLayerTreeNode*, int, int ) ), this, SLOT( onRemovedChildren() ) );
connect( layerTreeView, SIGNAL( currentLayerChanged( QgsMapLayer * ) ), this, SIGNAL( currentLayerChanged( QgsMapLayer * ) ) );
}
QgsAppLegendInterface::~QgsAppLegendInterface()
{
}
int QgsAppLegendInterface::addGroup( const QString& name, bool expand, QTreeWidgetItem* parent )
{
if ( parent )
return -1;
return addGroup( name, expand, -1 );
}
void QgsAppLegendInterface::setExpanded( QgsLayerTreeNode *node, bool expand )
{
QModelIndex idx = mLayerTreeView->layerTreeModel()->node2index( node );
if ( expand )
mLayerTreeView->expand( idx );
else
mLayerTreeView->collapse( idx );
}
int QgsAppLegendInterface::addGroup( const QString& name, bool expand, int parentIndex )
{
QgsLayerTreeGroup* parentGroup = parentIndex == -1 ? mLayerTreeView->layerTreeModel()->rootGroup() : groupIndexToNode( parentIndex );
if ( !parentGroup )
return -1;
QgsLayerTreeGroup* group = parentGroup->addGroup( name );
setExpanded( group, expand );
return groupNodeToIndex( group );
}
void QgsAppLegendInterface::removeGroup( int groupIndex )
{
QgsLayerTreeGroup* group = groupIndexToNode( groupIndex );
if ( !group || !QgsLayerTree::isGroup( group->parent() ) )
return;
QgsLayerTreeGroup* parentGroup = QgsLayerTree::toGroup( group->parent() );
parentGroup->removeChildNode( group );
}
void QgsAppLegendInterface::moveLayer( QgsMapLayer *ml, int groupIndex )
{
if ( !ml )
return;
QgsLayerTreeGroup* group = groupIndexToNode( groupIndex );
if ( !group )
return;
QgsLayerTreeLayer* nodeLayer = mLayerTreeView->layerTreeModel()->rootGroup()->findLayer( ml->id() );
if ( !nodeLayer || !QgsLayerTree::isGroup( nodeLayer->parent() ) )
return;
group->insertChildNode( 0, nodeLayer->clone() );
QgsLayerTreeGroup* nodeLayerParentGroup = QgsLayerTree::toGroup( nodeLayer->parent() );
nodeLayerParentGroup->removeChildNode( nodeLayer );
}
void QgsAppLegendInterface::setGroupExpanded( int groupIndex, bool expand )
{
if ( QgsLayerTreeGroup* group = groupIndexToNode( groupIndex ) )
setExpanded( group, expand );
}
void QgsAppLegendInterface::setGroupVisible( int groupIndex, bool visible )
{
if ( QgsLayerTreeGroup* group = groupIndexToNode( groupIndex ) )
group->setVisible( visible ? Qt::Checked : Qt::Unchecked );
}
static QgsLayerTreeGroup* _groupIndexToNode( int groupIndex, QgsLayerTreeGroup* parentGroup, int& currentIndex )
{
++currentIndex;
Q_FOREACH ( QgsLayerTreeNode* child, parentGroup->children() )
{
if ( QgsLayerTree::isGroup( child ) )
{
if ( currentIndex == groupIndex )
return QgsLayerTree::toGroup( child );
if ( QgsLayerTreeGroup* res = _groupIndexToNode( groupIndex, QgsLayerTree::toGroup( child ), currentIndex ) )
return res;
}
}
return nullptr;
}
QgsLayerTreeGroup* QgsAppLegendInterface::groupIndexToNode( int itemIndex )
{
int currentIndex = -1;
return _groupIndexToNode( itemIndex, mLayerTreeView->layerTreeModel()->rootGroup(), currentIndex );
}
static int _groupNodeToIndex( QgsLayerTreeGroup* group, QgsLayerTreeGroup* parentGroup, int& currentIndex )
{
++currentIndex;
Q_FOREACH ( QgsLayerTreeNode* child, parentGroup->children() )
{
if ( QgsLayerTree::isGroup( child ) )
{
QgsLayerTreeGroup* childGroup = QgsLayerTree::toGroup( child );
if ( childGroup == group )
return currentIndex;
int res = _groupNodeToIndex( group, childGroup, currentIndex );
if ( res != -1 )
return res;
}
}
return -1;
}
int QgsAppLegendInterface::groupNodeToIndex( QgsLayerTreeGroup* group )
{
int currentIndex = -1;
return _groupNodeToIndex( group, mLayerTreeView->layerTreeModel()->rootGroup(), currentIndex );
}
void QgsAppLegendInterface::setLayerVisible( QgsMapLayer *ml, bool visible )
{
if ( !ml )
return;
if ( QgsLayerTreeLayer* nodeLayer = mLayerTreeView->layerTreeModel()->rootGroup()->findLayer( ml->id() ) )
nodeLayer->setVisible( visible ? Qt::Checked : Qt::Unchecked );
}
void QgsAppLegendInterface::setLayerExpanded( QgsMapLayer * ml, bool expand )
{
if ( !ml )
return;
if ( QgsLayerTreeLayer* nodeLayer = mLayerTreeView->layerTreeModel()->rootGroup()->findLayer( ml->id() ) )
setExpanded( nodeLayer, expand );
}
static void _collectGroups( QgsLayerTreeGroup* parentGroup, QStringList& list )
{
Q_FOREACH ( QgsLayerTreeNode* child, parentGroup->children() )
{
if ( QgsLayerTree::isGroup( child ) )
{
QgsLayerTreeGroup* childGroup = QgsLayerTree::toGroup( child );
list << childGroup->name();
_collectGroups( childGroup, list );
}
}
}
QStringList QgsAppLegendInterface::groups()
{
QStringList list;
_collectGroups( mLayerTreeView->layerTreeModel()->rootGroup(), list );
return list;
}
QList< GroupLayerInfo > QgsAppLegendInterface::groupLayerRelationship()
{
QList< GroupLayerInfo > groupLayerList;
QList< QgsLayerTreeNode* > nodes = mLayerTreeView->layerTreeModel()->rootGroup()->children();
while ( !nodes.isEmpty() )
{
QgsLayerTreeNode* currentNode = nodes.takeFirst();
if ( QgsLayerTree::isLayer( currentNode ) )
{
QList<QString> layerList;
layerList.push_back( QgsLayerTree::toLayer( currentNode )->layerId() );
groupLayerList.push_back( qMakePair( QString(), layerList ) );
}
else if ( QgsLayerTree::isGroup( currentNode ) )
{
QList<QString> layerList;
Q_FOREACH ( QgsLayerTreeNode* gNode, QgsLayerTree::toGroup( currentNode )->children() )
{
if ( QgsLayerTree::isLayer( gNode ) )
{
layerList.push_back( QgsLayerTree::toLayer( gNode )->layerId() );
}
else if ( QgsLayerTree::isGroup( gNode ) )
{
layerList << QgsLayerTree::toGroup( gNode )->name();
nodes << gNode;
}
}
groupLayerList.push_back( qMakePair( QgsLayerTree::toGroup( currentNode )->name(), layerList ) );
}
}
return groupLayerList;
}
bool QgsAppLegendInterface::groupExists( int groupIndex )
{
return nullptr != groupIndexToNode( groupIndex );
}
bool QgsAppLegendInterface::isGroupExpanded( int groupIndex )
{
if ( QgsLayerTreeGroup* group = groupIndexToNode( groupIndex ) )
return group->isExpanded();
return false;
}
bool QgsAppLegendInterface::isGroupVisible( int groupIndex )
{
if ( QgsLayerTreeGroup* group = groupIndexToNode( groupIndex ) )
return group->isVisible() == Qt::Checked;
return false;
}
bool QgsAppLegendInterface::isLayerExpanded( QgsMapLayer *ml )
{
if ( !ml )
return false;
if ( QgsLayerTreeLayer* nodeLayer = mLayerTreeView->layerTreeModel()->rootGroup()->findLayer( ml->id() ) )
return nodeLayer->isExpanded();
return false;
}
bool QgsAppLegendInterface::isLayerVisible( QgsMapLayer *ml )
{
if ( !ml )
return false;
if ( QgsLayerTreeLayer* nodeLayer = mLayerTreeView->layerTreeModel()->rootGroup()->findLayer( ml->id() ) )
return nodeLayer->isVisible() == Qt::Checked;
return false;
}
QList<QgsMapLayer *> QgsAppLegendInterface::selectedLayers( bool inDrawOrder ) const
{
Q_UNUSED( inDrawOrder ); // TODO[MD]
return mLayerTreeView->selectedLayers();
}
QList< QgsMapLayer * > QgsAppLegendInterface::layers() const
{
QList<QgsMapLayer*> lst;
Q_FOREACH ( QgsLayerTreeLayer* node, mLayerTreeView->layerTreeModel()->rootGroup()->findLayers() )
{
if ( node->layer() )
lst << node->layer();
}
return lst;
}
void QgsAppLegendInterface::refreshLayerSymbology( QgsMapLayer *ml )
{
if ( !ml )
return;
mLayerTreeView->refreshLayerSymbology( ml->id() );
}
void QgsAppLegendInterface::onAddedChildren( QgsLayerTreeNode* node, int indexFrom, int indexTo )
{
emit groupRelationsChanged();
for ( int i = indexFrom; i <= indexTo; ++i )
{
QgsLayerTreeNode* child = node->children().at( i );
emit itemAdded( mLayerTreeView->layerTreeModel()->node2index( child ) );
// also notify about all children
if ( QgsLayerTree::isGroup( child ) && !child->children().isEmpty() )
onAddedChildren( child, 0, child->children().count() - 1 );
}
}
void QgsAppLegendInterface::onRemovedChildren()
{
emit groupRelationsChanged();
emit itemRemoved();
}
void QgsAppLegendInterface::addLegendLayerAction( QAction* action,
QString menu, QString id, QgsMapLayer::LayerType type, bool allLayers )
{
QgsAppLayerTreeViewMenuProvider* menuProvider = dynamic_cast<QgsAppLayerTreeViewMenuProvider*>( mLayerTreeView->menuProvider() );
if ( !menuProvider )
return;
menuProvider->addLegendLayerAction( action, menu, id, type, allLayers );
}
void QgsAppLegendInterface::addLegendLayerActionForLayer( QAction* action, QgsMapLayer* layer )
{
QgsAppLayerTreeViewMenuProvider* menuProvider = dynamic_cast<QgsAppLayerTreeViewMenuProvider*>( mLayerTreeView->menuProvider() );
if ( !menuProvider )
return;
menuProvider->addLegendLayerActionForLayer( action, layer );
}
bool QgsAppLegendInterface::removeLegendLayerAction( QAction* action )
{
QgsAppLayerTreeViewMenuProvider* menuProvider = dynamic_cast<QgsAppLayerTreeViewMenuProvider*>( mLayerTreeView->menuProvider() );
if ( !menuProvider )
return false;
return menuProvider->removeLegendLayerAction( action );
}
QgsMapLayer* QgsAppLegendInterface::currentLayer()
{
return mLayerTreeView->currentLayer();
}
bool QgsAppLegendInterface::setCurrentLayer( QgsMapLayer *layer )
{
if ( !mLayerTreeView->layerTreeModel()->rootGroup()->findLayer( layer->id() ) )
return false;
mLayerTreeView->setCurrentLayer( layer );
return true;
}

View File

@ -1,122 +0,0 @@
/***************************************************************************
qgsapplegendinterface.h
--------------------------------------
Date : 23-Nov-2009
Copyright : (C) 2009 by Andres Manz
Email : manz dot andres at gmail dot com
****************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSLEGENDAPPIFACE_H
#define QGSLEGENDAPPIFACE_H
#include "qgslegendinterface.h"
#include <QModelIndex>
class QgsLayerTreeGroup;
class QgsLayerTreeNode;
class QgsLayerTreeView;
class QgsMapLayer;
/** \ingroup gui
* QgsLegendInterface
* Abstract base class to make QgsLegend available to plugins.
*/
class QgsAppLegendInterface : public QgsLegendInterface
{
Q_OBJECT
public:
//! Constructor
explicit QgsAppLegendInterface( QgsLayerTreeView * layerTreeView );
//! Destructor
~QgsAppLegendInterface();
//! Return a string list of groups
QStringList groups() override;
//! Return the relationship between groups and layers in the legend
QList< GroupLayerInfo > groupLayerRelationship() override;
//! Returns the currently selected layers of QgsLegendLayers.
QList<QgsMapLayer *> selectedLayers( bool inDrawOrder = false ) const override;
//! Return all layers in the project in drawing order
QList< QgsMapLayer * > layers() const override;
//! Check if a group exists
bool groupExists( int groupIndex ) override;
//! Check if a group is expanded
bool isGroupExpanded( int groupIndex ) override;
//! Check if a group is visible
bool isGroupVisible( int groupIndex ) override;
//! Check if a layer is expanded
bool isLayerExpanded( QgsMapLayer * ml ) override;
//! Check if a layer is visible
bool isLayerVisible( QgsMapLayer * ml ) override;
void addLegendLayerAction( QAction* action, QString menu, QString id,
QgsMapLayer::LayerType type, bool allLayers ) override;
void addLegendLayerActionForLayer( QAction* action, QgsMapLayer* layer ) override;
bool removeLegendLayerAction( QAction* action ) override;
QgsMapLayer* currentLayer() override;
bool setCurrentLayer( QgsMapLayer *layer ) override;
public slots:
//! Add a new group
int addGroup( const QString& name, bool expand = true, QTreeWidgetItem* parent = nullptr ) override;
//! Add a new group at a specified index
int addGroup( const QString& name, bool expand, int groupIndex ) override;
//! Remove all groups with the given name
void removeGroup( int groupIndex ) override;
//! Move a layer to a group
void moveLayer( QgsMapLayer *ml, int groupIndex ) override;
//! Collapse or expand a group
virtual void setGroupExpanded( int groupIndex, bool expand ) override;
//! Collapse or expand a layer
virtual void setLayerExpanded( QgsMapLayer * ml, bool expand ) override;
//! Set the visibility of a group
virtual void setGroupVisible( int groupIndex, bool visible ) override;
//! Set the visibility of a layer
virtual void setLayerVisible( QgsMapLayer * ml, bool visible ) override;
//! refresh layer symbology
void refreshLayerSymbology( QgsMapLayer *ml ) override;
protected slots:
void onAddedChildren( QgsLayerTreeNode* node, int indexFrom, int indexTo );
void onRemovedChildren();
private:
//! Pointer to QgsLegend object
QgsLayerTreeView* mLayerTreeView;
QgsLayerTreeGroup* groupIndexToNode( int itemIndex );
int groupNodeToIndex( QgsLayerTreeGroup* group );
void setExpanded( QgsLayerTreeNode *node, bool expand );
};
#endif //QGSLEGENDAPPIFACE_H

View File

@ -28,6 +28,7 @@
#include "qgisappinterface.h"
#include "qgisappstylesheet.h"
#include "qgisapp.h"
#include "qgsapplayertreeviewmenuprovider.h"
#include "qgscomposer.h"
#include "qgscomposerview.h"
#include "qgsmaplayer.h"
@ -48,7 +49,6 @@
QgisAppInterface::QgisAppInterface( QgisApp * _qgis )
: qgis( _qgis )
, mTimer( nullptr )
, legendIface( _qgis->layerTreeView() )
, pluginManagerIface( _qgis->pluginManager() )
{
// connect signals
@ -76,11 +76,6 @@ QgisAppInterface::~QgisAppInterface()
{
}
QgsLegendInterface* QgisAppInterface::legendInterface()
{
return &legendIface;
}
QgsPluginManagerInterface* QgisAppInterface::pluginManagerInterface()
{
return &pluginManagerIface;
@ -91,6 +86,34 @@ QgsLayerTreeView*QgisAppInterface::layerTreeView()
return qgis->layerTreeView();
}
void QgisAppInterface::addCustomActionForLayerType( QAction* action,
QString menu, QgsMapLayer::LayerType type, bool allLayers )
{
QgsAppLayerTreeViewMenuProvider* menuProvider = dynamic_cast<QgsAppLayerTreeViewMenuProvider*>( qgis->layerTreeView()->menuProvider() );
if ( !menuProvider )
return;
menuProvider->addLegendLayerAction( action, menu, type, allLayers );
}
void QgisAppInterface::addCustomActionForLayer( QAction* action, QgsMapLayer* layer )
{
QgsAppLayerTreeViewMenuProvider* menuProvider = dynamic_cast<QgsAppLayerTreeViewMenuProvider*>( qgis->layerTreeView()->menuProvider() );
if ( !menuProvider )
return;
menuProvider->addLegendLayerActionForLayer( action, layer );
}
bool QgisAppInterface::removeCustomActionForLayerType( QAction* action )
{
QgsAppLayerTreeViewMenuProvider* menuProvider = dynamic_cast<QgsAppLayerTreeViewMenuProvider*>( qgis->layerTreeView()->menuProvider() );
if ( !menuProvider )
return false;
return menuProvider->removeLegendLayerAction( action );
}
void QgisAppInterface::zoomFull()
{
qgis->zoomFull();

View File

@ -19,7 +19,6 @@
#define QGISIFACE_H
#include "qgisinterface.h"
#include "qgsapplegendinterface.h"
#include "qgsapppluginmanagerinterface.h"
class QgisApp;
@ -46,12 +45,15 @@ class APP_EXPORT QgisAppInterface : public QgisInterface
QgisAppInterface( QgisApp *qgisapp );
~QgisAppInterface();
QgsLegendInterface* legendInterface() override;
QgsPluginManagerInterface* pluginManagerInterface() override;
QgsLayerTreeView* layerTreeView() override;
virtual void addCustomActionForLayerType( QAction* action, QString menu,
QgsMapLayer::LayerType type, bool allLayers ) override;
virtual void addCustomActionForLayer( QAction* action, QgsMapLayer* layer ) override;
virtual bool removeCustomActionForLayerType( QAction* action ) override;
/* Exposed functions */
//! Zoom map to full extent
@ -532,9 +534,6 @@ class APP_EXPORT QgisAppInterface : public QgisInterface
QTimer *mTimer;
//! Pointer to the LegendInterface object
QgsAppLegendInterface legendIface;
//! Pointer to the PluginManagerInterface object
QgsAppPluginManagerInterface pluginManagerIface;
};

View File

@ -333,10 +333,10 @@ QMenu* QgsAppLayerTreeViewMenuProvider::createContextMenu()
void QgsAppLayerTreeViewMenuProvider::addLegendLayerAction( QAction* action, const QString& menu, const QString& id,
void QgsAppLayerTreeViewMenuProvider::addLegendLayerAction( QAction* action, const QString& menu,
QgsMapLayer::LayerType type, bool allLayers )
{
mLegendLayerActionMap[type].append( LegendLayerAction( action, menu, id, allLayers ) );
mLegendLayerActionMap[type].append( LegendLayerAction( action, menu, allLayers ) );
}
bool QgsAppLayerTreeViewMenuProvider::removeLegendLayerAction( QAction* action )

View File

@ -24,15 +24,13 @@ class QAction;
struct LegendLayerAction
{
LegendLayerAction( QAction* a, const QString& m, const QString& i, bool all )
LegendLayerAction( QAction* a, const QString& m, bool all )
: action( a )
, menu( m )
, id( i )
, allLayers( all )
{}
QAction* action;
QString menu;
QString id;
bool allLayers;
QList<QgsMapLayer*> layers;
};
@ -47,7 +45,7 @@ class QgsAppLayerTreeViewMenuProvider : public QObject, public QgsLayerTreeViewM
QMenu* createContextMenu() override;
void addLegendLayerAction( QAction* action, const QString& menu, const QString& id,
void addLegendLayerAction( QAction* action, const QString& menu,
QgsMapLayer::LayerType type, bool allLayers );
bool removeLegendLayerAction( QAction* action );
void addLegendLayerActionForLayer( QAction* action, QgsMapLayer* layer );

View File

@ -240,7 +240,6 @@ SET(QGIS_GUI_SRCS
qgskeyvaluewidget.cpp
qgslistwidget.cpp
qgslegendfilterbutton.cpp
qgslegendinterface.cpp
qgslimitedrandomcolorrampdialog.cpp
qgsludialog.cpp
qgsmanageconnectionsdialog.cpp
@ -404,7 +403,6 @@ SET(QGIS_GUI_MOC_HDRS
qgskeyvaluewidget.h
qgslistwidget.h
qgslegendfilterbutton.h
qgslegendinterface.h
qgslimitedrandomcolorrampdialog.h
qgslonglongvalidator.h
qgsludialog.h

View File

@ -32,7 +32,6 @@ class QgsCustomDropHandler;
class QgsFeature;
class QgsLayerTreeMapCanvasBridge;
class QgsLayerTreeView;
class QgsLegendInterface;
class QgsMapCanvas;
class QgsMapLayer;
class QgsMapLayerConfigWidgetFactory;
@ -49,6 +48,7 @@ class QgsVectorLayerTools;
#include <map>
#include "qgis.h"
#include "qgsmaplayer.h"
/** \ingroup gui
@ -75,13 +75,36 @@ class GUI_EXPORT QgisInterface : public QObject
//! Virtual destructor
virtual ~QgisInterface();
//! Get pointer to legend interface
virtual QgsLegendInterface* legendInterface() = 0;
virtual QgsPluginManagerInterface* pluginManagerInterface() = 0;
virtual QgsLayerTreeView* layerTreeView() = 0;
/** Add action to context menu for layers in the layer tree.
* If allLayers is true, then the action will be available for all layers of given type,
* otherwise the action will be available only for specific layers added with addCustomActionForLayer()
* after this call.
*
* If menu argument is not empty, the action will be also added to a menu within the main window,
* creating menu with the given name if it does not exist yet.
*
* @see removeCustomActionForLayerType()
* @see addCustomActionForLayer()
*/
virtual void addCustomActionForLayerType( QAction* action, QString menu,
QgsMapLayer::LayerType type, bool allLayers ) = 0;
/** Add action to context menu for a specific layer in the layer tree.
* It is necessary to first call addCustomActionForLayerType() with allLayers=false
* in order for this method to have any effect.
* @see addCustomActionForLayerType()
*/
virtual void addCustomActionForLayer( QAction* action, QgsMapLayer* layer ) = 0;
/** Remove action for layers in the layer tree previously added with addCustomActionForLayerType()
* @see addCustomActionForLayerType()
*/
virtual bool removeCustomActionForLayerType( QAction* action ) = 0;
public slots: // TODO: do these functions really need to be slots?
/* Exposed functions */

View File

@ -1,26 +0,0 @@
/***************************************************************************
qgslegendinterface.cpp
--------------------------------------
Date : 19-Nov-2009
Copyright : (C) 2009 by Andres Manz
Email : manz dot andres at gmail dot com
****************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgslegendinterface.h"
QgsLegendInterface::QgsLegendInterface()
{
}
QgsLegendInterface::~QgsLegendInterface()
{
}

View File

@ -1,152 +0,0 @@
/***************************************************************************
qgslegendinterface.h
--------------------------------------
Date : 19-Nov-2009
Copyright : (C) 2009 by Andres Manz
Email : manz dot andres at gmail dot com
****************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSLEGENDINTERFACE_H
#define QGSLEGENDINTERFACE_H
#include <QObject>
#include <QPair>
#include <QStringList>
#include <QModelIndex>
class QgsMapLayer;
class QTreeWidgetItem;
class QAction;
#include "qgsmaplayer.h"
//Information about relationship between groups and layers
//key: group name (or null strings for single layers without groups)
//value: containter with layer ids contained in the group
typedef QPair< QString, QList<QString> > GroupLayerInfo;
/** \ingroup gui
* QgsLegendInterface
* Abstract base class to make QgsLegend available to plugins.
*/
class GUI_EXPORT QgsLegendInterface : public QObject
{
Q_OBJECT
public:
//! Constructor
QgsLegendInterface();
//! Virtual destructor
virtual ~QgsLegendInterface();
//! Return a string list of groups
virtual QStringList groups() = 0;
//! Return the relationship between groups and layers in the legend
virtual QList< GroupLayerInfo > groupLayerRelationship() { return QList< GroupLayerInfo >(); }
//! Returns the currently selected layers of QgsLegendLayers.
//! @param inDrawOrder return layers in drawing order
//! @returns list of layers, else an empty list
virtual QList<QgsMapLayer *> selectedLayers( bool inDrawOrder = false ) const = 0;
//! Return all layers in the project in drawing order
virtual QList< QgsMapLayer * > layers() const = 0;
//! Check if a group exists
virtual bool groupExists( int groupIndex ) = 0;
//! Check if a group is expanded
virtual bool isGroupExpanded( int groupIndex ) = 0;
//! Check if a group is visible
virtual bool isGroupVisible( int groupIndex ) = 0;
//! Check if a layer is expanded
virtual bool isLayerExpanded( QgsMapLayer * ml ) = 0;
//! Check if a layer is visible
virtual bool isLayerVisible( QgsMapLayer * ml ) = 0;
//! Add action for layers in the legend
virtual void addLegendLayerAction( QAction* action, QString menu, QString id,
QgsMapLayer::LayerType type, bool allLayers ) = 0;
/** Add action for a specific layers in the legend.
* Use this in combination with addLegendLayerAction( allLayers = False )
*/
virtual void addLegendLayerActionForLayer( QAction* action, QgsMapLayer* layer ) = 0;
//! Remove action for layers in the legend
virtual bool removeLegendLayerAction( QAction* action ) = 0;
//! Returns the current layer if the current item is a QgsLegendLayer.
//! If the current item is a QgsLegendLayer, its first maplayer is returned.
//! Else, 0 is returned.
virtual QgsMapLayer* currentLayer() = 0;
//! set the current layer
//! returns true if the layer exists, false otherwise
virtual bool setCurrentLayer( QgsMapLayer *layer ) = 0;
signals:
//! emitted when a group index has changed
void groupIndexChanged( int oldIndex, int newIndex );
/* //! emitted when group relations have changed */
void groupRelationsChanged();
/* //! emitted when an item (group/layer) is added */
void itemAdded( const QModelIndex& index );
/* //! emitted when an item (group/layer) is removed */
void itemRemoved();
//! Emitted whenever current (selected) layer changes
// the pointer to layer can be null if no layer is selected
void currentLayerChanged( QgsMapLayer * layer );
public slots:
//! Add a new group
//! a parent group can be given to nest the new group in it
virtual int addGroup( const QString& name, bool expand = true, QTreeWidgetItem* parent = nullptr ) = 0;
//! Add a new group
//! a parent group index has to be given to nest the new group in it
virtual int addGroup( const QString& name, bool expand, int parentIndex ) = 0;
//! Remove group on index
virtual void removeGroup( int groupIndex ) = 0;
//! Move a layer to a group
virtual void moveLayer( QgsMapLayer * ml, int groupIndex ) = 0;
//! Collapse or expand a group
virtual void setGroupExpanded( int groupIndex, bool expand ) = 0;
//! Collapse or expand a layer
virtual void setLayerExpanded( QgsMapLayer * ml, bool expand ) = 0;
//! Set the visibility of a group
virtual void setGroupVisible( int groupIndex, bool visible ) = 0;
//! Set the visibility of a layer
virtual void setLayerVisible( QgsMapLayer * ml, bool visible ) = 0;
//! Refresh layer symbology
virtual void refreshLayerSymbology( QgsMapLayer *ml ) = 0;
};
#endif

View File

@ -32,7 +32,6 @@
#include <QList>
#include "qgisinterface.h"
#include "qgslegendinterface.h"
#include "qgsapplication.h"
#include "qgscomposition.h"