Commit 760629d5 authored by Mathieu Faverge's avatar Mathieu Faverge

Finish to cleanup the code factoring in settings_window

parent 5b1e78a4
......@@ -193,7 +193,6 @@ public:
static const int _MAX_NB_RECENT_FILES = 10;
static void save_config_file();
static void load_config_file();
/*!
......
......@@ -631,8 +631,7 @@ void Interface_graphic::on_reload_triggered() {
if(_is_rendering_trace) {
Element_pos zoom[2]={Info::Splitter::_x_min,Info::Splitter::_x_max};
if(_ui_settings != NULL){
//_ui_settings->updateTrace( _core->get_trace() );
//_ui_settings->on_apply_clicked();
_ui_settings->refresh();
}
if(_ui_node_selection!=NULL)
_ui_node_selection->on_reset_button_clicked();
......@@ -1244,5 +1243,3 @@ void Interface_graphic::update_settings() {
_core->launch_action(Core::_STATE_RENDER_UPDATE);
}
......@@ -159,22 +159,7 @@ Settings_tab::Settings_tab(Core *core, std::string ecname)
background->addWidget(content);
background->addLayout(footer);
// Initialize the parameters of the tab
{
Session &S = Session::getSession();
QStringList palettes;
string current;
S.get_palettes_name( _ecname, palettes );
current = S.get_current_palette( _ecname );
list_palette->clear();
list_palette->addItems(palettes);
// Set the combobox at the good index.
list_palette->setCurrentIndex(list_palette->findText(QString::fromStdString(current)));
fill_table();
}
refresh();
QMetaObject::connectSlotsByName(this);
}
......@@ -197,78 +182,46 @@ Settings_tab::~Settings_tab()
}
void
Settings_tab::color_changed(const QColor &qc, int row)
Settings_tab::refresh()
{
_changed = true;
if( !content || !list_palette)
return;
Color color(qc.red()/255., qc.green()/255., qc.blue()/255.);
if (row == -1) {
// Find the row of the colorPicker
row = 0;
while(content->cellWidget(row, 1) &&
content->cellWidget(row, 1) != sender()) {
row ++;
}
}
if(!content->cellWidget(row, 1))
return; // epic fail...
std::string palette_name = list_palette->currentText().toStdString();
std::string ev_name = content->item(row, 0)->text().toStdString();
std::string ev_alias = content->item(row, 3)->text().toStdString();
Session &S = Session::getSession();
Palette *p = S.get_palette(_ecname, palette_name);
// Initialize the parameters of the tab
Session &S = Session::getSession();
QStringList palettes;
string current;
// Get the former color
// Quick and dirty patch
Color *old = p->get_color(ev_name);
if ( old == NULL ) {
old = new Color(1, 1, 1);
}
QColor q(old->get_red()*255, old->get_green()*255, old->get_blue()*255);
S.get_palettes_name( _ecname, palettes );
current = S.get_current_palette( _ecname );
// Get the check status
bool checked = qobject_cast<QCheckBox *>(content->cellWidget(row, 2))->checkState()== Qt::Checked;
list_palette->clear();
list_palette->addItems(palettes);
// Set the combobox at the good index.
list_palette->setCurrentIndex(list_palette->findText(QString::fromStdString(current)));
// If the state has not already been changed, we register it
if( _changes.count(ev_alias) == 0 ) {
_changes[ev_alias] = row;
}
return;
fill_table();
}
void
Settings_tab::visible_changed(const int checked, int row)
Settings_tab::item_changed(int row)
{
_changed = true;
if( !content || !list_palette )
if( !content || !list_palette)
return;
if (row == -1) {
// Find the row of the checkBox
// Find the row of the colorPicker
row = 0;
while(content->cellWidget(row, 2) &&
content->cellWidget(row, 2) != sender()) {
while(content->cellWidget(row, 1) &&
content->cellWidget(row, 1) != sender()) {
row ++;
}
}
if(!content->cellWidget(row, 2))
if(!content->cellWidget(row, 1))
return; // epic fail...
std::string ev_alias = content->item(row, 3)->text().toStdString();
// Get the color
QColor qc = qobject_cast<QtColorPicker *>(content->cellWidget(row, 1))->currentColor();
Color color(qc.red()/255, qc.green()/255, qc.blue()/255);
// If the state has not already been changed, we register it
if( _changes.count(ev_alias) == 0 ) {
_changes[ev_alias] = row;
......@@ -302,13 +255,13 @@ Settings_tab::add_table_line(int &row,
color_widget->setCurrentColor(qc);
color_widget->setColorDialogEnabled(false);
connect(color_widget, SIGNAL(colorChanged(const QColor &)),
this, SLOT(color_changed(const QColor &)) );
this, SLOT(item_changed()) );
/* Visible */
QCheckBox *cb = new QCheckBox();
cb->setChecked( ev->get_visible() );
connect(cb, SIGNAL(stateChanged(int)),
this, SLOT(visible_changed(int)));
this, SLOT(item_changed()));
/* Set the row */
content->insertRow(row);
......@@ -319,14 +272,13 @@ Settings_tab::add_table_line(int &row,
// If we reload from file, backup the changes
if( !used ) {
if (c != ev->get_used_color()) {
color_changed( qc, row );
}
if (!ev->get_visible()) {
visible_changed( true, row );
// Change the color test
if ( (c != ev->get_used_color()) ||
(!ev->get_visible()) )
{
item_changed( row );
}
}
row ++;
}
......@@ -360,10 +312,43 @@ Settings_tab::fill_table( bool used )
}
}
void
Settings_tab::update_table_from_palette( string pname )
{
Session &S = Session::getSession();
Palette *p = S.get_palette(_ecname, pname);
map<string, EntityValue*> *ev_list;
map<string, EntityValue*>::const_iterator ev;
int rownbr = content->rowCount();
for( int i=0; i < rownbr; i++ ) {
string ev_name = content->item(i, 0)->text().toStdString();
string ev_alias = content->item(i, 3)->text().toStdString();
Color *c = p->get_color( ev_name );
if ( c != NULL ) {
_changed = true;
bool v = p->is_visible( ev_name );
QtColorPicker *color_widget = qobject_cast<QtColorPicker *>(content->cellWidget(i, 1));
color_widget->setCurrentColor(QColor(c->get_red() *255,
c->get_green()*255,
c->get_blue() *255));
QCheckBox *cb = qobject_cast<QCheckBox *>(content->cellWidget(i, 2));
cb->setCheckState( v ? Qt::Checked : Qt::Unchecked );
_changes[ev_alias] = i;
}
}
}
void
Settings_tab::on_list_palette_currentIndexChanged(const QString & text)
{
//fill_table_from_palette( text.toStdString() );
update_table_from_palette( text.toStdString() );
}
void
......@@ -423,8 +408,7 @@ Settings_tab::on_btn_palette_rm_clicked()
assert(index != -1);
list_palette->setCurrentIndex( index );
// TODO: Switch to default
//fill_table_from_palette( "Default" );
update_table_from_palette( "Default" );
}
}
......@@ -513,7 +497,6 @@ void
Settings_tab::on_btn_reload_clicked()
{
fill_table(false);
on_btn_apply_clicked();
}
Settings_window::Settings_window(Core *c, QWidget *parent)
......@@ -548,8 +531,17 @@ void Settings_window::on_tabWidget_currentChanged(int ) {
}
void
Settings_window::refresh()
{
_tab_states->refresh();
_tab_events->refresh();
_tab_links ->refresh();
}
void Settings_window::show() {
// The plugin tab
refresh();
dir_list->clear();
plugin_load_dirs_name();
reload_minimap_tab();
......@@ -641,6 +633,10 @@ void Settings_window::plugin_load_dirs_name() {
void
Settings_window::on_btn_ok_clicked()
{
_tab_states->on_btn_apply_clicked();
_tab_events->on_btn_apply_clicked();
_tab_links ->on_btn_apply_clicked();
if( _changed ) {
//on_apply_clicked();
// Catch by at least the interface_graphic which will dispatch it to the classes which needs
......@@ -654,6 +650,10 @@ Settings_window::on_btn_ok_clicked()
void
Settings_window::on_btn_cancel_clicked()
{
_tab_states->on_btn_cancel_clicked();
_tab_events->on_btn_cancel_clicked();
_tab_links ->on_btn_cancel_clicked();
hide();
}
......@@ -668,13 +668,12 @@ Settings_window::on_cb_tip_currentIndexChanged(int index)
void
Settings_window::on_cb_nolinks_stateChanged(int index)
{
Info::Render::_arrows_shape = index;
//_core->launch_action(Core::_STATE_RENDER_UPDATE);
}
void
Settings_window::on_cb_noevents_stateChanged(int index)
{
Info::Render::_arrows_shape = index;
//_core->launch_action(Core::_STATE_RENDER_UPDATE);
}
......@@ -99,37 +99,30 @@ public:
~Settings_tab();
void refresh();
void updateTrace();
private:
void add_table_line( int &row,
EntityValue *ev,
bool used );
void fill_table( bool used=true );
void fill_table_from_palette( std::string );
void update_table_from_palette( std::string );
private slots:
public slots:
void on_btn_apply_clicked();
void on_btn_cancel_clicked();
/*!
* \fn color_changed(const QColor &c)
* \brief Slot called when the user changes an object color in the table.
* \param c : the new color
*/
void color_changed(const QColor &c, int row = -1);
private slots:
/*!
* \fn visible_changed(const QColor &c)
* \brief Slot called when the user changes the visible state of an object
* in the table.
* \param c : the new color
* \fn item_changed(int row = -1)
* \brief Slot called when the user changes an object color, or the
* visibility in the table.
*/
void visible_changed(const int checked, int row = -1);
void item_changed(int row = -1);
void on_list_palette_currentIndexChanged(const QString &text);
void on_btn_palette_cp_clicked();
void on_btn_palette_rm_clicked();
void on_btn_apply_clicked();
void on_btn_cancel_clicked();
void on_btn_reload_clicked();
};
......@@ -175,6 +168,7 @@ public:
* (to get them back if we cancel for example)
*/
void show();
void refresh();
public slots:
/*!
......
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