Skip to content

Commit 8ce3d96

Browse files
committed
Refactoring and disconnect bug fixed
1 parent a2dab27 commit 8ce3d96

File tree

4 files changed

+70
-94
lines changed

4 files changed

+70
-94
lines changed

src/fdmlcontrol.cpp

Lines changed: 60 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
** at **
2525
** iqo.uni-hannover.de **
2626
** **
27-
** Date: 12 June 2019 **
28-
** Version: 1.0.0 **
2927
****************************************************************************/
3028

3129
#include "fdmlcontrol.h"
@@ -57,13 +55,8 @@ FDMLControl::FDMLControl(QWidget *parent) : QMainWindow(parent){
5755
connect(this, &FDMLControl::openSerialPort, this->queryManager, &QueryManager::openSerialPort);
5856
connect(this, &FDMLControl::closeSerialPort, this->queryManager, &QueryManager::closeSerialPort);
5957
connect(this->queryManager, &QueryManager::serialOpen, this, &FDMLControl::enableGui);
60-
connect(this->console, &QueryWidget::query, this->queryManager, &QueryManager::receiveQuery);
61-
connect(this->plot, &QueryWidget::query, this->queryManager, &QueryManager::receiveQuery);
6258
connect(this->queryManager, &QueryManager::info, this->logConsole, &MessageConsole::slot_displayInfo);
6359
connect(this->queryManager, &QueryManager::error, this->logConsole, &MessageConsole::slot_displayError);
64-
connect(this->authenticator, &QueryWidget::query, this->queryManager, &QueryManager::receiveQuery);
65-
connect(this->authenticator, &QueryWidget::info, this->logConsole, &MessageConsole::slot_displayInfo);
66-
connect(this->authenticator, &QueryWidget::error, this->logConsole, &MessageConsole::slot_displayError);
6760
connect(&comThread, &QThread::finished, queryManager, &QueryManager::deleteLater);
6861
connect(&comThread, &QThread::finished, &comThread, &QThread::deleteLater);
6962
comThread.start();
@@ -72,6 +65,7 @@ FDMLControl::FDMLControl(QWidget *parent) : QMainWindow(parent){
7265
}
7366

7467
FDMLControl::~FDMLControl() {
68+
this->queryManager->abort = true;
7569
emit this->closeSerialPort();
7670
QApplication::processEvents();
7771
comThread.quit();
@@ -81,12 +75,14 @@ FDMLControl::~FDMLControl() {
8175
}
8276

8377
void FDMLControl::initQueryWidgets(){
84-
QDir filePath(COMMAND_FILE_PATH);
78+
//load gui elements from xml file
79+
QDir filePath(COMMAND_FILE_PATH);
8580
this->widgetManager->createWidgetsFromXmlFile(filePath.absolutePath());
8681
QList<IntValueWidget*> intValueWidgets = this->widgetManager->getIntValueWidgets();
8782
QList<ButtonQueryWidget*> buttonWidgets = this->widgetManager->getButtonWidgets();
88-
auto comboBoxWidgets = this->widgetManager->getComboBoxWidgets();
83+
QList<ComboBoxQueryWidget*> comboBoxWidgets = this->widgetManager->getComboBoxWidgets();
8984

85+
//init button area
9086
auto buttonLayout = new QHBoxLayout(this);
9187
buttonLayout->setContentsMargins(1, 3, 1, 3);
9288
buttonLayout->setSpacing(1);
@@ -98,75 +94,26 @@ void FDMLControl::initQueryWidgets(){
9894
}
9995
buttonLayout->addStretch();
10096

101-
//Init IntVlaueWidgets and scroll area
97+
//init scroll area
10298
auto scrollAreaLayout = new QVBoxLayout(this->ui.scrollAreaWidgetContents);
10399
scrollAreaLayout->setSpacing(6);
104100
scrollAreaLayout->setContentsMargins(6, 0, 6, 0);
105101

106-
auto acquisitionLayout = this->generateLayout("Acquisition");
107-
auto galvoLayout = this->generateLayout("Glavo Waveforms");
108-
auto rgpolLayout = this->generateLayout("Rg Pol");
109-
auto filterLayout = this->generateLayout("Filter Control");
110-
auto boosterLayout = this->generateLayout("BoosterSOA");
111-
auto bncLayout = this->generateLayout("BNC Configuration");
112-
auto otherLayout = this->generateLayout("Other");
113-
114-
for (int i = 0; i < intValueWidgets.size(); i++) {
115-
QString currName = intValueWidgets.at(i)->getName();
116-
if(currName.contains("acq.") || currName.contains("scpll.")){
117-
acquisitionLayout->addWidget(intValueWidgets.at(i));
118-
}
119-
else if (currName.contains("xyout.")) {
120-
galvoLayout->addWidget(intValueWidgets.at(i));
121-
}
122-
else if (currName.contains("rg.")) {
123-
rgpolLayout->addWidget(intValueWidgets.at(i));
124-
}
125-
else if (currName.contains("flt.")) {
126-
filterLayout->addWidget(intValueWidgets.at(i));
127-
}
128-
else if (currName.contains("ldc.")) {
129-
boosterLayout->addWidget(intValueWidgets.at(i));
130-
}
131-
else if (currName.contains("bnc.")) {
132-
bncLayout->addWidget(intValueWidgets.at(i));
133-
}
134-
else {
135-
otherLayout->addWidget(intValueWidgets.at(i));
136-
}
137-
connect(intValueWidgets.at(i), &QueryWidget::query, this->queryManager, &QueryManager::receiveQuery, Qt::QueuedConnection);
138-
connect(intValueWidgets.at(i), &QueryWidget::info, this->logConsole, &MessageConsole::slot_displayInfo);
139-
connect(intValueWidgets.at(i), &QueryWidget::error, this->logConsole, &MessageConsole::slot_displayError);
140-
}
102+
auto acquisitionLayout = this->generateLayout(tr("Acquisition"));
103+
auto galvoLayout = this->generateLayout(tr("Galvo Waveforms"));
104+
auto rgpolLayout = this->generateLayout(tr("Rg Pol"));
105+
auto filterLayout = this->generateLayout(tr("Filter Control"));
106+
auto boosterLayout = this->generateLayout(tr("Booster SOA"));
107+
auto bncLayout = this->generateLayout(tr("BNC Configuration"));
108+
auto otherLayout = this->generateLayout(tr("Other"));
141109

142-
//Init ComboBoxQueryWidgets
143-
for (int i = 0; i < comboBoxWidgets.size(); i++) {
144-
QString currName = comboBoxWidgets.at(i)->getName();
145-
if (currName.contains("acq.") || currName.contains("scpll.")) {
146-
acquisitionLayout->addWidget(comboBoxWidgets.at(i));
147-
}
148-
else if (currName.contains("xyout.")) {
149-
galvoLayout->addWidget(comboBoxWidgets.at(i));
150-
}
151-
else if (currName.contains("rg.")) {
152-
rgpolLayout->addWidget(comboBoxWidgets.at(i));
153-
}
154-
else if (currName.contains("flt.")) {
155-
rgpolLayout->addWidget(comboBoxWidgets.at(i));
156-
}
157-
else if (currName.contains("ldc.")) {
158-
boosterLayout->addWidget(comboBoxWidgets.at(i));
159-
}
160-
else if (currName.contains("bnc.")) {
161-
bncLayout->addWidget(comboBoxWidgets.at(i));
162-
}
163-
else {
164-
otherLayout->addWidget(comboBoxWidgets.at(i));
165-
}
166-
connect(comboBoxWidgets.at(i), &QueryWidget::query, this->queryManager, &QueryManager::receiveQuery, Qt::QueuedConnection);
167-
connect(comboBoxWidgets.at(i), &QueryWidget::info, this->logConsole, &MessageConsole::slot_displayInfo);
168-
connect(comboBoxWidgets.at(i), &QueryWidget::error, this->logConsole, &MessageConsole::slot_displayError);
169-
}
110+
for (int i = 0; i < intValueWidgets.size(); i++) {
111+
this->sortQueryWidgetIntoGui(intValueWidgets.at(i), acquisitionLayout, galvoLayout, rgpolLayout, filterLayout, boosterLayout, bncLayout,otherLayout);
112+
}
113+
114+
for (int i = 0; i < comboBoxWidgets.size(); i++) {
115+
this->sortQueryWidgetIntoGui(comboBoxWidgets.at(i), acquisitionLayout, galvoLayout, rgpolLayout, filterLayout, boosterLayout, bncLayout,otherLayout);
116+
}
170117

171118
this->acqFrame = acquisitionLayout->parentWidget();
172119
this->galvoFrame = galvoLayout->parentWidget();
@@ -184,9 +131,42 @@ void FDMLControl::initQueryWidgets(){
184131
scrollAreaLayout->addWidget(bncFrame);
185132
scrollAreaLayout->addWidget(otherFrame);
186133

134+
//init plot, log and authenticator
187135
connect(this->plot, &QueryWidget::info, this->logConsole, &MessageConsole::slot_displayInfo);
188136
connect(this->plot, &QueryWidget::error, this->logConsole, &MessageConsole::slot_displayError);
137+
connect(this->plot, &QueryWidget::query, this->queryManager, &QueryManager::receiveQuery);
138+
connect(this->console, &QueryWidget::query, this->queryManager, &QueryManager::receiveQuery);
139+
connect(this->authenticator, &QueryWidget::query, this->queryManager, &QueryManager::receiveQuery);
140+
connect(this->authenticator, &QueryWidget::info, this->logConsole, &MessageConsole::slot_displayInfo);
141+
connect(this->authenticator, &QueryWidget::error, this->logConsole, &MessageConsole::slot_displayError);
142+
}
189143

144+
void FDMLControl::sortQueryWidgetIntoGui(QueryWidget* widget, QVBoxLayout* acquisitionLayout, QVBoxLayout* galvoLayout, QVBoxLayout* rgpolLayout, QVBoxLayout* filterLayout, QVBoxLayout* boosterLayout, QVBoxLayout* bncLayout, QVBoxLayout* otherLayout){
145+
QString currName = widget->getName();
146+
if(currName.contains("acq.") || currName.contains("scpll.")){
147+
acquisitionLayout->addWidget(widget);
148+
}
149+
else if (currName.contains("xyout.")) {
150+
galvoLayout->addWidget(widget);
151+
}
152+
else if (currName.contains("rg.")) {
153+
rgpolLayout->addWidget(widget);
154+
}
155+
else if (currName.contains("flt.")) {
156+
filterLayout->addWidget(widget);
157+
}
158+
else if (currName.contains("ldc.")) {
159+
boosterLayout->addWidget(widget);
160+
}
161+
else if (currName.contains("bnc.")) {
162+
bncLayout->addWidget(widget);
163+
}
164+
else {
165+
otherLayout->addWidget(widget);
166+
}
167+
connect(widget, &QueryWidget::query, this->queryManager, &QueryManager::receiveQuery, Qt::QueuedConnection);
168+
connect(widget, &QueryWidget::info, this->logConsole, &MessageConsole::slot_displayInfo);
169+
connect(widget, &QueryWidget::error, this->logConsole, &MessageConsole::slot_displayError);
190170
}
191171

192172
void FDMLControl::initGui(){
@@ -247,7 +227,6 @@ QVBoxLayout * FDMLControl::generateLayout(QString name){
247227
frame->setAutoFillBackground(true);
248228
frame->setPalette(pal);
249229
frame->show();
250-
251230
frame->setFrameShape(QFrame::StyledPanel);
252231

253232
auto layout = new QVBoxLayout(frame);
@@ -256,8 +235,8 @@ QVBoxLayout * FDMLControl::generateLayout(QString name){
256235

257236
QFont font;
258237
font.setBold(true);
259-
auto label = new QLabel(frame);
260238

239+
auto label = new QLabel(frame);
261240
label->setFont(font);
262241
label->setText(name + ": ");
263242

@@ -266,10 +245,12 @@ QVBoxLayout * FDMLControl::generateLayout(QString name){
266245
}
267246

268247
void FDMLControl::slot_openSerialPort(){
248+
this->queryManager->abort = false;
269249
emit this->openSerialPort(this->comSettings->settings());
270250
}
271251

272252
void FDMLControl::slot_closeSerialPort(){
253+
this->queryManager->abort = true;
273254
this->plot->setAutoUpdate(false);
274255
emit closeSerialPort();
275256
}
@@ -280,8 +261,8 @@ void FDMLControl::enableGui(bool enable){
280261
this->readOutAction->setEnabled(enable);
281262

282263
if (enable) {
283-
this->authenticator->authenticate();
284-
this->widgetManager->queryCurrentValues();
264+
this->authenticator->authenticate();
265+
this->widgetManager->queryCurrentValues();
285266
}
286267
}
287268

@@ -303,8 +284,8 @@ void FDMLControl::showAbout() {
303284
"Contact: zabic"
304285
"@"
305286
"iqo.uni-hannover.de<br>"
306-
"Date: 17 June 2019<br>"
307-
"Version: 1.0.1"));
287+
"Date: 21 June 2019<br>"
288+
"Version: 1.0.2"));
308289
}
309290

310291
void FDMLControl::toggleExpertView() {
@@ -314,7 +295,6 @@ void FDMLControl::toggleExpertView() {
314295

315296
if(this->rgpolFrame != nullptr){this->rgpolFrame->setVisible(visibleChecked);} // todo: Check all frames to see if the contained elements are expert elements before changing the visibility of the frame
316297
if(this->filterFrame != nullptr){this->filterFrame->setVisible(visibleChecked);} // todo: Check all frames to see if the contained elements are expert elements before changing the visibility of the frame
317-
318298
}
319299

320300
void FDMLControl::toggleLogView() {

src/fdmlcontrol.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
** at **
2525
** iqo.uni-hannover.de **
2626
** **
27-
** Date: 12 June 2019 **
28-
** Version: 1.0.0 **
2927
****************************************************************************/
3028

3129
#pragma once
@@ -71,12 +69,6 @@ class FDMLControl : public QMainWindow
7169
QAction* logViewAction;
7270
QAction* readOutAction;
7371

74-
void initQueryWidgets();
75-
void initGui();
76-
void initMenu();
77-
void enableGroupBoxes(bool enable);
78-
QVBoxLayout* generateLayout(QString name);
79-
8072
QWidget* acqFrame;
8173
QWidget* galvoFrame;
8274
QWidget* rgpolFrame;
@@ -85,6 +77,13 @@ class FDMLControl : public QMainWindow
8577
QWidget* bncFrame;
8678
QWidget* otherFrame;
8779

80+
void initQueryWidgets();
81+
void sortQueryWidgetIntoGui(QueryWidget* widget, QVBoxLayout* acquisitionLayout, QVBoxLayout* galvoLayout, QVBoxLayout* rgpolLayout, QVBoxLayout* filterLayout, QVBoxLayout* boosterLayout, QVBoxLayout* bncLayout, QVBoxLayout* otherLayout);
82+
void initGui();
83+
void initMenu();
84+
void enableGroupBoxes(bool enable);
85+
QVBoxLayout* generateLayout(QString name);
86+
8887

8988
public slots:
9089
void slot_openSerialPort();

src/querymanager.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,22 @@
2424
** at **
2525
** iqo.uni-hannover.de **
2626
** **
27-
** Date: 12 June 2019 **
28-
** Version: 1.0.0 **
2927
****************************************************************************/
3028

3129
#include "querymanager.h"
3230

3331
QueryManager::QueryManager(){
3432
this->serial = new QSerialPort(this);
3533
this->sendLog = true;
34+
this->abort = false;
3635
}
3736

3837
QueryManager::~QueryManager()
3938
{
4039
}
4140

4241
void QueryManager::receiveQuery(QueryWidget* widget, QString query) {
42+
if(abort){return;}
4343
//Convert query string to QByteArray and send query to serial device
4444
QByteArray carriageReturn = "\r";
4545
QByteArray command = query.toLocal8Bit() + carriageReturn;
@@ -48,7 +48,6 @@ void QueryManager::receiveQuery(QueryWidget* widget, QString query) {
4848
emit error(tr("Serial write error! Query: ") + query);
4949
return;
5050
}
51-
5251
if (this->serial->waitForBytesWritten(1000)) {
5352
//Read serial response until end of response was received ("\n" or "\r") or until timeout (1000 ms) occured
5453
QByteArray response = this->serial->readAll();

src/querymanager.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
** at **
2525
** iqo.uni-hannover.de **
2626
** **
27-
** Date: 12 June 2019 **
28-
** Version: 1.0.0 **
2927
****************************************************************************/
3028

3129
#pragma once
@@ -44,13 +42,13 @@ class QueryManager : public QObject
4442
public:
4543
QueryManager();
4644
~QueryManager();
45+
bool abort;
4746

4847
private:
4948
QSerialPort* serial;
5049
QTimer* timeoutTimer;
5150
bool sendLog;
5251

53-
5452
public slots:
5553
void receiveQuery(QueryWidget* widget, QString query);
5654
void openSerialPort(ComSettings settings);

0 commit comments

Comments
 (0)