X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fwidgets%2Fdevicetoolbutton.hpp;fp=pv%2Fwidgets%2Fdevicetoolbutton.hpp;h=1fb0a54486057cbcd776b3f782580d54f416ea43;hb=079d39ea735015597a65390e4c5cacc7d272f78c;hp=0000000000000000000000000000000000000000;hpb=168888e25af380e62280acec3e3f316bbfed09d9;p=pulseview.git diff --git a/pv/widgets/devicetoolbutton.hpp b/pv/widgets/devicetoolbutton.hpp new file mode 100644 index 0000000..1fb0a54 --- /dev/null +++ b/pv/widgets/devicetoolbutton.hpp @@ -0,0 +1,99 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2014 Joel Holdsworth + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef PULSEVIEW_PV_WIDGETS_DEVICETOOLBUTTON_H +#define PULSEVIEW_PV_WIDGETS_DEVICETOOLBUTTON_H + +#include +#include +#include + +#include +#include +#include +#include + +struct srd_decoder; + +namespace sigrok { +class Device; +} + +namespace pv { + +class DeviceManager; + +namespace widgets { + +class DeviceToolButton : public QToolButton +{ + Q_OBJECT; + +public: + /** + * Constructor + * @param parent the parent widget. + * @param device_manager the device manager. + * @param connect_action the connect-to-device action. + */ + DeviceToolButton(QWidget *parent, DeviceManager &device_manager, + QAction *connect_action); + + /** + * Returns a reference to the selected device. + */ + std::shared_ptr selected_device(); + + /** + * Sets the current list of devices. + * @param device the list of devices. + * @param selected_device the currently active device. + */ + void set_device_list( + const std::list< std::shared_ptr > &devices, + std::shared_ptr selected); + +private: + /** + * Repopulates the menu from the device list. + */ + void update_device_list(); + +private Q_SLOTS: + void on_action(QObject *action); + +Q_SIGNALS: + void device_selected(); + +private: + DeviceManager &device_manager_; + QAction *const connect_action_; + + QMenu menu_; + QSignalMapper mapper_; + + std::shared_ptr selected_device_; + std::vector< std::weak_ptr > devices_; +}; + +} // widgets +} // pv + +#endif // PULSEVIEW_PV_WIDGETS_DEVICETOOLBUTTON_H