Skip to content
Permalink
Browse files
Loading and saving of custom layer order
  • Loading branch information
wonder-sk committed May 21, 2014
1 parent 55c4ae5 commit 393a41588e8d3f91980d340086e4a6ad4407173e
@@ -2227,25 +2227,18 @@ void QgisApp::initLayerTreeView()
addDockWidget( Qt::LeftDockWidgetArea, mLayerTreeDock );

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

mMapLayerOrder = new QgsCustomLayerOrderWidget(mLayerTreeCanvasBridge, this);
mMapLayerOrder->setObjectName("theMapLayerOrder");

QCheckBox *orderCb = new QCheckBox( tr( "Control rendering order" ) );
orderCb->setChecked( false );

mMapLayerOrder->setWhatsThis( tr( "Map layer list that displays all layers in drawing order." ) );
mLayerOrderDock = new QDockWidget( tr( "Layer order" ), this );
mLayerOrderDock->setObjectName( "LayerOrder" );
mLayerOrderDock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );

QWidget* w = new QWidget( this );
QVBoxLayout* l = new QVBoxLayout;
l->setMargin( 0 );
l->addWidget( mMapLayerOrder );
l->addWidget( orderCb );
w->setLayout( l );
mLayerOrderDock->setWidget( w );
mLayerOrderDock->setWidget( mMapLayerOrder );
addDockWidget( Qt::LeftDockWidgetArea, mLayerOrderDock );
mLayerOrderDock->hide();
}
@@ -3263,6 +3256,8 @@ void QgisApp::fileNew( bool thePromptToSaveFlag, bool forceBlank )
QgsProject* prj = QgsProject::instance();
prj->clear();

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
@@ -22,6 +22,12 @@ QgsLayerTreeMapCanvasBridge::QgsLayerTreeMapCanvasBridge(QgsLayerTreeGroup *root
setCanvasLayers();
}

void QgsLayerTreeMapCanvasBridge::clear()
{
setHasCustomLayerOrder(false);
setCustomLayerOrder(defaultLayerOrder());
}

QStringList QgsLayerTreeMapCanvasBridge::defaultLayerOrder() const
{
QStringList order;
@@ -147,6 +153,45 @@ void QgsLayerTreeMapCanvasBridge::setCanvasLayers()
mPendingCanvasUpdate = false;
}

void QgsLayerTreeMapCanvasBridge::readProject(const QDomDocument& doc)
{
QDomElement elem = doc.documentElement().firstChildElement("layer-tree-canvas");
if (elem.isNull())
return;

QDomElement customOrderElem = elem.firstChildElement("custom-order");
if (!customOrderElem.isNull())
{
QStringList order;
QDomElement itemElem = customOrderElem.firstChildElement("item");
while (!itemElem.isNull())
{
order.append(itemElem.text());
itemElem = itemElem.nextSiblingElement("item");
}

setHasCustomLayerOrder( customOrderElem.attribute("enabled", 0).toInt() );
setCustomLayerOrder(order);
}
}

void QgsLayerTreeMapCanvasBridge::writeProject(QDomDocument& doc)
{
QDomElement elem = doc.createElement("layer-tree-canvas");
QDomElement customOrderElem = doc.createElement("custom-order");
customOrderElem.setAttribute("enabled", mHasCustomLayerOrder ? 1 : 0);

foreach (QString layerId, mCustomLayerOrder)
{
QDomElement itemElem = doc.createElement("item");
itemElem.appendChild(doc.createTextNode(layerId));
customOrderElem.appendChild(itemElem);
}
elem.appendChild(customOrderElem);

doc.documentElement().appendChild(elem);
}

void QgsLayerTreeMapCanvasBridge::setCanvasLayers(QgsLayerTreeNode *node, QList<QgsMapCanvasLayer> &layers)
{
if (QgsLayerTree::isLayer(node))
@@ -17,6 +17,8 @@ class GUI_EXPORT QgsLayerTreeMapCanvasBridge : public QObject
public:
QgsLayerTreeMapCanvasBridge(QgsLayerTreeGroup* root, QgsMapCanvas* canvas, QObject* parent = 0);

void clear();

bool hasCustomLayerOrder() const { return mHasCustomLayerOrder; }
QStringList customLayerOrder() const { return mCustomLayerOrder; }

@@ -39,6 +41,9 @@ public slots:
//! 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);

0 comments on commit 393a415

Please sign in to comment.