projects
/
pulseview.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
8b45452
)
Wrapped Cursors in a shared_ptr
author
Joel Holdsworth
<joel@airwebreathe.org.uk>
Sat, 18 May 2013 16:33:51 +0000
(17:33 +0100)
committer
Joel Holdsworth
<joel@airwebreathe.org.uk>
Sun, 19 May 2013 08:46:00 +0000
(09:46 +0100)
pv/view/cursor.cpp
patch
|
blob
|
history
pv/view/cursor.h
patch
|
blob
|
history
pv/view/cursorpair.cpp
patch
|
blob
|
history
pv/view/cursorpair.h
patch
|
blob
|
history
pv/view/ruler.cpp
patch
|
blob
|
history
pv/view/ruler.h
patch
|
blob
|
history
pv/view/view.cpp
patch
|
blob
|
history
pv/view/view.h
patch
|
blob
|
history
diff --git
a/pv/view/cursor.cpp
b/pv/view/cursor.cpp
index 7a4272f956642b1129d1c3c37987074ff99cafa7..6eb575e3175cc5128c6af17fbef0279a416a041f 100644
(file)
--- a/
pv/view/cursor.cpp
+++ b/
pv/view/cursor.cpp
@@
-33,6
+33,8
@@
#include <extdef.h>
#include <extdef.h>
+using namespace boost;
+
namespace pv {
namespace view {
namespace pv {
namespace view {
@@
-45,14
+47,16
@@
const int Cursor::Offset = 1;
const int Cursor::ArrowSize = 4;
const int Cursor::ArrowSize = 4;
-Cursor::Cursor(const View &view, double time, Cursor &other) :
- TimeMarker(view, LineColour, time),
- _other(other)
+Cursor::Cursor(const View &view, double time) :
+ TimeMarker(view, LineColour, time)
{
}
QRectF Cursor::get_label_rect(const QRect &rect) const
{
{
}
QRectF Cursor::get_label_rect(const QRect &rect) const
{
+ const shared_ptr<Cursor> other(get_other_cursor());
+ assert(other);
+
const float x = (_time - _view.offset()) / _view.scale();
const QSizeF label_size(
const float x = (_time - _view.offset()) / _view.scale();
const QSizeF label_size(
@@
-62,7
+66,7
@@
QRectF Cursor::get_label_rect(const QRect &rect) const
Cursor::Offset - Cursor::ArrowSize - 0.5f;
const float height = label_size.height();
Cursor::Offset - Cursor::ArrowSize - 0.5f;
const float height = label_size.height();
- if (_time >
_other.
time())
+ if (_time >
other->
time())
return QRectF(x, top, label_size.width(), height);
else
return QRectF(x - label_size.width(), top,
return QRectF(x, top, label_size.width(), height);
else
return QRectF(x - label_size.width(), top,
@@
-72,6
+76,9
@@
QRectF Cursor::get_label_rect(const QRect &rect) const
void Cursor::paint_label(QPainter &p, const QRect &rect,
unsigned int prefix)
{
void Cursor::paint_label(QPainter &p, const QRect &rect,
unsigned int prefix)
{
+ const shared_ptr<Cursor> other(get_other_cursor());
+ assert(other);
+
compute_text_size(p, prefix);
const QRectF r(get_label_rect(rect));
compute_text_size(p, prefix);
const QRectF r(get_label_rect(rect));
@@
-107,9
+114,9
@@
void Cursor::paint_label(QPainter &p, const QRect &rect,
QPointF(r.right() - 1, rect.bottom() - 1),
};
QPointF(r.right() - 1, rect.bottom() - 1),
};
- const QPointF *const points = (_time >
_other.
time()) ?
+ const QPointF *const points = (_time >
other->
time()) ?
left_points : right_points;
left_points : right_points;
- const QPointF *const highlight_points = (_time >
_other.
time()) ?
+ const QPointF *const highlight_points = (_time >
other->
time()) ?
left_highlight_points : right_highlight_points;
if (selected()) {
left_highlight_points : right_highlight_points;
if (selected()) {
@@
-141,5
+148,12
@@
void Cursor::compute_text_size(QPainter &p, unsigned int prefix)
Ruler::format_time(_time, prefix, 2)).size();
}
Ruler::format_time(_time, prefix, 2)).size();
}
+shared_ptr<Cursor> Cursor::get_other_cursor() const
+{
+ const CursorPair &cursors = _view.cursors();
+ return (cursors.first().get() == this) ?
+ cursors.second() : cursors.first();
+}
+
} // namespace view
} // namespace pv
} // namespace view
} // namespace pv
diff --git
a/pv/view/cursor.h
b/pv/view/cursor.h
index 48bf7a0ee930ab49a7975af25d0ed8ba38588afc..89ea1e715e3f1a0c83dc4b2de32056cd32f98bfa 100644
(file)
--- a/
pv/view/cursor.h
+++ b/
pv/view/cursor.h
@@
-23,6
+23,8
@@
#include "timemarker.h"
#include "timemarker.h"
+#include <boost/shared_ptr.hpp>
+
#include <QSizeF>
class QPainter;
#include <QSizeF>
class QPainter;
@@
-49,9
+51,8
@@
public:
* Constructor.
* @param view A reference to the view that owns this cursor pair.
* @param time The time to set the flag to.
* Constructor.
* @param view A reference to the view that owns this cursor pair.
* @param time The time to set the flag to.
- * @param other A reference to the other cursor.
*/
*/
- Cursor(const View &view, double time
, Cursor &other
);
+ Cursor(const View &view, double time);
public:
/**
public:
/**
@@
-73,9
+74,9
@@
public:
private:
void compute_text_size(QPainter &p, unsigned int prefix);
private:
void compute_text_size(QPainter &p, unsigned int prefix);
-private:
- const Cursor &_other;
+ boost::shared_ptr<Cursor> get_other_cursor() const;
+private:
QSizeF _text_size;
};
QSizeF _text_size;
};
diff --git
a/pv/view/cursorpair.cpp
b/pv/view/cursorpair.cpp
index d8af3d76f319e19596e406f2b4aa9deca1f24685..70c7bac9235b41d203b74054036c36dbcd8f8fa9 100644
(file)
--- a/
pv/view/cursorpair.cpp
+++ b/
pv/view/cursorpair.cpp
@@
-25,6
+25,7
@@
#include <algorithm>
#include <algorithm>
+using namespace boost;
using namespace std;
namespace pv {
using namespace std;
namespace pv {
@@
-33,28
+34,18
@@
namespace view {
const int CursorPair::DeltaPadding = 8;
CursorPair::CursorPair(const View &view) :
const int CursorPair::DeltaPadding = 8;
CursorPair::CursorPair(const View &view) :
- _first(
view, 0.0, _second
),
- _second(
view, 1.0, _first
),
+ _first(
new Cursor(view, 0.0)
),
+ _second(
new Cursor(view, 1.0)
),
_view(view)
{
}
_view(view)
{
}
-
const Cursor&
CursorPair::first() const
+
shared_ptr<Cursor>
CursorPair::first() const
{
return _first;
}
{
return _first;
}
-Cursor& CursorPair::first()
-{
- return _first;
-}
-
-const Cursor& CursorPair::second() const
-{
- return _second;
-}
-
-Cursor& CursorPair::second()
+shared_ptr<Cursor> CursorPair::second() const
{
return _second;
}
{
return _second;
}
@@
-82,6
+73,9
@@
QRectF CursorPair::get_label_rect(const QRect &rect) const
void CursorPair::draw_markers(QPainter &p,
const QRect &rect, unsigned int prefix)
{
void CursorPair::draw_markers(QPainter &p,
const QRect &rect, unsigned int prefix)
{
+ assert(_first);
+ assert(_second);
+
compute_text_size(p, prefix);
QRectF delta_rect(get_label_rect(rect));
compute_text_size(p, prefix);
QRectF delta_rect(get_label_rect(rect));
@@
-102,12
+96,12
@@
void CursorPair::draw_markers(QPainter &p,
p.setPen(Cursor::TextColour);
p.drawText(text_rect, Qt::AlignCenter | Qt::AlignVCenter,
p.setPen(Cursor::TextColour);
p.drawText(text_rect, Qt::AlignCenter | Qt::AlignVCenter,
- Ruler::format_time(_second
.time() - _first.
time(), prefix, 2));
+ Ruler::format_time(_second
->time() - _first->
time(), prefix, 2));
}
// Paint the cursor markers
}
// Paint the cursor markers
- _first
.
paint_label(p, rect, prefix);
- _second
.
paint_label(p, rect, prefix);
+ _first
->
paint_label(p, rect, prefix);
+ _second
->
paint_label(p, rect, prefix);
}
void CursorPair::draw_viewport_background(QPainter &p,
}
void CursorPair::draw_viewport_background(QPainter &p,
@@
-128,21
+122,30
@@
void CursorPair::draw_viewport_background(QPainter &p,
void CursorPair::draw_viewport_foreground(QPainter &p,
const QRect &rect)
{
void CursorPair::draw_viewport_foreground(QPainter &p,
const QRect &rect)
{
- _first.paint(p, rect);
- _second.paint(p, rect);
+ assert(_first);
+ assert(_second);
+
+ _first->paint(p, rect);
+ _second->paint(p, rect);
}
void CursorPair::compute_text_size(QPainter &p, unsigned int prefix)
{
}
void CursorPair::compute_text_size(QPainter &p, unsigned int prefix)
{
+ assert(_first);
+ assert(_second);
+
_text_size = p.boundingRect(QRectF(), 0, Ruler::format_time(
_text_size = p.boundingRect(QRectF(), 0, Ruler::format_time(
- _second
.time() - _first.
time(), prefix, 2)).size();
+ _second
->time() - _first->
time(), prefix, 2)).size();
}
pair<float, float> CursorPair::get_cursor_offsets() const
{
}
pair<float, float> CursorPair::get_cursor_offsets() const
{
+ assert(_first);
+ assert(_second);
+
return pair<float, float>(
return pair<float, float>(
- (_first
.
time() - _view.offset()) / _view.scale(),
- (_second
.
time() - _view.offset()) / _view.scale());
+ (_first
->
time() - _view.offset()) / _view.scale(),
+ (_second
->
time() - _view.offset()) / _view.scale());
}
} // namespace view
}
} // namespace view
diff --git
a/pv/view/cursorpair.h
b/pv/view/cursorpair.h
index 42e6e51fa32ca3c764ac521b1d16318983e56825..2e70f7da92b9dca7dec6770713624aefa8cf8b8c 100644
(file)
--- a/
pv/view/cursorpair.h
+++ b/
pv/view/cursorpair.h
@@
-23,6
+23,8
@@
#include "cursor.h"
#include "cursor.h"
+#include <boost/shared_ptr.hpp>
+
#include <QPainter>
class QPainter;
#include <QPainter>
class QPainter;
@@
-43,24
+45,14
@@
public:
CursorPair(const View &view);
/**
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.
+ * Returns a pointer to the first cursor.
*/
*/
-
Cursor& second()
;
+
boost::shared_ptr<Cursor> first() const
;
/**
/**
- * Returns a
reference
to the second cursor.
+ * Returns a
pointer
to the second cursor.
*/
*/
-
const Cursor&
second() const;
+
boost::shared_ptr<Cursor>
second() const;
public:
QRectF get_label_rect(const QRect &rect) const;
public:
QRectF get_label_rect(const QRect &rect) const;
@@
-77,7
+69,7
@@
public:
std::pair<float, float> get_cursor_offsets() const;
private:
std::pair<float, float> get_cursor_offsets() const;
private:
-
Cursor
_first, _second;
+
boost::shared_ptr<Cursor>
_first, _second;
const View &_view;
QSizeF _text_size;
const View &_view;
QSizeF _text_size;
diff --git
a/pv/view/ruler.cpp
b/pv/view/ruler.cpp
index fa5c488e4f576107e51f490b75ec4162b906aeb9..74bc1f979b5ee7b8f04a4643ad8f455bb9d3c1ab 100644
(file)
--- a/
pv/view/ruler.cpp
+++ b/
pv/view/ruler.cpp
@@
-34,6
+34,7
@@
#include <QPainter>
#include <QTextStream>
#include <QPainter>
#include <QTextStream>
+using namespace boost;
using namespace std;
namespace pv {
using namespace std;
namespace pv {
@@
-49,8
+50,7
@@
const int Ruler::FirstSIPrefixPower = -15;
const int Ruler::HoverArrowSize = 5;
Ruler::Ruler(View &parent) :
const int Ruler::HoverArrowSize = 5;
Ruler::Ruler(View &parent) :
- MarginWidget(parent),
- _grabbed_marker(NULL)
+ MarginWidget(parent)
{
setMouseTracking(true);
{
setMouseTracking(true);
@@
-61,8
+61,8
@@
Ruler::Ruler(View &parent) :
void Ruler::clear_selection()
{
CursorPair &cursors = _view.cursors();
void Ruler::clear_selection()
{
CursorPair &cursors = _view.cursors();
- cursors.first()
.
select(false);
- cursors.second()
.
select(false);
+ cursors.first()
->
select(false);
+ cursors.second()
->
select(false);
update();
}
update();
}
@@
-181,32
+181,30
@@
void Ruler::paintEvent(QPaintEvent*)
void Ruler::mouseMoveEvent(QMouseEvent *e)
{
void Ruler::mouseMoveEvent(QMouseEvent *e)
{
- if (!_grabbed_marker)
- return;
-
- _grabbed_marker->set_time(_view.offset() +
- ((double)e->x() + 0.5) * _view.scale());
+ if (shared_ptr<TimeMarker> m = _grabbed_marker.lock())
+ m->set_time(_view.offset() +
+ ((double)e->x() + 0.5) * _view.scale());
}
void Ruler::mousePressEvent(QMouseEvent *e)
{
if (e->buttons() & Qt::LeftButton) {
}
void Ruler::mousePressEvent(QMouseEvent *e)
{
if (e->buttons() & Qt::LeftButton) {
- _grabbed_marker
= NULL
;
+ _grabbed_marker
.reset()
;
clear_selection();
if (_view.cursors_shown()) {
CursorPair &cursors = _view.cursors();
clear_selection();
if (_view.cursors_shown()) {
CursorPair &cursors = _view.cursors();
- if (cursors.first()
.
get_label_rect(
+ if (cursors.first()
->
get_label_rect(
rect()).contains(e->pos()))
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()))
rect()).contains(e->pos()))
- _grabbed_marker =
&
cursors.second();
+ _grabbed_marker = cursors.second();
}
}
- if
(_grabbed_marker
)
-
_grabbed_marker
->select();
+ if
(shared_ptr<TimeMarker> m = _grabbed_marker.lock()
)
+
m
->select();
selection_changed();
}
selection_changed();
}
@@
-214,14
+212,14
@@
void Ruler::mousePressEvent(QMouseEvent *e)
void Ruler::mouseReleaseEvent(QMouseEvent *)
{
void Ruler::mouseReleaseEvent(QMouseEvent *)
{
- _grabbed_marker
= NULL
;
+ _grabbed_marker
.reset()
;
}
void Ruler::draw_hover_mark(QPainter &p)
{
const int x = _view.hover_point().x();
}
void Ruler::draw_hover_mark(QPainter &p)
{
const int x = _view.hover_point().x();
- if (x == -1 ||
_grabbed_marker
)
+ if (x == -1 ||
!_grabbed_marker.expired()
)
return;
p.setPen(QPen(Qt::NoPen));
return;
p.setPen(QPen(Qt::NoPen));
diff --git
a/pv/view/ruler.h
b/pv/view/ruler.h
index ba03f312103fce4c42dfcb518c63ab82c35cade6..7514aeca86672d849f82019b1c257232f6afba16 100644
(file)
--- a/
pv/view/ruler.h
+++ b/
pv/view/ruler.h
@@
-21,6
+21,8
@@
#ifndef PULSEVIEW_PV_VIEW_RULER_H
#define PULSEVIEW_PV_VIEW_RULER_H
#ifndef PULSEVIEW_PV_VIEW_RULER_H
#define PULSEVIEW_PV_VIEW_RULER_H
+#include <boost/weak_ptr.hpp>
+
#include "marginwidget.h"
namespace pv {
#include "marginwidget.h"
namespace pv {
@@
-67,7
+69,7
@@
private slots:
void hover_point_changed();
private:
void hover_point_changed();
private:
-
TimeMarker *
_grabbed_marker;
+
boost::weak_ptr<TimeMarker>
_grabbed_marker;
};
} // namespace view
};
} // namespace view
diff --git
a/pv/view/view.cpp
b/pv/view/view.cpp
index bc82e0b4c4a6c7ab2b9e9e5c3896c81fac66db92..eca6b8eabce92c05575cbefeb1473ea95e424028 100644
(file)
--- a/
pv/view/view.cpp
+++ b/
pv/view/view.cpp
@@
-85,9
+85,9
@@
View::View(SigSession &session, QWidget *parent) :
connect(&_session, SIGNAL(data_updated()),
this, SLOT(data_updated()));
connect(&_session, SIGNAL(data_updated()),
this, SLOT(data_updated()));
- connect(
&_cursors.firs
t(), SIGNAL(time_changed()),
+ connect(
_cursors.first().ge
t(), SIGNAL(time_changed()),
this, SLOT(marker_time_changed()));
this, SLOT(marker_time_changed()));
- connect(
&_cursors.second
(), SIGNAL(time_changed()),
+ connect(
_cursors.second().get
(), SIGNAL(time_changed()),
this, SLOT(marker_time_changed()));
connect(_header, SIGNAL(signals_moved()),
this, SLOT(marker_time_changed()));
connect(_header, SIGNAL(signals_moved()),
@@
-174,8
+174,8
@@
void View::show_cursors(bool show)
void View::centre_cursors()
{
const double time_width = _scale * _viewport->width();
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);
_ruler->update();
_viewport->update();
}
_ruler->update();
_viewport->update();
}
@@
-185,6
+185,11
@@
CursorPair& View::cursors()
return _cursors;
}
return _cursors;
}
+const CursorPair& View::cursors() const
+{
+ return _cursors;
+}
+
const QPoint& View::hover_point() const
{
return _hover_point;
const QPoint& View::hover_point() const
{
return _hover_point;
diff --git
a/pv/view/view.h
b/pv/view/view.h
index 18da73224e952a8bae50421fa59735d21438e419..155c875b777c8143bbd34fe8a88336388214a8ba 100644
(file)
--- a/
pv/view/view.h
+++ b/
pv/view/view.h
@@
-106,6
+106,11
@@
public:
*/
CursorPair& cursors();
*/
CursorPair& cursors();
+ /**
+ * Returns a reference to the pair of cursors.
+ */
+ const CursorPair& cursors() const;
+
const QPoint& hover_point() const;
void normalize_layout();
const QPoint& hover_point() const;
void normalize_layout();