#include <boost/algorithm/string/join.hpp>
+#include <pv/data/mathsignal.hpp>
#include <pv/devicemanager.hpp>
#include <pv/devices/hardwaredevice.hpp>
#include <pv/devices/inputfile.hpp>
using std::copy;
using std::list;
using std::make_pair;
+using std::make_shared;
using std::map;
using std::max;
using std::min;
StandardBar(session, parent, view, false),
action_new_view_(new QAction(this)),
action_open_(new QAction(this)),
+ action_save_(new QAction(this)),
action_save_as_(new QAction(this)),
action_save_selection_as_(new QAction(this)),
action_restore_setup_(new QAction(this)),
sample_rate_("Hz", this),
updating_sample_rate_(false),
updating_sample_count_(false),
- sample_count_supported_(false)
+ sample_count_supported_(false),
#ifdef ENABLE_DECODE
- , add_decoder_button_(new QToolButton())
+ add_decoder_button_(new QToolButton()),
#endif
+ add_math_signal_button_(new QToolButton())
{
setObjectName(QString::fromUtf8("MainBar"));
connect(action_restore_setup_, SIGNAL(triggered(bool)),
this, SLOT(on_actionRestoreSetup_triggered()));
- action_save_as_->setText(tr("&Save As..."));
+ action_save_->setText(tr("&Save..."));
+ action_save_->setIcon(QIcon::fromTheme("document-save-as",
+ QIcon(":/icons/document-save-as.png")));
+ action_save_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
+ connect(action_save_, SIGNAL(triggered(bool)),
+ this, SLOT(on_actionSave_triggered()));
+
+ action_save_as_->setText(tr("Save &As..."));
action_save_as_->setIcon(QIcon::fromTheme("document-save-as",
QIcon(":/icons/document-save-as.png")));
- action_save_as_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
connect(action_save_as_, SIGNAL(triggered(bool)),
this, SLOT(on_actionSaveAs_triggered()));
// Save button
vector<QAction*> save_actions;
+ save_actions.push_back(action_save_);
save_actions.push_back(action_save_as_);
save_actions.push_back(action_save_selection_as_);
QAction* separator_s = new QAction(this);
this, SLOT(export_file(shared_ptr<sigrok::OutputFormat>)));
save_button_->setMenu(export_menu);
- save_button_->setDefaultAction(action_save_as_);
+ save_button_->setDefaultAction(action_save_);
save_button_->setPopupMode(QToolButton::MenuButtonPopup);
// Device selector menu
this, SLOT(on_add_decoder_clicked()));
#endif
+ // Setup the math signal button
+ add_math_signal_button_->setIcon(QIcon(":/icons/add-math-signal.svg"));
+ add_math_signal_button_->setPopupMode(QToolButton::InstantPopup);
+ add_math_signal_button_->setToolTip(tr("Add math signal"));
+ add_math_signal_button_->setShortcut(QKeySequence(Qt::Key_M));
+
+ connect(add_math_signal_button_, SIGNAL(clicked()),
+ this, SLOT(on_add_math_signal_clicked()));
+
+
connect(&sample_count_, SIGNAL(value_changed()),
this, SLOT(on_sample_count_changed()));
connect(&sample_rate_, SIGNAL(value_changed()),
return action_open_;
}
+QAction* MainBar::action_save() const
+{
+ return action_save_;
+}
+
QAction* MainBar::action_save_as() const
{
return action_save_as_;
sample_count_supported_ = true;
// Add notification of reconfigure events
- disconnect(this, SLOT(on_config_changed()));
+ // Note: No need to disconnect the previous signal as that QObject instance is destroyed
connect(&opts->binding(), SIGNAL(config_changed()),
this, SLOT(on_config_changed()));
msg.exec();
}
-void MainBar::export_file(shared_ptr<OutputFormat> format, bool selection_only)
+void MainBar::export_file(shared_ptr<OutputFormat> format, bool selection_only, QString file_name)
{
using pv::dialogs::StoreProgress;
tr("All Files"));
// Show the file dialog
- const QString file_name = QFileDialog::getSaveFileName(
- this, tr("Save File"), dir, filter);
+ if (file_name.isEmpty())
+ file_name = QFileDialog::getSaveFileName(this, tr("Save File"), dir, filter);
if (file_name.isEmpty())
return;
options = dlg.options();
}
- if (!selection_only)
- session_.set_name(QFileInfo(file_name).fileName());
+ if (!selection_only) {
+ if (format == session_.device_manager().context()->output_formats()["srzip"]) {
+ session_.set_save_path(QFileInfo(file_name).absolutePath());
+ session_.set_name(QFileInfo(file_name).fileName());
+ } else
+ session_.set_save_path("");
+ }
StoreProgress *dlg = new StoreProgress(file_name, format, options,
sample_range, session_, this);
}
}
+void MainBar::on_actionSave_triggered()
+{
+ // A path is only set if we loaded/saved an srzip file before
+ if (session_.save_path().isEmpty()) {
+ on_actionSaveAs_triggered();
+ return;
+ }
+
+ QFileInfo fi = QFileInfo(QDir(session_.save_path()), session_.name());
+ export_file(session_.device_manager().context()->output_formats()["srzip"], false,
+ fi.absoluteFilePath());
+}
+
void MainBar::on_actionSaveAs_triggered()
{
export_file(session_.device_manager().context()->output_formats()["srzip"]);
show_decoder_selector(&session_);
}
+void MainBar::on_add_math_signal_clicked()
+{
+ shared_ptr<data::SignalBase> signal = make_shared<data::MathSignal>(session_);
+ session_.add_generated_signal(signal);
+}
+
void MainBar::add_toolbar_widgets()
{
addWidget(new_view_button_);
addSeparator();
addWidget(add_decoder_button_);
#endif
+ addWidget(add_math_signal_button_);
}
bool MainBar::eventFilter(QObject *watched, QEvent *event)