You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
2.2 KiB
C++
90 lines
2.2 KiB
C++
|
|
#pragma once
|
|
|
|
#include "iBase_global.h"
|
|
|
|
#include <QHash>
|
|
#include <QString>
|
|
|
|
class QDataStream;
|
|
|
|
// XPF文件格式节点
|
|
class I_BASE_EXPORT ZxXpfNode
|
|
{
|
|
public:
|
|
ZxXpfNode();
|
|
virtual ~ZxXpfNode();
|
|
|
|
public:
|
|
// 获取根节点
|
|
ZxXpfNode* getRoot() const;
|
|
|
|
// 获取父节点
|
|
ZxXpfNode* getParent() const;
|
|
|
|
// 获取节点名字
|
|
const QString& getName() const;
|
|
|
|
// 设置节点名字
|
|
void setName(const QString& sName);
|
|
|
|
#ifdef QT_DEBUG
|
|
// 把树结构以文本方式输出到Debug窗口,暂未启用
|
|
void dump(int indent = 0);
|
|
#endif
|
|
|
|
// 添加/插入子节点
|
|
ZxXpfNode* addChild(ZxXpfNode* pNode);
|
|
ZxXpfNode* addChild(ZxXpfNode* pNode, int nPos);
|
|
ZxXpfNode* addChild(ZxXpfNode* pNode, ZxXpfNode* pInsertBefore);
|
|
ZxXpfNode* addChild(const QString& sName);
|
|
ZxXpfNode* addChild(const QString& sName, const QVariant& data);
|
|
|
|
// 添加无名子节点, 并在子节点中存入数据.
|
|
ZxXpfNode* addUnnamedChild(const QVariant& data);
|
|
|
|
// 查找指定名字的节点.
|
|
ZxXpfNode* findChild(const QString& sName, bool bCreateIfNotFound = false);
|
|
|
|
// 当前节点的数据
|
|
void setData(const QVariant& d);
|
|
const QVariant& getData() const;
|
|
|
|
// 从树上移除节点.
|
|
void detach();
|
|
|
|
// 删除当前结点数据并删除所有子节点
|
|
void clear();
|
|
|
|
// 获取/设定指定属性.
|
|
const QVariant& getAttribute(const QString& key);
|
|
QVariant getAttribute(const QString& key, const QVariant& defaultValue);
|
|
void setAttribute(const QString& key, const QVariant& v);
|
|
|
|
// 克隆
|
|
virtual ZxXpfNode* clone() const;
|
|
void makeIndex(ZxXpfNode* p);
|
|
|
|
// 获取子节点
|
|
const QVector<ZxXpfNode*>& getChildren() const;
|
|
typedef QHash<QString, ZxXpfNode*> ChildrenMap;
|
|
ChildrenMap* getChildrenMap();
|
|
void releaseMap();
|
|
|
|
// 存取/加载入口
|
|
bool loadNode(QDataStream& stream);
|
|
bool saveNode(QDataStream& stream);
|
|
|
|
protected:
|
|
|
|
// 涉及的一些内部变量
|
|
int m_nProperChildCount;
|
|
QString m_sName;
|
|
QVariant* m_pData;
|
|
ZxXpfNode* m_pParent;
|
|
ChildrenMap* m_pChildrenMap;
|
|
QVector<ZxXpfNode*> m_vecChildren;
|
|
|
|
friend class ZxXpfDoc;
|
|
};
|