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 <sstream>
|
||||
|
||||
// Article::Article() : Entity() {}
|
||||
|
||||
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::setPrice(int price) { price_ = price; }
|
||||
|
@ -29,10 +25,7 @@ Sale* Article::getSale() { return salePtr_; }
|
|||
|
||||
int Article::getPrice() const { return price_; }
|
||||
|
||||
std::string Article::getPriceAsString() const
|
||||
{
|
||||
return formatCentAsEuroString(price_);
|
||||
}
|
||||
std::string Article::getPriceAsString() const { return formatCentAsEuroString(price_); }
|
||||
|
||||
int Article::getArticleNo() const { return articleNo_; }
|
||||
|
||||
|
|
|
@ -12,7 +12,8 @@
|
|||
class CsvReader
|
||||
{
|
||||
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
|
|
@ -136,10 +136,7 @@ void Database::updateDbToVer2()
|
|||
endTransaction();
|
||||
}
|
||||
|
||||
void Database::updateDbToVer3()
|
||||
{
|
||||
newDb();
|
||||
}
|
||||
void Database::updateDbToVer3() { newDb(); }
|
||||
|
||||
void Database::init()
|
||||
{
|
||||
|
@ -274,8 +271,7 @@ unsigned int Database::storeSellers(std::vector<std::unique_ptr<Seller>>& seller
|
|||
if (retCode != SQLITE_OK)
|
||||
throw std::runtime_error(sqlite3_errmsg(db_));
|
||||
|
||||
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":id"),
|
||||
seller->getId());
|
||||
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":id"), seller->getId());
|
||||
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":seller_no"),
|
||||
seller->getSellerNo());
|
||||
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) {
|
||||
count += static_cast<int>(seller->getArticles(false).size());
|
||||
|
||||
retCode =
|
||||
sqlite3_prepare_v2(db_, "DELETE FROM sellers WHERE seller_no = :id", -1, &stmt, nullptr);
|
||||
retCode = sqlite3_prepare_v2(db_, "DELETE FROM sellers WHERE seller_no = :id", -1,
|
||||
&stmt, nullptr);
|
||||
|
||||
if (retCode != SQLITE_OK)
|
||||
throw std::runtime_error(sqlite3_errmsg(db_));
|
||||
|
||||
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":id"),
|
||||
seller->getId());
|
||||
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":id"), seller->getId());
|
||||
|
||||
retCode = sqlite3_step(stmt);
|
||||
|
||||
|
@ -363,7 +358,7 @@ unsigned int Database::storeArticles(std::vector<Article*> articles)
|
|||
boost::uuids::to_string(article->getUuid()).c_str(), -1,
|
||||
SQLITE_TRANSIENT);
|
||||
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":seller_id"),
|
||||
article->getSeller()->getId());
|
||||
article->getSeller()->getId());
|
||||
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":source_no"),
|
||||
article->getSourceNo());
|
||||
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":article_no"),
|
||||
|
@ -399,7 +394,7 @@ unsigned int Database::storeArticles(std::vector<Article*> articles)
|
|||
boost::uuids::to_string(article->getUuid()).c_str(), -1,
|
||||
SQLITE_TRANSIENT);
|
||||
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":seller_id"),
|
||||
article->getSeller()->getId());
|
||||
article->getSeller()->getId());
|
||||
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":source_no"),
|
||||
article->getSourceNo());
|
||||
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":article_no"),
|
||||
|
@ -592,8 +587,7 @@ unsigned int Database::loadSellers(std::vector<std::unique_ptr<Seller>>& sellers
|
|||
if (retCode != SQLITE_OK)
|
||||
throw std::runtime_error(sqlite3_errmsg(db_));
|
||||
|
||||
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":seller_id"),
|
||||
seller->getId());
|
||||
sqlite3_bind_int(stmt, sqlite3_bind_parameter_index(stmt, ":seller_id"), seller->getId());
|
||||
|
||||
retCode = sqlite3_step(stmt);
|
||||
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
|
||||
class Entity
|
||||
{
|
||||
public:
|
||||
public:
|
||||
enum class State { NEW, UPDATE, DELETE, OK };
|
||||
virtual ~Entity() = default;
|
||||
void setState(State state) { state_ = state; }
|
||||
virtual State getState() const;
|
||||
|
||||
private:
|
||||
private:
|
||||
State state_{State::NEW};
|
||||
};
|
||||
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
#include "entityint.h"
|
||||
|
||||
EntityInt::EntityInt(int id) {
|
||||
id_ = id;
|
||||
}
|
||||
EntityInt::EntityInt(int id) { id_ = id; }
|
||||
|
||||
void EntityInt::setId(int id) {
|
||||
id_ = id;
|
||||
}
|
||||
void EntityInt::setId(int id) { id_ = id; }
|
||||
|
|
|
@ -17,11 +17,6 @@ void EntityUuid::setUuidFromString(const std::string& uuidString)
|
|||
uuid_ = generator(uuidString);
|
||||
}
|
||||
|
||||
void EntityUuid::setSourceNo(int sourceNo) { sourceNo_ = sourceNo; }
|
||||
|
||||
void EntityUuid::setSourceNo(int sourceNo) {
|
||||
sourceNo_ = sourceNo;
|
||||
}
|
||||
|
||||
int EntityUuid::getSourceNo() const {
|
||||
return sourceNo_;
|
||||
}
|
||||
int EntityUuid::getSourceNo() const { return sourceNo_; }
|
||||
|
|
|
@ -12,7 +12,8 @@
|
|||
class ExcelReader
|
||||
{
|
||||
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
|
|
@ -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
|
||||
}
|
||||
|
||||
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;
|
||||
std::ofstream file(filePath);
|
||||
|
@ -94,7 +95,8 @@ void JsonUtil::exportSales(const std::filesystem::path& filePath, Marketplace* m
|
|||
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);
|
||||
json jsonValues = json::parse(file);
|
||||
|
|
|
@ -3,16 +3,18 @@
|
|||
|
||||
#include "marketplace.h"
|
||||
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
class JsonUtil
|
||||
{
|
||||
public:
|
||||
static void exportSellers(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 importSales(const std::filesystem::path& filePath, Marketplace* market, int cashPointNo);
|
||||
static void exportSales(const std::filesystem::path& filePath, Marketplace* market,
|
||||
int cashPointNo);
|
||||
static void importSales(const std::filesystem::path& filePath, Marketplace* market,
|
||||
int cashPointNo);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -3,11 +3,11 @@
|
|||
#include "utils.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <numeric>
|
||||
#include <sstream>
|
||||
#include <filesystem>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
|
@ -104,20 +104,10 @@ Seller* Marketplace::findSellerWithSellerNo(int sellerNo)
|
|||
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)
|
||||
{
|
||||
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(); }
|
||||
|
@ -189,8 +179,9 @@ void Marketplace::exportReportToCSV(const fs::path& filePath, int feeInPercent,
|
|||
<< escapeCsvValue(seller->getFirstName(), delimiter) << delimiter
|
||||
<< seller->numArticlesOffered() << delimiter << seller->numArticlesSold() << delimiter
|
||||
<< escapeCsvValue(seller->sumAsString(), delimiter) << delimiter
|
||||
<< escapeCsvValue(paymentAsString(seller->sumInCents(), feeInPercent, maxFeeInEuro * 100),
|
||||
delimiter)
|
||||
<< escapeCsvValue(
|
||||
paymentAsString(seller->sumInCents(), feeInPercent, maxFeeInEuro * 100),
|
||||
delimiter)
|
||||
<< "\n";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#ifndef MARKETPLACE_H
|
||||
#define MARKETPLACE_H
|
||||
|
||||
#include "database.h"
|
||||
#include "article.h"
|
||||
#include "database.h"
|
||||
#include "sale.h"
|
||||
#include "seller.h"
|
||||
|
||||
|
|
|
@ -13,8 +13,6 @@ ArticlesVec& Sale::getArticles() { return articles_; }
|
|||
|
||||
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);
|
||||
|
||||
if (it != articles_.end()) {
|
||||
|
|
|
@ -32,7 +32,6 @@ class Seller : public EntityInt
|
|||
std::string getSellerNoAsString() const;
|
||||
int numArticlesOffered() const;
|
||||
int numArticlesSold() const;
|
||||
// int numArticlesTotal() const;
|
||||
std::vector<Article*> getArticles(bool onlySold = true) const;
|
||||
Article* getArticleByUuid(const std::string& uuidString);
|
||||
int getMaxArticleNo() const;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include "utils.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <numeric>
|
||||
#include <algorithm>
|
||||
|
||||
std::string formatCentAsEuroString(const int cent, int width)
|
||||
{
|
||||
|
@ -51,23 +51,24 @@ std::string& ltrim(std::string& str, const std::string& chars)
|
|||
str.erase(0, str.find_first_not_of(chars));
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
std::string& rtrim(std::string& str, const std::string& chars)
|
||||
{
|
||||
str.erase(str.find_last_not_of(chars) + 1);
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
std::string& trim(std::string& str, const std::string& chars)
|
||||
{
|
||||
return ltrim(rtrim(str, chars), chars);
|
||||
}
|
||||
|
||||
bool case_insensitive_match(std::string s1, std::string s2) {
|
||||
//convert s1 and s2 into lower case strings
|
||||
transform(s1.begin(), s1.end(), s1.begin(), ::tolower);
|
||||
transform(s2.begin(), s2.end(), s2.begin(), ::tolower);
|
||||
if(s1.compare(s2) == 0)
|
||||
return true; //The strings are same
|
||||
return false; //not matched
|
||||
bool case_insensitive_match(std::string s1, std::string s2)
|
||||
{
|
||||
// convert s1 and s2 into lower case strings
|
||||
transform(s1.begin(), s1.end(), s1.begin(), ::tolower);
|
||||
transform(s2.begin(), s2.end(), s2.begin(), ::tolower);
|
||||
if (s1.compare(s2) == 0)
|
||||
return true; // The strings are same
|
||||
return false; // not matched
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
#include "basketmodel.h"
|
||||
|
||||
#include <QFont>
|
||||
#include <QSettings>
|
||||
#include <QFontDatabase>
|
||||
#include <QSettings>
|
||||
|
||||
BasketModel::BasketModel(Marketplace* market, QObject* parent)
|
||||
: QAbstractTableModel(parent), marketplace_(market)
|
||||
|
@ -22,7 +22,7 @@ QVariant BasketModel::data(const QModelIndex& index, int role) const
|
|||
QFont myFont;
|
||||
|
||||
QFont myFixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont);
|
||||
if (myFixedFont.fixedPitch() == false) {
|
||||
if (myFixedFont.fixedPitch() == false) {
|
||||
myFixedFont.setFamily("monospace");
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
class BasketModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit BasketModel(Marketplace* market, QObject* parent = nullptr);
|
||||
|
@ -15,15 +15,12 @@ class BasketModel : public QAbstractTableModel
|
|||
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, 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 finishSale();
|
||||
void cancelSale();
|
||||
virtual bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
|
||||
|
||||
signals:
|
||||
signals:
|
||||
void basketDataChanged();
|
||||
|
||||
private:
|
||||
|
|
|
@ -19,14 +19,6 @@ int main(int argc, char* argv[])
|
|||
QCoreApplication::setOrganizationDomain("rustysoft.de");
|
||||
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;
|
||||
QLocale german(QLocale::German);
|
||||
#ifdef __linux__
|
||||
|
|
|
@ -29,7 +29,7 @@ class MainWindow : public QMainWindow
|
|||
void onCancelAllArticlesButtonClicked(bool checked);
|
||||
void onAboutQt();
|
||||
void onAbout();
|
||||
virtual bool eventFilter(QObject *target, QEvent *event) override;
|
||||
virtual bool eventFilter(QObject* target, QEvent* event) override;
|
||||
|
||||
protected:
|
||||
virtual void closeEvent(QCloseEvent* event) override;
|
||||
|
|
|
@ -33,7 +33,4 @@ void PriceDialog::accept()
|
|||
}
|
||||
}
|
||||
|
||||
void PriceDialog::setForceDesc(bool force)
|
||||
{
|
||||
forceDesc_ = force;
|
||||
}
|
||||
void PriceDialog::setForceDesc(bool force) { forceDesc_ = force; }
|
|
@ -24,7 +24,8 @@ class ReportDialog : public QDialog
|
|||
void onReportViewSelectionChanged(const QItemSelection& selected,
|
||||
const QItemSelection& deselected);
|
||||
|
||||
private : Ui::ReportDialog ui_;
|
||||
private:
|
||||
Ui::ReportDialog ui_;
|
||||
Marketplace* market_;
|
||||
std::unique_ptr<ReportModel> model_;
|
||||
};
|
||||
|
|
|
@ -12,7 +12,7 @@ class SaleModel : public QAbstractItemModel
|
|||
public:
|
||||
explicit SaleModel(Marketplace* market, QObject* parent = nullptr);
|
||||
virtual QModelIndex index(int row, int column,
|
||||
const QModelIndex& parent = QModelIndex()) const override;
|
||||
const QModelIndex& parent = QModelIndex()) const override;
|
||||
virtual QModelIndex parent(const QModelIndex& index) const override;
|
||||
virtual QVariant data(const QModelIndex& index, int role) const override;
|
||||
virtual int rowCount(const QModelIndex& parent) const override;
|
||||
|
|
|
@ -26,9 +26,6 @@ QVariant SellerModel::data(const QModelIndex& index, int role) const
|
|||
|
||||
Seller* seller = marketplace_->getSellers().at(index.row()).get();
|
||||
|
||||
/* if (seller->getState() == Seller::State::DELETE)
|
||||
return QVariant();
|
||||
*/
|
||||
switch (index.column()) {
|
||||
case 0:
|
||||
return seller->getId();
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
class SellerModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SellerModel(Marketplace* market, QObject* parent = nullptr);
|
||||
|
@ -16,7 +16,8 @@ class SellerModel : public QAbstractTableModel
|
|||
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, 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 removeRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
|
||||
|
||||
|
|
|
@ -36,7 +36,8 @@ class PosPrinter
|
|||
void printHeader(const std::string& commune = "Musterhausen");
|
||||
void printTest();
|
||||
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();
|
||||
|
||||
struct Command {
|
||||
|
|
Loading…
Reference in a new issue