]> sigrok.org Git - pulseview.git/commitdiff
Connect DecodeSignal and DecoderOutputView
authorSoeren Apel <redacted>
Sun, 8 Dec 2019 17:34:52 +0000 (18:34 +0100)
committerSoeren Apel <redacted>
Tue, 10 Dec 2019 10:15:05 +0000 (11:15 +0100)
pv/data/decodesignal.cpp
pv/data/decodesignal.hpp
pv/views/decoder_output/QHexView.cpp
pv/views/decoder_output/view.cpp
pv/views/decoder_output/view.hpp

index 2f14914529e2fcf348ab0a0d1cede95f62769af0..c497b862e638375b7aa54ad4b252f71260bc0c5a 100644 (file)
@@ -567,10 +567,13 @@ void DecodeSignal::get_binary_data_chunks_merged(uint32_t segment_id,
 
                // Determine overall size before copying to resize dest vector only once
                uint64_t size = 0;
+               int matches = 0;
                for (const DecodeBinaryData& d : segment->binary_data)
-                       if ((d.sample >= start_sample) && (d.sample < end_sample))
+                       if ((d.sample >= start_sample) && (d.sample < end_sample)) {
                                size += d.data.size();
-               dest->reserve(size);
+                               matches++;
+                       }
+               dest->resize(size);
 
                uint64_t index = 0;
                for (const DecodeBinaryData& d : segment->binary_data)
@@ -1371,7 +1374,7 @@ void DecodeSignal::binary_callback(srd_proto_data *pdata, void *decode_signal)
        DecodeBinaryData* bin_data = &(segment->binary_data.back());
 
        bin_data->sample = pdata->start_sample;
-       bin_data->data.reserve(pdb->size);
+       bin_data->data.resize(pdb->size);
        memcpy(bin_data->data.data(), pdb->data, pdb->size);
 
        ds->new_binary_data(ds->current_segment_id_);
index cd0f6faa4b3e472a7b2ca70378b363ea0a60a5e8..6162a20e808989939563df048f09badb23807ec8 100644 (file)
@@ -205,7 +205,7 @@ private:
 
 Q_SIGNALS:
        void new_annotations(); // TODO Supply segment for which they belong to
-       void new_binary_data(uint32_t segment_id);
+       void new_binary_data(unsigned int segment_id);
        void decode_reset();
        void decode_finished();
        void channels_updated();
index 2289a07d509fd6bff90d5360b42b4a67a42df9ab..53120ce07b75a6cdc296cd6a88e9e87510bdd8fd 100644 (file)
@@ -79,12 +79,16 @@ void QHexView::showFromOffset(size_t offset)
                int cursorY = cursorPos_ / (2 * BYTES_PER_LINE);
                verticalScrollBar() -> setValue(cursorY);
        }
+
+       viewport()->update();
 }
 
 void QHexView::clear()
 {
        verticalScrollBar()->setValue(0);
        data_ = nullptr;
+
+       viewport()->update();
 }
 
 QSize QHexView::getFullSize() const
@@ -121,7 +125,7 @@ void QHexView::paintEvent(QPaintEvent *event)
        // Fill widget background
        painter.fillRect(event->rect(), palette().color(QPalette::Base));
 
