#include <QVBoxLayout>
#include <QWidget>
+#include <QDockWidget>
+
#include "mainwindow.hpp"
#include "devicemanager.hpp"
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;
}
#endif
+shared_ptr<pv::view::View> MainWindow::get_active_view() const
+{
+ // If there's only one view, use it...
+ if (view_docks_.size() == 1)
+ return view_docks_.begin()->second;
+
+ // ...otherwise find the dock widget the widget with focus is contained in
+ QObject *w = QApplication::focusWidget();
+ QDockWidget *dock = 0;
+
+ while (w) {
+ dock = qobject_cast<QDockWidget*>(w);
+ if (dock)
+ break;
+ w = w->parent();
+ }
+
+ // Get the view contained in the dock widget
+ for (auto entry : view_docks_)
+ if (entry.first.get() == dock)
+ return entry.second;
+
+ return shared_ptr<pv::view::View>();
+}
+
+shared_ptr<pv::view::View> MainWindow::add_view(const QString &title,
+ view::ViewType type, Session &session)
+{
+ shared_ptr<pv::view::View> v;
+
+ if (type == pv::view::TraceView)
+ v = make_shared<pv::view::View>(session, this);
+
+ if (v) {
+ shared_ptr<QDockWidget> dock = make_shared<QDockWidget>(title, this);
+ dock->setWidget(v.get());
+ dock->setObjectName(title);
+ addDockWidget(Qt::TopDockWidgetArea, dock.get());
+ view_docks_[dock] = v;
+
+ dock->setFeatures(QDockWidget::DockWidgetMovable |
+ QDockWidget::DockWidgetFloatable);
+
+ 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());
+ action_view_show_cursors_->setChecked(v->cursors_shown());
+ }
+ }
+
+ return v;
+}
+
void MainWindow::run_stop()
{
switch (session_.get_capture_state()) {
{
using pv::dialogs::StoreProgress;
+ // Make sure there's a view selected to pull the data from
+ shared_ptr<pv::view::View> view = get_active_view();
+ if (!view) {
+ show_session_error(tr("No View Selected"), tr("Please click on the " \
+ "view whose data you want to save and try again."));
+ return;
+ }
+
// Stop any currently running capture session
session_.stop_capture();
// Selection only? Verify that the cursors are active and fetch their values
if (selection_only) {
- if (!view_->cursors()->enabled()) {
+ if (!view->cursors()->enabled()) {
show_session_error(tr("Missing Cursors"), tr("You need to set the " \
"cursors before you can save the data enclosed by them " \
"to a session file (e.g. using ALT-V - Show Cursors)."));
const double samplerate = session_.get_samplerate();
- const pv::util::Timestamp& start_time = view_->cursors()->first()->time();
- const pv::util::Timestamp& end_time = view_->cursors()->second()->time();
+ 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 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);
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
// Set the window icon
QIcon icon;
- icon.addFile(QString(":/icons/sigrok-logo-notext.svg"));
+ icon.addFile(QString(":/icons/sigrok-logo-notext.png"));
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);
-
- vertical_layout_->addWidget(view_);
-
// Setup the menu bar
pv::widgets::HidingMenuBar *const menu_bar =
new pv::widgets::HidingMenuBar(this);
action_view_sticky_scrolling_->setText(tr("&Sticky Scrolling"));
menu_view->addAction(action_view_sticky_scrolling_);
- view_->enable_sticky_scrolling(action_view_sticky_scrolling_->isChecked());
-
menu_view->addSeparator();
action_view_coloured_bg_->setCheckable(true);
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",
QIcon(":/icons/show-cursors.svg")));
action_view_show_cursors_->setShortcut(QKeySequence(Qt::Key_C));
// Setup the toolbar
main_bar_ = new toolbars::MainBar(session_, *this);
+ // Set up the initial view
+ add_view(tr("Untitled"), pv::view::TraceView, session_);
+
// Populate the device list and select the initially selected device
update_device_list();
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::on_actionViewZoomIn_triggered()
{
- view_->zoom(1);
+ shared_ptr<pv::view::View> view = get_active_view();
+ if (view)
+ view->zoom(1);
}
void MainWindow::on_actionViewZoomOut_triggered()
{
- view_->zoom(-1);
+ shared_ptr<pv::view::View> view = get_active_view();
+ if (view)
+ view->zoom(-1);
}
void MainWindow::on_actionViewZoomFit_triggered()
{
- view_->zoom_fit(action_view_zoom_fit_->isChecked());
+ shared_ptr<pv::view::View> view = get_active_view();
+ if (view)
+ view->zoom_fit(action_view_zoom_fit_->isChecked());
}
void MainWindow::on_actionViewZoomOneToOne_triggered()
{
- view_->zoom_one_to_one();
+ shared_ptr<pv::view::View> view = get_active_view();
+ if (view)
+ view->zoom_one_to_one();
}
void MainWindow::on_actionViewStickyScrolling_triggered()
{
- view_->enable_sticky_scrolling(action_view_sticky_scrolling_->isChecked());
+ shared_ptr<pv::view::View> view = get_active_view();
+ if (view)
+ view->enable_sticky_scrolling(action_view_sticky_scrolling_->isChecked());
}
void MainWindow::on_actionViewColouredBg_triggered()
{
- view_->enable_coloured_bg(action_view_coloured_bg_->isChecked());
+ shared_ptr<pv::view::View> view = get_active_view();
+ if (view)
+ view->enable_coloured_bg(action_view_coloured_bg_->isChecked());
}
void MainWindow::on_actionViewShowCursors_triggered()
{
- assert(view_);
+ shared_ptr<pv::view::View> view = get_active_view();
+ if (!view)
+ return;
- const bool show = !view_->cursors_shown();
+ const bool show = !view->cursors_shown();
if (show)
- view_->centre_cursors();
+ view->centre_cursors();
- view_->show_cursors(show);
+ view->show_cursors(show);
}
void MainWindow::on_actionAbout_triggered()
{
// 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()));