From 1e04e5fb31154ff8fc62b16d1b16ef3365548d6f Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Sun, 3 Jan 2016 18:37:58 -0500 Subject: [PATCH] Added the ability to save all frame details within the details screen to file. --- frameinfowindow.cpp | 62 +++++++++++++++++++++++++++++-- frameinfowindow.h | 4 ++ frameinfowindow.ui | 89 +++++++++++++++++++++++++-------------------- 3 files changed, 113 insertions(+), 42 deletions(-) diff --git a/frameinfowindow.cpp b/frameinfowindow.cpp index cc56a25..2c25331 100644 --- a/frameinfowindow.cpp +++ b/frameinfowindow.cpp @@ -13,8 +13,10 @@ FrameInfoWindow::FrameInfoWindow(const QVector *frames, QWidget *paren modelFrames = frames; - connect(ui->listFrameID, SIGNAL(currentTextChanged(QString)), this, SLOT(updateDetailsWindow(QString))); - connect(MainWindow::getReference(), SIGNAL(framesUpdated(int)), this, SLOT(updatedFrames(int))); + connect(ui->listFrameID, &QListWidget::currentTextChanged, this, &FrameInfoWindow::updateDetailsWindow); + connect(MainWindow::getReference(), &MainWindow::framesUpdated, this, &FrameInfoWindow::updatedFrames); + connect(ui->btnSave, &QAbstractButton::clicked, this, &FrameInfoWindow::saveDetails); + } void FrameInfoWindow::showEvent(QShowEvent* event) @@ -230,7 +232,9 @@ void FrameInfoWindow::updateDetailsWindow(QString newID) } } - avgInterval = avgInterval / (frameCache.count() - 1); + if (frameCache.count() > 1) + avgInterval = avgInterval / (frameCache.count() - 1); + else avgInterval = 0; tempItem = new QTreeWidgetItem(); @@ -317,3 +321,55 @@ void FrameInfoWindow::refreshIDList() ui->listFrameID->sortItems(); ui->lblFrameID->setText(tr("Frame IDs: (") + QString::number(ui->listFrameID->count()) + tr(" unique ids)")); } + +void FrameInfoWindow::saveDetails() +{ + QString filename; + QFileDialog dialog(this); + + QStringList filters; + filters.append(QString(tr("Text File (*.txt)"))); + + 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 (!filename.contains('.')) filename += ".txt"; + if (dialog.selectedNameFilter() == filters[0]) + { + QFile *outFile = new QFile(filename); + + if (!outFile->open(QIODevice::WriteOnly | QIODevice::Text)) + { + delete outFile; + return; + } + + //go through all IDs, recalculate the data, and then save it to file + for (int i = 0; i < ui->listFrameID->count(); i++) + { + updateDetailsWindow(ui->listFrameID->item(i)->text()); + dumpNode(ui->treeDetails->invisibleRootItem(), outFile, 0); + outFile->write("\n\n"); + } + + outFile->close(); + delete outFile; + } + } +} + +void FrameInfoWindow::dumpNode(QTreeWidgetItem* item, QFile *file, int indent) +{ + for (int i = 0; i < indent; i++) file->write("\t"); + file->write(item->text(0).toUtf8()); + file->write("\n"); + for( int i = 0; i < item->childCount(); ++i ) + dumpNode( item->child(i), file, indent + 1 ); +} + + diff --git a/frameinfowindow.h b/frameinfowindow.h index c22a7db..dc3ac57 100644 --- a/frameinfowindow.h +++ b/frameinfowindow.h @@ -2,7 +2,9 @@ #define FRAMEINFOWINDOW_H #include +#include #include +#include #include "can_structs.h" namespace Ui { @@ -21,6 +23,7 @@ public: private slots: void updateDetailsWindow(QString); void updatedFrames(int); + void saveDetails(); private: Ui::FrameInfoWindow *ui; @@ -33,6 +36,7 @@ private: void closeEvent(QCloseEvent *event); void readSettings(); void writeSettings(); + void dumpNode(QTreeWidgetItem* item, QFile *file, int indent); }; #endif // FRAMEINFOWINDOW_H diff --git a/frameinfowindow.ui b/frameinfowindow.ui index e8c5e6c..2b82ef0 100644 --- a/frameinfowindow.ui +++ b/frameinfowindow.ui @@ -13,53 +13,64 @@ Detailed Frame Information - + - + - - - Frame IDs: - - + + + + + Frame IDs: + + + + + + + + 0 + 0 + + + + + 120 + 0 + + + + + - - - - 0 - 0 - - - - - 120 - 0 - - - + + + + + Details: + + + + + + + + 1 + + + + + - - - - - Details: - - - - - - - - 1 - - - - - + + + Save details to file + +