134 } |
135 } |
135 |
136 |
136 std::sort(nCal.begin() , nCal.end(), [=]( const Calibrate& test1 , const Calibrate& test2 )->bool { |
137 std::sort(nCal.begin() , nCal.end(), [=]( const Calibrate& test1 , const Calibrate& test2 )->bool { |
137 return test2.angle < test1.angle; |
138 return test2.angle < test1.angle; |
138 }); |
139 }); |
|
140 this->dataHasErrors = false; |
139 |
141 |
140 for (int i = 0; i < newtotal; i++) { |
142 for (int i = 0; i < newtotal; i++) { |
141 qDebug() << i << nCal[i].sg << nCal[i].plato << nCal[i].angle; |
143 qDebug() << i << nCal[i].sg << nCal[i].plato << nCal[i].angle; |
142 |
144 |
143 y[i] = nCal[i].plato; |
145 y[i] = nCal[i].plato; |
144 x[i] = nCal[i].angle; |
146 x[i] = nCal[i].angle; |
|
147 |
|
148 gerror = aerror = false; |
|
149 if ((nCal[i].angle < 10) || (nCal[i].angle > 80)) |
|
150 aerror = true; |
|
151 if (i == 0) { |
|
152 if (nCal[0].plato <= nCal[1].plato) |
|
153 gerror = true; |
|
154 } else if (i == (newtotal -1)) { |
|
155 if (nCal[i].plato != 0) |
|
156 gerror = true; |
|
157 } else { |
|
158 if ((nCal[i].plato <= nCal[i + 1].plato) || (nCal[i].plato >= nCal[i - 1].plato)) |
|
159 gerror = true; |
|
160 } |
|
161 if (gerror || aerror) |
|
162 this->dataHasErrors = true; |
145 |
163 |
146 w = QString("%1").arg(nCal[i].sg, 1, 'f', 4, '0'); |
164 w = QString("%1").arg(nCal[i].sg, 1, 'f', 4, '0'); |
147 QTableWidgetItem *item = new QTableWidgetItem(w); |
165 QTableWidgetItem *item = new QTableWidgetItem(w); |
148 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); |
166 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); |
|
167 if (gerror) |
|
168 item->setForeground(QBrush(QColor(Qt::red))); |
149 ui->dataTable->setItem(i, 0, item); |
169 ui->dataTable->setItem(i, 0, item); |
150 |
170 |
151 w = QString("%1").arg(nCal[i].plato, 1, 'f', 3, '0'); |
171 w = QString("%1").arg(nCal[i].plato, 1, 'f', 3, '0'); |
152 item = new QTableWidgetItem(w); |
172 item = new QTableWidgetItem(w); |
153 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); |
173 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); |
|
174 if (gerror) |
|
175 item->setForeground(QBrush(QColor(Qt::red))); |
154 ui->dataTable->setItem(i, 1, item); |
176 ui->dataTable->setItem(i, 1, item); |
155 |
177 |
156 w = QString("%1").arg(nCal[i].angle, 1, 'f', 5, '0'); |
178 w = QString("%1").arg(nCal[i].angle, 1, 'f', 5, '0'); |
157 item = new QTableWidgetItem(w); |
179 item = new QTableWidgetItem(w); |
158 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); |
180 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); |
|
181 if (aerror) |
|
182 item->setForeground(QBrush(QColor(Qt::red))); |
159 ui->dataTable->setItem(i, 2, item); |
183 ui->dataTable->setItem(i, 2, item); |
160 |
184 |
161 /* Add the Delete row button */ |
185 /* Add the Delete row button */ |
162 pWidget = new QWidget(); |
186 pWidget = new QWidget(); |
163 QPushButton* btn_del = new QPushButton(); |
187 QPushButton* btn_del = new QPushButton(); |
180 * Check the new formula against the old formula. |
204 * Check the new formula against the old formula. |
181 */ |
205 */ |
182 this->textIsChanged = (_data_old.compare(_data_new) == 0) ? false:true; |
206 this->textIsChanged = (_data_old.compare(_data_new) == 0) ? false:true; |
183 qDebug() << "changed" << this->textIsChanged << _data_old.compare(_data_new); |
207 qDebug() << "changed" << this->textIsChanged << _data_old.compare(_data_new); |
184 CalibrateiSpindel::WindowTitle(); |
208 CalibrateiSpindel::WindowTitle(); |
185 ui->saveButton->setEnabled(this->textIsChanged); |
|
186 |
209 |
187 new_plot = new QLineSeries(); |
210 new_plot = new QLineSeries(); |
188 old_plot = new QLineSeries(); |
211 old_plot = new QLineSeries(); |
189 |
212 |
190 for (int i = 0; i < oldtotal; i++) { |
213 for (int i = 0; i < oldtotal; i++) { |
240 if (this->textIsChanged) { |
263 if (this->textIsChanged) { |
241 int rc = QMessageBox::warning(this, tr("iSpindel calibrate changed"), tr("The calibration data has been modified. Save changes?"), |
264 int rc = QMessageBox::warning(this, tr("iSpindel calibrate changed"), tr("The calibration data has been modified. Save changes?"), |
242 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save); |
265 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save); |
243 switch (rc) { |
266 switch (rc) { |
244 case QMessageBox::Save: |
267 case QMessageBox::Save: |
245 on_saveButton_clicked(); |
268 if (this->dataHasErrors) { |
|
269 QMessageBox::warning(this, tr("iSpindel calibrate"), tr("Data is changed but has errors, not saving.")); |
|
270 return; /* Return to the editor page */ |
|
271 } else { |
|
272 SaveData(); |
|
273 } |
246 break; /* Saved and then Quit */ |
274 break; /* Saved and then Quit */ |
247 case QMessageBox::Discard: |
275 case QMessageBox::Discard: |
248 break; /* Quit without Save */ |
276 break; /* Quit without Save */ |
249 case QMessageBox::Cancel: |
277 case QMessageBox::Cancel: |
250 return; /* Return to the editor page */ |
278 return; /* Return to the editor page */ |