Skip to content
Permalink
Browse files
Completely move layer order to core
  • Loading branch information
m-kuhn committed Mar 23, 2017
1 parent 798b1ed commit f33aabd90aab071d8b1f8f163e6cbed8869110c3
Showing with 641 additions and 511 deletions.
  1. +1 −1 python/core/composer/qgscomposerlegend.sip
  2. +47 −14 python/core/layertree/qgslayertree.sip
  3. +3 −3 python/core/layertree/qgslayertreemodel.sip
  4. +1 −1 python/core/layertree/qgslayertreeutils.sip
  5. +0 −4 python/core/qgsproject.sip
  6. +0 −8 python/gui/layertree/qgscustomlayerorderwidget.sip
  7. +4 −35 python/gui/layertree/qgslayertreemapcanvasbridge.sip
  8. +1 −0 src/app/dwg/qgsdwgimportdialog.cpp
  9. +2 −6 src/app/qgisapp.cpp
  10. +11 −6 src/app/qgsdxfexportdialog.cpp
  11. +2 −2 src/app/qgsdxfexportdialog.h
  12. +3 −6 src/app/qgsmapthemes.cpp
  13. +1 −1 src/app/qgsprojectlayergroupdialog.cpp
  14. +2 −2 src/app/qgsprojectlayergroupdialog.h
  15. +1 −0 src/app/qgsprojectproperties.cpp
  16. +1 −0 src/app/qgsvectorlayerproperties.cpp
  17. +1 −1 src/app/qgsvectorlayerproperties.h
  18. +2 −1 src/core/CMakeLists.txt
  19. +9 −17 src/core/composer/qgscomposerlegend.cpp
  20. +2 −2 src/core/composer/qgscomposerlegend.h
  21. +243 −0 src/core/layertree/qgslayertree.cpp
  22. +194 −33 src/core/layertree/qgslayertree.h
  23. +3 −3 src/core/layertree/qgslayertreemodel.cpp
  24. +7 −6 src/core/layertree/qgslayertreemodel.h
  25. +6 −6 src/core/layertree/qgslayertreeutils.cpp
  26. +1 −1 src/core/layertree/qgslayertreeutils.h
  27. +1 −1 src/core/qgsmapthemecollection.cpp
  28. +22 −63 src/core/qgsproject.cpp
  29. +3 −27 src/core/qgsproject.h
  30. +21 −13 src/gui/layertree/qgscustomlayerorderwidget.cpp
  31. +5 −4 src/gui/layertree/qgscustomlayerorderwidget.h
  32. +5 −185 src/gui/layertree/qgslayertreemapcanvasbridge.cpp
  33. +9 −37 src/gui/layertree/qgslayertreemapcanvasbridge.h
  34. +2 −2 src/plugins/offline_editing/offline_editing_plugin_gui.cpp
  35. +1 −1 src/plugins/offline_editing/offline_editing_plugin_gui.h
  36. +1 −0 src/providers/virtual/qgsembeddedlayerselectdialog.cpp
  37. +1 −0 src/providers/virtual/qgsvirtuallayersourceselect.cpp
  38. +2 −1 src/server/qgswmsconfigparser.cpp
  39. +5 −4 src/server/qgswmsprojectparser.cpp
  40. +2 −2 src/server/qgswmsprojectparser.h
  41. +1 −1 src/server/services/wms/qgswmsrenderer.cpp
  42. +3 −3 tests/src/core/testqgslayertree.cpp
  43. +8 −8 tests/src/core/testqgslegendrenderer.cpp
  44. +1 −0 tests/src/core/testqgsvectorlayerjoinbuffer.cpp
@@ -13,7 +13,7 @@ class QgsLegendModel : QgsLayerTreeModel

public:
//! Construct the model based on the given layer tree
QgsLegendModel( QgsLayerTreeGroup* rootNode, QObject *parent /TransferThis/ = 0 );
QgsLegendModel( QgsLayerTree* rootNode, QObject *parent /TransferThis/ = 0 );

QVariant data( const QModelIndex& index, int role ) const;

