Saving of filtered frames now works. Also, saving and loading of main filter list is now implemented.

This commit is contained in:
Collin Kidder
2015-06-29 22:50:53 -04:00
parent 65656b185b
commit 46a25cc1e5
4 changed files with 140 additions and 0 deletions
+54
View File
@@ -1,5 +1,7 @@
#include "canframemodel.h"
#include <QFile>
int CANFrameModel::rowCount(const QModelIndex &parent) const
{
return filteredFrames.count();
@@ -380,6 +382,53 @@ void CANFrameModel::insertFrames(const QVector<CANFrame> &newFrames)
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
* 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;
}
const QVector<CANFrame>* CANFrameModel::getFilteredListReference() const
{
return &filteredFrames;
}
const QMap<int, bool>* CANFrameModel::getFiltersReference() const
{
return &filters;