Skip to content

Commit

Permalink
[FIX] : fix the ADataTable for support row selections and context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
aiekick committed Jun 19, 2024
1 parent aa06d8f commit 05e4f8f
Show file tree
Hide file tree
Showing 14 changed files with 356 additions and 72 deletions.
34 changes: 25 additions & 9 deletions src/Frontend/Tables/CategoriesTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,30 @@ bool CategoriesTable::drawMenu() {
return false;
}

double CategoriesTable::m_getAmount(const size_t& vIdx) {
size_t CategoriesTable::m_getItemsCount() const {
return m_Categories.size();
}

RowID CategoriesTable::m_getItemRowID(const size_t& vIdx) const {
if (vIdx < m_Categories.size()) {
return m_Categories.at(vIdx).id;
}
return 0; // the db row id cant be 0
}

double CategoriesTable::m_getItemAmount(const size_t& vIdx) const {
return m_Categories.at(vIdx).amount;
}

void CategoriesTable::m_drawContent(const size_t& vIdx, const double& vMaxAmount) {
void CategoriesTable::m_drawTableContent(const size_t& vIdx, const double& vMaxAmount) {
const auto& e = m_Categories.at(vIdx);
ImGui::TableNextColumn();
ImGui::Text("%s", e.name.c_str());
m_drawColumnSelectable(vIdx, e.id, e.name);
m_drawColumnDebit(e.debit);
m_drawColumnCredit(e.credit);
m_drawColumnAmount(e.amount);
m_drawColumnBars(e.amount, vMaxAmount);
}

size_t CategoriesTable::m_getItemsCount() {
return m_Categories.size();
}

void CategoriesTable::m_setupColumns() {
ImGui::TableSetupScrollFreeze(0, 1);
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed);
Expand All @@ -53,16 +59,26 @@ void CategoriesTable::m_setupColumns() {
ImGui::TableHeadersRow();
}

void CategoriesTable::m_drawContextMenuContent() {
CTOOL_DEBUG_BREAK;
}

void CategoriesTable::m_doActionOnDblClick() {
CTOOL_DEBUG_BREAK;
}

void CategoriesTable::m_updateCategories() {
const auto account_id = m_getAccountID();
if (account_id > 0) {
m_Categories.clear();
DataBase::Instance()->GetCategoriesStats( //
account_id,
[this](const CategoryName& vCategoryName,
[this](const RowID& vRowID,
const CategoryName& vCategoryName,
const TransactionDebit& vTransactionDebit,
const TransactionCredit& vTransactionCredit) { //
Category e;
e.id = vRowID;
e.name = vCategoryName;
e.debit = vTransactionDebit;
e.credit = vTransactionCredit;
Expand Down
9 changes: 6 additions & 3 deletions src/Frontend/Tables/CategoriesTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ class CategoriesTable : public ADataTable {
bool drawMenu();

protected:
double m_getAmount(const size_t& vIdx) final;
void m_drawContent(const size_t& vIdx, const double& vMaxAmount) final;
size_t m_getItemsCount() final;
size_t m_getItemsCount() const final;
RowID m_getItemRowID(const size_t& vIdx) const final;
double m_getItemAmount(const size_t& vIdx) const final;
void m_drawTableContent(const size_t& vIdx, const double& vMaxAmount) final;
void m_setupColumns() final;
void m_drawContextMenuContent() final;
void m_doActionOnDblClick() final;

private:
void m_updateCategories();
Expand Down
34 changes: 25 additions & 9 deletions src/Frontend/Tables/EntitiesTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,30 @@ bool EntitiesTable::drawMenu() {
return false;
}

double EntitiesTable::m_getAmount(const size_t& vIdx) {
size_t EntitiesTable::m_getItemsCount() const {
return m_Entities.size();
}

RowID EntitiesTable::m_getItemRowID(const size_t& vIdx) const {
if (vIdx < m_Entities.size()) {
return m_Entities.at(vIdx).id;
}
return 0; // the db row id cant be 0
}

double EntitiesTable::m_getItemAmount(const size_t& vIdx) const {
return m_Entities.at(vIdx).amount;
}

void EntitiesTable::m_drawContent(const size_t& vIdx, const double& vMaxAmount) {
void EntitiesTable::m_drawTableContent(const size_t& vIdx, const double& vMaxAmount) {
const auto& e = m_Entities.at(vIdx);
ImGui::TableNextColumn();
ImGui::Text("%s", e.name.c_str());
m_drawColumnSelectable(vIdx, e.id, e.name);
m_drawColumnDebit(e.debit);
m_drawColumnCredit(e.credit);
m_drawColumnAmount(e.amount);
m_drawColumnBars(e.amount, vMaxAmount);
}

size_t EntitiesTable::m_getItemsCount() {
return m_Entities.size();
}

void EntitiesTable::m_setupColumns() {
ImGui::TableSetupScrollFreeze(0, 1);
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed);
Expand All @@ -53,16 +59,26 @@ void EntitiesTable::m_setupColumns() {
ImGui::TableHeadersRow();
}

void EntitiesTable::m_drawContextMenuContent() {
CTOOL_DEBUG_BREAK;
}

void EntitiesTable::m_doActionOnDblClick() {
CTOOL_DEBUG_BREAK;
}

void EntitiesTable::m_updateEntities() {
const auto account_id = m_getAccountID();
if (account_id > 0) {
m_Entities.clear();
DataBase::Instance()->GetEntitiesStats( //
account_id,
[this](const EntityName& vEntityName,
[this](const RowID& vRowID,
const EntityName& vEntityName,
const TransactionDebit& vTransactionDebit,
const TransactionCredit& vTransactionCredit) { //
Entity e;
e.id = vRowID;
e.name = vEntityName;
e.debit = vTransactionDebit;
e.credit = vTransactionCredit;
Expand Down
9 changes: 6 additions & 3 deletions src/Frontend/Tables/EntitiesTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ class EntitiesTable : public ADataTable {
bool drawMenu();

protected:
double m_getAmount(const size_t& vIdx) final;
void m_drawContent(const size_t& vIdx, const double& vMaxAmount) final;
size_t m_getItemsCount() final;
size_t m_getItemsCount() const final;
RowID m_getItemRowID(const size_t& vIdx) const final;
double m_getItemAmount(const size_t& vIdx) const final;
void m_drawTableContent(const size_t& vIdx, const double& vMaxAmount) final;
void m_setupColumns() final;
void m_drawContextMenuContent() final;
void m_doActionOnDblClick() final;

private:
void m_updateEntities();
Expand Down
34 changes: 25 additions & 9 deletions src/Frontend/Tables/OperationsTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,30 @@ bool OperationsTable::drawMenu() {
return false;
}

double OperationsTable::m_getAmount(const size_t& vIdx) {
size_t OperationsTable::m_getItemsCount() const {
return m_Operations.size();
}

RowID OperationsTable::m_getItemRowID(const size_t& vIdx) const {
if (vIdx < m_Operations.size()) {
return m_Operations.at(vIdx).id;
}
return 0; // the db row id cant be 0
}

double OperationsTable::m_getItemAmount(const size_t& vIdx) const {
return m_Operations.at(vIdx).amount;
}

void OperationsTable::m_drawContent(const size_t& vIdx, const double& vMaxAmount) {
void OperationsTable::m_drawTableContent(const size_t& vIdx, const double& vMaxAmount) {
const auto& e = m_Operations.at(vIdx);
ImGui::TableNextColumn();
ImGui::Text("%s", e.name.c_str());
m_drawColumnSelectable(vIdx, e.id, e.name);
m_drawColumnDebit(e.debit);
m_drawColumnCredit(e.credit);
m_drawColumnAmount(e.amount);
m_drawColumnBars(e.amount, vMaxAmount);
}

size_t OperationsTable::m_getItemsCount() {
return m_Operations.size();
}

void OperationsTable::m_setupColumns() {
ImGui::TableSetupScrollFreeze(0, 1);
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed);
Expand All @@ -53,16 +59,26 @@ void OperationsTable::m_setupColumns() {
ImGui::TableHeadersRow();
}

void OperationsTable::m_drawContextMenuContent() {
CTOOL_DEBUG_BREAK;
}

void OperationsTable::m_doActionOnDblClick() {
CTOOL_DEBUG_BREAK;
}

void OperationsTable::m_updateOperations() {
const auto account_id = m_getAccountID();
if (account_id > 0) {
m_Operations.clear();
DataBase::Instance()->GetOperationsStats( //
account_id,
[this](const OperationName& vOperationName,
[this](const RowID& vRowID,
const OperationName& vOperationName,
const TransactionDebit& vTransactionDebit,
const TransactionCredit& vTransactionCredit) { //
Operation e;
e.id = vRowID;
e.name = vOperationName;
e.debit = vTransactionDebit;
e.credit = vTransactionCredit;
Expand Down
9 changes: 6 additions & 3 deletions src/Frontend/Tables/OperationsTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ class OperationsTable : public ADataTable {
bool drawMenu();

protected:
double m_getAmount(const size_t& vIdx) final;
void m_drawContent(const size_t& vIdx, const double& vMaxAmount) final;
size_t m_getItemsCount() final;
size_t m_getItemsCount() const final;
RowID m_getItemRowID(const size_t& vIdx) const final;
double m_getItemAmount(const size_t& vIdx) const final;
void m_drawTableContent(const size_t& vIdx, const double& vMaxAmount) final;
void m_setupColumns() final;
void m_drawContextMenuContent() final;
void m_doActionOnDblClick() final;

private:
void m_updateOperations();
Expand Down
76 changes: 76 additions & 0 deletions src/Frontend/Tables/TransactionsTable.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <Frontend/Tables/TransactionsTable.h>
#include <Models/DataBase.h>

TransactionsTable::TransactionsTable() : ADataTable("TransactionsTable", 5) {
}

TransactionsTable::~TransactionsTable() {
}

bool TransactionsTable::load() {
ADataTable::load();
m_updateTransactions();
return true;
}

void TransactionsTable::unload() {
ADataTable::unload();
}

bool TransactionsTable::drawMenu() {
if (ADataTable::drawMenu()) {
m_updateTransactions();
return true;
}
return false;
}

size_t TransactionsTable::m_getItemsCount() const {
return m_Transactions.size();
}

RowID TransactionsTable::m_getItemRowID(const size_t& vIdx) const {
if (vIdx < m_Transactions.size()) {
return m_Transactions.at(vIdx).id;
}
return 0; // the db row id cant be 0
}

double TransactionsTable::m_getItemAmount(const size_t& vIdx) const {
return m_Transactions.at(vIdx).amount;
}

void TransactionsTable::m_drawTableContent(const size_t& vIdx, const double& vMaxAmount) {
const auto& t = m_Transactions.at(vIdx);
m_drawColumnSelectable(vIdx, t.id, t.description);
m_drawColumnDebit(t.debit);
m_drawColumnCredit(t.credit);
m_drawColumnAmount(t.amount);
m_drawColumnBars(t.amount, vMaxAmount);
}

void TransactionsTable::m_setupColumns() {
ImGui::TableSetupScrollFreeze(0, 1);
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("Debit", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("Credit", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("Amount", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("Bars", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableHeadersRow();
}

void TransactionsTable::m_drawContextMenuContent() {
CTOOL_DEBUG_BREAK;
}

void TransactionsTable::m_doActionOnDblClick() {
CTOOL_DEBUG_BREAK;
}

void TransactionsTable::m_updateTransactions() {
const auto account_id = m_getAccountID();
if (account_id > 0) {
m_Transactions.clear();
CTOOL_DEBUG_BREAK;
}
}
28 changes: 28 additions & 0 deletions src/Frontend/Tables/TransactionsTable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include <Frontend/Tables/abstract/ADataTable.h>

class TransactionsTable : public ADataTable {
private:
std::vector<Transaction> m_Transactions;

public:
TransactionsTable();
~TransactionsTable();

bool load();
void unload();
bool drawMenu();

protected:
size_t m_getItemsCount() const final;
RowID m_getItemRowID(const size_t& vIdx) const final;
double m_getItemAmount(const size_t& vIdx) const final;
void m_drawTableContent(const size_t& vIdx, const double& vMaxAmount) final;
void m_setupColumns() final;
void m_drawContextMenuContent() final;
void m_doActionOnDblClick() final;

private:
void m_updateTransactions();
};
Loading

0 comments on commit 05e4f8f

Please sign in to comment.