From 4fe06f499c5dafe187832036b900354f0d1da284 Mon Sep 17 00:00:00 2001 From: Soeren Apel Date: Fri, 7 Nov 2014 17:12:18 +0100 Subject: [PATCH] Replace map by list to preserve device order --- pv/mainwindow.cpp | 8 +++++--- pv/toolbars/samplingbar.cpp | 8 ++++---- pv/toolbars/samplingbar.h | 5 ++--- 3 files changed, 11 insertions(+), 10 deletions(-) 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; -- 2.30.2