-
Notifications
You must be signed in to change notification settings - Fork 1
/
beanpacketsloggerwindow.cpp
88 lines (74 loc) · 2.81 KB
/
beanpacketsloggerwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "beanpacketsloggerwindow.h"
#include "ui_beanpacketsloggerwindow.h"
#include "beanpacketsloggermodel.h"
#include "beanpacketsloggerheaderview.h"
#include <QFileDialog>
#include <QDebug>
#include <QCommonStyle>
BeanPacketsLoggerWindow::BeanPacketsLoggerWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::BeanPacketsLoggerWindow)
{
ui->setupUi(this);
QCommonStyle style;
ui->actionSaveAll->setIcon(style.standardIcon(QStyle::SP_DriveFDIcon));
ui->toolBar->setContextMenuPolicy(Qt::PreventContextMenu);
auto logTable = ui->tableLog;
logModel = new BeanPacketsLoggerModel();
logTable->setModel(logModel);
//BeanPacketsLoggerHeaderView *myHeader = new BeanPacketsLoggerHeaderView(Qt::Horizontal, ui->tableLog);
//ui->tableLog->setHorizontalHeader(myHeader);
QHeaderView *verticalHeader = logTable->verticalHeader();
verticalHeader->setSectionResizeMode(QHeaderView::Fixed);
verticalHeader->setDefaultSectionSize(24);
int columnWidth = 30;
logTable->setColumnWidth(0, 30); //checkboxes
logTable->setColumnWidth(1, columnWidth * 4); // time
logTable->setColumnWidth(2, columnWidth);
logTable->setColumnWidth(3, columnWidth);
logTable->setColumnWidth(4, columnWidth);
logTable->setColumnWidth(5, columnWidth * 5);
logTable->setColumnWidth(6, columnWidth);
logTable->setColumnWidth(7, columnWidth);
logTable->setColumnWidth(8, columnWidth * 20);
// ui->tableLog->setColumnWidth(8, columnWidth * 20)
logTable->setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
// //////////
ui->tableIds->setColumnCount(2);
ui->tableIds->setRowCount(2);
ui->tableIds->verticalHeader()->hide();
QStringList m_TableHeader;
m_TableHeader << "Dst" << "Msg" ;
ui->tableIds->setHorizontalHeaderLabels(m_TableHeader);
ui->tableIds->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
ui->tableIds->resizeColumnsToContents();
ui->tableIds->setColumnWidth(0, columnWidth*2);
ui->tableIds->setColumnWidth(1, columnWidth*2);
auto *cb = new QCheckBox;
cb->setText("TODO");
ui->tableIds->setCellWidget(1, 1, cb);
}
BeanPacketsLoggerWindow::~BeanPacketsLoggerWindow()
{
delete ui;
delete logModel;
}
void BeanPacketsLoggerWindow::appendPacket(BeanPacket *packet)
{
logModel->appendPacket(packet);
if (ui->cbAutoScroll->isChecked()) {
ui->tableLog->scrollToBottom();
}
}
void BeanPacketsLoggerWindow::on_pushButton_clicked()
{
logModel->clearPackets();
}
void BeanPacketsLoggerWindow::on_actionSaveAll_triggered()
{
QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),
QDir::homePath() + "/untitled.csv",
tr("Dumps (*.txt *.csv)"));
qDebug() << fileName;
logModel->saveAsCSV(fileName);
}