]> sigrok.org Git - pulseview.git/blame - pv/widgets/devicetoolbutton.hpp
Save/restore view states and signal settings
[pulseview.git] / pv / widgets / devicetoolbutton.hpp
CommitLineData
079d39ea
JH
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2014 Joel Holdsworth <joel@airwebreathe.org.uk>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
7a01bd36
JH
21#ifndef PULSEVIEW_PV_WIDGETS_DEVICETOOLBUTTON_HPP
22#define PULSEVIEW_PV_WIDGETS_DEVICETOOLBUTTON_HPP
079d39ea
JH
23
24#include <list>
25#include <memory>
26#include <vector>
27
28#include <QAction>
29#include <QMenu>
30#include <QSignalMapper>
31#include <QToolButton>
32
33struct srd_decoder;
34
079d39ea
JH
35namespace pv {
36
37class DeviceManager;
38
da30ecb7
JH
39namespace devices {
40class Device;
41}
42
079d39ea
JH
43namespace widgets {
44
45class DeviceToolButton : public QToolButton
46{
47 Q_OBJECT;
48
49public:
50 /**
51 * Constructor
52 * @param parent the parent widget.
53 * @param device_manager the device manager.
54 * @param connect_action the connect-to-device action.
55 */
56 DeviceToolButton(QWidget *parent, DeviceManager &device_manager,
57 QAction *connect_action);
58
59 /**
60 * Returns a reference to the selected device.
61 */
da30ecb7 62 std::shared_ptr<devices::Device> selected_device();
079d39ea
JH
63
64 /**
65 * Sets the current list of devices.
66 * @param device the list of devices.
67 * @param selected_device the currently active device.
68 */
69 void set_device_list(
da30ecb7
JH
70 const std::list< std::shared_ptr<devices::Device> > &devices,
71 std::shared_ptr<devices::Device> selected);
079d39ea 72
7e0c99bf
SA
73 /**
74 * Sets the current device to "no device". Useful for when a selected
75 * device fails to open.
76 */
77 void reset();
78
079d39ea
JH
79private:
80 /**
81 * Repopulates the menu from the device list.
82 */
83 void update_device_list();
84
85private Q_SLOTS:
86 void on_action(QObject *action);
87
1982c650
SA
88 void on_menu_hovered(QAction *action);
89
90 void on_menu_hover_timeout();
91
079d39ea
JH
92Q_SIGNALS:
93 void device_selected();
94
95private:
96 DeviceManager &device_manager_;
97 QAction *const connect_action_;
98
99 QMenu menu_;
100 QSignalMapper mapper_;
101
da30ecb7
JH
102 std::shared_ptr<devices::Device> selected_device_;
103 std::vector< std::weak_ptr<devices::Device> > devices_;
1982c650
SA
104
105 QString device_tooltip_;
079d39ea
JH
106};
107
108} // widgets
109} // pv
110
7a01bd36 111#endif // PULSEVIEW_PV_WIDGETS_DEVICETOOLBUTTON_HPP