2 * This file is part of the PulseView project.
4 * Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #include <libsigrokcxx/libsigrokcxx.hpp>
28 #include "importmenu.hpp"
34 using std::shared_ptr;
36 using sigrok::Context;
37 using sigrok::InputFormat;
42 ImportMenu::ImportMenu(QWidget *parent, shared_ptr<Context> context,
43 QAction *open_action) :
51 addAction(open_action);
52 setDefaultAction(open_action);
56 const map<string, shared_ptr<InputFormat> > formats =
57 context->input_formats();
59 for (const pair<string, shared_ptr<InputFormat> > &f : formats) {
61 QAction *const action = addAction(tr("Import %1...")
62 .arg(QString::fromStdString(f.second->description())));
63 action->setData(qVariantFromValue((void*)f.second.get()));
64 mapper_.setMapping(action, action);
65 connect(action, SIGNAL(triggered()), &mapper_, SLOT(map()));
68 connect(&mapper_, SIGNAL(mapped(QObject*)),
69 this, SLOT(on_action(QObject*)));
72 void ImportMenu::on_action(QObject *action)
76 const map<string, shared_ptr<InputFormat> > formats =
77 context_->input_formats();
78 const auto iter = find_if(formats.cbegin(), formats.cend(),
79 [&](const pair<string, shared_ptr<InputFormat> > &f) {
80 return f.second.get() ==
81 ((QAction*)action)->data().value<void*>(); });
82 if (iter == formats.cend())
85 format_selected((*iter).second);