]> sigrok.org Git - pulseview.git/commitdiff
MainWindow: Added initial import menu with no options
authorJoel Holdsworth <redacted>
Sat, 17 Jan 2015 15:58:21 +0000 (15:58 +0000)
committerUwe Hermann <redacted>
Thu, 11 Jun 2015 18:38:48 +0000 (20:38 +0200)
pv/mainwindow.cpp
pv/mainwindow.hpp
pv/toolbars/mainbar.cpp
pv/toolbars/mainbar.hpp

index a339b19a1b8b3963c59a21a1d075a4493effdb2f..e48df546613a308b9e1374df3ea197be56fc71c5 100644 (file)
@@ -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<OutputFormat> format)
        dlg->run();
 }
 
+void MainWindow::import_file(shared_ptr<InputFormat> format)
+{
+       assert(format);
+
+       QSettings settings;
+       const QString dir = settings.value(SettingOpenDirectory).toString();
+
+       // Construct the filter
+       const vector<string> 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<sigrok::OutputFormat>)));
        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<sigrok::InputFormat>)),
+               this, SLOT(import_file(std::shared_ptr<sigrok::InputFormat>)));
+       menu_file->addAction(menu_file_import->menuAction());
+
        menu_file->addSeparator();
 
        action_connect_->setText(tr("&Connect to Device..."));
index 35ccf0655d10b4e37699f87d47d9f308cb007822..99772e3d0037aad26ca983fefb1ca00242b46d5b 100644 (file)
@@ -102,6 +102,7 @@ public:
 
 public Q_SLOTS:
        void export_file(std::shared_ptr<sigrok::OutputFormat> format);
+       void import_file(std::shared_ptr<sigrok::InputFormat> format);
 
 private:
        void setup_ui();
index 9c5049dd8aa92d291e9c8b0e5b1e92b823685262..8c2be4686b29075711e1c1a5926855518f8aed8f 100644 (file)
@@ -38,6 +38,7 @@
 #include <pv/popups/channels.hpp>
 #include <pv/util.hpp>
 #include <pv/widgets/exportmenu.hpp>
+#include <pv/widgets/importmenu.hpp>
 
 #include <libsigrokcxx/libsigrokcxx.hpp>
 
@@ -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<sigrok::InputFormat>)),
+               &main_window_,
+               SLOT(import_file(std::shared_ptr<sigrok::InputFormat>)));
+
+       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());
index 64c8a6c7e146aa1cba8564e30d2bf3a9fe0dbc3b..8e299dc9f8a121436c77891ad9fbb0ce7ac9c656 100644 (file)
@@ -38,7 +38,8 @@
 #include <pv/widgets/sweeptimingwidget.hpp>
 
 namespace sigrok {
-       class Device;
+class Device;
+class InputFormat;
 }
 
 Q_DECLARE_METATYPE(std::shared_ptr<sigrok::Device>)