From: Soeren Apel Date: Mon, 24 Aug 2015 10:32:11 +0000 (+0200) Subject: Fix #510 by disabling removal of the last decoder from the popup X-Git-Tag: pulseview-0.3.0~135 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=ff59fa2c05db46e78c7fd0240223664fe0b2ad9b;p=pulseview.git Fix #510 by disabling removal of the last decoder from the popup --- diff --git a/pv/view/decodetrace.cpp b/pv/view/decodetrace.cpp index 36e7a104..7bb62b2b 100644 --- a/pv/view/decodetrace.cpp +++ b/pv/view/decodetrace.cpp @@ -642,13 +642,17 @@ void DecodeTrace::create_decoder_form(int index, const srd_decoder *const decoder = dec->decoder(); assert(decoder); + const bool decoder_deletable = index > 0; + pv::widgets::DecoderGroupBox *const group = new pv::widgets::DecoderGroupBox( - QString::fromUtf8(decoder->name)); + QString::fromUtf8(decoder->name), nullptr, decoder_deletable); group->set_decoder_visible(dec->shown()); - delete_mapper_.setMapping(group, index); - connect(group, SIGNAL(delete_decoder()), &delete_mapper_, SLOT(map())); + if (decoder_deletable) { + delete_mapper_.setMapping(group, index); + connect(group, SIGNAL(delete_decoder()), &delete_mapper_, SLOT(map())); + } show_hide_mapper_.setMapping(group, index); connect(group, SIGNAL(show_hide_decoder()), diff --git a/pv/widgets/decodergroupbox.cpp b/pv/widgets/decodergroupbox.cpp index 7127ba13..81e5e902 100644 --- a/pv/widgets/decodergroupbox.cpp +++ b/pv/widgets/decodergroupbox.cpp @@ -30,7 +30,7 @@ namespace pv { namespace widgets { -DecoderGroupBox::DecoderGroupBox(QString title, QWidget *parent) : +DecoderGroupBox::DecoderGroupBox(QString title, QWidget *parent, bool isDeletable) : QWidget(parent), layout_(new QGridLayout), show_hide_button_(QIcon(":/icons/decoder-shown.svg"), QString(), this) @@ -51,13 +51,15 @@ DecoderGroupBox::DecoderGroupBox(QString title, QWidget *parent) : this, SIGNAL(show_hide_decoder())); toolbar->addWidget(&show_hide_button_); - QPushButton *const delete_button = new QPushButton( - QIcon(":/icons/decoder-delete.svg"), QString(), this); - delete_button->setFlat(true); - delete_button->setIconSize(QSize(16, 16)); - connect(delete_button, SIGNAL(clicked()), - this, SIGNAL(delete_decoder())); - toolbar->addWidget(delete_button); + if (isDeletable) { + QPushButton *const delete_button = new QPushButton( + QIcon(":/icons/decoder-delete.svg"), QString(), this); + delete_button->setFlat(true); + delete_button->setIconSize(QSize(16, 16)); + connect(delete_button, SIGNAL(clicked()), + this, SIGNAL(delete_decoder())); + toolbar->addWidget(delete_button); + } } void DecoderGroupBox::add_layout(QLayout *layout) diff --git a/pv/widgets/decodergroupbox.hpp b/pv/widgets/decodergroupbox.hpp index 73bc9971..75544318 100644 --- a/pv/widgets/decodergroupbox.hpp +++ b/pv/widgets/decodergroupbox.hpp @@ -34,7 +34,8 @@ class DecoderGroupBox : public QWidget Q_OBJECT public: - DecoderGroupBox(QString title, QWidget *parent = nullptr); + DecoderGroupBox(QString title, QWidget *parent = nullptr, + bool isDeletable = true); void add_layout(QLayout *layout);