]> sigrok.org Git - pulseview.git/commitdiff
Split annotation data set into rows, and improved painting.
authorJoel Holdsworth <redacted>
Sun, 2 Feb 2014 17:48:47 +0000 (17:48 +0000)
committerUwe Hermann <redacted>
Sun, 2 Feb 2014 20:57:10 +0000 (21:57 +0100)
This has allowed the removal of Annotation::_row and Annotation::_pd_index

CMakeLists.txt
pv/data/decode/annotation.cpp
pv/data/decode/annotation.h
pv/data/decode/row.cpp [new file with mode: 0644]
pv/data/decode/row.h [new file with mode: 0644]
pv/data/decode/rowdata.cpp [new file with mode: 0644]
pv/data/decode/rowdata.h [new file with mode: 0644]
pv/data/decoderstack.cpp
pv/data/decoderstack.h
pv/view/decodetrace.cpp

index acec89764da6c3453d6c222555e36c11e5c51750..d98ff54c87023717e0ba5660b85b637070b8138a 100644 (file)
@@ -210,6 +210,8 @@ if(ENABLE_DECODE)
                pv/data/decoderstack.cpp
                pv/data/decode/annotation.cpp
                pv/data/decode/decoder.cpp
+               pv/data/decode/row.cpp
+               pv/data/decode/rowdata.cpp
                pv/prop/binding/decoderoptions.cpp
                pv/view/decodetrace.cpp
                pv/widgets/decodergroupbox.cpp
index 4a6890b5a4e519a5aac786d408d97953985a4836..b0517ae69ef9c6a13eefc4bad41efeea08b7d9a0 100644 (file)
@@ -40,7 +40,6 @@ Annotation::Annotation(const srd_proto_data *const pdata) :
        assert(pda);
 
        _format = pda->ann_format;
-       _row = 0;
 
        const char *const *annotations = (char**)pda->ann_text;
        while(*annotations) {
@@ -64,31 +63,11 @@ int Annotation::format() const
        return _format;
 }
 
-int Annotation::row() const
-{
-       return _row;
-}
-
-int Annotation::pd_index() const
-{
-       return _pd_index;
-}
-
 const std::vector<QString>& Annotation::annotations() const
 {
        return _annotations;
 }
 
-void Annotation::set_row(int row)
-{
-       _row = row;
-}
-
-void Annotation::set_pd_index(int pd_index)
-{
-       _pd_index = pd_index;
-}
-
 } // namespace decode
 } // namespace data
 } // namespace pv
index 64e6db57a0b5462e47d94afa955c8891deff069b..6d0a19aeb38b2043e680d8e8bac8440a1e92f2e0 100644 (file)
@@ -39,8 +39,6 @@ public:
        uint64_t start_sample() const;
        uint64_t end_sample() const;
        int format() const;
-       int row() const;
-       int pd_index() const;
        const std::vector<QString>& annotations() const;
 
        void set_row(int row);
@@ -50,8 +48,6 @@ private:
        uint64_t _start_sample;
        uint64_t _end_sample;
        int _format;
-       int _row;
-       int _pd_index;
        std::vector<QString> _annotations; 
 };
 
