命名规范

This commit is contained in:
2026-07-29 12:30:40 +08:00
parent ae07e67619
commit 5a3511bb58
261 changed files with 8776 additions and 8831 deletions
+204
View File
@@ -0,0 +1,204 @@
#include <QApplication>
#include <QWidget>
#ifdef _WINDOWS
#include <QTextCodec>
#include <Windows.h>
#endif
#include <QStyle>
#include <QWidget>
#include <QtWidgets>
#include "Demo_Gallery/export.h"
#include "Renderive/export.h"
namespace Table_Space {
struct Base_Table_Model {
virtual ~Base_Table_Model() = default;
using Len_Type = int;
using Index_Type = int;
enum Expand_Type {
None,
Left_UP,
Right_Down,
};
enum Data_Type {
Parent,
Son,
Normal
};
struct Base_Data {
virtual ~Base_Data() = default;
virtual void paint(QPainter* painter, QRect rect) = 0;
QWidget* widget{};
};
struct Base_Info {
virtual ~Base_Info() = default;
Len_Type len = 0;
virtual void paint(QPainter* painter, QRect rect) = 0;
};
virtual void insert_row(Index_Type pos, std::vector<std::shared_ptr<Base_Info>> rows, Expand_Type expand) = 0;
virtual void insert_col(Index_Type pos, std::vector<std::shared_ptr<Base_Info>> cols, Expand_Type expand) = 0;
virtual void remove_row(Index_Type pos, Index_Type row) = 0;
virtual void remove_col(Index_Type pos, Index_Type col) = 0;
virtual void merge(Index_Type col, Index_Type row, Index_Type col_len, Index_Type row_len) = 0;
virtual void split(Index_Type col, Index_Type row, Index_Type col_len, Index_Type row_len) = 0;
virtual QPoint span(Index_Type col, Index_Type row) = 0; // 获取某一个元素 横跨行数,列数
virtual std::shared_ptr<Base_Data> data(Index_Type col, Index_Type row) = 0;
virtual std::shared_ptr<Base_Data> parent(Index_Type col, Index_Type row) = 0;
virtual Data_Type type(Index_Type col, Index_Type row) = 0;
int col_space = 14;
int row_space = 14;
};
struct Table_Model : public Base_Table_Model {
struct Data : Base_Data {
std::shared_ptr<Data> parent = nullptr;
void paint(QPainter* painter, QRect rect) override {
painter->fillRect(rect, Qt::red);
painter->drawText(rect, Qt::AlignCenter, text);
}
QString text;
Data_Type type;
};
using Dp = std::shared_ptr<Data>;
using Dpl = std::vector<Dp>;
struct Info : Base_Info {
void paint(QPainter* painter, QRect rect) override {
painter->fillRect(rect, Qt::red);
painter->drawText(rect, Qt::AlignCenter, text);
}
QString text;
Dpl data;
};
~Table_Model() override;
void check_all() {}
void insert_row(Index_Type pos, std::vector<std::shared_ptr<Base_Info>> rows, Expand_Type expand) override {}
void insert_col(Index_Type pos, std::vector<std::shared_ptr<Base_Info>> insert_cols, Expand_Type expand) override {}
void remove_row(Index_Type pos, Index_Type num) override {
auto start = rows.begin() + pos;
rows.erase(start, start + num);
const auto n = rows.size();
for (int i = 0; i < n; ++i) {
auto& l = cols.at(i);
auto s = l->data.begin() + pos;
l->data.erase(s, s + num);
}
}
void remove_col(Index_Type pos, Index_Type num) override {
auto start = cols.begin() + pos;
cols.erase(start, start + num);
const auto n = rows.size();
for (int i = 0; i < n; ++i) {
auto& l = rows.at(i);
auto s = l->data.begin() + pos;
l->data.erase(s, s + num);
}
}
void merge(Index_Type col, Index_Type row, Index_Type col_len, Index_Type row_len) override {
const auto par = cols.at(col)->data.at(row);
const auto cn = cols.size();
const auto rn = rows.size();
for (auto c = col; c < cn; ++c) {
for (auto r = row; r < rn; ++r) {
const auto d = cols.at(c)->data.at(r);
d->type = Son;
d->parent = par;
}
}
par->type = Parent;
}
void split(Index_Type col, Index_Type row, Index_Type col_len, Index_Type row_len) override {
const auto cn = cols.size();
const auto rn = rows.size();
for (auto c = col; c < cn; ++c) {
for (auto r = row; r < rn; ++r) {
const auto d = cols.at(c)->data.at(r);
d->type = Normal;
d->parent = d;
}
}
}
QPoint span(Index_Type col, Index_Type row) override {
const auto d = cols.at(col)->data.at(row);
if (d->type == Normal)
return {1, 1};
if (d->type == Son)
return {0, 0};
if (d->type == Parent) {
Index_Type cur_col = col + 1;
while (cur_col < cols.size()) {
auto c = cols.at(cur_col)->data.at(row);
if (c->parent != d)
break;
cur_col++;
}
Index_Type cur_row = row + 1;
while (cur_row < rows.size()) {
auto c = rows.at(col)->data.at(cur_row);
if (c->parent != d)
break;
cur_row++;
}
return {cur_col - col, cur_row - row};
}
printf("span unknown type[%d]!", d->type);
ASSERT(false, "span unknown type!");
}
std::shared_ptr<Base_Data> data(Index_Type col, Index_Type row) override {
return cols.at(col)->data.at(row);
}
std::shared_ptr<Base_Data> parent(Index_Type col, Index_Type row) override {
auto d = cols.at(col)->data.at(row);
return d->parent;
}
Data_Type type(Index_Type col, Index_Type row) override {
auto d = cols.at(col)->data.at(row);
return d->type;
}
private:
std::vector<std::shared_ptr<Info>> cols;
std::vector<std::shared_ptr<Info>> rows;
};
} // namespace Table_Space
class Base_Widget : public QWidget {
public:
Base_Widget() {
// 初始化按钮,放置在 widget 中
QPushButton* btn = new QPushButton("你好", this);
btn->setGeometry(50, 50, 500, 30); // 设置按钮的位置和大小
QPushButton* btn2 = new QPushButton("按钮2", this);
btn2->setGeometry(150, 150, 100, 30); // 这个按钮部分会超出父控件区域
}
protected:
void paintEvent(QPaintEvent* event) override {
QPainter painter(this);
// 设置父控件背景颜色
painter.fillRect(rect(), Qt::black);
// 定义裁剪区域(在父控件内的有效区域)
QRegion region(0, 0, 300, 300); // 设置裁剪区域为 300x300,超出部分隐藏
setMask(region); // 设置掩膜,超出区域将不会显示
QWidget::paintEvent(event); // 默认绘制子控件
}
};
int main(int argc, char* argv[]) {
QApplication app(argc, argv);
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
#ifdef _WINDOWS
SetConsoleOutputCP(CP_UTF8);
system("chcp 65001");
// setbuf(stdout, 0);
#endif
QElapsedTimer timer;
timer.start();
Demo_Gallery w;
// Base_Widget w;
w.resize(1000, 600);
w.show();
// renderive::Graphic g;
// g.resize(1000, 600);
// g.show();
// auto it = new renderive::SelectColorDialog();
// it->resize(1000, 600);
// it->show();
renderive::start_render_scheduler();
qDebug() << "启动耗时 " << timer.elapsed();
// f();
return QApplication::exec();
}