]> sigrok.org Git - pulseview.git/commitdiff
DeviceManager: Deprecated build_display_name and friends
authorJoel Holdsworth <redacted>
Sat, 28 Mar 2015 18:54:21 +0000 (18:54 +0000)
committerUwe Hermann <redacted>
Thu, 11 Jun 2015 18:38:41 +0000 (20:38 +0200)
pv/devicemanager.cpp
pv/devicemanager.hpp
pv/dialogs/connect.cpp
pv/mainwindow.cpp
pv/session.cpp
pv/widgets/devicetoolbutton.cpp

index 36d6fb6a44f1d0c10ae05a234503e5347122a85c..17a49774465c3d90fa7c8e3171d10bd4900c33f1 100644 (file)
@@ -22,6 +22,7 @@
 #include "session.hpp"
 
 #include <cassert>
+#include <functional>
 #include <stdexcept>
 #include <sstream>
 #include <string>
@@ -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<devices::HardwareDevice> device : driver_devices)
-               build_display_name(device);
-
        devices_.insert(devices_.end(), driver_devices.begin(),
                driver_devices.end());
-       devices_.sort([&](shared_ptr<devices::Device> a,
-               shared_ptr<devices::Device> 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<devices::HardwareDevice> DeviceManager::find_device_from_info(
        return last_resort_dev;
 }
 
-void DeviceManager::build_display_name(shared_ptr<devices::Device> device)
-{
-       const shared_ptr<sigrok::Device> sr_dev = device->device();
-       auto session_device = dynamic_pointer_cast<sigrok::SessionDevice>(sr_dev);
-       auto hardware_device = dynamic_pointer_cast<sigrok::HardwareDevice>(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<string> 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<devices::HardwareDevice> 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<devices::Device> dev)
-{
-       return display_names_[dev];
-}
-
-const std::string DeviceManager::get_full_name(
-       std::shared_ptr<devices::Device> dev)
-{
-       return full_names_[dev];
-}
-
-void DeviceManager::update_display_name(
-       std::shared_ptr<devices::Device> dev)
-{
-       build_display_name(dev);
-}
-
-bool DeviceManager::compare_devices(
-       shared_ptr<devices::Device> a, shared_ptr<devices::Device> b)
-{
+bool DeviceManager::compare_devices(shared_ptr<devices::Device> a,
+       shared_ptr<devices::Device> 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
index 8bceed34ff409d7a1a7769d0ad2c9c7fcf6a1f4f..33e784de5f564f9c35968806e274e12da528b423 100644 (file)
@@ -69,15 +69,6 @@ public:
        const std::shared_ptr<devices::HardwareDevice> find_device_from_info(
                const std::map<std::string, std::string> search_info);
 
-       void build_display_name(std::shared_ptr<devices::Device> device);
-
-       const std::string get_display_name(
-               std::shared_ptr<devices::Device> dev);
-
-       const std::string get_full_name(std::shared_ptr<devices::Device> dev);
-
-       void update_display_name(std::shared_ptr<devices::Device> dev);
-
 private:
        bool compare_devices(std::shared_ptr<devices::Device> a,
                std::shared_ptr<devices::Device> b);
@@ -85,9 +76,6 @@ private:
 protected:
        std::shared_ptr<sigrok::Context> context_;
        std::list< std::shared_ptr<devices::HardwareDevice> > devices_;
-
-       std::map< std::shared_ptr<devices::Device>, std::string > display_names_;
-       std::map< std::shared_ptr<devices::Device>, std::string > full_names_;
 };
 
 } // namespace pv
index 20836901b006a981cebb107d88054e51ef98a899..4fcbf694279edd0a4a2527d4869e6e45aa93ed01 100644 (file)
@@ -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());
 
index b7a0818b62ab5c7a28e88fecdfc0b1938133d73a..ac5372a6f46d295468699ca95460cbab647720ef 100644 (file)
@@ -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()));
 }
 
index 27154d13cd238c8713e4aab4f5415fa773cbd123..d5126660f56b140d2337d64b1df625a4ea44b148 100644 (file)
@@ -133,7 +133,6 @@ void Session::set_device(shared_ptr<devices::Device> device)
                (shared_ptr<sigrok::Device> device, shared_ptr<Packet> packet) {
                        data_feed_in(device, packet);
                });
-       device_manager_.update_display_name(device_);
        update_signals(device_);
 
        decode_traces_.clear();
index 7ba8aa28ce6704a0553911890af33fd3ef86ff74..723542b9fd9d3c6f874e4494004ee1b64eb383f1 100644 (file)
@@ -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<Device> >(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();
 }