Skip to content
Permalink
Browse files
Use Qt::CheckState also for layer node visibility (for consistency)
  • Loading branch information
wonder-sk committed May 21, 2014
1 parent 8a539e0 commit 36d8d88e09fda643a6865761f67fff80153c8876
@@ -4211,7 +4211,7 @@ void QgisApp::hideAllLayers()
QgsDebugMsg( "hiding all layers!" );

foreach ( QgsLayerTreeLayer* nodeLayer, mLayerTreeView->layerTreeModel()->rootGroup()->findLayers() )
nodeLayer->setVisible( false );
nodeLayer->setVisible( Qt::Unchecked );
}


@@ -4221,7 +4221,7 @@ void QgisApp::showAllLayers()
QgsDebugMsg( "Showing all layers!" );

foreach ( QgsLayerTreeLayer* nodeLayer, mLayerTreeView->layerTreeModel()->rootGroup()->findLayers() )
nodeLayer->setVisible( true );
nodeLayer->setVisible( Qt::Checked );
}


@@ -248,7 +248,7 @@ void QgsLayerTreeGroup::setVisible(Qt::CheckState state)
if (QgsLayerTree::isGroup(child))
QgsLayerTree::toGroup(child)->setVisible(mChecked);
else if (QgsLayerTree::isLayer(child))
QgsLayerTree::toLayer(child)->setVisible(mChecked == Qt::Checked);
QgsLayerTree::toLayer(child)->setVisible(mChecked);
}

mChangingChildVisibility = false;
@@ -289,7 +289,7 @@ void QgsLayerTreeGroup::updateVisibilityFromChildren()
{
if (QgsLayerTree::isLayer(child))
{
bool layerVisible = QgsLayerTree::toLayer(child)->isVisible();
bool layerVisible = QgsLayerTree::toLayer(child)->isVisible() == Qt::Checked;
if (layerVisible) hasVisible = true;
if (!layerVisible) hasHidden = true;
}
@@ -1,10 +1,11 @@
#include "qgslayertreelayer.h"

#include "qgslayertreeutils.h"
#include "qgsmaplayerregistry.h"


QgsLayerTreeLayer::QgsLayerTreeLayer(QgsMapLayer *layer)
: QgsLayerTreeNode(NodeLayer), mLayerId(layer->id()), mLayer(layer), mVisible(true)
: QgsLayerTreeNode(NodeLayer), mLayerId(layer->id()), mLayer(layer), mVisible(Qt::Checked)
{
Q_ASSERT( QgsMapLayerRegistry::instance()->mapLayer(mLayerId) == layer );
}
@@ -14,7 +15,7 @@ QgsLayerTreeLayer::QgsLayerTreeLayer(QString layerId, QString name)
, mLayerId(layerId)
, mLayerName(name)
, mLayer(0)
, mVisible(true)
, mVisible(Qt::Checked)
{
attachToLayer();
}
@@ -47,13 +48,13 @@ void QgsLayerTreeLayer::attachToLayer()
}
}

void QgsLayerTreeLayer::setVisible(bool state)
void QgsLayerTreeLayer::setVisible(Qt::CheckState state)
{
if (mVisible == state)
return;

mVisible = state;
emit visibilityChanged(state ? Qt::Checked : Qt::Unchecked);
emit visibilityChanged(state);
}

QgsLayerTreeLayer* QgsLayerTreeLayer::readXML(QDomElement& element)
@@ -63,7 +64,7 @@ QgsLayerTreeLayer* QgsLayerTreeLayer::readXML(QDomElement& element)

QString layerID = element.attribute("id");
QString layerName = element.attribute("name");
bool visible = element.attribute("visible").toInt();
Qt::CheckState checked = QgsLayerTreeUtils::checkStateFromXml(element.attribute("checked"));
bool isExpanded = (element.attribute("expanded", "1") == "1");

