Skip to content

Commit 8ca3cec

Browse files
author
m.zabic
committed
save feature added, gui-scrolling experience improved
1 parent c42e2e1 commit 8ca3cec

19 files changed

+109
-99
lines changed

src/FDMLControl.pro

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ HEADERS += ./fdmlcontrol.h \
5252
plotwidget.h \
5353
querymanager.h \
5454
querywidget.h \
55-
querywidgetmanager.h
55+
querywidgetmanager.h \
56+
eventguard.h
5657

5758
SOURCES += ./fdmlcontrol.cpp \
5859
./QCustomPlot/qcustomplot.cpp \
@@ -67,10 +68,11 @@ SOURCES += ./fdmlcontrol.cpp \
6768
plotwidget.cpp \
6869
querymanager.cpp \
6970
querywidget.cpp \
70-
querywidgetmanager.cpp
71+
querywidgetmanager.cpp \
72+
eventguard.cpp
7173

72-
FORMS += ./ComSettingsWidget.ui \
73-
./ConsoleWidget.ui \
74+
FORMS += ./comsettingswidget.ui \
75+
./consolewidget.ui \
7476
./fdmlcontrol.ui
7577

7678
RESOURCES += fdmlcontrol.qrc

src/authenticationwidget.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ AuthenticationWidget::~AuthenticationWidget()
4141
{
4242
}
4343

