Improve database tab

This commit is contained in:
Loic Guegan 2022-12-27 19:41:33 +01:00
parent 32fdf9272e
commit cb6fbd18f3
9 changed files with 76 additions and 15 deletions

View file

@ -1,6 +1,14 @@
#include "BaseGameTab.hpp"
#include <wx/filename.h>
#define NOTIFY_MANAGE_TAB() \
{ \
wxCommandEvent e(REFRESH_MANAGE_TAB,GetId()); \
ProcessEvent(e); \
}
wxDECLARE_EVENT(REFRESH_MANAGE_TAB, wxCommandEvent);
BaseGameTab::BaseGameTab(wxFrame *parent, std::shared_ptr<GameBase> base)
: TabBase_TabGames(parent),base(base) {
@ -31,6 +39,7 @@ void BaseGameTab::OnDelete(wxCommandEvent &event) {
deleted.push_back(glm->GetItemGameId(i));
glm->MarkItemAsDeleted(i);
}
NOTIFY_MANAGE_TAB();
}
std::shared_ptr<Game> BaseGameTab::OpenGame(long gameid, long item) {
@ -44,6 +53,7 @@ std::shared_ptr<Game> BaseGameTab::OpenGame(long gameid, long item) {
edited[gameid]=g;
deleted.push_back(gameid);
glm->MarkItemAsOpen(item);
NOTIFY_MANAGE_TAB();
return g;
}
}
@ -79,6 +89,7 @@ void BaseGameTab::Reset(std::shared_ptr<GameBase> base){
base->GetTag("ECO"));
}
}
NOTIFY_MANAGE_TAB();
}

View file

