From 36d912ef73dfdbc733d8f00a45b85b43a73a76d4 Mon Sep 17 00:00:00 2001 From: Gennady Pospelov <g.pospelov@fz-juelich.de> Date: Wed, 1 Oct 2014 15:31:55 +0200 Subject: [PATCH] Global shortcut ctrl-r to run the simulation from any view of main window. --- GUI/coregui/Models/JobQueueData.cpp | 6 +++--- .../SimulationWidgets/SimulationSetupWidget.cpp | 2 +- GUI/coregui/Views/SimulationView.cpp | 7 +++++++ GUI/coregui/Views/SimulationView.h | 3 +++ GUI/coregui/mainwindow/actionmanager.cpp | 14 +++++++++++++- GUI/coregui/mainwindow/actionmanager.h | 4 ++++ GUI/coregui/mainwindow/mainwindow.cpp | 5 +++++ GUI/coregui/mainwindow/mainwindow.h | 1 + 8 files changed, 37 insertions(+), 5 deletions(-) diff --git a/GUI/coregui/Models/JobQueueData.cpp b/GUI/coregui/Models/JobQueueData.cpp index b976270f356..fb4d997e371 100644 --- a/GUI/coregui/Models/JobQueueData.cpp +++ b/GUI/coregui/Models/JobQueueData.cpp @@ -127,9 +127,6 @@ void JobQueueData::runJob(const QString &identifier) Simulation *simulation(0); try{ simulation = DomainSimulationBuilder::getSimulation(jobItem->getSampleModel(), jobItem->getInstrumentModel()); - ThreadInfo info; - info.n_threads = jobItem->getNumberOfThreads(); - simulation->setThreadInfo(info); } catch(const std::exception &ex) { jobItem->setStatus(JobItem::Failed); @@ -143,6 +140,9 @@ void JobQueueData::runJob(const QString &identifier) return; } + ThreadInfo info; + info.n_threads = jobItem->getNumberOfThreads(); + simulation->setThreadInfo(info); m_simulations[identifier] = simulation; JobRunner *runner = new JobRunner(identifier, simulation); diff --git a/GUI/coregui/Views/Components/SimulationWidgets/SimulationSetupWidget.cpp b/GUI/coregui/Views/Components/SimulationWidgets/SimulationSetupWidget.cpp index aff22dfb88b..f72d4461e3a 100644 --- a/GUI/coregui/Views/Components/SimulationWidgets/SimulationSetupWidget.cpp +++ b/GUI/coregui/Views/Components/SimulationWidgets/SimulationSetupWidget.cpp @@ -232,7 +232,7 @@ QStringList SimulationSetupWidget::getCPUUsageOptions() int nthreads = Utils::System::getThreadHardwareConcurrency(); for(int i = nthreads; i>0; i--){ if(i == nthreads) { - result.append(QString("max (%1 threads)").arg(QString::number(i))); + result.append(QString("Max (%1 threads)").arg(QString::number(i))); } else if(i == 1) { result.append(QString("%1 thread").arg(QString::number(i))); } else { diff --git a/GUI/coregui/Views/SimulationView.cpp b/GUI/coregui/Views/SimulationView.cpp index 79951946aec..a04d6b9dd91 100644 --- a/GUI/coregui/Views/SimulationView.cpp +++ b/GUI/coregui/Views/SimulationView.cpp @@ -41,3 +41,10 @@ void SimulationView::updateSimulationViewElements() qDebug() << "SimulationView::updateSimulationViewElements()" << m_sampleModel << m_instrumentModel; m_simulationSetupWidget->updateViewElements(); } + + +void SimulationView::onRunSimulationShortcut() +{ + qDebug() << "SimulationView::onRunSimulationShortcut()"; + m_simulationSetupWidget->onRunSimulation(); +} diff --git a/GUI/coregui/Views/SimulationView.h b/GUI/coregui/Views/SimulationView.h index eecdd69fa84..01664bf7965 100644 --- a/GUI/coregui/Views/SimulationView.h +++ b/GUI/coregui/Views/SimulationView.h @@ -21,6 +21,9 @@ public: void updateSimulationViewElements(); +public slots: + void onRunSimulationShortcut(); + private: JobQueueModel *m_jobQueueModel; SampleModel *m_sampleModel; diff --git a/GUI/coregui/mainwindow/actionmanager.cpp b/GUI/coregui/mainwindow/actionmanager.cpp index 1aeb7c0f7b6..f10979aab5e 100644 --- a/GUI/coregui/mainwindow/actionmanager.cpp +++ b/GUI/coregui/mainwindow/actionmanager.cpp @@ -5,8 +5,10 @@ #include "projectmanager.h" #include "stringutils.h" #include <QMenuBar> +#include <QShortcut> #include <QSettings> #include <QFileInfo> +#include <QKeySequence> #include <QDebug> #include <QDir> #include <iostream> @@ -19,11 +21,12 @@ ActionManager::ActionManager(MainWindow *parent) , m_menuBar(0) , m_fileMenu(0) , m_helpMenu(0) - + , m_runSimulationShortcut(0) { setParent(parent); createActions(); createMenus(); + createGlobalShortcuts(); } @@ -90,6 +93,14 @@ void ActionManager::createMenus() } +void ActionManager::createGlobalShortcuts() +{ + m_runSimulationShortcut = new QShortcut(QKeySequence(tr("Ctrl+r")), m_mainWindow); + m_runSimulationShortcut->setContext((Qt::ApplicationShortcut)); + connect(m_runSimulationShortcut, SIGNAL(activated()), m_mainWindow, SLOT(onRunSimulationShortcut())); +} + + void ActionManager::aboutToShowRecentProjects() { qDebug() << "ActionManager::aboutToShowRecentProjects() ->" << m_mainWindow->getProjectManager()->getRecentProjects(); @@ -117,3 +128,4 @@ void ActionManager::aboutToShowRecentProjects() + diff --git a/GUI/coregui/mainwindow/actionmanager.h b/GUI/coregui/mainwindow/actionmanager.h index 22c82ec27d0..02d11d3693a 100644 --- a/GUI/coregui/mainwindow/actionmanager.h +++ b/GUI/coregui/mainwindow/actionmanager.h @@ -9,6 +9,7 @@ class QMenu; class QAction; class QMenuBar; class MainWindow; +class QShortcut; //! Class to handle MainWindow's menu and corresponding actions @@ -36,8 +37,11 @@ private: QMenu *m_recentProjectsMenu; QMenu *m_helpMenu; + QShortcut *m_runSimulationShortcut; + void createActions(); void createMenus(); + void createGlobalShortcuts(); }; diff --git a/GUI/coregui/mainwindow/mainwindow.cpp b/GUI/coregui/mainwindow/mainwindow.cpp index 8623bea0dd6..7beba09c5a0 100644 --- a/GUI/coregui/mainwindow/mainwindow.cpp +++ b/GUI/coregui/mainwindow/mainwindow.cpp @@ -161,6 +161,11 @@ void MainWindow::writeSettings() m_settings->sync(); } +void MainWindow::onRunSimulationShortcut() +{ + m_simulationView->onRunSimulationShortcut(); +} + void MainWindow::openRecentProject() { diff --git a/GUI/coregui/mainwindow/mainwindow.h b/GUI/coregui/mainwindow/mainwindow.h index fb5a573e7f6..d07d0adbc17 100644 --- a/GUI/coregui/mainwindow/mainwindow.h +++ b/GUI/coregui/mainwindow/mainwindow.h @@ -56,6 +56,7 @@ public slots: void openRecentProject(); void readSettings(); void writeSettings(); + void onRunSimulationShortcut(); protected: virtual void closeEvent(QCloseEvent *event); -- GitLab