code cleanup
This commit is contained in:
parent
710b4cf9fb
commit
9fd29d588f
24 changed files with 60 additions and 101 deletions
|
@ -4,12 +4,8 @@
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
// Article::Article() : Entity() {}
|
|
||||||
|
|
||||||
Article::Article(int price) : price_(price) {}
|
Article::Article(int price) : price_(price) {}
|
||||||
|
|
||||||
// Article::Article(std::shared_ptr<Seller> sellerPtr) : Entity() { sellerPtr_ = sellerPtr; }
|
|
||||||
|
|
||||||
void Article::setArticleNo(int articleNo) { articleNo_ = articleNo; }
|
void Article::setArticleNo(int articleNo) { articleNo_ = articleNo; }
|
||||||
|
|
||||||
void Article::setPrice(int price) { price_ = price; }
|
void Article::setPrice(int price) { price_ = price; }
|
||||||
|
@ -29,10 +25,7 @@ Sale* Article::getSale() { return salePtr_; }
|
||||||
|
|
||||||
int Article::getPrice() const { return price_; }
|
int Article::getPrice() const { return price_; }
|
||||||
|
|
||||||
std::string Article::getPriceAsString() const
|
std::string Article::getPriceAsString() const { return formatCentAsEuroString(price_); }
|
||||||
{
|
|
||||||
return formatCentAsEuroString(price_);
|
|
||||||
}
|
|
||||||
|
|
||||||
int Article::getArticleNo() const { return articleNo_; }
|
int Article::getArticleNo() const { return articleNo_; }
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,8 @@
|
||||||
class CsvReader
|
class CsvReader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static std::size_t readSellersFromFile(const std::filesystem::path& filePath, Marketplace* market);
|
static std::size_t readSellersFromFile(const std::filesystem::path& filePath,
|
||||||
|
Marketplace* market);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -136,10 +136,7 @@ void Database::updateDbToVer2()
|
||||||
endTransaction();
|
endTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Database::updateDbToVer3()
|
void Database::updateDbToVer3() { newDb(); }
|
||||||
{
|
|
||||||
newDb();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Database::init()
|
void Database::init()
|
||||||
{
|
{
|
||||||
|
@ -274,8 +271,7 @@ unsigned int Database::storeSellers(std::vector<std::unique_ptr<Seller>>& seller
|
||||||
if (retCode != SQLITE_OK)
|
if (retCode != SQLITE_OK)
|
||||||
throw std::runtime_error(sqlite3_errmsg(db_));
|
throw std::runtime_error(sqlite3_errmsg(db_));
|
||||||
|
|
||||||
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":id"),
|
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":id"), seller->getId());
|
||||||
seller->getId());
|
|
||||||
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":seller_no"),
|
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":seller_no"),
|
||||||
seller->getSellerNo());
|
seller->getSellerNo());
|
||||||
sqlite3_bind_text(stmt, sqlite3_bind_parameter_index(stmt, ":first_name"),
|
sqlite3_bind_text(stmt, sqlite3_bind_parameter_index(stmt, ":first_name"),
|
||||||
|
@ -298,14 +294,13 @@ unsigned int Database::storeSellers(std::vector<std::unique_ptr<Seller>>& seller
|
||||||
} else if (seller->getState() == Seller::State::DELETE) {
|
} else if (seller->getState() == Seller::State::DELETE) {
|
||||||
count += static_cast<int>(seller->getArticles(false).size());
|
count += static_cast<int>(seller->getArticles(false).size());
|
||||||
|
|
||||||
retCode =
|
retCode = sqlite3_prepare_v2(db_, "DELETE FROM sellers WHERE seller_no = :id", -1,
|
||||||
sqlite3_prepare_v2(db_, "DELETE FROM sellers WHERE seller_no = :id", -1, &stmt, nullptr);
|
&stmt, nullptr);
|
||||||
|
|
||||||
if (retCode != SQLITE_OK)
|
if (retCode != SQLITE_OK)
|
||||||
throw std::runtime_error(sqlite3_errmsg(db_));
|
throw std::runtime_error(sqlite3_errmsg(db_));
|
||||||
|
|
||||||
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":id"),
|
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":id"), seller->getId());
|
||||||
seller->getId());
|
|
||||||
|
|
||||||
retCode = sqlite3_step(stmt);
|
retCode = sqlite3_step(stmt);
|
||||||
|
|
||||||
|
@ -592,8 +587,7 @@ unsigned int Database::loadSellers(std::vector<std::unique_ptr<Seller>>& sellers
|
||||||
if (retCode != SQLITE_OK)
|
if (retCode != SQLITE_OK)
|
||||||
throw std::runtime_error(sqlite3_errmsg(db_));
|
throw std::runtime_error(sqlite3_errmsg(db_));
|
||||||
|
|
||||||
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":seller_id"),
|
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":seller_id"), seller->getId());
|
||||||
seller->getId());
|
|
||||||
|
|
||||||
retCode = sqlite3_step(stmt);
|
retCode = sqlite3_step(stmt);
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
#include "entityint.h"
|
#include "entityint.h"
|
||||||
|
|
||||||
EntityInt::EntityInt(int id) {
|
EntityInt::EntityInt(int id) { id_ = id; }
|
||||||
id_ = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
void EntityInt::setId(int id) {
|
void EntityInt::setId(int id) { id_ = id; }
|
||||||
id_ = id;
|
|
||||||
}
|
|
||||||
|
|
|
@ -17,11 +17,6 @@ void EntityUuid::setUuidFromString(const std::string& uuidString)
|
||||||
uuid_ = generator(uuidString);
|
uuid_ = generator(uuidString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EntityUuid::setSourceNo(int sourceNo) { sourceNo_ = sourceNo; }
|
||||||
|
|
||||||
void EntityUuid::setSourceNo(int sourceNo) {
|
int EntityUuid::getSourceNo() const { return sourceNo_; }
|
||||||
sourceNo_ = sourceNo;
|
|
||||||
}
|
|
||||||
|
|
||||||
int EntityUuid::getSourceNo() const {
|
|
||||||
return sourceNo_;
|
|
||||||
}
|
|
||||||
|
|
|
@ -12,7 +12,8 @@
|
||||||
class ExcelReader
|
class ExcelReader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static std::size_t readSellersFromFile(const std::filesystem::path& filePath, Marketplace* market);
|
static std::size_t readSellersFromFile(const std::filesystem::path& filePath,
|
||||||
|
Marketplace* market);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -61,7 +61,8 @@ std::size_t JsonUtil::importSellers(const std::filesystem::path& filePath, Marke
|
||||||
return market->getSellers().size() - 1; // minus 1 because we don't count the "special" seller
|
return market->getSellers().size() - 1; // minus 1 because we don't count the "special" seller
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonUtil::exportSales(const std::filesystem::path& filePath, Marketplace* market, int cashPointNo)
|
void JsonUtil::exportSales(const std::filesystem::path& filePath, Marketplace* market,
|
||||||
|
int cashPointNo)
|
||||||
{
|
{
|
||||||
json root;
|
json root;
|
||||||
std::ofstream file(filePath);
|
std::ofstream file(filePath);
|
||||||
|
@ -94,7 +95,8 @@ void JsonUtil::exportSales(const std::filesystem::path& filePath, Marketplace* m
|
||||||
file << root.dump(4) << std::endl;
|
file << root.dump(4) << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonUtil::importSales(const std::filesystem::path& filePath, Marketplace* market, int cashPointNo)
|
void JsonUtil::importSales(const std::filesystem::path& filePath, Marketplace* market,
|
||||||
|
int cashPointNo)
|
||||||
{
|
{
|
||||||
std::ifstream file(filePath);
|
std::ifstream file(filePath);
|
||||||
json jsonValues = json::parse(file);
|
json jsonValues = json::parse(file);
|
||||||
|
|
|
@ -3,16 +3,18 @@
|
||||||
|
|
||||||
#include "marketplace.h"
|
#include "marketplace.h"
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class JsonUtil
|
class JsonUtil
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void exportSellers(const std::filesystem::path& filePath, Marketplace* market);
|
static void exportSellers(const std::filesystem::path& filePath, Marketplace* market);
|
||||||
static std::size_t importSellers(const std::filesystem::path& filePath, Marketplace* market);
|
static std::size_t importSellers(const std::filesystem::path& filePath, Marketplace* market);
|
||||||
static void exportSales(const std::filesystem::path& filePath, Marketplace* market, int cashPointNo);
|
static void exportSales(const std::filesystem::path& filePath, Marketplace* market,
|
||||||
static void importSales(const std::filesystem::path& filePath, Marketplace* market, int cashPointNo);
|
int cashPointNo);
|
||||||
|
static void importSales(const std::filesystem::path& filePath, Marketplace* market,
|
||||||
|
int cashPointNo);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -3,11 +3,11 @@
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <filesystem>
|
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
|
@ -104,20 +104,10 @@ Seller* Marketplace::findSellerWithSellerNo(int sellerNo)
|
||||||
return (*iter).get();
|
return (*iter).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Seller* Marketplace::findSellerWithUuid(const std::string& uuid)
|
|
||||||
{
|
|
||||||
auto iter = std::find_if(sellers_.begin(), sellers_.end(),
|
|
||||||
[uuid](const auto& a) { return a->getUuidAsString() == uuid; });
|
|
||||||
if (iter == sellers_.end())
|
|
||||||
return nullptr;
|
|
||||||
return (*iter).get();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
void Marketplace::addArticleToBasket(std::unique_ptr<Article> article)
|
void Marketplace::addArticleToBasket(std::unique_ptr<Article> article)
|
||||||
{
|
{
|
||||||
basket_.insert(basket_.begin(), std::move(article)); // article to the beginning of the basket vector
|
basket_.insert(basket_.begin(),
|
||||||
|
std::move(article)); // article to the beginning of the basket vector
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Marketplace::basketSize() { return basket_.size(); }
|
size_t Marketplace::basketSize() { return basket_.size(); }
|
||||||
|
@ -189,7 +179,8 @@ void Marketplace::exportReportToCSV(const fs::path& filePath, int feeInPercent,
|
||||||
<< escapeCsvValue(seller->getFirstName(), delimiter) << delimiter
|
<< escapeCsvValue(seller->getFirstName(), delimiter) << delimiter
|
||||||
<< seller->numArticlesOffered() << delimiter << seller->numArticlesSold() << delimiter
|
<< seller->numArticlesOffered() << delimiter << seller->numArticlesSold() << delimiter
|
||||||
<< escapeCsvValue(seller->sumAsString(), delimiter) << delimiter
|
<< escapeCsvValue(seller->sumAsString(), delimiter) << delimiter
|
||||||
<< escapeCsvValue(paymentAsString(seller->sumInCents(), feeInPercent, maxFeeInEuro * 100),
|
<< escapeCsvValue(
|
||||||
|
paymentAsString(seller->sumInCents(), feeInPercent, maxFeeInEuro * 100),
|
||||||
delimiter)
|
delimiter)
|
||||||
<< "\n";
|
<< "\n";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#ifndef MARKETPLACE_H
|
#ifndef MARKETPLACE_H
|
||||||
#define MARKETPLACE_H
|
#define MARKETPLACE_H
|
||||||
|
|
||||||
#include "database.h"
|
|
||||||
#include "article.h"
|
#include "article.h"
|
||||||
|
#include "database.h"
|
||||||
#include "sale.h"
|
#include "sale.h"
|
||||||
#include "seller.h"
|
#include "seller.h"
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,6 @@ ArticlesVec& Sale::getArticles() { return articles_; }
|
||||||
|
|
||||||
void Sale::removeArticle(const Article* articlePtr)
|
void Sale::removeArticle(const Article* articlePtr)
|
||||||
{
|
{
|
||||||
/* auto it = std::find_if(articles_.begin(), articles_.end(),
|
|
||||||
[&articlePtr](auto art) { return art.get() == articlePtr; }); */
|
|
||||||
auto it = std::find(articles_.begin(), articles_.end(), articlePtr);
|
auto it = std::find(articles_.begin(), articles_.end(), articlePtr);
|
||||||
|
|
||||||
if (it != articles_.end()) {
|
if (it != articles_.end()) {
|
||||||
|
|
|
@ -32,7 +32,6 @@ class Seller : public EntityInt
|
||||||
std::string getSellerNoAsString() const;
|
std::string getSellerNoAsString() const;
|
||||||
int numArticlesOffered() const;
|
int numArticlesOffered() const;
|
||||||
int numArticlesSold() const;
|
int numArticlesSold() const;
|
||||||
// int numArticlesTotal() const;
|
|
||||||
std::vector<Article*> getArticles(bool onlySold = true) const;
|
std::vector<Article*> getArticles(bool onlySold = true) const;
|
||||||
Article* getArticleByUuid(const std::string& uuidString);
|
Article* getArticleByUuid(const std::string& uuidString);
|
||||||
int getMaxArticleNo() const;
|
int getMaxArticleNo() const;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
std::string formatCentAsEuroString(const int cent, int width)
|
std::string formatCentAsEuroString(const int cent, int width)
|
||||||
{
|
{
|
||||||
|
@ -63,7 +63,8 @@ std::string& trim(std::string& str, const std::string& chars)
|
||||||
return ltrim(rtrim(str, chars), chars);
|
return ltrim(rtrim(str, chars), chars);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool case_insensitive_match(std::string s1, std::string s2) {
|
bool case_insensitive_match(std::string s1, std::string s2)
|
||||||
|
{
|
||||||
// convert s1 and s2 into lower case strings
|
// convert s1 and s2 into lower case strings
|
||||||
transform(s1.begin(), s1.end(), s1.begin(), ::tolower);
|
transform(s1.begin(), s1.end(), s1.begin(), ::tolower);
|
||||||
transform(s2.begin(), s2.end(), s2.begin(), ::tolower);
|
transform(s2.begin(), s2.end(), s2.begin(), ::tolower);
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#include "basketmodel.h"
|
#include "basketmodel.h"
|
||||||
|
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
#include <QSettings>
|
|
||||||
#include <QFontDatabase>
|
#include <QFontDatabase>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
BasketModel::BasketModel(Marketplace* market, QObject* parent)
|
BasketModel::BasketModel(Marketplace* market, QObject* parent)
|
||||||
: QAbstractTableModel(parent), marketplace_(market)
|
: QAbstractTableModel(parent), marketplace_(market)
|
||||||
|
|
|
@ -15,9 +15,6 @@ class BasketModel : public QAbstractTableModel
|
||||||
virtual int columnCount(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 data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
||||||
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) 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, int role = Qt::EditRole) override;
|
|
||||||
//virtual bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
|
|
||||||
void addArticle(Seller* seller, int price, const std::string& desc);
|
void addArticle(Seller* seller, int price, const std::string& desc);
|
||||||
void finishSale();
|
void finishSale();
|
||||||
void cancelSale();
|
void cancelSale();
|
||||||
|
|
|
@ -19,14 +19,6 @@ int main(int argc, char* argv[])
|
||||||
QCoreApplication::setOrganizationDomain("rustysoft.de");
|
QCoreApplication::setOrganizationDomain("rustysoft.de");
|
||||||
QCoreApplication::setApplicationName("kima2");
|
QCoreApplication::setApplicationName("kima2");
|
||||||
|
|
||||||
// Make sure that only one instance of the application runs
|
|
||||||
// Of course the uuid used here is unique to this application
|
|
||||||
// (commented out in favour of SingleApplication)
|
|
||||||
/*QSharedMemory shared("26297455-946a-4607-bfb7-5025a5f1e136");
|
|
||||||
if (!shared.create(512, QSharedMemory::ReadWrite)) {
|
|
||||||
exit(0);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
QTranslator qTranslator;
|
QTranslator qTranslator;
|
||||||
QLocale german(QLocale::German);
|
QLocale german(QLocale::German);
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
|
|
@ -33,7 +33,4 @@ void PriceDialog::accept()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PriceDialog::setForceDesc(bool force)
|
void PriceDialog::setForceDesc(bool force) { forceDesc_ = force; }
|
||||||
{
|
|
||||||
forceDesc_ = force;
|
|
||||||
}
|
|
|
@ -24,7 +24,8 @@ class ReportDialog : public QDialog
|
||||||
void onReportViewSelectionChanged(const QItemSelection& selected,
|
void onReportViewSelectionChanged(const QItemSelection& selected,
|
||||||
const QItemSelection& deselected);
|
const QItemSelection& deselected);
|
||||||
|
|
||||||
private : Ui::ReportDialog ui_;
|
private:
|
||||||
|
Ui::ReportDialog ui_;
|
||||||
Marketplace* market_;
|
Marketplace* market_;
|
||||||
std::unique_ptr<ReportModel> model_;
|
std::unique_ptr<ReportModel> model_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,9 +26,6 @@ QVariant SellerModel::data(const QModelIndex& index, int role) const
|
||||||
|
|
||||||
Seller* seller = marketplace_->getSellers().at(index.row()).get();
|
Seller* seller = marketplace_->getSellers().at(index.row()).get();
|
||||||
|
|
||||||
/* if (seller->getState() == Seller::State::DELETE)
|
|
||||||
return QVariant();
|
|
||||||
*/
|
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0:
|
case 0:
|
||||||
return seller->getId();
|
return seller->getId();
|
||||||
|
|
|
@ -16,7 +16,8 @@ class SellerModel : public QAbstractTableModel
|
||||||
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) 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 QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
||||||
virtual Qt::ItemFlags flags(const QModelIndex& index) const override;
|
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 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 insertRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
|
||||||
virtual bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
|
virtual bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,8 @@ class PosPrinter
|
||||||
void printHeader(const std::string& commune = "Musterhausen");
|
void printHeader(const std::string& commune = "Musterhausen");
|
||||||
void printTest();
|
void printTest();
|
||||||
void printSaleReceipt(Sale* sale, const std::string& commune = "Dettingen");
|
void printSaleReceipt(Sale* sale, const std::string& commune = "Dettingen");
|
||||||
void printSellerReceipt(Seller* seller, const int percent, const int maxFeeInCent, const std::string& commune = "Dettingen");
|
void printSellerReceipt(Seller* seller, const int percent, const int maxFeeInCent,
|
||||||
|
const std::string& commune = "Dettingen");
|
||||||
bool isValid();
|
bool isValid();
|
||||||
|
|
||||||
struct Command {
|
struct Command {
|
||||||
|
|
Loading…
Reference in a new issue