]> sigrok.org Git - pulseview.git/blame - pv/widgets/exportmenu.cpp
TraceView: Fix variable name
[pulseview.git] / pv / widgets / exportmenu.cpp
CommitLineData
ce6001b8
JH
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
5 *
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.
10 *
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.
15 *
16 * You should have received a copy of the GNU General Public License
efdec55a 17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
ce6001b8
JH
18 */
19
20#include <algorithm>
21#include <cassert>
22#include <string>
23#include <utility>
24
25#include <libsigrokcxx/libsigrokcxx.hpp>
26
27#include "exportmenu.hpp"
28
29using std::find_if;
30using std::map;
31using std::pair;
32using std::string;
33using std::shared_ptr;
34
35using sigrok::Context;
36using sigrok::OutputFormat;
37
38namespace pv {
39namespace widgets {
40
41ExportMenu::ExportMenu(QWidget *parent, shared_ptr<Context> context,
686d9151 42 std::vector<QAction *>open_actions) :
ce6001b8
JH
43 QMenu(parent),
44 context_(context),
45 mapper_(this)
46{
47 assert(context);
48
686d9151
SA
49 if (!open_actions.empty()) {
50 bool first_action = true;
51 for (auto open_action : open_actions) {
52 addAction(open_action);
53
54 if (first_action) {
55 first_action = false;
56 setDefaultAction(open_action);
57 }
58 }
ce6001b8
JH
59 addSeparator();
60 }
61
62 const map<string, shared_ptr<OutputFormat> > formats =
63 context->output_formats();
64
65 for (const pair<string, shared_ptr<OutputFormat> > &f : formats) {
66 if (f.first == "srzip")
67 continue;
68
69 assert(f.second);
70 QAction *const action = addAction(tr("Export %1...")
71 .arg(QString::fromStdString(f.second->description())));
72 action->setData(qVariantFromValue((void*)f.second.get()));
73 mapper_.setMapping(action, action);
74 connect(action, SIGNAL(triggered()), &mapper_, SLOT(map()));
75 }
76
77 connect(&mapper_, SIGNAL(mapped(QObject*)),
78 this, SLOT(on_action(QObject*)));
79}
80
81void ExportMenu::on_action(QObject *action)
82{
83 assert(action);
84
85 const map<string, shared_ptr<OutputFormat> > formats =
86 context_->output_formats();
87 const auto iter = find_if(formats.cbegin(), formats.cend(),
88 [&](const pair<string, shared_ptr<OutputFormat> > &f) {
89 return f.second.get() ==
90 ((QAction*)action)->data().value<void*>(); });
91 if (iter == formats.cend())
92 return;
93
94 format_selected((*iter).second);
95}
96
97} // widgets
98} // pv