#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)),
action_save_setup_(new QAction(this)),
action_connect_(new QAction(this)),
+ new_view_button_(new QToolButton()),
open_button_(new QToolButton()),
save_button_(new QToolButton()),
device_selector_(parent, session.device_manager(), action_connect_),
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"));
action_open_->setText(tr("&Open..."));
action_open_->setIcon(QIcon::fromTheme("document-open",
QIcon(":/icons/document-open.png")));
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+ action_open_->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_O));
+#else
action_open_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O));
+#endif
connect(action_open_, SIGNAL(triggered(bool)),
this, SLOT(on_actionOpen_triggered()));
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")));
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+ action_save_->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S));
+#else
+ action_save_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
+#endif
+ 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()));
action_save_selection_as_->setText(tr("Save Selected &Range As..."));
action_save_selection_as_->setIcon(QIcon::fromTheme("document-save-as",
QIcon(":/icons/document-save-as.png")));
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+ action_save_selection_as_->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_R));
+#else
action_save_selection_as_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R));
+#endif
connect(action_save_selection_as_, SIGNAL(triggered(bool)),
this, SLOT(on_actionSaveSelectionAs_triggered()));
connect(action_connect_, SIGNAL(triggered(bool)),
this, SLOT(on_actionConnect_triggered()));
+ // New view button
+ QMenu *menu_new_view = new QMenu();
+ connect(menu_new_view, SIGNAL(triggered(QAction*)),
+ this, SLOT(on_actionNewView_triggered(QAction*)));
+
+ for (int i = 0; i < views::ViewTypeCount; i++) {
+ QAction *const action = menu_new_view->addAction(tr(views::ViewTypeNames[i]));
+ action->setData(QVariant::fromValue(i));
+ }
+
+ new_view_button_->setMenu(menu_new_view);
+ new_view_button_->setDefaultAction(action_new_view_);
+ new_view_button_->setPopupMode(QToolButton::MenuButtonPopup);
+
// Open button
vector<QAction*> open_actions;
open_actions.push_back(action_open_);
// 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
add_decoder_button_->setIcon(QIcon(":/icons/add-decoder.svg"));
add_decoder_button_->setPopupMode(QToolButton::InstantPopup);
add_decoder_button_->setToolTip(tr("Add protocol decoder"));
+ add_decoder_button_->setShortcut(QKeySequence(Qt::Key_D));
connect(add_decoder_button_, SIGNAL(clicked()),
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);
options = dlg.options();
}
- session_.load_file(file_name, nullptr, format, options);
+ session_.load_file(file_name, "", format, options);
const QString abs_path = QFileInfo(file_name).absolutePath();
settings.setValue(SettingOpenDirectory, abs_path);
commit_sample_rate();
}
-void MainBar::on_actionNewView_triggered()
+void MainBar::on_actionNewView_triggered(QAction* action)
{
- new_view(&session_);
+ if (action)
+ new_view(&session_, action->data().toInt());
+ else
+ // When the icon of the button is clicked, we create a trace view
+ new_view(&session_, views::ViewTypeTrace);
}
void MainBar::on_actionOpen_triggered()
}
}
+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()
{
- addAction(action_new_view_);
+ addWidget(new_view_button_);
addSeparator();
addWidget(open_button_);
addWidget(save_button_);
addSeparator();
addWidget(add_decoder_button_);
#endif
+ addWidget(add_math_signal_button_);
}
bool MainBar::eventFilter(QObject *watched, QEvent *event)