Fix to make access of canbus frames const correct. It's now not really possible to modify the captured canbus frames from outside the model class that holds them. This is safer and more future proof.
Boring update but it might save head scratching in the future.
This commit is contained in:
+23
-7
@@ -260,13 +260,29 @@ void CANFrameModel::clearFrames()
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
//Is this safe? Maybe not but if we don't change it then that's OK
|
||||
//Is it the best C++ practice? Probably not. This breaks the MVC paradigm
|
||||
//but, it's for a good cause.
|
||||
//Implement proper "const"ness for this function. No one should be
|
||||
//adding frames via this reference. Unfortunately, I've done just that in
|
||||
//places like the file loading code.
|
||||
QVector<CANFrame>* CANFrameModel::getListReference()
|
||||
/*
|
||||
* Since the getListReference function returns readonly
|
||||
* you can't insert frames with it. Instead this function
|
||||
* allows for a mass import of frames into the model
|
||||
*/
|
||||
void CANFrameModel::insertFrames(const QVector<CANFrame> &newFrames)
|
||||
{
|
||||
beginInsertRows(QModelIndex(), frames.count() + 1, frames.count() + newFrames.count());
|
||||
for (int i = 0; i < newFrames.count(); i++)
|
||||
{
|
||||
frames.append(newFrames[i]);
|
||||
}
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
/*
|
||||
*This used to not be const correct but it is now. So, there's little harm in
|
||||
* allowing external code to peek at our frames. There's just no touching.
|
||||
* This ability to get a direct read-only reference speeds up a variety of
|
||||
* external code that needs to access frames directly and doesn't care about
|
||||
* this model's normal output mechanism.
|
||||
*/
|
||||
const QVector<CANFrame>* CANFrameModel::getListReference() const
|
||||
{
|
||||
return &frames;
|
||||
}
|
||||
|
||||
+2
-1
@@ -31,7 +31,8 @@ public:
|
||||
void setOverwriteMode(bool);
|
||||
void normalizeTiming();
|
||||
void recalcOverwrite();
|
||||
QVector<CANFrame> *getListReference();
|
||||
void insertFrames(const QVector<CANFrame> &newFrames);
|
||||
const QVector<CANFrame> *getListReference() const; //thou shalt not modify these frames externally!
|
||||
|
||||
|
||||
private:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef CONFIG
|
||||
#define CONFIG
|
||||
|
||||
#define VERSION 114
|
||||
#define VERSION 115
|
||||
|
||||
#endif // CONFIG
|
||||
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ const QColor FlowViewWindow::graphColors[8] = {Qt::blue, Qt::green, Qt::black, Q
|
||||
Qt::gray, Qt::yellow, Qt::cyan, Qt::darkMagenta}; //4 5 6 7
|
||||
|
||||
|
||||
FlowViewWindow::FlowViewWindow(QVector<CANFrame> *frames, QWidget *parent) :
|
||||
FlowViewWindow::FlowViewWindow(const QVector<CANFrame> *frames, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::FlowViewWindow)
|
||||
{
|
||||
|
||||
+2
-2
@@ -13,7 +13,7 @@ class FlowViewWindow : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit FlowViewWindow(QVector<CANFrame> *frames, QWidget *parent = 0);
|
||||
explicit FlowViewWindow(const QVector<CANFrame> *frames, QWidget *parent = 0);
|
||||
~FlowViewWindow();
|
||||
void showEvent(QShowEvent*);
|
||||
|
||||
@@ -38,7 +38,7 @@ private:
|
||||
Ui::FlowViewWindow *ui;
|
||||
QList<int> foundID;
|
||||
QList<CANFrame> frameCache;
|
||||
QVector<CANFrame> *modelFrames;
|
||||
const QVector<CANFrame> *modelFrames;
|
||||
unsigned char refBytes[8];
|
||||
unsigned char currBytes[8];
|
||||
int currentPosition;
|
||||
|
||||
+5
-5
@@ -117,7 +117,7 @@ bool FrameFileIO::loadCRTDFile(QString filename, QVector<CANFrame>* frames)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FrameFileIO::saveCRTDFile(QString filename, QVector<CANFrame>* frames)
|
||||
bool FrameFileIO::saveCRTDFile(QString filename, const QVector<CANFrame>* frames)
|
||||
{
|
||||
QFile *outFile = new QFile(filename);
|
||||
|
||||
@@ -197,7 +197,7 @@ bool FrameFileIO::loadNativeCSVFile(QString filename, QVector<CANFrame>* frames)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FrameFileIO::saveNativeCSVFile(QString filename, QVector<CANFrame>* frames)
|
||||
bool FrameFileIO::saveNativeCSVFile(QString filename, const QVector<CANFrame>* frames)
|
||||
{
|
||||
QFile *outFile = new QFile(filename);
|
||||
|
||||
@@ -273,7 +273,7 @@ bool FrameFileIO::loadGenericCSVFile(QString filename, QVector<CANFrame>* frames
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FrameFileIO::saveGenericCSVFile(QString filename, QVector<CANFrame>* frames)
|
||||
bool FrameFileIO::saveGenericCSVFile(QString filename, const QVector<CANFrame>* frames)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -345,7 +345,7 @@ bool FrameFileIO::loadLogFile(QString filename, QVector<CANFrame>* frames)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FrameFileIO::saveLogFile(QString filename, QVector<CANFrame>* frames)
|
||||
bool FrameFileIO::saveLogFile(QString filename, const QVector<CANFrame>* frames)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -403,7 +403,7 @@ bool FrameFileIO::loadMicrochipFile(QString filename, QVector<CANFrame>* frames)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FrameFileIO::saveMicrochipFile(QString filename, QVector<CANFrame>* frames)
|
||||
bool FrameFileIO::saveMicrochipFile(QString filename, const QVector<CANFrame>* frames)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
+5
-5
@@ -26,11 +26,11 @@ public:
|
||||
static bool loadGenericCSVFile(QString, QVector<CANFrame>*);
|
||||
static bool loadLogFile(QString, QVector<CANFrame>*);
|
||||
static bool loadMicrochipFile(QString, QVector<CANFrame>*);
|
||||
static bool saveCRTDFile(QString, QVector<CANFrame>*);
|
||||
static bool saveNativeCSVFile(QString, QVector<CANFrame>*);
|
||||
static bool saveGenericCSVFile(QString, QVector<CANFrame>*);
|
||||
static bool saveLogFile(QString, QVector<CANFrame>*);
|
||||
static bool saveMicrochipFile(QString, QVector<CANFrame>*);
|
||||
static bool saveCRTDFile(QString, const QVector<CANFrame>*);
|
||||
static bool saveNativeCSVFile(QString, const QVector<CANFrame>*);
|
||||
static bool saveGenericCSVFile(QString, const QVector<CANFrame>*);
|
||||
static bool saveLogFile(QString, const QVector<CANFrame>*);
|
||||
static bool saveMicrochipFile(QString, const QVector<CANFrame>*);
|
||||
static QString loadFrameFile(QVector<CANFrame>*);
|
||||
};
|
||||
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
#include "mainwindow.h"
|
||||
#include <QtDebug>
|
||||
|
||||
FrameInfoWindow::FrameInfoWindow(QVector<CANFrame> *frames, QWidget *parent) :
|
||||
FrameInfoWindow::FrameInfoWindow(const QVector<CANFrame> *frames, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::FrameInfoWindow)
|
||||
{
|
||||
|
||||
+2
-2
@@ -14,7 +14,7 @@ class FrameInfoWindow : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit FrameInfoWindow(QVector<CANFrame> *frames, QWidget *parent = 0);
|
||||
explicit FrameInfoWindow(const QVector<CANFrame> *frames, QWidget *parent = 0);
|
||||
~FrameInfoWindow();
|
||||
void showEvent(QShowEvent*);
|
||||
|
||||
@@ -27,7 +27,7 @@ private:
|
||||
|
||||
QList<int> foundID;
|
||||
QList<CANFrame> frameCache;
|
||||
QVector<CANFrame> *modelFrames;
|
||||
const QVector<CANFrame> *modelFrames;
|
||||
|
||||
void refreshIDList();
|
||||
};
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
FramePlaybackWindow::FramePlaybackWindow(QVector<CANFrame> *frames, SerialWorker *worker, QWidget *parent) :
|
||||
FramePlaybackWindow::FramePlaybackWindow(const QVector<CANFrame> *frames, SerialWorker *worker, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::FramePlaybackWindow)
|
||||
{
|
||||
|
||||
@@ -27,7 +27,7 @@ class FramePlaybackWindow : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit FramePlaybackWindow(QVector<CANFrame> *frames, SerialWorker *worker, QWidget *parent = 0);
|
||||
explicit FramePlaybackWindow(const QVector<CANFrame> *frames, SerialWorker *worker, QWidget *parent = 0);
|
||||
~FramePlaybackWindow();
|
||||
|
||||
private slots:
|
||||
@@ -57,7 +57,7 @@ private:
|
||||
Ui::FramePlaybackWindow *ui;
|
||||
QList<int> foundID;
|
||||
QList<CANFrame> frameCache;
|
||||
QVector<CANFrame> *modelFrames;
|
||||
const QVector<CANFrame> *modelFrames;
|
||||
int currentPosition;
|
||||
QTimer *playbackTimer;
|
||||
SerialWorker *serialWorker;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "ui_framesenderwindow.h"
|
||||
#include "utility.h"
|
||||
|
||||
FrameSenderWindow::FrameSenderWindow(QVector<CANFrame> *frames, QWidget *parent) :
|
||||
FrameSenderWindow::FrameSenderWindow(const QVector<CANFrame> *frames, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::FrameSenderWindow)
|
||||
{
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@ class FrameSenderWindow : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit FrameSenderWindow(QVector<CANFrame> *frames, QWidget *parent = 0);
|
||||
explicit FrameSenderWindow(const QVector<CANFrame> *frames, QWidget *parent = 0);
|
||||
~FrameSenderWindow();
|
||||
|
||||
private slots:
|
||||
@@ -26,7 +26,7 @@ private:
|
||||
Ui::FrameSenderWindow *ui;
|
||||
QList<FrameSendData> sendingData;
|
||||
QList<CANFrame> frameCache;
|
||||
QVector<CANFrame> *modelFrames;
|
||||
const QVector<CANFrame> *modelFrames;
|
||||
QTimer *intervalTimer;
|
||||
|
||||
void doModifiers(int);
|
||||
|
||||
+3
-3
@@ -4,7 +4,7 @@
|
||||
#include "mainwindow.h"
|
||||
#include <QDebug>
|
||||
|
||||
GraphingWindow::GraphingWindow(QVector<CANFrame> *frames, QWidget *parent) :
|
||||
GraphingWindow::GraphingWindow(const QVector<CANFrame> *frames, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::GraphingWindow)
|
||||
{
|
||||
@@ -344,8 +344,8 @@ void GraphingWindow::addNewGraph()
|
||||
void GraphingWindow::createGraph(GraphParams ¶ms, bool createGraphParam)
|
||||
{
|
||||
int tempVal;
|
||||
float yminval=10000000, ymaxval = -1000000;
|
||||
float xminval=100000000000, xmaxval = -100000000000;
|
||||
float yminval=10000000.0, ymaxval = -1000000.0;
|
||||
float xminval=10000000000.0, xmaxval = -10000000000.0;
|
||||
|
||||
qDebug() << "New Graph ID: " << params.ID;
|
||||
qDebug() << "Start byte: " << params.startByte;
|
||||
|
||||
+2
-2
@@ -29,7 +29,7 @@ class GraphingWindow : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit GraphingWindow(QVector<CANFrame> *, QWidget *parent = 0);
|
||||
explicit GraphingWindow(const QVector<CANFrame> *, QWidget *parent = 0);
|
||||
~GraphingWindow();
|
||||
void showEvent(QShowEvent*);
|
||||
|
||||
@@ -53,7 +53,7 @@ private slots:
|
||||
private:
|
||||
Ui::GraphingWindow *ui;
|
||||
QList<CANFrame> frameCache;
|
||||
QVector<CANFrame> *modelFrames;
|
||||
const QVector<CANFrame> *modelFrames;
|
||||
QList<GraphParams> graphParams;
|
||||
QPen selectedPen;
|
||||
bool needScaleSetup; //do we need to set x,y graphing extents?s
|
||||
|
||||
+11
-8
@@ -307,18 +307,21 @@ void MainWindow::handleLoadFile()
|
||||
ui->canFramesView->scrollToTop();
|
||||
model->clearFrames();
|
||||
|
||||
if (dialog.selectedNameFilter() == filters[0]) result = FrameFileIO::loadCRTDFile(filename, model->getListReference());
|
||||
if (dialog.selectedNameFilter() == filters[1]) result = FrameFileIO::loadNativeCSVFile(filename, model->getListReference());
|
||||
if (dialog.selectedNameFilter() == filters[2]) result = FrameFileIO::loadGenericCSVFile(filename, model->getListReference());
|
||||
if (dialog.selectedNameFilter() == filters[3]) result = FrameFileIO::loadLogFile(filename, model->getListReference());
|
||||
if (dialog.selectedNameFilter() == filters[4]) result = FrameFileIO::loadMicrochipFile(filename, model->getListReference());
|
||||
QVector<CANFrame> tempFrames;
|
||||
|
||||
if (dialog.selectedNameFilter() == filters[0]) result = FrameFileIO::loadCRTDFile(filename, &tempFrames);
|
||||
if (dialog.selectedNameFilter() == filters[1]) result = FrameFileIO::loadNativeCSVFile(filename, &tempFrames);
|
||||
if (dialog.selectedNameFilter() == filters[2]) result = FrameFileIO::loadGenericCSVFile(filename, &tempFrames);
|
||||
if (dialog.selectedNameFilter() == filters[3]) result = FrameFileIO::loadLogFile(filename, &tempFrames);
|
||||
if (dialog.selectedNameFilter() == filters[4]) result = FrameFileIO::loadMicrochipFile(filename, &tempFrames);
|
||||
if (result)
|
||||
{
|
||||
model->insertFrames(tempFrames);
|
||||
|
||||
QStringList fileList = filename.split('/');
|
||||
loadedFileName = fileList[fileList.length() - 1];
|
||||
|
||||
model->recalcOverwrite();
|
||||
model->sendRefresh();
|
||||
ui->lbNumFrames->setText(QString::number(model->rowCount()));
|
||||
if (ui->cbAutoScroll->isChecked()) ui->canFramesView->scrollToBottom();
|
||||
|
||||
@@ -348,7 +351,7 @@ void MainWindow::handleSaveFile()
|
||||
|
||||
if (dialog.exec() == QDialog::Accepted)
|
||||
{
|
||||
QVector<CANFrame> *frames = model->getListReference();
|
||||
const QVector<CANFrame> *frames = model->getListReference();
|
||||
filename = dialog.selectedFiles()[0];
|
||||
if (dialog.selectedNameFilter() == filters[0]) result = FrameFileIO::saveCRTDFile(filename, frames);
|
||||
if (dialog.selectedNameFilter() == filters[1]) result = FrameFileIO::saveNativeCSVFile(filename, frames);
|
||||
@@ -433,7 +436,7 @@ void MainWindow::handleSaveDecoded()
|
||||
void MainWindow::saveDecodedTextFile(QString filename)
|
||||
{
|
||||
QFile *outFile = new QFile(filename);
|
||||
QVector<CANFrame> *frames = model->getListReference();
|
||||
const QVector<CANFrame> *frames = model->getListReference();
|
||||
|
||||
if (!outFile->open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user