diff --git a/pv/data/decode/row.cpp b/pv/data/decode/row.cpp
new file mode 100644 (file)
index 0000000..0eee547
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2014 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * 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 "row.h"
+
+namespace pv {
+namespace data {
+namespace decode {
+
+Row::Row() :
+       _decoder(NULL),
+       _row(NULL)
+{
+}
+
+Row::Row(const srd_decoder *decoder, const srd_decoder_annotation_row *row) :
+       _decoder(decoder),
+       _row(row)
+{
+}
+
+const srd_decoder* Row::decoder() const
+{
+       return _decoder;
+}
+
+const srd_decoder_annotation_row* Row::row() const
+{
+       return _row;
+}
+
+bool Row::operator<(const Row &other) const
+{
+       return (_decoder < other._decoder) ||
+               (_decoder == other._decoder && _row < other._row);
+}
+
+} // decode
+} // data
+} // pv
diff --git a/pv/data/decode/row.h b/pv/data/decode/row.h
new file mode 100644 (file)
index 0000000..4ee05f6
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2014 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * 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_DATA_DECODE_ROW_H
+#define PULSEVIEW_PV_DATA_DECODE_ROW_H
+
+#include <vector>
+
+#include "annotation.h"
+
+struct srd_decoder;
+struct srd_decoder_annotation_row;
+
+namespace pv {
+namespace data {
+namespace decode {
+
+class Row
+{
+public:
+       Row();
+
+       Row(const srd_decoder *decoder,
+               const srd_decoder_annotation_row *row = NULL);
+
+       const srd_decoder* decoder() const;
+       const srd_decoder_annotation_row* row() const;
+
+       bool operator<(const Row &other) const;
+
+private:
+       const srd_decoder *_decoder;
+       const srd_decoder_annotation_row *_row;
+};
+
+} // decode
+} // data
+} // pv
+
+#endif // PULSEVIEW_PV_DATA_DECODE_ROW_H
diff --git a/pv/data/decode/rowdata.cpp b/pv/data/decode/rowdata.cpp
new file mode 100644 (file)
index 0000000..a06af61
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2014 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * 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 <boost/bind.hpp>
+
+#include <assert.h>
+
+#include "rowdata.h"
+
+using std::vector;
+
+namespace pv {
+namespace data {
+namespace decode {
+
+RowData::RowData()
+{
+}
+
+uint64_t RowData::get_max_sample() const
+{
+       if (_annotations.empty())
+               return 0;
+       return _annotations.back().end_sample();
+}
+
+void RowData::get_annotation_subset(
+       std::vector<pv::data::decode::Annotation> &dest,
+       uint64_t start_sample, uint64_t end_sample) const
+{
+       const vector<size_t>::const_iterator start_iter =
+               lower_bound(_ann_end_index.begin(),
+                       _ann_end_index.end(), start_sample,
+                       bind(&RowData::index_entry_end_sample_lt,
+                               this, _1, _2));
+
+       const vector<size_t>::const_iterator end_iter =
+               upper_bound(_ann_start_index.begin(),
+                       _ann_start_index.end(), end_sample,
+                       bind(&RowData::index_entry_start_sample_gt,
+                               this, _1, _2));
+
+       for (vector<size_t>::const_iterator i = start_iter;
+               i != _ann_end_index.end() && *i != *end_iter; i++)
+               dest.push_back(_annotations[*i]);
+}
+
+void RowData::push_annotation(const Annotation &a)
+{
+       const size_t offset = _annotations.size();
+       _annotations.push_back(a);
+
+       // Insert the annotation into the start index
+       vector<size_t>::iterator i = _ann_start_index.end();
+       if (!_ann_start_index.empty() &&
+               _annotations[_ann_start_index.back()].start_sample() >
+                       a.start_sample())
+               i = upper_bound(_ann_start_index.begin(),
+                       _ann_start_index.end(), a.start_sample(),
+                       bind(&RowData::index_entry_start_sample_gt,
+                               this, _1, _2));
+
+       _ann_start_index.insert(i, offset);
+
+       // Insert the annotation into the end index
+       vector<size_t>::iterator j = _ann_end_index.end();
+       if (!_ann_end_index.empty() &&
+               _annotations[_ann_end_index.back()].end_sample() <
+                       a.end_sample())
+               j = upper_bound(_ann_end_index.begin(),
+                       _ann_end_index.end(), a.end_sample(),
+                       bind(&RowData::index_entry_end_sample_gt,
+                               this, _1, _2));
+
+       _ann_end_index.insert(j, offset);
+}
+
+bool RowData::index_entry_start_sample_gt(
+       const uint64_t sample, const size_t index) const
+{
+       assert(index < _annotations.size());
+       return _annotations[index].start_sample() > sample;
+}
+
+bool RowData::index_entry_end_sample_lt(
+       const size_t index, const uint64_t sample) const
+{
+       assert(index < _annotations.size());
+       return _annotations[index].end_sample() < sample;
+}
+
+bool RowData::index_entry_end_sample_gt(
+       const uint64_t sample, const size_t index) const
+{
+       assert(index < _annotations.size());
+       return _annotations[index].end_sample() > sample;
+}
+
+} // decode
+} // data
+} // pv
diff --git a/pv/data/decode/rowdata.h b/pv/data/decode/rowdata.h
new file mode 100644 (file)
index 0000000..3cd454e
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2014 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * 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_DATA_DECODE_ROWDATA_H
+#define PULSEVIEW_PV_DATA_DECODE_ROWDATA_H
+
+#include <vector>
+
+#include "annotation.h"
+
+namespace pv {
+namespace data {
+namespace decode {
+
+class RowData
+{
+public:
+       RowData();
+
+public:
+       uint64_t get_max_sample() const;
+
+       /**
+        * Extracts sorted annotations between two period into a vector.
+        */
+       void get_annotation_subset(
+               std::vector<pv::data::decode::Annotation> &dest,
+               uint64_t start_sample, uint64_t end_sample) const;
+
+       void push_annotation(const Annotation& a);
+
+private:
+       bool index_entry_start_sample_gt(
+               const uint64_t sample, const size_t index) const;
+       bool index_entry_end_sample_lt(
+               const size_t index, const uint64_t sample) const;
+       bool index_entry_end_sample_gt(
+               const uint64_t sample, const size_t index) const;
+
+private:
+       std::vector<Annotation> _annotations;
+
+       /**
+        * _ann_start_index and _ann_end_index contain lists of annotions
+        * (represented by offsets in the _annotations vector), sorted in
+        * ascending ordered by the start_sample and end_sample respectively.
+        */
+       std::vector<size_t> _ann_start_index, _ann_end_index;
+};
+
+}
+} // data
+} // pv
+
+#endif // PULSEVIEW_PV_DATA_DECODE_ROWDATA_H
index 1c6b3c6b57c792e5c040e62593a0bd8161eef94e..323f5cc2cd4b45397cf18e1cd59560dc0ef17f33 100644 (file)
@@ -20,7 +20,6 @@
 
 #include <libsigrokdecode/libsigrokdecode.h>
 
