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