2020-08-31 04:03:41 +08:00
|
|
|
#include "calkitdialog.h"
|
2021-10-21 19:00:34 +08:00
|
|
|
|
2020-08-31 04:03:41 +08:00
|
|
|
#include "ui_calkitdialog.h"
|
2021-10-21 19:00:34 +08:00
|
|
|
#include "CustomWidgets/informationbox.h"
|
2020-08-31 04:03:41 +08:00
|
|
|
|
2021-10-21 19:00:34 +08:00
|
|
|
#include <QPushButton>
|
2020-08-31 04:03:41 +08:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <fstream>
|
|
|
|
#include <touchstone.h>
|
|
|
|
#include <QtGlobal>
|
2022-08-26 06:46:53 +08:00
|
|
|
#include <QAction>
|
|
|
|
#include <QMenu>
|
2020-08-31 04:03:41 +08:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
CalkitDialog::CalkitDialog(Calkit &c, QWidget *parent) :
|
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::CalkitDialog),
|
2022-08-26 06:46:53 +08:00
|
|
|
kit(c)
|
2020-08-31 04:03:41 +08:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2022-08-26 06:46:53 +08:00
|
|
|
updateEntries();
|
2021-11-28 06:32:41 +08:00
|
|
|
|
2022-08-26 06:46:53 +08:00
|
|
|
connect(ui->bDelete, &QPushButton::clicked, [=](){
|
|
|
|
auto row = ui->list->currentRow();
|
|
|
|
if(row >= 0) {
|
|
|
|
delete kit.standards[row];
|
|
|
|
kit.standards.erase(kit.standards.begin() + row);
|
|
|
|
updateStandardList();
|
2021-11-28 06:32:41 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-08-26 06:46:53 +08:00
|
|
|
connect(ui->bMoveUp, &QPushButton::clicked, [=](){
|
|
|
|
auto row = ui->list->currentRow();
|
|
|
|
if(row >= 1) {
|
|
|
|
swap(kit.standards[row], kit.standards[row-1]);
|
|
|
|
ui->list->setCurrentRow(row-1);
|
|
|
|
updateStandardList();
|
|
|
|
}
|
2020-10-03 19:01:59 +08:00
|
|
|
});
|
|
|
|
|
2022-08-26 06:46:53 +08:00
|
|
|
connect(ui->bMoveDown, &QPushButton::clicked, [=](){
|
|
|
|
auto row = ui->list->currentRow();
|
|
|
|
if(row < ui->list->count() - 1) {
|
|
|
|
swap(kit.standards[row], kit.standards[row+1]);
|
|
|
|
ui->list->setCurrentRow(row+1);
|
|
|
|
updateStandardList();
|
2021-11-28 06:32:41 +08:00
|
|
|
}
|
2022-08-26 06:46:53 +08:00
|
|
|
});
|
2020-08-31 04:03:41 +08:00
|
|
|
|
2022-08-26 06:46:53 +08:00
|
|
|
connect(ui->list, &QListWidget::currentRowChanged, this, &CalkitDialog::updateListEditButtons);
|
2020-08-31 04:03:41 +08:00
|
|
|
|
2022-08-26 06:46:53 +08:00
|
|
|
auto addMenu = new QMenu();
|
|
|
|
for(auto t : CalStandard::Virtual::availableTypes()) {
|
|
|
|
auto action = new QAction(CalStandard::Virtual::TypeToString(t));
|
|
|
|
connect(action, &QAction::triggered, [=](){
|
|
|
|
auto newStandard = CalStandard::Virtual::create(t);
|
|
|
|
if(newStandard) {
|
|
|
|
kit.standards.push_back(newStandard);
|
|
|
|
updateStandardList();
|
|
|
|
// start the edit dialog of the newly created standard
|
|
|
|
kit.standards.back()->edit(bind(&CalkitDialog::updateStandardList, this));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
addMenu->addAction(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->bAdd->setMenu(addMenu);
|
|
|
|
|
2022-08-27 01:25:24 +08:00
|
|
|
updateStandardList();
|
|
|
|
|
2022-08-26 06:46:53 +08:00
|
|
|
connect(ui->list, &QListWidget::doubleClicked, [=](const QModelIndex &index){
|
|
|
|
if(!index.isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
kit.standards[index.row()]->edit(bind(&CalkitDialog::updateStandardList, this));
|
2020-08-31 04:03:41 +08:00
|
|
|
});
|
|
|
|
|
2022-01-02 03:11:03 +08:00
|
|
|
connect(ui->buttonBox->button(QDialogButtonBox::Apply), &QPushButton::clicked, [this]() {
|
|
|
|
parseEntries();
|
|
|
|
emit settingsChanged();
|
|
|
|
});
|
2020-08-31 04:03:41 +08:00
|
|
|
connect(ui->buttonBox->button(QDialogButtonBox::Ok), &QPushButton::clicked, [this]() {
|
|
|
|
parseEntries();
|
2022-01-02 03:11:03 +08:00
|
|
|
emit settingsChanged();
|
2020-11-15 03:43:36 +08:00
|
|
|
accept();
|
2020-08-31 04:03:41 +08:00
|
|
|
});
|
|
|
|
connect(ui->buttonBox->button(QDialogButtonBox::Open), &QPushButton::clicked, [=](){
|
|
|
|
auto filename = QFileDialog::getOpenFileName(this, "Open calibration kit coefficients", "", "Calibration kit files (*.calkit)", nullptr, QFileDialog::DontUseNativeDialog);
|
|
|
|
if(filename.length() > 0) {
|
2021-10-13 02:52:11 +08:00
|
|
|
try {
|
2022-08-26 06:46:53 +08:00
|
|
|
kit = Calkit::fromFile(filename);
|
2022-03-17 19:53:13 +08:00
|
|
|
} catch (runtime_error &e) {
|
2021-10-13 03:58:44 +08:00
|
|
|
InformationBox::ShowError("Error", "The calibration kit file could not be parsed (" + QString(e.what()) + ")");
|
2021-10-13 02:52:11 +08:00
|
|
|
qWarning() << "Parsing of calibration kit failed while opening calibration file: " << e.what();
|
|
|
|
}
|
2020-08-31 04:03:41 +08:00
|
|
|
updateEntries();
|
2022-08-27 01:25:24 +08:00
|
|
|
updateStandardList();
|
2020-08-31 04:03:41 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(ui->buttonBox->button(QDialogButtonBox::Save), &QPushButton::clicked, [=](){
|
|
|
|
auto filename = QFileDialog::getSaveFileName(this, "Save calibration kit coefficients", "", "Calibration kit files (*.calkit)", nullptr, QFileDialog::DontUseNativeDialog);
|
|
|
|
if(filename.length() > 0) {
|
|
|
|
parseEntries();
|
2022-08-26 06:46:53 +08:00
|
|
|
kit.toFile(filename);
|
2020-08-31 04:03:41 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
CalkitDialog::~CalkitDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2022-08-26 06:46:53 +08:00
|
|
|
void CalkitDialog::updateListEditButtons()
|
2020-08-31 04:03:41 +08:00
|
|
|
{
|
2022-08-26 06:46:53 +08:00
|
|
|
ui->bDelete->setEnabled(ui->list->currentRow() >= 0);
|
|
|
|
ui->bMoveUp->setEnabled(ui->list->currentRow() >= 1);
|
|
|
|
ui->bMoveDown->setEnabled(ui->list->currentRow() >= 0 && ui->list->currentRow() < ui->list->count() - 1);
|
|
|
|
}
|
2020-11-08 21:30:19 +08:00
|
|
|
|
2022-08-26 06:46:53 +08:00
|
|
|
void CalkitDialog::parseEntries()
|
|
|
|
{
|
|
|
|
kit.manufacturer = ui->manufacturer->text();
|
|
|
|
kit.serialnumber = ui->serialnumber->text();
|
|
|
|
kit.description = ui->description->toPlainText();
|
2020-08-31 04:03:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CalkitDialog::updateEntries()
|
|
|
|
{
|
2022-08-26 06:46:53 +08:00
|
|
|
ui->manufacturer->setText(kit.manufacturer);
|
|
|
|
ui->serialnumber->setText(kit.serialnumber);
|
|
|
|
ui->description->setPlainText(kit.description);
|
|
|
|
}
|
2021-11-28 06:32:41 +08:00
|
|
|
|
2022-08-26 06:46:53 +08:00
|
|
|
void CalkitDialog::updateStandardList()
|
|
|
|
{
|
|
|
|
auto row = ui->list->currentRow();
|
|
|
|
ui->list->clear();
|
|
|
|
for(auto s : kit.standards) {
|
|
|
|
ui->list->addItem(s->getDescription());
|
2020-10-03 19:01:59 +08:00
|
|
|
}
|
2022-08-26 06:46:53 +08:00
|
|
|
if(row >= 0) {
|
|
|
|
if(row < ui->list->count()) {
|
|
|
|
ui->list->setCurrentRow(row);
|
|
|
|
} else if(ui->list->count() > 0) {
|
|
|
|
ui->list->setCurrentRow(ui->list->count() - 1);
|
|
|
|
}
|
2020-11-08 21:30:19 +08:00
|
|
|
}
|
2022-08-26 06:46:53 +08:00
|
|
|
updateListEditButtons();
|
2020-08-31 04:03:41 +08:00
|
|
|
}
|