-#include <boost/bind.hpp>
 #include <boost/foreach.hpp>
 #include <boost/thread/thread.hpp>
 
@@ -40,10 +39,16 @@ using boost::lock_guard;
 using boost::mutex;
 using boost::shared_ptr;
 using std::deque;
+using std::make_pair;
+using std::max;
 using std::min;
 using std::list;
+using std::map;
+using std::pair;
 using std::vector;
 
+using namespace pv::data::decode;
+
 namespace pv {
 namespace data {
 
@@ -80,8 +85,6 @@ void DecoderStack::push(boost::shared_ptr<decode::Decoder> decoder)
 
 void DecoderStack::remove(int index)
 {
-       using pv::data::decode::Decoder;
-
        assert(index >= 0);
        assert(index < (int)_stack.size());
 
@@ -100,27 +103,47 @@ int64_t DecoderStack::samples_decoded() const
        return _samples_decoded;
 }
 
+std::vector<Row> DecoderStack::get_rows() const
+{
+       lock_guard<mutex> lock(_mutex);
+
+       vector<Row> rows;
+
+       BOOST_FOREACH (const shared_ptr<decode::Decoder> &dec, _stack)
+       {
+               assert(dec);
+               const srd_decoder *const decc = dec->decoder();
+               assert(dec->decoder());
+
+               // Add a row for the decoder if it doesn't have a row list
+               if (!decc->annotation_rows)
+                       rows.push_back(Row(decc));
+
+               // Add the decoder rows
+               for (const GSList *l = decc->annotation_rows; l; l = l->next)
+               {
+                       const srd_decoder_annotation_row *const ann_row =
+                               (srd_decoder_annotation_row *)l->data;
+                       assert(ann_row);
+                       rows.push_back(Row(decc, ann_row));
+               }
+       }
+
+       return rows;
+}
+
 void DecoderStack::get_annotation_subset(
        std::vector<pv::data::decode::Annotation> &dest,
-       uint64_t start_sample, uint64_t end_sample) const
+       const Row &row, uint64_t start_sample,
+       uint64_t end_sample) const
 {
        lock_guard<mutex> lock(_mutex);
 
-       const vector<size_t>::const_iterator start_iter =
-               lower_bound(_ann_end_index.begin(),
-                       _ann_end_index.end(), start_sample,
-                       bind(&DecoderStack::index_entry_end_sample_lt,
-                               this, _1, _2));
-
-       const vector<size_t>::const_iterator end_iter =
-               upper_bound(_ann_start_index.begin(),
-                       _ann_start_index.end(), end_sample,
-                       bind(&DecoderStack::index_entry_start_sample_gt,
-                               this, _1, _2));
-
-       for (vector<size_t>::const_iterator i = start_iter;
-               i != _ann_end_index.end() && *i != *end_iter; i++)
-               dest.push_back(_annotations[*i]);
+       std::map<const Row, decode::RowData>::const_iterator iter =
+               _rows.find(row);
+       if (iter != _rows.end())
+               (*iter).second.get_annotation_subset(dest,
+                       start_sample, end_sample);
 }
 
 QString DecoderStack::error_message()
@@ -129,6 +152,14 @@ QString DecoderStack::error_message()
        return _error_message;
 }
 
