aboutsummaryrefslogtreecommitdiff
path: root/src/base_tab/GameListManager.hpp
blob: d48ac3620f36b4aa40d979b4f1a6b8da3c4c29b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#pragma once

#include "ochess.hpp"
#include <algorithm>
#include <vector>

#define TERMS_IN(COL) (row.COL.find(terms) != std::string::npos)
#define BG_OPEN(INDEX) game_list->SetItemBackgroundColour(INDEX, *wxGREEN)
#define BG_DELETE(INDEX) game_list->SetItemBackgroundColour(INDEX, *wxRED)
#define BG_IMPORT(INDEX) game_list->SetItemBackgroundColour(INDEX, *wxBLUE)
#define DISPLAY_ALL_ROWS() {for(std::size_t i=0;i<rows.size();i++){DisplayRow(i);}}

///@brief Column content type
typedef std::string CType;

///@brief Row item content
typedef struct Item {
    long id;
    CType White;
    CType Black;
    CType Event;
    CType Round;
    CType Result;
    CType Eco;
} RType;

/**
 * @brief A manager for wxListCtrl that display games
 * 
 */
class GameListManager {
    long game_counter;
    wxListCtrl *game_list;
    std::vector<long> deleted_games, opened_games, imported_games;

    void DisplayRow(long id);
    void ClearDisplayedRow();
public:
    /// @brief Accessible outside (DO NOT MODIFY FROM OUTSIDE)
    std::vector<RType> rows;

    GameListManager(wxListCtrl *game_list);
    /// @brief Add a game to the list
    long AddGame(CType White,CType Black,CType Event,CType Round, CType Result, CType Eco);
    void MarkItemAsOpen(long item);
    void MarkItemAsDeleted(long item);
    void MarkItemAsImported(long item);
    /// @brief Clear the state of the GameListManager
    void Clear();
    /// @brief Return the id of the selected items
    std::vector<long> GetSelectedItems();
    /// @brief Get the game id from the item id
    long GetItemGameId(long item);
    /// @brief Filter the rows given terms
    void Filter(std::string terms);
    /// @brief Remove all filters
    void ClearFilter();
    /// @brief Sort items by the given column
    void SortBy(short col);
};