Skip to content

Commit fdeb7e3

Browse files
committed
Changed default values & code cleaning
1 parent 5528a60 commit fdeb7e3

File tree

6 files changed

+95
-92
lines changed

6 files changed

+95
-92
lines changed

argaction.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ argAction::~argAction()
2929

3030
}
3131

32-
bool argAction::setDoubleSpinBox(void *doubleSpinBox, QString argValue)
32+
bool argAction::setDoubleSpinBox(void *doubleSpinBox, const QString argValue)
3333
{
3434
bool ok;
3535
double value = argValue.toDouble(&ok);
@@ -40,7 +40,7 @@ bool argAction::setDoubleSpinBox(void *doubleSpinBox, QString argValue)
4040
return ok;
4141
}
4242

43-
bool argAction::setSpinBox(void *spinBox, QString argValue)
43+
bool argAction::setSpinBox(void *spinBox, const QString argValue)
4444
{
4545
bool ok;
4646
int value = argValue.toInt(&ok, 10);
@@ -51,7 +51,7 @@ bool argAction::setSpinBox(void *spinBox, QString argValue)
5151
return ok;
5252
}
5353

54-
bool argAction::setCheckBox(void *checkBox, QString argValue)
54+
bool argAction::setCheckBox(void *checkBox, const QString argValue)
5555
{
5656
if(argValue == "1" || argValue.compare("true", Qt::CaseInsensitive) == 0)
5757
{
@@ -67,14 +67,14 @@ bool argAction::setCheckBox(void *checkBox, QString argValue)
6767
return false;
6868
}
6969

70-
bool argAction::setLineEdit(void *lineEdit, QString argValue)
70+
bool argAction::setLineEdit(void *lineEdit, const QString argValue)
7171
{
7272
static_cast<QLineEdit *>(lineEdit)->setText(argValue);
7373

7474
return true;
7575
}
7676

77-
bool argAction::setComboBox(void *comboBox, QString argValue)
77+
bool argAction::setComboBox(void *comboBox, const QString argValue)
7878
{
7979
int index = static_cast<QComboBox *>(comboBox)->findText(argValue, Qt::MatchFixedString);
8080

@@ -87,7 +87,7 @@ bool argAction::setComboBox(void *comboBox, QString argValue)
8787
return false;
8888
}
8989

90-
bool argAction::setButtonGroup(void *buttonGroup, QString argValue)
90+
bool argAction::setButtonGroup(void *buttonGroup, const QString argValue)
9191
{
9292
if(argValue == "1" || argValue.compare("true", Qt::CaseInsensitive) == 0)
9393
{
@@ -139,7 +139,7 @@ QString argAction::getButtonGroup(void *buttonGroup)
139139
return "false";
140140
}
141141

142-
bool argAction::setValue(QString key, QString value)
142+
bool argAction::setValue(const QString key, const QString value)
143143
{
144144
argElement element;
145145

@@ -152,7 +152,7 @@ bool argAction::setValue(QString key, QString value)
152152
return false;
153153
}
154154

155-
QStringList argAction::getAllArgs(bool getCommentedOptions, bool getDisabledObjects)
155+
QStringList argAction::getAllArgs(const bool getCommentedOptions, const bool getDisabledObjects)
156156
{
157157
QStringList output;
158158
QString value;

argaction.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ class argAction
3434
{
3535
protected:
3636

37-
static bool setDoubleSpinBox(void *doubleSpinBox, QString argValue);
38-
static bool setSpinBox(void *spinBox, QString argValue);
39-
static bool setCheckBox(void *checkBox, QString argValue);
40-
static bool setLineEdit(void *lineEdit, QString argValue);
41-
static bool setComboBox(void *comboBox, QString argValue);
42-
static bool setButtonGroup(void *buttonGroup, QString argValue);
37+
static bool setDoubleSpinBox(void *doubleSpinBox, const QString argValue);
38+
static bool setSpinBox(void *spinBox, const QString argValue);
39+
static bool setCheckBox(void *checkBox, const QString argValue);
40+
static bool setLineEdit(void *lineEdit, const QString argValue);
41+
static bool setComboBox(void *comboBox, const QString argValue);
42+
static bool setButtonGroup(void *buttonGroup, const QString argValue);
4343
static QString getDoubleSpinBox(void *doubleSpinBox);
4444
static QString getSpinBox(void *spinBox);
4545
static QString getCheckBox(void *checkBox);
@@ -61,41 +61,41 @@ class argAction
6161
explicit argAction();
6262
~argAction();
6363

64-
bool setValue(QString key, QString value);
64+
bool setValue(const QString key, const QString value);
6565

66-
QStringList getAllArgs(bool getCommentedOptions = false, bool getDisabledObjects = false);
66+
QStringList getAllArgs(const bool getCommentedOptions = false, const bool getDisabledObjects = false);
6767

68-
inline void insert( QString argName, QDoubleSpinBox *doubleSpinBox, bool commentedOption = false )
68+
inline void insert( const QString argName, QDoubleSpinBox *doubleSpinBox, const bool commentedOption = false )
6969
{
7070
argList.insert( argName, (argElement){ .setFunction = &setDoubleSpinBox, .getFunction = &getDoubleSpinBox,
7171
.object = doubleSpinBox, .commentedOption = commentedOption } );
7272
}
7373

74-
inline void insert( QString argName, QSpinBox *spinBox, bool commentedOption = false )
74+
inline void insert( const QString argName, QSpinBox *spinBox, const bool commentedOption = false )
7575
{
7676
argList.insert( argName, (argElement){ .setFunction = &setSpinBox, .getFunction = &getSpinBox,
7777
.object = spinBox, .commentedOption = commentedOption } );
7878
}
7979

80-
inline void insert( QString argName, QCheckBox *checkBox, bool commentedOption = false )
80+
inline void insert( const QString argName, QCheckBox *checkBox, const bool commentedOption = false )
8181
{
8282
argList.insert( argName, (argElement){ .setFunction = &setCheckBox, .getFunction = &getCheckBox,
8383
.object = checkBox, .commentedOption = commentedOption } );
8484
}
8585

86-
inline void insert( QString argName, QLineEdit *lineEdit, bool commentedOption = false )
86+
inline void insert( const QString argName, QLineEdit *lineEdit, const bool commentedOption = false )
8787
{
8888
argList.insert( argName, (argElement){ .setFunction = &setLineEdit, .getFunction = &getLineEdit,
8989
.object = lineEdit, .commentedOption = commentedOption } );
9090
}
9191

92-
inline void insert( QString argName, QComboBox *comboBox, bool commentedOption = false )
92+
inline void insert( const QString argName, QComboBox *comboBox, const bool commentedOption = false )
9393
{
9494
argList.insert( argName, (argElement){ .setFunction = &setComboBox, .getFunction = &getComboBox,
9595
.object = comboBox, .commentedOption = commentedOption } );
9696
}
9797

98-
inline void insert( QString argName, QButtonGroup *buttonGroup, bool commentedOption = false )
98+
inline void insert( const QString argName, QButtonGroup *buttonGroup, const bool commentedOption = false )
9999
{
100100
argList.insert( argName, (argElement){ .setFunction = &setButtonGroup, .getFunction = &getButtonGroup,
101101
.object = buttonGroup, .commentedOption = commentedOption } );

mainwindow.cpp

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ MainWindow::MainWindow(QWidget *parent) :
9494
args[ AUTOLEVELLERARGS ].insert("software", ui->softwareComboBox);
9595
args[ AUTOLEVELLERARGS ].insert("al-x", ui->alxDoubleSpinBox);
9696
args[ AUTOLEVELLERARGS ].insert("al-y", ui->alyDoubleSpinBox);
97-
args[ AUTOLEVELLERARGS ].insert("al-probefeed", ui->alprobefeedDoubleSpinBox);
97+
args[ AUTOLEVELLERARGS ].insert("al-probefeed", ui->alprobefeedSpinBox);
9898
args[ AUTOLEVELLERARGS ].insert("al-probeon", ui->alprobeonLineEdit);
9999
args[ AUTOLEVELLERARGS ].insert("al-probeoff", ui->alprobeoffLineEdit);
100100

@@ -171,7 +171,7 @@ void MainWindow::getPostambleFile()
171171
getFilename(ui->postambleLineEdit, "postamble file");
172172
}
173173

174-
void MainWindow::getFilename(QLineEdit *saveTo, QString name)
174+
void MainWindow::getFilename(QLineEdit *saveTo, const QString name)
175175
{
176176
QString filename;
177177

@@ -191,49 +191,43 @@ void MainWindow::getOutputDirectory()
191191

192192
void MainWindow::changeMetricInputUnits(bool metric)
193193
{
194-
int index;
195-
double cfactor;
196-
const char *distance[2] = { " mm", " in" };
197-
const char *speedMin[2] = { " mm/min", " in/min" };
198-
const char *speedSec[2] = { " mm/s", " in/s" };
194+
QDoubleSpinBox *doubleSpinBoxes[] = { ui->zworkDoubleSpinBox, ui->zsafeDoubleSpinBox, ui->offsetDoubleSpinBox,
195+
ui->zdrillDoubleSpinBox, ui->zchangeDoubleSpinBox, ui->cutterdiameterDoubleSpinBox,
196+
ui->zcutDoubleSpinBox, ui->cutinfeedDoubleSpinBox, ui->outlinewidthDoubleSpinBox,
197+
ui->bridgesDoubleSpinBox, ui->zbridgesDoubleSpinBox, ui->alxDoubleSpinBox,
198+
ui->alyDoubleSpinBox, ui->g64DoubleDoubleSpinBox };
199199

200-
QDoubleSpinBox *doubleSpinBoxes[] = { ui->zworkDoubleSpinBox, ui->zsafeDoubleSpinBox,ui->offsetDoubleSpinBox, ui->zdrillDoubleSpinBox,
201-
ui->zchangeDoubleSpinBox, ui->cutterdiameterDoubleSpinBox, ui->zcutDoubleSpinBox,
202-
ui->cutinfeedDoubleSpinBox, ui->outlinewidthDoubleSpinBox, ui->bridgesDoubleSpinBox,
203-
ui->zbridgesDoubleSpinBox, ui->alxDoubleSpinBox, ui->alyDoubleSpinBox,
204-
ui->g64DoubleDoubleSpinBox };
200+
QSpinBox *spinBoxes[] = { ui->millfeedSpinBox, ui->drillfeedSpinBox, ui->cutfeedSpinBox, ui->alprobefeedSpinBox };
205201

206202
const unsigned int doubleSpinBoxesLen = sizeof(doubleSpinBoxes) / sizeof(doubleSpinBoxes[0]);
207-
208-
if (metric)
209-
{
210-
index = 0;
211-
cfactor = 1/2.54;
212-
}
213-
else
214-
{
215-
index = 1;
216-
cfactor = 2.54;
217-
}
203+
const unsigned int spinBoxesLen = sizeof(spinBoxes) / sizeof(spinBoxes[0]);
204+
const double cfactor = metric ? 1/2.54 : 2.54;
205+
const char *distance = metric ? " mm" : " in" ;
206+
const char *speed = metric ? " mm/min" : " in/min" ;
218207

219208
for( unsigned int i = 0; i < doubleSpinBoxesLen; i++ )
220-
adjustMetricImperial( doubleSpinBoxes[i], cfactor, distance[index] );
209+
adjustMetricImperial( doubleSpinBoxes[i], cfactor, distance );
221210

222-
adjustMetricImperial( ui->millfeedSpinBox, cfactor, speedMin[index] );
223-
adjustMetricImperial( ui->drillfeedSpinBox, cfactor, speedMin[index] );
224-
adjustMetricImperial( ui->cutfeedSpinBox, cfactor, speedMin[index] );
225-
adjustMetricImperial( ui->alprobefeedDoubleSpinBox, cfactor, speedSec[index] );
211+
for( unsigned int i = 0; i < spinBoxesLen; i++ )
212+
adjustMetricImperial( spinBoxes[i], cfactor, speed );
226213
}
227214

228215
void MainWindow::adjustMetricImperial(QSpinBox *spinBox, const double cfactor, const QString suffix)
229216
{
230-
int value = spinBox->value();
231-
int maximum = spinBox->maximum();
232-
int minimum = spinBox->minimum();
217+
int value;
218+
int maximum;
219+
int minimum;
233220

234-
spinBox->setMaximum( round( maximum * cfactor ) );
235-
spinBox->setMinimum( round( minimum * cfactor ) );
236-
spinBox->setValue( round( value * cfactor ) );
221+
if( changeMetricImperialValues )
222+
{
223+
value = spinBox->value();
224+
maximum = spinBox->maximum();
225+
minimum = spinBox->minimum();
226+
227+
spinBox->setMaximum( round( maximum * cfactor ) );
228+
spinBox->setMinimum( round( minimum * cfactor ) );
229+
spinBox->setValue( round( value * cfactor ) );
230+
}
237231

238232
spinBox->setSuffix(suffix);
239233
}
@@ -455,7 +449,7 @@ void MainWindow::askAndLoadConfFile()
455449
QMessageBox::information(this, "Error", "The selected file can't be opened");
456450
}
457451

458-
bool MainWindow::loadConfFile(QString filename)
452+
bool MainWindow::loadConfFile(const QString filename)
459453
{
460454
QFile confFile (this);
461455
QString currentLine;
@@ -508,7 +502,7 @@ void MainWindow::askAndSaveConfFile()
508502
saveConfFile(filename);
509503
}
510504

511-
void MainWindow::saveConfFile(QString filename)
505+
void MainWindow::saveConfFile(const QString filename)
512506
{
513507
QFile confFile (this);
514508
QStringList arguments;

mainwindow.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,12 @@ private slots:
9595
QPlainTextEdit *outputTextEdit;
9696
QPushButton *killClosePushButton;
9797

98-
void enableImperialMetricAdjustment(bool enable);
9998
QStringList getCmdLineArguments();
100-
void getFilename(QLineEdit *saveTo, QString name);
99+
void getFilename(QLineEdit *saveTo, const QString name);
101100
void adjustMetricImperial(QSpinBox *spinBox, const double cfactor, const QString suffix);
102101
void adjustMetricImperial(QDoubleSpinBox *doubleSpinBox, const double cfactor, const QString suffix);
103-
void saveConfFile(QString filename);
104-
bool loadConfFile(QString filename);
102+
void saveConfFile(const QString filename);
103+
bool loadConfFile(const QString filename);
105104
void loadDefaultConfFile();
106105
};
107106

0 commit comments

Comments
 (0)