mainwindow.cpp 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528
  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. // Init time references
  307. _lockedTime = 0;
  308. // Possibly clear old session widgets
  309. clearWidgets();
  310. // Enable the MDI area
  311. _mdiArea->setEnabled(true);
  312. // Install fresh data widgets
  313. for (int i = 0; i < _dataDescriptions->count(); i++)
  314. {
  315. if (_dataDescriptions->at(i)->widget != DATA_WIDGET_NONE)
  316. {
  317. DataWidget* dataWidget = addDataWidget(_dataDescriptions->at(i));
  318. _widgetWindowsManager->displayWidgetWindow(dataWidget);
  319. }
  320. }
  321. // Install fresh interactive widgets
  322. for (int i = 0; i < _paramDescriptions->count(); i++)
  323. {
  324. if (_paramDescriptions->at(i)->widget != INTERACTIVE_WIDGET_NONE)
  325. {
  326. InteractiveWidget* interactiveWidget = addInteractiveWidget(
  327. _paramDescriptions->at(i));
  328. displayInteractiveWidget(interactiveWidget);
  329. }
  330. }
  331. emit sessionOpened();
  332. }
  333. void MainWindow::closeSession()
  334. {
  335. // Clear old data/params descriptions
  336. clearDescriptions();
  337. // Disable the MDI area
  338. _mdiArea->setEnabled(false);
  339. // Update gantt time controller
  340. _ganttTimeView->setValue(effectiveRunningTime());
  341. // Close the preferences dialog if open
  342. if (_preferencesDialog != 0)
  343. {
  344. _preferencesDialog->close();
  345. }
  346. // Stop the communication thread
  347. if (_communicationThread->isRunning())
  348. {
  349. _communicationThread->exit(0);
  350. qDebug() << "MainWindow : stopped communication thread";
  351. }
  352. QMessageBox::information(
  353. this,
  354. tr("End of the session"),
  355. tr("The session has just finished (time running : ")
  356. + QString::number(runningTime()) + "ms, time locked : "
  357. + QString::number(lockedTime())
  358. + "ms, time effectively running : " + QString::number(
  359. effectiveRunningTime()) + "ms)", QMessageBox::Ok);
  360. emit sessionClosed();
  361. }
  362. void MainWindow::debugLock()
  363. {
  364. qDebug() << "MainWindow : locking session";
  365. _currentLockTime.start();
  366. setStatusBarIcon(":/images/lock.png");
  367. setStatusBarMessage("Locked");
  368. emit debugLocked();
  369. }
  370. void MainWindow::debugStep()
  371. {
  372. qDebug() << "MainWindow : unlocking session";
  373. _lockedTime += _currentLockTime.elapsed();
  374. _currentLockTime = QTime();
  375. _actionDebug->setEnabled(true);
  376. setStatusBarIcon("");
  377. setStatusBarMessage("Running");
  378. emit debugStepped();
  379. }
  380. void MainWindow::sessionMainWindowSetupLoaded(MainWindowSetup mainWindowSetup)
  381. {
  382. qDebug() << "MainWindow : restoring main window setup from another session";
  383. // Load geometry
  384. if (restoreGeometry(mainWindowSetup.geometry) == false)
  385. {
  386. qDebug() << "MainWindow : failed to restore main window geometry";
  387. }
  388. // Load display mode
  389. setDisplayMode(mainWindowSetup.displayMode);
  390. }
  391. void MainWindow::sessionParametersDockSetupLoaded(
  392. ParametersDockSetup parametersDockSetup)
  393. {
  394. qDebug() << "MainWindow : "
  395. "restoring parameters dock setup from another session";
  396. }
  397. void MainWindow::sessionWidgetWindowsSetupLoaded(
  398. QList<DataWidgetSetup> dataWidgetsSetup,
  399. QList<DataAggregatorWidgetSetup> dataAggregatorWidgetsSetup)
  400. {
  401. qDebug()
  402. << "MainWindow : "
  403. "restoring widget windows setup from another session";
  404. // Restore data widgets setup
  405. for (int i = 0; i < dataWidgetsSetup.count(); i++)
  406. {
  407. DataWidget *dataWidget = dataWidgetFromDataId(
  408. dataWidgetsSetup.at(i).dataId);
  409. if (dataWidget->isInside() != dataWidgetsSetup.at(i).inside)
  410. {
  411. dataWidget->setInside(dataWidgetsSetup.at(i).inside);
  412. if (dataWidget->isInside() == true)
  413. {
  414. _widgetWindowsManager->flyingWindowToMdi(dataWidget);
  415. }
  416. else
  417. {
  418. _widgetWindowsManager->mdiToFlyingWindow(dataWidget);
  419. }
  420. }
  421. if (dataWidget->isInside() == false)
  422. {
  423. dataWidget->restoreGeometry(dataWidgetsSetup.at(i).geometry);
  424. }
  425. else
  426. {
  427. dataWidget->parentWidget()->restoreGeometry(
  428. dataWidgetsSetup.at(i).geometry);
  429. }
  430. }
  431. // Restore data aggregator widgets setup
  432. for (int i = 0; i < dataAggregatorWidgetsSetup.count(); i++)
  433. {
  434. DataAggregatorWidget *dataAggregatorWidget = addDataAggregatorWidget(
  435. dataAggregatorWidgetsSetup.at(i).dataIds);
  436. _widgetWindowsManager->displayWidgetWindow(dataAggregatorWidget);
  437. if (dataAggregatorWidget->isInside()
  438. != dataAggregatorWidgetsSetup.at(i).inside)
  439. {
  440. dataAggregatorWidget->setInside(
  441. dataAggregatorWidgetsSetup.at(i).inside);
  442. if (dataAggregatorWidget->isInside() == true)
  443. {
  444. _widgetWindowsManager->flyingWindowToMdi(dataAggregatorWidget);
  445. }
  446. else
  447. {
  448. _widgetWindowsManager->mdiToFlyingWindow(dataAggregatorWidget);
  449. }
  450. }
  451. if (dataAggregatorWidget->isInside() == false)
  452. {
  453. dataAggregatorWidget ->restoreGeometry(
  454. dataAggregatorWidgetsSetup.at(i).geometry);
  455. }
  456. else
  457. {
  458. dataAggregatorWidget->parentWidget() ->restoreGeometry(
  459. dataAggregatorWidgetsSetup.at(i).geometry);
  460. }
  461. }
  462. }
  463. void MainWindow::protocolErrorCaught(QString errorMessage)
  464. {
  465. qDebug() << "MainWindow : protocol error caught (" + errorMessage + ")";
  466. }
  467. void MainWindow::synchronizeSessionTime(qlonglong serverTimestamp)
  468. {
  469. qDebug() << "Synchronized with server reference timestamp ("
  470. << serverTimestamp << ")";
  471. _referenceTimestamp = serverTimestamp;
  472. if (_preGoTimer.isNull())
  473. {
  474. _preGoTimer.start();
  475. }
  476. else
  477. {
  478. _preGoTimer.restart();
  479. }
  480. }
  481. void MainWindow::initClient(QString serverID,
  482. QList<DataDescription*> *dataDescriptions,
  483. QList<ParamDescription*> *paramDescriptions,
  484. QList<starpu_top_device> *serverDevices)
  485. {
  486. _serverID = serverID;
  487. _dataDescriptions = dataDescriptions;
  488. _paramDescriptions = paramDescriptions;
  489. _serverDevices = serverDevices;
  490. setReady(true);
  491. // Display widget choices list in preferences dialog
  492. _preferencesDialog = new PreferencesDialog(this, _configurationManager,
  493. _sessionSetupManager, 1);
  494. emit preferencesDialogCreated(_widgetsDisplayModesList->currentIndex());
  495. _preferencesDialog->setVisible(true);
  496. }
  497. /* -------------------------------------------------------------------------- */
  498. /* Actions */
  499. /* -------------------------------------------------------------------------- */
  500. void MainWindow::connectionSucceeded()
  501. {
  502. qDebug() << "MainWindow : connected to server";
  503. setConnected(true);
  504. }
  505. void MainWindow::connectionAborted(QString message)
  506. {
  507. QMessageBox::critical(this, "StarPU-Top", message, QMessageBox::Ok);
  508. setConnected(false);
  509. }
  510. void MainWindow::disconnected()
  511. {
  512. if (isRunning())
  513. {
  514. setRunning(false);
  515. }
  516. if (isReady())
  517. {
  518. setReady(false);
  519. }
  520. setConnected(false);
  521. qDebug() << "MainWindow : disconnected from server";
  522. }
  523. void MainWindow::on_actionConnect_triggered()
  524. {
  525. setStatusBarMessage("Awaiting connection...");
  526. _actionConnect->setEnabled(false);
  527. // Initiate connection to server
  528. _communicationThread->start(/*QThread::NormalPriority*/);
  529. _communicationThread->moveToThread(_communicationThread);
  530. }
  531. void MainWindow::on_actionLaunch_StarPU_triggered()
  532. {
  533. // Tell server to launch the session
  534. setRunning(true);
  535. emit clientLaunched();
  536. }
  537. void MainWindow::on_actionDebug_triggered(bool enabled)
  538. {
  539. _actionDebug->setEnabled(false);
  540. _actionDebug->setToolTip("Waiting for the server's acknowledgement...");
  541. _actionDebug->setIconText("Waiting for the server's acknowledgement...");
  542. emit debugEnabled(enabled);
  543. }
  544. void MainWindow::on_actionSaveSessionSetup_triggered()
  545. {
  546. if (_sessionSetupManager->saveSessionSetup(_serverID) == true)
  547. {
  548. qDebug() << "MainWindow : session setup successfully saved";
  549. statusBar()->showMessage(tr("Session setup successfully saved"),3000);
  550. }
  551. else
  552. {
  553. statusBar()->showMessage(tr("Couldn't save the session setup"),3000);
  554. }
  555. }
  556. void MainWindow::on_actionQuit_triggered()
  557. {
  558. close(); // Calls CloseEvent()
  559. }
  560. void MainWindow::on_actionAddDataAggregatorWidget_triggered()
  561. {
  562. AbstractWidgetWindow *widgetWindow =
  563. (AbstractWidgetWindow*) addDataAggregatorWidget();
  564. _widgetWindowsManager->displayWidgetWindow(widgetWindow);
  565. }
  566. void MainWindow::on_actionPreferences_triggered()
  567. {
  568. int tabindex = (_connected ? 1 : 0);
  569. // Open preferences dialog
  570. _preferencesDialog = new PreferencesDialog(this, _configurationManager,
  571. _sessionSetupManager, tabindex);
  572. _preferencesDialog->setVisible(true);
  573. emit preferencesDialogCreated(_widgetsDisplayModesList->currentIndex());
  574. }
  575. void MainWindow::on_actionAbout_triggered()
  576. {
  577. AboutDialog *aboutDialog = new AboutDialog(this);
  578. aboutDialog->setVisible(true);
  579. }
  580. /* -------------------------------------------------------------------------- */
  581. /* Getters */
  582. /* -------------------------------------------------------------------------- */
  583. const QSplitter *MainWindow::splitter() const
  584. {
  585. return _splitter;
  586. }
  587. const QDockWidget *MainWindow::parametersDock() const
  588. {
  589. return ui->parametersDock;
  590. }
  591. const WidgetWindowsManager* MainWindow::widgetWindowsManager() const
  592. {
  593. return _widgetWindowsManager;
  594. }
  595. const ConfigurationManager* MainWindow::configurationManager() const
  596. {
  597. return _configurationManager;
  598. }
  599. const SessionSetupManager* MainWindow::sessionSetupManager() const
  600. {
  601. return _sessionSetupManager;
  602. }
  603. const TaskManager* MainWindow::taskManager() const
  604. {
  605. return _taskManager;
  606. }
  607. const QHash<DataWidgetType, QString> *MainWindow::dataWidgetNames() const
  608. {
  609. return &_dataWidgetNames;
  610. }
  611. const QHash<DataType, QSet<DataWidgetType> >
  612. *MainWindow::dataWidgetPossibilities() const
  613. {
  614. return &_dataWidgetPossibilities;
  615. }
  616. const QHash<InteractiveWidgetType, QString>
  617. *MainWindow::interactiveWidgetNames() const
  618. {
  619. return &_interactiveWidgetNames;
  620. }
  621. const QHash<ParamType, QSet<InteractiveWidgetType> >
  622. *MainWindow::interactiveWidgetPossibilities() const
  623. {
  624. return &_interactiveWidgetPossibilities;
  625. }
  626. int MainWindow::nbDataWidgets() const
  627. {
  628. return _nbDataWidgets;
  629. }
  630. int MainWindow::nbInteractiveWidgets() const
  631. {
  632. return _nbInteractiveWidgets;
  633. }
  634. int MainWindow::nbDataAggregatorWidgets() const
  635. {
  636. return _nbDataAggregatorWidgets;
  637. }
  638. QString MainWindow::serverID() const
  639. {
  640. return _serverID;
  641. }
  642. const QList<DataDescription*> *MainWindow::dataDescriptions() const
  643. {
  644. return _dataDescriptions;
  645. }
  646. const QList<ParamDescription*> *MainWindow::paramDescriptions() const
  647. {
  648. return _paramDescriptions;
  649. }
  650. bool MainWindow::isConnected() const
  651. {
  652. return _connected;
  653. }
  654. bool MainWindow::isReady() const
  655. {
  656. return _ready;
  657. }
  658. bool MainWindow::isRunning() const
  659. {
  660. return _running;
  661. }
  662. bool MainWindow::isDebugEnabled() const
  663. {
  664. return _debug;
  665. }
  666. DisplayMode MainWindow::displayMode() const
  667. {
  668. return _displayMode;
  669. }
  670. int MainWindow::effectiveRunningTime() const
  671. {
  672. if (_runningTime.isNull())
  673. {
  674. return 0;
  675. }
  676. return _runningTime.elapsed() - (_lockedTime + currentLockTime());
  677. }
  678. int MainWindow::runningTime() const
  679. {
  680. if (_runningTime.isNull())
  681. {
  682. return 0;
  683. }
  684. return _runningTime.elapsed();
  685. }
  686. int MainWindow::currentLockTime() const
  687. {
  688. if (_currentLockTime.isNull())
  689. {
  690. return 0;
  691. }
  692. return _currentLockTime.elapsed();
  693. }
  694. int MainWindow::lockedTime() const
  695. {
  696. return _lockedTime;
  697. }
  698. /* -------------------------------------------------------------------------- */
  699. /* Setters */
  700. /* -------------------------------------------------------------------------- */
  701. void MainWindow::setStatusBarMessage(QString message)
  702. {
  703. if (_statusBarLabel != 0)
  704. {
  705. _statusBarLabel->setText(message);
  706. }
  707. }
  708. void MainWindow::updateStatusBarMessage(QString message)
  709. {
  710. setStatusBarMessage(message);
  711. }
  712. void MainWindow::setStatusBarIcon(QString iconFile)
  713. {
  714. if (_statusBarIcon != 0)
  715. {
  716. _statusBarIcon->setPixmap(QPixmap(iconFile));
  717. }
  718. }
  719. void MainWindow::setConnected(bool connected)
  720. {
  721. _connected = connected;
  722. if (_connected == false)
  723. {
  724. Q_ASSERT_X(_ready == false && _running == false,
  725. "MainWindow::setConnected()",
  726. "MainWindow states hierarchy violated");
  727. _actionConnect->setEnabled(true);
  728. _actionLaunch->setEnabled(false);
  729. _actionDebug->setEnabled(false);
  730. _actionSaveSessionSetup->setEnabled(false);
  731. _actionAddDataAggregatorWidget->setEnabled(false);
  732. setStatusBarMessage(tr("Disconnected"));
  733. }
  734. else
  735. {
  736. _actionConnect->setEnabled(false);
  737. setStatusBarMessage(
  738. tr("Connected (") + _configurationManager->serverHost() + ":"
  739. + QString::number(_configurationManager->serverPort())
  740. + ")");
  741. }
  742. }
  743. void MainWindow::setReady(bool ready)
  744. {
  745. _ready = ready;
  746. if (_ready == true)
  747. {
  748. Q_ASSERT_X(_connected == true, "MainWindow::setReady()",
  749. "MainWindow states hierarchy violated");
  750. _actionLaunch->setEnabled(true);
  751. _actionDebug->setEnabled(true);
  752. _actionAddDataAggregatorWidget->setEnabled(true);
  753. setStatusBarMessage(
  754. tr("Connected and ready (") + _serverID + tr(" on ")
  755. + _configurationManager->serverHost() + ":"
  756. + QString::number(_configurationManager->serverPort())
  757. + ")");
  758. openSession();
  759. _actionSaveSessionSetup->setEnabled(true);
  760. }
  761. else
  762. {
  763. Q_ASSERT_X(_running == false, "MainWindow::setReady()",
  764. "MainWindow states hierarchy violated");
  765. _actionConnect->setEnabled(false);
  766. _actionLaunch->setEnabled(false);
  767. _actionDebug->setEnabled(false);
  768. _actionAddDataAggregatorWidget->setEnabled(false);
  769. setStatusBarMessage(
  770. tr("Connected (") + _configurationManager->serverHost() + ":"
  771. + QString::number(_configurationManager->serverPort())
  772. + ")");
  773. closeSession();
  774. _actionSaveSessionSetup->setEnabled(false);
  775. }
  776. }
  777. void MainWindow::setRunning(bool running)
  778. {
  779. _running = running;
  780. if (running == true)
  781. {
  782. Q_ASSERT_X(_connected == true && _ready == true,
  783. "MainWindow::setRunning()",
  784. "MainWindow states hierarchy violated");
  785. // Stop pre-running time and start running time
  786. _preGoTime = _preGoTimer.elapsed() + _referenceTimestamp;
  787. qDebug() << "Pre-Go time :" << _preGoTime;
  788. if (_runningTime.isNull())
  789. {
  790. _runningTime.start();
  791. }
  792. else
  793. {
  794. _runningTime.restart();
  795. }
  796. _actionLaunch->setEnabled(false);
  797. setStatusBarMessage(tr("Running"));
  798. setWindowTitle(
  799. windowTitle() + " (" + _serverID + tr(" on ")
  800. + _configurationManager->serverHost() + ":"
  801. + QString::number(_configurationManager->serverPort())
  802. + ")");
  803. }
  804. else
  805. {
  806. _actionLaunch->setEnabled(true);
  807. setStatusBarMessage(
  808. tr("Connected and ready (") + _serverID + tr(" on ")
  809. + _configurationManager->serverHost() + ":"
  810. + QString::number(_configurationManager->serverPort())
  811. + ")");
  812. setWindowTitle(tr("StarPU-Top"));
  813. }
  814. }
  815. void MainWindow::setDebug(bool enabled)
  816. {
  817. _debug = enabled;
  818. _actionDebug->setEnabled(true);
  819. if (_debug == true)
  820. {
  821. qDebug() << "MainWindow : enabling debug mode";
  822. _actionDebug->setIcon(QIcon(":/images/debugoff.png"));
  823. _actionDebug->setIconText("Disable debug");
  824. _actionDebug->setText("Disable debug");
  825. _actionDebug->setToolTip("Disable debug");
  826. _debugConsole->setVisible(true);
  827. }
  828. else
  829. {
  830. qDebug() << "MainWindow : disabling debug mode";
  831. _actionDebug->setIcon(QIcon(":/images/debugon.png"));
  832. _actionDebug->setIconText("Enable debug");
  833. _actionDebug->setText("Enable debug");
  834. _actionDebug->setToolTip("Enable debug");
  835. _debugConsole->setVisible(false);
  836. }
  837. }
  838. void MainWindow::setDisplayMode(DisplayMode displayMode)
  839. {
  840. _displayMode = displayMode;
  841. switch (_displayMode)
  842. {
  843. case DISPLAY_FLYING_WINDOWS:
  844. _widgetWindowsManager->mdiToFlyingWindows();
  845. break;
  846. case DISPLAY_MDI_NORMAL:
  847. _widgetWindowsManager->flyingWindowsToMdi();
  848. break;
  849. }
  850. }
  851. void MainWindow::setDebugMessage(QString debugMessage)
  852. {
  853. if (isDebugEnabled() == true)
  854. {
  855. _debugConsole->appendDebugLogMessage(debugMessage);
  856. }
  857. else
  858. {
  859. qDebug() << "Debug message ignored (received while not in debug mode)";
  860. }
  861. }
  862. void MainWindow::setDebugLock(QString debugLockMessage)
  863. {
  864. if (isDebugEnabled() == true)
  865. {
  866. debugLock();
  867. _debugConsole->appendDebugLockMessage(debugLockMessage);
  868. }
  869. else
  870. {
  871. qDebug() << "Debug lock ignored (received while not in debug mode)";
  872. }
  873. }
  874. /* -------------------------------------------------------------------------- */
  875. /* Other methods */
  876. /* -------------------------------------------------------------------------- */
  877. void MainWindow::clearDescriptions()
  878. {
  879. clearDataDescriptions();
  880. clearParamDescriptions();
  881. }
  882. DataWidget* MainWindow::addDataWidget(DataDescription *dataDescription)
  883. {
  884. // Create new data widget following the description
  885. bool inside = (_displayMode == DISPLAY_FLYING_WINDOWS ? false : true);
  886. DataWidget *dataWidget = new DataWidget(dataDescription,
  887. _widgetWindowsManager,
  888. this, inside);
  889. _dataWidgets->append(QPointer<DataWidget> (dataWidget));
  890. _nbDataWidgets++;
  891. return dataWidget;
  892. }
  893. void MainWindow::clearWidgets()
  894. {
  895. clearDataWidgets();
  896. clearInteractiveWidgets();
  897. }
  898. void MainWindow::clearDataWidgets()
  899. {
  900. _widgetWindowsManager->closeWidgetWindows();
  901. _dataWidgets->clear();
  902. }
  903. void MainWindow::removeDestroyedDataWidgets()
  904. {
  905. // Clear all null data widget pointers in the data widgets list
  906. for (int i = 0; i < _dataWidgets->count(); i++)
  907. {
  908. if (_dataWidgets->at(i).isNull())
  909. {
  910. _dataWidgets->removeAt(i);
  911. _nbDataWidgets--;
  912. }
  913. }
  914. }
  915. void MainWindow::clearDataDescriptions()
  916. {
  917. _dataDescriptions->clear();
  918. }
  919. InteractiveWidget *MainWindow::addInteractiveWidget(
  920. ParamDescription *paramDescription)
  921. {
  922. // Add new interactive widget following the description
  923. InteractiveWidget *interactiveWidget = new InteractiveWidget(
  924. paramDescription, this);
  925. _interactiveWidgets->append(
  926. QPointer<InteractiveWidget> (interactiveWidget));
  927. _nbInteractiveWidgets++;
  928. return interactiveWidget;
  929. }
  930. DataAggregatorWidget *MainWindow::addDataAggregatorWidget(QList<int> dataIds)
  931. {
  932. bool inside = (_displayMode == DISPLAY_FLYING_WINDOWS ? false : true);
  933. DataAggregatorWidget *dataAggregatorWidget = new DataAggregatorWidget(
  934. _widgetWindowsManager, this, inside, dataIds);
  935. _dataAggregatorWidgets->append(
  936. QPointer<DataAggregatorWidget> (dataAggregatorWidget));
  937. _nbDataAggregatorWidgets++;
  938. return dataAggregatorWidget;
  939. }
  940. void MainWindow::displayInteractiveWidget(InteractiveWidget *interactiveWidget)
  941. {
  942. // Display interactive widget in the dock widget
  943. QVBoxLayout* layout = (QVBoxLayout*) _parametersDockScrollArea->layout();
  944. layout->addWidget(interactiveWidget);
  945. }
  946. void MainWindow::clearInteractiveWidgets()
  947. {
  948. qDebug() << "Closing all interactive widgets";
  949. for (int i = 0; i < _interactiveWidgets->count(); i++)
  950. {
  951. _interactiveWidgets->at(i).data()->close();
  952. }
  953. _interactiveWidgets->clear();
  954. }
  955. void MainWindow::removeDestroyedInteractiveWidgets()
  956. {
  957. // Clear all null data widget pointers in the data widgets list
  958. for (int i = 0; i < _interactiveWidgets->count(); i++)
  959. {
  960. if (_interactiveWidgets->at(i).isNull())
  961. {
  962. _interactiveWidgets->removeAt(i);
  963. _paramDescriptions->at(i)->widget = INTERACTIVE_WIDGET_NONE;
  964. _nbInteractiveWidgets--;
  965. }
  966. }
  967. }
  968. void MainWindow::clearParamDescriptions()
  969. {
  970. _paramDescriptions->clear();
  971. }
  972. void MainWindow::removeDestroyedDataAggregatorWidgets()
  973. {
  974. // Clear all null data aggregator widget pointers in list
  975. for (int i = 0; i < _dataAggregatorWidgets->count(); i++)
  976. {
  977. if (_dataAggregatorWidgets->at(i).isNull())
  978. {
  979. _dataAggregatorWidgets->removeAt(i);
  980. _nbDataAggregatorWidgets--;
  981. }
  982. }
  983. }
  984. /* -------------------------------------------------------------------------- */
  985. /* Getters */
  986. /* -------------------------------------------------------------------------- */
  987. QString MainWindow::statusBarMessage() const
  988. {
  989. return _statusBarLabel->text();
  990. }
  991. const QList<QPointer<DataWidget> > *MainWindow::dataWidgets() const
  992. {
  993. return _dataWidgets;
  994. }
  995. const QList<QPointer<InteractiveWidget> >
  996. *MainWindow::interactiveWidgets() const
  997. {
  998. return _interactiveWidgets;
  999. }
  1000. const QList<QPointer<DataAggregatorWidget> >
  1001. *MainWindow::dataAggregatorWidgets() const
  1002. {
  1003. return _dataAggregatorWidgets;
  1004. }
  1005. DataWidget *MainWindow::dataWidgetFromDataId(int dataId)
  1006. {
  1007. for (int i = 0; i < _dataWidgets->count(); i++)
  1008. {
  1009. if (_dataWidgets->at(i)->description()->id == dataId)
  1010. return _dataWidgets->at(i);
  1011. }
  1012. return 0;
  1013. }
  1014. InteractiveWidget *MainWindow::interactiveWidgetFromParamId(int paramId)
  1015. {
  1016. for (int i = 0; i < _interactiveWidgets->count(); i++)
  1017. {
  1018. if (_interactiveWidgets->at(i)->description()->id == paramId)
  1019. return _interactiveWidgets->at(i);
  1020. }
  1021. return 0;
  1022. }
  1023. DataDescription *MainWindow::dataDescriptionFromId(int dataId)
  1024. {
  1025. for (int i = 0; i < _dataDescriptions->count(); i++)
  1026. {
  1027. if (_dataDescriptions->at(i)->id == dataId)
  1028. return _dataDescriptions->at(i);
  1029. }
  1030. return 0;
  1031. }
  1032. ParamDescription *MainWindow::paramDescriptionFromId(int paramId)
  1033. {
  1034. for (int i = 0; i < _paramDescriptions->count(); i++)
  1035. {
  1036. if (_paramDescriptions->at(i)->id == paramId)
  1037. return _paramDescriptions->at(i);
  1038. }
  1039. return 0;
  1040. }
  1041. const QList<starpu_top_device> *MainWindow::serverDevices() const
  1042. {
  1043. return _serverDevices;
  1044. }
  1045. /* -------------------------------------------------------------------------- */
  1046. /* Other methods */
  1047. /* -------------------------------------------------------------------------- */
  1048. void MainWindow::updateDataWidgetsDisplayMode(int index)
  1049. {
  1050. // Update the display mode
  1051. setDisplayMode(
  1052. (DisplayMode) _widgetsDisplayModesList->itemData(index).toInt());
  1053. }
  1054. void MainWindow::updateDisplayModeIndex(int index)
  1055. {
  1056. // Update display mode choice index in the toolbar
  1057. _widgetsDisplayModesList->setCurrentIndex(index);
  1058. }
  1059. void MainWindow::updateDataWidgetType(int dataId, DataWidgetType newWidget)
  1060. {
  1061. // Update the data widget description with type selected by user
  1062. DataDescription *dataDescription = dataDescriptionFromId(dataId);
  1063. if (dataDescription != 0)
  1064. {
  1065. DataWidgetType oldWidget = dataDescription->widget;
  1066. dataDescription->widget = newWidget;
  1067. qDebug() << "Data of id" << dataId << "changed widget type (old :"
  1068. << oldWidget << " new:" << newWidget << ")";
  1069. DataWidget *dataWidget = dataWidgetFromDataId(dataId);
  1070. if (newWidget == DATA_WIDGET_NONE && oldWidget != DATA_WIDGET_NONE)
  1071. { // We have disabled this data
  1072. emit dataDisabled(dataId);
  1073. qDebug() << "Data of id has been" << dataId << "DISABLED";
  1074. _widgetWindowsManager->closeWidgetWindow(dataWidget);
  1075. }
  1076. else if (newWidget != DATA_WIDGET_NONE && oldWidget == DATA_WIDGET_NONE)
  1077. { // We have enabled this data
  1078. // The entire widget needs to be created
  1079. _widgetWindowsManager->displayWidgetWindow(
  1080. addDataWidget(dataDescriptionFromId(dataId)));
  1081. emit dataEnabled(dataId);
  1082. qDebug() << "Data of id has been" << dataId << "ENABLED";
  1083. }
  1084. else if (newWidget != DATA_WIDGET_NONE && oldWidget != DATA_WIDGET_NONE)
  1085. { // Neither disable nor enabled, just change of the widget
  1086. // The widget just needs to redraw the internal data widget
  1087. dataWidget->recreateInternalWidget();
  1088. }
  1089. }
  1090. }
  1091. void MainWindow::updateInteractiveWidgetType(int paramId,
  1092. InteractiveWidgetType newWidget)
  1093. {
  1094. ParamDescription *paramDescription = paramDescriptionFromId(paramId);
  1095. if (paramDescription != 0)
  1096. {
  1097. InteractiveWidgetType oldWidget = paramDescription->widget;
  1098. paramDescription->widget = newWidget;
  1099. qDebug() << "Param of id" << paramId << "changed widget type (old :"
  1100. << oldWidget << " new:" << newWidget << ")";
  1101. // The widget just needs to redraw the internal interactive widget
  1102. InteractiveWidget *interactiveWidget = interactiveWidgetFromParamId(
  1103. paramId);
  1104. interactiveWidget->recreateInternalWidget();
  1105. }
  1106. }
  1107. /* -------------------------------------------------------------------------- */
  1108. /* Slots */
  1109. /* -------------------------------------------------------------------------- */
  1110. void MainWindow::updateInteractiveWidget(int interactiveWidgetId, bool value,
  1111. qlonglong timestamp)
  1112. {
  1113. InteractiveWidget *interactiveWidget = interactiveWidgetFromParamId(
  1114. interactiveWidgetId);
  1115. if (interactiveWidget != 0)
  1116. {
  1117. qDebug() << "Updating interactive widget of id" << interactiveWidgetId
  1118. << "updated with value" << value << "and timestamp"
  1119. << timestamp;
  1120. interactiveWidget->setValue(value);
  1121. }
  1122. else
  1123. {
  1124. qDebug() << "Trying to update inexistant interactive widget ! (id"
  1125. << interactiveWidgetId << ")";
  1126. }
  1127. }
  1128. void MainWindow::updateInteractiveWidget(int interactiveWidgetId, int value,
  1129. qlonglong timestamp)
  1130. {
  1131. InteractiveWidget *interactiveWidget = interactiveWidgetFromParamId(
  1132. interactiveWidgetId);
  1133. if (interactiveWidget != 0)
  1134. {
  1135. qDebug() << "Updating interactive widget of id" << interactiveWidgetId
  1136. << "updated with value" << value << "and timestamp"
  1137. << timestamp;
  1138. interactiveWidget->setValue(value);
  1139. }
  1140. else
  1141. {
  1142. qDebug() << "Trying to update inexistant interactive widget ! (id"
  1143. << interactiveWidgetId << ")";
  1144. }
  1145. }
  1146. void MainWindow::updateInteractiveWidget(int interactiveWidgetId, double value,
  1147. qlonglong timestamp)
  1148. {
  1149. InteractiveWidget *interactiveWidget = interactiveWidgetFromParamId(
  1150. interactiveWidgetId);
  1151. if (interactiveWidget != 0)
  1152. {
  1153. qDebug() << "Updating interactive widget of id" << interactiveWidgetId
  1154. << "updated with value" << value << "and timestamp"
  1155. << timestamp;
  1156. interactiveWidget->setValue(value);
  1157. }
  1158. else
  1159. {
  1160. qDebug() << "Trying to update inexistant interactive widget ! (id"
  1161. << interactiveWidgetId << ")";
  1162. }
  1163. }
  1164. void MainWindow::updateTaskPrev(int taskId, int deviceId, qlonglong timestamp,
  1165. qlonglong timestampStart,
  1166. qlonglong timestampEnd)
  1167. {
  1168. _taskManager->addTaskPrev(taskId, deviceId, timestampStart - _preGoTime,
  1169. timestampEnd - _preGoTime);
  1170. }
  1171. void MainWindow::updateTaskStart(int taskId, int deviceId, qlonglong timestamp)
  1172. {
  1173. _taskManager->addTaskStart(taskId, deviceId, timestamp - _preGoTime);
  1174. }
  1175. void MainWindow::updateTaskEnd(int taskId, qlonglong timestamp)
  1176. {
  1177. _taskManager->addTaskEnd(taskId, timestamp - _preGoTime);
  1178. }
  1179. void MainWindow::updateDataWidget(int dataWidgetId, bool value,
  1180. qlonglong timestamp)
  1181. {
  1182. DataWidget *dataWidget = dataWidgetFromDataId(dataWidgetId);
  1183. if (dataWidget != 0)
  1184. {
  1185. qDebug() << "MainWindow : updating data widget of id" << dataWidgetId
  1186. << "with value" << value << "and timestamp" << timestamp;
  1187. dataWidget->setValue(value);
  1188. }
  1189. else
  1190. {
  1191. qDebug()
  1192. << "MainWindow : trying to update inexistant data widget ! (id"
  1193. << dataWidgetId << ")";
  1194. }
  1195. }
  1196. void MainWindow::updateDataWidget(int dataWidgetId, int value,
  1197. qlonglong timestamp)
  1198. {
  1199. DataWidget *dataWidget = dataWidgetFromDataId(dataWidgetId);
  1200. if (dataWidget != 0)
  1201. {
  1202. qDebug() << "MainWindow : updating data widget of id" << dataWidgetId
  1203. << "with value" << value << "and timestamp" << timestamp;
  1204. dataWidget->setValue(value);
  1205. }
  1206. else
  1207. {
  1208. qDebug()
  1209. << "MainWindow : trying to update inexistant data widget ! (id"
  1210. << dataWidgetId << ")";
  1211. }
  1212. }
  1213. void MainWindow::updateDataWidget(int dataWidgetId, double value,
  1214. qlonglong timestamp)
  1215. {
  1216. DataWidget *dataWidget = dataWidgetFromDataId(dataWidgetId);
  1217. if (dataWidget != 0)
  1218. {
  1219. qDebug() << "MainWindow : updating data widget of id" << dataWidgetId
  1220. << "with value" << value << "and timestamp" << timestamp;
  1221. dataWidget->setValue(value);
  1222. }
  1223. else
  1224. {
  1225. qDebug()
  1226. << "MainWindow : trying to update inexistant data widget ! (id"
  1227. << dataWidgetId << ")";
  1228. }
  1229. }
  1230. void MainWindow::interactiveWidgetUpdated(int interactiveWidgetId, bool value)
  1231. {
  1232. qDebug() << "MainWindow : interactive widget of id" << interactiveWidgetId
  1233. << "updated with value" << value;
  1234. emit paramValueUpdated(interactiveWidgetId, value);
  1235. }
  1236. void MainWindow::interactiveWidgetUpdated(int interactiveWidgetId, int value)
  1237. {
  1238. qDebug() << "MainWindow : interactive widget of id" << interactiveWidgetId
  1239. << "updated with value" << value;
  1240. emit paramValueUpdated(interactiveWidgetId, value);
  1241. }
  1242. void MainWindow::interactiveWidgetUpdated(int interactiveWidgetId, double value)
  1243. {
  1244. qDebug() << "MainWindow : interactive widget of id" << interactiveWidgetId
  1245. << "updated with value" << value;
  1246. emit paramValueUpdated(interactiveWidgetId, value);
  1247. }
  1248. void MainWindow::initDataWidgetLists()
  1249. {
  1250. //Names
  1251. _dataWidgetNames.insert(DATA_WIDGET_LCD, tr("Lcd"));
  1252. _dataWidgetNames.insert(DATA_WIDGET_PLOT, tr("Plot"));
  1253. _dataWidgetNames.insert(DATA_WIDGET_LEVEL, tr("Level"));
  1254. _dataWidgetNames.insert(DATA_WIDGET_LED, tr("Led"));
  1255. _dataWidgetNames.insert(DATA_WIDGET_DIAL, tr("Dial"));
  1256. _dataWidgetNames.insert(DATA_WIDGET_NONE, tr("<none>"));
  1257. // Sets of widgets for each type
  1258. // Bool
  1259. _dataBoolWidgets.insert(DATA_WIDGET_LED);
  1260. // Int
  1261. _dataIntWidgets.insert(DATA_WIDGET_LCD);
  1262. _dataIntWidgets.insert(DATA_WIDGET_PLOT);
  1263. _dataIntWidgets.insert(DATA_WIDGET_LEVEL);
  1264. _dataIntWidgets.insert(DATA_WIDGET_DIAL);
  1265. // Float
  1266. _dataFloatWidgets.insert(DATA_WIDGET_LCD);
  1267. _dataFloatWidgets.insert(DATA_WIDGET_PLOT);
  1268. _dataFloatWidgets.insert(DATA_WIDGET_LEVEL);
  1269. _dataFloatWidgets.insert(DATA_WIDGET_DIAL);
  1270. // Associate a type to widget possibilities
  1271. _dataWidgetPossibilities.insert(DATA_TYPE_BOOL, _dataBoolWidgets);
  1272. _dataWidgetPossibilities.insert(DATA_TYPE_INT, _dataIntWidgets);
  1273. _dataWidgetPossibilities.insert(DATA_TYPE_FLOAT, _dataFloatWidgets);
  1274. }
  1275. void MainWindow::initInteractiveWidgetLists()
  1276. {
  1277. _interactiveWidgetNames.insert(INTERACTIVE_WIDGET_SLIDER, tr("Slider"));
  1278. _interactiveWidgetNames.insert(INTERACTIVE_WIDGET_KNOB, tr("Knob"));
  1279. _interactiveWidgetNames.insert(INTERACTIVE_WIDGET_WHEEL, tr("Wheel"));
  1280. _interactiveWidgetNames.insert(INTERACTIVE_WIDGET_CHECKBOX, tr("Checkbox"));
  1281. _interactiveWidgetNames.insert(INTERACTIVE_WIDGET_SPINBOX, tr("Spinbox"));
  1282. _interactiveWidgetNames.insert(INTERACTIVE_WIDGET_DOUBLESPINBOX,
  1283. tr("Double Spinbox"));
  1284. _interactiveWidgetNames.insert(INTERACTIVE_WIDGET_DIAL, tr("Dial"));
  1285. _interactiveWidgetNames.insert(INTERACTIVE_WIDGET_COMBOBOX, tr("Combobox"));
  1286. _interactiveWidgetNames.insert(INTERACTIVE_WIDGET_NONE, tr("<none>"));
  1287. // Sets of widgets for each type
  1288. // Bool
  1289. _paramBoolWidgets.insert(INTERACTIVE_WIDGET_CHECKBOX);
  1290. // Int
  1291. _paramIntWidgets.insert(INTERACTIVE_WIDGET_SLIDER);
  1292. _paramIntWidgets.insert(INTERACTIVE_WIDGET_KNOB);
  1293. _paramIntWidgets.insert(INTERACTIVE_WIDGET_WHEEL);
  1294. _paramIntWidgets.insert(INTERACTIVE_WIDGET_SPINBOX);
  1295. _paramIntWidgets.insert(INTERACTIVE_WIDGET_DIAL);
  1296. // Float
  1297. _paramFloatWidgets.insert(INTERACTIVE_WIDGET_SLIDER);
  1298. _paramFloatWidgets.insert(INTERACTIVE_WIDGET_KNOB);
  1299. _paramFloatWidgets.insert(INTERACTIVE_WIDGET_WHEEL);
  1300. _paramFloatWidgets.insert(INTERACTIVE_WIDGET_DOUBLESPINBOX);
  1301. _paramFloatWidgets.insert(INTERACTIVE_WIDGET_DIAL);
  1302. // Enum
  1303. _paramEnumWidgets.insert(INTERACTIVE_WIDGET_COMBOBOX);
  1304. // Associate a type to widget possibilities
  1305. _interactiveWidgetPossibilities.insert(PARAM_TYPE_BOOL, _paramBoolWidgets);
  1306. _interactiveWidgetPossibilities.insert(PARAM_TYPE_INT, _paramIntWidgets);
  1307. _interactiveWidgetPossibilities.insert(PARAM_TYPE_FLOAT,
  1308. _paramFloatWidgets);
  1309. _interactiveWidgetPossibilities.insert(PARAM_TYPE_ENUM, _paramEnumWidgets);
  1310. }