自定义内存分配池
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user