X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=pv%2Fview%2Fheader.cpp;h=fdfd896f2ac877339412ed415722cb5789101ba7;hb=aca64cac30aadeee90510958b081cd385221b258;hp=361a60c138208911ce5bf044c685f8d0c4a3d52a;hpb=eae6e30af53f6b3e42dc5be212c82870078276b0;p=pulseview.git diff --git a/pv/view/header.cpp b/pv/view/header.cpp index 361a60c1..fdfd896f 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -24,7 +24,8 @@ #include "signal.h" #include "../sigsession.h" -#include +#include +#include #include #include @@ -38,6 +39,7 @@ using std::max; using std::make_pair; using std::pair; using std::shared_ptr; +using std::stable_sort; using std::vector; namespace pv { @@ -106,13 +108,30 @@ void Header::clear_selection() update(); } +void Header::show_popup(const shared_ptr &item) +{ + using pv::widgets::Popup; + + Popup *const p = item->create_popup(&_view); + if (!p) + return; + + const QPoint pt(width() - BaselineOffset, item->get_y()); + p->set_position(mapToGlobal(pt), Popup::Right); + p->show(); +} + void Header::paintEvent(QPaintEvent*) { // The trace labels are not drawn with the arrows exactly on the // left edge of the widget, because then the selection shadow // would be clipped away. const int w = width() - BaselineOffset; - const vector< shared_ptr > row_items(_view.child_items()); + + vector< shared_ptr > row_items(_view.child_items()); + stable_sort(row_items.begin(), row_items.end(), + [](const shared_ptr &a, const shared_ptr &b) { + return a->v_offset() < b->v_offset(); }); QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); @@ -181,8 +200,6 @@ void Header::mousePressEvent(QMouseEvent *event) void Header::mouseReleaseEvent(QMouseEvent *event) { - using pv::widgets::Popup; - assert(event); if (event->button() == Qt::LeftButton) { if (_dragging) @@ -191,15 +208,8 @@ void Header::mouseReleaseEvent(QMouseEvent *event) { const shared_ptr mouse_over_row_item = get_mouse_over_row_item(event->pos()); - if (mouse_over_row_item) { - const int w = width() - BaselineOffset; - Popup *const p = - mouse_over_row_item->create_popup(&_view); - p->set_position(mapToGlobal(QPoint(w, - mouse_over_row_item->get_y())), - Popup::Right); - p->show(); - } + if (mouse_over_row_item) + show_popup(mouse_over_row_item); } _dragging = false; @@ -258,9 +268,14 @@ void Header::leaveEvent(QEvent*) void Header::contextMenuEvent(QContextMenuEvent *event) { const shared_ptr r = get_mouse_over_row_item(_mouse_point); + if (!r) + return; + + QMenu *const menu = r->create_context_menu(this); + if (!menu) + return; - if (r) - r->create_context_menu(this)->exec(event->globalPos()); + menu->exec(event->globalPos()); } void Header::keyPressEvent(QKeyEvent *e)