From: Soeren Apel Date: Fri, 7 Nov 2014 16:12:18 +0000 (+0100) Subject: Replace map by list to preserve device order X-Git-Tag: pulseview-0.3.0~520 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=4fe06f499c5dafe187832036b900354f0d1da284;p=pulseview.git Replace map by list to preserve device order --- diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 42ae9576..6142709c 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -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, string> device_names; + list< pair< shared_ptr, 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) diff --git a/pv/toolbars/samplingbar.cpp b/pv/toolbars/samplingbar.cpp index 2350a45f..14990d81 100644 --- a/pv/toolbars/samplingbar.cpp +++ b/pv/toolbars/samplingbar.cpp @@ -109,7 +109,7 @@ SamplingBar::SamplingBar(SigSession &session, QWidget *parent) : } void SamplingBar::set_device_list( - const std::map< shared_ptr, string > &device_names, + const std::list< std::pair, std::string> > &devices, shared_ptr 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)); } diff --git a/pv/toolbars/samplingbar.h b/pv/toolbars/samplingbar.h index 7c0ec9af..d8d81219 100644 --- a/pv/toolbars/samplingbar.h +++ b/pv/toolbars/samplingbar.h @@ -23,7 +23,7 @@ #include -#include +#include #include #include @@ -62,8 +62,7 @@ public: SamplingBar(SigSession &session, QWidget *parent); void set_device_list( - const std::map< std::shared_ptr, std::string > - &device_names, + const std::list< std::pair, std::string> > &devices, std::shared_ptr selected); std::shared_ptr get_selected_device() const;