New custom model that somewhat speeds up loading of canbus frame but it's still dog slow.

This commit is contained in:
Collin Kidder
2015-04-27 18:31:30 -04:00
parent 6fc8cf73c7
commit 1deff8af58
7 changed files with 164 additions and 53 deletions
+4 -2
View File
@@ -13,9 +13,11 @@ TEMPLATE = app
SOURCES += main.cpp\ SOURCES += main.cpp\
mainwindow.cpp mainwindow.cpp \
canframemodel.cpp
HEADERS += mainwindow.h \ HEADERS += mainwindow.h \
can_structs.h can_structs.h \
canframemodel.h
FORMS += mainwindow.ui FORMS += mainwindow.ui
+4 -4
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.4.0, 2015-04-26T23:13:45. --> <!-- Written by QtCreator 3.4.0, 2015-04-27T17:16:33. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
@@ -226,11 +226,11 @@
</valuelist> </valuelist>
<value type="int" key="PE.EnvironmentAspect.Base">2</value> <value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/> <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">ReverseCAN</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">SavvyCAN</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:C:/Users/Collin/Documents/ReverseCAN/ReverseCAN.pro</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:C:/Users/Collin/Documents/SavvyCAN/SavvyCAN.pro</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value> <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">ReverseCAN.pro</value> <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">SavvyCAN.pro</value>
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value> <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal">false</value> <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal">false</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value> <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value>
+111
View File
@@ -0,0 +1,111 @@
#include "canframemodel.h"
int CANFrameModel::rowCount(const QModelIndex &parent) const
{
return frames.count();
}
int CANFrameModel::columnCount(const QModelIndex &index) const
{
return 6;
}
CANFrameModel::CANFrameModel(QObject *parent)
: QAbstractTableModel(parent)
{
frames.reserve(100000); //ask for at least 100,000 entries. This gives good performance up to this limit
}
QVariant CANFrameModel::data(const QModelIndex &index, int role) const
{
QString tempString;
if (!index.isValid())
return QVariant();
if (index.row() >= frames.count())
return QVariant();
if (role == Qt::DisplayRole) {
CANFrame thisFrame = frames.at(index.row());
switch (index.column())
{
case 0: //timestamp
return QString::number(thisFrame.timestamp);
break;
case 1: //id
return QString::number(thisFrame.ID, 16);
break;
case 2: //ext
return QString::number(thisFrame.extended);
break;
case 3: //bus
return QString::number(thisFrame.bus);
break;
case 4: //len
return QString::number(thisFrame.len);
break;
case 5: //data
for (int i = 0; i < thisFrame.len; i++)
{
tempString.append(QString::number(thisFrame.data[i], 16));
tempString.append(" ");
}
return tempString;
break;
default:
return QVariant();
}
}
else
return QVariant();
}
QVariant CANFrameModel::headerData(int section, Qt::Orientation orientation,
int role) const
{
if (role != Qt::DisplayRole)
return QVariant();
if (orientation == Qt::Horizontal)
{
switch (section)
{
case 0:
return QString(tr("Timestamp"));
break;
case 1:
return QString(tr("ID"));
break;
case 2:
return QString(tr("Ext"));
break;
case 3:
return QString(tr("Bus"));
break;
case 4:
return QString(tr("Len"));
break;
case 5:
return QString(tr("Data"));
break;
}
}
else
return QString::number(section);
}
void CANFrameModel::addFrame(CANFrame &frame)
{
beginInsertRows(QModelIndex(), frames.count() + 1, frames.count() + 1);
frames.append(frame);
endInsertRows();
}
void CANFrameModel::clearFrames()
{
beginRemoveRows(QModelIndex(), 0, frames.count());
frames.clear();
endRemoveRows();
}
+31
View File
@@ -0,0 +1,31 @@
#ifndef CANFRAMEMODEL_H
#define CANFRAMEMODEL_H
#include <QAbstractTableModel>
#include <QList>
#include "can_structs.h"
class CANFrameModel: public QAbstractTableModel
{
Q_OBJECT
public:
CANFrameModel(QObject *parent = 0);
int rowCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
int CANFrameModel::columnCount(const QModelIndex &) const;
void addFrame(CANFrame &frame);
void clearFrames();
private:
QList<CANFrame> frames;
};
#endif // CANFRAMEMODEL_H
+5 -41
View File
@@ -3,43 +3,25 @@
#include "can_structs.h" #include "can_structs.h"
#include <QDateTime> #include <QDateTime>
#include <QFileDialog> #include <QFileDialog>
#include <QStandardItemModel> #include "canframemodel.h"
MainWindow::MainWindow(QWidget *parent) : MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
ui(new Ui::MainWindow) ui(new Ui::MainWindow)
{ {
ui->setupUi(this); ui->setupUi(this);
model = new QStandardItemModel(); model = new CANFrameModel();
ui->canFramesView->setModel(model); ui->canFramesView->setModel(model);
QStringList headers; QStringList headers;
headers << "Timestamp" << "ID" << "Ext" << "Bus" << "Len" << "Data"; headers << "Timestamp" << "ID" << "Ext" << "Bus" << "Len" << "Data";
model->setHorizontalHeaderLabels(headers); //model->setHorizontalHeaderLabels(headers);
ui->canFramesView->setColumnWidth(0, 110); ui->canFramesView->setColumnWidth(0, 110);
ui->canFramesView->setColumnWidth(1, 70); ui->canFramesView->setColumnWidth(1, 70);
ui->canFramesView->setColumnWidth(2, 40); ui->canFramesView->setColumnWidth(2, 40);
ui->canFramesView->setColumnWidth(3, 40); ui->canFramesView->setColumnWidth(3, 40);
ui->canFramesView->setColumnWidth(4, 40); ui->canFramesView->setColumnWidth(4, 40);
ui->canFramesView->setColumnWidth(5, 300); ui->canFramesView->setColumnWidth(5, 300);
/*
for (int row = 0; row < 4000; row++)
{
QStandardItem *item = new QStandardItem(QString("10000ms"));
model->setItem(row, 0, item);
item = new QStandardItem(QString("0x107"));
model->setItem(row, 1, item);
item = new QStandardItem(QString("F"));
model->setItem(row, 2, item);
item = new QStandardItem(QString("1"));
model->setItem(row, 3, item);
item = new QStandardItem(QString("8"));
model->setItem(row, 4, item);
item = new QStandardItem(QString("0x10 0xE0 0x10 0x30 0x40 0x50 0xFF 0x23"));
model->setItem(row, 5, item);
}
*/
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
@@ -47,27 +29,9 @@ MainWindow::~MainWindow()
delete ui; delete ui;
} }
void MainWindow::addFrameToDisplay(CANFrame frame) void MainWindow::addFrameToDisplay(CANFrame &frame)
{ {
int row = model->rowCount(); model->addFrame(frame);
QStandardItem *item = new QStandardItem(QString::number(frame.timestamp));
model->setItem(row, 0, item);
item = new QStandardItem(QString::number(frame.ID, 16));
model->setItem(row, 1, item);
item = new QStandardItem(QString::number(frame.extended));
model->setItem(row, 2, item);
item = new QStandardItem(QString::number(frame.bus));
model->setItem(row, 3, item);
item = new QStandardItem(QString::number(frame.len));
model->setItem(row, 4, item);
QString tempString;
for (int i = 0; i < frame.len; i++)
{
tempString.append(QString::number(frame.data[i], 16));
tempString.append(" ");
}
item = new QStandardItem(tempString);
model->setItem(row, 5, item);
} }
void MainWindow::loadCRTDFile(QString filename) void MainWindow::loadCRTDFile(QString filename)
+3 -3
View File
@@ -2,7 +2,7 @@
#define MAINWINDOW_H #define MAINWINDOW_H
#include <QMainWindow> #include <QMainWindow>
#include <QStandardItemModel> #include "canframemodel.h"
#include "can_structs.h" #include "can_structs.h"
namespace Ui { namespace Ui {
@@ -22,13 +22,13 @@ private slots:
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
QStandardItemModel *model; CANFrameModel *model;
void loadCRTDFile(QString); void loadCRTDFile(QString);
void loadNativeCSVFile(QString); void loadNativeCSVFile(QString);
void loadGenericCSVFile(QString); void loadGenericCSVFile(QString);
void loadLogFile(QString); void loadLogFile(QString);
void loadMicrochipFile(QString); void loadMicrochipFile(QString);
void addFrameToDisplay(CANFrame); void addFrameToDisplay(CANFrame &);
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H
+6 -3
View File
@@ -38,6 +38,9 @@
<property name="alternatingRowColors"> <property name="alternatingRowColors">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="wordWrap">
<bool>false</bool>
</property>
</widget> </widget>
</widget> </widget>
<widget class="QMenuBar" name="menuBar"> <widget class="QMenuBar" name="menuBar">
@@ -82,7 +85,7 @@
<enum>TopToolBarArea</enum> <enum>TopToolBarArea</enum>
</attribute> </attribute>
<attribute name="toolBarBreak"> <attribute name="toolBarBreak">
<bool>true</bool> <bool>false</bool>
</attribute> </attribute>
</widget> </widget>
<widget class="QStatusBar" name="statusBar"/> <widget class="QStatusBar" name="statusBar"/>
@@ -142,8 +145,8 @@
<slot>handleLoadFile()</slot> <slot>handleLoadFile()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>244</x> <x>-1</x>
<y>50</y> <y>-1</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>507</x> <x>507</x>