diff --git a/src/core/article.cpp b/src/core/article.cpp index 0715d93..3de88de 100644 --- a/src/core/article.cpp +++ b/src/core/article.cpp @@ -4,12 +4,8 @@ #include #include -// Article::Article() : Entity() {} - Article::Article(int price) : price_(price) {} -// Article::Article(std::shared_ptr 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_; } diff --git a/src/core/csvreader.h b/src/core/csvreader.h index 4c88551..1f9d924 100644 --- a/src/core/csvreader.h +++ b/src/core/csvreader.h @@ -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 \ No newline at end of file diff --git a/src/core/database.cpp b/src/core/database.cpp index f95deae..9d0df7d 100644 --- a/src/core/database.cpp +++ b/src/core/database.cpp @@ -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>& 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>& seller } else if (seller->getState() == Seller::State::DELETE) { count += static_cast(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 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 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>& 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); diff --git a/src/core/entity.h b/src/core/entity.h index ca48f47..a0eb97c 100644 --- a/src/core/entity.h +++ b/src/core/entity.h @@ -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}; }; diff --git a/src/core/entityint.cpp b/src/core/entityint.cpp index 835c5ff..28e210e 100644 --- a/src/core/entityint.cpp +++ b/src/core/entityint.cpp @@ -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; } diff --git a/src/core/entityuuid.cpp b/src/core/entityuuid.cpp index 07eaf8d..570c624 100644 --- a/src/core/entityuuid.cpp +++ b/src/core/entityuuid.cpp @@ -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_; } diff --git a/src/core/excelreader.h b/src/core/excelreader.h index b9d0e1c..62f06c4 100644 --- a/src/core/excelreader.h +++ b/src/core/excelreader.h @@ -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 \ No newline at end of file diff --git a/src/core/jsonutil.cpp b/src/core/jsonutil.cpp index dc7e4dc..9a20603 100644 --- a/src/core/jsonutil.cpp +++ b/src/core/jsonutil.cpp @@ -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); diff --git a/src/core/jsonutil.h b/src/core/jsonutil.h index 4d06ace..2cc33a2 100644 --- a/src/core/jsonutil.h +++ b/src/core/jsonutil.h @@ -3,16 +3,18 @@ #include "marketplace.h" -#include #include +#include 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 \ No newline at end of file diff --git a/src/core/marketplace.cpp b/src/core/marketplace.cpp index c9f4b7a..3fe234a 100644 --- a/src/core/marketplace.cpp +++ b/src/core/marketplace.cpp @@ -3,11 +3,11 @@ #include "utils.h" #include +#include #include #include #include #include -#include 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) { - 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"; } } diff --git a/src/core/marketplace.h b/src/core/marketplace.h index 47e25bd..fe45e02 100644 --- a/src/core/marketplace.h +++ b/src/core/marketplace.h @@ -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" diff --git a/src/core/sale.cpp b/src/core/sale.cpp index ae3f143..1fce577 100644 --- a/src/core/sale.cpp +++ b/src/core/sale.cpp @@ -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()) { diff --git a/src/core/seller.h b/src/core/seller.h index 0c6dd38..e3dda18 100644 --- a/src/core/seller.h +++ b/src/core/seller.h @@ -32,7 +32,6 @@ class Seller : public EntityInt std::string getSellerNoAsString() const; int numArticlesOffered() const; int numArticlesSold() const; - // int numArticlesTotal() const; std::vector getArticles(bool onlySold = true) const; Article* getArticleByUuid(const std::string& uuidString); int getMaxArticleNo() const; diff --git a/src/core/utils.cpp b/src/core/utils.cpp index 498e34f..10b1b5f 100644 --- a/src/core/utils.cpp +++ b/src/core/utils.cpp @@ -1,8 +1,8 @@ #include "utils.h" +#include #include #include -#include 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 } \ No newline at end of file diff --git a/src/gui/basketmodel.cpp b/src/gui/basketmodel.cpp index 2ac1931..d693782 100644 --- a/src/gui/basketmodel.cpp +++ b/src/gui/basketmodel.cpp @@ -1,8 +1,8 @@ #include "basketmodel.h" #include -#include #include +#include 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"); } diff --git a/src/gui/basketmodel.h b/src/gui/basketmodel.h index 2a9b7fc..5cc6be6 100644 --- a/src/gui/basketmodel.h +++ b/src/gui/basketmodel.h @@ -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: diff --git a/src/gui/kima2.cpp b/src/gui/kima2.cpp index 1b6ad96..5ff27fb 100644 --- a/src/gui/kima2.cpp +++ b/src/gui/kima2.cpp @@ -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__ diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 755faa0..578886b 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -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; diff --git a/src/gui/pricedialog.cpp b/src/gui/pricedialog.cpp index f28f190..93a7223 100644 --- a/src/gui/pricedialog.cpp +++ b/src/gui/pricedialog.cpp @@ -33,7 +33,4 @@ void PriceDialog::accept() } } -void PriceDialog::setForceDesc(bool force) -{ - forceDesc_ = force; -} \ No newline at end of file +void PriceDialog::setForceDesc(bool force) { forceDesc_ = force; } \ No newline at end of file diff --git a/src/gui/reportdialog.h b/src/gui/reportdialog.h index 64edc5c..14e298a 100644 --- a/src/gui/reportdialog.h +++ b/src/gui/reportdialog.h @@ -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 model_; }; diff --git a/src/gui/salemodel.h b/src/gui/salemodel.h index 91190e9..dc2623d 100644 --- a/src/gui/salemodel.h +++ b/src/gui/salemodel.h @@ -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; diff --git a/src/gui/sellermodel.cpp b/src/gui/sellermodel.cpp index 9b9e660..63b939e 100644 --- a/src/gui/sellermodel.cpp +++ b/src/gui/sellermodel.cpp @@ -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(); diff --git a/src/gui/sellermodel.h b/src/gui/sellermodel.h index 5449bfb..0952bb4 100644 --- a/src/gui/sellermodel.h +++ b/src/gui/sellermodel.h @@ -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; diff --git a/src/printer/posprinter.h b/src/printer/posprinter.h index 8ede494..fd92314 100644 --- a/src/printer/posprinter.h +++ b/src/printer/posprinter.h @@ -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 {