diff options
author | rtk0c <[email protected]> | 2021-04-28 15:18:51 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2021-04-28 15:18:51 -0700 |
commit | 00fd95526677d670d002ca81069636f0f74b91f7 (patch) | |
tree | a783f05be218a58c2b78175425f7576664c3f1a9 /core/src/UI/UI_DatabaseView.cpp | |
parent | b7d5b514e7bffd3149a99bc7f1424f8251876d85 (diff) |
Code cleanup, fix database view paging and selection
Diffstat (limited to 'core/src/UI/UI_DatabaseView.cpp')
-rw-r--r-- | core/src/UI/UI_DatabaseView.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/core/src/UI/UI_DatabaseView.cpp b/core/src/UI/UI_DatabaseView.cpp index 884ab51..4009e5b 100644 --- a/core/src/UI/UI_DatabaseView.cpp +++ b/core/src/UI/UI_DatabaseView.cpp @@ -56,6 +56,8 @@ private: /// index by offsetting by \c mFirstCachedRowId. std::vector<int> mActiveEntries; + /// Number of rows in the table. + int mRowCount; /// Last possible page for the current set table and filter (inclusive). int mLastPage; /// The current page the user is on. @@ -71,6 +73,13 @@ public: void OnProjectChanged(Project* newProject) { mProject = newProject; + auto& stmt = newProject->GetTransactionsModel().GetSales().GetRowCountStatement; + if (stmt.executeStep()) { + mRowCount = stmt.getColumn(0).getInt(); + } else { + // TODO report error + } + mFirstCachedRowId = 0; mLastCachedRowId = 0; @@ -116,6 +125,7 @@ public: auto ls = LocaleStrings::Instance.get(); if (ImGui::Button(ICON_FA_ARROW_LEFT, mCurrentPage == 0)) { + mSelectedEntryRowId = -1; SetPage(mCurrentPage - 1); } @@ -125,6 +135,7 @@ public: ImGui::SameLine(); if (ImGui::Button(ICON_FA_ARROW_RIGHT, mCurrentPage == mLastPage)) { + mSelectedEntryRowId = -1; SetPage(mCurrentPage + 1); } @@ -165,6 +176,9 @@ public: void DrawEntry(const SaleEntry& entry, int rowId) { auto ls = LocaleStrings::Instance.get(); + ImGui::PushID(rowId); + ImGui::TableNextRow(); + ImGui::TableNextColumn(); if (ImGui::Selectable(entry.Customer.c_str(), mSelectedEntryRowId == rowId, ImGuiSelectableFlags_SpanAllColumns)) { mSelectedEntryRowId = rowId; @@ -179,6 +193,8 @@ public: } else { ImGui::Text("%s", entry.DeliveryTime.c_str()); } + + ImGui::PopID(); } const SaleEntry& GetEntry(int64_t rowId) const { @@ -197,7 +213,7 @@ private: void UpdateLastPage() { mLastPage = mActiveEntries.empty() - ? 0 // TODO calc page + ? CalcPageForRowId(mRowCount) : CalcPageForRowId(mActiveEntries.back()); } @@ -267,7 +283,10 @@ private: auto t = chrono::system_clock::to_time_t(tp); char data[32]; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" // C++ doesn't have std::localtime_s std::strftime(data, sizeof(data), "%Y-%m-%d %H:%M:%S", std::localtime(&t)); +#pragma clang diagnostic pop return std::string(data); }; @@ -351,7 +370,6 @@ void UI::DatabaseViewTab() { purchasesView.Draw(); ImGui::EndTabItem(); } - ImGui::EndTabBar(); } } |