X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fmainwindow.cpp;h=874f66ce7c2cd8e0fb07d326affa837b7d976d9f;hp=f8463257b5b882531692abc3c0ab4803efdcfa64;hb=3a21afa6;hpb=0f8f8c180b32413177f3940ea6f216d1cbadf09b diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index f8463257..874f66ce 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -38,6 +38,7 @@ #include "devicemanager.hpp" #include "util.hpp" +#include "devices/hardwaredevice.hpp" #include "dialogs/about.hpp" #include "toolbars/mainbar.hpp" #include "view/view.hpp" @@ -46,6 +47,7 @@ #include #include +using std::dynamic_pointer_cast; using std::list; using std::make_shared; using std::map; @@ -65,9 +67,6 @@ MainWindow::MainWindow(DeviceManager &device_manager, QWidget *parent) : QMainWindow(parent), device_manager_(device_manager), - session_(device_manager), - open_file_name_(open_file_name), - open_file_format_(open_file_format), action_view_sticky_scrolling_(new QAction(this)), action_view_coloured_bg_(new QAction(this)), action_about_(new QAction(this)) @@ -76,6 +75,32 @@ MainWindow::MainWindow(DeviceManager &device_manager, setup_ui(); restore_ui_settings(); + + if (!open_file_name.empty()) { + shared_ptr session = add_session(); + session->main_bar()->load_init_file(open_file_name, open_file_format); + } + + // Add empty default session if there aren't any sessions + if (sessions_.size() == 0) { + shared_ptr session = add_session(); + + map dev_info; + shared_ptr other_device, demo_device; + + // Use any available device that's not demo + for (shared_ptr dev : device_manager_.devices()) { + if (dev->hardware_device()->driver()->name() == "demo") { + demo_device = dev; + } else { + other_device = dev; + } + } + + // ...and if there isn't any, just use demo then + session->main_bar()->select_device(other_device ? + other_device : demo_device); + } } MainWindow::~MainWindow() @@ -92,7 +117,10 @@ MainWindow::~MainWindow() dock->setWidget(0); const std::shared_ptr view = entry.second; - session_.deregister_view(view); + + for (shared_ptr session : sessions_) + if (session->has_view(view)) + session->deregister_view(view); } } @@ -163,31 +191,44 @@ shared_ptr MainWindow::add_view(const QString &title, if (type == view::TraceView) { connect(&session, SIGNAL(trigger_event(util::Timestamp)), v.get(), SLOT(trigger_event(util::Timestamp))); - connect(v.get(), SIGNAL(sticky_scrolling_changed(bool)), this, - SLOT(sticky_scrolling_changed(bool))); - connect(v.get(), SIGNAL(always_zoom_to_fit_changed(bool)), this, - SLOT(always_zoom_to_fit_changed(bool))); v->enable_sticky_scrolling(action_view_sticky_scrolling_->isChecked()); v->enable_coloured_bg(action_view_coloured_bg_->isChecked()); shared_ptr main_bar = session.main_bar(); if (!main_bar) { - main_bar = make_shared(session_, *this, - open_file_name_, open_file_format_); + main_bar = make_shared(session, *this); dock_main->addToolBar(main_bar.get()); session.set_main_bar(main_bar); - - open_file_name_.clear(); - open_file_format_.clear(); } main_bar->action_view_show_cursors()->setChecked(v->cursors_shown()); + + connect(v.get(), SIGNAL(always_zoom_to_fit_changed(bool)), + main_bar.get(), SLOT(on_always_zoom_to_fit_changed(bool))); } } return v; } +shared_ptr MainWindow::add_session() +{ + int id = sessions_.size(); + QString name = tr("Untitled-%1").arg(id + 1); + + shared_ptr session = make_shared(device_manager_, name); + + connect(session.get(), SIGNAL(add_view(const QString&, view::ViewType, Session*)), + this, SLOT(on_add_view(const QString&, view::ViewType, Session*))); + + sessions_.push_back(session); + + shared_ptr main_view = + add_view(name, pv::view::TraceView, *session); + + return session; +} + void MainWindow::setup_ui() { setObjectName(QString::fromUtf8("MainWindow")); @@ -214,10 +255,6 @@ void MainWindow::setup_ui() action_about_->setObjectName(QString::fromUtf8("actionAbout")); action_about_->setText(tr("&About...")); - // Set up the initial view - shared_ptr main_view = - add_view(tr("Untitled"), pv::view::TraceView, session_); - // Set the title setWindowTitle(tr("PulseView")); } @@ -225,41 +262,38 @@ void MainWindow::setup_ui() void MainWindow::save_ui_settings() { QSettings settings; - - map dev_info; - list key_list; + int id = 0; settings.beginGroup("MainWindow"); settings.setValue("state", saveState()); settings.setValue("geometry", saveGeometry()); settings.endGroup(); - if (session_.device()) { - settings.beginGroup("Device"); - key_list.push_back("vendor"); - key_list.push_back("model"); - key_list.push_back("version"); - key_list.push_back("serial_num"); - key_list.push_back("connection_id"); - - dev_info = device_manager_.get_device_info( - session_.device()); - - for (string key : key_list) { - if (dev_info.count(key)) - settings.setValue(QString::fromUtf8(key.c_str()), - QString::fromUtf8(dev_info.at(key).c_str())); - else - settings.remove(QString::fromUtf8(key.c_str())); + for (shared_ptr session : sessions_) { + // Ignore sessions using the demo device + if (session->device()) { + shared_ptr device = + dynamic_pointer_cast< devices::HardwareDevice > + (session->device()); + + if (device && + device->hardware_device()->driver()->name() == "demo") + continue; } + settings.beginGroup("Session" + QString::number(id++)); + settings.remove(""); // Remove all keys in this group + session->save_settings(settings); settings.endGroup(); } + + settings.setValue("sessions", id); } void MainWindow::restore_ui_settings() { QSettings settings; + int i, session_count; settings.beginGroup("MainWindow"); @@ -270,6 +304,15 @@ void MainWindow::restore_ui_settings() resize(1000, 720); settings.endGroup(); + + session_count = settings.value("sessions", 0).toInt(); + + for (i = 0; i < session_count; i++) { + settings.beginGroup("Session" + QString::number(i)); + shared_ptr session = add_session(); + session->restore_settings(settings); + settings.endGroup(); + } } void MainWindow::closeEvent(QCloseEvent *event) @@ -294,6 +337,15 @@ bool MainWindow::restoreState(const QByteArray &state, int version) return false; } +void MainWindow::on_add_view(const QString &title, view::ViewType type, + Session *session) +{ + // We get a pointer and need a reference + for (std::shared_ptr s : sessions_) + if (s.get() == session) + add_view(title, type, *s); +} + void MainWindow::on_actionViewStickyScrolling_triggered() { shared_ptr view = get_active_view();