]> sigrok.org Git - pulseview.git/commitdiff
Fix #1089 by updating the signal labels and group labels
authorSoeren Apel <redacted>
Thu, 8 Feb 2018 15:32:19 +0000 (16:32 +0100)
committerSoeren Apel <redacted>
Thu, 8 Feb 2018 15:32:19 +0000 (16:32 +0100)
Group names currently don't change, so this doesn't do much
but they may change in the future, so it's useful to do anyway.

pv/data/signalbase.cpp
pv/data/signalbase.hpp
pv/popups/channels.cpp
pv/popups/channels.hpp

index f421e7609de8f1ccb7bfce95905bec16b62cf7a6..5aec9ba884677e924cb8e0d1d533a62c4ef467b2 100644 (file)
@@ -81,6 +81,14 @@ QString SignalBase::internal_name() const
        return internal_name_;
 }
 
+QString SignalBase::display_name() const
+{
+       if (name() != internal_name_)
+               return name() + " (" + internal_name_ + ")";
+       else
+               return name();
+}
+
 void SignalBase::set_name(QString name)
 {
        if (channel_)
index 6a3af14b3f0115c64dee8f1438fc21accfc37168..7375c1dbfb149b360962fee6f0a6e846752132fa 100644 (file)
@@ -140,6 +140,12 @@ public:
         */
        QString internal_name() const;
 
+       /**
+        * Produces a string for this signal that can be used for display,
+        * i.e. it contains one or both of the signal/internal names.
+        */
+       QString display_name() const;
+
        /**
         * Sets the name of the signal.
         */
index ca142d68582a433eb0626661a459e8000653a5c6..3fb90ae760bac81287b6850353d06809dea01c5e 100644 (file)
 
 #include "channels.hpp"
 
+#include <pv/session.hpp>
 #include <pv/binding/device.hpp>
 #include <pv/data/signalbase.hpp>
 #include <pv/devices/device.hpp>
-#include <pv/session.hpp>
-#include <pv/views/trace/signal.hpp>
-
-#include <libsigrokcxx/libsigrokcxx.hpp>
-
-using namespace Qt;
 
+using std::make_shared;
 using std::map;
+using std::out_of_range;
 using std::shared_ptr;
-using std::make_shared;
 using std::unordered_set;
 using std::vector;
 
@@ -77,9 +73,8 @@ Channels::Channels(Session &session, QWidget *parent) :
 
        // Populate channel groups
        for (auto entry : device->channel_groups()) {
-               shared_ptr<ChannelGroup> group = entry.second;
-               // Make a set of signals, and removed this signals from the
-               // signal map.
+               const shared_ptr<ChannelGroup> group = entry.second;
+               // Make a set of signals and remove these signals from the signal map
                vector< shared_ptr<SignalBase> > group_sigs;
                for (auto channel : group->channels()) {
                        const auto iter = signal_map.find(channel);
@@ -130,14 +125,13 @@ void Channels::set_all_channels(bool set)
 {
        updating_channels_ = true;
 
-       for (map<QCheckBox*, shared_ptr<SignalBase> >::const_iterator i =
-                       check_box_signal_map_.begin();
-                       i != check_box_signal_map_.end(); i++) {
-               const shared_ptr<SignalBase> sig = (*i).second;
+       for (auto entry : check_box_signal_map_) {
+               QCheckBox *cb = entry.first;
+               const shared_ptr<SignalBase> sig = entry.second;
                assert(sig);
 
                sig->set_enabled(set);
-               (*i).first->setChecked(set);
+               cb->setChecked(set);
        }
 
        updating_channels_ = false;
@@ -156,10 +150,13 @@ void Channels::populate_group(shared_ptr<ChannelGroup> group,
                binding = make_shared<Device>(group);
 
        // Create a title if the group is going to have any content
-       if ((!sigs.empty() || (binding && !binding->properties().empty())) &&
-               group)
-               layout_.addRow(new QLabel(
-                       QString("<h3>%1</h3>").arg(group->name().c_str())));
+       if ((!sigs.empty() || (binding && !binding->properties().empty())) && group)
+       {
+               QLabel *label = new QLabel(
+                       QString("<h3>%1</h3>").arg(group->name().c_str()));
+               layout_.addRow(label);
+               group_label_map_[group] = label;
+       }
 
        // Create the channel group grid
        QGridLayout *const channel_grid = create_channel_group_grid(sigs);
@@ -181,7 +178,7 @@ QGridLayout* Channels::create_channel_group_grid(
        for (const shared_ptr<SignalBase>& sig : sigs) {
                assert(sig);
 
-               QCheckBox *const checkbox = new QCheckBox(sig->name());
+               QCheckBox *const checkbox = new QCheckBox(sig->display_name());
                check_box_mapper_.setMapping(checkbox, checkbox);
                connect(checkbox, SIGNAL(toggled(bool)),
                        &check_box_mapper_, SLOT(map()));
@@ -201,15 +198,31 @@ void Channels::showEvent(QShowEvent *event)
 {
        pv::widgets::Popup::showEvent(event);
 
+       const shared_ptr<sigrok::Device> device = session_.device()->device();
+       assert(device);
+
+       // Update group labels
+       for (auto entry : device->channel_groups()) {
+               const shared_ptr<ChannelGroup> group = entry.second;
+
+               try {
+                       QLabel* label = group_label_map_.at(group);
+                       label->setText(QString("<h3>%1</h3>").arg(group->name().c_str()));
+               } catch (out_of_range) {
+                       // Do nothing
+               }
+       }
+
        updating_channels_ = true;
 
-       for (map<QCheckBox*, shared_ptr<SignalBase> >::const_iterator i =
-                       check_box_signal_map_.begin();
-                       i != check_box_signal_map_.end(); i++) {
-               const shared_ptr<SignalBase> sig = (*i).second;
+       for (auto entry : check_box_signal_map_) {
+               QCheckBox *cb = entry.first;
+               const shared_ptr<SignalBase> sig = entry.second;
                assert(sig);
 
-               (*i).first->setChecked(sig->enabled());
+               // Update the check box
+               cb->setChecked(sig->enabled());
+               cb->setText(sig->display_name());
        }
 
        updating_channels_ = false;
index 3701325bc704572758831b8781d800a56cc39065..b23af57046d808252ac7e8b6594c470926bcd87c 100644 (file)
@@ -95,6 +95,7 @@ private:
        vector< shared_ptr<pv::binding::Device> > group_bindings_;
        map< QCheckBox*, shared_ptr<pv::data::SignalBase> >
                check_box_signal_map_;
+       map< shared_ptr<sigrok::ChannelGroup>, QLabel*> group_label_map_;
 
        QHBoxLayout buttons_bar_;
        QPushButton enable_all_channels_;