69 lines
1.6 KiB
C++
69 lines
1.6 KiB
C++
#pragma once
|
|
#include <QVector>
|
|
#include <QStack>
|
|
namespace Psc {
|
|
class Node {
|
|
public:
|
|
explicit Node();
|
|
//判断状态
|
|
int index();
|
|
bool isRoot();
|
|
bool isLeaf();
|
|
bool isFirst();
|
|
bool isLast();
|
|
Node *previous();
|
|
Node *next();
|
|
Node *lastChild();
|
|
Node *firstChild();
|
|
Node *root();
|
|
int getDeep();
|
|
//遍历值
|
|
QVector<Node *> deepTraversed();
|
|
QVector<Node *> sequenceTraversed();
|
|
QVector<Node *> descendants();
|
|
|
|
|
|
Node *par = nullptr;
|
|
QVector<Node*> sons;
|
|
QString text;
|
|
bool expand = true;
|
|
int height = 20;
|
|
|
|
void addChild(Node *child) {
|
|
sons.append(child);
|
|
child->par = this;
|
|
}
|
|
};
|
|
|
|
|
|
struct Tree_Pos {
|
|
Node *p{};
|
|
int depth{};
|
|
int node_pos{};
|
|
int offset{};
|
|
int pos() {return node_pos + offset;}
|
|
QStack<QPair<Node*, int>> rest;
|
|
};
|
|
|
|
|
|
class Tree_Model {
|
|
public:
|
|
QVector<Node*> roots;
|
|
int tab_pixel_size = 8;
|
|
int png_len = 20;
|
|
int tab_width = 10;
|
|
int space = 4;
|
|
int height();
|
|
int width() {
|
|
return 1000;
|
|
}
|
|
};
|
|
|
|
|
|
Tree_Pos get_pos(int pos, const QVector<Node*>& roots, int space);
|
|
QVector<Node*> deepTraversed(const QVector<Node*>& nodes);
|
|
|
|
using Node_Call_Back = const std::function<void(Node*, int, int)>&;
|
|
void select_node(const QVector<Node*>& roots, int view_y, int length, int space, Node_Call_Back call_back);
|
|
}
|