Skip to content

Commit

Permalink
Add option to clear both received data and graph
Browse files Browse the repository at this point in the history
  • Loading branch information
wh201906 committed Nov 22, 2023
1 parent daf3460 commit a477902
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/datatab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ void DataTab::on_receivedTimestampBox_stateChanged(int arg1)
}

void DataTab::on_receivedClearButton_clicked()
{
clearRxData();
emit clearGraph();
}

void DataTab::clearRxData()
{
lastReceivedByte = '\0'; // anything but '\r'
emit clearReceivedData();
Expand Down Expand Up @@ -631,6 +637,19 @@ void DataTab::onRecordDataChanged(bool enabled)
}
}

void DataTab::onClearBehaviorChanged(bool clearBoth)
{
acceptClearSignal = clearBoth;
}

void DataTab::onRxClearSignalReceived()
{
if(acceptClearSignal)
{
on_receivedClearButton_clicked();
}
}

void DataTab::recordDataToBeSent()
{
settings->beginGroup("SerialTest_Data");
Expand Down
6 changes: 6 additions & 0 deletions src/datatab.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public slots:
void onConnTypeChanged(Connection::Type type);
void onConnEstablished();
void onRecordDataChanged(bool enabled);
void onClearBehaviorChanged(bool clearBoth);
void onRxClearSignalReceived();
protected:
bool eventFilter(QObject *watched, QEvent *event) override;
void showEvent(QShowEvent *ev) override;
Expand Down Expand Up @@ -102,6 +104,8 @@ private slots:
QVector<Metadata>* RxMetadata;
QByteArray* rawSendedData = nullptr;

bool acceptClearSignal = false;

void loadPreference();
void showUpTabHelper(int tabID);
inline QString stringWithTimestamp(const QString& str, qint64 timestamp);
Expand All @@ -110,13 +114,15 @@ private slots:
static DataTab* m_currInstance;
static void onSharedTextReceived(JNIEnv *env, jobject thiz, jstring text);
#endif
void clearRxData();
signals:
void send(const QByteArray& data);
void setDataCodec(QTextCodec* codec);
void setPlotDecoder(QTextDecoder* decoder);
void updateRxTxLen(bool updateRx, bool updateTx);
void clearSendedData();
void clearReceivedData();
void clearGraph();
void setTxDataRecording(bool enabled);
void showUpTab(int tabID);
};
Expand Down
4 changes: 4 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ MainWindow::MainWindow(QWidget *parent)

plotTab = new PlotTab();
connect(dataTab, &DataTab::setPlotDecoder, plotTab, &PlotTab::setDecoder);
connect(dataTab, &DataTab::clearGraph, plotTab, &PlotTab::onClearSignalReceived);
connect(plotTab, &PlotTab::clearRxData, dataTab, &DataTab::onRxClearSignalReceived);
ui->funcTab->insertTab(2, plotTab, tr("Plot"));

ctrlTab = new CtrlTab();
Expand All @@ -87,6 +89,8 @@ MainWindow::MainWindow(QWidget *parent)
connect(settingsTab, &SettingsTab::recordDataChanged, dataTab, &DataTab::onRecordDataChanged);
connect(settingsTab, &SettingsTab::mergeTimestampChanged, this, &MainWindow::onMergeTimestampChanged);
connect(settingsTab, &SettingsTab::timestampIntervalChanged, this, &MainWindow::onTimestampIntervalChanged);
connect(settingsTab, &SettingsTab::clearBehaviorChanged, dataTab, &DataTab::onClearBehaviorChanged);
connect(settingsTab, &SettingsTab::clearBehaviorChanged, plotTab, &PlotTab::onClearBehaviorChanged);
ui->funcTab->insertTab(5, settingsTab, tr("Settings"));

deviceTab->getAvailableTypes(true);
Expand Down
21 changes: 20 additions & 1 deletion src/plottab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ void PlotTab::changeGraphNum(int newNum)
}

void PlotTab::on_plot_clearButton_clicked()
{
clearGraph();
emit clearRxData();
}

