]> sigrok.org Git - pulseview.git/commitdiff
Added initial support for export
authorJoel Holdsworth <redacted>
Sat, 17 Jan 2015 19:35:33 +0000 (19:35 +0000)
committerUwe Hermann <redacted>
Tue, 27 Jan 2015 15:28:31 +0000 (16:28 +0100)
pv/mainwindow.cpp
pv/mainwindow.hpp
pv/toolbars/mainbar.cpp

index 039f4aeb7b3c9871f66cd8ebddf78ca69cc0d5c8..c30720be182de05ec02e319c093e6221b507affd 100644 (file)
@@ -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> device)
        }
 }
 
+void MainWindow::export_file(shared_ptr<OutputFormat> 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<sigrok::OutputFormat>)),
+               this, SLOT(export_file(std::shared_ptr<sigrok::OutputFormat>)));
+       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()
index 2548e0ef4d8a1ceade73d6e2ea3cabf76adcd011..f975ca516b5dbc0c84dbccd1e2c967e256ac3467 100644 (file)
@@ -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<sigrok::Device> device);
 
+public Q_SLOTS:
+       void export_file(std::shared_ptr<sigrok::OutputFormat> format);
+
 private:
        void setup_ui();
 
index acab199da8853dbd075c1665a3dabdbb8a4fe5ab..4ff8235727fd3ffea81c118eb0ab62c847f3503b 100644 (file)
@@ -36,6 +36,7 @@
 #include <pv/popups/deviceoptions.hpp>
 #include <pv/popups/channels.hpp>
 #include <pv/util.hpp>
+#include <pv/widgets/exportmenu.hpp>
 
 #include <libsigrokcxx/libsigrokcxx.hpp>
 
@@ -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<sigrok::OutputFormat>)),
+               &main_window_,
+               SLOT(export_file(std::shared_ptr<sigrok::OutputFormat>)));
+
+       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());