]> sigrok.org Git - pulseview.git/blobdiff - pv/widgets/importmenu.cpp
Session: Fix issue #67 by improving error handling
[pulseview.git] / pv / widgets / importmenu.cpp
index 145bbb43bc14c8357256287b947da89853ecce89..dcca307ecc731bb01e6946fd9f38d4c0ec17f4ac 100644 (file)
@@ -31,6 +31,7 @@ using std::map;
 using std::pair;
 using std::string;
 using std::shared_ptr;
+using std::vector;
 
 using sigrok::Context;
 using sigrok::InputFormat;
@@ -39,33 +40,45 @@ namespace pv {
 namespace widgets {
 
 ImportMenu::ImportMenu(QWidget *parent, shared_ptr<Context> context,
-       QAction *open_action) :
+       vector<QAction *>open_actions) :
        QMenu(parent),
        context_(context),
        mapper_(this)
 {
        assert(context);
 
-       if (open_action) {
-               addAction(open_action);
-               setDefaultAction(open_action);
+       if (!open_actions.empty()) {
+               bool first_action = true;
+               for (auto open_action : open_actions) {
+                       addAction(open_action);
+
+                       if (first_action) {
+                               first_action = false;
+                               setDefaultAction(open_action);
+                       }
+               }
                addSeparator();
        }
 
        const map<string, shared_ptr<InputFormat> > formats =
                context->input_formats();
 
-       for (const pair<string, shared_ptr<InputFormat> > &f : formats) {
+       for (const pair<const string, shared_ptr<InputFormat> > &f : formats) {
                assert(f.second);
                QAction *const action = addAction(tr("Import %1...")
                        .arg(QString::fromStdString(f.second->description())));
-               action->setData(qVariantFromValue((void*)f.second.get()));
+               action->setData(QVariant::fromValue((void*)f.second.get()));
                mapper_.setMapping(action, action);
                connect(action, SIGNAL(triggered()), &mapper_, SLOT(map()));
        }
 
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+       connect(&mapper_, SIGNAL(mappedObject(QObject*)),
+               this, SLOT(on_action(QObject*)));
+#else
        connect(&mapper_, SIGNAL(mapped(QObject*)),
                this, SLOT(on_action(QObject*)));
+#endif
 }
 
 void ImportMenu::on_action(QObject *action)
@@ -84,5 +97,5 @@ void ImportMenu::on_action(QObject *action)
        format_selected((*iter).second);
 }
 
-} // widgets
-} // pv
+}  // namespace widgets
+}  // namespace pv