还是一堆bug的状态

This commit is contained in:
2026-08-01 20:09:45 +08:00
parent 0df7beda49
commit 8fb9683182
294 changed files with 13678 additions and 10864 deletions
+45 -43
View File
@@ -3,69 +3,68 @@
#include <stack>
#include <algorithm>
#include <iostream>
namespace Psc {
int Node::get_deep() {
namespace Flex_Qt {
int Tree_Node::get_deep() {
int ret = -1;
Node* cur = static_cast<Node*>(this);
Tree_Node* cur = static_cast<Tree_Node*>(this);
while (cur) {
cur = cur->par;
ret++;
}
return ret;
}
Node::Node() {
}
int Node::index() {
auto found = std::find(par->sons.begin(), par->sons.end(), static_cast<Node*>(this));
Tree_Node::Tree_Node() {}
int Tree_Node::index() {
auto found = std::find(par->sons.begin(), par->sons.end(), static_cast<Tree_Node*>(this));
return found == par->sons.end() ? -1 : static_cast<int>(std::distance(par->sons.begin(), found));
}
bool Node::is_root() {
bool Tree_Node::is_root() {
return par == nullptr;
}
bool Node::is_leaf() {
bool Tree_Node::is_leaf() {
return !sons.size();
}
bool Node::is_first() {
bool Tree_Node::is_first() {
return index() == 0;
}
bool Node::is_last() {
bool Tree_Node::is_last() {
return index() == par->sons.size() - 1;
}
Node* Node::previous() {
Tree_Node* Tree_Node::previous() {
if (is_first())
return nullptr;
return par->sons[index() - 1];
}
Node* Node::next() {
Tree_Node* Tree_Node::next() {
if (is_last())
return nullptr;
return par->sons[index() + 1];
}
Node* Node::last_child() {
Tree_Node* Tree_Node::last_child() {
if (is_leaf())
std::cout << "last_child() error";
return sons[sons.size() - 1];
}
Node* Node::first_child() {
Tree_Node* Tree_Node::first_child() {
if (is_leaf())
std::cout << "first_child() error";
return sons[0];
}
Node* Node::root() {
Node* ret = static_cast<Node*>(this);
Tree_Node* Tree_Node::root() {
Tree_Node * ret = static_cast<Tree_Node*>(this);
while (ret->par != nullptr) {
ret = ret->par;
}
return ret;
}
std::vector<Node*> Node::deep_traversed() {
std::vector<Node*> result;
std::vector<Tree_Node*> Tree_Node::deep_traversed() {
std::vector<Tree_Node*> result;
if (!this)
return result;
std::stack<Node*> stack;
std::stack<Tree_Node*> stack;
stack.push(this);
while (!stack.empty()) {
Node* node = stack.top();
Tree_Node * node = stack.top();
stack.pop();
result.push_back(node);
// 逆序压入子节点,保证从左到右的遍历顺序
@@ -75,13 +74,13 @@ std::vector<Node*> Node::deep_traversed() {
}
return result;
}
std::vector<Node*> Node::sequence_traversed() {
std::vector<Node*> ret;
std::queue<Node*> que;
Node* that = this;
std::vector<Tree_Node*> Tree_Node::sequence_traversed() {
std::vector<Tree_Node*> ret;
std::queue<Tree_Node*> que;
Tree_Node * that = this;
que.push(that);
while (!que.empty()) {
Node* cur = que.front();
Tree_Node * cur = que.front();
que.pop();
int n = cur->sons.size();
ret.push_back(cur);
@@ -91,22 +90,23 @@ std::vector<Node*> Node::sequence_traversed() {
}
return ret;
}
std::vector<Node*> Node::descendants() {
std::vector<Node*>&& ret = sequence_traversed();
std::vector<Tree_Node*> Tree_Node::descendants() {
std::vector<Tree_Node*>&& ret = sequence_traversed();
ret.erase(ret.begin());
return ret;
}
std::vector<Node*> deep_traversed(const std::vector<Node*>& nodes) {
std::vector<Node*> result;
std::vector<Tree_Node*> deep_traversed(const std::vector<Tree_Node*>& nodes) {
std::vector<Tree_Node*> result;
if (nodes.empty())
return result;
std::stack<Node*> stack;
for (Node* node : nodes) {
std::stack<Tree_Node*> stack;
for (Tree_Node * node : nodes)
{
if (node)
stack.push(node);
}
while (!stack.empty()) {
Node* node = stack.top();
Tree_Node * node = stack.top();
stack.pop();
result.push_back(node);
// 逆序压入子节点,保证从左到右的遍历顺序
@@ -119,12 +119,13 @@ std::vector<Node*> deep_traversed(const std::vector<Node*>& nodes) {
#define ReMain (pos - total_height)
int Tree_Model::height() {
int total_height = 0;
std::stack<std::pair<Node*, int>> stack;
for (Node* node : roots) {
std::stack<std::pair<Tree_Node*, int>> stack;
for (Tree_Node * node : roots)
{
if (node)
stack.push({node, 0});
}
Node* cur{};
Tree_Node * cur{};
int deep{};
while (!stack.empty()) {
auto t = stack.top();
@@ -140,14 +141,15 @@ int Tree_Model::height() {
}
return total_height;
}
Tree_Pos get_pos(int pos, const std::vector<Node*>& roots, int space) {
Tree_Pos get_pos(int pos, const std::vector<Tree_Node*>& roots, int space) {
int total_height = 0;
std::stack<std::pair<Node*, int>> stack;
for (Node* node : roots) {
std::stack<std::pair<Tree_Node*, int>> stack;
for (Tree_Node * node : roots)
{
if (node)
stack.push({node, 0});
}
Node* cur{};
Tree_Node * cur{};
int deep{};
while (!stack.empty()) {
auto t = stack.top();
@@ -166,9 +168,9 @@ Tree_Pos get_pos(int pos, const std::vector<Node*>& roots, int space) {
}
return Tree_Pos{cur, deep, total_height, ReMain, stack};
}
void select_node(const std::vector<Node*>& roots, int view_y, int length, int space, Node_Call_Back call_back) {
void select_node(const std::vector<Tree_Node*>& roots, int view_y, int length, int space, Node_Call_Back call_back) {
auto ret = get_pos(view_y, roots, space);
std::stack<std::pair<Node*, int>>& stack = ret.rest;
std::stack<std::pair<Tree_Node*, int>>& stack = ret.rest;
int cur_inside_y = ret.node_pos;
int cur_inside_end = cur_inside_y + length;
while (!stack.empty()) {
@@ -186,4 +188,4 @@ void select_node(const std::vector<Node*>& roots, int view_y, int length, int sp
}
}
}
} // namespace Psc
}
+22 -22
View File
@@ -4,49 +4,49 @@
#include <stack>
#include <utility>
#include <vector>
namespace Psc {
class Node {
namespace Flex_Qt {
class Tree_Node {
public:
explicit Node();
explicit Tree_Node();
// 判断状态
int index();
bool is_root();
bool is_leaf();
bool is_first();
bool is_last();
Node* previous();
Node* next();
Node* last_child();
Node* first_child();
Node* root();
Tree_Node* previous();
Tree_Node* next();
Tree_Node* last_child();
Tree_Node* first_child();
Tree_Node* root();
int get_deep();
// 遍历值
std::vector<Node*> deep_traversed();
std::vector<Node*> sequence_traversed();
std::vector<Node*> descendants();
Node* par = nullptr;
std::vector<Node*> sons;
std::vector<Tree_Node*> deep_traversed();
std::vector<Tree_Node*> sequence_traversed();
std::vector<Tree_Node*> descendants();
Tree_Node* par = nullptr;
std::vector<Tree_Node*> sons;
QString text;
bool expand = true;
int height = 20;
void add_child(Node* child) {
void add_child(Tree_Node* child) {
sons.push_back(child);
child->par = this;
}
};
struct Tree_Pos {
Node* p{};
Tree_Node* p{};
int depth{};
int node_pos{};
int offset{};
int pos() {
return node_pos + offset;
}
std::stack<std::pair<Node*, int>> rest;
std::stack<std::pair<Tree_Node*, int>> rest;
};
class Tree_Model {
public:
std::vector<Node*> roots;
std::vector<Tree_Node*> roots;
int tab_pixel_size = 8;
int png_len = 20;
int tab_width = 10;
@@ -56,8 +56,8 @@ public:
return 1000;
}
};
Tree_Pos get_pos(int pos, const std::vector<Node*>& roots, int space);
std::vector<Node*> deep_traversed(const std::vector<Node*>& nodes);
using Node_Call_Back = const std::function<void(Node*, int, int)>&;
void select_node(const std::vector<Node*>& roots, int view_y, int length, int space, Node_Call_Back call_back);
} // namespace Psc
Tree_Pos get_pos(int pos, const std::vector<Tree_Node*>& roots, int space);
std::vector<Tree_Node*> deep_traversed(const std::vector<Tree_Node*>& nodes);
using Node_Call_Back = const std::function<void(Tree_Node*, int, int)>&;
void select_node(const std::vector<Tree_Node*>& roots, int view_y, int length, int space, Node_Call_Back call_back);
}
+6 -6
View File
@@ -6,10 +6,10 @@
#include <stack>
#include "../../component/SVG.h"
#include "Tree_Model.h"
namespace Psc {
namespace Flex_Qt {
Tree_View* create_Tree_View() {
auto cn = [](const QString& text) {
auto ret = new Node();
auto ret = new Tree_Node();
ret->text = text;
return ret;
};
@@ -63,7 +63,7 @@ void Tree_View::paintEvent(QPaintEvent* event) {
static auto expand = SVG_Image_Render().set_path(":/you_jian_tou.svg").create().to_image({model->png_len, model->png_len}, Qt::black);
static auto retract = expand.transformed(QTransform().rotate(90));
painter.setClipRect(view_rect);
select_node(roots, _view_pos.y(), view_rect.height(), model->space, [&](Node* cur, int depth, int cur_inside_y) {
select_node(roots, _view_pos.y(), view_rect.height(), model->space, [&](Tree_Node* cur, int depth, int cur_inside_y) {
int x = depth * model->tab_width;
int cur_h = cur->height;
{
@@ -93,7 +93,7 @@ void Tree_View::mouse_event(QMouseEvent* event, QEvent::Type type) {
bool on_h_slider = h_bar.get_slider_rect(width(), height()).contains(event->pos());
bool on_v_slider = v_bar.get_slider_rect(width(), height()).contains(event->pos());
if (type == QEvent::MouseButtonPress || type == QEvent::MouseButtonDblClick) {
select_node(model->roots, _view_pos.y(), view_rect.height(), model->space, [&](Node* cur, int depth, int cur_inside_y) {
select_node(model->roots, _view_pos.y(), view_rect.height(), model->space, [&](Tree_Node* cur, int depth, int cur_inside_y) {
int x = depth * model->tab_width;
int cur_h = cur->height;
QPoint sta = {x, cur_inside_y};
@@ -103,7 +103,7 @@ void Tree_View::mouse_event(QMouseEvent* event, QEvent::Type type) {
QRect r(wsta, wend);
if (r.contains(pos)) {
cur->expand = !cur->expand;
qDebug() << "1111111 1 " << cur->expand;
std::cout << "1111111 1 " << cur->expand;
update();
}
});
@@ -196,4 +196,4 @@ void Tree_View::wheelEvent(QWheelEvent* event) {
_view_pos.setY(v_bar.view_pos());
update();
}
} // namespace Psc
}
+2 -2
View File
@@ -4,7 +4,7 @@
#include <QPen>
#include <QWidget>
#include "../Table/scroll.h"
namespace Psc {
namespace Flex_Qt {
class Tree_Model;
class Tree_View : public QWidget {
public:
@@ -34,4 +34,4 @@ protected:
void wheelEvent(QWheelEvent* event) override;
};
Tree_View* create_Tree_View();
} // namespace Psc
}