code formatting

This commit is contained in:
Martin Brodbeck 2022-07-07 15:37:33 +02:00
parent 5f7d91a18e
commit 6944051c31
18 changed files with 269 additions and 269 deletions

View file

@ -5,13 +5,13 @@
#include <QSettings> #include <QSettings>
BasketModel::BasketModel(Marketplace* market, QObject* parent) BasketModel::BasketModel(Marketplace* market, QObject* parent)
: QAbstractTableModel(parent), marketplace_(market) : QAbstractTableModel(parent), m_marketplace(market)
{ {
} }
int BasketModel::rowCount([[maybe_unused]] const QModelIndex& parent) const int BasketModel::rowCount([[maybe_unused]] const QModelIndex& parent) const
{ {
return static_cast<int>(marketplace_->basketSize()); return static_cast<int>(m_marketplace->basketSize());
} }
int BasketModel::columnCount([[maybe_unused]] const QModelIndex& parent) const { return 4; } int BasketModel::columnCount([[maybe_unused]] const QModelIndex& parent) const { return 4; }
@ -46,10 +46,10 @@ QVariant BasketModel::data(const QModelIndex& index, int role) const
if (role != Qt::DisplayRole) if (role != Qt::DisplayRole)
return QVariant(); return QVariant();
if (marketplace_->basketSize() == 0) if (m_marketplace->basketSize() == 0)
return QVariant(); return QVariant();
Article* article = marketplace_->getBasket().at(index.row()).get(); Article* article = m_marketplace->getBasket().at(index.row()).get();
switch (index.column()) { switch (index.column()) {
case 0: case 0:
@ -92,45 +92,45 @@ QVariant BasketModel::headerData(int section, Qt::Orientation orientation, int r
void BasketModel::addArticle(Seller* seller, int price, const std::string& desc) void BasketModel::addArticle(Seller* seller, int price, const std::string& desc)
{ {
emit beginInsertRows(QModelIndex(), marketplace_->getBasket().size(), emit beginInsertRows(QModelIndex(), m_marketplace->getBasket().size(),
marketplace_->getBasket().size()); m_marketplace->getBasket().size());
auto article = std::make_unique<Article>(price); auto article = std::make_unique<Article>(price);
article->createUuid(); article->createUuid();
article->setDescription(desc); article->setDescription(desc);
article->setArticleNo(marketplace_->getNextArticleNo()); article->setArticleNo(m_marketplace->getNextArticleNo());
article->setSourceNo(QSettings().value("global/cashPointNo").toInt()); article->setSourceNo(QSettings().value("global/cashPointNo").toInt());
article->setSeller(seller); article->setSeller(seller);
marketplace_->addArticleToBasket(std::move(article)); m_marketplace->addArticleToBasket(std::move(article));
emit endInsertRows(); emit endInsertRows();
} }
void BasketModel::finishSale() void BasketModel::finishSale()
{ {
emit beginRemoveRows(QModelIndex(), 0, marketplace_->getBasket().size() - 1); emit beginRemoveRows(QModelIndex(), 0, m_marketplace->getBasket().size() - 1);
auto sale = std::make_unique<Sale>(); auto sale = std::make_unique<Sale>();
sale->createUuid(); sale->createUuid();
sale->setSourceNo(QSettings().value("global/cashPointNo").toInt()); sale->setSourceNo(QSettings().value("global/cashPointNo").toInt());
marketplace_->finishCurrentSale(std::move(sale)); m_marketplace->finishCurrentSale(std::move(sale));
emit endRemoveRows(); emit endRemoveRows();
emit basketDataChanged(); emit basketDataChanged();
} }
void BasketModel::cancelSale() void BasketModel::cancelSale()
{ {
emit beginRemoveRows(QModelIndex(), 0, marketplace_->getBasket().size() - 1); emit beginRemoveRows(QModelIndex(), 0, m_marketplace->getBasket().size() - 1);
marketplace_->getBasket().clear(); m_marketplace->getBasket().clear();
emit endRemoveRows(); emit endRemoveRows();
} }
bool BasketModel::removeRows(int row, int count, const QModelIndex& parent) bool BasketModel::removeRows(int row, int count, const QModelIndex& parent)
{ {
auto article = marketplace_->getBasket().at(row).get(); auto article = m_marketplace->getBasket().at(row).get();
emit beginRemoveRows(parent, row, row + count - 1); emit beginRemoveRows(parent, row, row + count - 1);
marketplace_->getBasket().erase( m_marketplace->getBasket().erase(
std::remove_if(marketplace_->getBasket().begin(), marketplace_->getBasket().end(), std::remove_if(m_marketplace->getBasket().begin(), m_marketplace->getBasket().end(),
[&article](const auto& a) { return a->getUuid() == article->getUuid(); }), [&article](const auto& a) { return a->getUuid() == article->getUuid(); }),
marketplace_->getBasket().end()); m_marketplace->getBasket().end());
emit endRemoveRows(); emit endRemoveRows();
return true; return true;
} }

View file

@ -24,7 +24,7 @@ class BasketModel : public QAbstractTableModel
void basketDataChanged(); void basketDataChanged();
private: private:
Marketplace* marketplace_; Marketplace* m_marketplace;
}; };
#endif #endif

View file

@ -32,10 +32,10 @@ constexpr int STATUSBAR_TIMEOUT = 5000;
MainWindow::MainWindow() MainWindow::MainWindow()
{ {
ui_.setupUi(this); m_ui.setupUi(this);
marketplace_ = std::make_unique<Marketplace>(); m_marketplace = std::make_unique<Marketplace>();
Database::InitResult res = marketplace_->loadFromDb(); Database::InitResult res = m_marketplace->loadFromDb();
if (res == Database::InitResult::OUTDATED_REPLACED) { if (res == Database::InitResult::OUTDATED_REPLACED) {
QMessageBox(QMessageBox::Icon::Information, "Datenbankinformation", QMessageBox(QMessageBox::Icon::Information, "Datenbankinformation",
"Es wurde eine <b>veraltete</b> Datenbankdatei erkannt.<br />Diese wurde " "Es wurde eine <b>veraltete</b> Datenbankdatei erkannt.<br />Diese wurde "
@ -44,19 +44,19 @@ 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(), m_ui.basketView);
ui_.basketView->setModel(model); m_ui.basketView->setModel(model);
ui_.basketView->setColumnHidden(0, true); // hide the uuid m_ui.basketView->setColumnHidden(0, true); // hide the uuid
setWindowTitle("KIMA2 - Kasse Nr. " + QSettings().value("global/cashPointNo").toString()); setWindowTitle("KIMA2 - Kasse Nr. " + QSettings().value("global/cashPointNo").toString());
ui_.salesView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); m_ui.salesView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
setSaleModel(); setSaleModel();
connect(ui_.actionQuit, &QAction::triggered, qApp, QApplication::closeAllWindows, connect(m_ui.actionQuit, &QAction::triggered, qApp, QApplication::closeAllWindows,
Qt::QueuedConnection); Qt::QueuedConnection);
connect(ui_.newAction, &QAction::triggered, this, [this]() { connect(m_ui.newAction, &QAction::triggered, this, [this]() {
if (marketplace_->getSellers().size() == 0 && marketplace_->getSales().size() == 0) { if (m_marketplace->getSellers().size() == 0 && m_marketplace->getSales().size() == 0) {
return; return;
} }
auto dlgResult = auto dlgResult =
@ -68,34 +68,34 @@ MainWindow::MainWindow()
if (dlgResult == QMessageBox::No) if (dlgResult == QMessageBox::No)
return; return;
delete ui_.salesView->model(); delete m_ui.salesView->model();
dynamic_cast<BasketModel *>(ui_.basketView->model())->cancelSale(); dynamic_cast<BasketModel *>(m_ui.basketView->model())->cancelSale();
marketplace_->clear(); m_marketplace->clear();
setSaleModel(); setSaleModel();
updateStatLabel(); updateStatLabel();
}); });
ui_.sellerNoEdit->installEventFilter(this); m_ui.sellerNoEdit->installEventFilter(this);
ui_.givenSpinBox->installEventFilter(this); m_ui.givenSpinBox->installEventFilter(this);
connect(ui_.actionEditSeller, &QAction::triggered, this, connect(m_ui.actionEditSeller, &QAction::triggered, this,
&MainWindow::onActionEditSellerTriggered); &MainWindow::onActionEditSellerTriggered);
connect(ui_.paidButton, &QPushButton::clicked, this, &MainWindow::onPaidButtonTriggered); connect(m_ui.paidButton, &QPushButton::clicked, this, &MainWindow::onPaidButtonTriggered);
connect(ui_.givenSpinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, connect(m_ui.givenSpinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
&MainWindow::onGivenSpinBoxValueChanged); &MainWindow::onGivenSpinBoxValueChanged);
connect(ui_.basketView->selectionModel(), &QItemSelectionModel::selectionChanged, this, connect(m_ui.basketView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&MainWindow::onBasketViewSelectionChanged); &MainWindow::onBasketViewSelectionChanged);
connect(ui_.cancelArticleButton, &QPushButton::clicked, this, connect(m_ui.cancelArticleButton, &QPushButton::clicked, this,
&MainWindow::onCancelArticleButtonClicked); &MainWindow::onCancelArticleButtonClicked);
connect(ui_.cancelSaleButton, &QPushButton::clicked, this, connect(m_ui.cancelSaleButton, &QPushButton::clicked, this,
&MainWindow::onCancelSaleButtonClicked); &MainWindow::onCancelSaleButtonClicked);
connect(ui_.printSaleReceiptButton, &QPushButton::clicked, this, connect(m_ui.printSaleReceiptButton, &QPushButton::clicked, this,
&MainWindow::onPrintSaleReceiptButtonClicked); &MainWindow::onPrintSaleReceiptButtonClicked);
connect(ui_.cancelAllArticlesButton, &QPushButton::clicked, this, connect(m_ui.cancelAllArticlesButton, &QPushButton::clicked, this,
&MainWindow::onCancelAllArticlesButtonClicked); &MainWindow::onCancelAllArticlesButtonClicked);
connect(ui_.aboutQtAction, &QAction::triggered, this, &MainWindow::onAboutQt); connect(m_ui.aboutQtAction, &QAction::triggered, this, &MainWindow::onAboutQt);
connect(ui_.aboutAction, &QAction::triggered, this, &MainWindow::onAbout); connect(m_ui.aboutAction, &QAction::triggered, this, &MainWindow::onAbout);
connect(ui_.openManualAction, &QAction::triggered, this, []() { connect(m_ui.openManualAction, &QAction::triggered, this, []() {
auto locations = QStandardPaths::standardLocations(QStandardPaths::DataLocation); auto locations = QStandardPaths::standardLocations(QStandardPaths::DataLocation);
for (auto location : locations) { for (auto location : locations) {
if (QFile::exists(location + QString("/Benutzerhandbuch.pdf"))) { if (QFile::exists(location + QString("/Benutzerhandbuch.pdf"))) {
@ -105,7 +105,7 @@ MainWindow::MainWindow()
} }
} }
}); });
connect(ui_.licenseAction, &QAction::triggered, this, [this]() { connect(m_ui.licenseAction, &QAction::triggered, this, [this]() {
QString licenseText( QString licenseText(
"Copyright © 2018-2022 Martin Brodbeck\n\n" "Copyright © 2018-2022 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,34 +126,34 @@ 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, [this]() { ReportDialog(this).exec(); }); connect(m_ui.reportAction, &QAction::triggered, this, [this]() { ReportDialog(this).exec(); });
connect(ui_.configAction, &QAction::triggered, this, [this]() { connect(m_ui.configAction, &QAction::triggered, this, [this]() {
int result = SettingsDialog(this).exec(); int result = SettingsDialog(this).exec();
if (result == QDialog::Accepted) { if (result == QDialog::Accepted) {
delete ui_.salesView->model(); delete m_ui.salesView->model();
marketplace_->loadFromDb(); m_marketplace->loadFromDb();
setSaleModel(); setSaleModel();
} }
this->setWindowTitle("KIMA2 - Kasse Nr. " + this->setWindowTitle("KIMA2 - Kasse Nr. " +
QSettings().value("global/cashPointNo").toString()); QSettings().value("global/cashPointNo").toString());
}); });
connect(ui_.importSellerExcelAction, &QAction::triggered, this, connect(m_ui.importSellerExcelAction, &QAction::triggered, this,
&MainWindow::onImportSellerExcelActionTriggered); &MainWindow::onImportSellerExcelActionTriggered);
connect(ui_.importSellerJsonAction, &QAction::triggered, this, connect(m_ui.importSellerJsonAction, &QAction::triggered, this,
&MainWindow::onImportSellerJsonActionTriggered); &MainWindow::onImportSellerJsonActionTriggered);
connect(ui_.exportSellerJsonAction, &QAction::triggered, this, connect(m_ui.exportSellerJsonAction, &QAction::triggered, this,
&MainWindow::onExportSellerJsonActionTriggered); &MainWindow::onExportSellerJsonActionTriggered);
connect(ui_.exportSalesJsonAction, &QAction::triggered, this, connect(m_ui.exportSalesJsonAction, &QAction::triggered, this,
&MainWindow::onExportSalesJsonActionTriggered); &MainWindow::onExportSalesJsonActionTriggered);
connect(ui_.importSalesJsonAction, &QAction::triggered, this, connect(m_ui.importSalesJsonAction, &QAction::triggered, this,
&MainWindow::onImportSalesJsonActionTriggered); &MainWindow::onImportSalesJsonActionTriggered);
readGeometry(); readGeometry();
setWindowIcon(QIcon(":/misc/kima2.ico")); setWindowIcon(QIcon(":/misc/kima2.ico"));
updateStatLabel(); updateStatLabel();
ui_.lastPriceLabel1->setText(formatCentAsEuroString(0).c_str()); m_ui.lastPriceLabel1->setText(formatCentAsEuroString(0).c_str());
ui_.lastPriceLabel2->setText(formatCentAsEuroString(0).c_str()); m_ui.lastPriceLabel2->setText(formatCentAsEuroString(0).c_str());
} }
void MainWindow::onActionEditSellerTriggered() void MainWindow::onActionEditSellerTriggered()
@ -161,11 +161,11 @@ void MainWindow::onActionEditSellerTriggered()
auto dialog = std::make_unique<SellerDialog>(this); auto dialog = std::make_unique<SellerDialog>(this);
int retCode = dialog->exec(); int retCode = dialog->exec();
delete ui_.salesView->model(); delete m_ui.salesView->model();
if (retCode == QDialog::Accepted) { if (retCode == QDialog::Accepted) {
marketplace_->sortSellers(); m_marketplace->sortSellers();
marketplace_->storeToDb(); m_marketplace->storeToDb();
statusBar()->showMessage("Änderungen an den Verkäufer-Stammdaten gespeichert.", statusBar()->showMessage("Änderungen an den Verkäufer-Stammdaten gespeichert.",
STATUSBAR_TIMEOUT); STATUSBAR_TIMEOUT);
} else { } else {
@ -179,32 +179,32 @@ void MainWindow::onActionEditSellerTriggered()
void MainWindow::setSaleModel() void MainWindow::setSaleModel()
{ {
ui_.salesView->setModel(new SaleModel(getMarketplace(), ui_.salesView)); m_ui.salesView->setModel(new SaleModel(getMarketplace(), m_ui.salesView));
ui_.salesView->setColumnHidden(2, true); m_ui.salesView->setColumnHidden(2, true);
ui_.salesView->resizeColumnToContents(0); m_ui.salesView->resizeColumnToContents(0);
ui_.salesView->resizeColumnToContents(1); m_ui.salesView->resizeColumnToContents(1);
ui_.printSaleReceiptButton->setEnabled(false); m_ui.printSaleReceiptButton->setEnabled(false);
ui_.cancelSaleButton->setEnabled(false); m_ui.cancelSaleButton->setEnabled(false);
connect(static_cast<BasketModel *>(ui_.basketView->model()), &BasketModel::basketDataChanged, connect(static_cast<BasketModel *>(m_ui.basketView->model()), &BasketModel::basketDataChanged,
static_cast<SaleModel *>(ui_.salesView->model()), &SaleModel::onBasketDataChanged); static_cast<SaleModel *>(m_ui.salesView->model()), &SaleModel::onBasketDataChanged);
connect(ui_.salesView->selectionModel(), &QItemSelectionModel::selectionChanged, this, connect(m_ui.salesView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&MainWindow::onSalesViewSelectionChanged); &MainWindow::onSalesViewSelectionChanged);
} }
void MainWindow::onPaidButtonTriggered() void MainWindow::onPaidButtonTriggered()
{ {
if (marketplace_->basketSize() > 0) { if (m_marketplace->basketSize() > 0) {
QString lastPrice{marketplace_->getBasketSumAsString().c_str()}; QString lastPrice{m_marketplace->getBasketSumAsString().c_str()};
dynamic_cast<BasketModel *>(ui_.basketView->model())->finishSale(); dynamic_cast<BasketModel *>(m_ui.basketView->model())->finishSale();
ui_.salesView->resizeColumnToContents(0); m_ui.salesView->resizeColumnToContents(0);
ui_.lastPriceLabel1->setText(lastPrice); m_ui.lastPriceLabel1->setText(lastPrice);
ui_.lastPriceLabel2->setText(lastPrice); m_ui.lastPriceLabel2->setText(lastPrice);
ui_.basketSumLabel->setText(formatCentAsEuroString(0).c_str()); m_ui.basketSumLabel->setText(formatCentAsEuroString(0).c_str());
ui_.drawbackLabel->setText(formatCentAsEuroString(0).c_str()); m_ui.drawbackLabel->setText(formatCentAsEuroString(0).c_str());
ui_.drawbackContainerWidget->setEnabled(false); m_ui.drawbackContainerWidget->setEnabled(false);
ui_.sellerNoEdit->setFocus(); m_ui.sellerNoEdit->setFocus();
statusBar()->showMessage("Verkaufsvorgang erfolgreich durchgeführt.", STATUSBAR_TIMEOUT); statusBar()->showMessage("Verkaufsvorgang erfolgreich durchgeführt.", STATUSBAR_TIMEOUT);
updateStatLabel(); updateStatLabel();
} }
@ -212,7 +212,7 @@ void MainWindow::onPaidButtonTriggered()
bool MainWindow::eventFilter(QObject *target, QEvent *event) bool MainWindow::eventFilter(QObject *target, QEvent *event)
{ {
if (target == ui_.sellerNoEdit) { if (target == m_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) {
@ -225,7 +225,7 @@ bool MainWindow::eventFilter(QObject *target, QEvent *event)
return true; return true;
} }
} }
} else if (target == ui_.givenSpinBox) { } else if (target == m_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) {
@ -234,9 +234,9 @@ bool MainWindow::eventFilter(QObject *target, QEvent *event)
return true; return true;
} }
} else if (keyEvent->key() == Qt::Key::Key_Escape) { } else if (keyEvent->key() == Qt::Key::Key_Escape) {
ui_.drawbackLabel->setText(formatCentAsEuroString(0).c_str()); m_ui.drawbackLabel->setText(formatCentAsEuroString(0).c_str());
ui_.drawbackContainerWidget->setEnabled(false); m_ui.drawbackContainerWidget->setEnabled(false);
ui_.sellerNoEdit->setFocus(); m_ui.sellerNoEdit->setFocus();
} }
} }
} }
@ -247,15 +247,15 @@ void MainWindow::checkSellerNo(bool ctrlPressed)
{ {
using std::regex, std::regex_match, std::smatch; using std::regex, std::regex_match, std::smatch;
auto inputText = ui_.sellerNoEdit->text().toStdString(); auto inputText = m_ui.sellerNoEdit->text().toStdString();
if (inputText.empty()) { if (inputText.empty()) {
if (ctrlPressed == false) { if (ctrlPressed == false) {
onPaidButtonTriggered(); onPaidButtonTriggered();
} else if (marketplace_->getBasket().size() > 0) { } else if (m_marketplace->getBasket().size() > 0) {
ui_.drawbackContainerWidget->setEnabled(true); m_ui.drawbackContainerWidget->setEnabled(true);
ui_.givenSpinBox->setFocus(); m_ui.givenSpinBox->setFocus();
ui_.givenSpinBox->selectAll(); m_ui.givenSpinBox->selectAll();
} }
return; return;
} }
@ -264,13 +264,13 @@ void MainWindow::checkSellerNo(bool ctrlPressed)
smatch result; smatch result;
if (!regex_match(inputText, result, pattern)) { if (!regex_match(inputText, result, pattern)) {
ui_.sellerNoEdit->clear(); m_ui.sellerNoEdit->clear();
return; return;
} }
int sellerNo = std::stoi(result[0]); int sellerNo = std::stoi(result[0]);
auto seller = marketplace_->findSellerWithSellerNo(sellerNo); auto seller = m_marketplace->findSellerWithSellerNo(sellerNo);
if (seller) { if (seller) {
PriceDialog priceDialog(this); PriceDialog priceDialog(this);
if (sellerNo == 0) { if (sellerNo == 0) {
@ -280,30 +280,30 @@ 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 *>(m_ui.basketView->model())->addArticle(seller, price, desc);
ui_.basketView->resizeColumnToContents(1); m_ui.basketView->resizeColumnToContents(1);
ui_.basketSumLabel->setText(marketplace_->getBasketSumAsString().c_str()); m_ui.basketSumLabel->setText(m_marketplace->getBasketSumAsString().c_str());
} }
} }
ui_.sellerNoEdit->clear(); m_ui.sellerNoEdit->clear();
} }
void MainWindow::onGivenSpinBoxValueChanged(double value) void MainWindow::onGivenSpinBoxValueChanged(double value)
{ {
int givenInCent = std::round(value * 100); int givenInCent = std::round(value * 100);
int basketSumInCent = marketplace_->getBasketSumInCent(); int basketSumInCent = m_marketplace->getBasketSumInCent();
int drawback = givenInCent - basketSumInCent; int drawback = givenInCent - basketSumInCent;
ui_.drawbackLabel->setText(formatCentAsEuroString(drawback).c_str()); m_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); m_ui.cancelArticleButton->setEnabled(true);
} else { } else {
ui_.cancelArticleButton->setEnabled(false); m_ui.cancelArticleButton->setEnabled(false);
} }
} }
@ -311,21 +311,21 @@ 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); m_ui.cancelSaleButton->setEnabled(true);
if (!selected.indexes()[0].parent().isValid()) if (!selected.indexes()[0].parent().isValid())
ui_.printSaleReceiptButton->setEnabled(true); m_ui.printSaleReceiptButton->setEnabled(true);
else else
ui_.printSaleReceiptButton->setEnabled(false); m_ui.printSaleReceiptButton->setEnabled(false);
} else { } else {
ui_.cancelSaleButton->setEnabled(false); m_ui.cancelSaleButton->setEnabled(false);
ui_.printSaleReceiptButton->setEnabled(false); m_ui.printSaleReceiptButton->setEnabled(false);
} }
} }
void MainWindow::onCancelArticleButtonClicked([[maybe_unused]] bool checked) void MainWindow::onCancelArticleButtonClicked([[maybe_unused]] bool checked)
{ {
auto selModel = ui_.basketView->selectionModel(); auto selModel = m_ui.basketView->selectionModel();
if (selModel->hasSelection() == false) if (selModel->hasSelection() == false)
return; return;
@ -342,16 +342,16 @@ void MainWindow::onCancelArticleButtonClicked([[maybe_unused]] bool checked)
// Deleting the rows, beginning with the last one! // Deleting the rows, beginning with the last one!
for (auto iter = indexes.constEnd() - 1; iter >= indexes.constBegin(); --iter) { for (auto iter = indexes.constEnd() - 1; iter >= indexes.constBegin(); --iter) {
ui_.basketView->model()->removeRow(iter->row()); m_ui.basketView->model()->removeRow(iter->row());
} }
ui_.basketSumLabel->setText(marketplace_->getBasketSumAsString().c_str()); // Update basket sum m_ui.basketSumLabel->setText(m_marketplace->getBasketSumAsString().c_str()); // Update basket sum
ui_.sellerNoEdit->setFocus(); m_ui.sellerNoEdit->setFocus();
} }
void MainWindow::onCancelSaleButtonClicked([[maybe_unused]] bool checked) void MainWindow::onCancelSaleButtonClicked([[maybe_unused]] bool checked)
{ {
auto selModel = ui_.salesView->selectionModel(); auto selModel = m_ui.salesView->selectionModel();
if (selModel->hasSelection() == false) if (selModel->hasSelection() == false)
return; return;
@ -368,25 +368,25 @@ void MainWindow::onCancelSaleButtonClicked([[maybe_unused]] bool checked)
// Deleting the rows, beginning with the last one! // Deleting the rows, beginning with the last one!
for (auto iter = indexes.constEnd() - 1; iter >= indexes.constBegin(); --iter) { for (auto iter = indexes.constEnd() - 1; iter >= indexes.constBegin(); --iter) {
ui_.salesView->model()->removeRow(iter->row(), iter->parent()); m_ui.salesView->model()->removeRow(iter->row(), iter->parent());
} }
ui_.salesView->collapseAll(); m_ui.salesView->collapseAll();
QString lastPriceValue(formatCentAsEuroString(0).c_str()); QString lastPriceValue(formatCentAsEuroString(0).c_str());
if (ui_.salesView->model()->rowCount() > 0) { if (m_ui.salesView->model()->rowCount() > 0) {
lastPriceValue = lastPriceValue =
ui_.salesView->model()->data(ui_.salesView->model()->index(0, 1)).toString(); m_ui.salesView->model()->data(m_ui.salesView->model()->index(0, 1)).toString();
} }
ui_.lastPriceLabel1->setText(lastPriceValue); m_ui.lastPriceLabel1->setText(lastPriceValue);
ui_.lastPriceLabel2->setText(lastPriceValue); m_ui.lastPriceLabel2->setText(lastPriceValue);
updateStatLabel(); updateStatLabel();
} }
void MainWindow::onPrintSaleReceiptButtonClicked([[maybe_unused]] bool checked) void MainWindow::onPrintSaleReceiptButtonClicked([[maybe_unused]] bool checked)
{ {
auto selModel = ui_.salesView->selectionModel(); auto selModel = m_ui.salesView->selectionModel();
if (selModel->hasSelection() == false) if (selModel->hasSelection() == false)
return; return;
@ -395,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 = m_marketplace->getSales().at(indexes[0].row());
auto printerDevice = auto printerDevice =
convertToPosPrinterDevice(posPrinterDevice.toStdString(), posPrinterEndpoint.toStdString()); convertToPosPrinterDevice(posPrinterDevice.toStdString(), posPrinterEndpoint.toStdString());
@ -415,7 +415,7 @@ void MainWindow::onPrintSaleReceiptButtonClicked([[maybe_unused]] bool checked)
void MainWindow::onCancelAllArticlesButtonClicked([[maybe_unused]] bool checked) void MainWindow::onCancelAllArticlesButtonClicked([[maybe_unused]] bool checked)
{ {
if (ui_.basketView->model()->rowCount() == 0) if (m_ui.basketView->model()->rowCount() == 0)
return; return;
auto dlgResult = auto dlgResult =
@ -426,10 +426,10 @@ 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 *>(m_ui.basketView->model())->cancelSale();
ui_.basketSumLabel->setText(marketplace_->getBasketSumAsString().c_str()); // Update basket sum m_ui.basketSumLabel->setText(m_marketplace->getBasketSumAsString().c_str()); // Update basket sum
ui_.sellerNoEdit->setFocus(); m_ui.sellerNoEdit->setFocus();
} }
void MainWindow::onAboutQt() { QMessageBox::aboutQt(this); } void MainWindow::onAboutQt() { QMessageBox::aboutQt(this); }
@ -447,7 +447,7 @@ void MainWindow::onAbout()
void MainWindow::onImportSellerExcelActionTriggered() void MainWindow::onImportSellerExcelActionTriggered()
{ {
if (!marketplace_->getSales().empty()) { if (!m_marketplace->getSales().empty()) {
QMessageBox(QMessageBox::Icon::Information, "Import nicht möglich", QMessageBox(QMessageBox::Icon::Information, "Import nicht möglich",
"Der Import ist nicht möglich, da schon Verkäufe getätigt wurden.", "Der Import ist nicht möglich, da schon Verkäufe getätigt wurden.",
QMessageBox::StandardButton::Ok, this) QMessageBox::StandardButton::Ok, this)
@ -471,7 +471,7 @@ void MainWindow::onImportSellerExcelActionTriggered()
std::size_t numImported{}; std::size_t numImported{};
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, m_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. "
@ -482,7 +482,7 @@ void MainWindow::onImportSellerExcelActionTriggered()
return; return;
} }
} else { } else {
numImported = CsvReader::readSellersFromFile(filePath, marketplace_.get()); numImported = CsvReader::readSellersFromFile(filePath, m_marketplace.get());
} }
updateStatLabel(); updateStatLabel();
@ -498,7 +498,7 @@ void MainWindow::onImportSellerExcelActionTriggered()
void MainWindow::onImportSellerJsonActionTriggered() void MainWindow::onImportSellerJsonActionTriggered()
{ {
if (!marketplace_->getSales().empty()) { if (!m_marketplace->getSales().empty()) {
QMessageBox(QMessageBox::Icon::Information, "Import nicht möglich", QMessageBox(QMessageBox::Icon::Information, "Import nicht möglich",
"Der Import ist nicht möglich, da schon Verkäufe getätigt wurden.", "Der Import ist nicht möglich, da schon Verkäufe getätigt wurden.",
QMessageBox::StandardButton::Ok, this) QMessageBox::StandardButton::Ok, this)
@ -519,7 +519,7 @@ void MainWindow::onImportSellerJsonActionTriggered()
#endif #endif
std::size_t numImported{}; std::size_t numImported{};
numImported = JsonUtil::importSellers(filePath, marketplace_.get()); numImported = JsonUtil::importSellers(filePath, m_marketplace.get());
updateStatLabel(); updateStatLabel();
@ -546,7 +546,7 @@ void MainWindow::onExportSellerJsonActionTriggered()
fs::path filePath(filename.toStdString()); fs::path filePath(filename.toStdString());
#endif #endif
JsonUtil::exportSellers(filePath, marketplace_.get()); JsonUtil::exportSellers(filePath, m_marketplace.get());
} }
void MainWindow::onExportSalesJsonActionTriggered() void MainWindow::onExportSalesJsonActionTriggered()
@ -567,7 +567,7 @@ void MainWindow::onExportSalesJsonActionTriggered()
fs::path filePath(filename.toStdString()); fs::path filePath(filename.toStdString());
#endif #endif
JsonUtil::exportSales(filePath, marketplace_.get(), JsonUtil::exportSales(filePath, m_marketplace.get(),
settings.value("global/cashPointNo").toInt()); settings.value("global/cashPointNo").toInt());
} }
@ -587,9 +587,9 @@ void MainWindow::onImportSalesJsonActionTriggered()
fs::path filePath(filename.toStdString()); fs::path filePath(filename.toStdString());
#endif #endif
delete ui_.salesView->model(); delete m_ui.salesView->model();
try { try {
JsonUtil::importSales(filePath, marketplace_.get(), JsonUtil::importSales(filePath, m_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,
@ -630,9 +630,9 @@ void MainWindow::updateStatLabel()
{ {
std::string statistics("<b>KIMA2 - Version "); std::string statistics("<b>KIMA2 - Version ");
statistics += PROJECT_VERSION; statistics += PROJECT_VERSION;
statistics += "</b><br />Verkäufer: " + std::to_string(marketplace_->getSellers().size() - 1); statistics += "</b><br />Verkäufer: " + std::to_string(m_marketplace->getSellers().size() - 1);
statistics += "<br />Kunden: " + std::to_string(marketplace_->getSales().size()); statistics += "<br />Kunden: " + std::to_string(m_marketplace->getSales().size());
statistics += "<br />Umsatz: " + marketplace_->getOverallSumAsString(); statistics += "<br />Umsatz: " + m_marketplace->getOverallSumAsString();
ui_.statLabel->setText(statistics.c_str()); m_ui.statLabel->setText(statistics.c_str());
} }

View file

@ -16,7 +16,7 @@ class MainWindow : public QMainWindow
public: public:
MainWindow(); MainWindow();
Marketplace* getMarketplace() { return marketplace_.get(); } Marketplace* getMarketplace() { return m_marketplace.get(); }
private slots: private slots:
void onBasketViewSelectionChanged(const QItemSelection& selected, void onBasketViewSelectionChanged(const QItemSelection& selected,
@ -49,8 +49,8 @@ class MainWindow : public QMainWindow
void readGeometry(); void readGeometry();
void updateStatLabel(); void updateStatLabel();
Ui::MainWindow ui_; Ui::MainWindow m_ui;
std::unique_ptr<Marketplace> marketplace_; std::unique_ptr<Marketplace> m_marketplace;
}; };
#endif #endif

View file

@ -6,31 +6,31 @@
PriceDialog::PriceDialog(QWidget* parent, bool forceDesc, Qt::WindowFlags f) : QDialog(parent, f) PriceDialog::PriceDialog(QWidget* parent, bool forceDesc, Qt::WindowFlags f) : QDialog(parent, f)
{ {
forceDesc_ = forceDesc; m_forceDesc = forceDesc;
ui_.setupUi(this); m_ui.setupUi(this);
ui_.priceSpinBox->setFocus(); m_ui.priceSpinBox->setFocus();
} }
int PriceDialog::getPrice() const { return static_cast<int>(ui_.priceSpinBox->value() * 100); } int PriceDialog::getPrice() const { return static_cast<int>(m_ui.priceSpinBox->value() * 100); }
std::string PriceDialog::getDescription() const { return ui_.descEdit->text().toStdString(); } std::string PriceDialog::getDescription() const { return m_ui.descEdit->text().toStdString(); }
void PriceDialog::accept() void PriceDialog::accept()
{ {
if (static_cast<int>(std::round(ui_.priceSpinBox->value() * 100.0L)) % 50 != 0) { if (static_cast<int>(std::round(m_ui.priceSpinBox->value() * 100.0L)) % 50 != 0) {
QMessageBox(QMessageBox::Icon::Warning, "Falsche Preiseingabe", QMessageBox(QMessageBox::Icon::Warning, "Falsche Preiseingabe",
"Es sind nur 0,50 Cent-Schritte erlaubt.", QMessageBox::StandardButton::Ok, "Es sind nur 0,50 Cent-Schritte erlaubt.", QMessageBox::StandardButton::Ok,
this) this)
.exec(); .exec();
} else if (forceDesc_ && ui_.descEdit->text().trimmed().isEmpty()) { } else if (m_forceDesc && m_ui.descEdit->text().trimmed().isEmpty()) {
QMessageBox(QMessageBox::Icon::Warning, "Artikelbeschreibung fehlt", QMessageBox(QMessageBox::Icon::Warning, "Artikelbeschreibung fehlt",
"Da Sie auf das Sonderkonto buchen ist eine Artikelbeschreibung erforderlich.", "Da Sie auf das Sonderkonto buchen ist eine Artikelbeschreibung erforderlich.",
QMessageBox::StandardButton::Ok, this) QMessageBox::StandardButton::Ok, this)
.exec(); .exec();
ui_.descEdit->setFocus(); m_ui.descEdit->setFocus();
} else { } else {
QDialog::accept(); QDialog::accept();
} }
} }
void PriceDialog::setForceDesc(bool force) { forceDesc_ = force; } void PriceDialog::setForceDesc(bool force) { m_forceDesc = force; }

View file

@ -19,8 +19,8 @@ class PriceDialog : public QDialog
private: private:
void on_model_duplicateSellerNo(const QString& message); void on_model_duplicateSellerNo(const QString& message);
virtual void accept() override; virtual void accept() override;
Ui::PriceDialog ui_; Ui::PriceDialog m_ui;
bool forceDesc_; bool m_forceDesc;
}; };
#endif #endif

View file

@ -19,20 +19,20 @@ namespace fs = std::filesystem;
ReportDialog::ReportDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f) ReportDialog::ReportDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f)
{ {
ui_.setupUi(this); m_ui.setupUi(this);
market_ = dynamic_cast<MainWindow *>(parent)->getMarketplace(); m_market = dynamic_cast<MainWindow *>(parent)->getMarketplace();
model_ = std::make_unique<ReportModel>(market_, ui_.reportView); m_model = std::make_unique<ReportModel>(m_market, m_ui.reportView);
ui_.reportView->setModel(model_.get()); m_ui.reportView->setModel(m_model.get());
ui_.reportView->hideColumn(0); m_ui.reportView->hideColumn(0);
ui_.reportView->setRowHidden(0, true); // hide the special "Sonderkonto" user m_ui.reportView->setRowHidden(0, true); // hide the special "Sonderkonto" user
connect(ui_.exportCsvButton, &QPushButton::clicked, this, connect(m_ui.exportCsvButton, &QPushButton::clicked, this,
&ReportDialog::onExportCsvButtonClicked); &ReportDialog::onExportCsvButtonClicked);
connect(ui_.printReportButton, &QPushButton::clicked, this, connect(m_ui.printReportButton, &QPushButton::clicked, this,
&ReportDialog::onPrintReportButtonClicked); &ReportDialog::onPrintReportButtonClicked);
connect(ui_.printSellerReceiptButton, &QPushButton::clicked, this, connect(m_ui.printSellerReceiptButton, &QPushButton::clicked, this,
&ReportDialog::onPrintSellerReceiptButtonClicked); &ReportDialog::onPrintSellerReceiptButtonClicked);
connect(ui_.reportView->selectionModel(), &QItemSelectionModel::selectionChanged, this, connect(m_ui.reportView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&ReportDialog::onReportViewSelectionChanged); &ReportDialog::onReportViewSelectionChanged);
} }
@ -54,7 +54,7 @@ void ReportDialog::onExportCsvButtonClicked()
fs::path filePath(filename.toStdString()); fs::path filePath(filename.toStdString());
#endif #endif
market_->exportReportToCSV(filePath, feeInPercent, maxFeeInEuro); m_market->exportReportToCSV(filePath, feeInPercent, maxFeeInEuro);
} }
void ReportDialog::onPrintReportButtonClicked() void ReportDialog::onPrintReportButtonClicked()
@ -76,7 +76,7 @@ void ReportDialog::onPrintReportButtonClicked()
int height = printer.height(); int height = printer.height();
int width = printer.width(); int width = printer.width();
const double ENTRIES_PER_PAGE = 51; const double ENTRIES_PER_PAGE = 51;
const auto &sellers = market_->getSellers(); const auto &sellers = m_market->getSellers();
unsigned int numPages = std::ceil(sellers.size() / ENTRIES_PER_PAGE); unsigned int numPages = std::ceil(sellers.size() / ENTRIES_PER_PAGE);
painter.begin(&printer); painter.begin(&printer);
@ -126,7 +126,7 @@ void ReportDialog::onPrintReportButtonClicked()
} }
// pieces booked on the special account "Sonderkonto" // pieces booked on the special account "Sonderkonto"
const auto specialSeller = market_->findSellerWithSellerNo(0); const auto specialSeller = m_market->findSellerWithSellerNo(0);
if (specialSeller && specialSeller->numArticlesSold() > 0) { if (specialSeller && specialSeller->numArticlesSold() > 0) {
printer.newPage(); printer.newPage();
painter.setFont(QFont("Arial", 16, QFont::Bold)); painter.setFont(QFont("Arial", 16, QFont::Bold));
@ -163,8 +163,8 @@ void ReportDialog::onPrintReportButtonClicked()
"Auswertung Kindersachenmarkt"); "Auswertung Kindersachenmarkt");
painter.setFont(fixedFont); painter.setFont(fixedFont);
QString content("Gesamtstatistik\n===============\n\n"); QString content("Gesamtstatistik\n===============\n\n");
int numArticlesOffered = market_->getNumArticlesOffered(); int numArticlesOffered = m_market->getNumArticlesOffered();
int numArticlesSold = market_->getNumArticlesSold(); int numArticlesSold = m_market->getNumArticlesSold();
double percentArticlesSold = double percentArticlesSold =
(static_cast<double>(numArticlesSold) / static_cast<double>(numArticlesOffered)) * 100; (static_cast<double>(numArticlesSold) / static_cast<double>(numArticlesOffered)) * 100;
content += QString("Registrierte Verkäufer: %1\n").arg(sellers.size() - 1, 6); content += QString("Registrierte Verkäufer: %1\n").arg(sellers.size() - 1, 6);
@ -172,14 +172,14 @@ void ReportDialog::onPrintReportButtonClicked()
content += QString("Verkaufte Artikel: %1 (%L2 %)\n") content += QString("Verkaufte Artikel: %1 (%L2 %)\n")
.arg(numArticlesSold, 6) .arg(numArticlesSold, 6)
.arg(percentArticlesSold, 0, 'f', 2); .arg(percentArticlesSold, 0, 'f', 2);
content += QString("Anzahl Kunden: %1\n\n").arg(market_->getSales().size(), 6); content += QString("Anzahl Kunden: %1\n\n").arg(m_market->getSales().size(), 6);
content += QString("Gesamtumsatz: %1\n").arg(market_->getOverallSumAsString().c_str(), 10); content += QString("Gesamtumsatz: %1\n").arg(m_market->getOverallSumAsString().c_str(), 10);
content += content +=
QString("Ausgezahlt: %1\n") QString("Ausgezahlt: %1\n")
.arg(market_->getOverallPaymentAsString(feeInPercent, maxFeeInEuro * 100).c_str(), 10); .arg(m_market->getOverallPaymentAsString(feeInPercent, maxFeeInEuro * 100).c_str(), 10);
content += content +=
QString("Verbleibend: %1\n\n") QString("Verbleibend: %1\n\n")
.arg(market_->getOverallRevenueAsString(feeInPercent, maxFeeInEuro * 100).c_str(), 10); .arg(m_market->getOverallRevenueAsString(feeInPercent, maxFeeInEuro * 100).c_str(), 10);
content += QString("(Einbehaltener Prozentsatz: %1 %)\n").arg(feeInPercent, 3); content += QString("(Einbehaltener Prozentsatz: %1 %)\n").arg(feeInPercent, 3);
content += QString("(Maximal einbehaltener Betrag: %1 €)\n").arg(maxFeeInEuro, 3); content += QString("(Maximal einbehaltener Betrag: %1 €)\n").arg(maxFeeInEuro, 3);
@ -196,12 +196,12 @@ void ReportDialog::onPrintSellerReceiptButtonClicked()
QString posPrinterDevice = settings.value("global/posPrinterDevice", "").toString(); QString posPrinterDevice = settings.value("global/posPrinterDevice", "").toString();
QString posPrinterEndpoint = settings.value("global/posPrinterEndpoint", "").toString(); QString posPrinterEndpoint = settings.value("global/posPrinterEndpoint", "").toString();
auto selModel = ui_.reportView->selectionModel(); auto selModel = m_ui.reportView->selectionModel();
if (selModel->hasSelection() == false) if (selModel->hasSelection() == false)
return; return;
auto indexes = selModel->selectedRows(); auto indexes = selModel->selectedRows();
auto &seller = market_->getSellers().at(indexes[0].row()); auto &seller = m_market->getSellers().at(indexes[0].row());
auto printerDevice = auto printerDevice =
convertToPosPrinterDevice(posPrinterDevice.toStdString(), posPrinterEndpoint.toStdString()); convertToPosPrinterDevice(posPrinterDevice.toStdString(), posPrinterEndpoint.toStdString());
@ -224,8 +224,8 @@ void ReportDialog::onReportViewSelectionChanged(const QItemSelection &selected,
[[maybe_unused]] const QItemSelection &deselected) [[maybe_unused]] const QItemSelection &deselected)
{ {
if (selected.size() > 0) { if (selected.size() > 0) {
ui_.printSellerReceiptButton->setEnabled(true); m_ui.printSellerReceiptButton->setEnabled(true);
} else { } else {
ui_.printSellerReceiptButton->setEnabled(false); m_ui.printSellerReceiptButton->setEnabled(false);
} }
} }