44-
bool AuthenticationWidget::isKeyAvailable(){
44+
bool AuthenticationWidget::isKeyAvailable()
45+
{
4546
return this->keyAvailable;
4647
}
4748

48-
void AuthenticationWidget::loadKeyFromFile(QString filePath){
49+
void AuthenticationWidget::loadKeyFromFile(QString filePath) {
4950
QFile inputFile(filePath);
5051
if (inputFile.open(QIODevice::ReadOnly)){
5152
QTextStream in(&inputFile);
@@ -97,7 +98,7 @@ void AuthenticationWidget::handleResponse(QString initialQuery, QString response
9798
}
9899
}
99100
}
100-
else if (status == "401"){
101+
else if (status == "401") {
101102
emit error(tr("Invalid command! Initial query: ") + initialQuery + tr(" Response: ") + recoveredResponse);
102103
}
103104
else {

src/authenticationwidget.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,18 @@ class AuthenticationWidget : public QueryWidget
4343

4444
bool isKeyAvailable();
4545

46+
4647
private:
4748
QString key;
4849
bool keyAvailable;
4950

51+
5052
public slots:
5153
void loadKeyFromFile(QString filePath);
5254
void authenticate();
5355
void handleResponse(QString initialQuery, QString response) override;
5456

57+
5558
signals:
5659

5760
};
58-

src/buttonquerywidget.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,17 @@ ButtonQueryWidget::ButtonQueryWidget(QWidget *parent) : QueryWidget(parent) {
4040
}
4141

4242
ButtonQueryWidget::ButtonQueryWidget(QString name, QString command, bool expert, QString infoText, QWidget* parent) : ButtonQueryWidget(parent) {
43-
this->name = name;
44-
this->command = command;
45-
this->expert = expert;
46-
this->setToolTip("<font>" + infoText + "</font>");
47-
this->button->setText(name);
43+
this->name = name;
44+
this->command = command;
45+
this->expert = expert;
46+
this->setToolTip("<font>" + infoText + "</font>");
47+
this->button->setText(name);
4848
}
4949

50-
ButtonQueryWidget::~ButtonQueryWidget()
51-
{
50+
ButtonQueryWidget::~ButtonQueryWidget() {
5251
}
5352

54-
void ButtonQueryWidget::handleResponse(QString initialQuery, QString response){
53+
void ButtonQueryWidget::handleResponse(QString initialQuery, QString response) {
5554
}
5655

5756
void ButtonQueryWidget::sendQuery() {

src/buttonquerywidget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ class ButtonQueryWidget : public QueryWidget
4242
ButtonQueryWidget(QString name, QString command, bool expert, QString infoText, QWidget *parent = nullptr);
4343
~ButtonQueryWidget();
4444

45+
4546
private:
4647
QPushButton* button;
4748
QHBoxLayout* layout;
4849
QString command;
4950

51+
5052
public slots:
5153
void handleResponse(QString initialQuery, QString response) override;
5254
void sendQuery();

src/comboboxquerywidget.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
ComboBoxQueryWidget::ComboBoxQueryWidget(QWidget *parent) : QueryWidget(parent) {
3232
this->comboBox = new QComboBox(this);
33+
this->comboBox->setFocusPolicy(Qt::StrongFocus);
34+
this->comboBox->installEventFilter(new EventGuard(this->comboBox)); //StrongFocus and event filter prevent the accidental change of comboBox value inside QScrollArea
3335
this->label = new QLabel(this);
3436
this->layout = new QHBoxLayout(this);
3537
this->layout->setMargin(0);
@@ -59,7 +61,11 @@ ComboBoxQueryWidget::~ComboBoxQueryWidget()
5961
{
6062
}
6163

62-
void ComboBoxQueryWidget::handleResponse(QString initialQuery, QString response){
64+
QString ComboBoxQueryWidget::content() {
65+
return this->name + ":" + "\t" + this->comboBox->currentText();
66+
}
67+
68+
void ComboBoxQueryWidget::handleResponse(QString initialQuery, QString response) {
6369
//check if response is not empty
6470
if (!(response.size() > 2)) {
6571
emit error(tr("Could not change value, response too short. Initial query: ") + initialQuery + tr(" Response: ") + response);

src/comboboxquerywidget.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <QString>
3434
#include <QHBoxLayout>
3535
#include "querywidget.h"
36+
#include "eventguard.h"
3637

3738
class ComboBoxQueryWidget : public QueryWidget
3839
{
@@ -42,6 +43,8 @@ class ComboBoxQueryWidget : public QueryWidget
4243
ComboBoxQueryWidget(QWidget *parent = nullptr);
4344
ComboBoxQueryWidget(QString name, QStringList options, bool expert, QString infoText, QWidget *parent = nullptr);
4445
~ComboBoxQueryWidget();
46+
QString content() override;
47+
4548

4649
private:
4750
QComboBox* comboBox;
@@ -50,11 +53,13 @@ class ComboBoxQueryWidget : public QueryWidget
5053
QStringList options;
5154
bool enableDisableComboBox;
5255

56+
5357
public slots:
5458
void handleResponse(QString initialQuery, QString response) override;
5559
void changeValue(int value);
5660
void queryCurrentValue();
5761

62+
5863
signals:
5964

6065
};

src/comsettingswidget.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,3 @@ private slots:
104104
void connectCom();
105105
void disconnectCom();
106106
};
107-

src/consolewidget.cpp

Lines changed: 0 additions & 56 deletions
This file was deleted.

src/consolewidget.h

Lines changed: 2 additions & 2 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
@@ -42,9 +40,11 @@ class ConsoleWidget : public QueryWidget
4240
ConsoleWidget(QWidget *parent = Q_NULLPTR);
4341
~ConsoleWidget();
4442

43+
4544
private:
4645
Ui::ConsoleWidget ui;
4746

47+
4848
public slots:
4949
void handleResponse(QString initialQuery, QString response) override;
5050
void slot_commandSent();

src/fdmlcontrol.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ FDMLControl::FDMLControl(QWidget *parent) : QMainWindow(parent){
5959
connect(this->queryManager, &QueryManager::serialOpen, this, &FDMLControl::enableGui);
6060
connect(this->queryManager, &QueryManager::info, this->logConsole, &MessageConsole::slot_displayInfo);
6161
connect(this->queryManager, &QueryManager::error, this->logConsole, &MessageConsole::slot_displayError);
62+
connect(this->widgetManager, &QueryWidgetManager::info, this->logConsole, &MessageConsole::slot_displayInfo);
63+
connect(this->widgetManager, &QueryWidgetManager::error, this->logConsole, &MessageConsole::slot_displayError);
6264
connect(&comThread, &QThread::finished, queryManager, &QueryManager::deleteLater);
6365
connect(&comThread, &QThread::finished, &comThread, &QThread::deleteLater);
6466
comThread.start();
@@ -187,9 +189,11 @@ void FDMLControl::initGui(){
187189

188190
void FDMLControl::initMenu(){
189191
QMenu *fileMenu = this->menuBar()->addMenu(tr("&File"));
190-
QAction *exitAct = fileMenu->addAction(tr("E&xit"), this, &QWidget::close);
191-
exitAct->setShortcuts(QKeySequence::Quit);
192-
exitAct->setStatusTip(tr("Close FDML Control"));
192+
QAction* saveToFileAction = fileMenu->addAction(tr("&Save Parameters"), this->widgetManager, &QueryWidgetManager::saveWidgetValuesToFile);
193+
saveToFileAction->setStatusTip(tr("Save parameter values that are visible in right area of FDMLControl"));
194+
QAction *exitAct = fileMenu->addAction(tr("E&xit"), this, &QWidget::close);
195+
exitAct->setShortcuts(QKeySequence::Quit);
196+
exitAct->setStatusTip(tr("Close FDML Control"));
193197

194198
QMenu* viewMenu = this->menuBar()->addMenu(tr("&View"));
195199
this->expertViewAction = viewMenu->addAction(tr("&Expert"), this, &FDMLControl::toggleExpertView);
@@ -290,8 +294,8 @@ void FDMLControl::showAbout() {
290294
"Contact: zabic"
291295
"@"
292296
"iqo.uni-hannover.de<br>"
293-
"Date: 17 July 2019<br>"
294-
"Version: 1.0.3"));
297+
"Date: ")+ VERSION_DATE + tr("<br>"
298+
"Version: ") + VERSION);
295299
}
296300

297301
void FDMLControl::toggleExpertView() {

src/fdmlcontrol.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,20 @@
4444

4545
#define COMMAND_FILE_PATH QCoreApplication::applicationDirPath() + "/fdml_commands.xml"
4646
#define KEY_FILE_PATH QCoreApplication::applicationDirPath() + "/key.dat"
47+
#define VERSION "1.0.4"
48+
#define VERSION_DATE "13 September 2019"
4749

4850
class FDMLControl : public QMainWindow
4951
{
5052
Q_OBJECT
5153
QThread comThread;
5254

55+
5356
public:
5457
FDMLControl(QWidget *parent = Q_NULLPTR);
5558
~FDMLControl();
5659

60+
5761
private:
5862
Ui::FDMLControlClass ui;
5963
ConsoleWidget* console;
@@ -96,6 +100,7 @@ public slots:
96100
void readOutDevice();
97101
void authenticateAsAdmin();
98102

103+
99104
signals:
100105
void serialResponse(QString);
101106
void openSerialPort(ComSettings);

src/intvaluewidget.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ IntValueWidget::IntValueWidget(QWidget* parent, QString name) : QueryWidget(pare
3434
this->value = 0;
3535
this->name = name;
3636
this->spinBox = new QSpinBox(this);
37+
this->spinBox->setFocusPolicy(Qt::StrongFocus);
38+
this->spinBox->installEventFilter(new EventGuard(this->spinBox)); //StrongFocus and event filter prevent the accidental change of spinbox value inside QScrollArea
3739
this->label = new QLabel(this->name, this);
3840
this->layout = new QHBoxLayout(this);
3941
this->layout->setMargin(0);
@@ -55,18 +57,20 @@ IntValueWidget::~IntValueWidget()
5557
{
5658
}
5759

58-
void IntValueWidget::setMin(int minValue)
59-
{
60+
void IntValueWidget::setMin(int minValue) {
6061
this->spinBox->setMinimum(minValue);
6162
}
6263

63-
void IntValueWidget::setMax(int maxValue)
64-
{
64+
void IntValueWidget::setMax(int maxValue) {
6565
this->spinBox->setMaximum(maxValue);
6666
}
6767

6868
void IntValueWidget::setStepSize(int stepSize){
69-
this->spinBox->setSingleStep(stepSize);
69+
this->spinBox->setSingleStep(stepSize);
70+
}
71+
72+
QString IntValueWidget::content(){
73+
return this->name + ":" + "\t" + QString::number(this->value);
7074
}
7175

7276
void IntValueWidget::setValue(int value) {

src/intvaluewidget.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@
2929
****************************************************************************/
3030

3131
#pragma once
32+
3233
#include <qwidget.h>
3334
#include <qspinbox.h>
3435
#include <qlabel.h>
3536
#include <qlayout.h>
3637
#include <QCoreApplication>
3738
#include "querywidget.h"
39+
#include "eventguard.h"
3840

3941
class IntValueWidget : public QueryWidget
4042
{
@@ -46,7 +48,9 @@ class IntValueWidget : public QueryWidget
4648
void setMin(int minValue);
4749
void setMax(int maxValue);
4850
void setStepSize(int stepSize);
51+
QString content() override;
4952

53+
5054
private:
5155
int value;
5256
QSpinBox* spinBox;
@@ -60,8 +64,7 @@ public slots:
6064
void queryCurrentValue();
6165
void handleResponse(QString initialQuery, QString response) override;
6266

67+
6368
signals:
6469
void valueChanged(QString name, int value);
65-
6670
};
67-

src/messageconsole.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
** Version: 1.0.0 **
2929
****************************************************************************/
3030

31-
#ifndef MESSAGECONSOLE_H
32-
#define MESSAGECONSOLE_H
31+
#pragma once
3332

3433
#include <QTextEdit>
3534
#include <QGridLayout>
@@ -71,5 +70,3 @@ public slots:
7170
void slot_displayInfo(QString info);
7271
void slot_displayError(QString error);
7372
};
74-
75-
#endif // MESSAGECONSOLE_H

0 commit comments

Comments
 (0)