Skip to content
Permalink
Browse files
Updates to QGIS app to use layer tree view instead of legend widget
  • Loading branch information
wonder-sk committed May 21, 2014
1 parent bbdf144 commit 21b2a9a7747921717c64cda858de960370597661

Large diffs are not rendered by default.

@@ -242,6 +242,19 @@ QgsLayerTreeLayer *QgsLayerTreeGroup::findLayer(const QString& layerId)
return 0;
}

QList<QgsLayerTreeLayer*> QgsLayerTreeGroup::findLayers() const
{
QList<QgsLayerTreeLayer*> list;
foreach (QgsLayerTreeNode* child, mChildren)
{
if (child->nodeType() == QgsLayerTreeNode::NodeLayer)
list << static_cast<QgsLayerTreeLayer*>(child);
else if (child->nodeType() == QgsLayerTreeNode::NodeGroup)
list << static_cast<QgsLayerTreeGroup*>(child)->findLayers();
}
return list;
}

QgsLayerTreeGroup* QgsLayerTreeGroup::findGroup(const QString& name)
{
foreach (QgsLayerTreeNode* child, mChildren)
@@ -163,6 +163,7 @@ class QgsLayerTreeGroup : public QgsLayerTreeNode
void removeAllChildren();

QgsLayerTreeLayer* findLayer(const QString& layerId);
QList<QgsLayerTreeLayer*> findLayers() const;
QgsLayerTreeGroup* findGroup(const QString& name);

static QgsLayerTreeGroup* readXML(QDomElement& element);
@@ -2,6 +2,8 @@

#include "qgslayertreenode.h"

#include "qgsvectorlayer.h"

#include <QDomElement>

bool QgsLayerTreeUtils::readOldLegend(QgsLayerTreeGroup* root, const QDomElement& legendElem)
@@ -92,3 +94,33 @@ void QgsLayerTreeUtils::addLegendLayerToTreeWidget( const QDomElement& layerElem

parent->addChildNode(layerNode);
}



bool QgsLayerTreeUtils::layersEditable( const QList<QgsLayerTreeLayer*>& layerNodes )
{
foreach ( QgsLayerTreeLayer* layerNode, layerNodes )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer*>( layerNode->layer() );
if ( !vl )
continue;

if ( vl->isEditable() )
return true;
}
return false;
}

bool QgsLayerTreeUtils::layersModified( const QList<QgsLayerTreeLayer*>& layerNodes )
{
foreach ( QgsLayerTreeLayer* layerNode, layerNodes )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer*>( layerNode->layer() );
if ( !vl )
continue;

if ( vl->isEditable() && vl->isModified() )
return true;
}
return false;
}
@@ -2,10 +2,12 @@
#define QGSLAYERTREEUTILS_H

#include <qnamespace.h>
#include <QList>

class QDomElement;

class QgsLayerTreeGroup;
class QgsLayerTreeLayer;

class CORE_EXPORT QgsLayerTreeUtils
{
@@ -17,6 +19,8 @@ class CORE_EXPORT QgsLayerTreeUtils
static QString checkStateToXml(Qt::CheckState state);
static Qt::CheckState checkStateFromXml(QString txt);

static bool layersEditable( const QList<QgsLayerTreeLayer*>& layerNodes );
static bool layersModified( const QList<QgsLayerTreeLayer*>& layerNodes );


protected:
@@ -186,3 +186,14 @@ QList<QgsLayerTreeLayer*> QgsLayerTreeView::selectedLayerNodes() const
}
return layerNodes;
}

QList<QgsMapLayer*> QgsLayerTreeView::selectedLayers() const
{
QList<QgsMapLayer*> list;
foreach (QgsLayerTreeLayer* node, selectedLayerNodes())
{
if (node->layer())
list << node->layer();
}
return list;
}
@@ -36,6 +36,8 @@ class GUI_EXPORT QgsLayerTreeView : public QTreeView
QList<QgsLayerTreeNode*> selectedNodes(bool skipInternal = false) const;
QList<QgsLayerTreeLayer*> selectedLayerNodes() const;

QList<QgsMapLayer*> selectedLayers() const;

protected:
void contextMenuEvent(QContextMenuEvent* event);

@@ -29,7 +29,7 @@ class GUI_EXPORT QgsLayerTreeViewDefaultActions : public QObject
QAction* actionMakeTopLevel(QObject* parent = 0);
QAction* actionGroupSelected(QObject* parent = 0);

protected slots:
public slots:
void addGroup();
void removeGroupOrLayer();
void renameGroupOrLayer();

0 comments on commit 21b2a9a

Please sign in to comment.