21 |
21 |
22 |
22 |
23 |
23 |
24 Setup::Setup(QWidget *parent) : QDialog(parent), ui(new Ui::Setup) |
24 Setup::Setup(QWidget *parent) : QDialog(parent), ui(new Ui::Setup) |
25 { |
25 { |
|
26 QSqlQuery query; |
|
27 |
26 qDebug() << "Setup start"; |
28 qDebug() << "Setup start"; |
|
29 ui->setupUi(this); |
|
30 setWindowTitle( QString("BMSapp - %1 - Setup").arg(VERSIONSTRING) ); |
27 |
31 |
28 ui->setupUi(this); |
32 query.prepare("SELECT * FROM profile_setup WHERE record='1'"); |
|
33 query.exec(); |
|
34 query.next(); |
29 |
35 |
30 setWindowTitle( QString("BMSapp - %1 - Setup").arg(VERSIONSTRING) ); |
36 ui->breweryEdit->setText(query.value(1).toString()); // max 128 |
|
37 |
|
38 ui->fwhEdit->setValue(query.value(4).toInt()); |
|
39 ui->mashhopEdit->setValue(query.value(3).toInt()); |
|
40 ui->pelletEdit->setValue(query.value(5).toInt()); |
|
41 ui->hopplugEdit->setValue(query.value(6).toInt()); |
|
42 ui->wethopEdit->setValue(query.value(7).toInt()); |
|
43 ui->cryohopEdit->setValue(query.value(8).toInt()); |
|
44 connect(ui->fwhEdit, &QSpinBox::textChanged, this, &Setup::is_changed); |
|
45 connect(ui->mashhopEdit, &QSpinBox::textChanged, this, &Setup::is_changed); |
|
46 connect(ui->pelletEdit, &QSpinBox::textChanged, this, &Setup::is_changed); |
|
47 connect(ui->hopplugEdit, &QSpinBox::textChanged, this, &Setup::is_changed); |
|
48 connect(ui->wethopEdit, &QSpinBox::textChanged, this, &Setup::is_changed); |
|
49 connect(ui->cryohopEdit, &QSpinBox::textChanged, this, &Setup::is_changed); |
|
50 |
|
51 ui->grainEdit->setValue(query.value(12).toDouble()); |
|
52 ui->brixEdit->setValue(query.value(11).toDouble()); |
|
53 connect(ui->grainEdit, &QDoubleSpinBox::textChanged, this, &Setup::is_changed); |
|
54 connect(ui->brixEdit, &QDoubleSpinBox::textChanged, this, &Setup::is_changed); |
|
55 |
|
56 ui->colorEdit->addItem(tr("Morey")); |
|
57 ui->colorEdit->addItem(tr("Mosher")); |
|
58 ui->colorEdit->addItem(tr("Daniels")); |
|
59 ui->colorEdit->addItem(tr("Halberstadt")); |
|
60 ui->colorEdit->addItem(tr("Naudts")); |
|
61 ui->colorEdit->setEditable(true); |
|
62 ui->colorEdit->setCurrentIndex(query.value(10).toInt()); |
|
63 connect(ui->colorEdit, &QComboBox::currentTextChanged, this, &Setup::is_changed); |
|
64 |
|
65 ui->ibuEdit->addItem(tr("Tinseth")); |
|
66 ui->ibuEdit->addItem(tr("Rager")); |
|
67 ui->ibuEdit->addItem(tr("Daniels")); |
|
68 ui->ibuEdit->setEditable(true); |
|
69 ui->ibuEdit->setCurrentIndex(query.value(9).toInt()); |
|
70 connect(ui->ibuEdit, &QComboBox::currentTextChanged, this, &Setup::is_changed); |
|
71 |
|
72 QSqlQuery query2("SELECT record,name FROM inventory_waters"); |
|
73 query2.first(); |
|
74 int pos = -1; |
|
75 ui->waterEdit->setEditable(true); |
|
76 ui->waterEdit->setPlaceholderText(tr("Choose default water")); |
|
77 for (int i = 0 ; i < query2.size() ; i++ ) { |
|
78 ui->waterEdit->addItem(query2.value(1).toString()); |
|
79 if (query2.value(0).toInt() == query.value(13).toInt()) { |
|
80 pos = i; |
|
81 } |
|
82 query2.next(); |
|
83 } |
|
84 if (pos >= 0) |
|
85 ui->waterEdit->setCurrentIndex(pos); |
|
86 connect(ui->waterEdit, &QComboBox::currentTextChanged, this, &Setup::is_changed); |
|
87 |
|
88 QSqlQuery query3("SELECT DISTINCT laboratory FROM inventory_yeasts ORDER BY laboratory"); |
|
89 query3.first(); |
|
90 pos = -1; |
|
91 ui->yeastEdit->setEditable(true); |
|
92 ui->yeastEdit->setPlaceholderText(tr("Choose laboratory")); |
|
93 for (int i = 0 ; i < query3.size() ; i++ ) { |
|
94 ui->yeastEdit->addItem(query3.value(0).toString()); |
|
95 if (QString::compare(query.value(14).toString(), query3.value(0).toString(), Qt::CaseSensitive) == 0) |
|
96 pos = i; |
|
97 query3.next(); |
|
98 } |
|
99 if (pos >= 0) |
|
100 ui->yeastEdit->setCurrentIndex(pos); |
|
101 connect(ui->yeastEdit, &QComboBox::currentTextChanged, this, &Setup::is_changed); |
|
102 |
|
103 // query.value(2).toString() logo varchar(1024) |
31 } |
104 } |
32 |
105 |
33 |
106 |
34 Setup::~Setup() |
107 Setup::~Setup() |
35 { |
108 { |
36 qDebug() << "Setup done"; |
109 qDebug() << "Setup done"; |
37 delete ui; |
110 delete ui; |
38 } |
111 } |
39 |
112 |
40 |
113 |
|
114 /* |
|
115 * Also called from the Quit button if there are changes to save. |
|
116 */ |
|
117 void Setup::on_saveButton_clicked() |
|
118 { |
|
119 QSqlQuery query; |
|
120 |
|
121 /* |
|
122 * Search record number of the current water. |
|
123 */ |
|
124 query.prepare("SELECT record FROM inventory_waters WHERE name=:name"); |
|
125 query.bindValue(":name", ui->waterEdit->currentText()); |
|
126 query.exec(); |
|
127 query.first(); |
|
128 int record = query.value(0).toInt(); |
|
129 |
|
130 /* |
|
131 * Update all other data |
|
132 */ |
|
133 query.prepare("UPDATE profile_setup SET brewery_name=:brewery, factor_mashhop=:mashhop, factor_fwh=:fwh, factor_pellet=:pellet, " |
|
134 "factor_plug=:plug, factor_wethop=:wet, factor_cryohop=:cryo, color_method=:color, ibu_method=:ibu, " |
|
135 "brix_correction=:brix, grain_absorbtion=:grain, default_water=:water, my_yeastlab=:yeast WHERE record='1'"); |
|
136 query.bindValue(":brewery", ui->breweryEdit->text()); |
|
137 query.bindValue(":mashhop", ui->mashhopEdit->value()); |
|
138 query.bindValue(":fwh", ui->fwhEdit->value()); |
|
139 query.bindValue(":pellet", ui->pelletEdit->value()); |
|
140 query.bindValue(":plug", ui->hopplugEdit->value()); |
|
141 query.bindValue(":wet", ui->wethopEdit->value()); |
|
142 query.bindValue(":cryo", ui->cryohopEdit->value()); |
|
143 query.bindValue(":color", ui->colorEdit->currentIndex()); |
|
144 query.bindValue(":ibu", ui->ibuEdit->currentIndex()); |
|
145 query.bindValue(":brix", ui->brixEdit->value()); |
|
146 query.bindValue(":grain", ui->grainEdit->value()); |
|
147 query.bindValue(":water", record); |
|
148 query.bindValue(":yeast", ui->yeastEdit->currentText()); |
|
149 query.exec(); |
|
150 if (query.lastError().isValid()) { |
|
151 qDebug() << "Setup Save error:" << query.lastError(); |
|
152 QMessageBox::warning(this, tr("Database error"), |
|
153 tr("MySQL error: %1\n%2\n%3") |
|
154 .arg(query.lastError().nativeErrorCode()) |
|
155 .arg(query.lastError().driverText()) |
|
156 .arg(query.lastError().databaseText())); |
|
157 } else { |
|
158 qDebug() << "Setup Saved"; |
|
159 } |
|
160 |
|
161 this->fieldIsChanged = false; |
|
162 setWindowTitle( QString("BMSapp - %1 - Setup").arg(VERSIONSTRING) ); |
|
163 } |
|
164 |
|
165 |
41 void Setup::on_quitButton_clicked() |
166 void Setup::on_quitButton_clicked() |
42 { |
167 { |
|
168 if (this->fieldIsChanged) { |
|
169 int rc = QMessageBox::warning(this, tr("Setup changed"), tr("The setup has been modified\n Save changes?"), |
|
170 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save); |
|
171 switch (rc) { |
|
172 case QMessageBox::Save: |
|
173 on_saveButton_clicked(); |
|
174 break; /* Saved and then Quit */ |
|
175 case QMessageBox::Discard: |
|
176 break; /* Quit without Save */ |
|
177 case QMessageBox::Cancel: |
|
178 return; /* Return to the setup page */ |
|
179 } |
|
180 } |
43 emit firstWindow(); |
181 emit firstWindow(); |
44 } |
182 } |
45 |
183 |
|
184 |
|
185 void Setup::is_changed() |
|
186 { |
|
187 this->fieldIsChanged = true; |
|
188 setWindowTitle( QString("BMSapp - %1 - Setup **").arg(VERSIONSTRING) ); |
|
189 } |