初步实现单独的图层管理器。
注意:没有和mapcavas通讯。
This commit is contained in:
110
HPPA/LayerTreeNode.cpp
Normal file
110
HPPA/LayerTreeNode.cpp
Normal file
@ -0,0 +1,110 @@
|
||||
#include "LayerTreeNode.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
LayerTreeNode::LayerTreeNode(const QString& name, QObject* parent)
|
||||
: QObject(parent), m_name(name)
|
||||
{
|
||||
}
|
||||
|
||||
LayerTreeNode::~LayerTreeNode()
|
||||
{
|
||||
qDeleteAll(m_children);
|
||||
m_children.clear();
|
||||
}
|
||||
|
||||
QString LayerTreeNode::name() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
void LayerTreeNode::setName(const QString& name)
|
||||
{
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
QIcon LayerTreeNode::icon() const
|
||||
{
|
||||
return m_icon;
|
||||
}
|
||||
|
||||
void LayerTreeNode::setIcon(const QIcon& icon)
|
||||
{
|
||||
m_icon = icon;
|
||||
}
|
||||
|
||||
Qt::CheckState LayerTreeNode::visible() const
|
||||
{
|
||||
return m_visible;
|
||||
}
|
||||
|
||||
void LayerTreeNode::setVisible(Qt::CheckState s)
|
||||
{
|
||||
m_visible = s;
|
||||
}
|
||||
|
||||
LayerTreeNode* LayerTreeNode::parentNode() const
|
||||
{
|
||||
return m_parentNode;
|
||||
}
|
||||
|
||||
void LayerTreeNode::setParentNode(LayerTreeNode* p)
|
||||
{
|
||||
m_parentNode = p;
|
||||
// <20><> QObject <20><> parent Ҳ<><D2B2><EFBFBD>棨<EFBFBD><E6A3A8><EFBFBD><EFBFBD> Qt <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ι<EFBFBD><CEB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD>Ӱ<EFBFBD><D3B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD> delete children<65><6E>
|
||||
if (p) this->setParent(p);
|
||||
else this->setParent(nullptr);
|
||||
}
|
||||
|
||||
int LayerTreeNode::rowInParent() const
|
||||
{
|
||||
if (!m_parentNode) return 0;
|
||||
|
||||
const auto& siblings = m_parentNode->m_children;
|
||||
for (int i = 0; i < siblings.size(); ++i)
|
||||
{
|
||||
if (siblings[i] == this) return i;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LayerTreeNode::childCount() const
|
||||
{
|
||||
return m_children.size();
|
||||
}
|
||||
|
||||
LayerTreeNode* LayerTreeNode::childAt(int row) const
|
||||
{
|
||||
if (row < 0 || row >= m_children.size()) return nullptr;
|
||||
return m_children[row];
|
||||
}
|
||||
|
||||
const QVector<LayerTreeNode*>& LayerTreeNode::children() const
|
||||
{
|
||||
return m_children;
|
||||
}
|
||||
|
||||
void LayerTreeNode::appendChild(LayerTreeNode* child)
|
||||
{
|
||||
insertChild(m_children.size(), child);
|
||||
}
|
||||
|
||||
void LayerTreeNode::insertChild(int row, LayerTreeNode* child)
|
||||
{
|
||||
if (!child) return;
|
||||
|
||||
if (row < 0 || row > m_children.size())
|
||||
row = m_children.size();
|
||||
|
||||
child->setParentNode(this);
|
||||
m_children.insert(row, child);
|
||||
}
|
||||
|
||||
LayerTreeNode* LayerTreeNode::takeChild(int row)
|
||||
{
|
||||
if (row < 0 || row >= m_children.size()) return nullptr;
|
||||
LayerTreeNode* taken = m_children.takeAt(row);
|
||||
if (taken) taken->setParentNode(nullptr);
|
||||
return taken;
|
||||
}
|
||||
Reference in New Issue
Block a user