Split DeviceOptions dialog into two popups: DeviceOptions and Probes
authorJoel Holdsworth <joel@airwebreathe.org.uk>
Mon, 7 Oct 2013 18:10:40 +0000 (19:10 +0100)
committerJoel Holdsworth <joel@airwebreathe.org.uk>
Sun, 13 Oct 2013 10:52:32 +0000 (11:52 +0100)
CMakeLists.txt
pv/dialogs/deviceoptions.cpp [deleted file]
pv/dialogs/deviceoptions.h [deleted file]
pv/popups/deviceoptions.cpp [new file with mode: 0644]
pv/popups/deviceoptions.h [new file with mode: 0644]
pv/popups/probes.cpp [new file with mode: 0644]
pv/popups/probes.h [new file with mode: 0644]
pv/toolbars/samplingbar.cpp
pv/toolbars/samplingbar.h

index 945b40cdad72677db556bcf58832685a404aeb8f..43208aae80f1f51fdc38b3b2c4d8e77b6a451371 100644 (file)
@@ -115,7 +115,8 @@ set(pulseview_SOURCES
        pv/dialogs/about.cpp
        pv/dialogs/connect.cpp
        pv/dialogs/decoder.cpp
        pv/dialogs/about.cpp
        pv/dialogs/connect.cpp
        pv/dialogs/decoder.cpp
-       pv/dialogs/deviceoptions.cpp
+       pv/popups/deviceoptions.cpp
+       pv/popups/probes.cpp
        pv/prop/bool.cpp
        pv/prop/double.cpp
        pv/prop/enum.cpp
        pv/prop/bool.cpp
        pv/prop/double.cpp
        pv/prop/enum.cpp
@@ -156,7 +157,8 @@ set(pulseview_HEADERS
        pv/data/decoder.h
        pv/dialogs/about.h
        pv/dialogs/connect.h
        pv/data/decoder.h
        pv/dialogs/about.h
        pv/dialogs/connect.h
-       pv/dialogs/deviceoptions.h
+       pv/popups/deviceoptions.h
+       pv/popups/probes.h
        pv/toolbars/samplingbar.h
        pv/view/cursor.h
        pv/view/decodesignal.h
        pv/toolbars/samplingbar.h
        pv/view/cursor.h
        pv/view/decodesignal.h
diff --git a/pv/dialogs/deviceoptions.cpp b/pv/dialogs/deviceoptions.cpp
deleted file mode 100644 (file)
index fe21c9a..0000000
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * This file is part of the PulseView project.
- *
- * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
- *
- * 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
- */
-
-#include "deviceoptions.h"
-
-#include <boost/foreach.hpp>
-
-#include <QFormLayout>
-#include <QListWidget>
-
-#include <pv/prop/property.h>
-
-using namespace boost;
-using namespace std;
-
-namespace pv {
-namespace dialogs {
-
-DeviceOptions::DeviceOptions(QWidget *parent, struct sr_dev_inst *sdi) :
-       QDialog(parent),
-       _sdi(sdi),
-       _layout(this),
-       _probes_box(tr("Probes"), this),
-       _probes(this),
-       _probes_bar(this),
-       _enable_all_probes(this),
-       _disable_all_probes(this),
-       _props_box(tr("Configuration"), this),
-       _button_box(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
-               Qt::Horizontal, this),
-       _device_options_binding(sdi)
-{
-       setWindowTitle(tr("Configure Device"));
-
-       connect(&_enable_all_probes, SIGNAL(clicked()),
-               this, SLOT(enable_all_probes()));
-       connect(&_disable_all_probes, SIGNAL(clicked()),
-               this, SLOT(disable_all_probes()));
-
-       connect(&_button_box, SIGNAL(accepted()), this, SLOT(accept()));
-       connect(&_button_box, SIGNAL(rejected()), this, SLOT(reject()));
-
-       setLayout(&_layout);
-
-       setup_probes();
-       _probes_box.setLayout(&_probes_box_layout);
-       _probes_box_layout.addWidget(&_probes);
-
-       _enable_all_probes.setText(tr("Enable All"));
-       _probes_bar.addWidget(&_enable_all_probes);
-
-       _disable_all_probes.setText(tr("Disable All"));
-       _probes_bar.addWidget(&_disable_all_probes);
-
-       _probes_box_layout.addWidget(&_probes_bar);
-       _layout.addWidget(&_probes_box);
-
-
-       _props_box.setLayout(&_props_box_layout);
-       _props_box_layout.addWidget(
-               _device_options_binding.get_property_form(this));
-       _layout.addWidget(&_props_box);
-
-       _layout.addWidget(&_button_box);
-}
-
-void DeviceOptions::accept()
-{
-       using namespace Qt;
-
-       QDialog::accept();
-
-       // Commit the probes
-       for (int i = 0; i < _probes.count(); i++) {
-               const QListWidgetItem *const item = _probes.item(i);
-               assert(item);
-               sr_probe *const probe = (sr_probe*)
-                       item->data(UserRole).value<void*>();
-               assert(probe);
-               probe->enabled = item->checkState() == Checked;
-       }
-
-       // Commit the properties
-       _device_options_binding.commit();
-}
-
-void DeviceOptions::setup_probes()
-{
-       using namespace Qt;
-
-       for (const GSList *l = _sdi->probes; l; l = l->next) {
-               sr_probe *const probe = (sr_probe*)l->data;
-               assert(probe);
-               QListWidgetItem *const item = new QListWidgetItem(
-                       probe->name, &_probes);
-               assert(item);
-               item->setCheckState(probe->enabled ?
-                       Checked : Unchecked);
-               item->setData(UserRole,
-                       qVariantFromValue((void*)probe));
-               _probes.addItem(item);
-       }
-}
-
-void DeviceOptions::set_all_probes(bool set)
-{
-       for (int i = 0; i < _probes.count(); i++) {
-               QListWidgetItem *const item = _probes.item(i);
-               assert(item);
-               item->setCheckState(set ? Qt::Checked : Qt::Unchecked);
-       }
-}
-
-void DeviceOptions::enable_all_probes()
-{
-       set_all_probes(true);
-}
-
-void DeviceOptions::disable_all_probes()
-{
-       set_all_probes(false);
-}
-
-} // namespace dialogs
-} // namespace pv
diff --git a/pv/dialogs/deviceoptions.h b/pv/dialogs/deviceoptions.h
deleted file mode 100644 (file)
index 059d336..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * This file is part of the PulseView project.
- *
- * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
- *
- * 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_DEVICEOPTIONS_H
-#define PULSEVIEW_PV_DEVICEOPTIONS_H
-
-#include <QDialog>
-#include <QDialogButtonBox>
-#include <QGroupBox>
-#include <QListWidget>
-#include <QToolBar>
-#include <QToolButton>
-#include <QVBoxLayout>
-
-#include <pv/prop/binding/deviceoptions.h>
-
-namespace pv {
-namespace dialogs {
-
-class DeviceOptions : public QDialog
-{
-       Q_OBJECT
-
-public:
-       DeviceOptions(QWidget *parent, struct sr_dev_inst *sdi);
-
-protected:
-       void accept();
-
-private:
-       void setup_probes();
-
-       void set_all_probes(bool set);
-
-private slots:
-       void enable_all_probes();
-       void disable_all_probes();
-
-private:
-       struct sr_dev_inst *const _sdi;
-
-       QVBoxLayout _layout;
-
-       QGroupBox _probes_box;
-       QVBoxLayout _probes_box_layout;
-       QListWidget _probes;
-       QToolBar _probes_bar;
-       QToolButton _enable_all_probes;
-       QToolButton _disable_all_probes;
-
-       QGroupBox _props_box;
-       QVBoxLayout _props_box_layout;
-
-       QDialogButtonBox _button_box;
-
-       pv::prop::binding::DeviceOptions _device_options_binding;
-};
-
-} // namespace dialogs
-} // namespace pv
-
-#endif // PULSEVIEW_PV_DEVICEOPTIONS_H
diff --git a/pv/popups/deviceoptions.cpp b/pv/popups/deviceoptions.cpp
new file mode 100644 (file)
index 0000000..c864865
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * 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
+ */
+
+#include "deviceoptions.h"
+
+#include <boost/foreach.hpp>
+
+#include <QFormLayout>
+#include <QListWidget>
+
+#include <pv/prop/property.h>
+
+using namespace boost;
+using namespace std;
+
+namespace pv {
+namespace popups {
+
+DeviceOptions::DeviceOptions(sr_dev_inst *sdi, QWidget *parent) :
+       Popup(parent),
+       _sdi(sdi),
+       _layout(this),
+       _binding(sdi)
+{
+       setLayout(&_layout);
+
+       _layout.addWidget(_binding.get_property_form(this));
+}
+
+void DeviceOptions::closeEvent(QCloseEvent*)
+{
+       _binding.commit();
+}
+
+} // namespace popups
+} // namespace pv
diff --git a/pv/popups/deviceoptions.h b/pv/popups/deviceoptions.h
new file mode 100644 (file)
index 0000000..50fc4fb
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * 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_POPUPS_DEVICEOPTIONS_H
+#define PULSEVIEW_PV_POPUPS_DEVICEOPTIONS_H
+
+#include <QGroupBox>
+#include <QVBoxLayout>
+
+#include <pv/prop/binding/deviceoptions.h>
+#include <pv/widgets/popup.h>
+
+namespace pv {
+namespace popups {
+
+class DeviceOptions : public pv::widgets::Popup
+{
+       Q_OBJECT
+
+public:
+       DeviceOptions(sr_dev_inst *sdi, QWidget *parent);
+
+private:
+       void closeEvent(QCloseEvent*);
+
+private:
+       sr_dev_inst *const _sdi;
+
+       QVBoxLayout _layout;
+
+       pv::prop::binding::DeviceOptions _binding;
+};
+
+} // namespace popups
+} // namespace pv
+
+#endif // PULSEVIEW_PV_POPUPS_DEVICEOPTIONS_H
diff --git a/pv/popups/probes.cpp b/pv/popups/probes.cpp
new file mode 100644 (file)
index 0000000..9684d43
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * 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
+ */
+
+#include "probes.h"
+
+using namespace Qt;
+
+namespace pv {
+namespace popups {
+
+Probes::Probes(sr_dev_inst *sdi, QWidget *parent) :
+       Popup(parent),
+       _sdi(sdi),
+       _layout(this),
+       _probes(this),
+       _probes_bar(this),
+       _enable_all_probes(this),
+       _disable_all_probes(this)
+{
+       assert(_sdi);
+
+       setLayout(&_layout);
+
+       connect(&_enable_all_probes, SIGNAL(clicked()),
+               this, SLOT(enable_all_probes()));
+       connect(&_disable_all_probes, SIGNAL(clicked()),
+               this, SLOT(disable_all_probes()));
+
+       _layout.addWidget(&_probes);
+
+       _enable_all_probes.setText(tr("Enable All"));
+       _probes_bar.addWidget(&_enable_all_probes);
+
+       _disable_all_probes.setText(tr("Disable All"));
+       _probes_bar.addWidget(&_disable_all_probes);
+
+       _layout.addWidget(&_probes_bar);
+
+       for (const GSList *l = _sdi->probes; l; l = l->next) {
+               sr_probe *const probe = (sr_probe*)l->data;
+               assert(probe);
+               QListWidgetItem *const item = new QListWidgetItem(
+                       probe->name, &_probes);
+               assert(item);
+               item->setData(UserRole,
+                       qVariantFromValue((void*)probe));
+               item->setCheckState(probe->enabled ?
+                       Checked : Unchecked);
+               _probes.addItem(item);
+       }
+
+       connect(&_probes, SIGNAL(itemChanged(QListWidgetItem*)),
+               this, SLOT(item_changed(QListWidgetItem*)));
+}
+
+void Probes::set_all_probes(bool set)
+{
+       for (int i = 0; i < _probes.count(); i++) {
+               QListWidgetItem *const item = _probes.item(i);
+               assert(item);
+               item->setCheckState(set ? Qt::Checked : Qt::Unchecked);
+
+               sr_probe *const probe = (sr_probe*)
+                       item->data(UserRole).value<void*>();
+               assert(probe);
+               probe->enabled = item->checkState() == Checked;
+       }
+}
+
+void Probes::item_changed(QListWidgetItem *item)
+{
+       assert(item);
+       sr_probe *const probe = (sr_probe*)
+               item->data(UserRole).value<void*>();
+       assert(probe);
+       probe->enabled = item->checkState() == Checked;
+}
+
+void Probes::enable_all_probes()
+{
+       set_all_probes(true);
+}
+
+void Probes::disable_all_probes()
+{
+       set_all_probes(false);
+}
+
+} // popups
+} // pv
diff --git a/pv/popups/probes.h b/pv/popups/probes.h
new file mode 100644 (file)
index 0000000..33f5d99
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * 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_POPUPS_PROBES_H
+#define PULSEVIEW_PV_POPUPS_PROBES_H
+
+#include <QListWidget>
+#include <QToolBar>
+#include <QToolButton>
+#include <QVBoxLayout>
+
+#include <pv/widgets/popup.h>
+
+namespace pv {
+namespace popups {
+
+class Probes : public pv::widgets::Popup
+{
+       Q_OBJECT
+
+public:
+       Probes(sr_dev_inst *sdi, QWidget *parent);
+
+private:
+       void set_all_probes(bool set);
+
+private slots:
+       void item_changed(QListWidgetItem *item);
+
+       void enable_all_probes();
+       void disable_all_probes();
+
+private:
+       sr_dev_inst *_sdi;
+
+       QVBoxLayout _layout;
+
+       QListWidget _probes;
+       QToolBar _probes_bar;
+       QToolButton _enable_all_probes;
+       QToolButton _disable_all_probes;
+};
+
+} // popups
+} // pv
+
+#endif // PULSEVIEW_PV_POPUPS_PROBES_H
index 7d94594c1509765bce99f158d516d86f7ccfdb5d..ae4f298b6f2eae30f744ce4636e344459b87b5c6 100644 (file)
@@ -32,7 +32,7 @@
 #include "samplingbar.h"
 
 #include <pv/devicemanager.h>
 #include "samplingbar.h"
 
 #include <pv/devicemanager.h>
-#include <pv/dialogs/deviceoptions.h>
+#include <pv/popups/deviceoptions.h>
 
 using namespace std;
 
 
 using namespace std;
 
@@ -68,6 +68,7 @@ SamplingBar::SamplingBar(QWidget *parent) :
        QToolBar("Sampling Bar", parent),
        _device_selector(this),
        _configure_button(this),
        QToolBar("Sampling Bar", parent),
        _device_selector(this),
        _configure_button(this),
+       _probes_button(this),
        _record_length_selector(this),
        _sample_rate_list(this),
        _icon_red(":/icons/status-red.svg"),
        _record_length_selector(this),
        _sample_rate_list(this),
        _icon_red(":/icons/status-red.svg"),
@@ -79,8 +80,6 @@ SamplingBar::SamplingBar(QWidget *parent) :
                this, SLOT(on_run_stop()));
        connect(&_device_selector, SIGNAL(currentIndexChanged (int)),
                this, SLOT(on_device_selected()));
                this, SLOT(on_run_stop()));
        connect(&_device_selector, SIGNAL(currentIndexChanged (int)),
                this, SLOT(on_device_selected()));