@@ -1,19 +1,10 @@
%ModuleHeaderCode
class QgsLayerTree : QgsLayerTreeGroup
{
%TypeHeaderCode
#include <qgslayertree.h>
%End

/**
* Namespace with helper functions for layer tree operations.
*
* Only generally useful routines should be here. Miscellaneous utility functions for work
* with the layer tree are in QgsLayerTreeUtils class.
*
* @note added in 2.4
*/
namespace QgsLayerTree
{
bool isGroup( QgsLayerTreeNode *node );
bool isLayer( const QgsLayerTreeNode *node );
static bool isGroup( QgsLayerTreeNode *node );
static bool isLayer( const QgsLayerTreeNode *node );

//! Cast node to a group. No type checking is done - use isGroup() to find out whether this operation is legal.
// PYTHON: automatic cast
@@ -23,4 +14,46 @@ namespace QgsLayerTree
// PYTHON: automatic cast
//inline QgsLayerTreeLayer* toLayer( QgsLayerTreeNode* node );

QList<QgsMapLayer *> customLayerOrder() const;
void setCustomLayerOrder( const QList<QgsMapLayer *> &customLayerOrder );
void setCustomLayerOrder( const QStringList &customLayerOrder );
QList<QgsMapLayer *> layerOrder() const;
bool hasCustomLayerOrder() const;
void setHasCustomLayerOrder( bool hasCustomLayerOrder );
static QgsLayerTree *readXml( QDomElement &element );







void readLayerOrderFromXml( const QDomElement &doc );

virtual void writeXml( QDomElement &parentElement );

virtual QgsLayerTree *clone() const;






void clear();

signals:





void customLayerOrderChanged();






void layerOrderChanged();
void hasCustomLayerOrderChanged( bool hasCustomLayerOrder );
};
@@ -28,7 +28,7 @@ class QgsLayerTreeModel : QAbstractItemModel
public:
//! Construct a new tree model with given layer tree (root node must not be null pointer).
//! The root node is not transferred by the model.
explicit QgsLayerTreeModel( QgsLayerTreeGroup* rootNode, QObject *parent /TransferThis/ = 0 );
explicit QgsLayerTreeModel( QgsLayerTree* rootNode, QObject *parent /TransferThis/ = 0 );
~QgsLayerTreeModel();

// Implementation of virtual functions from QAbstractItemModel
@@ -118,10 +118,10 @@ class QgsLayerTreeModel : QAbstractItemModel
QgsLayerTreeModelLegendNode* findLegendNode( const QString& layerId, const QString& ruleKey ) const;

//! Return pointer to the root node of the layer tree. Always a non-null pointer.
QgsLayerTreeGroup* rootGroup() const;
QgsLayerTree* rootGroup() const;
//! Reset the model and use a new root group node
//! @note added in 2.6
void setRootGroup( QgsLayerTreeGroup* newRootGroup );
void setRootGroup( QgsLayerTree* newRootGroup );

//! Force a refresh of legend nodes of a layer node.
//! Not necessary to call when layer's renderer is changed as the model listens to these events.
@@ -16,7 +16,7 @@ class QgsLayerTreeUtils
//! Try to load custom layer order from \verbatim <legend> \endverbatim tag from project files from QGIS 2.2 and below
static bool readOldLegendLayerOrder( const QDomElement& legendElem, bool& hasCustomOrder, QStringList& order );
//! Return \verbatim <legend> \endverbatim tag used in QGIS 2.2 and below
static QDomElement writeOldLegend( QDomDocument& doc, QgsLayerTreeGroup* root, bool hasCustomOrder, const QStringList& order );
static QDomElement writeOldLegend( QDomDocument& doc, QgsLayerTreeGroup* root, bool hasCustomOrder, const QList<QgsMapLayer *> &order );

//! Convert Qt::CheckState to QString
static QString checkStateToXml( Qt::CheckState state );
@@ -486,9 +486,6 @@ class QgsProject : QObject, QgsExpressionContextGenerator
*/
void reloadAllLayers();

QList< QgsMapLayer * > layerOrder() const;
void setLayerOrder( const QList< QgsMapLayer * > &order );

signals:
//! emitted when project is being read
void readProject( const QDomDocument& );
@@ -630,7 +627,6 @@ class QgsProject : QObject, QgsExpressionContextGenerator
void layerWasAdded( QgsMapLayer *layer );
void legendLayersAdded( const QList<QgsMapLayer *> &layers );

void layerOrderChanged();

public slots:
/**
@@ -16,12 +16,4 @@ class QgsCustomLayerOrderWidget : QWidget

public:
explicit QgsCustomLayerOrderWidget( QgsLayerTreeMapCanvasBridge* bridge, QWidget *parent /TransferThis/ = 0 );

protected slots:
void bridgeHasCustomLayerOrderChanged( bool state );
void bridgeCustomLayerOrderChanged( const QStringList& order );
//! Slot triggered when the ivsibility of a node changes
void nodeVisibilityChanged( QgsLayerTreeNode* node );

void modelUpdated();
};
@@ -21,57 +21,26 @@ class QgsLayerTreeMapCanvasBridge : QObject

public:
//! Constructor: does not take ownership of the layer tree nor canvas
QgsLayerTreeMapCanvasBridge( QgsLayerTreeGroup* root, QgsMapCanvas* canvas, QObject* parent /TransferThis/ = 0 );
QgsLayerTreeMapCanvasBridge( QgsLayerTree* root, QgsMapCanvas* canvas, QObject* parent /TransferThis/ = 0 );

void clear();

QgsLayerTreeGroup* rootGroup() const;
QgsMapCanvas* mapCanvas() const;
QgsLayerTree *rootGroup() const;
QgsMapCanvas *mapCanvas() const;

//! Associates overview canvas with the bridge, so the overview will be updated whenever main canvas is updated
//! @note added in 3.0
void setOvervewCanvas( QgsMapOverviewCanvas* overviewCanvas );
//! Returns associated overview canvas (may be null)
//! @note added in 3.0
QgsMapOverviewCanvas* overviewCanvas() const;

bool hasCustomLayerOrder() const;
QStringList customLayerOrder() const;

QStringList defaultLayerOrder() const;
QgsMapOverviewCanvas *overviewCanvas() const;

//! if enabled, will automatically set full canvas extent and destination CRS + map units
//! when first layer(s) are added
void setAutoSetupOnFirstLayer( bool enabled );
bool autoSetupOnFirstLayer() const;

public slots:
void setHasCustomLayerOrder( bool state );
void setCustomLayerOrder( const QStringList& order );

//! force update of canvas layers from the layer tree. Normally this should not be needed to be called.
void setCanvasLayers();

void readProject( const QDomDocument& doc );
void writeProject( QDomDocument& doc );

signals:
void hasCustomLayerOrderChanged( bool );
void customLayerOrderChanged( const QStringList& order );
void canvasLayersChanged( const QList< QgsMapLayer* >& layers );

protected:

void defaultLayerOrder( QgsLayerTreeNode* node, QStringList& order ) const;

void setCanvasLayers( QgsLayerTreeNode *node, QList<QgsMapLayer *> &canvasLayers, QList<QgsMapLayer *> &overviewLayers,
QList<QgsMapLayer *> &allLayers );

void deferredSetCanvasLayers();

protected slots:
void nodeAddedChildren( QgsLayerTreeNode* node, int indexFrom, int indexTo );
void nodeRemovedChildren();
void nodeVisibilityChanged();
void nodeCustomPropertyChanged( QgsLayerTreeNode* node, const QString& key );
};
@@ -42,6 +42,7 @@
#include "qgsmessagelog.h"
#include "qgslogger.h"
#include "qgsproperty.h"
#include "qgslayertree.h"


struct CursorOverride
@@ -3378,8 +3378,6 @@ void QgisApp::initLayerTreeView()
addDockWidget( Qt::LeftDockWidgetArea, mLayerTreeDock );

mLayerTreeCanvasBridge = new QgsLayerTreeMapCanvasBridge( QgsProject::instance()->layerTreeRoot(), mMapCanvas, this );
connect( QgsProject::instance(), &QgsProject::writeProject, mLayerTreeCanvasBridge, &QgsLayerTreeMapCanvasBridge::writeProject );
connect( QgsProject::instance(), &QgsProject::readProject, mLayerTreeCanvasBridge, &QgsLayerTreeMapCanvasBridge::readProject );

mMapLayerOrder = new QgsCustomLayerOrderWidget( mLayerTreeCanvasBridge, this );
mMapLayerOrder->setObjectName( QStringLiteral( "theMapLayerOrder" ) );
@@ -4769,8 +4767,6 @@ void QgisApp::fileNew( bool promptToSaveFlag, bool forceBlank )

prj->layerTreeRegistryBridge()->setNewLayersVisible( settings.value( QStringLiteral( "qgis/new_layers_visible" ), true ).toBool() );

mLayerTreeCanvasBridge->clear();

//set the color for selections
//the default can be set in qgisoptions
//use project properties to override the color on a per project basis
@@ -11833,11 +11829,11 @@ void QgisApp::writeProject( QDomDocument &doc )
// The <legend> tag is ignored by QGIS application in >= 2.4 and this way also the new project files
// can be opened in older versions of QGIS without losing information about layer groups.

QgsLayerTreeNode *clonedRoot = QgsProject::instance()->layerTreeRoot()->clone();
QgsLayerTree *clonedRoot = QgsProject::instance()->layerTreeRoot()->clone();
QgsLayerTreeUtils::replaceChildrenOfEmbeddedGroups( QgsLayerTree::toGroup( clonedRoot ) );
QgsLayerTreeUtils::updateEmbeddedGroupsProjectPath( QgsLayerTree::toGroup( clonedRoot ), QgsProject::instance() ); // convert absolute paths to relative paths if required
QDomElement oldLegendElem = QgsLayerTreeUtils::writeOldLegend( doc, QgsLayerTree::toGroup( clonedRoot ),
mLayerTreeCanvasBridge->hasCustomLayerOrder(), mLayerTreeCanvasBridge->customLayerOrder() );
clonedRoot->hasCustomLayerOrder(), clonedRoot->customLayerOrder() );
delete clonedRoot;
QDomElement qgisNode = doc.firstChildElement( QStringLiteral( "qgis" ) );
qgisNode.appendChild( oldLegendElem );
@@ -94,7 +94,7 @@ void FieldSelectorDelegate::setModelData( QWidget *editor, QAbstractItemModel *m
model->setData( index, vl->fields().lookupField( fcb->currentField() ) );
}

QgsVectorLayerAndAttributeModel::QgsVectorLayerAndAttributeModel( QgsLayerTreeGroup *rootNode, QObject *parent )
QgsVectorLayerAndAttributeModel::QgsVectorLayerAndAttributeModel( QgsLayerTree *rootNode, QObject *parent )
: QgsLayerTreeModel( rootNode, parent )
{
}
@@ -312,13 +312,18 @@ QList< QPair<QgsVectorLayer *, int> > QgsVectorLayerAndAttributeModel::layers()
}
}

QgsLayerTreeMapCanvasBridge *bridge = QgisApp::instance()->layerTreeCanvasBridge();
QStringList inDrawingOrder = bridge->hasCustomLayerOrder() ? bridge->customLayerOrder() : bridge->defaultLayerOrder();
QList< QPair<QgsVectorLayer *, int> > layersInROrder;

for ( int i = inDrawingOrder.size() - 1; i >= 0; i-- )
QList<QgsMapLayer *> layerOrder = mRootNode->layerOrder();

QList<QgsMapLayer *>::ConstIterator layerIterator = layerOrder.constEnd();

while ( layerIterator != layerOrder.constBegin() )
{
int idx = layerIdx.value( inDrawingOrder[i], -1 );
--layerIterator;

QgsMapLayer *l = *layerIterator;
int idx = layerIdx.value( l->id(), -1 );
if ( idx < 0 )
continue;

@@ -422,7 +427,7 @@ QgsDxfExportDialog::QgsDxfExportDialog( QWidget *parent, Qt::WindowFlags f )
{
setupUi( this );

mLayerTreeGroup = QgsLayerTree::toGroup( QgsProject::instance()->layerTreeRoot()->clone() );
mLayerTreeGroup = QgsProject::instance()->layerTreeRoot()->clone();
cleanGroup( mLayerTreeGroup );

mFieldSelectorDelegate = new FieldSelectorDelegate( this );
@@ -45,7 +45,7 @@ class QgsVectorLayerAndAttributeModel : public QgsLayerTreeModel
{
Q_OBJECT
public:
QgsVectorLayerAndAttributeModel( QgsLayerTreeGroup *rootNode, QObject *parent = nullptr );
QgsVectorLayerAndAttributeModel( QgsLayerTree *rootNode, QObject *parent = nullptr );
~QgsVectorLayerAndAttributeModel();

int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
@@ -105,7 +105,7 @@ class QgsDxfExportDialog : public QDialog, private Ui::QgsDxfExportDialogBase

private:
void cleanGroup( QgsLayerTreeNode *node );
QgsLayerTreeGroup *mLayerTreeGroup = nullptr;
QgsLayerTree *mLayerTreeGroup = nullptr;
FieldSelectorDelegate *mFieldSelectorDelegate = nullptr;

QgsCoordinateReferenceSystem mCRS;
@@ -86,15 +86,12 @@ QList<QgsMapLayer *> QgsMapThemes::orderedPresetVisibleLayers( const QString &na
QStringList visibleIds = QgsProject::instance()->mapThemeCollection()->mapThemeVisibleLayerIds( name );

// also make sure to order the layers according to map canvas order
QgsLayerTreeMapCanvasBridge *bridge = QgisApp::instance()->layerTreeCanvasBridge();
QStringList order = bridge->hasCustomLayerOrder() ? bridge->customLayerOrder() : bridge->defaultLayerOrder();
QList<QgsMapLayer *> lst;
Q_FOREACH ( const QString &layerID, order )
Q_FOREACH ( QgsMapLayer *layer, QgsProject::instance()->layerTreeRoot()->layerOrder() )
{
if ( visibleIds.contains( layerID ) )
if ( visibleIds.contains( layer->id() ) )
{
if ( QgsMapLayer *layer = QgsProject::instance()->mapLayer( layerID ) )
lst << layer;
lst << layer;
}
}
return lst;
@@ -29,7 +29,7 @@
QgsProjectLayerGroupDialog::QgsProjectLayerGroupDialog( QWidget *parent, const QString &projectFile, Qt::WindowFlags f )
: QDialog( parent, f )
, mShowEmbeddedContent( false )
, mRootGroup( new QgsLayerTreeGroup )
, mRootGroup( new QgsLayerTree )
{
setupUi( this );

@@ -21,7 +21,7 @@

class QDomElement;

class QgsLayerTreeGroup;
class QgsLayerTree;

//! A dialog to select layers and groups from a qgs project
class APP_EXPORT QgsProjectLayerGroupDialog: public QDialog, private Ui::QgsProjectLayerGroupDialogBase
@@ -52,7 +52,7 @@ class APP_EXPORT QgsProjectLayerGroupDialog: public QDialog, private Ui::QgsProj
QString mProjectPath;
bool mShowEmbeddedContent;

QgsLayerTreeGroup *mRootGroup = nullptr;
QgsLayerTree *mRootGroup = nullptr;
};

#endif //QGSPROJECTLAYERGROUPDIALOG_H
@@ -54,6 +54,7 @@
#include "qgslayertreemodel.h"
#include "qgsunittypes.h"
#include "qgstablewidgetitem.h"
#include "qgslayertree.h"

#include "qgsmessagelog.h"

@@ -57,6 +57,7 @@
#include "qgsstyle.h"

#include "layertree/qgslayertreelayer.h"
#include "qgslayertree.h"

#include <QMessageBox>
#include <QDir>
@@ -196,7 +196,7 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private

QgsExpressionContext createExpressionContext() const override;

std::unique_ptr<QgsLayerTreeGroup> mLayersDependenciesTreeGroup;
std::unique_ptr<QgsLayerTree> mLayersDependenciesTreeGroup;
std::unique_ptr<QgsLayerTreeModel> mLayersDependenciesTreeModel;

private slots:
@@ -69,6 +69,7 @@ SET(QGIS_CORE_SRCS
layertree/qgslayertreenode.cpp
layertree/qgslayertreeregistrybridge.cpp
layertree/qgslayertreeutils.cpp
layertree/qgslayertree.cpp

auth/qgsauthcertutils.cpp
auth/qgsauthconfig.cpp
@@ -605,6 +606,7 @@ SET(QGIS_CORE_MOC_HDRS
symbology-ng/qgssvgcache.h
symbology-ng/qgsstyle.h

layertree/qgslayertree.h
layertree/qgslayertreegroup.h
layertree/qgslayertreelayer.h
layertree/qgslayertreemodel.h
@@ -899,7 +901,6 @@ SET(QGIS_CORE_HDRS
symbology-ng/qgsvectorfieldsymbollayer.h
symbology-ng/qgsgeometrygeneratorsymbollayer.h

layertree/qgslayertree.h
layertree/qgslayertreeutils.h

geometry/qgsabstractgeometry.h

0 comments on commit f33aabd

Please sign in to comment.