@ -1,18 +1,21 @@
#pragma once
#include "gamebase/GameBase.hpp"
#include "gamebase/PGNGameBase.hpp"
#include "GameListManager.hpp"
class BaseGameTab : public TabBase_TabGames {
std::shared_ptr<GameBase> base;
public:
std::shared_ptr<GameListManager> glm;
/// @brief Old deleted games id
std::vector<std::uint32_t> deleted;
/// @brief Old edited game id+object
std::unordered_map<long, std::shared_ptr<Game>> edited;
public:
std::shared_ptr<GameListManager> glm;
BaseGameTab(wxFrame *parent, std::shared_ptr<GameBase> base);
void Reset(std::shared_ptr<GameBase> base);

View file

@ -2,9 +2,22 @@
#include <algorithm>
#include "gamebase/GameBase.hpp"
#define NOTIFY_MANAGE_TAB() \
{ \
wxCommandEvent e(REFRESH_MANAGE_TAB,GetId()); \
ProcessEvent(e); \
}
wxDECLARE_EVENT(REFRESH_MANAGE_TAB, wxCommandEvent);
BaseImportTab::BaseImportTab(wxFrame *parent, std::shared_ptr<GameBase> db, TabInfos *main_tab):
TabBase_TabImport(parent), main_tab(main_tab), base(db)
{
// Init counters
import_ndb=0;
import_ngames=0;
import_nselect=0;
glm=std::make_shared<GameListManager>(game_list);
RefreshImportLists();
RefreshPendingImports();
@ -27,17 +40,19 @@ void BaseImportTab::OnImportDatabase(wxCommandEvent &event){
}
void BaseImportTab::RefreshPendingImports(){
int ngames=games_to_import.size();
int ndb=databases_to_import.size();
int nbselect=0;
import_ndb=databases_to_import.size();
import_ngames=games_to_import.size();
import_nselect=0;
for (auto it = selected_games_to_import.begin(); it != selected_games_to_import.end(); it++){
nbselect+=it->second.size();
import_nselect+=it->second.size();
}
pending_imports->Clear();
if(ngames+ndb+nbselect>0){
pending_imports->AppendText(" Pending imports: "+std::to_string(ngames+nbselect)+" games and "+std::to_string(ndb)+" databases");
if(import_ndb+import_ngames+import_nselect>0){
pending_imports->AppendText(" Pending imports: "+std::to_string(import_ngames+import_nselect)+" games and "+std::to_string(import_ndb)+" databases");
}else
pending_imports->SetHint("No pending imports");
NOTIFY_MANAGE_TAB();
}
void BaseImportTab::RefreshImportLists(){
@ -116,6 +131,7 @@ void BaseImportTab::Reset(std::shared_ptr<GameBase> base){
this->selected_games_to_import.clear();
glm->Clear();
RefreshPendingImports();
NOTIFY_MANAGE_TAB();
}
std::vector<std::shared_ptr<Game>> BaseImportTab::GetGameToImport(){

View file

@ -18,6 +18,7 @@ class BaseImportTab : public TabBase_TabImport {
void RefreshPendingImports();
public:
int import_ndb, import_ngames,import_nselect;
BaseImportTab(wxFrame *parent, std::shared_ptr<GameBase> db, TabInfos *main_tab);
void RefreshImportLists();
void OnLoad(wxCommandEvent &event);

View file

@ -2,9 +2,8 @@
#define ADD_INFO(text) {informations->WriteText(text);informations->WriteText("\n");}
BaseManageTab::BaseManageTab(wxFrame *parent, std::shared_ptr<GameBase> db, std::shared_ptr<GameListManager> glm):
TabBase_TabManage(parent), glm(glm), base(db)
BaseManageTab::BaseManageTab(wxFrame *parent, std::shared_ptr<GameBase> db, std::shared_ptr<GameListManager> glm, BaseImportTab *import_tab,BaseGameTab *games_tab):
TabBase_TabManage(parent), glm(glm), base(db), import_tab(import_tab), games_tab(games_tab)
{
RefreshInformations();
}
@ -17,6 +16,20 @@ void BaseManageTab::RefreshInformations(){
ADD_INFO("Last Modified: "+base_path.GetModificationTime().Format());
ADD_INFO("Database Format: "+base->GetFormat());
ADD_INFO("Total Number of Games: "+std::to_string(glm->rows.size()));
int ngames=import_tab->import_ngames;
int nselect=import_tab->import_nselect;
int ndb=import_tab->import_ndb;
int nedited=games_tab->edited.size();
int ndeleted=games_tab->deleted.size()-nedited;
if((ngames+nselect+ndb+nedited+ndeleted) >0){
ADD_INFO("\n---------- Pending operations ----------");
ADD_INFO("Imports:");
ADD_INFO(" -> "+std::to_string(ngames+nselect)+" game(s)");
ADD_INFO(" -> "+std::to_string(ndb)+ " database(s)");
ADD_INFO("Others:");
ADD_INFO(" -> "+std::to_string(nedited)+" edited game(s)");
ADD_INFO(" -> "+std::to_string(ndeleted)+" deleted game(s)");
}
}
void BaseManageTab::Reset(std::shared_ptr<GameBase> db) {

View file

@ -1,15 +1,22 @@
#pragma once
#include "ochess.hpp"
#include "GameListManager.hpp"
#include "gamebase/GameBase.hpp"
#include "BaseImportTab.hpp"
#include "BaseGameTab.hpp"
class BaseManageTab : public TabBase_TabManage {
/// @brief Never free the following pointer in that class
/// @brief Never free the following pointers in that class
std::shared_ptr<GameListManager> glm;
std::shared_ptr<GameBase> base;
BaseImportTab *import_tab;
BaseGameTab *games_tab;
public:
BaseManageTab(wxFrame *parent, std::shared_ptr<GameBase> db, std::shared_ptr<GameListManager> glm);
BaseManageTab(wxFrame *parent, std::shared_ptr<GameBase> db,
std::shared_ptr<GameListManager> glm, BaseImportTab *import_tab, BaseGameTab *games_tab);
void RefreshInformations();
void Reset(std::shared_ptr<GameBase> db);
};

View file

@ -1,6 +1,8 @@
#include "BaseTab.hpp"
#include <wx/filename.h>
wxDEFINE_EVENT(REFRESH_MANAGE_TAB, wxCommandEvent);
BaseTab::BaseTab(wxFrame *parent, std::string base_file)
: TabBase(parent), TabInfos(TabInfos::BASE), base_file(base_file){
@ -14,7 +16,7 @@ BaseTab::BaseTab(wxFrame *parent, std::string base_file)
import_tab=new BaseImportTab((wxFrame *)notebook,base,this);
notebook->AddPage(import_tab, "Import games");
// Manage tab
manage_tab=new BaseManageTab((wxFrame *)notebook, base, games_tab->glm);
manage_tab=new BaseManageTab((wxFrame *)notebook, base, games_tab->glm,import_tab,games_tab);
notebook->AddPage(manage_tab, "Manage database");
// Refresh dynamic elements of the database (tab title, available db for import etc.)
@ -23,6 +25,9 @@ BaseTab::BaseTab(wxFrame *parent, std::string base_file)
// Bindings
this->Bind(wxEVT_BUTTON, &BaseTab::OnSave, this, ID_SAVE_BUTTON);
this->Bind(wxEVT_LIST_ITEM_ACTIVATED, &BaseTab::OnOpenGame, this, ID_TABGAMES_GAME_LIST);
Bind(REFRESH_MANAGE_TAB,[tab=manage_tab](wxCommandEvent &e){
tab->RefreshInformations();
},wxID_ANY);
}
void BaseTab::OnOpenGame(wxListEvent &event){

View file

@ -10,6 +10,9 @@
wxDECLARE_EVENT(NEW_GAME_EVENT, wxCommandEvent);
wxDECLARE_EVENT(CLOSE_LINKED_TAB, wxCommandEvent);
// Local events
wxDECLARE_EVENT(REFRESH_MANAGE_TAB, wxCommandEvent);
class BaseTab : public TabBase, public TabInfos {
/// @brief The opened database
std::shared_ptr<GameBase> base;

View file

@ -1,3 +1,5 @@
#pragma once
#include "GameBase.hpp"
#include "pgnp.hpp"