-       connect(&_configure_button, SIGNAL(clicked()),
-               this, SLOT(on_configure()));
 
        _sample_rate_value.setDecimals(0);
        _sample_rate_value.setSuffix("Hz");
 
        _sample_rate_value.setDecimals(0);
        _sample_rate_value.setSuffix("Hz");
@@ -101,11 +100,14 @@ SamplingBar::SamplingBar(QWidget *parent) :
 
        _configure_button.setIcon(QIcon::fromTheme("configure",
                QIcon(":/icons/configure.png")));
 
        _configure_button.setIcon(QIcon::fromTheme("configure",
                QIcon(":/icons/configure.png")));
+       _probes_button.setIcon(QIcon::fromTheme("probes",
+               QIcon(":/icons/probes.svg")));
 
        _run_stop_button.setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
 
        addWidget(&_device_selector);
        addWidget(&_configure_button);
 
        _run_stop_button.setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
 
        addWidget(&_device_selector);
        addWidget(&_configure_button);
+       addWidget(&_probes_button);
        addWidget(&_record_length_selector);
        _sample_rate_list_action = addWidget(&_sample_rate_list);
        _sample_rate_value_action = addWidget(&_sample_rate_value);
        addWidget(&_record_length_selector);
        _sample_rate_list_action = addWidget(&_sample_rate_list);
        _sample_rate_value_action = addWidget(&_sample_rate_value);
