From: Joel Holdsworth Date: Sun, 7 Dec 2014 00:38:07 +0000 (+0000) Subject: View: Store CursorPair in a shared_ptr X-Git-Tag: pulseview-0.3.0~382 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=5c5ce7574062e0d3ad4f7d9dde70b482315d54fb;p=pulseview.git View: Store CursorPair in a shared_ptr --- diff --git a/pv/view/cursor.cpp b/pv/view/cursor.cpp index f4a5df6f..836d0e93 100644 --- a/pv/view/cursor.cpp +++ b/pv/view/cursor.cpp @@ -81,9 +81,10 @@ QRectF Cursor::get_label_rect(const QRect &rect) const shared_ptr Cursor::get_other_cursor() const { - const CursorPair &cursors = view_.cursors(); - return (cursors.first().get() == this) ? - cursors.second() : cursors.first(); + const shared_ptr cursors(view_.cursors()); + assert(cursors); + return (cursors->first().get() == this) ? + cursors->second() : cursors->first(); } } // namespace view diff --git a/pv/view/cursorheader.cpp b/pv/view/cursorheader.cpp index 1a656eb1..076b2a7f 100644 --- a/pv/view/cursorheader.cpp +++ b/pv/view/cursorheader.cpp @@ -71,14 +71,14 @@ void CursorHeader::paintEvent(QPaintEvent*) QPainter p(this); p.setRenderHint(QPainter::Antialiasing); + // The cursor labels are not drawn with the arrows exactly on the + // bottom line of the widget, because then the selection shadow + // would be clipped away. + const QRect r = rect().adjusted(0, 0, 0, -BaselineOffset); + // Draw the cursors - if (view_.cursors_shown()) { - // The cursor labels are not drawn with the arrows exactly on the - // bottom line of the widget, because then the selection shadow - // would be clipped away. - const QRect r = rect().adjusted(0, 0, 0, -BaselineOffset); - view_.cursors().draw_markers(p, r); - } + if (view_.cursors_shown()) + view_.cursors()->draw_markers(p, r); } void CursorHeader::mouseMoveEvent(QMouseEvent *e) @@ -107,13 +107,13 @@ void CursorHeader::mousePressEvent(QMouseEvent *e) clear_selection(); if (view_.cursors_shown()) { - CursorPair &cursors = view_.cursors(); - if (cursors.first()->get_label_rect( + shared_ptr cursors(view_.cursors()); + if (cursors->first()->get_label_rect( rect()).contains(e->pos())) - grabbed_marker_ = cursors.first(); - else if (cursors.second()->get_label_rect( + grabbed_marker_ = cursors->first(); + else if (cursors->second()->get_label_rect( rect()).contains(e->pos())) - grabbed_marker_ = cursors.second(); + grabbed_marker_ = cursors->second(); } if (shared_ptr m = grabbed_marker_.lock()) diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 28408eee..4575d05e 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -104,7 +104,7 @@ View::View(Session &session, QWidget *parent) : tick_period_(0.0), tick_prefix_(0), show_cursors_(false), - cursors_(*this), + cursors_(new CursorPair(*this)), hover_point_(-1, -1) { connect(horizontalScrollBar(), SIGNAL(valueChanged(int)), @@ -121,9 +121,9 @@ View::View(Session &session, QWidget *parent) : connect(&session_, SIGNAL(frame_ended()), this, SLOT(data_updated())); - connect(cursors_.first().get(), SIGNAL(time_changed()), + connect(cursors_->first().get(), SIGNAL(time_changed()), this, SLOT(marker_time_changed())); - connect(cursors_.second().get(), SIGNAL(time_changed()), + connect(cursors_->second().get(), SIGNAL(time_changed()), this, SLOT(marker_time_changed())); connect(header_, SIGNAL(signals_moved()), @@ -198,8 +198,8 @@ const Viewport* View::viewport() const vector< shared_ptr > View::time_items() const { vector< shared_ptr > items; - items.push_back(cursors_.first()); - items.push_back(cursors_.second()); + items.push_back(cursors_->first()); + items.push_back(cursors_->second()); return items; } @@ -357,18 +357,13 @@ void View::show_cursors(bool show) void View::centre_cursors() { const double time_width = scale_ * viewport_->width(); - cursors_.first()->set_time(offset_ + time_width * 0.4); - cursors_.second()->set_time(offset_ + time_width * 0.6); + cursors_->first()->set_time(offset_ + time_width * 0.4); + cursors_->second()->set_time(offset_ + time_width * 0.6); cursorheader_->update(); viewport_->update(); } -CursorPair& View::cursors() -{ - return cursors_; -} - -const CursorPair& View::cursors() const +std::shared_ptr View::cursors() const { return cursors_; } diff --git a/pv/view/view.hpp b/pv/view/view.hpp index a23f2848..026c7683 100644 --- a/pv/view/view.hpp +++ b/pv/view/view.hpp @@ -159,12 +159,7 @@ public: /** * Returns a reference to the pair of cursors. */ - CursorPair& cursors(); - - /** - * Returns a reference to the pair of cursors. - */ - const CursorPair& cursors() const; + std::shared_ptr cursors() const; const QPoint& hover_point() const; @@ -279,7 +274,7 @@ private: unsigned int tick_prefix_; bool show_cursors_; - CursorPair cursors_; + std::shared_ptr cursors_; QPoint hover_point_; diff --git a/pv/view/viewport.cpp b/pv/view/viewport.cpp index f5f0ab59..75902af2 100644 --- a/pv/view/viewport.cpp +++ b/pv/view/viewport.cpp @@ -68,7 +68,7 @@ void Viewport::paintEvent(QPaintEvent*) p.setRenderHint(QPainter::Antialiasing); if (view_.cursors_shown()) - view_.cursors().draw_viewport_background(p, rect()); + view_.cursors()->draw_viewport_background(p, rect()); const RowItemPaintParams pp(0, width(), view_.scale(), view_.offset()); @@ -86,7 +86,7 @@ void Viewport::paintEvent(QPaintEvent*) r->paint_fore(p, pp); if (view_.cursors_shown()) - view_.cursors().draw_viewport_foreground(p, rect()); + view_.cursors()->draw_viewport_foreground(p, rect()); p.end(); }