From 3084ed4b15663dd717ff656745db305f377ab215 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sat, 28 Mar 2015 18:54:21 +0000 Subject: [PATCH] DeviceManager: Deprecated build_display_name and friends --- pv/devicemanager.cpp | 86 +++------------------------------ pv/devicemanager.hpp | 12 ----- pv/dialogs/connect.cpp | 2 +- pv/mainwindow.cpp | 2 +- pv/session.cpp | 1 - pv/widgets/devicetoolbutton.cpp | 8 +-- 6 files changed, 14 insertions(+), 97 deletions(-) diff --git a/pv/devicemanager.cpp b/pv/devicemanager.cpp index 36d6fb6a..17a49774 100644 --- a/pv/devicemanager.cpp +++ b/pv/devicemanager.cpp @@ -22,6 +22,7 @@ #include "session.hpp" #include +#include #include #include #include @@ -36,6 +37,7 @@ using boost::algorithm::join; +using std::bind; using std::dynamic_pointer_cast; using std::list; using std::map; @@ -104,14 +106,11 @@ DeviceManager::driver_scan( driver_devices.push_back(d); } - for (shared_ptr device : driver_devices) - build_display_name(device); - devices_.insert(devices_.end(), driver_devices.begin(), driver_devices.end()); - devices_.sort([&](shared_ptr a, - shared_ptr b) - { return compare_devices(a, b); }); + devices_.sort(bind(&DeviceManager::compare_devices, this, _1, _2)); + driver_devices.sort(bind( + &DeviceManager::compare_devices, this, _1, _2)); return driver_devices; } @@ -187,80 +186,11 @@ const shared_ptr DeviceManager::find_device_from_info( return last_resort_dev; } -void DeviceManager::build_display_name(shared_ptr device) -{ - const shared_ptr sr_dev = device->device(); - auto session_device = dynamic_pointer_cast(sr_dev); - auto hardware_device = dynamic_pointer_cast(sr_dev); - - if (session_device) { - full_names_[device] = display_names_[device] = - boost::filesystem::path( - session_device->parent()->filename()).filename().string(); - return; - } - - // First, build the device's full name. It always contains all - // possible information. - vector parts = {sr_dev->vendor(), sr_dev->model(), - sr_dev->version(), sr_dev->serial_number()}; - - if (sr_dev->connection_id().length() > 0) - parts.push_back("("+sr_dev->connection_id()+")"); - - full_names_[device] = join(parts, " "); - - // Next, build the display name. It only contains fields as required. - - // If we can find another device with the same model/vendor then - // we have at least two such devices and need to distinguish them. - const bool multiple_dev = hardware_device && any_of( - devices_.begin(), devices_.end(), - [&](shared_ptr dev) { - return (dev->device()->vendor() == hardware_device->vendor() && - dev->device()->model() == hardware_device->model()) && - dev != device; - } ); - - parts = {sr_dev->vendor(), sr_dev->model()}; - - if (multiple_dev) { - parts.push_back(sr_dev->version()); - parts.push_back(sr_dev->serial_number()); - - if ((sr_dev->serial_number().length() == 0) && - (sr_dev->connection_id().length() > 0)) - parts.push_back("("+sr_dev->connection_id()+")"); - } - - display_names_[device] = join(parts, " "); -} - -const std::string DeviceManager::get_display_name( - std::shared_ptr dev) -{ - return display_names_[dev]; -} - -const std::string DeviceManager::get_full_name( - std::shared_ptr dev) -{ - return full_names_[dev]; -} - -void DeviceManager::update_display_name( - std::shared_ptr dev) -{ - build_display_name(dev); -} - -bool DeviceManager::compare_devices( - shared_ptr a, shared_ptr b) -{ +bool DeviceManager::compare_devices(shared_ptr a, + shared_ptr b) { assert(a); assert(b); - - return display_names_[a].compare(display_names_[b]) < 0; + return a->display_name(*this).compare(b->display_name(*this)) < 0; } } // namespace pv diff --git a/pv/devicemanager.hpp b/pv/devicemanager.hpp index 8bceed34..33e784de 100644 --- a/pv/devicemanager.hpp +++ b/pv/devicemanager.hpp @@ -69,15 +69,6 @@ public: const std::shared_ptr find_device_from_info( const std::map search_info); - void build_display_name(std::shared_ptr device); - - const std::string get_display_name( - std::shared_ptr dev); - - const std::string get_full_name(std::shared_ptr dev); - - void update_display_name(std::shared_ptr dev); - private: bool compare_devices(std::shared_ptr a, std::shared_ptr b); @@ -85,9 +76,6 @@ private: protected: std::shared_ptr context_; std::list< std::shared_ptr > devices_; - - std::map< std::shared_ptr, std::string > display_names_; - std::map< std::shared_ptr, std::string > full_names_; }; } // namespace pv diff --git a/pv/dialogs/connect.cpp b/pv/dialogs/connect.cpp index 20836901..4fcbf694 100644 --- a/pv/dialogs/connect.cpp +++ b/pv/dialogs/connect.cpp @@ -177,7 +177,7 @@ void Connect::scan_pressed() assert(device); QString text = QString::fromStdString( - device_manager_.get_display_name(device)); + device->display_name(device_manager_)); text += QString(" with %1 channels").arg( device->device()->channels().size()); diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index b7a0818b..ac5372a6 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -663,7 +663,7 @@ void MainWindow::device_selected() if (!device) return; - const string display_name = device_manager_.get_display_name(device); + const string display_name = device->display_name(device_manager_); setWindowTitle(tr("%1 - PulseView").arg(display_name.c_str())); } diff --git a/pv/session.cpp b/pv/session.cpp index 27154d13..d5126660 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -133,7 +133,6 @@ void Session::set_device(shared_ptr device) (shared_ptr device, shared_ptr packet) { data_feed_in(device, packet); }); - device_manager_.update_display_name(device_); update_signals(device_); decode_traces_.clear(); diff --git a/pv/widgets/devicetoolbutton.cpp b/pv/widgets/devicetoolbutton.cpp index 7ba8aa28..723542b9 100644 --- a/pv/widgets/devicetoolbutton.cpp +++ b/pv/widgets/devicetoolbutton.cpp @@ -73,7 +73,7 @@ void DeviceToolButton::set_device_list( { selected_device_ = selected; setText(QString::fromStdString( - device_manager_.get_display_name(selected))); + selected->display_name(device_manager_))); devices_ = vector< weak_ptr >(devices.begin(), devices.end()); update_device_list(); } @@ -91,11 +91,11 @@ void DeviceToolButton::update_device_list() continue; QAction *const a = new QAction(QString::fromStdString( - device_manager_.get_display_name(dev)), this); + dev->display_name(device_manager_)), this); a->setCheckable(true); a->setChecked(selected_device_ == dev); a->setData(qVariantFromValue((void*)dev.get())); - a->setToolTip(QString::fromStdString(device_manager_.get_full_name(dev))); + a->setToolTip(QString::fromStdString(dev->full_name())); mapper_.setMapping(a, a); connect(a, SIGNAL(triggered()), &mapper_, SLOT(map())); @@ -119,7 +119,7 @@ void DeviceToolButton::on_action(QObject *action) update_device_list(); setText(QString::fromStdString( - device_manager_.get_display_name(selected_device_))); + selected_device_->display_name(device_manager_))); device_selected(); } -- 2.30.2