@@ -292,7 +294,15 @@ void SamplingBar::commit_sample_rate()
 
 void SamplingBar::on_device_selected()
 {
 
 void SamplingBar::on_device_selected()
 {
+       using namespace pv::popups;
+
        update_sample_rate_selector();
        update_sample_rate_selector();
+
+       sr_dev_inst *const sdi = get_selected_device();
+
+       _configure_button.set_popup(new DeviceOptions(sdi, this));
+       _probes_button.set_popup(new Probes(sdi, this));
+
        device_selected();
 }
 
        device_selected();
 }
 
@@ -301,19 +311,6 @@ void SamplingBar::on_sample_rate_changed()
        commit_sample_rate();
 }
 
        commit_sample_rate();
 }
 
-void SamplingBar::on_configure()
-{
-       commit_sample_rate();
-
-       sr_dev_inst *const sdi = get_selected_device();
-       assert(sdi);
-
-       pv::dialogs::DeviceOptions dlg(this, sdi);
-       dlg.exec();
-
-       update_sample_rate_selector_value();
-}
-
 void SamplingBar::on_run_stop()
 {
        commit_sample_rate();   
 void SamplingBar::on_run_stop()
 {
        commit_sample_rate();   
index 1f40d0452ff6ca8d7265cc30703eab46bcf388d4..0c1a0539e4aaefca5e001469322f4d838e9a7769 100644 (file)
@@ -31,6 +31,8 @@
 #include <QToolButton>
 
 #include <pv/sigsession.h>
 #include <QToolButton>
 
 #include <pv/sigsession.h>
+#include <pv/popups/probes.h>
+#include <pv/widgets/popuptoolbutton.h>
 
 struct st_dev_inst;
 class QAction;
 
 struct st_dev_inst;
 class QAction;
@@ -71,12 +73,13 @@ private:
 private slots:
        void on_device_selected();
        void on_sample_rate_changed();
 private slots:
        void on_device_selected();
        void on_sample_rate_changed();
-       void on_configure();
        void on_run_stop();
 
 private:
        QComboBox _device_selector;
        void on_run_stop();
 
 private:
        QComboBox _device_selector;
-       QToolButton _configure_button;
+
+       pv::widgets::PopupToolButton _configure_button;
+       pv::widgets::PopupToolButton _probes_button;
 
        QComboBox _record_length_selector;
 
 
        QComboBox _record_length_selector;