From: Joel Holdsworth Date: Sat, 17 Jan 2015 19:35:33 +0000 (+0000) Subject: Added initial support for export X-Git-Tag: pulseview-0.3.0~242 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=998b89fd858e0dfc09c97cc4e3de718643f0017b;p=pulseview.git Added initial support for export --- diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 039f4aeb..c30720be 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -49,6 +49,7 @@ #include "toolbars/mainbar.hpp" #include "view/logicsignal.hpp" #include "view/view.hpp" +#include "widgets/exportmenu.hpp" #ifdef ENABLE_DECODE #include "widgets/decodermenu.hpp" #endif @@ -68,6 +69,7 @@ using std::string; using sigrok::Device; using sigrok::Error; using sigrok::HardwareDevice; +using sigrok::OutputFormat; namespace pv { @@ -190,6 +192,32 @@ void MainWindow::select_device(shared_ptr device) } } +void MainWindow::export_file(shared_ptr format) +{ + using pv::dialogs::StoreProgress; + + // Stop any currently running capture session + session_.stop_capture(); + + QSettings settings; + const QString dir = settings.value(SettingSaveDirectory).toString(); + + // Show the dialog + const QString file_name = QFileDialog::getSaveFileName( + this, tr("Save File"), dir, tr("%1 files (*.*)").arg( + QString::fromStdString(format->description()))); + + if (file_name.isEmpty()) + return; + + const QString abs_path = QFileInfo(file_name).absolutePath(); + settings.setValue(SettingSaveDirectory, abs_path); + + StoreProgress *dlg = new StoreProgress(file_name, format, + session_, this); + dlg->run(); +} + void MainWindow::setup_ui() { setObjectName(QString::fromUtf8("MainWindow")); @@ -234,6 +262,16 @@ void MainWindow::setup_ui() menu_file->addSeparator(); + widgets::ExportMenu *menu_file_export = new widgets::ExportMenu(this, + device_manager_.context()); + menu_file_export->setTitle(tr("&Export")); + connect(menu_file_export, + SIGNAL(format_selected(std::shared_ptr)), + this, SLOT(export_file(std::shared_ptr))); + menu_file->addAction(menu_file_export->menuAction()); + + menu_file->addSeparator(); + action_connect_->setText(tr("&Connect to Device...")); action_connect_->setObjectName(QString::fromUtf8("actionConnect")); menu_file->addAction(action_connect_); @@ -509,28 +547,7 @@ void MainWindow::on_actionOpen_triggered() void MainWindow::on_actionSaveAs_triggered() { - using pv::dialogs::StoreProgress; - - // Stop any currently running capture session - session_.stop_capture(); - - QSettings settings; - const QString dir = settings.value(SettingSaveDirectory).toString(); - - // Show the dialog - const QString file_name = QFileDialog::getSaveFileName( - this, tr("Save File"), dir, tr("Sigrok Sessions (*.sr)")); - - if (file_name.isEmpty()) - return; - - const QString abs_path = QFileInfo(file_name).absolutePath(); - settings.setValue(SettingSaveDirectory, abs_path); - - StoreProgress *dlg = new StoreProgress(file_name, - device_manager_.context()->output_formats()["srzip"], - session_, this); - dlg->run(); + export_file(device_manager_.context()->output_formats()["srzip"]); } void MainWindow::on_actionConnect_triggered() diff --git a/pv/mainwindow.hpp b/pv/mainwindow.hpp index 2548e0ef..f975ca51 100644 --- a/pv/mainwindow.hpp +++ b/pv/mainwindow.hpp @@ -34,6 +34,7 @@ class QVBoxLayout; namespace sigrok { class Device; +class OutputFormat; } namespace pv { @@ -92,6 +93,9 @@ public: void select_device(std::shared_ptr device); +public Q_SLOTS: + void export_file(std::shared_ptr format); + private: void setup_ui(); diff --git a/pv/toolbars/mainbar.cpp b/pv/toolbars/mainbar.cpp index acab199d..4ff82357 100644 --- a/pv/toolbars/mainbar.cpp +++ b/pv/toolbars/mainbar.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include @@ -87,6 +88,21 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : setFloatable(false); setContextMenuPolicy(Qt::PreventContextMenu); + // Save button + QToolButton *const save_button = new QToolButton(this); + + widgets::ExportMenu *export_menu = new widgets::ExportMenu(this, + session.device_manager().context(), + main_window.action_save_as()); + connect(export_menu, + SIGNAL(format_selected(std::shared_ptr)), + &main_window_, + SLOT(export_file(std::shared_ptr))); + + save_button->setMenu(export_menu); + save_button->setDefaultAction(main_window.action_save_as()); + save_button->setPopupMode(QToolButton::MenuButtonPopup); + // Device selector menu connect(&device_selector_, SIGNAL(device_selected()), this, SLOT(on_device_selected())); @@ -118,7 +134,7 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : // Setup the toolbar addAction(main_window.action_open()); - addAction(main_window.action_save_as()); + addWidget(save_button); addSeparator(); addAction(main_window.action_view_zoom_in()); addAction(main_window.action_view_zoom_out());