From e93f553816d1938ab1917dff497a36acec4257e3 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Tue, 20 Jan 2015 20:14:43 -0500 Subject: [PATCH 1/1] Added pv::dialogs::InputOutputOptions --- CMakeLists.txt | 2 + pv/dialogs/inputoutputoptions.cpp | 69 ++++++++++++++++++++++++++++++ pv/dialogs/inputoutputoptions.hpp | 71 +++++++++++++++++++++++++++++++ pv/dialogs/storeprogress.cpp | 8 +++- pv/dialogs/storeprogress.hpp | 1 + pv/mainwindow.cpp | 17 +++++++- pv/storesession.cpp | 8 +++- pv/storesession.hpp | 5 +++ 8 files changed, 176 insertions(+), 5 deletions(-) create mode 100644 pv/dialogs/inputoutputoptions.cpp create mode 100644 pv/dialogs/inputoutputoptions.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 99314d05..79dd8f8b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 index 00000000..8f013a26 --- /dev/null +++ b/pv/dialogs/inputoutputoptions.cpp @@ -0,0 +1,69 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2012 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 + */ + +#include "inputoutputoptions.hpp" + +#include + +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> &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& 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 index 00000000..cde778c0 --- /dev/null +++ b/pv/dialogs/inputoutputoptions.hpp @@ -0,0 +1,71 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2015 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_DIALOGS_INPUTOUTPUTOPTIONS_HPP +#define PULSEVIEW_PV_DIALOGS_INPUTOUTPUTOPTIONS_HPP + +#include +#include +#include +#include + +#include + +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> + &options, + QWidget *parent); + + /** + * Gets the map of selected options. + * @return the options. + */ + const std::map& options() const; + +protected: + void accept(); + +private: + QVBoxLayout layout_; + QDialogButtonBox button_box_; + pv::binding::InputOutput binding_; +}; + +} // namespace dialogs +} // namespace pv + +#endif // PULSEVIEW_PV_INPUTOUTPUTOPTIONS_HPP diff --git a/pv/dialogs/storeprogress.cpp b/pv/dialogs/storeprogress.cpp index dff8950a..a7f889e0 100644 --- a/pv/dialogs/storeprogress.cpp +++ b/pv/dialogs/storeprogress.cpp @@ -24,14 +24,20 @@ #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 output_format, + const map &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())); diff --git a/pv/dialogs/storeprogress.hpp b/pv/dialogs/storeprogress.hpp index 389aad81..19aef14a 100644 --- a/pv/dialogs/storeprogress.hpp +++ b/pv/dialogs/storeprogress.hpp @@ -41,6 +41,7 @@ class StoreProgress : public QProgressDialog public: StoreProgress(const QString &file_name, const std::shared_ptr output_format, + const std::map &options, const Session &session, QWidget *parent = 0); virtual ~StoreProgress(); diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index c30720be..81112aba 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -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 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 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 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(); } diff --git a/pv/storesession.cpp b/pv/storesession.cpp index d58fd498..92f64f5b 100644 --- a/pv/storesession.cpp +++ b/pv/storesession.cpp @@ -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 &output_format, const Session &session) : + const shared_ptr &output_format, + const map &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 options; + map options = options_; // If the output has the capability to write files, use it. // Otherwise, open the output stream. diff --git a/pv/storesession.hpp b/pv/storesession.hpp index 946fac41..9f31d59a 100644 --- a/pv/storesession.hpp +++ b/pv/storesession.hpp @@ -25,11 +25,14 @@ #include #include +#include #include #include #include #include +#include + #include namespace sigrok { @@ -55,6 +58,7 @@ private: public: StoreSession(const std::string &file_name, const std::shared_ptr &output_format, + const std::map &options, const Session &session); ~StoreSession(); @@ -78,6 +82,7 @@ Q_SIGNALS: private: const std::string file_name_; const std::shared_ptr output_format_; + const std::map options_; const Session &session_; std::shared_ptr output_; -- 2.30.2