QgsLayerTreeLayer* nodeLayer = 0;
@@ -78,7 +79,7 @@ QgsLayerTreeLayer* QgsLayerTreeLayer::readXML(QDomElement& element)

nodeLayer->readCommonXML(element);

nodeLayer->setVisible(visible);
nodeLayer->setVisible(checked);
nodeLayer->setExpanded(isExpanded);
return nodeLayer;
}
@@ -89,7 +90,7 @@ void QgsLayerTreeLayer::writeXML(QDomElement& parentElement)
QDomElement elem = doc.createElement("layer-tree-layer");
elem.setAttribute("id", mLayerId);
elem.setAttribute("name", layerName());
elem.setAttribute("visible", mVisible ? "1" : "0");
elem.setAttribute("checked", QgsLayerTreeUtils::checkStateToXml(mVisible));
elem.setAttribute("expanded", mExpanded ? "1" : "0");

writeCommonXML(elem);
@@ -30,8 +30,8 @@ class QgsLayerTreeLayer : public QgsLayerTreeNode
QString layerName() const { return mLayer ? mLayer->name() : mLayerName; }
void setLayerName(const QString& n) { if (mLayer) mLayer->setLayerName(n); else mLayerName = n; }

bool isVisible() const { return mVisible; }
void setVisible(bool state);
Qt::CheckState isVisible() const { return mVisible; }
void setVisible(Qt::CheckState visible);

static QgsLayerTreeLayer* readXML(QDomElement& element);
virtual void writeXML(QDomElement& parentElement);
@@ -53,7 +53,7 @@ protected slots:
QString mLayerId;
QString mLayerName; // only used if layer does not exist
QgsMapLayer* mLayer; // not owned! may be null
bool mVisible;
Qt::CheckState mVisible;
};


@@ -94,7 +94,7 @@ void QgsLayerTreeMapCanvasBridge::setCanvasLayers()
{
QgsLayerTreeLayer* nodeLayer = mRoot->findLayer(layerId);
if (nodeLayer)
layers << QgsMapCanvasLayer(nodeLayer->layer(), nodeLayer->isVisible(), nodeLayer->customProperty("overview", 0).toInt());
layers << QgsMapCanvasLayer(nodeLayer->layer(), nodeLayer->isVisible() == Qt::Checked, nodeLayer->customProperty("overview", 0).toInt());
}
}
else
@@ -110,7 +110,7 @@ void QgsLayerTreeMapCanvasBridge::setCanvasLayers(QgsLayerTreeNode *node, QList<
if (QgsLayerTree::isLayer(node))
{
QgsLayerTreeLayer* nodeLayer = QgsLayerTree::toLayer(node);
layers << QgsMapCanvasLayer(nodeLayer->layer(), nodeLayer->isVisible(), nodeLayer->customProperty("overview", 0).toInt());
layers << QgsMapCanvasLayer(nodeLayer->layer(), nodeLayer->isVisible() == Qt::Checked, nodeLayer->customProperty("overview", 0).toInt());
}

foreach (QgsLayerTreeNode* child, node->children())
@@ -212,7 +212,7 @@ QVariant QgsLayerTreeModel::data(const QModelIndex &index, int role) const
if (QgsLayerTree::isLayer(node))
{
QgsLayerTreeLayer* nodeLayer = QgsLayerTree::toLayer(node);
return nodeLayer->isVisible() ? Qt::Checked : Qt::Unchecked;
return nodeLayer->isVisible();
}
else if (QgsLayerTree::isGroup(node))
{
@@ -264,7 +264,7 @@ bool QgsLayerTreeModel::setData(const QModelIndex& index, const QVariant& value,
if (QgsLayerTree::isLayer(node))
{
QgsLayerTreeLayer* layer = QgsLayerTree::toLayer(node);
layer->setVisible(value.toInt() == Qt::Checked);
layer->setVisible((Qt::CheckState)value.toInt());
}
else if (QgsLayerTree::isGroup(node))
{

0 comments on commit 36d8d88

Please sign in to comment.