MainWindow::MainWindow(DeviceManager &device_manager,
string open_file_name, string open_file_format,
- QWidget *parent) :
+ bool restore_sessions, QWidget *parent) :
QMainWindow(parent),
device_manager_(device_manager),
session_selector_(this),
GlobalSettings::register_change_handler(GlobalSettings::Key_View_ShowSamplingPoints,
bind(&MainWindow::on_settingViewShowSamplingPoints_changed, this, _1));
+ GlobalSettings::register_change_handler(GlobalSettings::Key_View_ShowAnalogMinorGrid,
+ bind(&MainWindow::on_settingViewShowAnalogMinorGrid_changed, this, _1));
+
setup_ui();
- restore_ui_settings();
+ restore_ui_settings(restore_sessions);
if (!open_file_name.empty()) {
shared_ptr<Session> session = add_session();
dock_main->setCentralWidget(v.get());
dock->setWidget(dock_main);
+ dock->setContextMenuPolicy(Qt::PreventContextMenu);
dock->setFeatures(QDockWidget::DockWidgetMovable |
QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetClosable);
tv->enable_coloured_bg(settings.value(GlobalSettings::Key_View_ColouredBG).toBool());
tv->enable_show_sampling_points(settings.value(GlobalSettings::Key_View_ShowSamplingPoints).toBool());
+ tv->enable_show_analog_minor_grid(settings.value(GlobalSettings::Key_View_ShowAnalogMinorGrid).toBool());
if (!main_bar) {
/* Initial view, create the main bar */
void MainWindow::remove_session(shared_ptr<Session> session)
{
+ // Determine the height of the button before it collapses
int h = new_session_button_->height();
+ // Stop capture while the session still exists so that the UI can be
+ // updated in case we're currently running. If so, this will schedule a
+ // call to our on_capture_state_changed() slot for the next run of the
+ // event loop. We need to have this executed immediately or else it will
+ // be dismissed since the session object will be deleted by the time we
+ // leave this method and the event loop gets a chance to run again.
+ session->stop_capture();
+ QApplication::processEvents();
+
for (shared_ptr<views::ViewBase> view : session->views())
remove_view(view);
if (last_focused_session_ == session)
last_focused_session_.reset();
+ // Remove the session from our list of sessions (which also destroys it)
sessions_.remove_if([&](shared_ptr<Session> s) {
return s == session; });
view_show_sampling_points_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Period), this, SLOT(on_view_show_sampling_points_shortcut()));
view_show_sampling_points_shortcut_->setAutoRepeat(false);
+ view_show_analog_minor_grid_shortcut_ = new QShortcut(QKeySequence(Qt::Key_G), this, SLOT(on_view_show_analog_minor_grid_shortcut()));
+ view_show_analog_minor_grid_shortcut_->setAutoRepeat(false);
+
view_coloured_bg_shortcut_ = new QShortcut(QKeySequence(Qt::Key_B), this, SLOT(on_view_coloured_bg_shortcut()));
view_coloured_bg_shortcut_->setAutoRepeat(false);
run_stop_shortcut_->setAutoRepeat(false);
settings_button_ = new QToolButton();
- settings_button_->setIcon(QIcon::fromTheme("configure",
- QIcon(":/icons/configure.png")));
+ settings_button_->setIcon(QIcon::fromTheme("preferences-system",
+ QIcon(":/icons/preferences-system.png")));
settings_button_->setToolTip(tr("Settings"));
settings_button_->setAutoRaise(true);
settings.setValue("sessions", id);
}
-void MainWindow::restore_ui_settings()
+void MainWindow::restore_ui_settings(bool restore_sessions)
{
QSettings settings;
- int i, session_count;
settings.beginGroup("MainWindow");
settings.endGroup();
- session_count = settings.value("sessions", 0).toInt();
+ if (restore_sessions) {
+ int i, session_count;
- for (i = 0; i < session_count; i++) {
- settings.beginGroup("Session" + QString::number(i));
- shared_ptr<Session> session = add_session();
- session->restore_settings(settings);
- 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> session = add_session();
+ session->restore_settings(settings);
+ settings.endGroup();
+ }
}
}
{
shared_ptr<Session> session = get_tab_session(index);
- assert(session);
+ if (!session)
+ return;
if (session->data_saved() || (QMessageBox::question(this, tr("Confirmation"),
tr("This session contains unsaved data. Close it anyway?"),
settings.setValue(GlobalSettings::Key_View_ShowSamplingPoints, !state);
}
+void MainWindow::on_view_show_analog_minor_grid_shortcut()
+{
+ GlobalSettings settings;
+
+ bool state = settings.value(GlobalSettings::Key_View_ShowAnalogMinorGrid).toBool();
+ settings.setValue(GlobalSettings::Key_View_ShowAnalogMinorGrid, !state);
+}
+
void MainWindow::on_settingViewColouredBg_changed(const QVariant new_value)
{
bool state = new_value.toBool();
}
}
+void MainWindow::on_settingViewShowAnalogMinorGrid_changed(const QVariant new_value)
+{
+ bool state = new_value.toBool();
+
+ for (auto entry : view_docks_) {
+ shared_ptr<views::ViewBase> viewbase = entry.second;
+
+ // Only trace views have this setting
+ views::TraceView::View* view =
+ qobject_cast<views::TraceView::View*>(viewbase.get());
+ if (view)
+ view->enable_show_analog_minor_grid(state);
+ }
+}
+
void MainWindow::on_close_current_tab()
{
int tab = session_selector_.currentIndex();