-       if (!data_) {
+       if (!data_ || (data_->size() == 0)) {
                painter.setPen(palette().color(QPalette::Text));
                QString s = tr("No data available");
                int x = (areaSize.width() - fontMetrics().boundingRect(s).width()) / 2;
index 5c3b031dec55f4c7dbd6f56d551ad1b58ee4cc77..0eda5659325b264e0180a897f09a9da119004100 100644 (file)
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <libsigrokdecode/libsigrokdecode.h>
+#include <climits>
 
+#include <QByteArray>
+#include <QDebug>
 #include <QLabel>
 #include <QMenu>
 #include <QToolBar>
 #include <QVBoxLayout>
 
+#include <libsigrokdecode/libsigrokdecode.h>
+
 #include "view.hpp"
 #include "QHexView.hpp"
 
 #include "pv/session.hpp"
 #include "pv/util.hpp"
 
+using pv::data::DecodeSignal;
 using pv::data::SignalBase;
 using pv::util::TimeUnit;
 using pv::util::Timestamp;
 
+using std::numeric_limits;
 using std::shared_ptr;
 
 namespace pv {
@@ -47,7 +53,9 @@ View::View(Session &session, bool is_main_view, QMainWindow *parent) :
        signal_selector_(new QComboBox()),
        format_selector_(new QComboBox()),
        stacked_widget_(new QStackedWidget()),
-       hex_view_(new QHexView())
+       hex_view_(new QHexView()),
+       signal_(nullptr),
+       merged_data_(new QByteArray())
 {
        QVBoxLayout *root_layout = new QVBoxLayout(this);
        root_layout->setContentsMargins(0, 0, 0, 0);
@@ -70,6 +78,12 @@ View::View(Session &session, bool is_main_view, QMainWindow *parent) :
        // Add widget stack
        root_layout->addWidget(stacked_widget_);
        stacked_widget_->addWidget(hex_view_);
+       stacked_widget_->setCurrentIndex(0);
+
+       connect(signal_selector_, SIGNAL(currentIndexChanged(int)),
+               this, SLOT(on_selected_signal_changed(int)));
+
+       hex_view_->setData(merged_data_);
 
        reset_view_state();
 }
@@ -91,12 +105,14 @@ void View::reset_view_state()
 void View::clear_signals()
 {
        ViewBase::clear_signalbases();
+       signal_ = nullptr;
 }
 
 void View::clear_decode_signals()
 {
        signal_selector_->clear();
        format_selector_->setCurrentIndex(0);
+       signal_ = nullptr;
 }
 
 void View::add_decode_signal(shared_ptr<data::DecodeSignal> signal)
@@ -104,15 +120,20 @@ void View::add_decode_signal(shared_ptr<data::DecodeSignal> signal)
        connect(signal.get(), SIGNAL(name_changed(const QString&)),
                this, SLOT(on_signal_name_changed(const QString&)));
 
-       signal_selector_->addItem(signal->name(), QVariant::fromValue(signal.get()));
+       signal_selector_->addItem(signal->name(), QVariant::fromValue((void*)signal.get()));
 }
 
 void View::remove_decode_signal(shared_ptr<data::DecodeSignal> signal)
 {
-       int index = signal_selector_->findData(QVariant::fromValue(signal.get()));
+       int index = signal_selector_->findData(QVariant::fromValue((void*)signal.get()));
 
        if (index != -1)
                signal_selector_->removeItem(index);
+
+       if (signal.get() == signal_) {
+               signal_ = nullptr;
+               update_data();
+       }
 }
 
 void View::save_settings(QSettings &settings) const
@@ -127,6 +148,39 @@ void View::restore_settings(QSettings &settings)
        (void)settings;
 }
 
+void View::update_data()
+{
+       if (!signal_) {
+               merged_data_->clear();
+               return;
+       }
+
+       if (signal_->get_binary_data_chunk_count(current_segment_) == 0) {
+               merged_data_->clear();
+               return;
+       }
+
+       vector<uint8_t> data;
+       signal_->get_binary_data_chunks_merged(current_segment_, 0,
+               numeric_limits<uint64_t>::max(), &data);
+
+       merged_data_->resize(data.size());
+       memcpy(merged_data_->data(), data.data(), data.size());
+}
+
+void View::on_selected_signal_changed(int index)
+{
+       if (signal_)
+               disconnect(signal_, SIGNAL(new_binary_data(unsigned int)));
+
+       signal_ = (DecodeSignal*)signal_selector_->itemData(index).value<void*>();
+       update_data();
+
+       if (signal_)
+               connect(signal_, SIGNAL(new_binary_data(unsigned int)),
+                       this, SLOT(on_new_binary_data(unsigned int)));
+}
+
 void View::on_signal_name_changed(const QString &name)
 {
        SignalBase *sb = qobject_cast<SignalBase*>(QObject::sender());
@@ -137,6 +191,12 @@ void View::on_signal_name_changed(const QString &name)
                signal_selector_->setItemText(index, name);
 }
 
+void View::on_new_binary_data(unsigned int segment_id)
+{
+       if (segment_id == current_segment_)
+               update_data();
+}
+
 } // namespace decoder_output
 } // namespace views
 } // namespace pv
index ff636e03070d3915dca9716fb491bc2b7e990007..9f86cfae24b114756aed7d21744f633ff0a3b444 100644 (file)
@@ -24,6 +24,7 @@
 #include <QStackedWidget>
 
 #include <pv/views/viewbase.hpp>
+#include <pv/data/decodesignal.hpp>
 
 #include "QHexView.hpp"
 
@@ -61,13 +62,22 @@ public:
        virtual void save_settings(QSettings &settings) const;
        virtual void restore_settings(QSettings &settings);
 
+private:
+       void update_data();
+
 private Q_SLOTS:
+       void on_selected_signal_changed(int index);
        void on_signal_name_changed(const QString &name);
+       void on_new_binary_data(unsigned int segment_id);
 
 private:
        QComboBox *signal_selector_, *format_selector_;
        QStackedWidget *stacked_widget_;
        QHexView *hex_view_;
+
+       data::DecodeSignal *signal_;
+
+       QByteArray *merged_data_;
 };
 
 } // namespace decoder_output