自定义内存分配池
This commit is contained in:
@@ -19,9 +19,9 @@ namespace Psc::Message {
|
||||
static Config global_config;
|
||||
class Toast;
|
||||
class Resize_Watcher;
|
||||
static QHash<QWidget*, QVector<QPointer<Toast>>> containers;
|
||||
static QHash<QWidget*, QPointer<Resize_Watcher>> watchers;
|
||||
static QHash<QWidget*, QQueue<std::pair<Type, QString>>> queues;
|
||||
static std::unordered_map<QWidget*, std::vector<QPointer<Toast>>> containers;
|
||||
static std::unordered_map<QWidget*, QPointer<Resize_Watcher>> watchers;
|
||||
static std::unordered_map<QWidget*, std::queue<std::pair<Type, QString>>> queues;
|
||||
/* -------------------- 工具函数 -------------------- */
|
||||
static bool is_dark_palette() {
|
||||
QColor c = QApplication::palette().window().color();
|
||||
@@ -292,9 +292,10 @@ static void relayout(QWidget* top, Corner corner) {
|
||||
}
|
||||
}
|
||||
static void process_queue(QWidget* top, Corner corner) {
|
||||
if (queues[top].isEmpty())
|
||||
if (queues[top].empty())
|
||||
return;
|
||||
auto item = queues[top].dequeue();
|
||||
auto item = std::move(queues[top].front());
|
||||
queues[top].pop();
|
||||
auto* toast = new Toast(
|
||||
item.first,
|
||||
item.second,
|
||||
@@ -340,7 +341,7 @@ static void process_queue(QWidget* top, Corner corner) {
|
||||
// --------- 6️⃣ 超限处理 ----------
|
||||
if (list.size() > global_config.max_count) {
|
||||
auto old = list.front();
|
||||
list.removeFirst();
|
||||
list.erase(list.begin());
|
||||
if (old)
|
||||
old->disappear();
|
||||
}
|
||||
@@ -358,7 +359,7 @@ void show(Type type,
|
||||
QWidget* top = top_parent(parent);
|
||||
if (!top)
|
||||
return;
|
||||
queues[top].enqueue({type, text});
|
||||
queues[top].push({type, text});
|
||||
QTimer::singleShot(global_config.queue_interval,
|
||||
top,
|
||||
[top, corner]() {
|
||||
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
#include <QHash>
|
||||
#include <unordered_map>
|
||||
#include <QPointer>
|
||||
#include <QQueue>
|
||||
#include <QVector>
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
#include <QWidget>
|
||||
namespace Psc::Message {
|
||||
enum Type { success,
|
||||
|
||||
@@ -10,9 +10,9 @@ class Circular_Linked_List {
|
||||
public:
|
||||
Circular_Linked_List_Node<T>* head = nullptr;
|
||||
Circular_Linked_List_Node<T>* cur = nullptr;
|
||||
void init(const QVector<T>& data_list) {
|
||||
void init(const std::vector<T>& data_list) {
|
||||
head = new Circular_Linked_List_Node<T>();
|
||||
head->data = data_list.first();
|
||||
head->data = data_list.front();
|
||||
Circular_Linked_List_Node<T>* prev = head;
|
||||
int n = data_list.size();
|
||||
for (int i = 1; i < n - 1; i++) {
|
||||
@@ -23,7 +23,7 @@ public:
|
||||
prev = node;
|
||||
}
|
||||
auto tail = new Circular_Linked_List_Node<T>();
|
||||
tail->data = data_list.last();
|
||||
tail->data = data_list.back();
|
||||
tail->prev = prev;
|
||||
prev->next = tail;
|
||||
tail->next = head;
|
||||
@@ -69,10 +69,10 @@ public:
|
||||
node->next = that;
|
||||
that->prev = node;
|
||||
}
|
||||
QVector<Circular_Linked_List_Node<T>*> to_vector() {
|
||||
std::vector<Circular_Linked_List_Node<T>*> to_vector() {
|
||||
if (head == nullptr)
|
||||
return {};
|
||||
QVector<Circular_Linked_List_Node<T>*> ret;
|
||||
std::vector<Circular_Linked_List_Node<T>*> ret;
|
||||
Circular_Linked_List_Node<T>* cur = head;
|
||||
do {
|
||||
ret.push_back(cur);
|
||||
|
||||
@@ -18,17 +18,18 @@ void File_Dialog::paintEvent(QPaintEvent* event) {
|
||||
QPainter painter(this);
|
||||
int index = 0;
|
||||
for (File_Folder*& root : roots) {
|
||||
QQueue<File_Folder*> que;
|
||||
std::queue<File_Folder*> que;
|
||||
root->deep = 0;
|
||||
que.enqueue(root);
|
||||
que.push(root);
|
||||
while (!que.empty()) {
|
||||
File_Folder* cur = que.dequeue();
|
||||
File_Folder* cur = que.front();
|
||||
que.pop();
|
||||
int n = cur->sons.size();
|
||||
cur->draw(index++, &painter);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
if (cur->is_show_sons) {
|
||||
cur->sons[i]->deep = cur->deep + 1;
|
||||
que.enqueue(cur->sons[i]);
|
||||
que.push(cur->sons[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,9 +36,9 @@ public:
|
||||
class Graphic : public QWindow {
|
||||
public:
|
||||
Graphic();
|
||||
QVector<Graphic_Renderable*> renderables;
|
||||
QVector<Painter_Renderable*> painter_buffers;
|
||||
QVector<Opengl_Renderable*> opengl_buffers;
|
||||
std::vector<Graphic_Renderable*> renderables;
|
||||
std::vector<Painter_Renderable*> painter_buffers;
|
||||
std::vector<Opengl_Renderable*> opengl_buffers;
|
||||
bool first_resize = true;
|
||||
protected:
|
||||
bool event(QEvent*) override;
|
||||
|
||||
+36
-31
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include <QQueue>
|
||||
#include <QVector>
|
||||
#include <algorithm>
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
namespace renderive {
|
||||
template <typename That>
|
||||
class Node {
|
||||
@@ -9,7 +10,8 @@ public:
|
||||
int index() {
|
||||
if (!father)
|
||||
return -1;
|
||||
return father->sons.indexOf(static_cast<That*>(this));
|
||||
auto found = std::find(father->sons.begin(), father->sons.end(), static_cast<That*>(this));
|
||||
return found == father->sons.end() ? -1 : static_cast<int>(std::distance(father->sons.begin(), found));
|
||||
}
|
||||
bool root() {
|
||||
return !father;
|
||||
@@ -20,17 +22,17 @@ public:
|
||||
bool first() {
|
||||
if (!father)
|
||||
return false;
|
||||
return this == father->sons.first();
|
||||
return this == father->sons.front();
|
||||
}
|
||||
bool last() {
|
||||
if (!father)
|
||||
return false;
|
||||
return this == father->sons.last();
|
||||
return this == father->sons.back();
|
||||
}
|
||||
That* previous() {
|
||||
if (!father)
|
||||
return nullptr;
|
||||
int i = father->sons.indexOf(static_cast<That*>(this)) - 1;
|
||||
int i = index() - 1;
|
||||
if (i < 0)
|
||||
return nullptr;
|
||||
return father->sons[i];
|
||||
@@ -38,20 +40,20 @@ public:
|
||||
That* next() {
|
||||
if (!father)
|
||||
return nullptr;
|
||||
int i = father->sons.indexOf(static_cast<That*>(this)) + 1;
|
||||
if (i > father->sons.buffer_size())
|
||||
int i = index() + 1;
|
||||
if (i < 0 || i >= static_cast<int>(father->sons.size()))
|
||||
return nullptr;
|
||||
return father->sons[i];
|
||||
}
|
||||
That* last_child() {
|
||||
if (sons.empty())
|
||||
return nullptr;
|
||||
return sons.last();
|
||||
return sons.back();
|
||||
}
|
||||
That* first_child() {
|
||||
if (sons.empty())
|
||||
return nullptr;
|
||||
return sons.first();
|
||||
return sons.front();
|
||||
}
|
||||
That* root_node() {
|
||||
That* ret = static_cast<That*>(this);
|
||||
@@ -61,48 +63,51 @@ public:
|
||||
return ret;
|
||||
}
|
||||
int deep() {
|
||||
That* ret = static_cast<That*>(this);
|
||||
while (ret->father != nullptr) {
|
||||
ret = ret->father;
|
||||
ret++;
|
||||
int result = 0;
|
||||
That* current = static_cast<That*>(this);
|
||||
while (current->father != nullptr) {
|
||||
current = current->father;
|
||||
++result;
|
||||
}
|
||||
return ret;
|
||||
return result;
|
||||
}
|
||||
// 遍历值
|
||||
QVector<That*> deep_traversed() {
|
||||
std::vector<That*> deep_traversed() {
|
||||
std::vector<That*> ret;
|
||||
ret.append(static_cast<That*>(this));
|
||||
ret.push_back(static_cast<That*>(this));
|
||||
for (auto& child : sons) {
|
||||
ret.append(child->deep_traversed());
|
||||
std::vector<That*> descendants = child->deep_traversed();
|
||||
ret.insert(ret.end(), descendants.begin(), descendants.end());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
QVector<That*> sequence_traversed() {
|
||||
QVector<That*> ret;
|
||||
QQueue<That*> que;
|
||||
std::vector<That*> sequence_traversed() {
|
||||
std::vector<That*> ret;
|
||||
std::queue<That*> que;
|
||||
That* that = static_cast<That*>(this);
|
||||
que.enqueue(that);
|
||||
que.push(that);
|
||||
while (!que.empty()) {
|
||||
That* cur = que.dequeue();
|
||||
int n = cur->sons.buffer_size();
|
||||
ret.append(cur);
|
||||
That* cur = que.front();
|
||||
que.pop();
|
||||
int n = static_cast<int>(cur->sons.size());
|
||||
ret.push_back(cur);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
que.enqueue(cur->sons[i]);
|
||||
que.push(cur->sons[i]);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
QVector<That*> descendants() {
|
||||
QVector<That*>&& ret = sequence_traversed();
|
||||
ret.pop_front();
|
||||
std::vector<That*> descendants() {
|
||||
std::vector<That*>&& ret = sequence_traversed();
|
||||
ret.erase(ret.begin());
|
||||
return ret;
|
||||
}
|
||||
That* father = nullptr;
|
||||
QVector<That*> sons;
|
||||
std::vector<That*> sons;
|
||||
};
|
||||
template <typename NodeType>
|
||||
class Node_Manager {
|
||||
public:
|
||||
QVector<NodeType*> roots;
|
||||
std::vector<NodeType*> roots;
|
||||
};
|
||||
} // namespace renderive
|
||||
|
||||
+28
-35
@@ -1,76 +1,69 @@
|
||||
#pragma once
|
||||
#include <QHBoxLayout>
|
||||
#include <QObject>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
namespace renderive {
|
||||
template <typename T>
|
||||
class Roll_Object : QObject {
|
||||
public:
|
||||
explicit Roll_Object(QObject* parent = nullptr) : QObject(parent) {}
|
||||
explicit Roll_Object(QVector<T*> widgets, std::function<void(T*)> enter_func,
|
||||
std::function<void(T*)> leave_func, QObject* parent) :
|
||||
widgets(std::move(widgets)), enter_func(enter_func), leave_func(leave_func), QObject(parent) {
|
||||
if (enter_func)
|
||||
enter_func(widgets[index]);
|
||||
explicit Roll_Object(std::vector<T*> values, std::function<void(T*)> enter, std::function<void(T*)> leave, QObject* parent) : QObject(parent), widgets(std::move(values)), enter_func(std::move(enter)), leave_func(std::move(leave)) {
|
||||
if (enter_func && !widgets.empty())
|
||||
enter_func(widgets.front());
|
||||
}
|
||||
int index = 0;
|
||||
QVector<T*> widgets;
|
||||
std::vector<T*> widgets;
|
||||
std::function<void(T*)> enter_func;
|
||||
std::function<void(T*)> leave_func;
|
||||
T* cur() {
|
||||
if (widgets.empty())
|
||||
return nullptr;
|
||||
return widgets[index];
|
||||
return widgets[static_cast<std::size_t>(index)];
|
||||
}
|
||||
void set_cur(T* cur) {
|
||||
void set_cur(T* value) {
|
||||
if (widgets.empty())
|
||||
return;
|
||||
int new_index = widgets.indexOf(cur);
|
||||
auto found = std::find(widgets.begin(), widgets.end(), value);
|
||||
if (found == widgets.end())
|
||||
return;
|
||||
if (leave_func)
|
||||
leave_func(widgets[index]);
|
||||
index = new_index;
|
||||
leave_func(widgets[static_cast<std::size_t>(index)]);
|
||||
index = static_cast<int>(std::distance(widgets.begin(), found));
|
||||
if (enter_func)
|
||||
enter_func(widgets[index]);
|
||||
widgets[index]->update();
|
||||
enter_func(widgets[static_cast<std::size_t>(index)]);
|
||||
widgets[static_cast<std::size_t>(index)]->update();
|
||||
}
|
||||
void roll_right() {
|
||||
if (widgets.empty())
|
||||
return;
|
||||
if (leave_func)
|
||||
leave_func(widgets[index]);
|
||||
widgets[index]->update();
|
||||
if (widgets.last() != widgets[index]) {
|
||||
index++;
|
||||
}
|
||||
else {
|
||||
index = 0;
|
||||
}
|
||||
leave_func(widgets[static_cast<std::size_t>(index)]);
|
||||
widgets[static_cast<std::size_t>(index)]->update();
|
||||
index = (index + 1) % static_cast<int>(widgets.size());
|
||||
if (enter_func)
|
||||
enter_func(widgets[index]);
|
||||
widgets[index]->update();
|
||||
enter_func(widgets[static_cast<std::size_t>(index)]);
|
||||
widgets[static_cast<std::size_t>(index)]->update();
|
||||
}
|
||||
void roll_left() {
|
||||
if (widgets.empty())
|
||||
return;
|
||||
if (leave_func)
|
||||
leave_func(widgets[index]);
|
||||
widgets[index]->update();
|
||||
if (widgets.first() != widgets[index]) {
|
||||
index--;
|
||||
}
|
||||
else {
|
||||
index = widgets.size() - 1;
|
||||
}
|
||||
leave_func(widgets[static_cast<std::size_t>(index)]);
|
||||
widgets[static_cast<std::size_t>(index)]->update();
|
||||
index = index ? index - 1 : static_cast<int>(widgets.size()) - 1;
|
||||
if (enter_func)
|
||||
enter_func(widgets[index]);
|
||||
widgets[index]->update();
|
||||
enter_func(widgets[static_cast<std::size_t>(index)]);
|
||||
widgets[static_cast<std::size_t>(index)]->update();
|
||||
}
|
||||
QHBoxLayout* hbox_layout(int space) {
|
||||
auto ret = new QHBoxLayout;
|
||||
ret->setMargin(0);
|
||||
ret->setSpacing(space);
|
||||
for (auto widget : widgets) {
|
||||
for (T* widget : widgets)
|
||||
ret->addWidget(widget, 1);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -63,8 +63,8 @@ int Input_Core::cur_search_pos() {
|
||||
pos_len = im_get_spl_start_pos(start_pos);
|
||||
return static_cast<int>(pos_len);
|
||||
}
|
||||
QStringList Input_Core::get_candidate(unsigned int candnum) {
|
||||
QStringList text_list;
|
||||
std::vector<QString> Input_Core::get_candidate(unsigned int candnum) {
|
||||
std::vector<QString> text_list;
|
||||
if (candnum == 0)
|
||||
return text_list;
|
||||
char16* cand_buf = new char16[m_out_len];
|
||||
@@ -72,7 +72,7 @@ QStringList Input_Core::get_candidate(unsigned int candnum) {
|
||||
char16* cand;
|
||||
cand = im_get_candidate(i, cand_buf, static_cast<unsigned int>(m_out_len));
|
||||
if (cand) {
|
||||
text_list.append(QString::fromUtf16(cand));
|
||||
text_list.push_back(QString::fromUtf16(cand));
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
void reset_search();
|
||||
bool get_enable();
|
||||
void set_enable(bool able);
|
||||
QStringList get_candidate(unsigned int cnadnum);
|
||||
std::vector<QString> get_candidate(unsigned int cnadnum);
|
||||
signals :
|
||||
|
||||
void signal_input_able(bool);
|
||||
|
||||
@@ -111,12 +111,13 @@ void Virtual_Keyboard::get_candidate_list(const QString spell) {
|
||||
if (cand == 0) {
|
||||
return;
|
||||
}
|
||||
QStringList ret = core->get_candidate(cand);
|
||||
if (ret.isEmpty()) {
|
||||
std::vector<QString> ret = core->get_candidate(cand);
|
||||
if (ret.empty()) {
|
||||
return;
|
||||
}
|
||||
list_widget->clear();
|
||||
list_widget->addItems(ret);
|
||||
for (const QString& candidate : ret)
|
||||
list_widget->addItem(candidate);
|
||||
}
|
||||
void Virtual_Keyboard::handle_Key_Press(Key_Button* button) {
|
||||
if (state == Chinese) {
|
||||
|
||||
@@ -43,8 +43,8 @@ int binary_search(double value, T** spaces, int space_size, std::function<double
|
||||
}
|
||||
#undef LOWER
|
||||
#undef UPPER
|
||||
static int binary_search(double value, const QVector<double>& data, bool& ok) {
|
||||
if (data.isEmpty()) {
|
||||
static int binary_search(double value, const std::vector<double>& data, bool& ok) {
|
||||
if (data.empty()) {
|
||||
ok = false;
|
||||
return -1; // 返回 -1 表示数组为空
|
||||
}
|
||||
|
||||
@@ -13,12 +13,12 @@ using Handle_Mouse = std::function<void(QEvent::Type, QMouseEvent*)>;
|
||||
struct Background : Paintable {
|
||||
QGraphicsDropShadowEffect shadow_effect;
|
||||
Border* border{};
|
||||
QMap<Mouse_State, QColor> map;
|
||||
std::map<Mouse_State, QColor> map;
|
||||
Qt::SizeMode mode = Qt::RelativeSize;
|
||||
qreal radius = 0.1;
|
||||
bool enter = false;
|
||||
Mouse_State mouse_state = Mouse_State::Default;
|
||||
QVector<Handle_Mouse> mouse_handlers;
|
||||
std::vector<Handle_Mouse> mouse_handlers;
|
||||
void set_border(const QColor& border_color, int len = 1) {
|
||||
if (!border)
|
||||
border = new Border;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
#include <QMouseEvent>
|
||||
#include <QVector>
|
||||
#include <vector>
|
||||
namespace Psc {
|
||||
template <typename Handler_Type>
|
||||
class Delegate {
|
||||
public:
|
||||
QVector<Handler_Type> handlers;
|
||||
std::vector<Handler_Type> handlers;
|
||||
Delegate& operator+=(const Handler_Type& handler) {
|
||||
if (std::find(handlers.begin(), handlers.end(), handler) == handlers.end()) {
|
||||
handlers.push_back(handler);
|
||||
|
||||
@@ -103,8 +103,8 @@ void Layout::layout_impl() {
|
||||
int cros_length = T::cros_length(this);
|
||||
int cros_max = cros_length - cros_prefix - cros_suffix;
|
||||
int total_main = main_prefix + main_suffix;
|
||||
QVector<Layout_Item*> grow_items;
|
||||
QVector<Layout_Item*> shrink_items;
|
||||
std::vector<Layout_Item*> grow_items;
|
||||
std::vector<Layout_Item*> shrink_items;
|
||||
// ---------- 第一遍:初始化尺寸 & 收集 grow / shrink ----------
|
||||
for (auto* item : items) {
|
||||
auto size = item->sizeHint();
|
||||
@@ -129,7 +129,7 @@ void Layout::layout_impl() {
|
||||
}
|
||||
int available = main_length - total_main;
|
||||
// ---------- Grow ----------
|
||||
if (available > 0 && !grow_items.isEmpty()) {
|
||||
if (available > 0 && !grow_items.empty()) {
|
||||
int count = grow_items.size();
|
||||
int each = available / count;
|
||||
int remain = available % count;
|
||||
@@ -142,7 +142,7 @@ void Layout::layout_impl() {
|
||||
available = 0;
|
||||
}
|
||||
// ---------- Shrink(按比例,修正版本) ----------
|
||||
if (available < 0 && !shrink_items.isEmpty()) {
|
||||
if (available < 0 && !shrink_items.empty()) {
|
||||
int deficit = -available;
|
||||
int shrink_cap = 0;
|
||||
for (auto* item : shrink_items) {
|
||||
|
||||
@@ -10,7 +10,7 @@ public:
|
||||
}
|
||||
int space = 8;
|
||||
QMargins margins = {8, 8, 8, 8};
|
||||
QVector<Layout_Item*> items;
|
||||
std::vector<Layout_Item*> items;
|
||||
Qt::Orientation orientation = Qt::Horizontal;
|
||||
void layout();
|
||||
Direction direction = Direction::Default;
|
||||
|
||||
@@ -95,8 +95,8 @@ public:
|
||||
icon.use_get_main_by_cros = true;
|
||||
icon.size_policy.setFlag(Cross_Expand);
|
||||
icon.size_policy.setFlag(Get_Main_By_Cross);
|
||||
layout.items.append(&icon);
|
||||
layout.items.append(&text);
|
||||
layout.items.push_back(&icon);
|
||||
layout.items.push_back(&text);
|
||||
};
|
||||
void paint(QPainter* painter, QRect r, QPaintEvent* event) override {
|
||||
border.paint(painter, r, event);
|
||||
|
||||
@@ -18,8 +18,8 @@ public:
|
||||
Background background;
|
||||
Content content;
|
||||
Button() {
|
||||
paintAbles.append(&background);
|
||||
paintAbles.append(&content);
|
||||
paintAbles.push_back(&background);
|
||||
paintAbles.push_back(&content);
|
||||
}
|
||||
[[nodiscard]] QSize sizeHint() const override {
|
||||
auto ret = content.sizeHint();
|
||||
@@ -34,7 +34,7 @@ inline Button* create_icon(const QString& path, const QColor& background, const
|
||||
auto ret = new Button();
|
||||
ret->content.set_icon(path, QColor(Qt::color0));
|
||||
ret->background.set_color(background);
|
||||
ret->background.mouse_handlers.append(f);
|
||||
ret->background.mouse_handlers.push_back(f);
|
||||
return ret;
|
||||
};
|
||||
struct Switch_Button : Base {
|
||||
@@ -44,9 +44,9 @@ public:
|
||||
Content content1;
|
||||
Content content2;
|
||||
Switch_Button() {
|
||||
paintAbles.append(&background);
|
||||
paintAbles.append(&content1);
|
||||
paintAbles.append(&content2);
|
||||
paintAbles.push_back(&background);
|
||||
paintAbles.push_back(&content1);
|
||||
paintAbles.push_back(&content2);
|
||||
content1.show = true;
|
||||
content2.show = false;
|
||||
}
|
||||
@@ -65,7 +65,7 @@ inline Switch_Button* create_switch_icon(const QColor& background, const QString
|
||||
ret->content1.set_icon(path, QColor(Qt::color0));
|
||||
ret->content2.set_icon(path2, QColor(Qt::color0));
|
||||
ret->background.set_color(background);
|
||||
ret->background.mouse_handlers.append([ret, f, f2](QEvent::Type t, QMouseEvent* e) {
|
||||
ret->background.mouse_handlers.push_back([ret, f, f2](QEvent::Type t, QMouseEvent* e) {
|
||||
if (t == QEvent::MouseButtonPress) {
|
||||
if (ret->content1.show) {
|
||||
f(t, e);
|
||||
|
||||
@@ -45,13 +45,13 @@ struct Content : Paintable {
|
||||
int a = qMin(e->size().width(), e->size().height());
|
||||
if (icon) {
|
||||
Layout_Info t(Plottable_Icon, Layout_Item_Type::Fixed, Layout_Item_Type2::Fixed, a, a);
|
||||
layout.infos.append(t);
|
||||
layout.infos.push_back(t);
|
||||
}
|
||||
if (text) {
|
||||
QFontMetrics fm(text->font);
|
||||
int len = fm.horizontalAdvance(text->text);
|
||||
Layout_Info t(Plottable_Text, Layout_Item_Type::Fixed, Layout_Item_Type2::Expand, len, 0);
|
||||
layout.infos.append(t);
|
||||
layout.infos.push_back(t);
|
||||
}
|
||||
layout.cacl(e->size().width(), e->size().height());
|
||||
return Event_Type::refresh;
|
||||
|
||||
@@ -11,15 +11,15 @@ Table_Paint_Data::Table_Paint_Data(QIcon ic, QString t) {
|
||||
background_color = random_color;
|
||||
icon = Icon2(ic);
|
||||
text.text = t;
|
||||
layout.items.append(&icon.value());
|
||||
layout.items.append(&text);
|
||||
layout.items.push_back(&icon.value());
|
||||
layout.items.push_back(&text);
|
||||
}
|
||||
Table_Paint_Data::Table_Paint_Data(QString t) {
|
||||
renderive::Range r{155, 255};
|
||||
QColor random_color(renderive::get_data(r), renderive::get_data(r), renderive::get_data(r));
|
||||
background_color = random_color;
|
||||
text.text = t;
|
||||
layout.items.append(&text);
|
||||
layout.items.push_back(&text);
|
||||
}
|
||||
void Table_Paint_Data::update(bool show, Table_View* view, QPainter* painter, QRect rect) {
|
||||
painter->fillRect(rect, background_color);
|
||||
|
||||
@@ -80,12 +80,12 @@ Pos Memory_Table_Model::get_col(int x) {
|
||||
Pos Memory_Table_Model::get_row(int y) {
|
||||
return get_pos((Base_Info**)row_info_list.data(), row_info_list.size(), row_space, y, 0);
|
||||
}
|
||||
QVector<QVector<Base_Table_Data*>> exchange_row_col(const QVector<QVector<Base_Table_Data*>>& data) {
|
||||
QVector<QVector<Base_Table_Data*>> ret;
|
||||
std::vector<std::vector<Base_Table_Data*>> exchange_row_col(const std::vector<std::vector<Base_Table_Data*>>& data) {
|
||||
std::vector<std::vector<Base_Table_Data*>> ret;
|
||||
int m = data.size();
|
||||
int n = data.first().size();
|
||||
int n = data.front().size();
|
||||
for (int i = 0; i < n; ++i) {
|
||||
QVector<Base_Table_Data*> t;
|
||||
std::vector<Base_Table_Data*> t;
|
||||
for (int j = 0; j < m; ++j) {
|
||||
t.push_back(data[j][i]);
|
||||
}
|
||||
@@ -98,7 +98,7 @@ enum Cell_Type {
|
||||
Merge_Cell,
|
||||
Normal
|
||||
};
|
||||
Cell_Type cell_type(const QVector<QVector<Base_Table_Data*>>& data, int col, int row) {
|
||||
Cell_Type cell_type(const std::vector<std::vector<Base_Table_Data*>>& data, int col, int row) {
|
||||
auto that = data[col][row];
|
||||
if (that->parent != that)
|
||||
return Merge_Cell;
|
||||
@@ -136,11 +136,11 @@ void Memory_Table_Model::merge(int row, int col, int row_span, int col_span) {
|
||||
}
|
||||
}
|
||||
// parent 是复刻他上一行的parent
|
||||
bool Memory_Table_Model::insert_row(int pos, const QVector<Row_Info*>& infos, const QVector<QVector<Base_Table_Data*>>& d, Edge_Expand_Type t) {
|
||||
bool Memory_Table_Model::insert_row(int pos, const std::vector<Row_Info*>& infos, const std::vector<std::vector<Base_Table_Data*>>& d, Edge_Expand_Type t) {
|
||||
int col_num = col_info_list.size();
|
||||
int insert_row_num = infos.size();
|
||||
if (!d.empty() && d.first().size() != col_num) {
|
||||
qDebug() << VAR_QSTR_2(d.first().size(), col_num) << " " << QLOG_POS;
|
||||
if (!d.empty() && d.front().size() != col_num) {
|
||||
qDebug() << VAR_QSTR_2(d.front().size(), col_num) << " " << QLOG_POS;
|
||||
return false;
|
||||
}
|
||||
// 行结构转列结构
|
||||
@@ -175,17 +175,16 @@ bool Memory_Table_Model::insert_row(int pos, const QVector<Row_Info*>& infos, co
|
||||
auto cur = insert_col_list[col][j];
|
||||
cur->parent = par ? par : cur;
|
||||
}
|
||||
data[col] = data[col].mid(0, pos) + insert_col_list[col] + data[col].mid(pos);
|
||||
data[col].insert(data[col].begin() + pos, insert_col_list[col].begin(), insert_col_list[col].end());
|
||||
}
|
||||
// 添加结构信息
|
||||
row_info_list = row_info_list.mid(0, pos) + infos + row_info_list.mid(pos);
|
||||
row_info_list.insert(row_info_list.begin() + pos, infos.begin(), infos.end());
|
||||
return true;
|
||||
}
|
||||
bool Memory_Table_Model::insert_col(int pos, const QVector<Col_Info*>& infos, const QVector<QVector<Base_Table_Data*>>& d, Edge_Expand_Type t) {
|
||||
bool Memory_Table_Model::insert_col(int pos, const std::vector<Col_Info*>& infos, const std::vector<std::vector<Base_Table_Data*>>& d, Edge_Expand_Type t) {
|
||||
int row_num = row_info_list.size();
|
||||
int insert_col_num = infos.size();
|
||||
if (!d.empty() && d.first().size() != row_num) {
|
||||
qDebug() << VAR_QSTR_2(d.first().size(), row_num) << " " << QLOG_POS;
|
||||
if (!d.empty() && d.front().size() != row_num) {
|
||||
qDebug() << VAR_QSTR_2(d.front().size(), row_num) << " " << QLOG_POS;
|
||||
return false;
|
||||
}
|
||||
for (int row = 0; row < row_num; ++row) {
|
||||
@@ -219,9 +218,8 @@ bool Memory_Table_Model::insert_col(int pos, const QVector<Col_Info*>& infos, co
|
||||
cur->parent = par ? par : cur;
|
||||
}
|
||||
}
|
||||
data = data.mid(0, pos) + d + data.mid(pos);
|
||||
// 添加结构信息
|
||||
col_info_list = col_info_list.mid(0, pos) + infos + col_info_list.mid(pos);
|
||||
data.insert(data.begin() + pos, d.begin(), d.end());
|
||||
col_info_list.insert(col_info_list.begin() + pos, infos.begin(), infos.end());
|
||||
return true;
|
||||
}
|
||||
bool Memory_Table_Model::remove_row(int pos, int num) {
|
||||
@@ -229,12 +227,9 @@ bool Memory_Table_Model::remove_row(int pos, int num) {
|
||||
qDebug() << VAR_QSTR_3(pos, num, row_info_list.size()) << " " << QLOG_POS;
|
||||
return false;
|
||||
}
|
||||
int n = row_info_list.size();
|
||||
for (int i = 0; i < n; ++i) {
|
||||
auto& col = data[i];
|
||||
for (auto it : col.mid(pos, num)) {
|
||||
delete it;
|
||||
}
|
||||
for (auto& col : data) {
|
||||
for (auto item = col.begin() + pos; item != col.begin() + pos + num; ++item)
|
||||
delete *item;
|
||||
col.erase(col.begin() + pos, col.begin() + pos + num);
|
||||
}
|
||||
for (int i = 0; i < num; ++i) {
|
||||
@@ -248,12 +243,11 @@ bool Memory_Table_Model::remove_col(int pos, int num) {
|
||||
qDebug() << VAR_QSTR_3(pos, num, col_info_list.size()) << " " << QLOG_POS;
|
||||
return false;
|
||||
}
|
||||
for (auto& it : data.mid(pos, num)) {
|
||||
for (auto t : it) {
|
||||
delete t;
|
||||
}
|
||||
for (auto column = data.begin() + pos; column != data.begin() + pos + num; ++column) {
|
||||
for (auto* item : *column)
|
||||
delete item;
|
||||
}
|
||||
data.erase(data.begin() + pos, data.end() + pos + num);
|
||||
data.erase(data.begin() + pos, data.begin() + pos + num);
|
||||
for (int i = 0; i < num; ++i) {
|
||||
delete col_info_list[pos + i];
|
||||
}
|
||||
@@ -262,7 +256,7 @@ bool Memory_Table_Model::remove_col(int pos, int num) {
|
||||
}
|
||||
Cell_Info Memory_Table_Model::get_span(int xi, int yi) {
|
||||
int col_num = data.size();
|
||||
int row_num = data.first().size();
|
||||
int row_num = data.front().size();
|
||||
Base_Table_Data* that = data[xi][yi];
|
||||
int col_span = 1;
|
||||
int row_span = 1;
|
||||
|
||||
@@ -5,10 +5,10 @@ namespace Psc {
|
||||
// using T_Data = std::shared_ptr<Table_Data>;
|
||||
struct Edit_Func {
|
||||
virtual ~Edit_Func() = default;
|
||||
virtual bool insert_row(int pos, const QVector<Row_Info*>& infos, const QVector<QVector<Base_Table_Data*>>& data, Edge_Expand_Type t) {
|
||||
virtual bool insert_row(int pos, const std::vector<Row_Info*>& infos, const std::vector<std::vector<Base_Table_Data*>>& data, Edge_Expand_Type t) {
|
||||
return true;
|
||||
}
|
||||
virtual bool insert_col(int pos, const QVector<Col_Info*>& infos, const QVector<QVector<Base_Table_Data*>>& data, Edge_Expand_Type t) {
|
||||
virtual bool insert_col(int pos, const std::vector<Col_Info*>& infos, const std::vector<std::vector<Base_Table_Data*>>& data, Edge_Expand_Type t) {
|
||||
return true;
|
||||
}
|
||||
virtual bool remove_row(int pos, int num) {
|
||||
@@ -58,8 +58,8 @@ Pos get_pos(Base_Info** infos, int n, int space, int pos, int margin);
|
||||
struct Memory_Table_Model : Base_Table_Model, Edit_Func {
|
||||
void split(int row, int col, int row_span, int col_span) override;
|
||||
void merge(int row, int col, int row_span, int col_span) override;
|
||||
bool insert_row(int pos, const QVector<Row_Info*>& infos, const QVector<QVector<Base_Table_Data*>>& data, Edge_Expand_Type) override;
|
||||
bool insert_col(int pos, const QVector<Col_Info*>& infos, const QVector<QVector<Base_Table_Data*>>& data, Edge_Expand_Type) override;
|
||||
bool insert_row(int pos, const std::vector<Row_Info*>& infos, const std::vector<std::vector<Base_Table_Data*>>& data, Edge_Expand_Type) override;
|
||||
bool insert_col(int pos, const std::vector<Col_Info*>& infos, const std::vector<std::vector<Base_Table_Data*>>& data, Edge_Expand_Type) override;
|
||||
bool remove_row(int pos, int num) override;
|
||||
bool remove_col(int pos, int num) override;
|
||||
// 表格区域绝对位置计算
|
||||
@@ -87,9 +87,9 @@ struct Memory_Table_Model : Base_Table_Model, Edit_Func {
|
||||
return data[col][row];
|
||||
}
|
||||
protected:
|
||||
QVector<Col_Info*> col_info_list;
|
||||
QVector<Row_Info*> row_info_list;
|
||||
QVector<QVector<Base_Table_Data*>> data;
|
||||
std::vector<Col_Info*> col_info_list;
|
||||
std::vector<Row_Info*> row_info_list;
|
||||
std::vector<std::vector<Base_Table_Data*>> data;
|
||||
friend Table_View* create_table_view();
|
||||
friend Table_View* create_table_view2();
|
||||
};
|
||||
|
||||
@@ -84,7 +84,7 @@ void Table_View::paintEvent(QPaintEvent* event) {
|
||||
int xsi = x_sta.index;
|
||||
int max_col_num = std::min(x_end.index - x_sta.index + 1, model->total_col());
|
||||
int col_num = 0;
|
||||
QVector<Paint_Cache> xs;
|
||||
std::vector<Paint_Cache> xs;
|
||||
{
|
||||
int cur_x = x_sta.cell_pos;
|
||||
for (int i = 0; i < max_col_num; ++i) {
|
||||
@@ -100,7 +100,7 @@ void Table_View::paintEvent(QPaintEvent* event) {
|
||||
int ysi = y_sta.index;
|
||||
int max_row_num = std::min(y_end.index - y_sta.index + 1, model->total_row());
|
||||
int row_num = 0;
|
||||
QVector<Paint_Cache> ys;
|
||||
std::vector<Paint_Cache> ys;
|
||||
{
|
||||
int cur_y = y_sta.cell_pos;
|
||||
for (int i = 0; i < max_row_num; ++i) {
|
||||
@@ -122,7 +122,7 @@ void Table_View::paintEvent(QPaintEvent* event) {
|
||||
QPoint e = QPoint(cells_widget_rect.right(), end_y);
|
||||
painter.setClipRect(QRect(s, e));
|
||||
}
|
||||
QVector<int> middle_xs(col_num + 1);
|
||||
std::vector<int> middle_xs(col_num + 1);
|
||||
for (int i = 0; i < col_num; ++i) {
|
||||
auto& xd = xs[i];
|
||||
int sta_x = to_widget_pos({xd.cell_abs_pos, 0}).rx();
|
||||
@@ -154,7 +154,7 @@ void Table_View::paintEvent(QPaintEvent* event) {
|
||||
QPoint e = QPoint(end_x, cells_widget_rect.bottom());
|
||||
painter.setClipRect(QRect(s, e));
|
||||
}
|
||||
QVector<int> middle_ys(row_num);
|
||||
std::vector<int> middle_ys(row_num);
|
||||
for (int i = 0; i < row_num; ++i) {
|
||||
auto& yd = ys[i];
|
||||
int sta_y = to_widget_pos({0, yd.cell_abs_pos}).ry();
|
||||
@@ -180,7 +180,7 @@ void Table_View::paintEvent(QPaintEvent* event) {
|
||||
if (v_bar.show) {
|
||||
v_bar.draw(&painter);
|
||||
}
|
||||
QSet<Base_Table_Data*> set;
|
||||
std::set<Base_Table_Data*> set;
|
||||
// 绘制小方格
|
||||
painter.setClipRect(cells_widget_rect);
|
||||
painter.setPen(Qt::black);
|
||||
@@ -198,7 +198,7 @@ void Table_View::paintEvent(QPaintEvent* event) {
|
||||
if (
|
||||
r.col_index < xsi ||
|
||||
r.row_index < ysi) {
|
||||
if (!set.contains(cur_cell->parent)) {
|
||||
if (set.find(cur_cell->parent) == set.end()) {
|
||||
set.insert(cur_cell->parent);
|
||||
int sxi = r.col_index;
|
||||
int syi = r.row_index;
|
||||
@@ -436,14 +436,14 @@ void Table_View::wheelEvent(QWheelEvent* event) {
|
||||
#ifdef YC_USE_GTEST
|
||||
#include <gtest/gtest.h>
|
||||
TEST(Table, get_pos_test) {
|
||||
QVector<Base_info*> info_list;
|
||||
std::vector<Base_info*> info_list;
|
||||
// 4 2 1
|
||||
// 4 6 7
|
||||
info_list.push_back(new Base_info(4, ""));
|
||||
info_list.push_back(new Base_info(1, ""));
|
||||
auto size = static_cast<int>(info_list.size());
|
||||
auto d = info_list.data();
|
||||
QVector<std::pair<Base_Table_Info::Pos, int>> combined_data = {
|
||||
std::vector<std::pair<Base_Table_Info::Pos, int>> combined_data = {
|
||||
{Base_Table_Info::Pos{0, 0, -7}, -7},
|
||||
{Base_Table_Info::Pos{0, 0, 4}, 4},
|
||||
{Base_Table_Info::Pos{1, 6, 1}, 7},
|
||||
@@ -471,13 +471,13 @@ TEST(MatrixTest, BasicOperations) {
|
||||
EXPECT_EQ(mat.at(1, 1), 5);
|
||||
EXPECT_EQ(mat.at(2, 2), 9);
|
||||
// 测试 row 方法
|
||||
QVector<int> row_0 = mat.row(0);
|
||||
std::vector<int> row_0 = mat.row(0);
|
||||
EXPECT_EQ(row_0.size(), 3);
|
||||
EXPECT_EQ(row_0[0], 1);
|
||||
EXPECT_EQ(row_0[1], 2);
|
||||
EXPECT_EQ(row_0[2], 3);
|
||||
// 测试 col 方法
|
||||
QVector<int> col_0 = mat.col(0);
|
||||
std::vector<int> col_0 = mat.col(0);
|
||||
EXPECT_EQ(col_0.size(), 3);
|
||||
EXPECT_EQ(col_0[0], 1);
|
||||
EXPECT_EQ(col_0[1], 4);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "Tree_Model.h"
|
||||
#include <QQueue>
|
||||
#include <QStack>
|
||||
#include <queue>
|
||||
#include <stack>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
namespace Psc {
|
||||
int Node::get_deep() {
|
||||
@@ -15,7 +16,8 @@ int Node::get_deep() {
|
||||
Node::Node() {
|
||||
}
|
||||
int Node::index() {
|
||||
return par->sons.indexOf(static_cast<Node*>(this));
|
||||
auto found = std::find(par->sons.begin(), par->sons.end(), static_cast<Node*>(this));
|
||||
return found == par->sons.end() ? -1 : static_cast<int>(std::distance(par->sons.begin(), found));
|
||||
}
|
||||
bool Node::is_root() {
|
||||
return par == nullptr;
|
||||
@@ -56,15 +58,16 @@ Node* Node::root() {
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
QVector<Node*> Node::deep_traversed() {
|
||||
QVector<Node*> result;
|
||||
std::vector<Node*> Node::deep_traversed() {
|
||||
std::vector<Node*> result;
|
||||
if (!this)
|
||||
return result;
|
||||
QStack<Node*> stack;
|
||||
std::stack<Node*> stack;
|
||||
stack.push(this);
|
||||
while (!stack.isEmpty()) {
|
||||
Node* node = stack.pop();
|
||||
result.append(node);
|
||||
while (!stack.empty()) {
|
||||
Node* node = stack.top();
|
||||
stack.pop();
|
||||
result.push_back(node);
|
||||
// 逆序压入子节点,保证从左到右的遍历顺序
|
||||
for (int i = node->sons.size() - 1; i >= 0; --i) {
|
||||
stack.push(node->sons[i]);
|
||||
@@ -72,38 +75,40 @@ QVector<Node*> Node::deep_traversed() {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
QVector<Node*> Node::sequence_traversed() {
|
||||
QVector<Node*> ret;
|
||||
QQueue<Node*> que;
|
||||
std::vector<Node*> Node::sequence_traversed() {
|
||||
std::vector<Node*> ret;
|
||||
std::queue<Node*> que;
|
||||
Node* that = this;
|
||||
que.enqueue(that);
|
||||
que.push(that);
|
||||
while (!que.empty()) {
|
||||
Node* cur = que.dequeue();
|
||||
Node* cur = que.front();
|
||||
que.pop();
|
||||
int n = cur->sons.size();
|
||||
ret.append(cur);
|
||||
ret.push_back(cur);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
que.enqueue(cur->sons[i]);
|
||||
que.push(cur->sons[i]);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
QVector<Node*> Node::descendants() {
|
||||
QVector<Node*>&& ret = sequence_traversed();
|
||||
ret.pop_front();
|
||||
std::vector<Node*> Node::descendants() {
|
||||
std::vector<Node*>&& ret = sequence_traversed();
|
||||
ret.erase(ret.begin());
|
||||
return ret;
|
||||
}
|
||||
QVector<Node*> deep_traversed(const QVector<Node*>& nodes) {
|
||||
QVector<Node*> result;
|
||||
if (nodes.isEmpty())
|
||||
std::vector<Node*> deep_traversed(const std::vector<Node*>& nodes) {
|
||||
std::vector<Node*> result;
|
||||
if (nodes.empty())
|
||||
return result;
|
||||
QStack<Node*> stack;
|
||||
std::stack<Node*> stack;
|
||||
for (Node* node : nodes) {
|
||||
if (node)
|
||||
stack.push_front(node);
|
||||
stack.push(node);
|
||||
}
|
||||
while (!stack.isEmpty()) {
|
||||
Node* node = stack.pop();
|
||||
result.append(node);
|
||||
while (!stack.empty()) {
|
||||
Node* node = stack.top();
|
||||
stack.pop();
|
||||
result.push_back(node);
|
||||
// 逆序压入子节点,保证从左到右的遍历顺序
|
||||
for (int i = node->sons.size() - 1; i >= 0; --i) {
|
||||
stack.push(node->sons[i]);
|
||||
@@ -114,14 +119,14 @@ QVector<Node*> deep_traversed(const QVector<Node*>& nodes) {
|
||||
#define ReMain (pos - total_height)
|
||||
int Tree_Model::height() {
|
||||
int total_height = 0;
|
||||
QStack<QPair<Node*, int>> stack;
|
||||
std::stack<std::pair<Node*, int>> stack;
|
||||
for (Node* node : roots) {
|
||||
if (node)
|
||||
stack.push_front({node, 0});
|
||||
stack.push({node, 0});
|
||||
}
|
||||
Node* cur{};
|
||||
int deep{};
|
||||
while (!stack.isEmpty()) {
|
||||
while (!stack.empty()) {
|
||||
auto t = stack.top();
|
||||
cur = t.first;
|
||||
deep = t.second;
|
||||
@@ -135,16 +140,16 @@ int Tree_Model::height() {
|
||||
}
|
||||
return total_height;
|
||||
}
|
||||
Tree_Pos get_pos(int pos, const QVector<Node*>& roots, int space) {
|
||||
Tree_Pos get_pos(int pos, const std::vector<Node*>& roots, int space) {
|
||||
int total_height = 0;
|
||||
QStack<QPair<Node*, int>> stack;
|
||||
std::stack<std::pair<Node*, int>> stack;
|
||||
for (Node* node : roots) {
|
||||
if (node)
|
||||
stack.push_front({node, 0});
|
||||
stack.push({node, 0});
|
||||
}
|
||||
Node* cur{};
|
||||
int deep{};
|
||||
while (!stack.isEmpty()) {
|
||||
while (!stack.empty()) {
|
||||
auto t = stack.top();
|
||||
cur = t.first;
|
||||
deep = t.second;
|
||||
@@ -161,13 +166,14 @@ Tree_Pos get_pos(int pos, const QVector<Node*>& roots, int space) {
|
||||
}
|
||||
return Tree_Pos{cur, deep, total_height, ReMain, stack};
|
||||
}
|
||||
void select_node(const QVector<Node*>& roots, int view_y, int length, int space, Node_Call_Back call_back) {
|
||||
void select_node(const std::vector<Node*>& roots, int view_y, int length, int space, Node_Call_Back call_back) {
|
||||
auto ret = get_pos(view_y, roots, space);
|
||||
QStack<QPair<Node*, int>>& stack = ret.rest;
|
||||
std::stack<std::pair<Node*, int>>& stack = ret.rest;
|
||||
int cur_inside_y = ret.node_pos;
|
||||
int cur_inside_end = cur_inside_y + length;
|
||||
while (!stack.isEmpty()) {
|
||||
auto [cur, depth] = stack.pop();
|
||||
while (!stack.empty()) {
|
||||
auto [cur, depth] = stack.top();
|
||||
stack.pop();
|
||||
if (cur->expand) {
|
||||
for (int i = cur->sons.size() - 1; i >= 0; --i) {
|
||||
stack.push({cur->sons[i], depth + 1});
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#pragma once
|
||||
#include <QStack>
|
||||
#include <QVector>
|
||||
#include <QString>
|
||||
#include <functional>
|
||||
#include <stack>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
namespace Psc {
|
||||
class Node {
|
||||
public:
|
||||
@@ -18,16 +21,16 @@ public:
|
||||
Node* root();
|
||||
int get_deep();
|
||||
// 遍历值
|
||||
QVector<Node*> deep_traversed();
|
||||
QVector<Node*> sequence_traversed();
|
||||
QVector<Node*> descendants();
|
||||
std::vector<Node*> deep_traversed();
|
||||
std::vector<Node*> sequence_traversed();
|
||||
std::vector<Node*> descendants();
|
||||
Node* par = nullptr;
|
||||
QVector<Node*> sons;
|
||||
std::vector<Node*> sons;
|
||||
QString text;
|
||||
bool expand = true;
|
||||
int height = 20;
|
||||
void add_child(Node* child) {
|
||||
sons.append(child);
|
||||
sons.push_back(child);
|
||||
child->par = this;
|
||||
}
|
||||
};
|
||||
@@ -39,11 +42,11 @@ struct Tree_Pos {
|
||||
int pos() {
|
||||
return node_pos + offset;
|
||||
}
|
||||
QStack<QPair<Node*, int>> rest;
|
||||
std::stack<std::pair<Node*, int>> rest;
|
||||
};
|
||||
class Tree_Model {
|
||||
public:
|
||||
QVector<Node*> roots;
|
||||
std::vector<Node*> roots;
|
||||
int tab_pixel_size = 8;
|
||||
int png_len = 20;
|
||||
int tab_width = 10;
|
||||
@@ -53,8 +56,8 @@ public:
|
||||
return 1000;
|
||||
}
|
||||
};
|
||||
Tree_Pos get_pos(int pos, const QVector<Node*>& roots, int space);
|
||||
QVector<Node*> deep_traversed(const QVector<Node*>& nodes);
|
||||
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 QVector<Node*>& roots, int view_y, int length, int space, Node_Call_Back call_back);
|
||||
void select_node(const std::vector<Node*>& roots, int view_y, int length, int space, Node_Call_Back call_back);
|
||||
} // namespace Psc
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
#include <QDebug>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QQueue>
|
||||
#include <QStack>
|
||||
#include <queue>
|
||||
#include <stack>
|
||||
#include "../../component/SVG.h"
|
||||
#include "Tree_Model.h"
|
||||
namespace Psc {
|
||||
@@ -31,7 +31,7 @@ Tree_View* create_Tree_View() {
|
||||
}
|
||||
n1->add_child(n2);
|
||||
}
|
||||
roots.append(n1);
|
||||
roots.push_back(n1);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -21,11 +21,11 @@ Frame_Less_Widget::Frame_Less_Widget(QWidget* parent) : QWidget(parent) {
|
||||
bottom_margin = 16;
|
||||
right_margin = 16;
|
||||
left_margin = 16;
|
||||
shapes.append({Qt::SizeFDiagCursor, Qt::SizeVerCursor, Qt::SizeBDiagCursor,
|
||||
Qt::SizeHorCursor, Qt::ArrowCursor, Qt::SizeHorCursor,
|
||||
Qt::SizeBDiagCursor, Qt::SizeVerCursor, Qt::SizeFDiagCursor,
|
||||
Qt::ArrowCursor});
|
||||
change_sizes.append({[this]() {
|
||||
shapes = {Qt::SizeFDiagCursor, Qt::SizeVerCursor, Qt::SizeBDiagCursor,
|
||||
Qt::SizeHorCursor, Qt::ArrowCursor, Qt::SizeHorCursor,
|
||||
Qt::SizeBDiagCursor, Qt::SizeVerCursor, Qt::SizeFDiagCursor,
|
||||
Qt::ArrowCursor};
|
||||
change_sizes = {[this]() {
|
||||
// R11
|
||||
setGeometry(start_x + dx, start_y + dy, qMax(start_w - dx, get_min_width()), qMax(start_h - dy, get_min_height()));
|
||||
},
|
||||
@@ -62,7 +62,7 @@ Frame_Less_Widget::Frame_Less_Widget(QWidget* parent) : QWidget(parent) {
|
||||
},
|
||||
[]() {
|
||||
// null
|
||||
}});
|
||||
}};
|
||||
}
|
||||
int Frame_Less_Widget::get_min_width() {
|
||||
return 0;
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
#include <QColor>
|
||||
#include <QDebug>
|
||||
#include <QLinearGradient>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <QPixmap>
|
||||
#include <QString>
|
||||
#include <QWidget>
|
||||
@@ -39,8 +39,8 @@ public:
|
||||
int start_w{};
|
||||
int start_h{};
|
||||
int dx{}, dy{};
|
||||
QList<Qt::CursorShape> shapes;
|
||||
QList<change_size> change_sizes;
|
||||
std::vector<Qt::CursorShape> shapes;
|
||||
std::vector<change_size> change_sizes;
|
||||
int radius;
|
||||
QColor background_color = QColor(150, 150, 150, 130);
|
||||
virtual int get_min_width();
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
#include <QGraphicsDropShadowEffect>
|
||||
#include <QLineEdit>
|
||||
#include <QMainWindow>
|
||||
#include <QMap>
|
||||
#include <map>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QPainterPath>
|
||||
#include <QProxyStyle>
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QVector>
|
||||
#include <vector>
|
||||
#include <QWidget>
|
||||
#include <optional>
|
||||
enum class Layout_Item_Type {
|
||||
@@ -49,7 +49,7 @@ struct Layout {
|
||||
int prefix = 8, suffix = 8;
|
||||
int space = 8;
|
||||
int second_prefix = 8, second_suffix = 8;
|
||||
QVector<Layout_Info> infos;
|
||||
std::vector<Layout_Info> infos;
|
||||
enum Type {
|
||||
Prefix_Space,
|
||||
Surfix_Space,
|
||||
@@ -76,16 +76,16 @@ struct Layout {
|
||||
return {second_start, start, second_len, len};
|
||||
}
|
||||
};
|
||||
QMap<int, Pos> cache;
|
||||
std::map<int, Pos> cache;
|
||||
std::optional<Pos> get(int key) {
|
||||
auto iter = cache.find(key);
|
||||
if (iter == cache.end()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return *iter;
|
||||
return iter->second;
|
||||
}
|
||||
void cacl(int len, int second_len) {
|
||||
QVector<Pos> ret(infos.size());
|
||||
std::vector<Pos> ret(infos.size());
|
||||
int total_fixed_pixel_size = 0;
|
||||
int total_weight = 0;
|
||||
int show_size = 0;
|
||||
@@ -183,7 +183,7 @@ struct Paintable {
|
||||
bool show = true;
|
||||
};
|
||||
struct Base : QWidget {
|
||||
QVector<Paintable*> paintAbles;
|
||||
std::vector<Paintable*> paintAbles;
|
||||
void paintEvent(QPaintEvent* event) override {
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
Reference in New Issue
Block a user