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_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
#include(InstallRequiredSystemLibraries)

View file

@ -1,12 +1,12 @@
#include "mainwindow.h"
#include "basketmodel.h"
#include <config.h>
#include "pricedialog.h"
#include "reportdialog.h"
#include "salemodel.h"
#include "sellerdialog.h"
#include "settingsdialog.h"
#include <config.h>
#include <core/csvreader.h>
#include <core/excelreader.h>
@ -44,7 +44,7 @@ MainWindow::MainWindow()
}
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->setColumnHidden(0, true); // hide the uuid
@ -55,7 +55,7 @@ MainWindow::MainWindow()
connect(ui_.actionQuit, &QAction::triggered, qApp, QApplication::closeAllWindows,
Qt::QueuedConnection);
connect(ui_.newAction, &QAction::triggered, this, [=]() {
connect(ui_.newAction, &QAction::triggered, this, [this]() {
if (marketplace_->getSellers().size() == 0 && marketplace_->getSales().size() == 0) {
return;
}
@ -69,7 +69,7 @@ MainWindow::MainWindow()
return;
delete ui_.salesView->model();
dynamic_cast<BasketModel*>(ui_.basketView->model())->cancelSale();
dynamic_cast<BasketModel *>(ui_.basketView->model())->cancelSale();
marketplace_->clear();
setSaleModel();
updateStatLabel();
@ -105,7 +105,7 @@ MainWindow::MainWindow()
}
}
});
connect(ui_.licenseAction, &QAction::triggered, this, [=]() {
connect(ui_.licenseAction, &QAction::triggered, this, [this]() {
QString licenseText(
"Copyright © 2018-2021 Martin Brodbeck\n\n"
"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.");
QMessageBox::information(this, "Lizenzinformation", licenseText);
});
connect(ui_.reportAction, &QAction::triggered, this, [=]() {
ReportDialog(this).exec();
});
connect(ui_.configAction, &QAction::triggered, this, [=]() {
connect(ui_.reportAction, &QAction::triggered, this, [this]() { ReportDialog(this).exec(); });
connect(ui_.configAction, &QAction::triggered, this, [this]() {
int result = SettingsDialog(this).exec();
if (result == QDialog::Accepted) {
delete ui_.salesView->model();
@ -189,8 +187,8 @@ void MainWindow::setSaleModel()
ui_.printSaleReceiptButton->setEnabled(false);
ui_.cancelSaleButton->setEnabled(false);
connect(static_cast<BasketModel*>(ui_.basketView->model()), &BasketModel::basketDataChanged,
static_cast<SaleModel*>(ui_.salesView->model()), &SaleModel::onBasketDataChanged);
connect(static_cast<BasketModel *>(ui_.basketView->model()), &BasketModel::basketDataChanged,
static_cast<SaleModel *>(ui_.salesView->model()), &SaleModel::onBasketDataChanged);
connect(ui_.salesView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&MainWindow::onSalesViewSelectionChanged);
}
@ -199,7 +197,7 @@ void MainWindow::onPaidButtonTriggered()
{
if (marketplace_->basketSize() > 0) {
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_.lastPriceLabel1->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 (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->modifiers() & Qt::ControlModifier) {
checkSellerNo(true);
@ -229,7 +227,7 @@ bool MainWindow::eventFilter(QObject* target, QEvent* event)
}
} else if (target == ui_.givenSpinBox) {
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->modifiers() & Qt::ControlModifier) {
onPaidButtonTriggered();
@ -282,7 +280,7 @@ void MainWindow::checkSellerNo(bool ctrlPressed)
if (dialogResult == QDialog::Accepted) {
int price = priceDialog.getPrice();
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_.basketSumLabel->setText(marketplace_->getBasketSumAsString().c_str());
}
@ -299,8 +297,8 @@ void MainWindow::onGivenSpinBoxValueChanged(double value)
ui_.drawbackLabel->setText(formatCentAsEuroString(drawback).c_str());
}
void MainWindow::onBasketViewSelectionChanged(const QItemSelection& selected,
[[maybe_unused]] const QItemSelection& deselected)
void MainWindow::onBasketViewSelectionChanged(const QItemSelection &selected,
[[maybe_unused]] const QItemSelection &deselected)
{
if (selected.size() > 0) {
ui_.cancelArticleButton->setEnabled(true);
@ -309,8 +307,8 @@ void MainWindow::onBasketViewSelectionChanged(const QItemSelection& selected,
}
}
void MainWindow::onSalesViewSelectionChanged(const QItemSelection& selected,
[[maybe_unused]] const QItemSelection& deselected)
void MainWindow::onSalesViewSelectionChanged(const QItemSelection &selected,
[[maybe_unused]] const QItemSelection &deselected)
{
if (selected.size() > 0) {
ui_.cancelSaleButton->setEnabled(true);
@ -397,7 +395,7 @@ void MainWindow::onPrintSaleReceiptButtonClicked([[maybe_unused]] bool checked)
QString posPrinterEndpoint = settings.value("global/posPrinterEndpoint", "").toString();
auto indexes = selModel->selectedRows();
auto& sale = marketplace_->getSales().at(indexes[0].row());
auto &sale = marketplace_->getSales().at(indexes[0].row());
auto printerDevice =
convertToPosPrinterDevice(posPrinterDevice.toStdString(), posPrinterEndpoint.toStdString());
@ -428,15 +426,13 @@ void MainWindow::onCancelAllArticlesButtonClicked([[maybe_unused]] bool checked)
if (dlgResult == QMessageBox::No)
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_.sellerNoEdit->setFocus();
}
void MainWindow::onAboutQt() {
QMessageBox::aboutQt(this);
}
void MainWindow::onAboutQt() { QMessageBox::aboutQt(this); }
void MainWindow::onAbout()
{
@ -476,11 +472,12 @@ void MainWindow::onImportSellerExcelActionTriggered()
if (case_insensitive_match(filePath.extension().string(), std::string(".xlsx"))) {
try {
numImported = ExcelReader::readSellersFromFile(filePath, marketplace_.get());
} catch (const std::exception& e) {
} catch (const std::exception &e) {
QMessageBox(QMessageBox::Icon::Critical, "Fehler beim Importieren",
"Beim Import aus der Excel-Datei ist ein Fehler aufgetreten. "
"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;
return;
}
@ -594,7 +591,7 @@ void MainWindow::onImportSalesJsonActionTriggered()
try {
JsonUtil::importSales(filePath, marketplace_.get(),
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,
this)
.exec();
@ -623,7 +620,7 @@ void MainWindow::readGeometry()
settings.endGroup();
}
void MainWindow::closeEvent(QCloseEvent* event)
void MainWindow::closeEvent(QCloseEvent *event)
{
writeGeometry();
event->accept();

View file

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