This commit is contained in:
codeboss 2024-10-04 20:02:18 +08:00
parent d416efb5b5
commit be0914c9c1
4 changed files with 24 additions and 16 deletions

View File

@ -257,11 +257,14 @@ void DAGGraph::graph_layer_nodes_sort(int layer_index, QList<std::shared_ptr<DAG
} }
// 当前层次节点排序值修正 // 当前层次节点排序值修正
std::sort(nodes_within_current_layer.begin(), nodes_within_current_layer.end(),
[](std::shared_ptr<DAGOrderHelper> a, std::shared_ptr<DAGOrderHelper> b){ return a->sortNumber() < b->sortNumber(); });
for (auto idx = 1; idx < nodes_within_current_layer.size(); ++idx) { for (auto idx = 1; idx < nodes_within_current_layer.size(); ++idx) {
auto prev = nodes_within_current_layer[idx - 1]; auto prev = nodes_within_current_layer[idx - 1];
auto curr = nodes_within_current_layer[idx]; auto curr = nodes_within_current_layer[idx];
if (prev->sortNumber() == curr->sortNumber()) if (prev->sortNumber() == curr->sortNumber())
curr->setSortNumber(curr->sortNumber() + DBL_MIN); curr->setSortNumber(curr->sortNumber() + 0.000000000000001);
} }
} }

View File

@ -36,11 +36,11 @@ void ActivePresentNode::paint(QPainter* painter, const QStyleOptionGraphicsItem*
PenetrateNode::PenetrateNode(double width, const QString& towards, const QString& to) PenetrateNode::PenetrateNode(double width, const QString& towards, const QString& to)
: __GraphNodeBase(GraphNodeType::PenetrateNode), : __GraphNodeBase(GraphNodeType::PenetrateNode),
width_store(width), from_name(towards), to_name(to) { outline(QSizeF(20, 8)), from_name(towards), to_name(to) {
} }
void PenetrateNode::resizeWidth(double width) { void PenetrateNode::resizeOutline(double w, double h) {
this->width_store = width; this->outline = QSizeF(w, h);
this->update(); this->update();
} }
@ -53,7 +53,7 @@ QString PenetrateNode::nodeTo() const {
} }
QRectF PenetrateNode::boundingRect() const { QRectF PenetrateNode::boundingRect() const {
return QRectF(0, 0, this->width_store, 8); return QRectF(QPointF(), this->outline);
} }
void PenetrateNode::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { void PenetrateNode::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
@ -61,10 +61,11 @@ void PenetrateNode::paint(QPainter* painter, const QStyleOptionGraphicsItem* opt
painter->save(); painter->save();
auto ypos = outline.height() / 2 - 3;
if (this->isHighlighted()) if (this->isHighlighted())
painter->fillRect(QRectF(0, 2, outline.width(), 4), Qt::red); painter->fillRect(QRectF(0, ypos, outline.width(), 4), Qt::red);
else else
painter->fillRect(QRectF(0, 2, outline.width(), 4), Qt::black); painter->fillRect(QRectF(0, ypos, outline.width(), 4), Qt::black);
painter->restore(); painter->restore();
} }
@ -119,8 +120,8 @@ void TransitionCurve::paint(QPainter* painter, const QStyleOptionGraphicsItem* o
painter->save(); painter->save();
painter->setRenderHint(QPainter::Antialiasing); painter->setRenderHint(QPainter::Antialiasing);
auto start_pos = aj_start_pos - QGraphicsItem::pos() + QPointF(0, start_rect.height() / 2); auto start_pos = aj_start_pos - QGraphicsItem::pos() + QPointF(0, (int) start_rect.height() / 2);
auto end_pos = aj_end_pos - QGraphicsItem::pos() + QPointF(0, end_rect.height() / 2); auto end_pos = aj_end_pos - QGraphicsItem::pos() + QPointF(0, (int) end_rect.height() / 2);
auto line_epos = start_pos + QPointF(line_span, 0); auto line_epos = start_pos + QPointF(line_span, 0);
auto control_pos0 = line_epos + QPointF((outline.width() - line_span) / 3, 0); auto control_pos0 = line_epos + QPointF((outline.width() - line_span) / 3, 0);
@ -193,13 +194,16 @@ QList<IGraphNode*> DAGActiveView::layer_nodes_construction(const QHash<IGraphNod
} }
// 对其当前层次节点宽度 // 对其当前层次节点宽度
double curr_layer_width = 0; double curr_layer_width = 0, prev_node_height = 20;
for (auto n : current_nodes_helper.keys()) { for (auto n : current_nodes_helper.keys()) {
curr_layer_width = std::max(curr_layer_width, n->boundingRect().width()); curr_layer_width = std::max(curr_layer_width, n->boundingRect().width());
} }
if (prev_layer_helper.size()) {
prev_node_height = prev_layer_helper.keys().first()->boundingRect().height();
for (auto n : current_nodes_helper.keys()) { for (auto n : current_nodes_helper.keys()) {
if (n->nodeType() == GraphNodeType::PenetrateNode) { if (n->nodeType() == GraphNodeType::PenetrateNode) {
static_cast<PenetrateNode*>(n)->resizeWidth(curr_layer_width); static_cast<PenetrateNode*>(n)->resizeOutline(curr_layer_width, prev_node_height);
}
} }
} }
@ -233,6 +237,7 @@ QList<IGraphNode*> DAGActiveView::layer_nodes_construction(const QHash<IGraphNod
return next_nodes; return next_nodes;
} }
#include <QTextEdit>
void DAGActiveView::updateWithEdges(QList<graph_data::Arrow> arrows) { void DAGActiveView::updateWithEdges(QList<graph_data::Arrow> arrows) {
// 清除当前视图 // 清除当前视图
this->scene_bind.clear(); this->scene_bind.clear();

View File

@ -62,13 +62,13 @@ namespace dags {
}; };
class PenetrateNode : public __GraphNodeBase { class PenetrateNode : public __GraphNodeBase {
private: private:
double width_store = 20; QSizeF outline;
QString from_name, to_name; QString from_name, to_name;
public: public:
PenetrateNode(double width, const QString &from, const QString &to); PenetrateNode(double width, const QString &from, const QString &to);
void resizeWidth(double width); void resizeOutline(double width, double height);
QString nodeFrom() const; QString nodeFrom() const;
QString nodeTo() const; QString nodeTo() const;

View File

@ -50,7 +50,7 @@ int main(int argc, char* argv[]) {
graph_data::Arrow(u8"c中文测试", u8"d中文测试") << graph_data::Arrow(u8"c中文测试", u8"d中文测试") <<
graph_data::Arrow(u8"b中文测试", u8"e中文测试") << graph_data::Arrow(u8"b中文测试", u8"e中文测试") <<
graph_data::Arrow(u8"d中文测试", u8"e中文测试") << graph_data::Arrow(u8"d中文测试", u8"e中文测试") <<
graph_data::Arrow(u8"a中文测试", u8"e中文测试"); graph_data::Arrow(u8"c中文测试", u8"e中文测试");
auto view = new dags::DAGActiveView; auto view = new dags::DAGActiveView;
view->updateWithEdges(arrows); view->updateWithEdges(arrows);
view->show(); view->show();