Commit a4ccee0e authored by Mathieu Faverge's avatar Mathieu Faverge

Factorize fill_table

parent 5f4a26b3
......@@ -88,7 +88,7 @@ Settings_window::Settings_window(Core *c, QWidget *parent) : QWidget(parent), _c
palette_list->addItems(palettes);
string current = S.get_current_palette("palette");
fill_table(current);
fill_table_states(current);
palette_list->setCurrentIndex(palette_list->findText(QString::fromStdString(current))); // Set the combobox at the good index.
......@@ -98,7 +98,7 @@ Settings_window::Settings_window(Core *c, QWidget *parent) : QWidget(parent), _c
event_types_palette_list->addItems(palettes);
current = S.get_current_palette("event_types");
// Need to load the types
fill_event_types_table(current);
fill_table_events(current);
event_types_palette_list->setCurrentIndex(event_types_palette_list->findText(QString::fromStdString(current))); // Set the combobox at the good index.
link_types_palette_list->clear();
// QStringList palettes;
......@@ -106,7 +106,7 @@ Settings_window::Settings_window(Core *c, QWidget *parent) : QWidget(parent), _c
link_types_palette_list->addItems(palettes);
current = S.get_current_palette("link_types");
// Need to load the types
fill_link_types_table(current);
fill_table_links(current);
link_types_palette_list->setCurrentIndex(link_types_palette_list->findText(QString::fromStdString(current))); // Set the combobox at the good index.
}
......@@ -178,23 +178,27 @@ void Settings_window::plugin_load_dirs_name() {
/****** State tab. ******/
/************************/
void Settings_window::fill_table(const string &palette_name) {
void Settings_window::fill_table( QTableWidget *table,
const char *slot,
const string pname,
const string &palette_name )
{
map<string, Color *> colors_settings;
map<string, Color *> colors_trace;
int row = 0;
/* Clean the table before insertion */
while(states_table->rowCount() > 0) { // Clear the current table
states_table->removeRow(0);
while(table->rowCount() > 0) { // Clear the current table
table->removeRow(0);
}
/* Get the list form settings */
Palette *p = Session::getSession().get_palette("palette",palette_name);
Palette *p = Session::getSession().get_palette( pname, palette_name );
colors_settings = p->get_map();
/* Get the list from trace */
if(_c->get_trace()) { // Need a trace loaded
_c->get_trace()->get_states_colors(colors_trace);
_c->get_trace()->get_colors(pname, colors_trace);
}
else {
//cerr << "no trace loaded" << endl;
......@@ -208,14 +212,32 @@ void Settings_window::fill_table(const string &palette_name) {
for(it = colors_settings.begin();
it != colors_settings.end(); ++it)
{
add_table_line(states_table, SLOT(state_color_changed(const QColor &)),
add_table_line(table, slot,
row, it->first, it->second, p->is_visible( it->first ));
}
}
void Settings_window::fill_table_states( const string &palette_name ) {
fill_table( states_table,
SLOT(state_color_changed(const QColor &)),
"palette", palette_name );
}
void Settings_window::fill_table_events( const string &palette_name ) {
fill_table( event_types_table,
SLOT(event_types_color_changed(const QColor &)),
"event_types", palette_name );
}
void Settings_window::fill_table_links( const string &palette_name ) {
fill_table( link_types_table,
SLOT(link_types_color_changed(const QColor &)),
"link_types", palette_name );
}
void Settings_window::on_palette_list_currentIndexChanged(const QString & text) {
_changed=true;
fill_table(text.toStdString());
fill_table_states(text.toStdString());
}
void Settings_window::add_palette(QComboBox* list, const std::string type){
......@@ -286,7 +308,7 @@ QString Settings_window::copy_palette(QTableWidget* , QComboBox* list, const std
void Settings_window::on_copy_palette_btn_clicked() {
QString text= copy_palette(states_table, palette_list, "palette");
fill_table(text.toStdString());
fill_table_states(text.toStdString());
}
......@@ -300,7 +322,7 @@ void Settings_window::rm_palette(QComboBox* list, const std::string type){
void Settings_window::on_rm_palette_btn_clicked() {
rm_palette(palette_list, "palette");
fill_table(palette_list->currentText().toStdString());
fill_table_states(palette_list->currentText().toStdString());
}
void Settings_window::on_reload_states_btn_clicked(){
......@@ -402,7 +424,6 @@ void Settings_window::color_changed(string name, QTableWidget *table, const QCol
return;
}
void Settings_window::state_color_changed(const QColor &qc) {
color_changed("palette", states_table, qc);
}
......@@ -415,6 +436,7 @@ void Settings_window::link_types_color_changed(const QColor &qc) {
color_changed("link_types", link_types_table, qc);
}
void Settings_window::add_table_line(QTableWidget *table,
const char *slot,
int &row, std::string st_name, Color *c, bool checked) {
......@@ -450,108 +472,14 @@ void Settings_window::add_table_line(QTableWidget *table,
/****** Types tab. ******/
/*************************/
void Settings_window::fill_event_types_table(const string &palette_name) {
Session &S = Session::getSession();
while(event_types_table->rowCount() > 0) { // Clear the current table
event_types_table->removeRow(0);
}
int row = 0;
Palette* p=S.get_palette("event_types",palette_name);
map<string, Color *> colors = p->get_map();
if(colors.empty()/*palette_name == "default"*/) { // Loads the colors of the current trace
const map<Name, EventType* > * event_types;
if(_c->get_trace()) { // Need a trace loaded
event_types = _c->get_trace()->get_event_types();
}
else {
cerr << "no trace loaded" << endl;
return;
}
for(map<Name, EventType *>::const_iterator it = event_types->begin() ;
it != event_types->end() ; ++ it) {
Color *color = NULL;
if((*it).second->get_extra_fields()!=NULL && ((*it).second->get_extra_fields()->find(string("Color")) != (*it).second->get_extra_fields()->end())) {
color = (Color *)((*it).second->get_extra_fields()->find(string("Color"))->second);
}
add_table_line(event_types_table, SLOT(event_types_color_changed(const QColor&)),
row, (*it).first.to_string(), color, true);
}
}
else { // Look for the state/color pairs in Session.
for(map<string, Color *>::iterator it = colors.begin() ;
it != colors.end() ; ++ it) {
add_table_line(event_types_table, SLOT(event_types_color_changed(const QColor&)),
row, (*it).first, (*it).second, p->is_visible((*it).first));
}
}
}
void Settings_window::fill_link_types_table(const string &palette_name) {
Session &S = Session::getSession();
while(link_types_table->rowCount() > 0) { // Clear the current table
link_types_table->removeRow(0);
}
int row = 0;
Palette* p= S.get_palette("link_types",palette_name);
map<string, Color *> colors = p->get_map();
if(colors.empty()/*palette_name == "default"*/) { // Loads the colors of the current trace
const map<Name, LinkType* > * link_types;
if(_c->get_trace()) { // Need a trace loaded
link_types = _c->get_trace()->get_link_types();
}
else {
cerr << "no trace loaded" << endl;
return;
}
for(map<Name, LinkType *>::const_iterator it = link_types->begin() ;
it != link_types->end() ; ++ it) {
Color *color = NULL;
if((*it).second->get_extra_fields()!=NULL && ((*it).second->get_extra_fields()->find(string("Color")) != (*it).second->get_extra_fields()->end())) {
color = (Color *)((*it).second->get_extra_fields()->find(string("Color"))->second);
}
add_table_line(link_types_table, SLOT(link_types_color_changed(const QColor&)),
row, (*it).first.to_string(), color, true);
}
}
else { // Look for the state/color pairs in Session.
for(map<string, Color *>::iterator it = colors.begin() ;
it != colors.end() ; ++ it) {
add_table_line(link_types_table, SLOT(link_types_color_changed(const QColor&)),
row, (*it).first, (*it).second, p->is_visible((*it).first));
}
}
}
void Settings_window::on_event_types_palette_list_currentIndexChanged(const QString &text) {
_changed=true;
fill_event_types_table(text.toStdString());
fill_table_events(text.toStdString());
}
void Settings_window::on_link_types_palette_list_currentIndexChanged(const QString &text) {
_changed=true;
fill_link_types_table(text.toStdString());
fill_table_links(text.toStdString());
}
void Settings_window::on_reload_link_types_palette_btn_clicked() {
......@@ -617,22 +545,22 @@ void Settings_window::on_reload_event_types_palette_btn_clicked() {
void Settings_window::on_copy_link_types_palette_btn_clicked() {
QString text= copy_palette(link_types_table, link_types_palette_list, "link_types");
fill_link_types_table(text.toStdString());
fill_table_links(text.toStdString());
}
void Settings_window::on_copy_event_types_palette_btn_clicked() {
QString text= copy_palette(event_types_table, event_types_palette_list, "event_types");
fill_event_types_table(text.toStdString());
fill_table_events(text.toStdString());
}
void Settings_window::on_rm_link_types_palette_btn_clicked() {
rm_palette(link_types_palette_list, "link_types");
fill_link_types_table(link_types_palette_list->currentText().toStdString());
fill_table_links(link_types_palette_list->currentText().toStdString());
}
void Settings_window::on_rm_event_types_palette_btn_clicked() {
rm_palette(event_types_palette_list, "event_types");
fill_event_types_table(event_types_palette_list->currentText().toStdString());
fill_table_events(event_types_palette_list->currentText().toStdString());
}
......
......@@ -79,7 +79,15 @@ private:
/*!
* \brief Fill the state table with the states and theirs colors depending on the palette set.
*/
void fill_table(const std::string &palette_name);
void fill_table(QTableWidget *table,
const char *slot,
const std::string pname,
const std::string &palette_name );
void fill_table_states( const std::string &palette_name );
void fill_table_events( const std::string &palette_name );
void fill_table_links( const std::string &palette_name );
/*!
* \brief Reload the general tab.
......
......@@ -884,6 +884,56 @@ void Trace::get_states_colors(map<string, Color * > &nc_map, Container *parent)
}
}
}
void Trace::get_events_colors(map<string, Color * > &nc_map) {
map<Name, EventType *>::const_iterator it;
for(it = _event_types.begin();
it != _event_types.end() ; ++ it)
{
Color *color = NULL;
if( (it->second->get_extra_fields() != NULL) &&
(it->second->get_extra_fields()->find(string("Color")) != it->second->get_extra_fields()->end()) )
{
color = (Color *)( it->second->get_extra_fields()->find(string("Color"))->second );
}
else {
color = new Color();
}
nc_map[ it->first.get_name() ] = color;
}
}
void Trace::get_links_colors(map<string, Color * > &nc_map) {
map<Name, LinkType *>::const_iterator it;
for(it = _link_types.begin();
it != _link_types.end() ; ++ it)
{
Color *color = NULL;
if( (it->second->get_extra_fields() != NULL) &&
(it->second->get_extra_fields()->find(string("Color")) != it->second->get_extra_fields()->end()) )
{
color = (Color *)( it->second->get_extra_fields()->find(string("Color"))->second );
}
else {
color = new Color();
}
nc_map[ it->first.get_name() ] = color;
}
}
void Trace::get_colors(const string type, map<string, Color * > &nc_map) {
if (type == "palette")
get_states_colors( nc_map );
else if (type == "event_types")
get_events_colors( nc_map );
else if (type == "link_types")
get_links_colors( nc_map );
}
/* Fill name_map with the names of the state contained in sub-tree node */
void get_state_names_colors_list(map<string, Color *> &name_map, Node<StateChange> *node) {
if (!node)
......
......@@ -468,6 +468,10 @@ public :
void get_all_variables(std::map<std::string, Variable *> &map_to_fill);
void get_states_colors(std::map<std::string, Color * > &, Container *parent = NULL);
void get_events_colors(std::map<std::string, Color * > &nc_map);
void get_links_colors(std::map<std::string, Color * > &nc_map);
void get_colors(const std::string type, std::map<std::string, Color * > &nc_map);
/*!
* \fn load_config_from_xml(QString filename)
......
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