-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCGTeaSidebar.cpp
More file actions
executable file
·94 lines (77 loc) · 3.36 KB
/
CGTeaSidebar.cpp
File metadata and controls
executable file
·94 lines (77 loc) · 3.36 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//
// Created by rostam on 15.10.19.
//
#include "CGTeaSidebar.h"
static const wxColour kRowEven(245, 248, 255);
static const wxColour kRowOdd (255, 255, 255);
static const wxColour kHeaderBg(55, 90, 145);
static const wxColour kHeaderFg(*wxWHITE);
static void fitGridColumns(wxGrid* grid) {
int w = grid->GetClientSize().GetWidth();
grid->AutoSizeColumn(0);
int col1 = w - grid->GetColSize(0);
if (col1 > 60)
grid->SetColSize(1, col1);
}
CGTeaSidebar::CGTeaSidebar(wxWindow* parent, wxWindowID winid) : wxPanel(parent, winid) {
auto* frame = static_cast<CGTeaFrame*>(wxGetTopLevelParent(this));
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_FRAMEBK));
statistics_grid = new wxGrid(this, wxID_ANY);
statistics_grid->CreateGrid((int)frame->availableReports.size(), 2);
statistics_grid->SetColLabelValue(0, "Report");
statistics_grid->SetColLabelValue(1, "Value");
statistics_grid->EnableEditing(false);
statistics_grid->HideRowLabels();
statistics_grid->SetDefaultCellAlignment(wxALIGN_LEFT, wxALIGN_CENTRE);
statistics_grid->SetDefaultRowSize(22, true);
statistics_grid->SetColLabelSize(24);
// Style column headers
wxFont headerFont = statistics_grid->GetLabelFont();
headerFont.MakeBold();
statistics_grid->SetLabelFont(headerFont);
statistics_grid->SetLabelBackgroundColour(kHeaderBg);
statistics_grid->SetLabelTextColour(kHeaderFg);
// Populate report names with zebra striping
for (int i = 0; i < (int)frame->availableReports.size(); i++) {
const wxColour& bg = (i % 2 == 0) ? kRowEven : kRowOdd;
statistics_grid->SetCellValue(i, 0, wxString(frame->availableReports[i]->name()));
statistics_grid->SetCellBackgroundColour(i, 0, bg);
statistics_grid->SetCellBackgroundColour(i, 1, bg);
}
statistics_grid->Bind(wxEVT_SIZE, [this](wxSizeEvent& e) {
e.Skip();
fitGridColumns(statistics_grid);
});
auto* compute_stat = new wxButton(this, 100, "Compute Statistics");
Connect(100, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(CGTeaSidebar::computeStat));
auto* sizer = new wxBoxSizer(wxVERTICAL);
sizer->Add(statistics_grid, 1, wxEXPAND | wxALL, 6);
sizer->Add(compute_stat, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 6);
SetSizer(sizer);
}
void CGTeaSidebar::computeStat(wxCommandEvent& WXUNUSED(event))
{
auto* frame = static_cast<CGTeaFrame*>(wxGetTopLevelParent(this));
const int total = (int)frame->availableReports.size();
if (auto* btn = FindWindowById(100, this)) btn->Disable();
for (int i = 0; i < total; i++)
statistics_grid->SetCellValue(i, 1, "...");
fitGridColumns(statistics_grid);
wxSafeYield(frame);
for (int i = 0; i < total; i++) {
const std::string& name = frame->availableReports[i]->name();
frame->SetStatusText(wxString::Format("Computing [%d/%d]: %s", i + 1, total, name));
wxSafeYield(frame);
std::string result;
try {
result = frame->availableReports[i]->report(frame->currentGraph);
} catch (...) {
result = "(error)";
}
statistics_grid->SetCellValue(i, 1, wxString(result));
fitGridColumns(statistics_grid);
wxSafeYield(frame);
}
frame->SetStatusText("Statistics computed.");
if (auto* btn = FindWindowById(100, this)) btn->Enable();
}