X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fmainwindow.cpp;h=db596c18ebe2a41d37ddc6fac107bfad9075e304;hb=25272feeeffbf2f67645a7be29ac8704c41c1bb0;hp=3c5af937fda9546eaf67e84b08a04eb819e41861;hpb=574c568d184240cd87be1b57fc00d60a4eac7566;p=pulseview.git diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 3c5af93..db596c1 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -42,6 +42,8 @@ #include #include +#include + #include "mainwindow.hpp" #include "devicemanager.hpp" @@ -73,7 +75,9 @@ using std::cerr; using std::endl; using std::list; +using std::make_shared; using std::map; +using std::max; using std::pair; using std::shared_ptr; using std::string; @@ -177,6 +181,11 @@ QAction* MainWindow::action_view_sticky_scrolling() const return action_view_sticky_scrolling_; } +QAction* MainWindow::action_view_coloured_bg() const +{ + return action_view_coloured_bg_; +} + QAction* MainWindow::action_view_show_cursors() const { return action_view_show_cursors_; @@ -252,7 +261,8 @@ void MainWindow::export_file(shared_ptr format, const pv::util::Timestamp& start_time = view_->cursors()->first()->time(); const pv::util::Timestamp& end_time = view_->cursors()->second()->time(); - const uint64_t start_sample = start_time.convert_to() * samplerate; + const uint64_t start_sample = + std::max((double)0, start_time.convert_to() * samplerate); const uint64_t end_sample = end_time.convert_to() * samplerate; sample_range = std::make_pair(start_sample, end_sample); @@ -269,7 +279,7 @@ void MainWindow::export_file(shared_ptr format, filter += "(*.*)"; else filter += QString("(*.%1);;%2 (*.*)").arg( - QString::fromStdString(join(exts, ", *."))).arg( + QString::fromStdString(join(exts, ", *.")), tr("All Files")); // Show the file dialog @@ -310,7 +320,7 @@ void MainWindow::import_file(shared_ptr format) const vector exts = format->extensions(); const QString filter = exts.empty() ? "" : tr("%1 files (*.%2)").arg( - QString::fromStdString(format->description())).arg( + QString::fromStdString(format->description()), QString::fromStdString(join(exts, ", *."))); // Show the file dialog @@ -349,16 +359,14 @@ void MainWindow::setup_ui() icon.addFile(QString(":/icons/sigrok-logo-notext.svg")); setWindowIcon(icon); - // Setup the central widget - central_widget_ = new QWidget(this); - vertical_layout_ = new QVBoxLayout(central_widget_); - vertical_layout_->setSpacing(6); - vertical_layout_->setContentsMargins(0, 0, 0, 0); - setCentralWidget(central_widget_); - - view_ = new pv::view::View(session_, this); + // Set up the initial view + shared_ptr view = make_shared(session_, this); + shared_ptr dock = make_shared(tr("Untitled"), this); + dock->setWidget(view.get()); + addDockWidget(Qt::TopDockWidgetArea, dock.get()); + view_docks_[dock] = view; - vertical_layout_->addWidget(view_); + view_ = view.get(); // view_ will be refactored later // Setup the menu bar pv::widgets::HidingMenuBar *const menu_bar = @@ -562,8 +570,9 @@ void MainWindow::select_init_device() QSettings settings; map dev_info; list key_list; + shared_ptr device; - // Re-select last used device if possible. + // Re-select last used device if possible but only if it's not demo settings.beginGroup("Device"); key_list.push_back("vendor"); key_list.push_back("model"); @@ -581,8 +590,24 @@ void MainWindow::select_init_device() dev_info.insert(std::make_pair(key, value)); } - const shared_ptr device = - device_manager_.find_device_from_info(dev_info); + if (dev_info.count("model") > 0) + if (dev_info.at("model").find("Demo device") == std::string::npos) + device = device_manager_.find_device_from_info(dev_info); + + // When we can't find a device similar to the one we used last + // time and there is at least one device aside from demo, use it + if (!device) { + for (shared_ptr dev : device_manager_.devices()) { + dev_info = device_manager_.get_device_info(dev); + + if (dev_info.count("model") > 0) + if (dev_info.at("model").find("Demo device") == std::string::npos) { + device = dev; + break; + } + } + } + select_device(device); update_device_list(); @@ -858,8 +883,11 @@ void MainWindow::device_selected() { // Set the title to include the device/file name const shared_ptr device = session_.device(); - if (!device) + + if (!device) { + main_bar_->reset_device_selector(); return; + } const string display_name = device->display_name(device_manager_); setWindowTitle(tr("%1 - PulseView").arg(display_name.c_str()));