Stats_window.cpp 4.7 KB
Newer Older
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
#include "Stats_window.hpp"

using namespace std;

Stats_window::Stats_window(Interface_console* core, QWidget *parent) : QMainWindow(parent) {
    setupUi(this);

    _core = core;

    CKFP(_ui_stats_area_layout = qFindChild<QVBoxLayout *>(this, "stats_area"), "Cannot find the stats_area_layout in the .ui file");

    _ui_stats_area = new Render_stats_opengl(this);
    _ui_stats_area_layout->addWidget(_ui_stats_area);
    
    QMetaObject::connectSlotsByName(NULL);
}

void Stats_window::set_container_names() {
    
    const list <Container *> *root_containers = _trace->get_root_containers();

    if(root_containers->empty()) {
        *Message::get_instance() << "No containers in this trace" << Message::ende;
        return;
    }
    // Add the root container names
    QList<QTreeWidgetItem *> items;
    for (list<Container *>::const_iterator it = root_containers->begin();
         it != root_containers->end();
         it ++) {
        string name = (*it)->get_name().to_string();
        QStringList temp(QString::fromStdString(name));
        QTreeWidgetItem *current_node = new QTreeWidgetItem((QTreeWidgetItem *)0, temp);
        items.append(current_node);
        
        // Recursivity to add the children names
        set_container_names_rec(current_node, (*it));
    }

    _nodes_selected->insertTopLevelItems(0, items);
}

void Stats_window::set_container_names_rec(QTreeWidgetItem *current_node, Container *current_container) {
    const list<Container *> *children = current_container->get_children();
    for (list<Container *>::const_iterator it = children->begin();
         it != children->end();
         it ++) {
        // We create the node and we do the recursivity
        string name = (*it)->get_name().to_string();
        QStringList temp(QString::fromStdString(name));
        QTreeWidgetItem *node = new QTreeWidgetItem(current_node, temp);
        set_container_names_rec(node ,(*it));
    }   
}

void Stats_window::set_trace(Trace *trace) {
    _trace = trace;
}


void Stats_window::init_window() {
    // We set the names of the containers for the tree widget
    _nodes_selected->clear();
    set_container_names();
    
    // We init the times
    _start_time = Info::Render::_x_min_visible;
    _end_time = Info::Render::_x_max_visible;

    QString temp;
    temp.setNum(_start_time);
    _start_time_widget->setText(temp);
    temp.setNum(_end_time);
    _end_time_widget->setText(temp);
75
76
77

    _ui_stats_area->clear();
    Reinit_scroll_bars();
78
79
80
81
}


void Stats_window::on_reload_button_clicked() {
82
    std::string kind_of_diagram = _kind_of_diagram_box->currentText ().toStdString();
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
    // We delete the previous selected containers
    if(!_selected_containers.empty()) {
        _selected_containers.clear();
    }

    // We fill the new selected containers
    QTreeWidgetItemIterator it(_nodes_selected);
    while (*it) {
        if ((*it)->isSelected()){
            _selected_containers.push_back(_trace->search_container((*it)->text(0).toStdString()));
        }
        it ++;
    }
    _number_of_selected_container = _selected_containers.size();

#ifdef STAT_DEBUG
    for(unsigned int i = 0 ; i < _selected_containers.size() ; i ++) {
        cout << _selected_containers[i]->get_name().to_string() << endl;
    }
#endif

104
105
    Reinit_scroll_bars();

106
107
    // We get the times
    _start_time = _start_time_widget->text().toDouble();
108
    _end_time   = _end_time_widget->text().toDouble();
109

110
    // We create a drawer
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
    DrawStats<Render_stats_opengl> *drawer;
    if(kind_of_diagram == "Horizontal Histogram") 
      {
	drawer = new DrawHDiagram<Render_stats_opengl>();
      }
    else if (kind_of_diagram == "Histogram") 
      {
	drawer = new DrawStats<Render_stats_opengl>();
      }
    else if (kind_of_diagram == "Chart") 
      {
	*Message::get_instance() << kind_of_diagram << " not yet implemented" << Message::endw;
	drawer = new DrawStats<Render_stats_opengl>();
      }
    else
      {
	*Message::get_instance() << kind_of_diagram << " not yet implemented" << Message::endw;
	drawer = new DrawStats<Render_stats_opengl>();
      }
    drawer->set_times(_start_time, _end_time);
    drawer->build(_ui_stats_area, _selected_containers);
132

133
    _ui_stats_area->updateGL();
134
135
}

136
137
138
139
void Stats_window::close_window(){
    _ui_stats_area->doneCurrent();
    hide();
}
140
141
142
143
144

// new_value is between 0 and 99
void Stats_window::on_y_scroll_valueChanged(int new_value) {
    _ui_stats_area->translate_y(new_value);
}
145
146
147
148
149
150
151
152
153
154
155
156
157

// new_value is between 0 and 99
void Stats_window::on_x_scroll_valueChanged(int new_value) {
    _ui_stats_area->translate_x(new_value);
}


void Stats_window::Reinit_scroll_bars() {
    _ui_stats_area->translate_y(0);
    _ui_stats_area->translate_y(0);
    x_scroll->setSliderPosition(0);
    y_scroll->setSliderPosition(0);
}