From: Joel Holdsworth Date: Wed, 25 Dec 2013 23:41:12 +0000 (+0000) Subject: Store annotations as objects emplaced in the vector X-Git-Tag: pulseview-0.2.0~182 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=db62bbfda512aeddca5b9d7b5960e9cf24b8859c;p=pulseview.git Store annotations as objects emplaced in the vector Rather than as pointers to heap allocated objects. --- diff --git a/pv/data/decoderstack.cpp b/pv/data/decoderstack.cpp index 6d5e4e19..e588ad6b 100644 --- a/pv/data/decoderstack.cpp +++ b/pv/data/decoderstack.cpp @@ -94,8 +94,7 @@ int64_t DecoderStack::samples_decoded() const return _samples_decoded; } -const vector< shared_ptr > - DecoderStack::annotations() const +const vector DecoderStack::annotations() const { lock_guard lock(_mutex); return _annotations; @@ -150,7 +149,7 @@ uint64_t DecoderStack::get_max_sample_count() const { if (_annotations.empty()) return 0; - return _annotations.back()->end_sample(); + return _annotations.back().end_sample(); } void DecoderStack::decode_proc(shared_ptr data) @@ -237,9 +236,8 @@ void DecoderStack::annotation_callback(srd_proto_data *pdata, void *decoder) DecoderStack *const d = (DecoderStack*)decoder; - shared_ptr a(new Annotation(pdata)); lock_guard lock(d->_mutex); - d->_annotations.push_back(a); + d->_annotations.push_back(Annotation(pdata)); d->new_decode_data(); } diff --git a/pv/data/decoderstack.h b/pv/data/decoderstack.h index dc656f91..58dd8871 100644 --- a/pv/data/decoderstack.h +++ b/pv/data/decoderstack.h @@ -78,8 +78,7 @@ public: int64_t samples_decoded() const; - const std::vector< boost::shared_ptr > - annotations() const; + const std::vector annotations() const; QString error_message(); @@ -112,8 +111,7 @@ private: mutable boost::mutex _mutex; int64_t _samples_decoded; - std::vector< boost::shared_ptr > - _annotations; + std::vector _annotations; QString _error_message; boost::thread _decode_thread; diff --git a/pv/view/decode/annotation.cpp b/pv/view/decode/annotation.cpp index 6a2f74a6..4a110e67 100644 --- a/pv/view/decode/annotation.cpp +++ b/pv/view/decode/annotation.cpp @@ -81,7 +81,7 @@ uint64_t Annotation::end_sample() const void Annotation::paint(QPainter &p, QColor text_color, int h, int left, int right, double samples_per_pixel, double pixels_offset, - int y) + int y) const { const double start = _start_sample / samples_per_pixel - pixels_offset; @@ -103,7 +103,7 @@ void Annotation::paint(QPainter &p, QColor text_color, int h, } void Annotation::draw_instant(QPainter &p, QColor fill, QColor outline, - QColor text_color, int h, double x, int y) + QColor text_color, int h, double x, int y) const { const QString text = _annotations.empty() ? QString() : _annotations.back(); @@ -120,7 +120,7 @@ void Annotation::draw_instant(QPainter &p, QColor fill, QColor outline, } void Annotation::draw_range(QPainter &p, QColor fill, QColor outline, - QColor text_color, int h, double start, double end, int y) + QColor text_color, int h, double start, double end, int y) const { const double top = y + .5 - h / 2; const double bottom = y + .5 + h / 2; @@ -159,7 +159,7 @@ void Annotation::draw_range(QPainter &p, QColor fill, QColor outline, QString best_annotation; int best_width = 0; - BOOST_FOREACH(QString &a, _annotations) { + BOOST_FOREACH(const QString &a, _annotations) { const int w = p.boundingRect(QRectF(), 0, a).width(); if (w <= rect.width() && w > best_width) best_annotation = a, best_width = w; diff --git a/pv/view/decode/annotation.h b/pv/view/decode/annotation.h index d0282114..94b7dc90 100644 --- a/pv/view/decode/annotation.h +++ b/pv/view/decode/annotation.h @@ -47,15 +47,15 @@ public: void paint(QPainter &p, QColor text_colour, int text_height, int left, int right, double samples_per_pixel, double pixels_offset, - int y); + int y) const; private: void draw_instant(QPainter &p, QColor fill, QColor outline, - QColor text_color, int h, double x, int y); + QColor text_color, int h, double x, int y) const; void draw_range(QPainter &p, QColor fill, QColor outline, QColor text_color, int h, double start, - double end, int y); + double end, int y) const; private: uint64_t _start_sample; diff --git a/pv/view/decodetrace.cpp b/pv/view/decodetrace.cpp index 2d641827..e582d1a8 100644 --- a/pv/view/decodetrace.cpp +++ b/pv/view/decodetrace.cpp @@ -135,12 +135,10 @@ void DecodeTrace::paint_mid(QPainter &p, int left, int right) const int y = get_y(); assert(_decoder_stack); - vector< shared_ptr > annotations(_decoder_stack->annotations()); - BOOST_FOREACH(shared_ptr a, annotations) { - assert(a); - a->paint(p, get_text_colour(), h, left, right, + vector annotations(_decoder_stack->annotations()); + BOOST_FOREACH(const Annotation &a, annotations) + a.paint(p, get_text_colour(), h, left, right, samples_per_pixel, pixels_offset, y); - } draw_unresolved_period(p, h, left, right, samples_per_pixel, pixels_offset);