View file

@ -25,9 +25,9 @@ class ReportDialog : public QDialog
const QItemSelection& deselected); const QItemSelection& deselected);
private: private:
Ui::ReportDialog ui_; Ui::ReportDialog m_ui;
Marketplace* market_; Marketplace* m_market;
std::unique_ptr<ReportModel> model_; std::unique_ptr<ReportModel> m_model;
}; };
#endif #endif

View file

@ -5,16 +5,16 @@
#include <QSettings> #include <QSettings>
ReportModel::ReportModel(Marketplace* market, QObject* parent) ReportModel::ReportModel(Marketplace* market, QObject* parent)
: QAbstractTableModel(parent), market_(market) : QAbstractTableModel(parent), m_market(market)
{ {
QSettings settings; QSettings settings;
feeInPercent_ = settings.value("global/feeInPercent").toInt(); m_feeInPercent = settings.value("global/feeInPercent").toInt();
maxFeeInCent_ = settings.value("global/maxFeeInEuro").toInt() * 100; m_maxFeeInCent = settings.value("global/maxFeeInEuro").toInt() * 100;
} }
int ReportModel::rowCount([[maybe_unused]] const QModelIndex& parent) const int ReportModel::rowCount([[maybe_unused]] const QModelIndex& parent) const
{ {
return static_cast<int>(market_->getSellers().size()); return static_cast<int>(m_market->getSellers().size());
} }
int ReportModel::columnCount([[maybe_unused]] const QModelIndex& parent) const { return 7; } int ReportModel::columnCount([[maybe_unused]] const QModelIndex& parent) const { return 7; }
@ -52,10 +52,10 @@ QVariant ReportModel::data(const QModelIndex& index, int role) const
if (role != Qt::DisplayRole) if (role != Qt::DisplayRole)
return QVariant(); return QVariant();
if (market_->getSellers().size() == 0) if (m_market->getSellers().size() == 0)
return QVariant(); return QVariant();
Seller* seller = market_->getSellers().at(index.row()).get(); Seller* seller = m_market->getSellers().at(index.row()).get();
switch (index.column()) { switch (index.column()) {
case 0: case 0:
@ -71,7 +71,7 @@ QVariant ReportModel::data(const QModelIndex& index, int role) const
case 5: case 5:
return seller->sumAsString().c_str(); return seller->sumAsString().c_str();
case 6: case 6:
return paymentAsString(seller->sumInCents(), feeInPercent_, maxFeeInCent_).c_str(); return paymentAsString(seller->sumInCents(), m_feeInPercent, m_maxFeeInCent).c_str();
default: default:
return "???"; return "???";
} }

