]> sigrok.org Git - pulseview.git/commitdiff
Fix #1488 by clearing the labels when categories are clicked
authorSoeren Apel <redacted>
Sat, 11 Jan 2020 23:12:58 +0000 (00:12 +0100)
committerUwe Hermann <redacted>
Sun, 12 Jan 2020 15:46:45 +0000 (16:46 +0100)
pv/subwindows/decoder_selector/subwindow.cpp

index ff2a6c8acad28856b7ee6eacdf5b9efcff3c8102..20603ed2b958a7eed50a3d1d530cc3da67b1b8a8 100644 (file)
@@ -222,38 +222,47 @@ vector<const srd_decoder*> SubWindow::get_decoders_providing(const char* output)
 
 void SubWindow::on_item_changed(const QModelIndex& index)
 {
-       if (!index.isValid())
-               return;
+       QString decoder_name, id, longname, desc, doc, tags;
 
-       QModelIndex id_index = index.model()->index(index.row(), 2, index.parent());
-       QString decoder_name = index.model()->data(id_index, Qt::DisplayRole).toString();
+       // If the parent isn't valid, a category title was clicked
+       if (index.isValid() && index.parent().isValid()) {
+               QModelIndex id_index = index.model()->index(index.row(), 2, index.parent());
+               decoder_name = index.model()->data(id_index, Qt::DisplayRole).toString();
 
-       if (decoder_name.isEmpty())
-               return;
+               if (decoder_name.isEmpty())
+                       return;
 
-       const srd_decoder* d = srd_decoder_get_by_id(decoder_name.toUtf8());
+               const srd_decoder* d = srd_decoder_get_by_id(decoder_name.toUtf8());
 
-       const QString id = QString::fromUtf8(d->id);
-       const QString longname = QString::fromUtf8(d->longname);
-       const QString desc = QString::fromUtf8(d->desc);
-       const QString doc = QString::fromUtf8(srd_decoder_doc_get(d)).trimmed();
+               id = QString::fromUtf8(d->id);
+               longname = QString::fromUtf8(d->longname);
+               desc = QString::fromUtf8(d->desc);
+               doc = QString::fromUtf8(srd_decoder_doc_get(d)).trimmed();
 
-       QString tags;
 #if DECODERS_HAVE_TAGS
-       for (GSList* li = (GSList*)d->tags; li; li = li->next) {
-               QString s = (li == (GSList*)d->tags) ?
-                       tr((char*)li->data) :
-                       QString(tr(", %1")).arg(tr((char*)li->data));
-               tags.append(s);
-       }
+               for (GSList* li = (GSList*)d->tags; li; li = li->next) {
+                       QString s = (li == (GSList*)d->tags) ?
+                               tr((char*)li->data) :
+                               QString(tr(", %1")).arg(tr((char*)li->data));
+                       tags.append(s);
+               }
 #endif
+       } else
+               doc = QString(tr(initial_notice));
+
+       if (!id.isEmpty())
+               info_label_header_->setText(
+                       QString("<span style='font-size:large'><b>%1 (%2)</b></span><br><i>%3</i>")
+                       .arg(longname, id, desc));
+       else
+               info_label_header_->clear();
 
-       info_label_header_->setText(QString("<span style='font-size:large'><b>%1 (%2)</b></span><br><i>%3</i>")
-               .arg(longname, id, desc));
        info_label_body_->setText(doc);
 
        if (!tags.isEmpty())
                info_label_footer_->setText(tr("<p align='right'>Tags: %1</p>").arg(tags));
+       else
+               info_label_footer_->clear();
 }
 
 void SubWindow::on_item_activated(const QModelIndex& index)