From 04e7a570e2aeed0d47299216fcedc46f174ab94a Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Sun, 5 Jul 2015 13:27:16 -0400 Subject: [PATCH] Update to make it easier to get the sub-windows to respond to changed preferences. Implemented seconds mode in flow view. --- filecomparatorwindow.cpp | 7 +++++-- filecomparatorwindow.h | 1 + flowviewwindow.cpp | 34 ++++++++++++++++++++++++++++------ flowviewwindow.h | 1 + frameinfowindow.cpp | 1 + frameplaybackwindow.cpp | 5 +++++ frameplaybackwindow.h | 3 ++- graphingwindow.cpp | 1 + mainwindow.cpp | 19 ++++++++++++++++++- mainwindow.h | 3 +++ serialworker.h | 2 +- 11 files changed, 66 insertions(+), 11 deletions(-) diff --git a/filecomparatorwindow.cpp b/filecomparatorwindow.cpp index cc225b0..c411923 100644 --- a/filecomparatorwindow.cpp +++ b/filecomparatorwindow.cpp @@ -9,8 +9,6 @@ FileComparatorWindow::FileComparatorWindow(QWidget *parent) : { ui->setupUi(this); - readSettings(); - connect(ui->btnFirstFile, SIGNAL(clicked(bool)), this, SLOT(loadFirstFile())); connect(ui->btnSecondFile, SIGNAL(clicked(bool)), this, SLOT(loadSecondFile())); connect(ui->btnSaveDetails, SIGNAL(clicked(bool)), this, SLOT(saveDetails())); @@ -24,6 +22,11 @@ FileComparatorWindow::~FileComparatorWindow() delete ui; } +void FileComparatorWindow::showEvent(QShowEvent *) +{ + readSettings(); +} + void FileComparatorWindow::closeEvent(QCloseEvent *event) { writeSettings(); diff --git a/filecomparatorwindow.h b/filecomparatorwindow.h index 5c94584..921ed00 100644 --- a/filecomparatorwindow.h +++ b/filecomparatorwindow.h @@ -41,6 +41,7 @@ private: QString secondFilename; void calculateDetails(); + void showEvent(QShowEvent *); void closeEvent(QCloseEvent *event); void readSettings(); void writeSettings(); diff --git a/flowviewwindow.cpp b/flowviewwindow.cpp index fed440e..92414c6 100644 --- a/flowviewwindow.cpp +++ b/flowviewwindow.cpp @@ -83,6 +83,9 @@ FlowViewWindow::FlowViewWindow(const QVector *frames, QWidget *parent) void FlowViewWindow::showEvent(QShowEvent* event) { QDialog::showEvent(event); + + readSettings(); + refreshIDList(); if (ui->listFrameID->count() > 0) { @@ -124,6 +127,8 @@ void FlowViewWindow::readSettings() { ui->cbTimeGraph->setChecked(true); } + + secondsMode = settings.value("Main/TimeSeconds", false).toBool(); } void FlowViewWindow::writeSettings() @@ -260,7 +265,13 @@ void FlowViewWindow::createGraph(int byteNum) if (graphByTime) { - x[j] = frameCache[j].timestamp; + if (secondsMode){ + x[j] = (double)(frameCache[j].timestamp) / 1000000.0; + } + else + { + x[j] = frameCache[j].timestamp; + } } else { @@ -487,11 +498,22 @@ void FlowViewWindow::updateGraphLocation() if (end >= frameCache.count()) end = frameCache.count() - 1; if (ui->cbTimeGraph->isChecked()) { - ui->graphView->xAxis->setRange(frameCache[start].timestamp, frameCache[end].timestamp); - ui->graphView->xAxis->setTickStep((frameCache[end].timestamp - frameCache[start].timestamp)/ 3.0); - ui->graphView->xAxis->setSubTickCount(0); - ui->graphView->xAxis->setNumberFormat("f"); - ui->graphView->xAxis->setNumberPrecision(0); + if (secondsMode) + { + ui->graphView->xAxis->setRange(frameCache[start].timestamp / 1000000.0, frameCache[end].timestamp / 1000000.0); + ui->graphView->xAxis->setTickStep((frameCache[end].timestamp - frameCache[start].timestamp)/ 3000000.0); + ui->graphView->xAxis->setSubTickCount(0); + ui->graphView->xAxis->setNumberFormat("f"); + ui->graphView->xAxis->setNumberPrecision(6); + } + else + { + ui->graphView->xAxis->setRange(frameCache[start].timestamp, frameCache[end].timestamp); + ui->graphView->xAxis->setTickStep((frameCache[end].timestamp - frameCache[start].timestamp)/ 3.0); + ui->graphView->xAxis->setSubTickCount(0); + ui->graphView->xAxis->setNumberFormat("f"); + ui->graphView->xAxis->setNumberPrecision(0); + } } else { diff --git a/flowviewwindow.h b/flowviewwindow.h index 3af01f3..9c71e76 100644 --- a/flowviewwindow.h +++ b/flowviewwindow.h @@ -46,6 +46,7 @@ private: bool playbackActive; bool playbackForward; static const QColor graphColors[8]; + bool secondsMode; void refreshIDList(); void updateFrameLabel(); diff --git a/frameinfowindow.cpp b/frameinfowindow.cpp index 47abe3a..62389d6 100644 --- a/frameinfowindow.cpp +++ b/frameinfowindow.cpp @@ -20,6 +20,7 @@ FrameInfoWindow::FrameInfoWindow(const QVector *frames, QWidget *paren void FrameInfoWindow::showEvent(QShowEvent* event) { QDialog::showEvent(event); + readSettings(); refreshIDList(); if (ui->listFrameID->count() > 0) { diff --git a/frameplaybackwindow.cpp b/frameplaybackwindow.cpp index ba9f1c6..00b466b 100644 --- a/frameplaybackwindow.cpp +++ b/frameplaybackwindow.cpp @@ -84,6 +84,11 @@ FramePlaybackWindow::~FramePlaybackWindow() delete playbackTimer; } +void FramePlaybackWindow::showEvent(QShowEvent *) +{ + readSettings(); +} + void FramePlaybackWindow::closeEvent(QCloseEvent *event) { writeSettings(); diff --git a/frameplaybackwindow.h b/frameplaybackwindow.h index 96f627d..bc33d7c 100644 --- a/frameplaybackwindow.h +++ b/frameplaybackwindow.h @@ -71,7 +71,8 @@ private: void refreshIDList(); void updateFrameLabel(); void updatePosition(bool forward); - void fillIDHash(SequenceItem &item); + void fillIDHash(SequenceItem &item); + void showEvent(QShowEvent *); void closeEvent(QCloseEvent *event); void readSettings(); void writeSettings(); diff --git a/graphingwindow.cpp b/graphingwindow.cpp index 8b9499a..a3e89cf 100644 --- a/graphingwindow.cpp +++ b/graphingwindow.cpp @@ -72,6 +72,7 @@ GraphingWindow::~GraphingWindow() void GraphingWindow::showEvent(QShowEvent* event) { QDialog::showEvent(event); + readSettings(); ui->graphingView->replot(); } diff --git a/mainwindow.cpp b/mainwindow.cpp index b78d929..ff0ad40 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -101,6 +101,7 @@ MainWindow::MainWindow(QWidget *parent) : connect(this, &MainWindow::closeSerialPort, worker, &SerialWorker::closeSerialPort, Qt::QueuedConnection); connect(this, &MainWindow::startFrameCapturing, worker, &SerialWorker::startFrameCapture); connect(this, &MainWindow::stopFrameCapturing, worker, &SerialWorker::stopFrameCapture); + connect(this, &MainWindow::settingsUpdated, worker, &SerialWorker::readSettings); serialWorkerThread.start(); serialWorkerThread.setPriority(QThread::HighPriority); @@ -237,6 +238,12 @@ void MainWindow::closeEvent(QCloseEvent *event) exitApp(); } +void MainWindow::updateSettings() +{ + readUpdateableSettings(); + emit settingsUpdated(); +} + void MainWindow::readSettings() { QSettings settings; @@ -249,6 +256,12 @@ void MainWindow::readSettings() { ui->cbAutoScroll->setChecked(true); } + readUpdateableSettings(); +} + +void MainWindow::readUpdateableSettings() +{ + QSettings settings; useHex = settings.value("Main/UseHex", true).toBool(); model->setHexMode(useHex); model->setSecondsMode(settings.value("Main/TimeSeconds", false).toBool()); @@ -770,7 +783,11 @@ void MainWindow::gotDeviceInfo(int build, int swCAN) void MainWindow::showSettingsDialog() { - if (!settingsDialog) settingsDialog = new MainSettingsDialog(); + if (!settingsDialog) + { + settingsDialog = new MainSettingsDialog(); + connect(settingsDialog, SIGNAL(finished(int)), this, SLOT(updateSettings())); + } settingsDialog->show(); } diff --git a/mainwindow.h b/mainwindow.h index 397171d..3e2efb5 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -69,6 +69,7 @@ private slots: public slots: void gotFrames(int, int); + void updateSettings(); signals: @@ -81,6 +82,7 @@ signals: //-1 = frames cleared, -2 = a new file has been loaded (so all frames are different), otherwise # of new frames void framesUpdated(int numFrames); //something has updated the frame list + void settingsUpdated(); private: Ui::MainWindow *ui; @@ -120,6 +122,7 @@ private: void updateFileStatus(); void closeEvent(QCloseEvent *event); void readSettings(); + void readUpdateableSettings(); void writeSettings(); }; diff --git a/serialworker.h b/serialworker.h index 531703d..3b61975 100644 --- a/serialworker.h +++ b/serialworker.h @@ -30,6 +30,7 @@ class SerialWorker : public QObject public: SerialWorker(CANFrameModel *model, QObject *parent = 0); ~SerialWorker(); + void readSettings(); signals: //we emit signals void error(const QString &); @@ -72,7 +73,6 @@ private: int deviceSingleWireMode; void procRXChar(unsigned char); - void readSettings(); }; #endif // SERIALTHREAD_H