View file

@ -15,9 +15,9 @@ class ReportModel : public QAbstractTableModel
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const override; virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
private: private:
Marketplace* market_; Marketplace* m_market;
int feeInPercent_{}; int m_feeInPercent{};
int maxFeeInCent_{}; int m_maxFeeInCent{};
}; };
#endif #endif

View file

@ -9,7 +9,7 @@
SaleModel::SaleModel(Marketplace* market, QObject* parent) : QAbstractItemModel(parent) SaleModel::SaleModel(Marketplace* market, QObject* parent) : QAbstractItemModel(parent)
{ {
marketplace_ = market; m_marketplace = market;
} }
QModelIndex SaleModel::index(int row, int column, const QModelIndex& parent) const QModelIndex SaleModel::index(int row, int column, const QModelIndex& parent) const
@ -18,7 +18,7 @@ QModelIndex SaleModel::index(int row, int column, const QModelIndex& parent) con
return QModelIndex(); return QModelIndex();
if (!parent.isValid()) { if (!parent.isValid()) {
Sale* sale = marketplace_->getSales().at(row).get(); Sale* sale = m_marketplace->getSales().at(row).get();
return createIndex(row, column, sale); return createIndex(row, column, sale);
} else if (!parent.parent().isValid()) { } else if (!parent.parent().isValid()) {
Sale* sale = static_cast<Sale*>(parent.internalPointer()); Sale* sale = static_cast<Sale*>(parent.internalPointer());
@ -49,10 +49,10 @@ QModelIndex SaleModel::parent(const QModelIndex& index) const
sale = dynamic_cast<Sale*>(ent); sale = dynamic_cast<Sale*>(ent);
if (sale) { if (sale) {
if (sale == rootItem.get()) if (sale == m_rootItem.get())
return QModelIndex(); return QModelIndex();
else { else {
return createIndex(-1, 0, rootItem.get()); return createIndex(-1, 0, m_rootItem.get());
} }
} else { } else {
article = dynamic_cast<Article*>(ent); article = dynamic_cast<Article*>(ent);
@ -132,7 +132,7 @@ int SaleModel::rowCount(const QModelIndex& parent) const
return 0; return 0;
if (!parent.isValid()) { if (!parent.isValid()) {
return marketplace_->getSales().size(); return m_marketplace->getSales().size();
} else if (!parent.parent().isValid()) { } else if (!parent.parent().isValid()) {
Sale* sale = static_cast<Sale*>(parent.internalPointer()); Sale* sale = static_cast<Sale*>(parent.internalPointer());
return sale->getArticles().size(); return sale->getArticles().size();
@ -167,7 +167,7 @@ QVariant SaleModel::headerData(int section, Qt::Orientation orientation, int rol
void SaleModel::onBasketDataChanged() void SaleModel::onBasketDataChanged()
{ {
emit beginResetModel(); emit beginResetModel();
auto& sales = marketplace_->getSales(); auto& sales = m_marketplace->getSales();
std::sort(sales.begin(), sales.end(), [](const auto& lhs, const auto& rhs) { std::sort(sales.begin(), sales.end(), [](const auto& lhs, const auto& rhs) {
return lhs->getTimestamp() > rhs->getTimestamp(); return lhs->getTimestamp() > rhs->getTimestamp();
}); });
@ -179,11 +179,11 @@ bool SaleModel::removeRows(int row, int count, const QModelIndex& parent)
if (!parent.isValid()) { if (!parent.isValid()) {
// remove complete sale // remove complete sale
emit beginRemoveRows(parent, row, row + count - 1); emit beginRemoveRows(parent, row, row + count - 1);
auto& sale = marketplace_->getSales().at(row); auto& sale = m_marketplace->getSales().at(row);
sale->setState(Sale::State::DELETE); sale->setState(Sale::State::DELETE);
std::for_each(sale->getArticles().begin(), sale->getArticles().end(), std::for_each(sale->getArticles().begin(), sale->getArticles().end(),
[](auto& a) { a->setState(Article::State::DELETE); }); [](auto& a) { a->setState(Article::State::DELETE); });
marketplace_->storeToDb(); m_marketplace->storeToDb();
emit endRemoveRows(); emit endRemoveRows();
} else if (!parent.parent().isValid()) { } else if (!parent.parent().isValid()) {
@ -199,7 +199,7 @@ bool SaleModel::removeRows(int row, int count, const QModelIndex& parent)
sale->setState(Sale::State::DELETE); sale->setState(Sale::State::DELETE);
} }
emit beginRemoveRows(parent.parent(), 0, 0); emit beginRemoveRows(parent.parent(), 0, 0);
marketplace_->storeToDb(); m_marketplace->storeToDb();
emit endRemoveRows(); emit endRemoveRows();
} }

View file

@ -24,8 +24,8 @@ class SaleModel : public QAbstractItemModel
void onBasketDataChanged(); void onBasketDataChanged();
private: private:
Marketplace* marketplace_; Marketplace* m_marketplace;
std::unique_ptr<Sale> rootItem{new Sale()}; std::unique_ptr<Sale> m_rootItem{new Sale()};
}; };
#endif #endif

View file

@ -7,25 +7,25 @@
SellerDialog::SellerDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f) SellerDialog::SellerDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f)
{ {
ui_.setupUi(this); m_ui.setupUi(this);
ui_.editButton->setVisible(false); m_ui.editButton->setVisible(false);
market_ = dynamic_cast<MainWindow*>(parent)->getMarketplace(); m_market = dynamic_cast<MainWindow*>(parent)->getMarketplace();
model_ = std::make_unique<SellerModel>(market_, ui_.tableView); m_model = std::make_unique<SellerModel>(m_market, m_ui.tableView);
ui_.tableView->setModel(model_.get()); m_ui.tableView->setModel(m_model.get());
ui_.tableView->setColumnHidden(0, true); // hide the uuid m_ui.tableView->setColumnHidden(0, true); // hide the uuid
ui_.tableView->setRowHidden(0, true); // hide the special "Sonderkonto" user m_ui.tableView->setRowHidden(0, true); // hide the special "Sonderkonto" user
connect(ui_.newButton, &QPushButton::clicked, this, &SellerDialog::on_newButton_clicked); connect(m_ui.newButton, &QPushButton::clicked, this, &SellerDialog::on_newButton_clicked);
connect(ui_.deleteButton, &QPushButton::clicked, this, &SellerDialog::on_deleteButton_clicked); connect(m_ui.deleteButton, &QPushButton::clicked, this, &SellerDialog::on_deleteButton_clicked);
connect(model_.get(), &SellerModel::duplicateSellerNo, this, connect(m_model.get(), &SellerModel::duplicateSellerNo, this,
&SellerDialog::on_model_duplicateSellerNo); &SellerDialog::on_model_duplicateSellerNo);
connect(ui_.tableView->selectionModel(), &QItemSelectionModel::selectionChanged, this, connect(m_ui.tableView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&SellerDialog::onSellerViewSelectionChanged); &SellerDialog::onSellerViewSelectionChanged);
} }
void SellerDialog::on_newButton_clicked() void SellerDialog::on_newButton_clicked()
{ {
// Don't allow new seller if market has already started // Don't allow new seller if market has already started
if (market_->getSales().size() > 0) { if (m_market->getSales().size() > 0) {
QMessageBox(QMessageBox::Icon::Warning, "Hinweis", QMessageBox(QMessageBox::Icon::Warning, "Hinweis",
"Da die Verkaufsphase schon begonnen hat (Artikel wurden bereits verkauft) " "Da die Verkaufsphase schon begonnen hat (Artikel wurden bereits verkauft) "
"können Sie keine Verkäufer mehr hinzufügen.", "können Sie keine Verkäufer mehr hinzufügen.",
@ -34,22 +34,22 @@ void SellerDialog::on_newButton_clicked()
return; return;
} }
ui_.tableView->reset(); m_ui.tableView->reset();
ui_.tableView->model()->insertRows(ui_.tableView->model()->rowCount(), 1); m_ui.tableView->model()->insertRows(m_ui.tableView->model()->rowCount(), 1);
ui_.tableView->scrollToBottom(); m_ui.tableView->scrollToBottom();
ui_.tableView->selectRow(ui_.tableView->model()->rowCount() - 1); m_ui.tableView->selectRow(m_ui.tableView->model()->rowCount() - 1);
QModelIndex idx = ui_.tableView->model()->index(ui_.tableView->model()->rowCount() - 1, 2); QModelIndex idx = m_ui.tableView->model()->index(m_ui.tableView->model()->rowCount() - 1, 2);
ui_.tableView->setCurrentIndex(idx); m_ui.tableView->setCurrentIndex(idx);
ui_.tableView->edit(idx); m_ui.tableView->edit(idx);
} }
void SellerDialog::on_deleteButton_clicked() void SellerDialog::on_deleteButton_clicked()
{ {
auto selModel = ui_.tableView->selectionModel(); auto selModel = m_ui.tableView->selectionModel();
if (selModel->hasSelection() == false) if (selModel->hasSelection() == false)
return; return;
if (market_->getSales().size() > 0) { if (m_market->getSales().size() > 0) {
QMessageBox(QMessageBox::Icon::Warning, "Hinweis", QMessageBox(QMessageBox::Icon::Warning, "Hinweis",
"Da die Verkaufsphase schon begonnen hat (Artikel wurden bereits verkauft) " "Da die Verkaufsphase schon begonnen hat (Artikel wurden bereits verkauft) "
"können Sie keine Verkäufer mehr löschen.", "können Sie keine Verkäufer mehr löschen.",
@ -72,7 +72,7 @@ void SellerDialog::on_deleteButton_clicked()
// Deleting the rows, beginning with the last one! // Deleting the rows, beginning with the last one!
for (auto iter = indexes.constEnd() - 1; iter >= indexes.constBegin(); --iter) { for (auto iter = indexes.constEnd() - 1; iter >= indexes.constBegin(); --iter) {
ui_.tableView->model()->removeRow(iter->row()); m_ui.tableView->model()->removeRow(iter->row());
} }
} }
@ -102,8 +102,8 @@ void SellerDialog::onSellerViewSelectionChanged(const QItemSelection& selected,
[[maybe_unused]] const QItemSelection& deselected) [[maybe_unused]] const QItemSelection& deselected)
{ {
if (selected.size() > 0) { if (selected.size() > 0) {
ui_.deleteButton->setEnabled(true); m_ui.deleteButton->setEnabled(true);
} else { } else {
ui_.deleteButton->setEnabled(false); m_ui.deleteButton->setEnabled(false);
} }
} }

View file

@ -26,9 +26,9 @@ class SellerDialog : public QDialog
void on_deleteButton_clicked(); void on_deleteButton_clicked();
void on_model_duplicateSellerNo(const QString& message); void on_model_duplicateSellerNo(const QString& message);
virtual void accept() override; virtual void accept() override;
Ui::SellerDialog ui_; Ui::SellerDialog m_ui;
Marketplace* market_; Marketplace* m_market;
std::unique_ptr<SellerModel> model_; std::unique_ptr<SellerModel> m_model;
}; };
#endif #endif

View file

@ -5,13 +5,13 @@
#include <QMessageBox> #include <QMessageBox>
SellerModel::SellerModel(Marketplace* market, QObject* parent) SellerModel::SellerModel(Marketplace* market, QObject* parent)
: QAbstractTableModel(parent), marketplace_(market) : QAbstractTableModel(parent), m_marketplace(market)
{ {
} }
int SellerModel::rowCount([[maybe_unused]] const QModelIndex& parent) const int SellerModel::rowCount([[maybe_unused]] const QModelIndex& parent) const
{ {
return marketplace_->getSellers().size(); return m_marketplace->getSellers().size();
} }
int SellerModel::columnCount([[maybe_unused]] const QModelIndex& parent) const { return 5; } int SellerModel::columnCount([[maybe_unused]] const QModelIndex& parent) const { return 5; }
@ -21,10 +21,10 @@ QVariant SellerModel::data(const QModelIndex& index, int role) const
if (role != Qt::DisplayRole) if (role != Qt::DisplayRole)
return QVariant(); return QVariant();
if (marketplace_->getSellers().size() == 0) if (m_marketplace->getSellers().size() == 0)
return QVariant(); return QVariant();
Seller* seller = marketplace_->getSellers().at(index.row()).get(); Seller* seller = m_marketplace->getSellers().at(index.row()).get();
switch (index.column()) { switch (index.column()) {
case 0: case 0:
@ -78,7 +78,7 @@ bool SellerModel::setData(const QModelIndex& index, const QVariant& value, int r
if (role != Qt::EditRole) if (role != Qt::EditRole)
return false; return false;
Seller* seller = marketplace_->getSellers().at(index.row()).get(); Seller* seller = m_marketplace->getSellers().at(index.row()).get();
switch (index.column()) { switch (index.column()) {
case 0: case 0:
@ -88,11 +88,11 @@ bool SellerModel::setData(const QModelIndex& index, const QVariant& value, int r
if (value.toInt() < 0) if (value.toInt() < 0)
return false; return false;
auto iter = auto iter =
std::find_if(marketplace_->getSellers().begin(), marketplace_->getSellers().end(), std::find_if(m_marketplace->getSellers().begin(), m_marketplace->getSellers().end(),
[&value](const std::unique_ptr<Seller>& s) { [&value](const std::unique_ptr<Seller>& s) {
return value.toInt() == s->getSellerNo(); return value.toInt() == s->getSellerNo();
}); });
if (iter != marketplace_->getSellers().end()) { if (iter != m_marketplace->getSellers().end()) {
emit duplicateSellerNo( emit duplicateSellerNo(
"Die Verkäufernummer muss eindeutig sein.\n(Möglicherweise wird die Nummer von " "Die Verkäufernummer muss eindeutig sein.\n(Möglicherweise wird die Nummer von "
"einem (ausgeblendeten) Eintrag, der zum Löschen vorgemerkt ist, verwendet.)"); "einem (ausgeblendeten) Eintrag, der zum Löschen vorgemerkt ist, verwendet.)");
@ -123,8 +123,8 @@ bool SellerModel::insertRows(int row, int count, const QModelIndex& parent)
{ {
emit beginInsertRows(parent, row, row + count - 1); emit beginInsertRows(parent, row, row + count - 1);
auto seller = std::make_unique<Seller>(); auto seller = std::make_unique<Seller>();
seller->setSellerNo(marketplace_->getNextSellerNo()); seller->setSellerNo(m_marketplace->getNextSellerNo());
marketplace_->getSellers().push_back(std::move(seller)); m_marketplace->getSellers().push_back(std::move(seller));
emit endInsertRows(); emit endInsertRows();
return true; return true;
@ -132,21 +132,21 @@ bool SellerModel::insertRows(int row, int count, const QModelIndex& parent)
bool SellerModel::removeRows(int row, int count, const QModelIndex& parent) bool SellerModel::removeRows(int row, int count, const QModelIndex& parent)
{ {
auto seller = marketplace_->getSellers().at(row).get(); auto seller = m_marketplace->getSellers().at(row).get();
if (seller->getState() == Seller::State::NEW) { if (seller->getState() == Seller::State::NEW) {
emit beginRemoveRows(parent, row, row + count - 1); emit beginRemoveRows(parent, row, row + count - 1);
marketplace_->getSellers().erase( m_marketplace->getSellers().erase(
std::remove_if(marketplace_->getSellers().begin(), marketplace_->getSellers().end(), std::remove_if(m_marketplace->getSellers().begin(), m_marketplace->getSellers().end(),
[&seller](const std::unique_ptr<Seller>& a) { [&seller](const std::unique_ptr<Seller>& a) {
return a->getId() == seller->getId(); return a->getId() == seller->getId();
}), }),
marketplace_->getSellers().end()); m_marketplace->getSellers().end());
emit endRemoveRows(); emit endRemoveRows();
return true; return true;
} else { } else {
emit beginRemoveRows(parent, row, row + count - 1); emit beginRemoveRows(parent, row, row + count - 1);
seller->setState(Seller::State::DELETE); seller->setState(Seller::State::DELETE);
marketplace_->storeToDb(true); m_marketplace->storeToDb(true);
emit endRemoveRows(); emit endRemoveRows();
return true; return true;
} }

View file

@ -25,7 +25,7 @@ class SellerModel : public QAbstractTableModel
void duplicateSellerNo(const QString &message); void duplicateSellerNo(const QString &message);
private: private:
Marketplace* marketplace_; Marketplace *m_marketplace;
}; };
#endif #endif

View file

@ -15,7 +15,7 @@
SettingsDialog::SettingsDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f) SettingsDialog::SettingsDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f)
{ {
ui_.setupUi(this); m_ui.setupUi(this);
QSettings settings{}; QSettings settings{};
int cashPointNo = settings.value("global/cashPointNo").toInt(); int cashPointNo = settings.value("global/cashPointNo").toInt();
@ -26,25 +26,25 @@ 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(); m_market = dynamic_cast<MainWindow *>(parent)->getMarketplace();
ui_.cashPointNoSpinBox->setValue(cashPointNo); m_ui.cashPointNoSpinBox->setValue(cashPointNo);
ui_.communeEdit->setText(commune); m_ui.communeEdit->setText(commune);
ui_.posPrinterDeviceEdit->setText(posPrinterDevice); m_ui.posPrinterDeviceEdit->setText(posPrinterDevice);
ui_.posPrinterEndpointEdit->setText(posPrinterEndpoint); m_ui.posPrinterEndpointEdit->setText(posPrinterEndpoint);
ui_.feePercentSpinBox->setValue(feeInPercent); m_ui.feePercentSpinBox->setValue(feeInPercent);
ui_.maxFeeSpinBox->setValue(maxFeeInEuro); m_ui.maxFeeSpinBox->setValue(maxFeeInEuro);
connect(ui_.testPosPrinterButton, &QPushButton::clicked, this, [this]() { connect(m_ui.testPosPrinterButton, &QPushButton::clicked, this, [this]() {
using namespace std::string_literals; using namespace std::string_literals;
try { try {
if (ui_.posPrinterDeviceEdit->text().isEmpty()) { if (m_ui.posPrinterDeviceEdit->text().isEmpty()) {
PosPrinter printer; PosPrinter printer;
printer.printTest(); printer.printTest();
} else { } else {
std::string posPrinterDeviceString = ui_.posPrinterDeviceEdit->text().toStdString(); std::string posPrinterDeviceString = m_ui.posPrinterDeviceEdit->text().toStdString();
std::string posPrinterEndpointString = std::string posPrinterEndpointString =
ui_.posPrinterEndpointEdit->text().toStdString(); m_ui.posPrinterEndpointEdit->text().toStdString();
try { try {
auto printerDevice = auto printerDevice =
@ -80,17 +80,17 @@ void SettingsDialog::accept()
QSettings settings; QSettings settings;
int oldCashPointNo = settings.value("global/cashPointNo").toInt(); int oldCashPointNo = settings.value("global/cashPointNo").toInt();
int newCashPointNo = ui_.cashPointNoSpinBox->value(); int newCashPointNo = m_ui.cashPointNoSpinBox->value();
settings.setValue("global/commune", ui_.communeEdit->text().trimmed()); settings.setValue("global/commune", m_ui.communeEdit->text().trimmed());
settings.setValue("global/posPrinterDevice", ui_.posPrinterDeviceEdit->text().trimmed()); settings.setValue("global/posPrinterDevice", m_ui.posPrinterDeviceEdit->text().trimmed());
settings.setValue("global/posPrinterEndpoint", ui_.posPrinterEndpointEdit->text().trimmed()); settings.setValue("global/posPrinterEndpoint", m_ui.posPrinterEndpointEdit->text().trimmed());
settings.setValue("global/feeInPercent", ui_.feePercentSpinBox->value()); settings.setValue("global/feeInPercent", m_ui.feePercentSpinBox->value());
settings.setValue("global/maxFeeInEuro", ui_.maxFeeSpinBox->value()); settings.setValue("global/maxFeeInEuro", m_ui.maxFeeSpinBox->value());
if (oldCashPointNo != newCashPointNo) { if (oldCashPointNo != newCashPointNo) {
int result{0}; int result{0};
if (market_ && market_->getSales().size() > 0) { if (m_market && m_market->getSales().size() > 0) {
result = QMessageBox(QMessageBox::Icon::Question, "Sind Sie sicher?", result = QMessageBox(QMessageBox::Icon::Question, "Sind Sie sicher?",
"Möchten Sie die Kassen-Nr wirklich ändern? Diese muss über alle " "Möchten Sie die Kassen-Nr wirklich ändern? Diese muss über alle "
"Installationen hinweg eindeutig sein.", "Installationen hinweg eindeutig sein.",
@ -112,7 +112,7 @@ void SettingsDialog::accept()
QDialog::accept(); QDialog::accept();
return; return;
} }
settings.setValue("global/cashPointNo", ui_.cashPointNoSpinBox->value()); settings.setValue("global/cashPointNo", m_ui.cashPointNoSpinBox->value());
} }
} }

View file

@ -19,8 +19,8 @@ class SettingsDialog : public QDialog
void accept() override; void accept() override;
private: private:
Ui::SettingsDialog ui_; Ui::SettingsDialog m_ui;
Marketplace* market_{}; Marketplace* m_market{};
}; };
#endif #endif