+void DecoderStack::clear()
+{
+       _samples_decoded = 0;
+       _error_message = QString();
+       _rows.clear();
+       _class_rows.clear();
+}
+
 void DecoderStack::begin_decode()
 {
        shared_ptr<pv::view::LogicSignal> logic_signal;
@@ -137,10 +168,39 @@ void DecoderStack::begin_decode()
        _decode_thread.interrupt();
        _decode_thread.join();
 
-       _samples_decoded = 0;
-
        clear();
 
+       // Add classes
+       BOOST_FOREACH (const shared_ptr<decode::Decoder> &dec, _stack)
+       {
+               assert(dec);
+               const srd_decoder *const decc = dec->decoder();
+               assert(dec->decoder());
+
+               // Add a row for the decoder if it doesn't have a row list
+               if (!decc->annotation_rows)
+                       _rows[Row(decc)] = decode::RowData();
+
+               // Add the decoder rows
+               for (const GSList *l = decc->annotation_rows; l; l = l->next)
+               {
+                       const srd_decoder_annotation_row *const ann_row =
+                               (srd_decoder_annotation_row *)l->data;
+                       assert(ann_row);
+
+                       const Row row(decc, ann_row);
+
+                       // Add a new empty row data object
+                       _rows[row] = decode::RowData();
+
+                       // Map out all the classes
+                       for (const GSList *ll = ann_row->ann_classes;
+                               ll; ll = ll->next)
+                               _class_rows[make_pair(decc,
+                                       GPOINTER_TO_INT(ll->data))] = row;
+               }
+       }
+
        // We get the logic data of the first probe in the list.
        // This works because we are currently assuming all
        // LogicSignals have the same data/snapshot
@@ -163,18 +223,16 @@ void DecoderStack::begin_decode()
                data);
 }
 
-void DecoderStack::clear()
-{
-       _annotations.clear();
-       _ann_start_index.clear();
-       _ann_end_index.clear();
-}
-
 uint64_t DecoderStack::get_max_sample_count() const
 {
-       if (_annotations.empty())
-               return 0;
-       return _annotations.back().end_sample();
+       uint64_t max_sample_count = 0;
+
+       for (map<const Row, RowData>::const_iterator i = _rows.begin();
+               i != _rows.end(); i++)
+               max_sample_count = max(max_sample_count,
+                       (*i).second.get_max_sample());
+
+       return max_sample_count;
 }
 
 void DecoderStack::decode_proc(shared_ptr<data::Logic> data)
@@ -196,9 +254,6 @@ void DecoderStack::decode_proc(shared_ptr<data::Logic> data)
        const unsigned int chunk_sample_count =
                DecodeChunkLength / snapshot->unit_size();
 
-       // Clear error message upon every new session run
-       _error_message = QString();
-
        // Create the session
        srd_session_new(&session);
        assert(session);
@@ -257,100 +312,47 @@ void DecoderStack::decode_proc(shared_ptr<data::Logic> data)
        srd_session_destroy(session);
 }
 
