]> sigrok.org Git - pulseview.git/blobdiff - pv/popups/channels.cpp
fix catching polymorphic types by value
[pulseview.git] / pv / popups / channels.cpp
index f8f94d1a4273534d09fbf9a2bb6766db518810c7..10146741224651594086b8c514b892f2ce2c20b2 100644 (file)
  * 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
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <map>
 
-#ifdef _WIN32
-// Windows: Avoid boost/thread namespace pollution (which includes windows.h).
-#define NOGDI
-#define NORESOURCE
-#endif
-#include <boost/thread/locks.hpp>
-#include <boost/thread/shared_mutex.hpp>
-
 #include <QCheckBox>
 #include <QFormLayout>
 #include <QGridLayout>
 
 #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/view/signal.hpp>
-
-#include <libsigrokcxx/libsigrokcxx.hpp>
 
-using namespace Qt;
-
-using boost::shared_lock;
-using boost::shared_mutex;
-using std::lock_guard;
+using std::make_shared;
 using std::map;
-using std::mutex;
-using std::set;
+using std::out_of_range;
 using std::shared_ptr;
 using std::unordered_set;
 using std::vector;
@@ -82,17 +65,16 @@ Channels::Channels(Session &session, QWidget *parent) :
        map<shared_ptr<Channel>, shared_ptr<SignalBase> > signal_map;
 
        unordered_set< shared_ptr<SignalBase> > sigs;
-       for (const shared_ptr<view::Signal> s : session_.signals())
-               sigs.insert(s->base());
+       for (const shared_ptr<data::SignalBase> b : session_.signalbases())
+               sigs.insert(b);
 
        for (const shared_ptr<SignalBase> &sig : sigs)
                signal_map[sig->channel()] = sig;
 
        // 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);
@@ -143,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;
@@ -166,22 +147,23 @@ void Channels::populate_group(shared_ptr<ChannelGroup> group,
        // popup.
        shared_ptr<Device> binding;
        if (group)
-               binding = shared_ptr<Device>(new Device(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);
+       QGridLayout *const channel_grid = create_channel_group_grid(sigs);
        layout_.addRow(channel_grid);
 
        // Create the channel group options
-       if (binding)
-       {
+       if (binding) {
                binding->add_properties_to_form(&layout_, true);
                group_bindings_.push_back(binding);
        }
@@ -196,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()));
@@ -216,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;
@@ -259,5 +257,5 @@ void Channels::disable_all_channels()
        set_all_channels(false);
 }
 
-} // popups
-} // pv
+}  // namespace popups
+}  // namespace pv