void PlotTab::clearGraph()
{
int num;
plotCounter = 0;
Expand Down Expand Up @@ -547,7 +553,7 @@ void PlotTab::processData()
plotCounter++;
if(!plotClearFlag.isEmpty() && dataList[0] == plotClearFlag)
{
on_plot_clearButton_clicked();
clearGraph();
}
else if(ui->plot_XTypeBox->currentIndex() == 0)
{
Expand Down Expand Up @@ -604,6 +610,19 @@ void PlotTab::onThemeChanged(const QString &themeName)
ui->qcpWidget->setDarkStyle(isDarkTheme);
}

void PlotTab::onClearBehaviorChanged(bool clearBoth)
{
acceptClearSignal = clearBoth;
}

void PlotTab::onClearSignalReceived()
{
if(acceptClearSignal)
{
clearGraph();
}
}

QCPAbstractLegendItem* PlotTab::getLegendItemByPos(const QPointF &pos)
{
int i;
Expand Down
6 changes: 6 additions & 0 deletions src/plottab.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ public slots:
void newData(const QByteArray &data);
void setDecoder(QTextDecoder* decoder);
void onThemeChanged(const QString& themeName);
void onClearBehaviorChanged(bool clearBoth);
void onClearSignalReceived();
signals:
void clearRxData();

private slots:
void onQCPLegendDoubleClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent* event);
Expand Down Expand Up @@ -84,12 +87,15 @@ private slots:
QTimer* m_dataProcessTimer;
std::default_random_engine* m_randEngine;

bool acceptClearSignal = false;

void updateTracer(double x);
QCPAbstractLegendItem *getLegendItemByPos(const QPointF &pos);
void setGraphProperty(QCPAbstractLegendItem *item);
inline double toDouble(const QString& str); // find valid value then convert
void saveGraphProperty();
void changeGraphNum(int newNum);
void clearGraph();
};

#endif // PLOTTAB_H
12 changes: 12 additions & 0 deletions src/settingstab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ void SettingsTab::loadPreference()
ui->Android_forceLandscapeBox->setChecked(m_settings->value("Android_ForceLandscape", true).toBool());
ui->Android_dockBox->setChecked(m_settings->value("Android_Dock", false).toBool());
ui->Opacity_Box->setValue(m_settings->value("Opacity", 100).toInt());
ui->General_simultaneousClearBox->setChecked(m_settings->value("ClearBothRxDataAndGraph", false).toBool());
int themeId = ui->Theme_nameBox->findData(m_settings->value("Theme_Name", "(none)").toString());
ui->Theme_nameBox->setCurrentIndex((themeId == -1) ? 0 : themeId);

Expand Down Expand Up @@ -251,6 +252,7 @@ void SettingsTab::loadPreference()
on_Data_recordDataBox_clicked();
on_Data_mergeTimestampBox_clicked();
on_Data_mergeTimestampIntervalBox_valueChanged(ui->Data_mergeTimestampIntervalBox->value());
on_General_simultaneousClearBox_clicked();

if(fontValid)
on_Font_setButton_clicked();
Expand Down Expand Up @@ -382,3 +384,13 @@ void SettingsTab::on_Data_mergeTimestampIntervalBox_valueChanged(int arg1)
emit timestampIntervalChanged(arg1);
}


void SettingsTab::on_General_simultaneousClearBox_clicked()
{
bool clearBoth = ui->General_simultaneousClearBox->isChecked();
m_settings->beginGroup("SerialTest");
m_settings->setValue("ClearBothRxDataAndGraph", clearBoth);
m_settings->endGroup();
emit clearBehaviorChanged(clearBoth);
}

3 changes: 3 additions & 0 deletions src/settingstab.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ private slots:

void on_Data_mergeTimestampIntervalBox_valueChanged(int arg1);

void on_General_simultaneousClearBox_clicked();

private:
Ui::SettingsTab *ui;
MySettings* m_settings;
Expand All @@ -74,6 +76,7 @@ private slots:
void recordDataChanged(bool enabled);
void mergeTimestampChanged(bool enabled);
void timestampIntervalChanged(int interval);
void clearBehaviorChanged(bool clearBoth);
};

#endif // SETTINGSTAB_H
7 changes: 7 additions & 0 deletions src/ui/settingstab.ui
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,13 @@ If no config file is detected, This app will create one in the current working d
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="General_simultaneousClearBox">
<property name="text">
<string>Clear received data in DataTab and graph in PlotTab simultaneously</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down

0 comments on commit a477902

Please sign in to comment.