-bool DecoderStack::index_entry_start_sample_gt(
-       const uint64_t sample, const size_t index) const
-{
-       assert(index < _annotations.size());
-       return _annotations[index].start_sample() > sample;
-}
-
-bool DecoderStack::index_entry_end_sample_lt(
-       const size_t index, const uint64_t sample) const
-{
-       assert(index < _annotations.size());
-       return _annotations[index].end_sample() < sample;
-}
-
-bool DecoderStack::index_entry_end_sample_gt(
-       const uint64_t sample, const size_t index) const
-{
-       assert(index < _annotations.size());
-       return _annotations[index].end_sample() > sample;
-}
-
-void DecoderStack::insert_annotation_into_start_index(
-       const pv::data::decode::Annotation &a, const size_t storage_offset)
-{
-       vector<size_t>::iterator i = _ann_start_index.end();
-       if (!_ann_start_index.empty() &&
-               _annotations[_ann_start_index.back()].start_sample() >
-                       a.start_sample())
-               i = upper_bound(_ann_start_index.begin(),
-                       _ann_start_index.end(), a.start_sample(),
-                       bind(&DecoderStack::index_entry_start_sample_gt,
-                               this, _1, _2));
-
-       _ann_start_index.insert(i, storage_offset);
-}
-
-void DecoderStack::insert_annotation_into_end_index(
-       const pv::data::decode::Annotation &a, const size_t storage_offset)
-{
-       vector<size_t>::iterator i = _ann_end_index.end();
-       if (!_ann_end_index.empty() &&
-               _annotations[_ann_end_index.back()].end_sample() <
-                       a.end_sample())
-               i = upper_bound(_ann_end_index.begin(),
-                       _ann_end_index.end(), a.end_sample(),
-                       bind(&DecoderStack::index_entry_end_sample_gt,
-                               this, _1, _2));
-
-       _ann_end_index.insert(i, storage_offset);
-}
-
 void DecoderStack::annotation_callback(srd_proto_data *pdata, void *decoder)
 {
-       using pv::data::decode::Annotation;
-
-       GSList *l, *ll;
-       int row, ann_class, idx = 0;
-       struct srd_decoder_annotation_row *ann_row;
-       struct srd_decoder *decc;
-
        assert(pdata);
        assert(decoder);
 
        DecoderStack *const d = (DecoderStack*)decoder;
+       assert(d);
 
        lock_guard<mutex> lock(d->_mutex);
 
-       Annotation a = Annotation(pdata);
-
-       decc = pdata->pdo->di->decoder;
-       BOOST_FOREACH(const shared_ptr<decode::Decoder> &dec, d->stack()) {
-               if (dec->decoder() == decc)
-                       break;
-               idx++;
-       }
-       a.set_pd_index(idx);
-
-       for (l = decc->annotation_rows, row = 0; l; l = l->next, row++)
+       const Annotation a(pdata);
+
+       // Find the row
+       assert(pdata->pdo);
+       assert(pdata->pdo->di);
+       const srd_decoder *const decc = pdata->pdo->di->decoder;
+       assert(decc);
+
+       map<const Row, decode::RowData>::iterator row_iter = d->_rows.end();
+       
+       // Try looking up the sub-row of this class
+       const map<pair<const srd_decoder*, int>, Row>::const_iterator r =
+               d->_class_rows.find(make_pair(decc, a.format()));
+       if (r != d->_class_rows.end())
+               row_iter = d->_rows.find((*r).second);
+       else
        {
-               ann_row = (struct srd_decoder_annotation_row *)l->data;
-
-               for (ll = ann_row->ann_classes, ann_class = 0; ll;
-                                       ll = ll->next, ann_class++)
-               {
-                       if (GPOINTER_TO_INT(ll->data) == a.format())
-                               a.set_row(row);
-               }
+               // Failing that, use the decoder as a key
+               row_iter = d->_rows.find(Row(decc));    
        }
 
-       const size_t offset = d->_annotations.size();
-       d->_annotations.push_back(a);
+       assert(row_iter != d->_rows.end());
+       if (row_iter == d->_rows.end()) {
+               qDebug() << "Unexpected annotation: decoder = " << decc <<
+                       ", format = " << a.format();
+               assert(0);
+               return;
+       }
 
-       d->insert_annotation_into_start_index(a, offset);
-       d->insert_annotation_into_end_index(a, offset);
+       // Add the annotation
+       (*row_iter).second.push_annotation(a);
 
        d->new_decode_data();
 }
index 9d032ad9756080c19fc8a83d5bc6f407260b906e..80ad64cdfebf90398213d801ef184f128cc7d4bd 100644 (file)
 #include <QObject>
 #include <QString>
 
+#include <pv/data/decode/row.h>
+#include <pv/data/decode/rowdata.h>
+
 struct srd_decoder;
+struct srd_decoder_annotation_row;
 struct srd_probe;
 struct srd_proto_data;
 
@@ -74,12 +78,15 @@ public:
 
        int64_t samples_decoded() const;
 
+       std::vector<decode::Row> get_rows() const;
+
        /**
         * Extracts sorted annotations between two period into a vector.
         */
        void get_annotation_subset(
                std::vector<pv::data::decode::Annotation> &dest,
-               uint64_t start_sample, uint64_t end_sample) const;
+               const decode::Row &row, uint64_t start_sample,
+               uint64_t end_sample) const;
 
        QString error_message();
 
