From: Joel Holdsworth Date: Thu, 18 Apr 2013 21:25:36 +0000 (+0100) Subject: Replaced std::pair with CursorPair X-Git-Tag: pulseview-0.1.0~38 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=b42d25c43e52c900cbdd3e5cde0282961b8721e7;p=pulseview.git Replaced std::pair with CursorPair --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d9ec8f2..7bc13e05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -121,6 +121,7 @@ set(pulseview_SOURCES pv/toolbars/samplingbar.cpp pv/view/analogsignal.cpp pv/view/cursor.cpp + pv/view/cursorpair.cpp pv/view/header.cpp pv/view/logicsignal.cpp pv/view/ruler.cpp diff --git a/pv/view/cursor.h b/pv/view/cursor.h index be779c00..2bedb5e9 100644 --- a/pv/view/cursor.h +++ b/pv/view/cursor.h @@ -48,7 +48,7 @@ private: public: /** * Constructor. - * @param colour A reference to the colour of this cursor. + * @param view A reference to the view that owns this cursor pair. * @param time The time to set the flag to. */ Cursor(const View &view, double time); diff --git a/pv/view/cursorpair.cpp b/pv/view/cursorpair.cpp new file mode 100644 index 00000000..7fe90c7b --- /dev/null +++ b/pv/view/cursorpair.cpp @@ -0,0 +1,56 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2013 Joel Holdsworth + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "cursorpair.h" + +#include "view.h" + +namespace pv { +namespace view { + +CursorPair::CursorPair(const View &view) : + _first(view, 0.0), + _second(view, 1.0), + _view(view) +{ +} + +const Cursor& CursorPair::first() const +{ + return _first; +} + +Cursor& CursorPair::first() +{ + return _first; +} + +const Cursor& CursorPair::second() const +{ + return _second; +} + +Cursor& CursorPair::second() +{ + return _second; +} + +} // namespace view +} // namespace pv diff --git a/pv/view/cursorpair.h b/pv/view/cursorpair.h new file mode 100644 index 00000000..8c721bb6 --- /dev/null +++ b/pv/view/cursorpair.h @@ -0,0 +1,68 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2013 Joel Holdsworth + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef PULSEVIEW_PV_VIEW_CURSORPAIR_H +#define PULSEVIEW_PV_VIEW_CURSORPAIR_H + +#include "cursor.h" + +class QPainter; + +namespace pv { +namespace view { + +class CursorPair +{ +public: + /** + * Constructor. + * @param view A reference to the view that owns this cursor pair. + */ + CursorPair(const View &view); + + /** + * Returns a reference to the first cursor. + */ + Cursor& first(); + + /** + * Returns a reference to the first cursor. + */ + const Cursor& first() const; + + /** + * Returns a reference to the second cursor. + */ + Cursor& second(); + + /** + * Returns a reference to the second cursor. + */ + const Cursor& second() const; + +private: + Cursor _first, _second; + const View &_view; +}; + +} // namespace view +} // namespace pv + +#endif // PULSEVIEW_PV_VIEW_CURSORPAIR_H diff --git a/pv/view/ruler.cpp b/pv/view/ruler.cpp index 9e639383..0322af8a 100644 --- a/pv/view/ruler.cpp +++ b/pv/view/ruler.cpp @@ -186,14 +186,13 @@ void Ruler::mousePressEvent(QMouseEvent *e) _grabbed_marker = NULL; if (_view.cursors_shown()) { - std::pair &cursors = - _view.cursors(); - if (cursors.first.get_label_rect( + CursorPair &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(); } } } @@ -209,9 +208,9 @@ void Ruler::draw_cursors(QPainter &p, unsigned int prefix) return; const QRect r = rect(); - pair &cursors = _view.cursors(); - cursors.first.paint_label(p, r, prefix); - cursors.second.paint_label(p, r, prefix); + CursorPair &cursors = _view.cursors(); + cursors.first().paint_label(p, r, prefix); + cursors.second().paint_label(p, r, prefix); } void Ruler::draw_hover_mark(QPainter &p) diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 95b8a5be..9c793bb8 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -72,8 +72,7 @@ View::View(SigSession &session, QWidget *parent) : _v_offset(0), _updating_scroll(false), _show_cursors(false), - _cursors(pair(Cursor(*this, 0.0), - Cursor(*this, 1.0))), + _cursors(*this), _hover_point(-1, -1) { connect(horizontalScrollBar(), SIGNAL(valueChanged(int)), @@ -86,9 +85,9 @@ View::View(SigSession &session, QWidget *parent) : connect(&_session, SIGNAL(data_updated()), this, SLOT(data_updated())); - connect(&_cursors.first, SIGNAL(time_changed()), + connect(&_cursors.first(), SIGNAL(time_changed()), this, SLOT(marker_time_changed())); - connect(&_cursors.second, SIGNAL(time_changed()), + connect(&_cursors.second(), SIGNAL(time_changed()), this, SLOT(marker_time_changed())); connect(_header, SIGNAL(signals_moved()), @@ -162,7 +161,7 @@ void View::show_cursors(bool show) _viewport->update(); } -std::pair& View::cursors() +CursorPair& View::cursors() { return _cursors; } diff --git a/pv/view/view.h b/pv/view/view.h index 980ccf1f..4eb255a2 100644 --- a/pv/view/view.h +++ b/pv/view/view.h @@ -23,12 +23,10 @@ #include -#include - #include #include -#include "cursor.h" +#include "cursorpair.h" namespace pv { @@ -101,7 +99,7 @@ public: /** * Returns a reference to the pair of cursors. */ - std::pair& cursors(); + CursorPair& cursors(); const QPoint& hover_point() const; @@ -157,7 +155,7 @@ private: bool _updating_scroll; bool _show_cursors; - std::pair _cursors; + CursorPair _cursors; QPoint _hover_point; }; diff --git a/pv/view/viewport.cpp b/pv/view/viewport.cpp index ba26c3c1..70282d41 100644 --- a/pv/view/viewport.cpp +++ b/pv/view/viewport.cpp @@ -127,9 +127,9 @@ void Viewport::draw_cursors_background(QPainter &p) p.setPen(Qt::NoPen); p.setBrush(QBrush(View::CursorAreaColour)); - const pair &c = _view.cursors(); - const float x1 = (c.first.time() - _view.offset()) / _view.scale(); - const float x2 = (c.second.time() - _view.offset()) / _view.scale(); + const CursorPair &c = _view.cursors(); + const float x1 = (c.first().time() - _view.offset()) / _view.scale(); + const float x2 = (c.second().time() - _view.offset()) / _view.scale(); const int l = (int)max(min(x1, x2), 0.0f); const int r = (int)min(max(x1, x2), (float)width()); @@ -142,9 +142,9 @@ void Viewport::draw_cursors_foreground(QPainter &p) return; const QRect r = rect(); - pair &cursors = _view.cursors(); - cursors.first.paint(p, r); - cursors.second.paint(p, r); + CursorPair &cursors = _view.cursors(); + cursors.first().paint(p, r); + cursors.second().paint(p, r); } void Viewport::on_signals_moved()