X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=pv%2Fmainwindow.cpp;h=ee2227d55782d957b3fb08e00f3961819759d464;hb=3d79f521396c8e908fd237f5328153165099f5c3;hp=0184ef0937c2fd6029cbd0899c8d6719ed3899db;hpb=2220e94218298b208041c5e828595d9e1b842c88;p=pulseview.git diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 0184ef09..ee2227d5 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -134,6 +134,11 @@ QAction* MainWindow::action_save_as() const return action_save_as_; } +QAction* MainWindow::action_save_selection_as() const +{ + return action_save_selection_as_; +} + QAction* MainWindow::action_connect() const { return action_connect_; @@ -218,7 +223,8 @@ void MainWindow::select_device(shared_ptr device) } } -void MainWindow::export_file(shared_ptr format) +void MainWindow::export_file(shared_ptr format, + bool selection_only) { using pv::dialogs::StoreProgress; @@ -228,6 +234,30 @@ void MainWindow::export_file(shared_ptr format) QSettings settings; const QString dir = settings.value(SettingSaveDirectory).toString(); + std::pair sample_range; + + // Selection only? Verify that the cursors are active and fetch their values + if (selection_only) { + if (!view_->cursors()->enabled()) { + show_session_error(tr("Missing Cursors"), tr("You need to set the " \ + "cursors before you can save the data enclosed by them " \ + "to a session file (e.g. using ALT-V - Show Cursors).")); + return; + } + + const double samplerate = session_.get_samplerate(); + + const pv::util::Timestamp& start_time = view_->cursors()->first()->time(); + const pv::util::Timestamp& end_time = view_->cursors()->second()->time(); + + const uint64_t start_sample = start_time.convert_to() * samplerate; + const uint64_t end_sample = end_time.convert_to() * samplerate; + + sample_range = std::make_pair(start_sample, end_sample); + } else { + sample_range = std::make_pair(0, 0); + } + // Construct the filter const vector exts = format->extensions(); QString filter = tr("%1 files ").arg( @@ -262,8 +292,6 @@ void MainWindow::export_file(shared_ptr format) options = dlg.options(); } - const std::pair sample_range = std::make_pair(0, 0); - StoreProgress *dlg = new StoreProgress(file_name, format, options, sample_range, session_, this); dlg->run(); @@ -661,75 +689,6 @@ void MainWindow::load_file(QString file_name, session_error(errorMessage, infoMessage); }); } -void MainWindow::save_selection_to_file() -{ - // Stop any currently running capture session - session_.stop_capture(); - - // Verify that the cursors are active and fetch their values - if (!view_->cursors()->enabled()) { - show_session_error(tr("Missing Cursors"), tr("You need to set the " \ - "cursors before you can save the data enclosed by them " \ - "to a session file (e.g. using ALT-V - Show Cursors).")); - return; - } - - const double samplerate = session_.get_samplerate(); - - const pv::util::Timestamp& start_time = view_->cursors()->first()->time(); - const pv::util::Timestamp& end_time = view_->cursors()->second()->time(); - - const uint64_t start_sample = start_time.convert_to() * samplerate; - const uint64_t end_sample = end_time.convert_to() * samplerate; - - const std::pair sample_range = - std::make_pair(start_sample, end_sample); - - // Ask for output file name - QSettings settings; - const QString dir = settings.value(SettingSaveDirectory).toString(); - - shared_ptr format = - device_manager_.context()->output_formats()["srzip"]; - - const vector exts = format->extensions(); - QString filter = tr("%1 files ").arg( - QString::fromStdString(format->description())); - - if (exts.empty()) - filter += "(*.*)"; - else - filter += QString("(*.%1);;%2 (*.*)").arg( - QString::fromStdString(join(exts, ", *."))).arg( - tr("All Files")); - - const QString file_name = QFileDialog::getSaveFileName( - this, tr("Save File"), dir, filter); - - if (file_name.isEmpty()) - return; - - const QString abs_path = QFileInfo(file_name).absolutePath(); - settings.setValue(SettingSaveDirectory, abs_path); - - // 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(); - } - - // Save - pv::dialogs::StoreProgress *dlg = new pv::dialogs::StoreProgress(file_name, - format, options, sample_range, session_, this); - dlg->run(); -} - void MainWindow::closeEvent(QCloseEvent *event) { save_ui_settings(); @@ -782,7 +741,7 @@ void MainWindow::on_actionSaveAs_triggered() void MainWindow::on_actionSaveSelectionAs_triggered() { - save_selection_to_file(); + export_file(device_manager_.context()->output_formats()["srzip"], true); } void MainWindow::on_actionConnect_triggered()