@@ -92,20 +99,6 @@ public:
 private:
        void decode_proc(boost::shared_ptr<data::Logic> data);
 
-       bool index_entry_start_sample_gt(
-               const uint64_t sample, const size_t index) const;
-       bool index_entry_end_sample_lt(
-               const size_t index, const uint64_t sample) const;
-       bool index_entry_end_sample_gt(
-               const uint64_t sample, const size_t index) const;
-
-       void insert_annotation_into_start_index(
-               const pv::data::decode::Annotation &a,
-               const size_t storage_offset);
-       void insert_annotation_into_end_index(
-               const pv::data::decode::Annotation &a,
-               const size_t storage_offset);
-
        static void annotation_callback(srd_proto_data *pdata,
                void *decoder);
 
@@ -126,14 +119,10 @@ private:
 
        mutable boost::mutex _mutex;
        int64_t _samples_decoded;
-       std::vector<pv::data::decode::Annotation> _annotations;
 
-       /**
-        * _ann_start_index and _ann_end_index contain lists of annotions
-        * (represented by offsets in the _annotations vector), sorted in
-        * ascending ordered by the start_sample and end_sample respectively.
-        */
-       std::vector<size_t> _ann_start_index, _ann_end_index;
+       std::map<const decode::Row, decode::RowData> _rows;
+
+       std::map<std::pair<const srd_decoder*, int>, decode::Row> _class_rows;
 
        QString _error_message;
 
index ce62ab6ff99098694b51db38e50554f5adb3be99..161eb9668bdd2217a43e8173d396138ea2908c6e 100644 (file)
@@ -122,7 +122,7 @@ void DecodeTrace::paint_back(QPainter &p, int left, int right)
 
 void DecodeTrace::paint_mid(QPainter &p, int left, int right)
 {
-       using pv::data::decode::Annotation;
+       using namespace pv::data::decode;
 
        const double scale = _view->scale();
        assert(scale > 0);
@@ -143,40 +143,43 @@ void DecodeTrace::paint_mid(QPainter &p, int left, int right)
                samples_per_pixel, 0.0);
 
        QFontMetrics m(QApplication::font());
-       const int h = (m.boundingRect(QRect(), 0, "Tg").height() * 5) / 4;
+       const int text_height =  m.boundingRect(QRect(), 0, "Tg").height();
+       const int annotation_height = (text_height * 5) / 4;
+       const int row_height = (text_height * 6) / 4;
 
        assert(_decoder_stack);
        const QString err = _decoder_stack->error_message();
        if (!err.isEmpty())
        {
                draw_error(p, err, left, right);
-               draw_unresolved_period(p, h, left, right, samples_per_pixel,
-                       pixels_offset);
+               draw_unresolved_period(p, annotation_height, left, right,
+                       samples_per_pixel, pixels_offset);
                return;
        }
 
+       // Iterate through the rows
        assert(_view);
-       const int y = get_y();
+       int y = get_y();
 
        assert(_decoder_stack);
-       vector<Annotation> annotations;
-       _decoder_stack->get_annotation_subset(annotations,
-               start_sample, end_sample);
 
-       BOOST_FOREACH(const Annotation &a, annotations)
+       const vector<Row> rows(_decoder_stack->get_rows());
+       BOOST_FOREACH (const Row &row, rows)
        {
-               // Every stacked PD is 60 pixels further down.
-               int y_stack_offset = a.pd_index() * 60;
-
-               // Every annotation row is 20 pixels further down.
-               int y_ann_row_offset = a.row() * 20;
-
-               draw_annotation(a, p, get_text_colour(), h, left, right,
-                       samples_per_pixel, pixels_offset,
-                       y + y_stack_offset + y_ann_row_offset);
+               vector<Annotation> annotations;
+               _decoder_stack->get_annotation_subset(annotations, row,
+                       start_sample, end_sample);
+               if (!annotations.empty()) {
+                       BOOST_FOREACH(const Annotation &a, annotations)
+                               draw_annotation(a, p, get_text_colour(),
+                                       annotation_height, left, right,
+                                       samples_per_pixel, pixels_offset, y);
+                       y += row_height;
+               }
        }
 
-       draw_unresolved_period(p, h, left, right,
+       // Draw the hatching
+       draw_unresolved_period(p, annotation_height, left, right,
                samples_per_pixel, pixels_offset);
 }