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>
BasketModel::BasketModel(Marketplace* market, QObject* parent)
: QAbstractTableModel(parent), marketplace_(market)
: QAbstractTableModel(parent), m_marketplace(market)
{
}
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; }
@ -46,10 +46,10 @@ QVariant BasketModel::data(const QModelIndex& index, int role) const
if (role != Qt::DisplayRole)
return QVariant();
if (marketplace_->basketSize() == 0)
if (m_marketplace->basketSize() == 0)
return QVariant();
Article* article = marketplace_->getBasket().at(index.row()).get();
Article* article = m_marketplace->getBasket().at(index.row()).get();
switch (index.column()) {
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)
{
emit beginInsertRows(QModelIndex(), marketplace_->getBasket().size(),
marketplace_->getBasket().size());
emit beginInsertRows(QModelIndex(), m_marketplace->getBasket().size(),
m_marketplace->getBasket().size());
auto article = std::make_unique<Article>(price);
article->createUuid();
article->setDescription(desc);
article->setArticleNo(marketplace_->getNextArticleNo());
article->setArticleNo(m_marketplace->getNextArticleNo());
article->setSourceNo(QSettings().value("global/cashPointNo").toInt());
article->setSeller(seller);
marketplace_->addArticleToBasket(std::move(article));
m_marketplace->addArticleToBasket(std::move(article));
emit endInsertRows();
}
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>();
sale->createUuid();
sale->setSourceNo(QSettings().value("global/cashPointNo").toInt());
marketplace_->finishCurrentSale(std::move(sale));
m_marketplace->finishCurrentSale(std::move(sale));
emit endRemoveRows();
emit basketDataChanged();
}
void BasketModel::cancelSale()
{
emit beginRemoveRows(QModelIndex(), 0, marketplace_->getBasket().size() - 1);
marketplace_->getBasket().clear();
emit beginRemoveRows(QModelIndex(), 0, m_marketplace->getBasket().size() - 1);
m_marketplace->getBasket().clear();
emit endRemoveRows();
}
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);
marketplace_->getBasket().erase(
std::remove_if(marketplace_->getBasket().begin(), marketplace_->getBasket().end(),
m_marketplace->getBasket().erase(
std::remove_if(m_marketplace->getBasket().begin(), m_marketplace->getBasket().end(),
[&article](const auto& a) { return a->getUuid() == article->getUuid(); }),
marketplace_->getBasket().end());
m_marketplace->getBasket().end());
emit endRemoveRows();
return true;
}

View File

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

View File

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

View File

