]> sigrok.org Git - pulseview.git/commitdiff
Replace map by list to preserve device order
authorSoeren Apel <redacted>
Fri, 7 Nov 2014 16:12:18 +0000 (17:12 +0100)
committerBert Vermeulen <redacted>
Sun, 9 Nov 2014 13:15:58 +0000 (14:15 +0100)
pv/mainwindow.cpp
pv/toolbars/samplingbar.cpp
pv/toolbars/samplingbar.h

index 42ae957640d491c19a7c740b9204c55224d7f852..6142709cd69efd9025805338b6a913aeb3053612 100644 (file)
@@ -61,6 +61,7 @@
 
 using std::list;
 using std::map;
+using std::pair;
 using std::shared_ptr;
 using std::string;
 
@@ -381,12 +382,13 @@ void MainWindow::update_device_list()
                devices.push_back(selected_device);
        assert(selected_device);
 
-       map<shared_ptr<Device>, string> device_names;
+       list< pair< shared_ptr<Device>, string> > device_list;
 
        for (auto device : devices)
-               device_names[device] = _device_manager.get_display_name(device);
+               device_list.push_back(make_pair(
+                       device, _device_manager.get_display_name(device)));
 
-       _sampling_bar->set_device_list(device_names, selected_device);
+       _sampling_bar->set_device_list(device_list, selected_device);
 }
 
 void MainWindow::closeEvent(QCloseEvent *event)
index 2350a45f8f76269f6457f67e3cf46d4652f25242..14990d81567704843fc08f05d7fb0ca17a40e430 100644 (file)
@@ -109,7 +109,7 @@ SamplingBar::SamplingBar(SigSession &session, QWidget *parent) :
 }
 
 void SamplingBar::set_device_list(
-       const std::map< shared_ptr<Device>, string > &device_names,
+       const std::list< std::pair<std::shared_ptr<sigrok::Device>, std::string> > &devices,
        shared_ptr<Device> selected)
 {
        int selected_index = -1;
@@ -120,16 +120,16 @@ void SamplingBar::set_device_list(
 
        _device_selector.clear();
 
-       for (auto entry : device_names) {
+       for (auto entry : devices) {
                auto device = entry.first;
-               auto description = entry.second;
+               auto display_name = entry.second;
 
                assert(device);
 
                if (selected == device)
                        selected_index = _device_selector.count();
 
-               _device_selector.addItem(description.c_str(),
+               _device_selector.addItem(display_name.c_str(),
                        qVariantFromValue(device));
        }
 
index 7c0ec9af2d75a2d29577e7d5126f1b2c78c717ee..d8d81219659e9a0cc19ca496ef8e11a6fcb2b234 100644 (file)
@@ -23,7 +23,7 @@
 
 #include <stdint.h>
 
-#include <map>
+#include <list>
 #include <memory>
 
 #include <QComboBox>
@@ -62,8 +62,7 @@ public:
        SamplingBar(SigSession &session, QWidget *parent);
 
        void set_device_list(
-               const std::map< std::shared_ptr<sigrok::Device>, std::string >
-                       &device_names,
+               const std::list< std::pair<std::shared_ptr<sigrok::Device>, std::string> > &devices,
                std::shared_ptr<sigrok::Device> selected);
 
        std::shared_ptr<sigrok::Device> get_selected_device() const;