using std::endl;
using std::list;
using std::map;
+using std::max;
using std::pair;
using std::shared_ptr;
using std::string;
action_view_zoom_fit_(new QAction(this)),
action_view_zoom_one_to_one_(new QAction(this)),
action_view_sticky_scrolling_(new QAction(this)),
+ action_view_coloured_bg_(new QAction(this)),
action_view_show_cursors_(new QAction(this)),
action_about_(new QAction(this))
#ifdef ENABLE_DECODE
, menu_decoders_add_(new pv::widgets::DecoderMenu(this, true))
#endif
{
+ qRegisterMetaType<util::Timestamp>("util::Timestamp");
+
setup_ui();
restore_ui_settings();
if (open_file_name.empty())
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_;
void MainWindow::run_stop()
{
- switch(session_.get_capture_state()) {
+ switch (session_.get_capture_state()) {
case Session::Stopped:
session_.start_capture([&](QString message) {
session_error("Capture failed", message); });
break;
-
case Session::AwaitingTrigger:
case Session::Running:
session_.stop_capture();
session_.set_device(device);
else
session_.set_default_device();
- } catch(const QString &e) {
+ } catch (const QString &e) {
QMessageBox msg(this);
msg.setText(e);
msg.setInformativeText(tr("Failed to Select Device"));
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<double>() * samplerate;
- const uint64_t end_sample = end_time.convert_to<double>() * samplerate;
+ const uint64_t start_sample =
+ std::max((double)0, start_time.convert_to<double>() * samplerate);
+ const uint64_t end_sample = end_time.convert_to<double>() * samplerate;
- sample_range = std::make_pair(start_sample, end_sample);
+ sample_range = std::make_pair(start_sample, end_sample);
} else {
sample_range = std::make_pair(0, 0);
}
filter += "(*.*)";
else
filter += QString("(*.%1);;%2 (*.*)").arg(
- QString::fromStdString(join(exts, ", *."))).arg(
+ QString::fromStdString(join(exts, ", *.")),
tr("All Files"));
// Show the file dialog
const vector<string> 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
QString::fromUtf8("actionViewZoomOneToOne"));
menu_view->addAction(action_view_zoom_one_to_one_);
- menu_file->addSeparator();
+ menu_view->addSeparator();
action_view_sticky_scrolling_->setCheckable(true);
action_view_sticky_scrolling_->setChecked(true);
menu_view->addSeparator();
+ action_view_coloured_bg_->setCheckable(true);
+ action_view_coloured_bg_->setChecked(true);
+ action_view_coloured_bg_->setShortcut(QKeySequence(Qt::Key_B));
+ action_view_coloured_bg_->setObjectName(
+ QString::fromUtf8("actionViewColouredBg"));
+ action_view_coloured_bg_->setText(tr("Use &coloured backgrounds"));
+ menu_view->addAction(action_view_coloured_bg_);
+
+ view_->enable_coloured_bg(action_view_coloured_bg_->isChecked());
+
+ menu_view->addSeparator();
+
action_view_show_cursors_->setCheckable(true);
action_view_show_cursors_->setChecked(view_->cursors_shown());
action_view_show_cursors_->setIcon(QIcon::fromTheme("show-cursors",
SLOT(capture_state_changed(int)));
connect(&session_, SIGNAL(device_selected()), this,
SLOT(device_selected()));
+ connect(&session_, SIGNAL(trigger_event(util::Timestamp)), view_,
+ SLOT(trigger_event(util::Timestamp)));
// Setup view_ events
connect(view_, SIGNAL(sticky_scrolling_changed(bool)), this,
SLOT(sticky_scrolling_changed(bool)));
connect(view_, SIGNAL(always_zoom_to_fit_changed(bool)), this,
SLOT(always_zoom_to_fit_changed(bool)));
+
}
-void MainWindow::select_init_device() {
+void MainWindow::select_init_device()
+{
QSettings settings;
map<string, string> dev_info;
list<string> key_list;
+ shared_ptr<devices::HardwareDevice> 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");
dev_info.insert(std::make_pair(key, value));
}
- const shared_ptr<devices::HardwareDevice> 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<devices::HardwareDevice> 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();
}
void MainWindow::load_init_file(const std::string &file_name,
- const std::string &format) {
+ const std::string &format)
+{
shared_ptr<InputFormat> input_format;
if (!format.empty()) {
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()));
new devices::SessionFile(
device_manager_.context(),
file_name.toStdString())));
- } catch(Error e) {
+ } catch (Error e) {
show_session_error(tr("Failed to load ") + file_name, e.what());
session_.set_default_device();
update_device_list();
view_->enable_sticky_scrolling(action_view_sticky_scrolling_->isChecked());
}
+void MainWindow::on_actionViewColouredBg_triggered()
+{
+ view_->enable_coloured_bg(action_view_coloured_bg_->isChecked());
+}
+
void MainWindow::on_actionViewShowCursors_triggered()
{
assert(view_);
{
// Set the title to include the device/file name
const shared_ptr<devices::Device> 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()));