Adopt to C++20

This commit is contained in:
Martin Brodbeck 2022-07-07 15:31:32 +02:00
parent acc3095e60
commit 2b7c099f5e
3 changed files with 56 additions and 59 deletions

View file

@ -4,7 +4,7 @@ project(kima2 VERSION 1.5.3)
set(CMAKE_MODULE_PATH "${CMAKE_HOME_DIRECTORY}/cmake") set(CMAKE_MODULE_PATH "${CMAKE_HOME_DIRECTORY}/cmake")
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
#include(InstallRequiredSystemLibraries) #include(InstallRequiredSystemLibraries)

View file

@ -1,12 +1,12 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "basketmodel.h" #include "basketmodel.h"
#include <config.h>
#include "pricedialog.h" #include "pricedialog.h"
#include "reportdialog.h" #include "reportdialog.h"
#include "salemodel.h" #include "salemodel.h"
#include "sellerdialog.h" #include "sellerdialog.h"
#include "settingsdialog.h" #include "settingsdialog.h"
#include <config.h>
#include <core/csvreader.h> #include <core/csvreader.h>
#include <core/excelreader.h> #include <core/excelreader.h>
@ -44,7 +44,7 @@ MainWindow::MainWindow()
} }
statusBar()->showMessage("Gespeicherte Daten wurden geladen.", STATUSBAR_TIMEOUT); statusBar()->showMessage("Gespeicherte Daten wurden geladen.", STATUSBAR_TIMEOUT);
BasketModel* model = new BasketModel(getMarketplace(), ui_.basketView); BasketModel *model = new BasketModel(getMarketplace(), ui_.basketView);
ui_.basketView->setModel(model); ui_.basketView->setModel(model);
ui_.basketView->setColumnHidden(0, true); // hide the uuid ui_.basketView->setColumnHidden(0, true); // hide the uuid
@ -55,7 +55,7 @@ MainWindow::MainWindow()
connect(ui_.actionQuit, &QAction::triggered, qApp, QApplication::closeAllWindows, connect(ui_.actionQuit, &QAction::triggered, qApp, QApplication::closeAllWindows,
Qt::QueuedConnection); Qt::QueuedConnection);
connect(ui_.newAction, &QAction::triggered, this, [=]() { connect(ui_.newAction, &QAction::triggered, this, [this]() {
if (marketplace_->getSellers().size() == 0 && marketplace_->getSales().size() == 0) { if (marketplace_->getSellers().size() == 0 && marketplace_->getSales().size() == 0) {
return; return;
} }
@ -69,7 +69,7 @@ MainWindow::MainWindow()
return; return;
delete ui_.salesView->model(); delete ui_.salesView->model();
dynamic_cast<BasketModel*>(ui_.basketView->model())->cancelSale(); dynamic_cast<BasketModel *>(ui_.basketView->model())->cancelSale();
marketplace_->clear(); marketplace_->clear();
setSaleModel(); setSaleModel();
updateStatLabel(); updateStatLabel();
@ -105,7 +105,7 @@ MainWindow::MainWindow()
} }
} }
}); });
connect(ui_.licenseAction, &QAction::triggered, this, [=]() { connect(ui_.licenseAction, &QAction::triggered, this, [this]() {
QString licenseText( QString licenseText(
"Copyright © 2018-2021 Martin Brodbeck\n\n" "Copyright © 2018-2021 Martin Brodbeck\n\n"
"Hiermit wird unentgeltlich jeder Person, die eine Kopie der Software und der " "Hiermit wird unentgeltlich jeder Person, die eine Kopie der Software und der "
@ -126,10 +126,8 @@ MainWindow::MainWindow()
"SOFTWARE ODER SONSTIGER VERWENDUNG DER SOFTWARE ENTSTANDEN."); "SOFTWARE ODER SONSTIGER VERWENDUNG DER SOFTWARE ENTSTANDEN.");
QMessageBox::information(this, "Lizenzinformation", licenseText); QMessageBox::information(this, "Lizenzinformation", licenseText);
}); });
connect(ui_.reportAction, &QAction::triggered, this, [=]() { connect(ui_.reportAction, &QAction::triggered, this, [this]() { ReportDialog(this).exec(); });
ReportDialog(this).exec(); connect(ui_.configAction, &QAction::triggered, this, [this]() {
});
connect(ui_.configAction, &QAction::triggered, this, [=]() {
int result = SettingsDialog(this).exec(); int result = SettingsDialog(this).exec();
if (result == QDialog::Accepted) { if (result == QDialog::Accepted) {
delete ui_.salesView->model(); delete ui_.salesView->model();
@ -189,8 +187,8 @@ void MainWindow::setSaleModel()
ui_.printSaleReceiptButton->setEnabled(false); ui_.printSaleReceiptButton->setEnabled(false);
ui_.cancelSaleButton->setEnabled(false); ui_.cancelSaleButton->setEnabled(false);
connect(static_cast<BasketModel*>(ui_.basketView->model()), &BasketModel::basketDataChanged, connect(static_cast<BasketModel *>(ui_.basketView->model()), &BasketModel::basketDataChanged,
static_cast<SaleModel*>(ui_.salesView->model()), &SaleModel::onBasketDataChanged); static_cast<SaleModel *>(ui_.salesView->model()), &SaleModel::onBasketDataChanged);
connect(ui_.salesView->selectionModel(), &QItemSelectionModel::selectionChanged, this, connect(ui_.salesView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&MainWindow::onSalesViewSelectionChanged); &MainWindow::onSalesViewSelectionChanged);
} }
@ -199,7 +197,7 @@ void MainWindow::onPaidButtonTriggered()
{ {
if (marketplace_->basketSize() > 0) { if (marketplace_->basketSize() > 0) {
QString lastPrice{marketplace_->getBasketSumAsString().c_str()}; QString lastPrice{marketplace_->getBasketSumAsString().c_str()};
dynamic_cast<BasketModel*>(ui_.basketView->model())->finishSale(); dynamic_cast<BasketModel *>(ui_.basketView->model())->finishSale();
ui_.salesView->resizeColumnToContents(0); ui_.salesView->resizeColumnToContents(0);
ui_.lastPriceLabel1->setText(lastPrice); ui_.lastPriceLabel1->setText(lastPrice);
ui_.lastPriceLabel2->setText(lastPrice); ui_.lastPriceLabel2->setText(lastPrice);
@ -212,11 +210,11 @@ void MainWindow::onPaidButtonTriggered()
} }
} }
bool MainWindow::eventFilter(QObject* target, QEvent* event) bool MainWindow::eventFilter(QObject *target, QEvent *event)
{ {
if (target == ui_.sellerNoEdit) { if (target == ui_.sellerNoEdit) {
if (event->type() == QEvent::KeyPress) { if (event->type() == QEvent::KeyPress) {
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event); QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if (keyEvent->key() == Qt::Key::Key_Enter || keyEvent->key() == Qt::Key::Key_Return) { if (keyEvent->key() == Qt::Key::Key_Enter || keyEvent->key() == Qt::Key::Key_Return) {
if (keyEvent->modifiers() & Qt::ControlModifier) { if (keyEvent->modifiers() & Qt::ControlModifier) {
checkSellerNo(true); checkSellerNo(true);
@ -229,7 +227,7 @@ bool MainWindow::eventFilter(QObject* target, QEvent* event)
} }
} else if (target == ui_.givenSpinBox) { } else if (target == ui_.givenSpinBox) {
if (event->type() == QEvent::KeyPress) { if (event->type() == QEvent::KeyPress) {
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event); QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if (keyEvent->key() == Qt::Key::Key_Enter || keyEvent->key() == Qt::Key::Key_Return) { if (keyEvent->key() == Qt::Key::Key_Enter || keyEvent->key() == Qt::Key::Key_Return) {
if (keyEvent->modifiers() & Qt::ControlModifier) { if (keyEvent->modifiers() & Qt::ControlModifier) {
onPaidButtonTriggered(); onPaidButtonTriggered();
@ -282,7 +280,7 @@ void MainWindow::checkSellerNo(bool ctrlPressed)
if (dialogResult == QDialog::Accepted) { if (dialogResult == QDialog::Accepted) {
int price = priceDialog.getPrice(); int price = priceDialog.getPrice();
std::string desc = priceDialog.getDescription(); std::string desc = priceDialog.getDescription();
dynamic_cast<BasketModel*>(ui_.basketView->model())->addArticle(seller, price, desc); dynamic_cast<BasketModel *>(ui_.basketView->model())->addArticle(seller, price, desc);
ui_.basketView->resizeColumnToContents(1); ui_.basketView->resizeColumnToContents(1);
ui_.basketSumLabel->setText(marketplace_->getBasketSumAsString().c_str()); ui_.basketSumLabel->setText(marketplace_->getBasketSumAsString().c_str());
} }
@ -299,8 +297,8 @@ void MainWindow::onGivenSpinBoxValueChanged(double value)
ui_.drawbackLabel->setText(formatCentAsEuroString(drawback).c_str()); ui_.drawbackLabel->setText(formatCentAsEuroString(drawback).c_str());
} }
void MainWindow::onBasketViewSelectionChanged(const QItemSelection& selected, void MainWindow::onBasketViewSelectionChanged(const QItemSelection &selected,
[[maybe_unused]] const QItemSelection& deselected) [[maybe_unused]] const QItemSelection &deselected)
{ {
if (selected.size() > 0) { if (selected.size() > 0) {
ui_.cancelArticleButton->setEnabled(true); ui_.cancelArticleButton->setEnabled(true);
@ -309,8 +307,8 @@ void MainWindow::onBasketViewSelectionChanged(const QItemSelection& selected,
} }
} }
void MainWindow::onSalesViewSelectionChanged(const QItemSelection& selected, void MainWindow::onSalesViewSelectionChanged(const QItemSelection &selected,
[[maybe_unused]] const QItemSelection& deselected) [[maybe_unused]] const QItemSelection &deselected)
{ {
if (selected.size() > 0) { if (selected.size() > 0) {
ui_.cancelSaleButton->setEnabled(true); ui_.cancelSaleButton->setEnabled(true);
@ -397,7 +395,7 @@ void MainWindow::onPrintSaleReceiptButtonClicked([[maybe_unused]] bool checked)
QString posPrinterEndpoint = settings.value("global/posPrinterEndpoint", "").toString(); QString posPrinterEndpoint = settings.value("global/posPrinterEndpoint", "").toString();
auto indexes = selModel->selectedRows(); auto indexes = selModel->selectedRows();
auto& sale = marketplace_->getSales().at(indexes[0].row()); auto &sale = marketplace_->getSales().at(indexes[0].row());
auto printerDevice = auto printerDevice =
convertToPosPrinterDevice(posPrinterDevice.toStdString(), posPrinterEndpoint.toStdString()); convertToPosPrinterDevice(posPrinterDevice.toStdString(), posPrinterEndpoint.toStdString());
@ -428,15 +426,13 @@ void MainWindow::onCancelAllArticlesButtonClicked([[maybe_unused]] bool checked)
if (dlgResult == QMessageBox::No) if (dlgResult == QMessageBox::No)
return; return;
dynamic_cast<BasketModel*>(ui_.basketView->model())->cancelSale(); dynamic_cast<BasketModel *>(ui_.basketView->model())->cancelSale();
ui_.basketSumLabel->setText(marketplace_->getBasketSumAsString().c_str()); // Update basket sum ui_.basketSumLabel->setText(marketplace_->getBasketSumAsString().c_str()); // Update basket sum
ui_.sellerNoEdit->setFocus(); ui_.sellerNoEdit->setFocus();
} }
void MainWindow::onAboutQt() { void MainWindow::onAboutQt() { QMessageBox::aboutQt(this); }
QMessageBox::aboutQt(this);
}
void MainWindow::onAbout() void MainWindow::onAbout()
{ {
@ -476,11 +472,12 @@ void MainWindow::onImportSellerExcelActionTriggered()
if (case_insensitive_match(filePath.extension().string(), std::string(".xlsx"))) { if (case_insensitive_match(filePath.extension().string(), std::string(".xlsx"))) {
try { try {
numImported = ExcelReader::readSellersFromFile(filePath, marketplace_.get()); numImported = ExcelReader::readSellersFromFile(filePath, marketplace_.get());
} catch (const std::exception& e) { } catch (const std::exception &e) {
QMessageBox(QMessageBox::Icon::Critical, "Fehler beim Importieren", QMessageBox(QMessageBox::Icon::Critical, "Fehler beim Importieren",
"Beim Import aus der Excel-Datei ist ein Fehler aufgetreten. " "Beim Import aus der Excel-Datei ist ein Fehler aufgetreten. "
"Sie könnten ggf. versuchen, die Daten aus einer .csv Datei zu imporieren.", "Sie könnten ggf. versuchen, die Daten aus einer .csv Datei zu imporieren.",
QMessageBox::StandardButton::Ok, this).exec(); QMessageBox::StandardButton::Ok, this)
.exec();
std::cerr << e.what() << std::endl; std::cerr << e.what() << std::endl;
return; return;
} }
@ -594,7 +591,7 @@ void MainWindow::onImportSalesJsonActionTriggered()
try { try {
JsonUtil::importSales(filePath, marketplace_.get(), JsonUtil::importSales(filePath, marketplace_.get(),
settings.value("global/cashPointNo").toInt()); settings.value("global/cashPointNo").toInt());
} catch (std::runtime_error& err) { } catch (std::runtime_error &err) {
QMessageBox(QMessageBox::Icon::Warning, "Import nicht möglich", err.what(), QMessageBox::Ok, QMessageBox(QMessageBox::Icon::Warning, "Import nicht möglich", err.what(), QMessageBox::Ok,
this) this)
.exec(); .exec();
@ -623,7 +620,7 @@ void MainWindow::readGeometry()
settings.endGroup(); settings.endGroup();
} }
void MainWindow::closeEvent(QCloseEvent* event) void MainWindow::closeEvent(QCloseEvent *event)
{ {
writeGeometry(); writeGeometry();
event->accept(); event->accept();

View file

@ -3,9 +3,9 @@
#include "mainwindow.h" #include "mainwindow.h"
#include <core/database.h> #include <core/database.h>
#include <core/utils.h>
#include <printer/posprinter.h> #include <printer/posprinter.h>
#include <printer/utils.h> #include <printer/utils.h>
#include <core/utils.h>
#include <exception> #include <exception>
#include <stdexcept> #include <stdexcept>
@ -13,7 +13,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QSettings> #include <QSettings>
SettingsDialog::SettingsDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f) SettingsDialog::SettingsDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f)
{ {
ui_.setupUi(this); ui_.setupUi(this);
@ -26,7 +26,7 @@ SettingsDialog::SettingsDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(par
int maxFeeInEuro = settings.value("global/maxFeeInEuro").toInt(); int maxFeeInEuro = settings.value("global/maxFeeInEuro").toInt();
if (parent) if (parent)
market_ = dynamic_cast<MainWindow*>(parent)->getMarketplace(); market_ = dynamic_cast<MainWindow *>(parent)->getMarketplace();
ui_.cashPointNoSpinBox->setValue(cashPointNo); ui_.cashPointNoSpinBox->setValue(cashPointNo);
ui_.communeEdit->setText(commune); ui_.communeEdit->setText(commune);
@ -35,7 +35,7 @@ SettingsDialog::SettingsDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(par
ui_.feePercentSpinBox->setValue(feeInPercent); ui_.feePercentSpinBox->setValue(feeInPercent);
ui_.maxFeeSpinBox->setValue(maxFeeInEuro); ui_.maxFeeSpinBox->setValue(maxFeeInEuro);
connect(ui_.testPosPrinterButton, &QPushButton::clicked, this, [=]() { connect(ui_.testPosPrinterButton, &QPushButton::clicked, this, [this]() {
using namespace std::string_literals; using namespace std::string_literals;
try { try {
if (ui_.posPrinterDeviceEdit->text().isEmpty()) { if (ui_.posPrinterDeviceEdit->text().isEmpty()) {
@ -55,7 +55,7 @@ SettingsDialog::SettingsDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(par
printer.printTest(); printer.printTest();
} }
} catch (std::exception&) { } catch (std::exception &) {
QMessageBox(QMessageBox::Icon::Warning, "Falsche Eingabe", QMessageBox(QMessageBox::Icon::Warning, "Falsche Eingabe",
QString("Eingabeformat für Device (hexadezimale IDs): " QString("Eingabeformat für Device (hexadezimale IDs): "
"<VendorID>:<ProductID>\nBeispiel: 0416:5011\n " "<VendorID>:<ProductID>\nBeispiel: 0416:5011\n "
@ -65,7 +65,7 @@ SettingsDialog::SettingsDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(par
return; return;
} }
} }
} catch (std::runtime_error& err) { } catch (std::runtime_error &err) {
QMessageBox(QMessageBox::Icon::Warning, "Bondrucker Fehler", QMessageBox(QMessageBox::Icon::Warning, "Bondrucker Fehler",
QString("Test schlug fehl: ") + err.what(), QMessageBox::StandardButton::Ok, QString("Test schlug fehl: ") + err.what(), QMessageBox::StandardButton::Ok,
this) this)
@ -103,7 +103,7 @@ void SettingsDialog::accept()
if (result == QMessageBox::Yes) { if (result == QMessageBox::Yes) {
try { try {
Database().updateCashPointNo(oldCashPointNo, newCashPointNo); Database().updateCashPointNo(oldCashPointNo, newCashPointNo);
} catch (std::exception& ex) { } catch (std::exception &ex) {
std::string errMsg("Das Ändern der Kassen-Nr. ist fehlgeschlagen: "); std::string errMsg("Das Ändern der Kassen-Nr. ist fehlgeschlagen: ");
errMsg.append(ex.what()); errMsg.append(ex.what());
QMessageBox(QMessageBox::Icon::Critical, "Fehler", errMsg.c_str(), QMessageBox(QMessageBox::Icon::Critical, "Fehler", errMsg.c_str(),