]> sigrok.org Git - pulseview.git/commitdiff
Added pv::dialogs::InputOutputOptions
authorJoel Holdsworth <redacted>
Wed, 21 Jan 2015 01:14:43 +0000 (20:14 -0500)
committerUwe Hermann <redacted>
Tue, 27 Jan 2015 15:28:32 +0000 (16:28 +0100)
CMakeLists.txt
pv/dialogs/inputoutputoptions.cpp [new file with mode: 0644]
pv/dialogs/inputoutputoptions.hpp [new file with mode: 0644]
pv/dialogs/storeprogress.cpp
pv/dialogs/storeprogress.hpp
pv/mainwindow.cpp
pv/storesession.cpp
pv/storesession.hpp

index 99314d05e8213fc9bb1e95c92fa568836169b37c..79dd8f8b3118e424e8279cd9498f9089ba4230e9 100644 (file)
@@ -157,6 +157,7 @@ set(pulseview_SOURCES
        pv/data/segment.cpp
        pv/dialogs/about.cpp
        pv/dialogs/connect.cpp
+       pv/dialogs/inputoutputoptions.cpp
        pv/dialogs/storeprogress.cpp
        pv/popups/deviceoptions.cpp
        pv/popups/channels.cpp
@@ -207,6 +208,7 @@ set(pulseview_HEADERS
        pv/binding/device.hpp
        pv/dialogs/about.hpp
        pv/dialogs/connect.hpp
+       pv/dialogs/inputoutputoptions.hpp
        pv/dialogs/storeprogress.hpp
        pv/popups/channels.hpp
        pv/popups/deviceoptions.hpp
diff --git a/pv/dialogs/inputoutputoptions.cpp b/pv/dialogs/inputoutputoptions.cpp
new file mode 100644 (file)
index 0000000..8f013a2
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * 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 "inputoutputoptions.hpp"
+
+#include <pv/prop/property.hpp>
+
+using std::map;
+using std::shared_ptr;
+using std::string;
+
+using Glib::VariantBase;
+
+using sigrok::Option;
+
+namespace pv {
+namespace dialogs {
+
+InputOutputOptions::InputOutputOptions(const QString &title,
+       const map<string, shared_ptr<Option>> &options, QWidget *parent) :
+       QDialog(parent),
+       layout_(this),
+       button_box_(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
+               Qt::Horizontal, this),
+       binding_(options)
+{
+       setWindowTitle(title);
+
+       connect(&button_box_, SIGNAL(accepted()), this, SLOT(accept()));
+       connect(&button_box_, SIGNAL(rejected()), this, SLOT(reject()));
+
+       setLayout(&layout_);
+
+       layout_.addWidget(binding_.get_property_form(this));
+       layout_.addWidget(&button_box_);
+}
+
+const map<string, VariantBase>& InputOutputOptions::options() const
+{
+       return binding_.options();
+}
+
+void InputOutputOptions::accept()
+{
+       QDialog::accept();
+
+       // Commit the properties
+       binding_.commit();
+}
+
+} // namespace dialogs
+} // namespace pv
diff --git a/pv/dialogs/inputoutputoptions.hpp b/pv/dialogs/inputoutputoptions.hpp
new file mode 100644 (file)
index 0000000..cde778c
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2015 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_DIALOGS_INPUTOUTPUTOPTIONS_HPP
+#define PULSEVIEW_PV_DIALOGS_INPUTOUTPUTOPTIONS_HPP
+
+#include <QDialog>
+#include <QDialogButtonBox>
+#include <QGroupBox>
+#include <QVBoxLayout>
+
+#include <pv/binding/inputoutput.hpp>
+
+namespace pv {
+namespace dialogs {
+
+/**
+ * Presents the selection of inpout/output options to the user.
+ */
+class InputOutputOptions : public QDialog
+{
+       Q_OBJECT
+
+public:
+       /**
+        * Constructor.
+        * @param title the title of the dialog.
+        * @param options the map of options to use as a template.
+        * @param parent the parent widget of the dialog.
+        */ 
+       InputOutputOptions(const QString &title,
+               const std::map<std::string, std::shared_ptr<sigrok::Option>>
+                       &options,
+               QWidget *parent);
+
+       /**
+        * Gets the map of selected options.
+        * @return the options.
+        */
+       const std::map<std::string, Glib::VariantBase>& options() const;
+
+protected:
+       void accept();
+
+private:
+       QVBoxLayout layout_;
+       QDialogButtonBox button_box_;
+       pv::binding::InputOutput binding_;
+};
+
+} // namespace dialogs
+} // namespace pv
+
+#endif // PULSEVIEW_PV_INPUTOUTPUTOPTIONS_HPP
index dff8950ac1993ac3d8c157cab87f0cfaffca0c54..a7f889e07940573c775bfbed361ec5b0823b161a 100644 (file)
 
 #include "storeprogress.hpp"
 
+using std::map;
+using std::string;
+
+using Glib::VariantBase;
+
 namespace pv {
 namespace dialogs {
 
 StoreProgress::StoreProgress(const QString &file_name,
        const std::shared_ptr<sigrok::OutputFormat> output_format,
+       const map<string, VariantBase> &options,
        const Session &session, QWidget *parent) :
        QProgressDialog(tr("Saving..."), tr("Cancel"), 0, 0, parent),
-       session_(file_name.toStdString(), output_format, session)
+       session_(file_name.toStdString(), output_format, options, session)
 {
        connect(&session_, SIGNAL(progress_updated()),
                this, SLOT(on_progress_updated()));
index 389aad81cc9b2dc4762ba2bb047a1c8c934c5a77..19aef14a0e5bcb504813ccee9134b434ec73a217 100644 (file)
@@ -41,6 +41,7 @@ class StoreProgress : public QProgressDialog
 public:
        StoreProgress(const QString &file_name,
                const std::shared_ptr<sigrok::OutputFormat> output_format,
+               const std::map<std::string, Glib::VariantBase> &options,
                const Session &session, QWidget *parent = 0);
 
        virtual ~StoreProgress();
index c30720be182de05ec02e319c093e6221b507affd..81112aba805ffa688fbef84bc91708c38ab569b6 100644 (file)
@@ -45,6 +45,7 @@
 #include "devicemanager.hpp"
 #include "dialogs/about.hpp"
 #include "dialogs/connect.hpp"
+#include "dialogs/inputoutputoptions.hpp"
 #include "dialogs/storeprogress.hpp"
 #include "toolbars/mainbar.hpp"
 #include "view/logicsignal.hpp"
@@ -202,7 +203,7 @@ void MainWindow::export_file(shared_ptr<OutputFormat> format)
        QSettings settings;
        const QString dir = settings.value(SettingSaveDirectory).toString();
 
-       // Show the dialog
+       // Show the file dialog
        const QString file_name = QFileDialog::getSaveFileName(
                this, tr("Save File"), dir, tr("%1 files (*.*)").arg(
                        QString::fromStdString(format->description())));
@@ -213,7 +214,19 @@ void MainWindow::export_file(shared_ptr<OutputFormat> format)
        const QString abs_path = QFileInfo(file_name).absolutePath();
        settings.setValue(SettingSaveDirectory, abs_path);
 
-       StoreProgress *dlg = new StoreProgress(file_name, format,
+       // Show the options dialog
+       map<string, Glib::VariantBase> options;
+       if (!format->options().empty()) {
+               dialogs::InputOutputOptions dlg(
+                       tr("Export %1").arg(QString::fromStdString(
+                               format->description())),
+                       format->options(), this);
+               if (!dlg.exec())
+                       return;
+               options = dlg.options();
+       }
+
+       StoreProgress *dlg = new StoreProgress(file_name, format, options,
                session_, this);
        dlg->run();
 }
index d58fd4981d3f5830f8c3c64b92f95d7347da92a4..92f64f5ba12a328b56bad5728ec8db14c3000b82 100644 (file)
@@ -47,6 +47,8 @@ using std::string;
 using std::thread;
 using std::vector;
 
+using Glib::VariantBase;
+
 using sigrok::ConfigKey;
 using sigrok::Error;
 using sigrok::OutputFormat;
@@ -56,9 +58,11 @@ namespace pv {
 const size_t StoreSession::BlockSize = 1024 * 1024;
 
 StoreSession::StoreSession(const std::string &file_name,
-       const shared_ptr<OutputFormat> &output_format, const Session &session) :
+       const shared_ptr<OutputFormat> &output_format,
+       const map<string, VariantBase> &options, const Session &session) :
        file_name_(file_name),
        output_format_(output_format),
+       options_(options),
        session_(session),
        interrupt_(false),
        units_stored_(0),
@@ -127,7 +131,7 @@ bool StoreSession::start()
                auto context = session_.session()->context();
                auto device = session_.device();
 
-               map<string, Glib::VariantBase> options;
+               map<string, Glib::VariantBase> options = options_;
 
                // If the output has the capability to write files, use it.
                // Otherwise, open the output stream.
index 946fac4172aab29a270aa37dd276c2b4f88a6507..9f31d59a7920c93d6252dba98acf0eee8fcef0d9 100644 (file)
 
 #include <atomic>
 #include <fstream>
+#include <map>
 #include <memory>
 #include <mutex>
 #include <string>
 #include <thread>
 
+#include <glibmm/variant.h>
+
 #include <QObject>
 
 namespace sigrok {
@@ -55,6 +58,7 @@ private:
 public:
        StoreSession(const std::string &file_name,
                const std::shared_ptr<sigrok::OutputFormat> &output_format,
+               const std::map<std::string, Glib::VariantBase> &options,
                const Session &session);
 
        ~StoreSession();
@@ -78,6 +82,7 @@ Q_SIGNALS:
 private:
        const std::string file_name_;
        const std::shared_ptr<sigrok::OutputFormat> output_format_;
+       const std::map<std::string, Glib::VariantBase> options_;
        const Session &session_;
 
        std::shared_ptr<sigrok::Output> output_;