@ -6,31 +6,31 @@
PriceDialog::PriceDialog(QWidget* parent, bool forceDesc, Qt::WindowFlags f) : QDialog(parent, f)
{
forceDesc_ = forceDesc;
ui_.setupUi(this);
ui_.priceSpinBox->setFocus();
m_forceDesc = forceDesc;
m_ui.setupUi(this);
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()
{
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",
"Es sind nur 0,50 Cent-Schritte erlaubt.", QMessageBox::StandardButton::Ok,
this)
.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",
"Da Sie auf das Sonderkonto buchen ist eine Artikelbeschreibung erforderlich.",
QMessageBox::StandardButton::Ok, this)
.exec();
ui_.descEdit->setFocus();
m_ui.descEdit->setFocus();
} else {
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:
void on_model_duplicateSellerNo(const QString& message);
virtual void accept() override;
Ui::PriceDialog ui_;
bool forceDesc_;
Ui::PriceDialog m_ui;
bool m_forceDesc;
};
#endif

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -7,25 +7,25 @@
SellerDialog::SellerDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f)
{
ui_.setupUi(this);
ui_.editButton->setVisible(false);
market_ = dynamic_cast<MainWindow*>(parent)->getMarketplace();
model_ = std::make_unique<SellerModel>(market_, ui_.tableView);
ui_.tableView->setModel(model_.get());
ui_.tableView->setColumnHidden(0, true); // hide the uuid
ui_.tableView->setRowHidden(0, true); // hide the special "Sonderkonto" user
connect(ui_.newButton, &QPushButton::clicked, this, &SellerDialog::on_newButton_clicked);
connect(ui_.deleteButton, &QPushButton::clicked, this, &SellerDialog::on_deleteButton_clicked);
connect(model_.get(), &SellerModel::duplicateSellerNo, this,
m_ui.setupUi(this);
m_ui.editButton->setVisible(false);
m_market = dynamic_cast<MainWindow*>(parent)->getMarketplace();
m_model = std::make_unique<SellerModel>(m_market, m_ui.tableView);
m_ui.tableView->setModel(m_model.get());
m_ui.tableView->setColumnHidden(0, true); // hide the uuid
m_ui.tableView->setRowHidden(0, true); // hide the special "Sonderkonto" user
connect(m_ui.newButton, &QPushButton::clicked, this, &SellerDialog::on_newButton_clicked);
connect(m_ui.deleteButton, &QPushButton::clicked, this, &SellerDialog::on_deleteButton_clicked);
connect(m_model.get(), &SellerModel::duplicateSellerNo, this,
&SellerDialog::on_model_duplicateSellerNo);
connect(ui_.tableView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
connect(m_ui.tableView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&SellerDialog::onSellerViewSelectionChanged);
}
void SellerDialog::on_newButton_clicked()
{
// 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",
"Da die Verkaufsphase schon begonnen hat (Artikel wurden bereits verkauft) "
"können Sie keine Verkäufer mehr hinzufügen.",
@ -34,22 +34,22 @@ void SellerDialog::on_newButton_clicked()
return;
}
ui_.tableView->reset();
ui_.tableView->model()->insertRows(ui_.tableView->model()->rowCount(), 1);
ui_.tableView->scrollToBottom();
ui_.tableView->selectRow(ui_.tableView->model()->rowCount() - 1);
QModelIndex idx = ui_.tableView->model()->index(ui_.tableView->model()->rowCount() - 1, 2);
ui_.tableView->setCurrentIndex(idx);
ui_.tableView->edit(idx);
m_ui.tableView->reset();
m_ui.tableView->model()->insertRows(m_ui.tableView->model()->rowCount(), 1);
m_ui.tableView->scrollToBottom();
m_ui.tableView->selectRow(m_ui.tableView->model()->rowCount() - 1);
QModelIndex idx = m_ui.tableView->model()->index(m_ui.tableView->model()->rowCount() - 1, 2);
m_ui.tableView->setCurrentIndex(idx);
m_ui.tableView->edit(idx);
}
void SellerDialog::on_deleteButton_clicked()
{
auto selModel = ui_.tableView->selectionModel();
auto selModel = m_ui.tableView->selectionModel();
if (selModel->hasSelection() == false)
return;
if (market_->getSales().size() > 0) {
if (m_market->getSales().size() > 0) {
QMessageBox(QMessageBox::Icon::Warning, "Hinweis",
"Da die Verkaufsphase schon begonnen hat (Artikel wurden bereits verkauft) "
"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!
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)
{
if (selected.size() > 0) {
ui_.deleteButton->setEnabled(true);
m_ui.deleteButton->setEnabled(true);
} 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_model_duplicateSellerNo(const QString& message);
virtual void accept() override;
Ui::SellerDialog ui_;
Marketplace* market_;
std::unique_ptr<SellerModel> model_;
Ui::SellerDialog m_ui;
Marketplace* m_market;
std::unique_ptr<SellerModel> m_model;
};
#endif

View File

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

View File

@ -9,23 +9,23 @@ class SellerModel : public QAbstractTableModel
{
Q_OBJECT
public:
explicit SellerModel(Marketplace* market, QObject* parent = nullptr);
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override;
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const override;
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
public:
explicit SellerModel(Marketplace *market, QObject *parent = nullptr);
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override;
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override;
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
virtual Qt::ItemFlags flags(const QModelIndex& index) const override;
virtual bool setData(const QModelIndex& index, const QVariant& value,
virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
virtual bool setData(const QModelIndex &index, const QVariant &value,
int role = Qt::EditRole) override;
virtual bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
virtual bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
virtual bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
virtual bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
signals:
void duplicateSellerNo(const QString& message);
signals:
void duplicateSellerNo(const QString &message);
private:
Marketplace* marketplace_;
private:
Marketplace *m_marketplace;
};
#endif

View File

@ -15,7 +15,7 @@
SettingsDialog::SettingsDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f)
{
ui_.setupUi(this);
m_ui.setupUi(this);
QSettings settings{};
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();
if (parent)
market_ = dynamic_cast<MainWindow *>(parent)->getMarketplace();
m_market = dynamic_cast<MainWindow *>(parent)->getMarketplace();
ui_.cashPointNoSpinBox->setValue(cashPointNo);
ui_.communeEdit->setText(commune);
ui_.posPrinterDeviceEdit->setText(posPrinterDevice);
ui_.posPrinterEndpointEdit->setText(posPrinterEndpoint);
ui_.feePercentSpinBox->setValue(feeInPercent);
ui_.maxFeeSpinBox->setValue(maxFeeInEuro);
m_ui.cashPointNoSpinBox->setValue(cashPointNo);
m_ui.communeEdit->setText(commune);
m_ui.posPrinterDeviceEdit->setText(posPrinterDevice);
m_ui.posPrinterEndpointEdit->setText(posPrinterEndpoint);
m_ui.feePercentSpinBox->setValue(feeInPercent);
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;
try {
if (ui_.posPrinterDeviceEdit->text().isEmpty()) {
if (m_ui.posPrinterDeviceEdit->text().isEmpty()) {
PosPrinter printer;
printer.printTest();
} else {
std::string posPrinterDeviceString = ui_.posPrinterDeviceEdit->text().toStdString();
std::string posPrinterDeviceString = m_ui.posPrinterDeviceEdit->text().toStdString();
std::string posPrinterEndpointString =
ui_.posPrinterEndpointEdit->text().toStdString();
m_ui.posPrinterEndpointEdit->text().toStdString();
try {
auto printerDevice =
@ -80,17 +80,17 @@ void SettingsDialog::accept()
QSettings settings;
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/posPrinterDevice", ui_.posPrinterDeviceEdit->text().trimmed());
settings.setValue("global/posPrinterEndpoint", ui_.posPrinterEndpointEdit->text().trimmed());
settings.setValue("global/feeInPercent", ui_.feePercentSpinBox->value());
settings.setValue("global/maxFeeInEuro", ui_.maxFeeSpinBox->value());
settings.setValue("global/commune", m_ui.communeEdit->text().trimmed());
settings.setValue("global/posPrinterDevice", m_ui.posPrinterDeviceEdit->text().trimmed());
settings.setValue("global/posPrinterEndpoint", m_ui.posPrinterEndpointEdit->text().trimmed());
settings.setValue("global/feeInPercent", m_ui.feePercentSpinBox->value());
settings.setValue("global/maxFeeInEuro", m_ui.maxFeeSpinBox->value());
if (oldCashPointNo != newCashPointNo) {
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?",
"Möchten Sie die Kassen-Nr wirklich ändern? Diese muss über alle "
"Installationen hinweg eindeutig sein.",
@ -112,7 +112,7 @@ void SettingsDialog::accept()
QDialog::accept();
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;
private:
Ui::SettingsDialog ui_;
Marketplace* market_{};
Ui::SettingsDialog m_ui;
Marketplace* m_market{};
};
#endif