Commit 7c3905a2 authored by Johnny Jazeix's avatar Johnny Jazeix
Browse files

An horizontal scroll bar added for the stats, and the printing of the

percentage above the values.
parent 1c3ac9af
......@@ -6,7 +6,7 @@
<x>0</x>
<y>0</y>
<width>855</width>
<height>701</height>
<height>720</height>
</rect>
</property>
<property name="windowTitle" >
......@@ -22,7 +22,7 @@
<x>0</x>
<y>26</y>
<width>855</width>
<height>675</height>
<height>694</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2" >
......@@ -112,14 +112,30 @@
<enum>QLayout::SetMaximumSize</enum>
</property>
<item>
<layout class="QVBoxLayout" name="stats_area" >
<layout class="QVBoxLayout" name="verticalLayout_5" >
<property name="sizeConstraint" >
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<layout class="QVBoxLayout" name="stats_area" />
</item>
<item>
<widget class="QScrollBar" name="x_scroll" >
<property name="pageStep" >
<number>3</number>
</property>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QScrollBar" name="y_scroll" >
<property name="pageStep" >
<number>3</number>
</property>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
......
......@@ -13,6 +13,7 @@ using namespace std;
Render_stats_opengl::Render_stats_opengl(QWidget *parent) : QGLWidget(parent){
_translated_y = 0;
_translated_x = 0;
}
Render_stats_opengl::~Render_stats_opengl(){
......@@ -52,7 +53,7 @@ void Render_stats_opengl::paintGL(){
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0, _screen_width, 0, _screen_height);
glTranslated(0, _translated_y, 0);
glTranslated(-_translated_x, _translated_y, 0);
list<Element_pos>::iterator it_pos;
list<string>::iterator it_txt;
......@@ -89,15 +90,33 @@ void Render_stats_opengl::paintGL(){
glFlush();
}
void Render_stats_opengl::translate_y(int value) {
_translated_y = (double)value/100.0*_render_height;
//cout << "h :" << _render_height << endl;
updateGL();
}
void Render_stats_opengl::translate_x(int value) {
_translated_x = (double)value/100.0*_render_width;
//cout << "w :" << _render_width << endl;
updateGL();
}
void Render_stats_opengl::set_total_height(Element_pos h) {
_render_height = h;
//cout << "total height of the stats: " << h << endl;
}
void Render_stats_opengl::translate_y(int value) {
_translated_y = (double)value/100.0*_render_height;
//cout << _render_height << endl;
updateGL();
void Render_stats_opengl::set_total_width(Element_pos w) {
_render_width = w;
}
void Render_stats_opengl::clear(){
makeCurrent();
_translated_y = 0;
_translated_x = 0;
_text_pos.clear();
_text_value.clear();
glDeleteLists(_rect_list, 1);
paintGL();
}
......@@ -36,6 +36,8 @@ private:
GLuint _rect_list;
double _translated_y;
double _translated_x;
public:
......@@ -102,10 +104,19 @@ public:
void end_draw();
void translate_y(int value);
void translate_x(int value);
/*!
* \brief Set the height of the render area.
*/
void set_total_height(Element_pos h);
/*!
* \brief Set the width of the render area.
*/
void set_total_width(Element_pos w);
void clear();
};
......
......@@ -31,7 +31,7 @@
* \brief The default y position for the container name.
* The origin is set at the north west.
*/
#define _POS_Y_CONTAINER_NAME _HEIGHT_FOR_ONE_CONTAINER_DEFAULT-10.0f
#define _POS_Y_CONTAINER_NAME _HEIGHT_FOR_ONE_CONTAINER_DEFAULT-30.0f
/*!
* \def _WIDTH_HISTOGRAM_DEFAULT
......@@ -132,11 +132,16 @@ public:
*/
void build(T* draw_object, std::vector<Container *> containers_to_print, std::string kind_of_diagram) {
draw_object->clear();
_size_for_one_container = draw_object->height();
_containers_to_print = containers_to_print;
const int number_of_containers = _containers_to_print.size();
draw_object->start_draw();
draw_object->set_total_height((number_of_containers-1)*_size_for_one_container);
draw_object->set_total_width(draw_object->width());
for(int i = 0 ; i < number_of_containers ; i ++) {
draw_container_name(draw_object, i);
......@@ -147,7 +152,7 @@ public:
end_draw(draw_object);
}
void draw_container_name(T* draw_object, const int container_id) {
void draw_container_name(T* draw_object, const int container_id) const {
// Get the position for the i-th container name
Element_pos pos_x = _pos_x_container_name;
......@@ -171,20 +176,12 @@ public:
int pos_x = _START_HISTOGRAM_X_DEFAULT;
int pos_y = _START_HISTOGRAM_Y_DEFAULT - container_id*_size_for_one_container;
const double max_percentage = get_max_percentage(temp_states);
// Draw axes
draw_object->draw_axis(pos_x, pos_y, _WIDTH_HISTOGRAM_DEFAULT*(_states[container_id].size()+1), _percentage_height_default*100);
draw_object->draw_text(pos_x-30, pos_y+_percentage_height_default*100, "1");
draw_object->draw_text(pos_x-30, pos_y+_percentage_height_default*100-5, QString::number(max_percentage*100., 'g', 3).toStdString()+"%");
draw_object->draw_horizontal_line(pos_x, pos_y+_percentage_height_default*100, _WIDTH_HISTOGRAM_DEFAULT*(_states[container_id].size()+1));
// // Draw 25%, 50% and 75% for help
// for(int i = 0 ;i < 3 ; i ++){
// char temp[4] = "\0";
// sprintf(temp, "%3lf", (float)(i+1)*0.25);
// draw_object->draw_text(pos_x-30, pos_y+_percentage_height_default*25*(i+1), temp);
// draw_object->draw_horizontal_line(pos_x, pos_y+_percentage_height_default*25*(i+1), _WIDTH_HISTOGRAM_DEFAULT*(_states[container_id].size()+1));
// }
// Draw the stats
for (map<const EntityValue *, stats *>::iterator it = temp_states.begin();
......@@ -193,17 +190,21 @@ public:
std::string name = (*it).first->get_name().to_string();
// We have to convert the percentage in a rectangle and print it
int height = (*it).second->_total_length*100.*_percentage_height_default/(_end_time-_start_time);
const double length = (*it).second->_total_length;
const double height = length*100.*_percentage_height_default/(_end_time-_start_time);
/* We search for a color */
// We search for a color
if((*it).first->get_extra_fields()->find(std::string("Color")) != (*it).first->get_extra_fields()->end()) {
const Color *color = (const Color *)(*it).first->get_extra_fields()->find(std::string("Color"))->second;
draw_object->draw_rect(pos_x, pos_y, _WIDTH_HISTOGRAM_DEFAULT, height, color->get_red(), color->get_green(), color->get_blue());
draw_object->draw_rect(pos_x, pos_y, _WIDTH_HISTOGRAM_DEFAULT, height/max_percentage, color->get_red(), color->get_green(), color->get_blue());
}
else {
draw_object->draw_rect(pos_x, pos_y, _WIDTH_HISTOGRAM_DEFAULT, height, 0.7, 0.7, 0.75);
draw_object->draw_rect(pos_x, pos_y, _WIDTH_HISTOGRAM_DEFAULT, height/max_percentage, 0.7, 0.7, 0.75);
}
// We print the percentage above
draw_object->draw_text(pos_x, pos_y+height/max_percentage+1, QString::number(length/(_end_time-_start_time)*100., 'f', 1).toStdString()+"%");
//std::cout << "State : " << name << " for " << (*it).second->_total_length*100./(_end_time-_start_time)<< "% between " << _start_time << " sec and " << _end_time << " sec" << std::endl;
pos_x += _WIDTH_HISTOGRAM_DEFAULT;
......@@ -263,7 +264,28 @@ public:
_end_time = end;
}
void updateGL(T* draw_object) {
/*!
*
* \return a value between 0. and 1.
*
*/
double get_max_percentage(std::map<const EntityValue*, stats*> &temp_states) const {
double value;
double max_length = 0.;
for (map<const EntityValue *, stats *>::iterator it = temp_states.begin();
it != temp_states.end();
it ++) {
if((*it).second->_total_length >= max_length) {
max_length = (*it).second->_total_length;
}
}
value = max_length/(_end_time-_start_time);
//std::cerr << value << std::endl;
return value;
}
void updateGL(T* draw_object) const {
draw_object->updateGL();
}
......
......@@ -72,6 +72,9 @@ void Stats_window::init_window() {
_start_time_widget->setText(temp);
temp.setNum(_end_time);
_end_time_widget->setText(temp);
_ui_stats_area->clear();
Reinit_scroll_bars();
}
......@@ -91,7 +94,6 @@ void Stats_window::on_reload_button_clicked() {
it ++;
}
_number_of_selected_container = _selected_containers.size();
_ui_stats_area->paintGL();
#ifdef STAT_DEBUG
for(unsigned int i = 0 ; i < _selected_containers.size() ; i ++) {
......@@ -99,6 +101,8 @@ void Stats_window::on_reload_button_clicked() {
}
#endif
Reinit_scroll_bars();
// We get the times
_start_time = _start_time_widget->text().toDouble();
_end_time = _end_time_widget->text().toDouble();
......@@ -108,7 +112,7 @@ void Stats_window::on_reload_button_clicked() {
drawer.set_times(_start_time, _end_time);
drawer.build(_ui_stats_area, _selected_containers, _kind_of_diagram_box->currentText ().toStdString());
drawer.updateGL(_ui_stats_area);
_ui_stats_area->updateGL();
}
void Stats_window::close_window(){
......@@ -120,3 +124,16 @@ void Stats_window::close_window(){
void Stats_window::on_y_scroll_valueChanged(int new_value) {
_ui_stats_area->translate_y(new_value);
}
// 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);
}
......@@ -53,12 +53,15 @@ public:
void set_trace(Trace *trace);
void init_window();
void Reinit_scroll_bars();
/*!
\fn close_window()
\brief Properly close the window
*/
void close_window();
private:
void set_container_names_rec(QTreeWidgetItem *current_node, Container *current_container);
......@@ -67,6 +70,7 @@ private slots:
void on_reload_button_clicked();
void on_y_scroll_valueChanged(int new_value);
void on_x_scroll_valueChanged(int new_value);
};
#endif // STATS_WINDOW_HPP
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment