Skip to content

Commit

Permalink
Move export PNG in tool bar to have better text control display
Browse files Browse the repository at this point in the history
  • Loading branch information
glt248 committed Nov 22, 2019
1 parent 5fd5021 commit e320b22
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
16 changes: 11 additions & 5 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "mainwindow.hpp"
#include "ui_mainwindow.h"
#include <x86intrin.h>
#include <cstdio>

/**
* @brief Constructor
Expand Down Expand Up @@ -125,7 +124,6 @@ void MainWindow::createUI()
{
enable_com_controls (false);
ui->statusBar->showMessage ("No ports detected.");
ui->savePNGButton->setEnabled(false);
return;
}

Expand Down Expand Up @@ -182,6 +180,9 @@ void MainWindow::createUI()
ui->spinYStep->setValue(m_prefs.spinYStep);
ui->spinAxesMin->setValue(m_prefs.spinAxesMin);
ui->spinAxesMax->setValue(m_prefs.spinAxesMax);

// disable PNG export before starting record
ui->actionRecord_PNG->setEnabled(false);
}
/** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

Expand Down Expand Up @@ -559,9 +560,9 @@ void MainWindow::on_spinYStep_valueChanged(int arg1)
/** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

/**
* @brief Save a PNG image of the plot to current EXE directory
* @brief Save a PNG image of the plot to current HOME directory
*/
void MainWindow::on_savePNGButton_clicked()
void MainWindow::on_actionRecord_PNG_triggered()
{
ui->plot->savePng (QDir::homePath() + '/' + QString::number(dataPointNumber) + '_' + QString::number(ui->plot->xAxis->coordToPixel(0)) + '_' + QString::number(ui->spinPoints->value()) + ".png", 1920, 1080, 2, 50);
//ui->plot->savePng (QDir::homePath() + '/' + QString::number(dataPointNumber) + ".png", 1920, 1080, 2, 50); // add home path before picture's name
Expand Down Expand Up @@ -742,6 +743,9 @@ void MainWindow::on_actionConnect_triggered()

/* Open serial port and connect its signals */
openPort (portInfo, baudRate, dataBits, parity, stopBits);

/* Enable PNG export */
ui->actionRecord_PNG->setEnabled(true);
}
}
/** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
Expand Down Expand Up @@ -801,7 +805,6 @@ void MainWindow::on_actionDisconnect_triggered()
ui->actionRecord_stream->setEnabled(true);
receivedData.clear(); // Clear received string

//ui->savePNGButton->setEnabled (false); // Disable export png, commented to be able to export when the plotting is stopped, permit zoom before export for example.
enable_com_controls (true);
}
}
Expand All @@ -820,6 +823,9 @@ void MainWindow::on_actionClear_triggered()
dataPointNumber = 0;
emit setupPlot();
ui->plot->replot();

/* Disable PNG export */
ui->actionRecord_PNG->setEnabled(false);
}
/** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

Expand Down
5 changes: 4 additions & 1 deletion mainwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private slots:
void readData(); // Slot for inside serial port
//void on_comboAxes_currentIndexChanged(int index); // Display number of axes and colors in status bar
void on_spinYStep_valueChanged(int arg1); // Spin box for changing Y axis tick step
void on_savePNGButton_clicked(); // Button for saving JPG
//void on_savePNGButton_clicked(); // Button for saving JPG
void onMouseMoveInPlot (QMouseEvent *event); // Displays coordinates of mouse pointer when clicked in plot in status bar
void on_spinPoints_valueChanged (int arg1); // Spin box controls how many data points are collected and displayed
void on_mouse_wheel_in_plot (QWheelEvent *event); // Makes wheel mouse works while plotting
Expand All @@ -84,6 +84,7 @@ private slots:
void on_actionPause_Plot_triggered();
void on_actionClear_triggered();
void on_actionRecord_stream_triggered();
void on_actionRecord_PNG_triggered();

void on_pushButton_TextEditHide_clicked();

Expand All @@ -97,6 +98,7 @@ private slots:

void on_pushButton_clicked();


signals:
void portOpenFail(); // Emitted when cannot open port
void portOpenOK(); // Emitted when port is open
Expand All @@ -114,6 +116,7 @@ private slots:
bool connected; // Status connection variable
bool plotting; // Status plotting variable
int dataPointNumber; // Keep track of data points

char buffer[10]; // buffer to convert number in string for png export
/* Channels of data (number of graphs) */
int channels;
Expand Down
26 changes: 13 additions & 13 deletions mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -528,13 +528,6 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="savePNGButton">
<property name="text">
<string>Save PNG</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand All @@ -555,12 +548,6 @@
</item>
<item>
<widget class="QGroupBox" name="gridGroupBox">
<property name="minimumSize">
<size>
<width>0</width>
<height>80</height>
</size>
</property>
<property name="title">
<string>TEXT CONTROLS</string>
</property>
Expand Down Expand Up @@ -703,6 +690,7 @@
<addaction name="actionHow_to_use"/>
<addaction name="separator"/>
<addaction name="actionRecord_stream"/>
<addaction name="actionRecord_PNG"/>
</widget>
<action name="actionConnect">
<property name="icon">
Expand Down Expand Up @@ -834,6 +822,18 @@
<bool>true</bool>
</property>
</action>
<action name="actionRecord_PNG">
<property name="icon">
<iconset resource="res/serial_port_plotter.qrc">
<normaloff>:/serial_port_plotter/ExPNG_nor.png</normaloff>:/serial_port_plotter/ExPNG_nor.png</iconset>
</property>
<property name="text">
<string>Record_PNG</string>
</property>
<property name="toolTip">
<string>Record the currently plot view in PNG image.</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
Expand Down
3 changes: 3 additions & 0 deletions res/serial_port_plotter.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<file alias="stop_act.png">icons/lynny-2x_white/Stop.png</file>
<file alias="clear_act.png">icons/lynny-2x_white/No Entry.png</file>
<file alias="help_act.png">icons/lynny-2x_white/Help.png</file>
<file alias="ExPNG_dis.png">icons/lynny-2x/File Type PNG.png</file>
<file alias="ExPNG_nor.png">icons/lynny-2x_text/File Type PNG.png</file>
<file alias="ExPNG_act.png">icons/lynny-2x_white/File Type PNG.png</file>
</qresource>
<qresource prefix="/">
<file>icons/line_icon_set/document.png</file>
Expand Down

0 comments on commit e320b22

Please sign in to comment.