From: Joel Holdsworth Date: Sat, 17 Jan 2015 15:58:21 +0000 (+0000) Subject: MainWindow: Added initial import menu with no options X-Git-Tag: pulseview-0.3.0~200 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=ed43ef2e59baab85aa0381b08db101b7800e5c64;p=pulseview.git MainWindow: Added initial import menu with no options --- diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index a339b19a..e48df546 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -56,6 +56,7 @@ #include "view/logicsignal.hpp" #include "view/view.hpp" #include "widgets/exportmenu.hpp" +#include "widgets/importmenu.hpp" #ifdef ENABLE_DECODE #include "widgets/decodermenu.hpp" #endif @@ -253,6 +254,34 @@ void MainWindow::export_file(shared_ptr format) dlg->run(); } +void MainWindow::import_file(shared_ptr format) +{ + assert(format); + + QSettings settings; + const QString dir = settings.value(SettingOpenDirectory).toString(); + + // Construct the filter + const vector exts = format->extensions(); + const QString filter = exts.empty() ? "" : + tr("%1 files (*.%2)").arg( + QString::fromStdString(format->description())).arg( + QString::fromStdString(join(exts, ", *."))); + + // Show the file dialog + const QString file_name = QFileDialog::getOpenFileName( + this, tr("Import File"), dir, tr( + "%1 files (*.*);;All Files (*.*)").arg( + QString::fromStdString(format->description()))); + + if (!file_name.isEmpty()) { + load_file(file_name, format); + + const QString abs_path = QFileInfo(file_name).absolutePath(); + settings.setValue(SettingOpenDirectory, abs_path); + } +} + void MainWindow::setup_ui() { setObjectName(QString::fromUtf8("MainWindow")); @@ -305,6 +334,14 @@ void MainWindow::setup_ui() this, SLOT(export_file(std::shared_ptr))); menu_file->addAction(menu_file_export->menuAction()); + widgets::ImportMenu *menu_file_import = new widgets::ImportMenu(this, + device_manager_.context()); + menu_file_import->setTitle(tr("&Import")); + connect(menu_file_import, + SIGNAL(format_selected(std::shared_ptr)), + this, SLOT(import_file(std::shared_ptr))); + menu_file->addAction(menu_file_import->menuAction()); + menu_file->addSeparator(); action_connect_->setText(tr("&Connect to Device...")); diff --git a/pv/mainwindow.hpp b/pv/mainwindow.hpp index 35ccf065..99772e3d 100644 --- a/pv/mainwindow.hpp +++ b/pv/mainwindow.hpp @@ -102,6 +102,7 @@ public: public Q_SLOTS: void export_file(std::shared_ptr format); + void import_file(std::shared_ptr format); private: void setup_ui(); diff --git a/pv/toolbars/mainbar.cpp b/pv/toolbars/mainbar.cpp index 9c5049dd..8c2be468 100644 --- a/pv/toolbars/mainbar.cpp +++ b/pv/toolbars/mainbar.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include @@ -54,6 +55,7 @@ using std::vector; using sigrok::Capability; using sigrok::ConfigKey; using sigrok::Error; +using sigrok::InputFormat; namespace pv { namespace toolbars { @@ -88,6 +90,21 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : setFloatable(false); setContextMenuPolicy(Qt::PreventContextMenu); + // Open button + QToolButton *const open_button = new QToolButton(this); + + widgets::ImportMenu *import_menu = new widgets::ImportMenu(this, + session.device_manager().context(), + main_window.action_open()); + connect(import_menu, + SIGNAL(format_selected(std::shared_ptr)), + &main_window_, + SLOT(import_file(std::shared_ptr))); + + open_button->setMenu(import_menu); + open_button->setDefaultAction(main_window.action_open()); + open_button->setPopupMode(QToolButton::MenuButtonPopup); + // Save button QToolButton *const save_button = new QToolButton(this); @@ -133,7 +150,7 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : QIcon(":/icons/menu.svg"))); // Setup the toolbar - addAction(main_window.action_open()); + addWidget(open_button); addWidget(save_button); addSeparator(); addAction(main_window.action_view_zoom_in()); diff --git a/pv/toolbars/mainbar.hpp b/pv/toolbars/mainbar.hpp index 64c8a6c7..8e299dc9 100644 --- a/pv/toolbars/mainbar.hpp +++ b/pv/toolbars/mainbar.hpp @@ -38,7 +38,8 @@ #include namespace sigrok { - class Device; +class Device; +class InputFormat; } Q_DECLARE_METATYPE(std::shared_ptr)