mainwindow.cpp 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531
  1. /*
  2. = StarPU-Top for StarPU =
  3. Copyright (C) 2011
  4. William Braik
  5. Yann Courtois
  6. Jean-Marie Couteyen
  7. Anthony Roy
  8. This library is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU Lesser General Public
  10. License as published by the Free Software Foundation; either
  11. version 2.1 of the License, or (at your option) any later version.
  12. This library is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. Lesser General Public License for more details.
  16. You should have received a copy of the GNU Lesser General Public
  17. License along with this library; if not, write to the Free Software
  18. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "mainwindow.h"
  21. #include "ui_mainwindow.h"
  22. #include <QCloseEvent>
  23. #include <QMessageBox>
  24. #include <QDebug>
  25. #include <QAction>
  26. #include <qwt_slider.h>
  27. #include "configurationmanager.h"
  28. #include "communicationthread.h"
  29. #include "widgetwindowsmanager.h"
  30. #include "sessionsetupmanager.h"
  31. #include "taskmanager.h"
  32. #include "debugconsole.h"
  33. #include "ganttwidget.h"
  34. #include "preferencesdialog.h"
  35. #include "interactivewidget.h"
  36. #include "datawidget.h"
  37. #include "dataaggregatorwidget.h"
  38. #include "aboutdialog.h"
  39. MainWindow::MainWindow(QWidget *parent) :
  40. QMainWindow(parent), ui(new Ui::MainWindow)
  41. {
  42. // Set up GUI components
  43. ui->setupUi(this);
  44. ui->mainToolBar->setWindowTitle("Toolbar");
  45. _mdiArea = new QMdiArea();
  46. _mdiArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
  47. _mdiArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
  48. // Init data
  49. initDataWidgetLists();
  50. initInteractiveWidgetLists();
  51. _dataWidgets = new QList<QPointer<DataWidget> > ();
  52. _interactiveWidgets = new QList<QPointer<InteractiveWidget> > ();
  53. _dataAggregatorWidgets = new QList<QPointer<DataAggregatorWidget> > ();
  54. _dataDescriptions = new QList<DataDescription*> ();
  55. _paramDescriptions = new QList<ParamDescription*> ();
  56. _serverDevices = new QList<starpu_top_device> ();
  57. _nbDataWidgets = _nbInteractiveWidgets = _nbDataAggregatorWidgets = 0;
  58. // Init managers
  59. _configurationManager = new ConfigurationManager();
  60. _communicationThread = new CommunicationThread(this, _configurationManager);
  61. _widgetWindowsManager = new WidgetWindowsManager(this, _mdiArea);
  62. _sessionSetupManager = new SessionSetupManager(this);
  63. _taskManager = new TaskManager();
  64. // Setup status bar
  65. _statusBarIcon = new QLabel();
  66. _statusBarLabel = new QLabel();
  67. statusBar()->addPermanentWidget(_statusBarIcon);
  68. statusBar()->addWidget(_statusBarLabel);
  69. // Setup interactions
  70. // Setup main actions
  71. // Action connect
  72. _actionConnect = ui->mainToolBar->addAction(QIcon(":/images/connect.png"),
  73. tr("Connect to StarPU"));
  74. _actionConnect->setIconText("Connect to StarPU");
  75. _actionConnect->setToolTip("Connect to StarPU");
  76. _actionConnect->setShortcut(QKeySequence("Ctrl+C"));
  77. QToolButton *connectButton =
  78. (QToolButton*)ui->mainToolBar->widgetForAction(_actionConnect);
  79. connectButton->setPopupMode(QToolButton::InstantPopup);
  80. QObject::connect(_actionConnect, SIGNAL(triggered()), this,
  81. SLOT(on_actionConnect_triggered()));
  82. QAction *settingsAction = new QAction(
  83. "Edit connection settings",
  84. _actionConnect);
  85. settingsAction->setIcon(QIcon(":/images/preferences.png"));
  86. QObject::connect(settingsAction, SIGNAL(triggered()), this,
  87. SLOT(on_actionPreferences_triggered()));
  88. connectButton->addAction(settingsAction);
  89. ui->menu_starpu_top->addAction(_actionConnect);
  90. // Action launch
  91. _actionLaunch = ui->mainToolBar->addAction(QIcon(":/images/play.png"),
  92. tr("Launch StarPU"));
  93. _actionLaunch->setIconText("Launch StarPU");
  94. _actionLaunch->setToolTip("Launch StarPU");
  95. _actionLaunch->setShortcut(QKeySequence("Ctrl+L"));
  96. ui->menu_starpu_top->addAction(_actionLaunch);
  97. QObject::connect(_actionLaunch, SIGNAL(triggered()), this,
  98. SLOT(on_actionLaunch_StarPU_triggered()));
  99. ui->mainToolBar->addSeparator();
  100. ui->menu_starpu_top->addSeparator();
  101. // Action debug
  102. _actionDebug = ui->mainToolBar->addAction(QIcon(":/images/debugon.png"),
  103. tr("Enable debug"));
  104. _actionDebug->setIconText("Enable debug");
  105. _actionDebug->setToolTip("Enable debug");
  106. _actionDebug->setShortcut(QKeySequence("Ctrl+D"));
  107. _actionDebug->setCheckable(true);
  108. ui->menu_starpu_top->addAction(_actionDebug);
  109. QObject::connect(_actionDebug, SIGNAL(toggled(bool)),
  110. this, SLOT(on_actionDebug_triggered(bool)));
  111. // Action save session setup
  112. _actionSaveSessionSetup = ui->mainToolBar->addAction(
  113. QIcon(":/images/windows.png"), tr("Save session setup"));
  114. _actionSaveSessionSetup->setIconText("Save session setup");
  115. _actionSaveSessionSetup->setToolTip("Save session setup");
  116. _actionSaveSessionSetup->setShortcut(QKeySequence("Ctrl+S"));
  117. ui->menu_starpu_top->addAction(_actionSaveSessionSetup);
  118. QObject::connect(_actionSaveSessionSetup, SIGNAL(triggered()), this,
  119. SLOT(on_actionSaveSessionSetup_triggered()));
  120. // Action add data aggregator widget
  121. _actionAddDataAggregatorWidget =
  122. ui->mainToolBar->addAction(QIcon(":/images/widget.png"),
  123. tr("Add data aggregator widget"));
  124. _actionAddDataAggregatorWidget->setIconText("Add data aggregator widget");
  125. _actionAddDataAggregatorWidget->setToolTip("Add data aggregator widget");
  126. _actionAddDataAggregatorWidget->setShortcut(QKeySequence("Ctrl+G"));
  127. ui->menu_starpu_top->addAction(_actionAddDataAggregatorWidget);
  128. QObject::connect(_actionAddDataAggregatorWidget, SIGNAL(triggered()), this,
  129. SLOT(on_actionAddDataAggregatorWidget_triggered()));
  130. ui->mainToolBar->addSeparator();
  131. ui->menu_starpu_top->addSeparator();
  132. // Action quit
  133. QAction *actionQuit = ui->menu_starpu_top->addAction(
  134. QIcon(":/images/quit.png"), tr("Quit"));
  135. actionQuit->setIconText("Quit");
  136. actionQuit->setToolTip("Quit");
  137. QObject::connect(actionQuit, SIGNAL(triggered()), this,
  138. SLOT(on_actionQuit_triggered()));
  139. actionQuit->setShortcut(QKeySequence("Ctrl+Q"));
  140. _widgetsDisplayModesList = new QComboBox(ui->mainToolBar);
  141. _widgetsDisplayModesList->addItem(tr("Flying windows"),
  142. DISPLAY_FLYING_WINDOWS);
  143. _widgetsDisplayModesList->addItem(tr("MDI, normal"), DISPLAY_MDI_NORMAL);
  144. _widgetsDisplayModesList->setCurrentIndex(1);
  145. QObject::connect(_widgetsDisplayModesList, SIGNAL(currentIndexChanged(int)),
  146. this, SLOT(updateDataWidgetsDisplayMode(int)));
  147. ui->mainToolBar->addWidget(_widgetsDisplayModesList);
  148. // Init GUI components
  149. // Retrieve the central widget layout
  150. QGridLayout *centralLayout = (QGridLayout*) ui->centralWidget->layout();
  151. // Install MDI area
  152. _mdiArea->setMinimumSize(500, 200);
  153. _mdiArea->addAction(_actionAddDataAggregatorWidget);
  154. _mdiArea->setContextMenuPolicy(Qt::ActionsContextMenu);
  155. _mdiArea->setEnabled(false);
  156. // Install gantt widget
  157. _ganttWidget = new GanttWidget(this, _taskManager);
  158. _ganttWidget->setMinimumSize(500, 200);
  159. // Install parameters dock
  160. _parametersDockScrollArea = new QScrollArea();
  161. _parametersDockScrollArea->setMinimumSize(250, 250);
  162. _parametersDockScrollArea->setLayout(new QVBoxLayout());
  163. ui->parametersDock->setWidget(_parametersDockScrollArea);
  164. // Install the gantt widget container and the gantt controllers
  165. QWidget *ganttContainer = new QWidget();
  166. QGridLayout *ganttContainerLayout = new QGridLayout();
  167. ganttContainer->setLayout(ganttContainerLayout);
  168. // Zoom controller
  169. QwtSlider *ganttZoom = new QwtSlider(ganttContainer, Qt::Vertical);
  170. ganttZoom->setRange(100.0, 20000.0, 1.0);
  171. ganttZoom->setValue(10000.0);
  172. QObject::connect(ganttZoom, SIGNAL(valueChanged(double)),
  173. _ganttWidget, SLOT(updateZoom(double)));
  174. // Time view controller
  175. _ganttTimeView = new QSpinBox();
  176. _ganttTimeView->setRange(0, INT_MAX);
  177. _ganttTimeView->setAccelerated(true);
  178. QObject::connect(_ganttTimeView, SIGNAL(valueChanged(int)),
  179. _ganttWidget, SLOT(updateTimeView(int)));
  180. // Prevision line controller
  181. QwtSlider *ganttPrevLine = new QwtSlider(ganttContainer, Qt::Horizontal);
  182. ganttPrevLine->setRange(0, 100);
  183. ganttPrevLine->setValue(66.67);
  184. QObject::connect(ganttPrevLine, SIGNAL(valueChanged(double)),
  185. _ganttWidget, SLOT(updatePrevLine(double)));
  186. // Set gantt layouts
  187. QHBoxLayout *ganttBottom = new QHBoxLayout();
  188. ganttBottom->addWidget(_ganttTimeView, 0);
  189. ganttBottom->addWidget(ganttPrevLine, 1);
  190. ganttContainerLayout->addWidget(_ganttWidget, 0, 0);
  191. ganttContainerLayout->addWidget(ganttZoom, 0, 1);
  192. ganttContainerLayout->addLayout(ganttBottom, 1, 0);
  193. // Install debug console
  194. _debugConsole = new DebugConsole(this);
  195. QObject::connect(_debugConsole, SIGNAL(stepped()), this, SLOT(debugStep()));
  196. _debugConsole->setVisible(false);
  197. // Install splitter
  198. _splitter = new QSplitter(Qt::Vertical);
  199. _splitter->setChildrenCollapsible(false);
  200. _splitter->setHandleWidth(5);
  201. _splitter->addWidget(_mdiArea);
  202. _splitter->addWidget(ganttContainer);
  203. _splitter->addWidget(_debugConsole);
  204. centralLayout->addWidget(_splitter, 0, 0);
  205. // Restore main window setup when a session setup is loaded
  206. QObject::connect(_sessionSetupManager,
  207. SIGNAL(mainWindowSetupLoaded(MainWindowSetup)),
  208. this,
  209. SLOT(sessionMainWindowSetupLoaded(MainWindowSetup)));
  210. // Restore parameters dock setup when a session setup is loaded
  211. QObject::connect(_sessionSetupManager,
  212. SIGNAL(parametersDockSetupLoaded(ParametersDockSetup)),
  213. this,
  214. SLOT(sessionParametersDockSetupLoaded(ParametersDockSetup)));
  215. // Restore widgets windows setup when a session setup is loaded
  216. QObject::connect(
  217. _sessionSetupManager,
  218. SIGNAL(
  219. widgetWindowsSetupLoaded(
  220. QList<DataWidgetSetup> ,
  221. QList<DataAggregatorWidgetSetup> )),
  222. this,
  223. SLOT(
  224. sessionWidgetWindowsSetupLoaded(
  225. QList<DataWidgetSetup> ,
  226. QList<DataAggregatorWidgetSetup> )));
  227. // Init UI states
  228. _displayMode = DISPLAY_MDI_NORMAL;
  229. _connected = false;
  230. _ready = false;
  231. _running = false;
  232. _debug = false;
  233. // Init main window connexion status
  234. setConnected(false);
  235. // Load previously saved configuration
  236. _configurationManager->syncConfiguration();
  237. }
  238. MainWindow::~MainWindow()
  239. {
  240. delete _statusBarLabel;
  241. delete _statusBarIcon;
  242. delete ui;
  243. delete _taskManager;
  244. }
  245. /* -------------------------------------------------------------------------- */
  246. /* Events */
  247. /* -------------------------------------------------------------------------- */
  248. void MainWindow::changeEvent(QEvent *e)
  249. {
  250. QMainWindow::changeEvent(e);
  251. switch (e->type())
  252. {
  253. case QEvent::LanguageChange:
  254. ui->retranslateUi(this);
  255. break;
  256. default:
  257. break;
  258. }
  259. }
  260. void MainWindow::closeEvent(QCloseEvent *ce)
  261. {
  262. int returned = -1;
  263. if (isRunning())
  264. {
  265. returned
  266. = QMessageBox::question(
  267. this,
  268. tr("Quit StarPU-Top ?"),
  269. tr("StarPU-Top is currently monitoring.\n")
  270. + tr(
  271. "Do you really want to stop "
  272. "monitoring and exit the application ?"),
  273. QMessageBox::Ok | QMessageBox::Cancel);
  274. }
  275. else
  276. {
  277. _configurationManager->syncConfiguration();
  278. qDebug() << "MainWindow : exiting the application";
  279. qApp->quit(); // Exit the application
  280. }
  281. if (returned == QMessageBox::Ok)
  282. {
  283. if (_communicationThread->isRunning())
  284. {
  285. _communicationThread->exit(0);
  286. qDebug() << "MainWindow : stopped communication thread";
  287. }
  288. _configurationManager->syncConfiguration();
  289. qDebug() << "MainWindow : exiting the application";
  290. qApp->quit(); // exit application
  291. }
  292. else
  293. {
  294. ce->ignore(); // ignore close event
  295. }
  296. }
  297. void MainWindow::openSession()
  298. {
  299. bool ok;
  300. // (Re)initialize the tasks database
  301. _taskManager->initialize();
  302. ok = _taskManager->connectDatabase();
  303. Q_ASSERT_X(ok == true,
  304. "MainWindow::openSession()",
  305. "Couldn't connect to the tasks database !");
  306. (void) ok;
  307. // Init time references
  308. _lockedTime = 0;
  309. // Possibly clear old session widgets
  310. clearWidgets();
  311. // Enable the MDI area
  312. _mdiArea->setEnabled(true);
  313. // Install fresh data widgets
  314. for (int i = 0; i < _dataDescriptions->count(); i++)
  315. {
  316. if (_dataDescriptions->at(i)->widget != DATA_WIDGET_NONE)
  317. {
  318. DataWidget* dataWidget = addDataWidget(_dataDescriptions->at(i));
  319. _widgetWindowsManager->displayWidgetWindow(dataWidget);
  320. }
  321. }
  322. // Install fresh interactive widgets
  323. for (int i = 0; i < _paramDescriptions->count(); i++)
  324. {
  325. if (_paramDescriptions->at(i)->widget != INTERACTIVE_WIDGET_NONE)
  326. {
  327. InteractiveWidget* interactiveWidget = addInteractiveWidget(
  328. _paramDescriptions->at(i));
  329. displayInteractiveWidget(interactiveWidget);
  330. }
  331. }
  332. emit sessionOpened();
  333. }
  334. void MainWindow::closeSession()
  335. {
  336. // Clear old data/params descriptions
  337. clearDescriptions();
  338. // Disable the MDI area
  339. _mdiArea->setEnabled(false);
  340. // Update gantt time controller
  341. _ganttTimeView->setValue(effectiveRunningTime());
  342. // Close the preferences dialog if open
  343. if (_preferencesDialog != 0)
  344. {
  345. _preferencesDialog->close();
  346. }
  347. // Stop the communication thread
  348. if (_communicationThread->isRunning())
  349. {
  350. _communicationThread->exit(0);
  351. qDebug() << "MainWindow : stopped communication thread";
  352. }
  353. QMessageBox::information(
  354. this,
  355. tr("End of the session"),
  356. tr("The session has just finished (time running : ")
  357. + QString::number(runningTime()) + "ms, time locked : "
  358. + QString::number(lockedTime())
  359. + "ms, time effectively running : " + QString::number(
  360. effectiveRunningTime()) + "ms)", QMessageBox::Ok);
  361. emit sessionClosed();
  362. }
  363. void MainWindow::debugLock()
  364. {
  365. qDebug() << "MainWindow : locking session";
  366. _currentLockTime.start();
  367. setStatusBarIcon(":/images/lock.png");
  368. setStatusBarMessage("Locked");
  369. emit debugLocked();
  370. }
  371. void MainWindow::debugStep()
  372. {
  373. qDebug() << "MainWindow : unlocking session";
  374. _lockedTime += _currentLockTime.elapsed();
  375. _currentLockTime = QTime();
  376. _actionDebug->setEnabled(true);
  377. setStatusBarIcon("");
  378. setStatusBarMessage("Running");
  379. emit debugStepped();
  380. }
  381. void MainWindow::sessionMainWindowSetupLoaded(MainWindowSetup mainWindowSetup)
  382. {
  383. qDebug() << "MainWindow : restoring main window setup from another session";
  384. // Load geometry
  385. if (restoreGeometry(mainWindowSetup.geometry) == false)
  386. {
  387. qDebug() << "MainWindow : failed to restore main window geometry";
  388. }
  389. // Load display mode
  390. setDisplayMode(mainWindowSetup.displayMode);
  391. }
  392. void MainWindow::sessionParametersDockSetupLoaded(
  393. ParametersDockSetup parametersDockSetup)
  394. {
  395. (void) parametersDockSetup;
  396. qDebug() << "MainWindow : "
  397. "restoring parameters dock setup from another session";
  398. }
  399. void MainWindow::sessionWidgetWindowsSetupLoaded(
  400. QList<DataWidgetSetup> dataWidgetsSetup,
  401. QList<DataAggregatorWidgetSetup> dataAggregatorWidgetsSetup)
  402. {
  403. qDebug()
  404. << "MainWindow : "
  405. "restoring widget windows setup from another session";
  406. // Restore data widgets setup
  407. for (int i = 0; i < dataWidgetsSetup.count(); i++)
  408. {
  409. DataWidget *dataWidget = dataWidgetFromDataId(
  410. dataWidgetsSetup.at(i).dataId);
  411. if (dataWidget->isInside() != dataWidgetsSetup.at(i).inside)
  412. {
  413. dataWidget->setInside(dataWidgetsSetup.at(i).inside);
  414. if (dataWidget->isInside() == true)
  415. {
  416. _widgetWindowsManager->flyingWindowToMdi(dataWidget);
  417. }
  418. else
  419. {
  420. _widgetWindowsManager->mdiToFlyingWindow(dataWidget);
  421. }
  422. }
  423. if (dataWidget->isInside() == false)
  424. {
  425. dataWidget->restoreGeometry(dataWidgetsSetup.at(i).geometry);
  426. }
  427. else
  428. {
  429. dataWidget->parentWidget()->restoreGeometry(
  430. dataWidgetsSetup.at(i).geometry);
  431. }
  432. }
  433. // Restore data aggregator widgets setup
  434. for (int i = 0; i < dataAggregatorWidgetsSetup.count(); i++)
  435. {
  436. DataAggregatorWidget *dataAggregatorWidget = addDataAggregatorWidget(
  437. dataAggregatorWidgetsSetup.at(i).dataIds);
  438. _widgetWindowsManager->displayWidgetWindow(dataAggregatorWidget);
  439. if (dataAggregatorWidget->isInside()
  440. != dataAggregatorWidgetsSetup.at(i).inside)
  441. {
  442. dataAggregatorWidget->setInside(
  443. dataAggregatorWidgetsSetup.at(i).inside);
  444. if (dataAggregatorWidget->isInside() == true)
  445. {
  446. _widgetWindowsManager->flyingWindowToMdi(dataAggregatorWidget);
  447. }
  448. else
  449. {
  450. _widgetWindowsManager->mdiToFlyingWindow(dataAggregatorWidget);
  451. }
  452. }
  453. if (dataAggregatorWidget->isInside() == false)
  454. {
  455. dataAggregatorWidget ->restoreGeometry(
  456. dataAggregatorWidgetsSetup.at(i).geometry);
  457. }
  458. else
  459. {
  460. dataAggregatorWidget->parentWidget() ->restoreGeometry(
  461. dataAggregatorWidgetsSetup.at(i).geometry);
  462. }
  463. }
  464. }
  465. void MainWindow::protocolErrorCaught(QString errorMessage)
  466. {
  467. qDebug() << "MainWindow : protocol error caught (" + errorMessage + ")";
  468. }
  469. void MainWindow::synchronizeSessionTime(qlonglong serverTimestamp)
  470. {
  471. qDebug() << "Synchronized with server reference timestamp ("
  472. << serverTimestamp << ")";
  473. _referenceTimestamp = serverTimestamp;
  474. if (_preGoTimer.isNull())
  475. {
  476. _preGoTimer.start();
  477. }
  478. else
  479. {
  480. _preGoTimer.restart();
  481. }
  482. }
  483. void MainWindow::initClient(QString serverID,
  484. QList<DataDescription*> *dataDescriptions,
  485. QList<ParamDescription*> *paramDescriptions,
  486. QList<starpu_top_device> *serverDevices)
  487. {
  488. _serverID = serverID;
  489. _dataDescriptions = dataDescriptions;
  490. _paramDescriptions = paramDescriptions;
  491. _serverDevices = serverDevices;
  492. setReady(true);
  493. // Display widget choices list in preferences dialog
  494. _preferencesDialog = new PreferencesDialog(this, _configurationManager,
  495. _sessionSetupManager, 1);
  496. emit preferencesDialogCreated(_widgetsDisplayModesList->currentIndex());
  497. _preferencesDialog->setVisible(true);
  498. }
  499. /* -------------------------------------------------------------------------- */
  500. /* Actions */
  501. /* -------------------------------------------------------------------------- */
  502. void MainWindow::connectionSucceeded()
  503. {
  504. qDebug() << "MainWindow : connected to server";
  505. setConnected(true);
  506. }
  507. void MainWindow::connectionAborted(QString message)
  508. {
  509. QMessageBox::critical(this, "StarPU-Top", message, QMessageBox::Ok);
  510. setConnected(false);
  511. }
  512. void MainWindow::disconnected()
  513. {
  514. if (isRunning())
  515. {
  516. setRunning(false);
  517. }
  518. if (isReady())
  519. {
  520. setReady(false);
  521. }
  522. setConnected(false);
  523. qDebug() << "MainWindow : disconnected from server";
  524. }
  525. void MainWindow::on_actionConnect_triggered()
  526. {
  527. setStatusBarMessage("Awaiting connection...");
  528. _actionConnect->setEnabled(false);
  529. // Initiate connection to server
  530. _communicationThread->start(/*QThread::NormalPriority*/);
  531. _communicationThread->moveToThread(_communicationThread);
  532. }
  533. void MainWindow::on_actionLaunch_StarPU_triggered()
  534. {
  535. // Tell server to launch the session
  536. setRunning(true);
  537. emit clientLaunched();
  538. }
  539. void MainWindow::on_actionDebug_triggered(bool enabled)
  540. {
  541. _actionDebug->setEnabled(false);
  542. _actionDebug->setToolTip("Waiting for the server's acknowledgement...");
  543. _actionDebug->setIconText("Waiting for the server's acknowledgement...");
  544. emit debugEnabled(enabled);
  545. }
  546. void MainWindow::on_actionSaveSessionSetup_triggered()
  547. {
  548. if (_sessionSetupManager->saveSessionSetup(_serverID) == true)
  549. {
  550. qDebug() << "MainWindow : session setup successfully saved";
  551. statusBar()->showMessage(tr("Session setup successfully saved"),3000);
  552. }
  553. else
  554. {
  555. statusBar()->showMessage(tr("Couldn't save the session setup"),3000);
  556. }
  557. }
  558. void MainWindow::on_actionQuit_triggered()
  559. {
  560. close(); // Calls CloseEvent()
  561. }
  562. void MainWindow::on_actionAddDataAggregatorWidget_triggered()
  563. {
  564. AbstractWidgetWindow *widgetWindow =
  565. (AbstractWidgetWindow*) addDataAggregatorWidget();
  566. _widgetWindowsManager->displayWidgetWindow(widgetWindow);
  567. }
  568. void MainWindow::on_actionPreferences_triggered()
  569. {
  570. int tabindex = (_connected ? 1 : 0);
  571. // Open preferences dialog
  572. _preferencesDialog = new PreferencesDialog(this, _configurationManager,
  573. _sessionSetupManager, tabindex);
  574. _preferencesDialog->setVisible(true);
  575. emit preferencesDialogCreated(_widgetsDisplayModesList->currentIndex());
  576. }
  577. void MainWindow::on_actionAbout_triggered()
  578. {
  579. AboutDialog *aboutDialog = new AboutDialog(this);
  580. aboutDialog->setVisible(true);
  581. }
  582. /* -------------------------------------------------------------------------- */
  583. /* Getters */
  584. /* -------------------------------------------------------------------------- */
  585. const QSplitter *MainWindow::splitter() const
  586. {
  587. return _splitter;
  588. }
  589. const QDockWidget *MainWindow::parametersDock() const
  590. {
  591. return ui->parametersDock;
  592. }
  593. const WidgetWindowsManager* MainWindow::widgetWindowsManager() const
  594. {
  595. return _widgetWindowsManager;
  596. }
  597. const ConfigurationManager* MainWindow::configurationManager() const
  598. {
  599. return _configurationManager;
  600. }
  601. const SessionSetupManager* MainWindow::sessionSetupManager() const
  602. {
  603. return _sessionSetupManager;
  604. }
  605. const TaskManager* MainWindow::taskManager() const
  606. {
  607. return _taskManager;
  608. }
  609. const QHash<DataWidgetType, QString> *MainWindow::dataWidgetNames() const
  610. {
  611. return &_dataWidgetNames;
  612. }
  613. const QHash<DataType, QSet<DataWidgetType> >
  614. *MainWindow::dataWidgetPossibilities() const
  615. {
  616. return &_dataWidgetPossibilities;
  617. }
  618. const QHash<InteractiveWidgetType, QString>
  619. *MainWindow::interactiveWidgetNames() const
  620. {
  621. return &_interactiveWidgetNames;
  622. }
  623. const QHash<ParamType, QSet<InteractiveWidgetType> >
  624. *MainWindow::interactiveWidgetPossibilities() const
  625. {
  626. return &_interactiveWidgetPossibilities;
  627. }
  628. int MainWindow::nbDataWidgets() const
  629. {
  630. return _nbDataWidgets;
  631. }
  632. int MainWindow::nbInteractiveWidgets() const
  633. {
  634. return _nbInteractiveWidgets;
  635. }
  636. int MainWindow::nbDataAggregatorWidgets() const
  637. {
  638. return _nbDataAggregatorWidgets;
  639. }
  640. QString MainWindow::serverID() const
  641. {
  642. return _serverID;
  643. }
  644. const QList<DataDescription*> *MainWindow::dataDescriptions() const
  645. {
  646. return _dataDescriptions;
  647. }
  648. const QList<ParamDescription*> *MainWindow::paramDescriptions() const
  649. {
  650. return _paramDescriptions;
  651. }
  652. bool MainWindow::isConnected() const
  653. {
  654. return _connected;
  655. }
  656. bool MainWindow::isReady() const
  657. {
  658. return _ready;
  659. }
  660. bool MainWindow::isRunning() const
  661. {
  662. return _running;
  663. }
  664. bool MainWindow::isDebugEnabled() const
  665. {
  666. return _debug;
  667. }
  668. DisplayMode MainWindow::displayMode() const
  669. {
  670. return _displayMode;
  671. }
  672. int MainWindow::effectiveRunningTime() const
  673. {
  674. if (_runningTime.isNull())
  675. {
  676. return 0;
  677. }
  678. return _runningTime.elapsed() - (_lockedTime + currentLockTime());
  679. }
  680. int MainWindow::runningTime() const
  681. {
  682. if (_runningTime.isNull())
  683. {
  684. return 0;
  685. }
  686. return _runningTime.elapsed();
  687. }
  688. int MainWindow::currentLockTime() const
  689. {
  690. if (_currentLockTime.isNull())
  691. {
  692. return 0;
  693. }
  694. return _currentLockTime.elapsed();
  695. }
  696. int MainWindow::lockedTime() const
  697. {
  698. return _lockedTime;
  699. }
  700. /* -------------------------------------------------------------------------- */
  701. /* Setters */
  702. /* -------------------------------------------------------------------------- */
  703. void MainWindow::setStatusBarMessage(QString message)
  704. {
  705. if (_statusBarLabel != 0)
  706. {
  707. _statusBarLabel->setText(message);
  708. }
  709. }
  710. void MainWindow::updateStatusBarMessage(QString message)
  711. {
  712. setStatusBarMessage(message);
  713. }
  714. void MainWindow::setStatusBarIcon(QString iconFile)
  715. {
  716. if (_statusBarIcon != 0)
  717. {
  718. _statusBarIcon->setPixmap(QPixmap(iconFile));
  719. }
  720. }
  721. void MainWindow::setConnected(bool connected)
  722. {
  723. _connected = connected;
  724. if (_connected == false)
  725. {
  726. Q_ASSERT_X(_ready == false && _running == false,
  727. "MainWindow::setConnected()",
  728. "MainWindow states hierarchy violated");
  729. _actionConnect->setEnabled(true);
  730. _actionLaunch->setEnabled(false);
  731. _actionDebug->setEnabled(false);
  732. _actionSaveSessionSetup->setEnabled(false);
  733. _actionAddDataAggregatorWidget->setEnabled(false);
  734. setStatusBarMessage(tr("Disconnected"));
  735. }
  736. else
  737. {
  738. _actionConnect->setEnabled(false);
  739. setStatusBarMessage(
  740. tr("Connected (") + _configurationManager->serverHost() + ":"
  741. + QString::number(_configurationManager->serverPort())
  742. + ")");
  743. }
  744. }
  745. void MainWindow::setReady(bool ready)
  746. {
  747. _ready = ready;
  748. if (_ready == true)
  749. {
  750. Q_ASSERT_X(_connected == true, "MainWindow::setReady()",
  751. "MainWindow states hierarchy violated");
  752. _actionLaunch->setEnabled(true);
  753. _actionDebug->setEnabled(true);
  754. _actionAddDataAggregatorWidget->setEnabled(true);
  755. setStatusBarMessage(
  756. tr("Connected and ready (") + _serverID + tr(" on ")
  757. + _configurationManager->serverHost() + ":"
  758. + QString::number(_configurationManager->serverPort())
  759. + ")");
  760. openSession();
  761. _actionSaveSessionSetup->setEnabled(true);
  762. }
  763. else
  764. {
  765. Q_ASSERT_X(_running == false, "MainWindow::setReady()",
  766. "MainWindow states hierarchy violated");
  767. _actionConnect->setEnabled(false);
  768. _actionLaunch->setEnabled(false);
  769. _actionDebug->setEnabled(false);
  770. _actionAddDataAggregatorWidget->setEnabled(false);
  771. setStatusBarMessage(
  772. tr("Connected (") + _configurationManager->serverHost() + ":"
  773. + QString::number(_configurationManager->serverPort())
  774. + ")");
  775. closeSession();
  776. _actionSaveSessionSetup->setEnabled(false);
  777. }
  778. }
  779. void MainWindow::setRunning(bool running)
  780. {
  781. _running = running;
  782. if (running == true)
  783. {
  784. Q_ASSERT_X(_connected == true && _ready == true,
  785. "MainWindow::setRunning()",
  786. "MainWindow states hierarchy violated");
  787. // Stop pre-running time and start running time
  788. _preGoTime = _preGoTimer.elapsed() + _referenceTimestamp;
  789. qDebug() << "Pre-Go time :" << _preGoTime;
  790. if (_runningTime.isNull())
  791. {
  792. _runningTime.start();
  793. }
  794. else
  795. {
  796. _runningTime.restart();
  797. }
  798. _actionLaunch->setEnabled(false);
  799. setStatusBarMessage(tr("Running"));
  800. setWindowTitle(
  801. windowTitle() + " (" + _serverID + tr(" on ")
  802. + _configurationManager->serverHost() + ":"
  803. + QString::number(_configurationManager->serverPort())
  804. + ")");
  805. }
  806. else
  807. {
  808. _actionLaunch->setEnabled(true);
  809. setStatusBarMessage(
  810. tr("Connected and ready (") + _serverID + tr(" on ")
  811. + _configurationManager->serverHost() + ":"
  812. + QString::number(_configurationManager->serverPort())
  813. + ")");
  814. setWindowTitle(tr("StarPU-Top"));
  815. }
  816. }
  817. void MainWindow::setDebug(bool enabled)
  818. {
  819. _debug = enabled;
  820. _actionDebug->setEnabled(true);
  821. if (_debug == true)
  822. {
  823. qDebug() << "MainWindow : enabling debug mode";
  824. _actionDebug->setIcon(QIcon(":/images/debugoff.png"));
  825. _actionDebug->setIconText("Disable debug");
  826. _actionDebug->setText("Disable debug");
  827. _actionDebug->setToolTip("Disable debug");
  828. _debugConsole->setVisible(true);
  829. }
  830. else
  831. {
  832. qDebug() << "MainWindow : disabling debug mode";
  833. _actionDebug->setIcon(QIcon(":/images/debugon.png"));
  834. _actionDebug->setIconText("Enable debug");
  835. _actionDebug->setText("Enable debug");
  836. _actionDebug->setToolTip("Enable debug");
  837. _debugConsole->setVisible(false);
  838. }
  839. }
  840. void MainWindow::setDisplayMode(DisplayMode displayMode)
  841. {
  842. _displayMode = displayMode;
  843. switch (_displayMode)
  844. {
  845. case DISPLAY_FLYING_WINDOWS:
  846. _widgetWindowsManager->mdiToFlyingWindows();
  847. break;
  848. case DISPLAY_MDI_NORMAL:
  849. _widgetWindowsManager->flyingWindowsToMdi();
  850. break;
  851. }
  852. }
  853. void MainWindow::setDebugMessage(QString debugMessage)
  854. {
  855. if (isDebugEnabled() == true)
  856. {
  857. _debugConsole->appendDebugLogMessage(debugMessage);
  858. }
  859. else
  860. {
  861. qDebug() << "Debug message ignored (received while not in debug mode)";
  862. }
  863. }
  864. void MainWindow::setDebugLock(QString debugLockMessage)
  865. {
  866. if (isDebugEnabled() == true)
  867. {
  868. debugLock();
  869. _debugConsole->appendDebugLockMessage(debugLockMessage);
  870. }
  871. else
  872. {
  873. qDebug() << "Debug lock ignored (received while not in debug mode)";
  874. }
  875. }
  876. /* -------------------------------------------------------------------------- */
  877. /* Other methods */
  878. /* -------------------------------------------------------------------------- */
  879. void MainWindow::clearDescriptions()
  880. {
  881. clearDataDescriptions();
  882. clearParamDescriptions();
  883. }
  884. DataWidget* MainWindow::addDataWidget(DataDescription *dataDescription)
  885. {
  886. // Create new data widget following the description
  887. bool inside = (_displayMode == DISPLAY_FLYING_WINDOWS ? false : true);
  888. DataWidget *dataWidget = new DataWidget(dataDescription,
  889. _widgetWindowsManager,
  890. this, inside);
  891. _dataWidgets->append(QPointer<DataWidget> (dataWidget));
  892. _nbDataWidgets++;
  893. return dataWidget;
  894. }
  895. void MainWindow::clearWidgets()
  896. {
  897. clearDataWidgets();
  898. clearInteractiveWidgets();
  899. }
  900. void MainWindow::clearDataWidgets()
  901. {
  902. _widgetWindowsManager->closeWidgetWindows();
  903. _dataWidgets->clear();
  904. }
  905. void MainWindow::removeDestroyedDataWidgets()
  906. {
  907. // Clear all null data widget pointers in the data widgets list
  908. for (int i = 0; i < _dataWidgets->count(); i++)
  909. {
  910. if (_dataWidgets->at(i).isNull())
  911. {
  912. _dataWidgets->removeAt(i);
  913. _nbDataWidgets--;
  914. }
  915. }
  916. }
  917. void MainWindow::clearDataDescriptions()
  918. {
  919. _dataDescriptions->clear();
  920. }
  921. InteractiveWidget *MainWindow::addInteractiveWidget(
  922. ParamDescription *paramDescription)
  923. {
  924. // Add new interactive widget following the description
  925. InteractiveWidget *interactiveWidget = new InteractiveWidget(
  926. paramDescription, this);
  927. _interactiveWidgets->append(
  928. QPointer<InteractiveWidget> (interactiveWidget));
  929. _nbInteractiveWidgets++;
  930. return interactiveWidget;
  931. }
  932. DataAggregatorWidget *MainWindow::addDataAggregatorWidget(QList<int> dataIds)
  933. {
  934. bool inside = (_displayMode == DISPLAY_FLYING_WINDOWS ? false : true);
  935. DataAggregatorWidget *dataAggregatorWidget = new DataAggregatorWidget(
  936. _widgetWindowsManager, this, inside, dataIds);
  937. _dataAggregatorWidgets->append(
  938. QPointer<DataAggregatorWidget> (dataAggregatorWidget));
  939. _nbDataAggregatorWidgets++;
  940. return dataAggregatorWidget;
  941. }
  942. void MainWindow::displayInteractiveWidget(InteractiveWidget *interactiveWidget)
  943. {
  944. // Display interactive widget in the dock widget
  945. QVBoxLayout* layout = (QVBoxLayout*) _parametersDockScrollArea->layout();
  946. layout->addWidget(interactiveWidget);
  947. }
  948. void MainWindow::clearInteractiveWidgets()
  949. {
  950. qDebug() << "Closing all interactive widgets";
  951. for (int i = 0; i < _interactiveWidgets->count(); i++)
  952. {
  953. _interactiveWidgets->at(i).data()->close();
  954. }
  955. _interactiveWidgets->clear();
  956. }
  957. void MainWindow::removeDestroyedInteractiveWidgets()
  958. {
  959. // Clear all null data widget pointers in the data widgets list
  960. for (int i = 0; i < _interactiveWidgets->count(); i++)
  961. {
  962. if (_interactiveWidgets->at(i).isNull())
  963. {
  964. _interactiveWidgets->removeAt(i);
  965. _paramDescriptions->at(i)->widget = INTERACTIVE_WIDGET_NONE;
  966. _nbInteractiveWidgets--;
  967. }
  968. }
  969. }
  970. void MainWindow::clearParamDescriptions()
  971. {
  972. _paramDescriptions->clear();
  973. }
  974. void MainWindow::removeDestroyedDataAggregatorWidgets()
  975. {
  976. // Clear all null data aggregator widget pointers in list
  977. for (int i = 0; i < _dataAggregatorWidgets->count(); i++)
  978. {
  979. if (_dataAggregatorWidgets->at(i).isNull())
  980. {
  981. _dataAggregatorWidgets->removeAt(i);
  982. _nbDataAggregatorWidgets--;
  983. }
  984. }
  985. }
  986. /* -------------------------------------------------------------------------- */
  987. /* Getters */
  988. /* -------------------------------------------------------------------------- */
  989. QString MainWindow::statusBarMessage() const
  990. {
  991. return _statusBarLabel->text();
  992. }
  993. const QList<QPointer<DataWidget> > *MainWindow::dataWidgets() const
  994. {
  995. return _dataWidgets;
  996. }
  997. const QList<QPointer<InteractiveWidget> >
  998. *MainWindow::interactiveWidgets() const
  999. {
  1000. return _interactiveWidgets;
  1001. }
  1002. const QList<QPointer<DataAggregatorWidget> >
  1003. *MainWindow::dataAggregatorWidgets() const
  1004. {
  1005. return _dataAggregatorWidgets;
  1006. }
  1007. DataWidget *MainWindow::dataWidgetFromDataId(int dataId)
  1008. {
  1009. for (int i = 0; i < _dataWidgets->count(); i++)
  1010. {
  1011. if (_dataWidgets->at(i)->description()->id == dataId)
  1012. return _dataWidgets->at(i);
  1013. }
  1014. return 0;
  1015. }
  1016. InteractiveWidget *MainWindow::interactiveWidgetFromParamId(int paramId)
  1017. {
  1018. for (int i = 0; i < _interactiveWidgets->count(); i++)
  1019. {
  1020. if (_interactiveWidgets->at(i)->description()->id == paramId)
  1021. return _interactiveWidgets->at(i);
  1022. }
  1023. return 0;
  1024. }
  1025. DataDescription *MainWindow::dataDescriptionFromId(int dataId)
  1026. {
  1027. for (int i = 0; i < _dataDescriptions->count(); i++)
  1028. {
  1029. if (_dataDescriptions->at(i)->id == dataId)
  1030. return _dataDescriptions->at(i);
  1031. }
  1032. return 0;
  1033. }
  1034. ParamDescription *MainWindow::paramDescriptionFromId(int paramId)
  1035. {
  1036. for (int i = 0; i < _paramDescriptions->count(); i++)
  1037. {
  1038. if (_paramDescriptions->at(i)->id == paramId)
  1039. return _paramDescriptions->at(i);
  1040. }
  1041. return 0;
  1042. }
  1043. const QList<starpu_top_device> *MainWindow::serverDevices() const
  1044. {
  1045. return _serverDevices;
  1046. }
  1047. /* -------------------------------------------------------------------------- */
  1048. /* Other methods */
  1049. /* -------------------------------------------------------------------------- */
  1050. void MainWindow::updateDataWidgetsDisplayMode(int index)
  1051. {
  1052. // Update the display mode
  1053. setDisplayMode(
  1054. (DisplayMode) _widgetsDisplayModesList->itemData(index).toInt());
  1055. }
  1056. void MainWindow::updateDisplayModeIndex(int index)
  1057. {
  1058. // Update display mode choice index in the toolbar
  1059. _widgetsDisplayModesList->setCurrentIndex(index);
  1060. }
  1061. void MainWindow::updateDataWidgetType(int dataId, DataWidgetType newWidget)
  1062. {
  1063. // Update the data widget description with type selected by user
  1064. DataDescription *dataDescription = dataDescriptionFromId(dataId);
  1065. if (dataDescription != 0)
  1066. {
  1067. DataWidgetType oldWidget = dataDescription->widget;
  1068. dataDescription->widget = newWidget;
  1069. qDebug() << "Data of id" << dataId << "changed widget type (old :"
  1070. << oldWidget << " new:" << newWidget << ")";
  1071. DataWidget *dataWidget = dataWidgetFromDataId(dataId);
  1072. if (newWidget == DATA_WIDGET_NONE && oldWidget != DATA_WIDGET_NONE)
  1073. { // We have disabled this data
  1074. emit dataDisabled(dataId);
  1075. qDebug() << "Data of id has been" << dataId << "DISABLED";
  1076. _widgetWindowsManager->closeWidgetWindow(dataWidget);
  1077. }
  1078. else if (newWidget != DATA_WIDGET_NONE && oldWidget == DATA_WIDGET_NONE)
  1079. { // We have enabled this data
  1080. // The entire widget needs to be created
  1081. _widgetWindowsManager->displayWidgetWindow(
  1082. addDataWidget(dataDescriptionFromId(dataId)));
  1083. emit dataEnabled(dataId);
  1084. qDebug() << "Data of id has been" << dataId << "ENABLED";
  1085. }
  1086. else if (newWidget != DATA_WIDGET_NONE && oldWidget != DATA_WIDGET_NONE)
  1087. { // Neither disable nor enabled, just change of the widget
  1088. // The widget just needs to redraw the internal data widget
  1089. dataWidget->recreateInternalWidget();
  1090. }
  1091. }
  1092. }
  1093. void MainWindow::updateInteractiveWidgetType(int paramId,
  1094. InteractiveWidgetType newWidget)
  1095. {
  1096. ParamDescription *paramDescription = paramDescriptionFromId(paramId);
  1097. if (paramDescription != 0)
  1098. {
  1099. InteractiveWidgetType oldWidget = paramDescription->widget;
  1100. paramDescription->widget = newWidget;
  1101. qDebug() << "Param of id" << paramId << "changed widget type (old :"
  1102. << oldWidget << " new:" << newWidget << ")";
  1103. // The widget just needs to redraw the internal interactive widget
  1104. InteractiveWidget *interactiveWidget = interactiveWidgetFromParamId(
  1105. paramId);
  1106. interactiveWidget->recreateInternalWidget();
  1107. }
  1108. }
  1109. /* -------------------------------------------------------------------------- */
  1110. /* Slots */
  1111. /* -------------------------------------------------------------------------- */
  1112. void MainWindow::updateInteractiveWidget(int interactiveWidgetId, bool value,
  1113. qlonglong timestamp)
  1114. {
  1115. InteractiveWidget *interactiveWidget = interactiveWidgetFromParamId(
  1116. interactiveWidgetId);
  1117. if (interactiveWidget != 0)
  1118. {
  1119. qDebug() << "Updating interactive widget of id" << interactiveWidgetId
  1120. << "updated with value" << value << "and timestamp"
  1121. << timestamp;
  1122. interactiveWidget->setValue(value);
  1123. }
  1124. else
  1125. {
  1126. qDebug() << "Trying to update inexistant interactive widget ! (id"
  1127. << interactiveWidgetId << ")";
  1128. }
  1129. }
  1130. void MainWindow::updateInteractiveWidget(int interactiveWidgetId, int value,
  1131. qlonglong timestamp)
  1132. {
  1133. InteractiveWidget *interactiveWidget = interactiveWidgetFromParamId(
  1134. interactiveWidgetId);
  1135. if (interactiveWidget != 0)
  1136. {
  1137. qDebug() << "Updating interactive widget of id" << interactiveWidgetId
  1138. << "updated with value" << value << "and timestamp"
  1139. << timestamp;
  1140. interactiveWidget->setValue(value);
  1141. }
  1142. else
  1143. {
  1144. qDebug() << "Trying to update inexistant interactive widget ! (id"
  1145. << interactiveWidgetId << ")";
  1146. }
  1147. }
  1148. void MainWindow::updateInteractiveWidget(int interactiveWidgetId, double value,
  1149. qlonglong timestamp)
  1150. {
  1151. InteractiveWidget *interactiveWidget = interactiveWidgetFromParamId(
  1152. interactiveWidgetId);
  1153. if (interactiveWidget != 0)
  1154. {
  1155. qDebug() << "Updating interactive widget of id" << interactiveWidgetId
  1156. << "updated with value" << value << "and timestamp"
  1157. << timestamp;
  1158. interactiveWidget->setValue(value);
  1159. }
  1160. else
  1161. {
  1162. qDebug() << "Trying to update inexistant interactive widget ! (id"
  1163. << interactiveWidgetId << ")";
  1164. }
  1165. }
  1166. void MainWindow::updateTaskPrev(int taskId, int deviceId, qlonglong timestamp,
  1167. qlonglong timestampStart,
  1168. qlonglong timestampEnd)
  1169. {
  1170. (void) timestamp;
  1171. _taskManager->addTaskPrev(taskId, deviceId, timestampStart - _preGoTime,
  1172. timestampEnd - _preGoTime);
  1173. }
  1174. void MainWindow::updateTaskStart(int taskId, int deviceId, qlonglong timestamp)
  1175. {
  1176. _taskManager->addTaskStart(taskId, deviceId, timestamp - _preGoTime);
  1177. }
  1178. void MainWindow::updateTaskEnd(int taskId, qlonglong timestamp)
  1179. {
  1180. _taskManager->addTaskEnd(taskId, timestamp - _preGoTime);
  1181. }
  1182. void MainWindow::updateDataWidget(int dataWidgetId, bool value,
  1183. qlonglong timestamp)
  1184. {
  1185. DataWidget *dataWidget = dataWidgetFromDataId(dataWidgetId);
  1186. if (dataWidget != 0)
  1187. {
  1188. qDebug() << "MainWindow : updating data widget of id" << dataWidgetId
  1189. << "with value" << value << "and timestamp" << timestamp;
  1190. dataWidget->setValue(value);
  1191. }
  1192. else
  1193. {
  1194. qDebug()
  1195. << "MainWindow : trying to update inexistant data widget ! (id"
  1196. << dataWidgetId << ")";
  1197. }
  1198. }
  1199. void MainWindow::updateDataWidget(int dataWidgetId, int value,
  1200. qlonglong timestamp)
  1201. {
  1202. DataWidget *dataWidget = dataWidgetFromDataId(dataWidgetId);
  1203. if (dataWidget != 0)
  1204. {
  1205. qDebug() << "MainWindow : updating data widget of id" << dataWidgetId
  1206. << "with value" << value << "and timestamp" << timestamp;
  1207. dataWidget->setValue(value);
  1208. }
  1209. else
  1210. {
  1211. qDebug()
  1212. << "MainWindow : trying to update inexistant data widget ! (id"
  1213. << dataWidgetId << ")";
  1214. }
  1215. }
  1216. void MainWindow::updateDataWidget(int dataWidgetId, double value,
  1217. qlonglong timestamp)
  1218. {
  1219. DataWidget *dataWidget = dataWidgetFromDataId(dataWidgetId);
  1220. if (dataWidget != 0)
  1221. {
  1222. qDebug() << "MainWindow : updating data widget of id" << dataWidgetId
  1223. << "with value" << value << "and timestamp" << timestamp;
  1224. dataWidget->setValue(value);
  1225. }
  1226. else
  1227. {
  1228. qDebug()
  1229. << "MainWindow : trying to update inexistant data widget ! (id"
  1230. << dataWidgetId << ")";
  1231. }
  1232. }
  1233. void MainWindow::interactiveWidgetUpdated(int interactiveWidgetId, bool value)
  1234. {
  1235. qDebug() << "MainWindow : interactive widget of id" << interactiveWidgetId
  1236. << "updated with value" << value;
  1237. emit paramValueUpdated(interactiveWidgetId, value);
  1238. }
  1239. void MainWindow::interactiveWidgetUpdated(int interactiveWidgetId, int value)
  1240. {
  1241. qDebug() << "MainWindow : interactive widget of id" << interactiveWidgetId
  1242. << "updated with value" << value;
  1243. emit paramValueUpdated(interactiveWidgetId, value);
  1244. }
  1245. void MainWindow::interactiveWidgetUpdated(int interactiveWidgetId, double value)
  1246. {
  1247. qDebug() << "MainWindow : interactive widget of id" << interactiveWidgetId
  1248. << "updated with value" << value;
  1249. emit paramValueUpdated(interactiveWidgetId, value);
  1250. }
  1251. void MainWindow::initDataWidgetLists()
  1252. {
  1253. //Names
  1254. _dataWidgetNames.insert(DATA_WIDGET_LCD, tr("Lcd"));
  1255. _dataWidgetNames.insert(DATA_WIDGET_PLOT, tr("Plot"));
  1256. _dataWidgetNames.insert(DATA_WIDGET_LEVEL, tr("Level"));
  1257. _dataWidgetNames.insert(DATA_WIDGET_LED, tr("Led"));
  1258. _dataWidgetNames.insert(DATA_WIDGET_DIAL, tr("Dial"));
  1259. _dataWidgetNames.insert(DATA_WIDGET_NONE, tr("<none>"));
  1260. // Sets of widgets for each type
  1261. // Bool
  1262. _dataBoolWidgets.insert(DATA_WIDGET_LED);
  1263. // Int
  1264. _dataIntWidgets.insert(DATA_WIDGET_LCD);
  1265. _dataIntWidgets.insert(DATA_WIDGET_PLOT);
  1266. _dataIntWidgets.insert(DATA_WIDGET_LEVEL);
  1267. _dataIntWidgets.insert(DATA_WIDGET_DIAL);
  1268. // Float
  1269. _dataFloatWidgets.insert(DATA_WIDGET_LCD);
  1270. _dataFloatWidgets.insert(DATA_WIDGET_PLOT);
  1271. _dataFloatWidgets.insert(DATA_WIDGET_LEVEL);
  1272. _dataFloatWidgets.insert(DATA_WIDGET_DIAL);
  1273. // Associate a type to widget possibilities
  1274. _dataWidgetPossibilities.insert(DATA_TYPE_BOOL, _dataBoolWidgets);
  1275. _dataWidgetPossibilities.insert(DATA_TYPE_INT, _dataIntWidgets);
  1276. _dataWidgetPossibilities.insert(DATA_TYPE_FLOAT, _dataFloatWidgets);
  1277. }
  1278. void MainWindow::initInteractiveWidgetLists()
  1279. {
  1280. _interactiveWidgetNames.insert(INTERACTIVE_WIDGET_SLIDER, tr("Slider"));
  1281. _interactiveWidgetNames.insert(INTERACTIVE_WIDGET_KNOB, tr("Knob"));
  1282. _interactiveWidgetNames.insert(INTERACTIVE_WIDGET_WHEEL, tr("Wheel"));
  1283. _interactiveWidgetNames.insert(INTERACTIVE_WIDGET_CHECKBOX, tr("Checkbox"));
  1284. _interactiveWidgetNames.insert(INTERACTIVE_WIDGET_SPINBOX, tr("Spinbox"));
  1285. _interactiveWidgetNames.insert(INTERACTIVE_WIDGET_DOUBLESPINBOX,
  1286. tr("Double Spinbox"));
  1287. _interactiveWidgetNames.insert(INTERACTIVE_WIDGET_DIAL, tr("Dial"));
  1288. _interactiveWidgetNames.insert(INTERACTIVE_WIDGET_COMBOBOX, tr("Combobox"));
  1289. _interactiveWidgetNames.insert(INTERACTIVE_WIDGET_NONE, tr("<none>"));
  1290. // Sets of widgets for each type
  1291. // Bool
  1292. _paramBoolWidgets.insert(INTERACTIVE_WIDGET_CHECKBOX);
  1293. // Int
  1294. _paramIntWidgets.insert(INTERACTIVE_WIDGET_SLIDER);
  1295. _paramIntWidgets.insert(INTERACTIVE_WIDGET_KNOB);
  1296. _paramIntWidgets.insert(INTERACTIVE_WIDGET_WHEEL);
  1297. _paramIntWidgets.insert(INTERACTIVE_WIDGET_SPINBOX);
  1298. _paramIntWidgets.insert(INTERACTIVE_WIDGET_DIAL);
  1299. // Float
  1300. _paramFloatWidgets.insert(INTERACTIVE_WIDGET_SLIDER);
  1301. _paramFloatWidgets.insert(INTERACTIVE_WIDGET_KNOB);
  1302. _paramFloatWidgets.insert(INTERACTIVE_WIDGET_WHEEL);
  1303. _paramFloatWidgets.insert(INTERACTIVE_WIDGET_DOUBLESPINBOX);
  1304. _paramFloatWidgets.insert(INTERACTIVE_WIDGET_DIAL);
  1305. // Enum
  1306. _paramEnumWidgets.insert(INTERACTIVE_WIDGET_COMBOBOX);
  1307. // Associate a type to widget possibilities
  1308. _interactiveWidgetPossibilities.insert(PARAM_TYPE_BOOL, _paramBoolWidgets);
  1309. _interactiveWidgetPossibilities.insert(PARAM_TYPE_INT, _paramIntWidgets);
  1310. _interactiveWidgetPossibilities.insert(PARAM_TYPE_FLOAT,
  1311. _paramFloatWidgets);
  1312. _interactiveWidgetPossibilities.insert(PARAM_TYPE_ENUM, _paramEnumWidgets);
  1313. }