code cleanup

This commit is contained in:
Martin Brodbeck 2019-10-07 14:08:01 +02:00
parent 710b4cf9fb
commit 9fd29d588f
24 changed files with 60 additions and 101 deletions

View file

@ -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_; }

View file

@ -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

View file

@ -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);
@ -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);

View file

@ -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; }

View file

@ -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_; }

View file

@ -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

View file

@ -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);

View 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

View file

@ -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,7 +179,8 @@ 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),
<< escapeCsvValue(
paymentAsString(seller->sumInCents(), feeInPercent, maxFeeInEuro * 100),
delimiter)
<< "\n";
}

View file

@ -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"

View file

@ -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()) {

View file

@ -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;

View file

@ -1,8 +1,8 @@
#include "utils.h"
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <algorithm>
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);
}
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
transform(s1.begin(), s1.end(), s1.begin(), ::tolower);
transform(s2.begin(), s2.end(), s2.begin(), ::tolower);

View file

@ -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)

View file

@ -15,9 +15,6 @@ 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();

View file

@ -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__

View file

@ -33,7 +33,4 @@ void PriceDialog::accept()
}
}
void PriceDialog::setForceDesc(bool force)
{
forceDesc_ = force;
}
void PriceDialog::setForceDesc(bool force) { forceDesc_ = force; }

View file

@ -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_;
};

View file

@ -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();

View file

@ -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;

View file

@ -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 {