Skip to content

Commit

Permalink
It is now possible to save the flowview bitfield and the flowview gra…
Browse files Browse the repository at this point in the history
…ph to image files (right click)
  • Loading branch information
collin80 committed Jun 17, 2015
1 parent 4439a73 commit a802805
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 8 deletions.
22 changes: 22 additions & 0 deletions candatagrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,28 @@ void CANDataGrid::paintEvent(QPaintEvent *event)
gridSize.setY(ySector);
}

void CANDataGrid::saveImage(QString filename, int width, int height)
{
//can't quite do the below commented out stuff
//it works but doesn't scale the image into that pixmap. Need to
//figure out how to draw the size of the pixmap
/*
QSize pSize;
if (width == 0) pSize.setWidth(this->size().width());
else pSize.setWidth(width);
if (height == 0) pSize.setHeight(this->size().height());
else pSize.setHeight(height);
QPixmap pixmap(pSize);
*/
QPixmap pixmap(this->size());

this->render(&pixmap);
pixmap.save(filename); //QT will automatically pick the file format given the extension
}

void CANDataGrid::setReference(unsigned char *newRef, bool bUpdate = true)
{
memcpy(refData, newRef, 8);
Expand Down
1 change: 1 addition & 0 deletions candatagrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class CANDataGrid : public QWidget
void paintEvent(QPaintEvent *event);
void setReference(unsigned char *, bool);
void updateData(unsigned char *, bool);
void saveImage(QString filename, int width, int height);

protected:
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
Expand Down
73 changes: 73 additions & 0 deletions flowviewwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ FlowViewWindow::FlowViewWindow(QVector<CANFrame> *frames, QWidget *parent) :

connect(MainWindow::getReference(), SIGNAL(framesUpdated(int)), this, SLOT(updatedFrames(int)));

ui->graphView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->graphView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequestGraph(QPoint)));
ui->flowView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->flowView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequestFlow(QPoint)));

playbackTimer->setInterval(ui->spinPlayback->value()); //set the timer to the default value of the control

}
Expand All @@ -94,6 +99,74 @@ FlowViewWindow::~FlowViewWindow()
delete playbackTimer;
}

void FlowViewWindow::contextMenuRequestFlow(QPoint pos)
{
QMenu *menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose);

menu->addAction(tr("Save image to file"), this, SLOT(saveFileFlow()));

menu->popup(ui->flowView->mapToGlobal(pos));
}

void FlowViewWindow::contextMenuRequestGraph(QPoint pos)
{
QMenu *menu = new QMenu(this);
menu->setAttribute(Qt::WA_DeleteOnClose);

menu->addAction(tr("Save image to file"), this, SLOT(saveFileGraph()));

menu->popup(ui->graphView->mapToGlobal(pos));
}

void FlowViewWindow::saveFileGraph()
{
QString filename;
QFileDialog dialog(this);

QStringList filters;
filters.append(QString(tr("PDF Files (*.pdf)")));
filters.append(QString(tr("PNG Files (*.png)")));
filters.append(QString(tr("JPEG Files (*.jpg)")));

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]) ui->graphView->savePdf(filename, true, 0, 0);
if (dialog.selectedNameFilter() == filters[1]) ui->graphView->savePng(filename, 1024, 768);
if (dialog.selectedNameFilter() == filters[2]) ui->graphView->saveJpg(filename, 1024, 768);
}
}

void FlowViewWindow::saveFileFlow()
{
QString filename;
QFileDialog dialog(this);

QStringList filters;
filters.append(QString(tr("PNG Files (*.png)")));
filters.append(QString(tr("JPEG Files (*.jpg)")));

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]) ui->flowView->saveImage(filename, 1024, 768);
if (dialog.selectedNameFilter() == filters[1]) ui->flowView->saveImage(filename, 1024, 768);
}
}

void FlowViewWindow::updatedFrames(int numFrames)
{
if (numFrames == -1) //all frames deleted. Kill the display
Expand Down
6 changes: 5 additions & 1 deletion flowviewwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ private slots:
void changeLooping(bool check);
void timerTriggered();
void changeID(QString);
void updatedFrames(int);
void updatedFrames(int);
void contextMenuRequestFlow(QPoint pos);
void contextMenuRequestGraph(QPoint pos);
void saveFileFlow();
void saveFileGraph();

private:
Ui::FlowViewWindow *ui;
Expand Down
9 changes: 2 additions & 7 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,8 @@ Range state - Find things that range like accelerator pedal inputs, road speed,
fuzzy scope - Try to find potential places where a given value might be stored - offer guesses and the program tries to find candidates for you
Things currently broken or in need of attention:
1. Currently no screen supports dynamic updates when new frames come in.
2. Some of the save formats are not actually implemented and silently fail.
3. It would be nice to be able to save the graphing view in the flow view.
4. It would also be nice to be able to save an image of the bitfield grid too.
5. New GVRET firmware has a hard time sending data (6 frames per second!)
6. If you load a file, use detailed view, clear it, load another, it seems to only show new IDs
Things currently broken or in need of attention: (push these over to github issues as soon as you can)
1. If you load a file, use detailed view, clear it, load another, it seems to only show new IDs
*/

QString MainWindow::loadedFileName = "";
Expand Down

0 comments on commit a802805

Please sign in to comment.