Saving of filtered frames now works. Also, saving and loading of main filter list is now implemented.
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
#include "canframemodel.h"
|
#include "canframemodel.h"
|
||||||
|
|
||||||
|
#include <QFile>
|
||||||
|
|
||||||
int CANFrameModel::rowCount(const QModelIndex &parent) const
|
int CANFrameModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
return filteredFrames.count();
|
return filteredFrames.count();
|
||||||
@@ -380,6 +382,53 @@ void CANFrameModel::insertFrames(const QVector<CANFrame> &newFrames)
|
|||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CANFrameModel::loadFilterFile(QString filename)
|
||||||
|
{
|
||||||
|
QFile *inFile = new QFile(filename);
|
||||||
|
QByteArray line;
|
||||||
|
int ID;
|
||||||
|
|
||||||
|
if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
|
return;
|
||||||
|
|
||||||
|
filters.clear();
|
||||||
|
|
||||||
|
while (!inFile->atEnd()) {
|
||||||
|
line = inFile->readLine().simplified();
|
||||||
|
if (line.length() > 2)
|
||||||
|
{
|
||||||
|
QList<QByteArray> tokens = line.split(',');
|
||||||
|
ID = tokens[0].toInt(NULL, 16);
|
||||||
|
if (tokens[1].toUpper() == "T") filters.insert(ID, true);
|
||||||
|
else filters.insert(ID, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
inFile->close();
|
||||||
|
|
||||||
|
sendRefresh();
|
||||||
|
|
||||||
|
emit updatedFiltersList();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CANFrameModel::saveFilterFile(QString filename)
|
||||||
|
{
|
||||||
|
QFile *outFile = new QFile(filename);
|
||||||
|
|
||||||
|
if (!outFile->open(QIODevice::WriteOnly | QIODevice::Text))
|
||||||
|
return;
|
||||||
|
|
||||||
|
QMap<int, bool>::const_iterator it;
|
||||||
|
for (it = filters.begin(); it != filters.end(); ++it)
|
||||||
|
{
|
||||||
|
outFile->write(QString::number(it.key(), 16).toUtf8());
|
||||||
|
outFile->putChar(',');
|
||||||
|
if (it.value()) outFile->putChar('T');
|
||||||
|
else outFile->putChar('F');
|
||||||
|
outFile->write("\n");
|
||||||
|
}
|
||||||
|
outFile->close();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*This used to not be const correct but it is now. So, there's little harm in
|
*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.
|
* allowing external code to peek at our frames. There's just no touching.
|
||||||
@@ -392,6 +441,11 @@ const QVector<CANFrame>* CANFrameModel::getListReference() const
|
|||||||
return &frames;
|
return &frames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QVector<CANFrame>* CANFrameModel::getFilteredListReference() const
|
||||||
|
{
|
||||||
|
return &filteredFrames;
|
||||||
|
}
|
||||||
|
|
||||||
const QMap<int, bool>* CANFrameModel::getFiltersReference() const
|
const QMap<int, bool>* CANFrameModel::getFiltersReference() const
|
||||||
{
|
{
|
||||||
return &filters;
|
return &filters;
|
||||||
|
|||||||
@@ -34,10 +34,13 @@ public:
|
|||||||
void setHexMode(bool);
|
void setHexMode(bool);
|
||||||
void setFilterState(int ID, bool state);
|
void setFilterState(int ID, bool state);
|
||||||
void setSecondsMode(bool);
|
void setSecondsMode(bool);
|
||||||
|
void loadFilterFile(QString filename);
|
||||||
|
void saveFilterFile(QString filename);
|
||||||
void normalizeTiming();
|
void normalizeTiming();
|
||||||
void recalcOverwrite();
|
void recalcOverwrite();
|
||||||
void insertFrames(const QVector<CANFrame> &newFrames);
|
void insertFrames(const QVector<CANFrame> &newFrames);
|
||||||
const QVector<CANFrame> *getListReference() const; //thou shalt not modify these frames externally!
|
const QVector<CANFrame> *getListReference() const; //thou shalt not modify these frames externally!
|
||||||
|
const QVector<CANFrame> *getFilteredListReference() const; //Thus saith the Lord, NO.
|
||||||
const QMap<int, bool> *getFiltersReference() const; //this neither
|
const QMap<int, bool> *getFiltersReference() const; //this neither
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|||||||
@@ -123,6 +123,9 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
connect(ui->actionFrame_Data_Analysis, SIGNAL(triggered(bool)), this, SLOT(showFrameDataAnalysis()));
|
connect(ui->actionFrame_Data_Analysis, SIGNAL(triggered(bool)), this, SLOT(showFrameDataAnalysis()));
|
||||||
connect(ui->btnClearFrames, SIGNAL(clicked(bool)), this, SLOT(clearFrames()));
|
connect(ui->btnClearFrames, SIGNAL(clicked(bool)), this, SLOT(clearFrames()));
|
||||||
connect(ui->actionSave_Log_File, SIGNAL(triggered(bool)), this, SLOT(handleSaveFile()));
|
connect(ui->actionSave_Log_File, SIGNAL(triggered(bool)), this, SLOT(handleSaveFile()));
|
||||||
|
connect(ui->actionSave_Filtered_Log_File, SIGNAL(triggered(bool)), this, SLOT(handleSaveFilteredFile()));
|
||||||
|
connect(ui->actionLoad_Filter_Definition, SIGNAL(triggered(bool)), this, SLOT(handleLoadFilters()));
|
||||||
|
connect(ui->actionSave_Filter_Definition, SIGNAL(triggered(bool)), this, SLOT(handleSaveFilters()));
|
||||||
connect(ui->action_Playback, SIGNAL(triggered(bool)), this, SLOT(showPlaybackWindow()));
|
connect(ui->action_Playback, SIGNAL(triggered(bool)), this, SLOT(showPlaybackWindow()));
|
||||||
connect(ui->btnBaudSet, SIGNAL(clicked(bool)), this, SLOT(changeBaudRates()));
|
connect(ui->btnBaudSet, SIGNAL(clicked(bool)), this, SLOT(changeBaudRates()));
|
||||||
connect(ui->actionFlow_View, SIGNAL(triggered(bool)), this, SLOT(showFlowViewWindow()));
|
connect(ui->actionFlow_View, SIGNAL(triggered(bool)), this, SLOT(showFlowViewWindow()));
|
||||||
@@ -451,6 +454,83 @@ void MainWindow::handleSaveFile()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::handleSaveFilteredFile()
|
||||||
|
{
|
||||||
|
QString filename;
|
||||||
|
QFileDialog dialog(this);
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
QStringList filters;
|
||||||
|
filters.append(QString(tr("CRTD Logs (*.txt)")));
|
||||||
|
filters.append(QString(tr("GVRET Logs (*.csv)")));
|
||||||
|
filters.append(QString(tr("Generic ID/Data CSV (*.csv)")));
|
||||||
|
filters.append(QString(tr("BusMaster Log (*.log)")));
|
||||||
|
filters.append(QString(tr("Microchip Log (*.log)")));
|
||||||
|
|
||||||
|
dialog.setFileMode(QFileDialog::AnyFile);
|
||||||
|
dialog.setNameFilters(filters);
|
||||||
|
dialog.setViewMode(QFileDialog::Detail);
|
||||||
|
dialog.setAcceptMode(QFileDialog::AcceptSave);
|
||||||
|
|
||||||
|
if (dialog.exec() == QDialog::Accepted)
|
||||||
|
{
|
||||||
|
const QVector<CANFrame> *frames = model->getFilteredListReference();
|
||||||
|
filename = dialog.selectedFiles()[0];
|
||||||
|
if (dialog.selectedNameFilter() == filters[0]) result = FrameFileIO::saveCRTDFile(filename, frames);
|
||||||
|
if (dialog.selectedNameFilter() == filters[1]) result = FrameFileIO::saveNativeCSVFile(filename, frames);
|
||||||
|
if (dialog.selectedNameFilter() == filters[2]) result = FrameFileIO::saveGenericCSVFile(filename, frames);
|
||||||
|
if (dialog.selectedNameFilter() == filters[3]) result = FrameFileIO::saveLogFile(filename, frames);
|
||||||
|
if (dialog.selectedNameFilter() == filters[4]) result = FrameFileIO::saveMicrochipFile(filename, frames);
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
QStringList fileList = filename.split('/');
|
||||||
|
loadedFileName = fileList[fileList.length() - 1];
|
||||||
|
updateFileStatus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::handleSaveFilters()
|
||||||
|
{
|
||||||
|
QString filename;
|
||||||
|
QFileDialog dialog(this);
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
QStringList filters;
|
||||||
|
filters.append(QString(tr("Filter list (*.ftl)")));
|
||||||
|
|
||||||
|
dialog.setFileMode(QFileDialog::AnyFile);
|
||||||
|
dialog.setNameFilters(filters);
|
||||||
|
dialog.setViewMode(QFileDialog::Detail);
|
||||||
|
dialog.setAcceptMode(QFileDialog::AcceptSave);
|
||||||
|
|
||||||
|
if (dialog.exec() == QDialog::Accepted)
|
||||||
|
{
|
||||||
|
filename = dialog.selectedFiles()[0];
|
||||||
|
if (dialog.selectedNameFilter() == filters[0]) model->saveFilterFile(filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::handleLoadFilters()
|
||||||
|
{
|
||||||
|
QString filename;
|
||||||
|
QFileDialog dialog(this);
|
||||||
|
|
||||||
|
QStringList filters;
|
||||||
|
filters.append(QString(tr("Filter List (*.ftl)")));
|
||||||
|
|
||||||
|
dialog.setFileMode(QFileDialog::ExistingFile);
|
||||||
|
dialog.setNameFilters(filters);
|
||||||
|
dialog.setViewMode(QFileDialog::Detail);
|
||||||
|
|
||||||
|
if (dialog.exec() == QDialog::Accepted)
|
||||||
|
{
|
||||||
|
filename = dialog.selectedFiles()[0];
|
||||||
|
//right now there is only one file type that can be loaded here so just do it.
|
||||||
|
model->loadFilterFile(filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::handleLoadDBC()
|
void MainWindow::handleLoadDBC()
|
||||||
{
|
{
|
||||||
QString filename;
|
QString filename;
|
||||||
|
|||||||
@@ -35,8 +35,11 @@ public:
|
|||||||
private slots:
|
private slots:
|
||||||
void handleLoadFile();
|
void handleLoadFile();
|
||||||
void handleSaveFile();
|
void handleSaveFile();
|
||||||
|
void handleSaveFilteredFile();
|
||||||
void handleLoadDBC();
|
void handleLoadDBC();
|
||||||
void handleSaveDBC();
|
void handleSaveDBC();
|
||||||
|
void handleSaveFilters();
|
||||||
|
void handleLoadFilters();
|
||||||
void connButtonPress();
|
void connButtonPress();
|
||||||
void showGraphingWindow();
|
void showGraphingWindow();
|
||||||
void showFrameDataAnalysis();
|
void showFrameDataAnalysis();
|
||||||
|
|||||||
Reference in New Issue
Block a user