diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 504d0c3..8add251 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -29,11 +29,11 @@ set(CORE_SOURCES add_library(core STATIC ${CORE_SOURCES}) target_include_directories(core PRIVATE ${PROJECT_SOURCE_DIR}/3rdparty/csv-parser/include) if (WIN32) - target_link_libraries(core PRIVATE printer Boost::boost Boost::date_time sqlite3 nlohmann_json::nlohmann_json ${XLNT_LIBRARY} csv) + target_link_libraries(core PRIVATE Boost::boost Boost::date_time sqlite3 nlohmann_json::nlohmann_json ${XLNT_LIBRARY} csv) target_link_libraries(core PRIVATE bcrypt) else() - target_link_libraries(core PRIVATE printer Boost::boost Boost::date_time sqlite3 nlohmann_json::nlohmann_json ${XLNT_LIBRARIES} csv) + target_link_libraries(core PRIVATE Boost::boost Boost::date_time sqlite3 nlohmann_json::nlohmann_json ${XLNT_LIBRARIES} csv) endif() #target_include_directories(core PRIVATE ${PROJECT_SOURCE_DIR}/3rdparty/csv-parser) -target_include_directories(core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_include_directories(core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/..) diff --git a/src/core/utils.cpp b/src/core/utils.cpp index 10b1b5f..83c7a3a 100644 --- a/src/core/utils.cpp +++ b/src/core/utils.cpp @@ -21,31 +21,6 @@ std::string formatCentAsEuroString(const int cent, int width) return currStream.str(); } -std::optional convertToPosPrinterDevice(const std::string& device, - const std::string& endpoint) -{ - if (device.empty()) { - return std::nullopt; - } - - PrinterDevice printerDevice; - std::string delimiter = ":"; - try { - printerDevice.idVendor = std::stoi(device.substr(0, device.find(delimiter)), 0, 16); - printerDevice.idProduct = std::stoi(device.substr(device.find(delimiter) + 1), 0, 16); - if (endpoint.empty()) { - printerDevice.endpoint = 0x03; - } else { - printerDevice.endpoint = std::stoi(endpoint, 0, 16); - } - - } catch (std::exception& ex) { - throw ex; - } - - return printerDevice; -} - std::string& ltrim(std::string& str, const std::string& chars) { str.erase(0, str.find_first_not_of(chars)); @@ -71,4 +46,4 @@ bool case_insensitive_match(std::string s1, std::string s2) 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/core/utils.h b/src/core/utils.h index 7ea6499..9ca2d32 100644 --- a/src/core/utils.h +++ b/src/core/utils.h @@ -1,15 +1,11 @@ -#ifndef UTILS_H -#define UTILS_H - -#include "posprinter.h" +#ifndef CORE_UTILS_H +#define CORE_UTILS_H #include #include #include std::string formatCentAsEuroString(const int cent, int width = 10); -std::optional convertToPosPrinterDevice(const std::string& vendor, - const std::string& endpoint); std::string& ltrim(std::string& str, const std::string& chars = "\t\n\v\f\r "); std::string& rtrim(std::string& str, const std::string& chars = "\t\n\v\f\r "); std::string& trim(std::string& str, const std::string& chars = "\t\n\v\f\r "); diff --git a/src/gui/basketmodel.h b/src/gui/basketmodel.h index 5cc6be6..7c1858c 100644 --- a/src/gui/basketmodel.h +++ b/src/gui/basketmodel.h @@ -1,7 +1,7 @@ #ifndef BASKET_MODEL_H #define BASKET_MODEL_H -#include +#include #include @@ -27,4 +27,4 @@ class BasketModel : public QAbstractTableModel Marketplace* marketplace_; }; -#endif \ No newline at end of file +#endif diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 0df9658..32d8813 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -2,18 +2,18 @@ #include "basketmodel.h" #include "config.h" -#include "jsonutil.h" #include "pricedialog.h" #include "reportdialog.h" #include "salemodel.h" #include "sellerdialog.h" #include "settingsdialog.h" -#include - -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 578886b..12f9689 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -3,7 +3,7 @@ #include "ui_mainwindow.h" -#include +#include #include #include @@ -53,4 +53,4 @@ class MainWindow : public QMainWindow std::unique_ptr marketplace_; }; -#endif \ No newline at end of file +#endif diff --git a/src/gui/reportdialog.cpp b/src/gui/reportdialog.cpp index 9cb7393..84971ec 100644 --- a/src/gui/reportdialog.cpp +++ b/src/gui/reportdialog.cpp @@ -2,8 +2,9 @@ #include "mainwindow.h" -#include -#include +#include +#include +#include #include diff --git a/src/gui/reportdialog.h b/src/gui/reportdialog.h index 14e298a..18e1802 100644 --- a/src/gui/reportdialog.h +++ b/src/gui/reportdialog.h @@ -5,7 +5,7 @@ #include "reportmodel.h" -#include +#include #include @@ -30,4 +30,4 @@ class ReportDialog : public QDialog std::unique_ptr model_; }; -#endif \ No newline at end of file +#endif diff --git a/src/gui/reportmodel.h b/src/gui/reportmodel.h index 6509d2f..36855da 100644 --- a/src/gui/reportmodel.h +++ b/src/gui/reportmodel.h @@ -1,7 +1,7 @@ #ifndef REPORT_MODEL_H #define REPORT_MODEL_H -#include +#include #include @@ -20,4 +20,4 @@ class ReportModel : public QAbstractTableModel int maxFeeInCent_{}; }; -#endif \ No newline at end of file +#endif diff --git a/src/gui/salemodel.cpp b/src/gui/salemodel.cpp index 3549003..93289e1 100644 --- a/src/gui/salemodel.cpp +++ b/src/gui/salemodel.cpp @@ -1,6 +1,6 @@ #include "salemodel.h" -#include +#include #include diff --git a/src/gui/salemodel.h b/src/gui/salemodel.h index dc2623d..6675bd6 100644 --- a/src/gui/salemodel.h +++ b/src/gui/salemodel.h @@ -1,7 +1,7 @@ #ifndef SALEMODEL_H #define SALEMODEL_H -#include +#include #include @@ -28,4 +28,4 @@ class SaleModel : public QAbstractItemModel std::unique_ptr rootItem{new Sale()}; }; -#endif \ No newline at end of file +#endif diff --git a/src/gui/sellermodel.h b/src/gui/sellermodel.h index 0952bb4..32b6b7d 100644 --- a/src/gui/sellermodel.h +++ b/src/gui/sellermodel.h @@ -1,7 +1,7 @@ #ifndef SELLER_MODEL_H #define SELLER_MODEL_H -#include +#include #include @@ -28,4 +28,4 @@ class SellerModel : public QAbstractTableModel Marketplace* marketplace_; }; -#endif \ No newline at end of file +#endif diff --git a/src/gui/settingsdialog.cpp b/src/gui/settingsdialog.cpp index ac3a7a4..57bcc81 100644 --- a/src/gui/settingsdialog.cpp +++ b/src/gui/settingsdialog.cpp @@ -2,9 +2,10 @@ #include "mainwindow.h" -#include -#include -#include +#include +#include +#include +#include #include #include @@ -116,4 +117,4 @@ void SettingsDialog::accept() } QDialog::accept(); -} \ No newline at end of file +} diff --git a/src/gui/settingsdialog.h b/src/gui/settingsdialog.h index 39e3086..da03ddc 100644 --- a/src/gui/settingsdialog.h +++ b/src/gui/settingsdialog.h @@ -3,7 +3,7 @@ #include "ui_settingsdialog.h" -#include +#include #include @@ -21,4 +21,4 @@ class SettingsDialog : public QDialog Marketplace* market_{}; }; -#endif \ No newline at end of file +#endif diff --git a/src/printer/CMakeLists.txt b/src/printer/CMakeLists.txt index 84c58a6..9dfaa3e 100644 --- a/src/printer/CMakeLists.txt +++ b/src/printer/CMakeLists.txt @@ -11,6 +11,7 @@ endif() set(PRINTER_SOURCES posprinter.cpp + utils.cpp ) add_library(printer STATIC ${PRINTER_SOURCES}) @@ -19,4 +20,4 @@ if(WIN32) else() target_link_libraries(printer core ${LibUSB_LIBRARIES}) endif() -target_include_directories(printer PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_include_directories(printer PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/..) diff --git a/src/printer/posprinter.cpp b/src/printer/posprinter.cpp index 43a900f..368d483 100644 --- a/src/printer/posprinter.cpp +++ b/src/printer/posprinter.cpp @@ -1,6 +1,6 @@ #include "posprinter.h" -#include +#include #include @@ -213,4 +213,4 @@ bool PosPrinter::isValid() return true; else return false; -} \ No newline at end of file +} diff --git a/src/printer/posprinter.h b/src/printer/posprinter.h index fd92314..4ddd083 100644 --- a/src/printer/posprinter.h +++ b/src/printer/posprinter.h @@ -1,8 +1,8 @@ #ifndef POS_PRINTER_H #define POS_PRINTER_H -#include -#include +#include +#include #include diff --git a/src/printer/utils.cpp b/src/printer/utils.cpp new file mode 100644 index 0000000..10cb4ed --- /dev/null +++ b/src/printer/utils.cpp @@ -0,0 +1,26 @@ +#include "utils.h" + +std::optional convertToPosPrinterDevice(const std::string& device, + const std::string& endpoint) +{ + if (device.empty()) { + return std::nullopt; + } + + PrinterDevice printerDevice; + std::string delimiter = ":"; + try { + printerDevice.idVendor = std::stoi(device.substr(0, device.find(delimiter)), 0, 16); + printerDevice.idProduct = std::stoi(device.substr(device.find(delimiter) + 1), 0, 16); + if (endpoint.empty()) { + printerDevice.endpoint = 0x03; + } else { + printerDevice.endpoint = std::stoi(endpoint, 0, 16); + } + + } catch (std::exception& ex) { + throw ex; + } + + return printerDevice; +} diff --git a/src/printer/utils.h b/src/printer/utils.h new file mode 100644 index 0000000..4429ae9 --- /dev/null +++ b/src/printer/utils.h @@ -0,0 +1,12 @@ +#ifndef PRINTER_UTILS_H +#define PRINTER_UTILS_H + +#include "posprinter.h" + +#include +#include + +std::optional convertToPosPrinterDevice(const std::string& vendor, + const std::string& endpoint); + +#endif