3434
3535using GuiState = GuiModel::GuiState;
3636
37- MainWindow::MainWindow (QStringList cmdArguments, GuiModel* pGuiModel,
38- SettingsModel* pSettingsModel, GraphDataModel* pGraphDataModel,
39- NoteModel* pNoteModel, DiagnosticModel* pDiagnosticModel,
40- DataParserModel* pDataParserModel, QWidget *parent) :
41- QMainWindow(parent),
42- _pUi(new Ui::MainWindow),
43- _pGuiModel(pGuiModel),
44- _pSettingsModel(pSettingsModel),
45- _pGraphDataModel(pGraphDataModel),
46- _pNoteModel(pNoteModel),
47- _pDiagnosticModel(pDiagnosticModel),
48- _pDataParserModel(pDataParserModel)
37+ MainWindow::MainWindow (QStringList cmdArguments,
38+ GuiModel* pGuiModel,
39+ SettingsModel* pSettingsModel,
40+ GraphDataModel* pGraphDataModel,
41+ NoteModel* pNoteModel,
42+ DiagnosticModel* pDiagnosticModel,
43+ DataParserModel* pDataParserModel,
44+ QWidget* parent)
45+ : QMainWindow(parent),
46+ _pUi(new Ui::MainWindow),
47+ _pGuiModel(pGuiModel),
48+ _pSettingsModel(pSettingsModel),
49+ _pGraphDataModel(pGraphDataModel),
50+ _pNoteModel(pNoteModel),
51+ _pDiagnosticModel(pDiagnosticModel),
52+ _pDataParserModel(pDataParserModel)
4953{
5054 _pUi->setupUi (this );
5155
@@ -60,7 +64,8 @@ MainWindow::MainWindow(QStringList cmdArguments, GuiModel* pGuiModel,
6064 connect (_pModbusPoll, &ModbusPoll::registerDataReady, _pGraphDataHandler, &GraphDataHandler::handleRegisterData);
6165
6266 _pGraphView = new GraphView (_pGuiModel, _pSettingsModel, _pGraphDataModel, _pNoteModel, _pUi->customPlot , this );
63- _pDataFileHandler = new DataFileHandler (_pGuiModel, _pGraphDataModel, _pNoteModel, _pSettingsModel, _pDataParserModel, this );
67+ _pDataFileHandler =
68+ new DataFileHandler (_pGuiModel, _pGraphDataModel, _pNoteModel, _pSettingsModel, _pDataParserModel, this );
6469 _pProjectFileHandler = new ProjectFileHandler (_pGuiModel, _pSettingsModel, _pGraphDataModel);
6570 _pExpressionStatus = new ExpressionStatus (_pGraphDataModel, pSettingsModel);
6671 _pCommunicationStats = new CommunicationStats (_pGraphDataModel);
@@ -84,13 +89,17 @@ MainWindow::MainWindow(QStringList cmdArguments, GuiModel* pGuiModel,
8489 connect (_pUi->actionManageNotes , &QAction::triggered, this , &MainWindow::showNotesDialog);
8590 connect (_pUi->actionExit , &QAction::triggered, this , &MainWindow::exitApplication);
8691 connect (_pUi->actionSaveDataFile , &QAction::triggered, _pDataFileHandler, &DataFileHandler::selectDataExportFile);
87- connect (_pUi->actionOpenProjectFile , &QAction::triggered, _pProjectFileHandler, &ProjectFileHandler::selectProjectOpenFile);
88- connect (_pUi->actionReloadProjectFile , &QAction::triggered, _pProjectFileHandler, &ProjectFileHandler::reloadProjectFile);
92+ connect (_pUi->actionOpenProjectFile , &QAction::triggered, _pProjectFileHandler,
93+ &ProjectFileHandler::selectProjectOpenFile);
94+ connect (_pUi->actionReloadProjectFile , &QAction::triggered, _pProjectFileHandler,
95+ &ProjectFileHandler::reloadProjectFile);
8996 connect (_pUi->actionOpenDataFile , &QAction::triggered, _pDataFileHandler, &DataFileHandler::selectDataImportFile);
9097 connect (_pUi->actionImportFromMbcFile , &QAction::triggered, this , &MainWindow::showMbcImportDialog);
9198 connect (_pUi->actionExportImage , &QAction::triggered, this , &MainWindow::selectImageExportFile);
92- connect (_pUi->actionSaveProjectFileAs , &QAction::triggered, _pProjectFileHandler, &ProjectFileHandler::selectProjectSaveFile);
93- connect (_pUi->actionSaveProjectFile , &QAction::triggered, _pProjectFileHandler, &ProjectFileHandler::saveProjectFile);
99+ connect (_pUi->actionSaveProjectFileAs , &QAction::triggered, _pProjectFileHandler,
100+ &ProjectFileHandler::selectProjectSaveFile);
101+ connect (_pUi->actionSaveProjectFile , &QAction::triggered, _pProjectFileHandler,
102+ &ProjectFileHandler::saveProjectFile);
94103 connect (_pUi->actionAbout , &QAction::triggered, this , &MainWindow::showAbout);
95104 connect (_pUi->actionOnlineDocumentation , &QAction::triggered, this , &MainWindow::openOnlineDoc);
96105 connect (_pUi->actionUpdateAvailable , &QAction::triggered, this , &MainWindow::openUpdateUrl);
@@ -100,7 +109,8 @@ MainWindow::MainWindow(QStringList cmdArguments, GuiModel* pGuiModel,
100109 connect (_pUi->actionSettings , &QAction::triggered, this , &MainWindow::showSettingsDialog);
101110 connect (_pUi->actionRegisterSettings , &QAction::triggered, this , &MainWindow::handleShowRegisterDialog);
102111 connect (_pUi->actionAddNote , &QAction::triggered, this , &MainWindow::addNoteToGraph);
103- connect (_pUi->actionZoom , &QAction::triggered, this , &MainWindow::toggleZoom); /* Only called on GUI click, not on setChecked */
112+ connect (_pUi->actionZoom , &QAction::triggered, this ,
113+ &MainWindow::toggleZoom); /* Only called on GUI click, not on setChecked */
104114
105115 /* -- connect model to view --*/
106116 connect (_pGuiModel, &GuiModel::highlightSamplesChanged, this , &MainWindow::updateHighlightSampleMenu);
@@ -183,7 +193,8 @@ MainWindow::MainWindow(QStringList cmdArguments, GuiModel* pGuiModel,
183193 connect (_pUi->customPlot , &QCustomPlot::customContextMenuRequested, this , &MainWindow::showContextMenu);
184194
185195 /* handle focus change */
186- connect (dynamic_cast <QApplication*>(QApplication::instance ()), &QApplication::focusChanged, this , &MainWindow::appFocusChanged);
196+ connect (dynamic_cast <QApplication*>(QApplication::instance ()), &QApplication::focusChanged, this ,
197+ &MainWindow::appFocusChanged);
187198
188199 /* Update notes in data file when requested by notes model */
189200 connect (_pNoteModel, &NoteModel::dataFileUpdateRequested, this , &MainWindow::updateDataFileNotes);
@@ -201,7 +212,8 @@ MainWindow::MainWindow(QStringList cmdArguments, GuiModel* pGuiModel,
201212
202213 connect (_pGraphDataHandler, &GraphDataHandler::graphDataReady, _pGraphView, &GraphView::plotResults);
203214 connect (_pGraphDataHandler, &GraphDataHandler::graphDataReady, _pLegend, &Legend::addLastReceivedDataToLegend);
204- connect (_pGraphDataHandler, &GraphDataHandler::graphDataReady, _pCommunicationStats, &CommunicationStats::updateCommunicationStats);
215+ connect (_pGraphDataHandler, &GraphDataHandler::graphDataReady, _pCommunicationStats,
216+ &CommunicationStats::updateCommunicationStats);
205217
206218 handleCommandLineArguments (cmdArguments);
207219
@@ -220,7 +232,6 @@ MainWindow::MainWindow(QStringList cmdArguments, GuiModel* pGuiModel,
220232 //_pGraphDataModel->setActive(2, false);
221233
222234#endif
223-
224235}
225236
226237MainWindow::~MainWindow ()
@@ -259,17 +270,14 @@ void MainWindow::keyReleaseEvent(QKeyEvent* event)
259270 QMainWindow::keyReleaseEvent (event);
260271}
261272
262- void MainWindow::closeEvent (QCloseEvent * event)
273+ void MainWindow::closeEvent (QCloseEvent* event)
263274{
264- if (
265- (_pGuiModel->guiState () == GuiState::DATA_LOADED)
266- && (_pNoteModel->isNotesDataUpdated ())
267- )
275+ if ((_pGuiModel->guiState () == GuiState::DATA_LOADED) && (_pNoteModel->isNotesDataUpdated ()))
268276 {
269- QMessageBox::StandardButton resBtn = QMessageBox::question (this , windowTitle (),
270- tr ( " The notes are changed. \n Do you want discard the changes or update (save) the data file? \n " ),
271- QMessageBox::Cancel | QMessageBox::Discard | QMessageBox::Save ,
272- QMessageBox::Cancel);
277+ QMessageBox::StandardButton resBtn = QMessageBox::question (
278+ this , windowTitle ( ),
279+ tr ( " The notes are changed. \n Do you want discard the changes or update (save) the data file? \n " ) ,
280+ QMessageBox::Cancel | QMessageBox::Discard | QMessageBox::Save, QMessageBox::Cancel);
273281 if (resBtn == QMessageBox::Cancel)
274282 {
275283 event->ignore ();
@@ -307,8 +315,7 @@ void MainWindow::selectImageExportFile()
307315 const QPixmap pixMap = this ->window ()->grab ();
308316
309317 QFileDialog dialog (this );
310- FileSelectionHelper::configureFileDialog (&dialog,
311- FileSelectionHelper::DIALOG_TYPE_SAVE,
318+ FileSelectionHelper::configureFileDialog (&dialog, FileSelectionHelper::DIALOG_TYPE_SAVE,
312319 FileSelectionHelper::FILE_TYPE_PNG);
313320
314321 QString selectedFile = FileSelectionHelper::showDialog (&dialog);
@@ -345,7 +352,7 @@ void MainWindow::openUpdateUrl()
345352
346353void MainWindow::menuShowHideGraphClicked (bool bState)
347354{
348- QAction * pAction = qobject_cast<QAction *>(QObject::sender ());
355+ QAction* pAction = qobject_cast<QAction*>(QObject::sender ());
349356
350357 const qint32 graphIdx = _pGraphDataModel->convertToGraphIndex (pAction->data ().toInt ());
351358 _pGraphDataModel->setVisible (graphIdx, bState);
@@ -375,7 +382,10 @@ void MainWindow::showRegisterDialog()
375382 if (_pGuiModel->guiState () == GuiState::DATA_LOADED)
376383 {
377384 QMessageBox::StandardButton reply;
378- reply = QMessageBox::question (this , " Clear data?" , " An imported data file is loaded. Do you want to clear the data and start adding registers for a new log?" , QMessageBox::Yes|QMessageBox::No);
385+ reply = QMessageBox::question (
386+ this , " Clear data?" ,
387+ " An imported data file is loaded. Do you want to clear the data and start adding registers for a new log?" ,
388+ QMessageBox::Yes | QMessageBox::No);
379389 if (reply != QMessageBox::Yes)
380390 {
381391 return ;
@@ -394,9 +404,7 @@ void MainWindow::showRegisterDialog()
394404void MainWindow::addNoteToGraph ()
395405{
396406 bool ok;
397- QString text = QInputDialog::getText (this , tr (" Add note" ),
398- tr (" Note text:" ), QLineEdit::Normal,
399- " " , &ok);
407+ QString text = QInputDialog::getText (this , tr (" Add note" ), tr (" Note text:" ), QLineEdit::Normal, " " , &ok);
400408 if (ok)
401409 {
402410 Note newNote (text, _lastRightClickPos);
@@ -557,7 +565,7 @@ void MainWindow::handleGraphColorChange(const quint32 graphIdx)
557565 {
558566 const quint32 activeIdx = static_cast <quint32>(_pGraphDataModel->convertToActiveGraphIndex (graphIdx));
559567
560- QPixmap pixmap (20 ,5 );
568+ QPixmap pixmap (20 , 5 );
561569 pixmap.fill (_pGraphDataModel->color (graphIdx));
562570
563571 QIcon showHideIcon = QIcon (pixmap);
@@ -613,13 +621,13 @@ void MainWindow::rebuildGraphMenu()
613621 QList<quint16> activeGraphList;
614622 _pGraphDataModel->activeGraphIndexList (&activeGraphList);
615623
616- for (qint32 activeIdx = 0 ; activeIdx < activeGraphList.size (); activeIdx++)
624+ for (qint32 activeIdx = 0 ; activeIdx < activeGraphList.size (); activeIdx++)
617625 {
618626
619627 QString label = _pGraphDataModel->label (activeGraphList[activeIdx]);
620- QAction * pShowHideAction = _pGraphShowHide->addAction (label);
628+ QAction* pShowHideAction = _pGraphShowHide->addAction (label);
621629
622- QPixmap pixmap (20 ,5 );
630+ QPixmap pixmap (20 , 5 );
623631 pixmap.fill (_pGraphDataModel->color (activeGraphList[activeIdx]));
624632 QIcon icon = QIcon (pixmap);
625633
@@ -727,7 +735,7 @@ void MainWindow::updateGuiState()
727735 _pUi->actionSaveProjectFileAs ->setEnabled (false );
728736 _pUi->actionSaveProjectFile ->setEnabled (false );
729737 _pUi->actionExportImage ->setEnabled (true );
730- _pUi->actionClearData ->setEnabled (false );
738+ _pUi->actionClearData ->setEnabled (false );
731739 _pUi->actionReloadProjectFile ->setEnabled (false );
732740
733741 _pGuiModel->setWindowTitleDetail (QFileInfo (_pDataParserModel->dataFilePath ()).fileName ());
@@ -789,15 +797,15 @@ void MainWindow::showContextMenu(const QPoint& pos)
789797 }
790798}
791799
792- void MainWindow::dragEnterEvent (QDragEnterEvent * e)
800+ void MainWindow::dragEnterEvent (QDragEnterEvent* e)
793801{
794802 if (e->mimeData ()->hasUrls ())
795803 {
796804 e->acceptProposedAction ();
797805 }
798806}
799807
800- void MainWindow::dropEvent (QDropEvent * e)
808+ void MainWindow::dropEvent (QDropEvent* e)
801809{
802810 if (!_pModbusPoll->isActive ())
803811 {
@@ -806,7 +814,7 @@ void MainWindow::dropEvent(QDropEvent *e)
806814 }
807815}
808816
809- void MainWindow::appFocusChanged (QWidget * old, QWidget * now)
817+ void MainWindow::appFocusChanged (QWidget* old, QWidget* now)
810818{
811819 Q_UNUSED (now);
812820 if (old != nullptr )
@@ -849,8 +857,9 @@ void MainWindow::handleCommandLineArguments(QStringList cmdArguments)
849857 argumentParser.setApplicationDescription (" Log data through the Modbus protocol" );
850858 argumentParser.addHelpOption ();
851859
852- // Project file option
853- argumentParser.addPositionalArgument (" project file" , QCoreApplication::translate (" main" , " Project file (.mbs) to open" ));
860+ // Project file option
861+ argumentParser.addPositionalArgument (" project file" ,
862+ QCoreApplication::translate (" main" , " Project file (.mbs) to open" ));
854863
855864 // Process arguments
856865 argumentParser.process (cmdArguments);
@@ -882,4 +891,3 @@ void MainWindow::handleFileOpen(QString filename)
882891 _pDataFileHandler->openDataFile (filename);
883892 }
884893}
885-
0 commit comments