diff options
author | rtk0c <[email protected]> | 2022-11-27 12:04:31 -0800 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-11-27 12:04:31 -0800 |
commit | 182c8f8357739f905bbd721006480502435b6b43 (patch) | |
tree | 082613a474d863182e2ad8f2167f1643f26e67a3 /app/source/Cplt/UI/UI_DatabaseView.cpp | |
parent | b01ed99a1cd0c863c8709930658513c04dd70f61 (diff) |
Update brace style to match rest of my projectscplt-imgui
Diffstat (limited to 'app/source/Cplt/UI/UI_DatabaseView.cpp')
-rw-r--r-- | app/source/Cplt/UI/UI_DatabaseView.cpp | 130 |
1 files changed, 41 insertions, 89 deletions
diff --git a/app/source/Cplt/UI/UI_DatabaseView.cpp b/app/source/Cplt/UI/UI_DatabaseView.cpp index 1e58eb0..091e80d 100644 --- a/app/source/Cplt/UI/UI_DatabaseView.cpp +++ b/app/source/Cplt/UI/UI_DatabaseView.cpp @@ -23,35 +23,30 @@ constexpr int kMaxEntriesPerPage = 32; constexpr int kSummaryItemCount = 3; constexpr int kSummaryMaxLength = 25; -std::pair<int, int> SplitEntryIndex(int entryIdx) -{ +std::pair<int, int> SplitEntryIndex(int entryIdx) { int page = entryIdx / kMaxEntriesPerPage; int row = entryIdx % kMaxEntriesPerPage; return { page, row }; } -enum class DeliveryDirection -{ +enum class DeliveryDirection { FactoryToWarehouse, WarehouseToCustomer, }; -struct Item -{ +struct Item { int ItemId; int Count; }; -struct DeliveryEntry -{ +struct DeliveryEntry { std::vector<Item> Items; std::string ItemsSummary; std::string ShipmentTime; std::string ArriveTime; DeliveryDirection Direction; - const char* StringifyDirection() const - { + const char* StringifyDirection() const { switch (Direction) { case DeliveryDirection::FactoryToWarehouse: return "Factory to warehouse"; case DeliveryDirection::WarehouseToCustomer: return "Warehouse to customer"; @@ -59,8 +54,7 @@ struct DeliveryEntry } }; -struct SaleEntry -{ +struct SaleEntry { static constexpr auto kType = DeliveryDirection::WarehouseToCustomer; std::vector<DeliveryEntry> AssociatedDeliveries; @@ -73,8 +67,7 @@ struct SaleEntry bool DeliveriesCached = false; }; -struct PurchaseEntry -{ +struct PurchaseEntry { static constexpr auto kType = DeliveryDirection::FactoryToWarehouse; std::vector<DeliveryEntry> AssociatedDeliveries; @@ -88,27 +81,22 @@ struct PurchaseEntry }; template <class T> -class GenericTableView -{ +class GenericTableView { public: - // clang-format off - static constexpr bool kHasItems = requires(T t) - { - t.Items; - t.ItemsSummary; - }; + static constexpr bool kHasItems = requires(T t) { + t.Items; + t.ItemsSummary; + }; static constexpr bool kHasCustomer = requires(T t) { t.Customer; }; static constexpr bool kHasDeadline = requires(T t) { t.Deadline; }; static constexpr bool kHasFactory = requires(T t) { t.Factory; }; static constexpr bool kHasOrderTime = requires(T t) { t.OrderTime; }; static constexpr bool kHasCompletionTime = requires(T t) { t.DeliveryTime; }; static constexpr int kColumnCount = kHasItems + kHasCustomer + kHasDeadline + kHasFactory + kHasOrderTime + kHasCompletionTime; - // clang-format on using Page = std::vector<T>; - struct QueryStatements - { + struct QueryStatements { SQLite::Statement* GetRowCount; SQLite::Statement* GetRows; SQLite::Statement* GetItems; @@ -143,18 +131,15 @@ protected: public: /// Calculate the first visible row's entry index. - int GetFirstVisibleRowIdx() const - { + int GetFirstVisibleRowIdx() const { return mCurrentPageNumber * kMaxEntriesPerPage; } - Project* GetProject() const - { + Project* GetProject() const { return mProject; } - void OnProjectChanged(Project* newProject) - { + void OnProjectChanged(Project* newProject) { mProject = newProject; auto& stmt = *Statements.GetRowCount; @@ -176,17 +161,13 @@ public: mSelectRow = -1; } - TableRowsFilter* GetFilter() const - { + TableRowsFilter* GetFilter() const { return mActiveFilter.get(); } - void OnFilterChanged() - { + void OnFilterChanged() { auto& stmt = *Statements.FilterRows; - // clang-format off DEFER { stmt.reset(); }; - // clang-format on // TODO lazy loading when too many results mActiveEntries.clear(); @@ -201,14 +182,12 @@ public: mSelectRow = -1; } - void OnFilterChanged(std::unique_ptr<TableRowsFilter> filter) - { + void OnFilterChanged(std::unique_ptr<TableRowsFilter> filter) { mActiveFilter = std::move(filter); OnFilterChanged(); } - void Display() - { + void Display() { bool dummy = true; if (ImGui::Button(ICON_FA_ARROW_LEFT, mCurrentPageNumber == 0)) { @@ -260,29 +239,25 @@ public: ImGui::Columns(1); } - void SetPage(int page) - { + void SetPage(int page) { mCurrentPageNumber = page; mCurrentPage = &LoadAndGetPage(page); mSelectRow = -1; } private: - static int CalcPageForRowId(int64_t entryIdx) - { + static int CalcPageForRowId(int64_t entryIdx) { return entryIdx / kMaxEntriesPerPage; } /// Calculate range [begin, end) of index for the list of entries that are currently visible that the path-th page would show. /// i.e. when there is a filter, look into \c mActiveEntryIndices; when there is no filter, use directly. - static std::pair<int64_t, int64_t> CalcRangeForPage(int page) - { + static std::pair<int64_t, int64_t> CalcRangeForPage(int page) { int begin = page * kMaxEntriesPerPage; return { begin, begin + kMaxEntriesPerPage }; } - void DisplayMainTable() - { + void DisplayMainTable() { if (ImGui::BeginTable("DataTable", kColumnCount, ImGuiTableFlags_Borders | ImGuiTableFlags_ScrollX)) { if constexpr (kHasCustomer) ImGui::TableSetupColumn(I18N_TEXT("Customer", L10N_DATABASE_COLUMN_CUSTOMER)); @@ -315,16 +290,14 @@ private: } } - void DisplayEntry(int rowIdx) - { + void DisplayEntry(int rowIdx) { // TODO // auto [pageNumber, pageEntry] = SplitRowIndex(rowIdx); // auto& entry = LoadAndGetPage(pageNumber)[pageEntry]; // DisplayEntry(entry, rowIdx); } - void DisplayEntry(T& entry, int rowIdx, int entryIdx) - { + void DisplayEntry(T& entry, int rowIdx, int entryIdx) { ImGui::PushID(rowIdx); ImGui::TableNextRow(); @@ -372,13 +345,11 @@ private: ImGui::PopID(); } - void EditEntry(T& entry, int rowIdx, int entryIdx) - { + void EditEntry(T& entry, int rowIdx, int entryIdx) { // TODO } - void DisplayDeliveriesTable() - { + void DisplayDeliveriesTable() { if (ImGui::BeginTable("DeliveriesTable", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_ScrollX)) { ImGui::TableSetupColumn(I18N_TEXT("Shipment time", L10N_DATABASE_COLUMN_SHIPMENT_TIME)); @@ -408,11 +379,8 @@ private: } } - std::vector<Item> LoadItems(SQLite::Statement& stmt, int64_t id) - { - // clang-format off + std::vector<Item> LoadItems(SQLite::Statement& stmt, int64_t id) { DEFER { stmt.reset(); }; - // clang-format on stmt.bind(1, id); @@ -429,8 +397,7 @@ private: return entries; } - std::string CreateItemsSummary(const std::vector<Item>& items) - { + std::string CreateItemsSummary(const std::vector<Item>& items) { if (items.empty()) { return "<empty>"; } @@ -455,8 +422,7 @@ private: return result; } - std::vector<DeliveryEntry> LoadDeliveriesEntries(int64_t orderId, DeliveryDirection type) - { + std::vector<DeliveryEntry> LoadDeliveriesEntries(int64_t orderId, DeliveryDirection type) { bool outgoingFlag; switch (type) { case DeliveryDirection::FactoryToWarehouse: outgoingFlag = false; break; @@ -464,9 +430,7 @@ private: } auto& stmt = mProject->Database.GetDeliveries().FilterByTypeAndId; - // clang-format off DEFER { stmt.reset(); }; - // clang-format on stmt.bind(1, orderId); stmt.bind(2, outgoingFlag); @@ -493,17 +457,14 @@ private: return entries; } - Page& LoadAndGetPage(int page) - { + Page& LoadAndGetPage(int page) { auto iter = mPages.find(page); if (iter != mPages.end()) { return iter.value(); } auto& stmt = *Statements.GetRows; - // clang-format off DEFER { stmt.reset(); }; - // clang-format on stmt.bind(1, kMaxEntriesPerPage); stmt.bind(2, page * kMaxEntriesPerPage); @@ -575,34 +536,29 @@ private: return res.value(); } - void DrawItems(const std::vector<Item>& items) - { + void DrawItems(const std::vector<Item>& items) { for (auto& item : items) { auto& name = mProject->Products.Find(item.ItemId)->GetName(); ImGui::Text("%s × %d", name.c_str(), item.Count); } } - void UpdateLastPage() - { + void UpdateLastPage() { mLastPage = mActiveEntries.empty() ? CalcPageForRowId(mRowCount) : CalcPageForRowId(mActiveEntries.back()); } }; -class SalesTableView : public GenericTableView<SaleEntry> -{ +class SalesTableView : public GenericTableView<SaleEntry> { public: - SalesTableView() - { + SalesTableView() { mEditDialogTitle = I18N_TEXT("Edit sales entry", L10N_DATABASE_SALES_VIEW_EDIT_DIALOG_TITLE); } #pragma clang diagnostic push #pragma ide diagnostic ignored "HidingNonVirtualFunction" - void OnProjectChanged(Project* newProject) - { + void OnProjectChanged(Project* newProject) { auto& table = newProject->Database.GetSales(); Statements.GetRowCount = &table.GetRowCount; Statements.GetRows = &table.GetRows; @@ -615,18 +571,15 @@ public: #pragma clang diagnostic pop }; -class PurchasesTableView : public GenericTableView<PurchaseEntry> -{ +class PurchasesTableView : public GenericTableView<PurchaseEntry> { public: - PurchasesTableView() - { + PurchasesTableView() { mEditDialogTitle = I18N_TEXT("Edit purchase entry", L10N_DATABASE_PURCHASES_VIEW_EDIT_DIALOG_TITLE); } #pragma clang diagnostic push #pragma ide diagnostic ignored "HidingNonVirtualFunction" - void OnProjectChanged(Project* newProject) - { + void OnProjectChanged(Project* newProject) { auto& table = newProject->Database.GetPurchases(); Statements.GetRowCount = &table.GetRowCount; Statements.GetRows = &table.GetRows; @@ -640,8 +593,7 @@ public: }; } // namespace CPLT_UNITY_ID -void UI::DatabaseViewTab() -{ +void UI::DatabaseViewTab() { auto& gs = GlobalStates::GetInstance(); static Project* currentProject = nullptr; |