# HG changeset patch # User Torsten # Date 1505001396 -7200 # Node ID ca4ab27152a9af04c42f99c68ea76155ea91d43d # Parent fbdefffeaa2134c447dcaec8f6988e41efff148b variable editor: remove & when reading names from tabs (bugs #51851, #51905) * variable-editor.cc (real_var_name): reading tab text and removing any & that might have been inserted by KDE; (edit_variable, selected_to_octave, double_click, save, transposeContent, up): use new function instead of reading the tab text directly as variable name * variable-editor.h: new function real_var_name diff -r fbdefffeaa21 -r ca4ab27152a9 libgui/src/variable-editor.cc --- a/libgui/src/variable-editor.cc Fri Sep 08 16:02:35 2017 -0700 +++ b/libgui/src/variable-editor.cc Sun Sep 10 01:56:36 2017 +0200 @@ -133,6 +133,16 @@ delete m_main; } +// Returns the real variable name from the tab addressed by 'index' +// cleaned from '&' possible inserted by KDE +QString +variable_editor::real_var_name (int index) +{ + QString var_name = m_tab_widget->tabText (index); + var_name.remove (QChar ('&')); + return var_name; +} + void variable_editor::edit_variable (const QString& name) { @@ -144,7 +154,7 @@ const int tab_count = m_tab_widget->count (); for (int i = 0; i < tab_count; ++i) - if (m_tab_widget->tabText (i) == name) + if (real_var_name (i) == name) { m_tab_widget->setCurrentIndex (i); return; // already open @@ -695,7 +705,7 @@ void variable_editor::double_click (const QModelIndex& idx) { - QString name = m_tab_widget->tabText (m_tab_widget->currentIndex ()); + QString name = real_var_name (m_tab_widget->currentIndex ()); QTableView *const table = get_table_data (m_tab_widget).m_table; variable_editor_model *const model = qobject_cast (table->model ()); @@ -719,7 +729,7 @@ void variable_editor::save (void) { - QString name = m_tab_widget->tabText (m_tab_widget->currentIndex ()); + QString name = real_var_name (m_tab_widget->currentIndex ()); QString file = QFileDialog::getSaveFileName (this, tr ("Save Variable %1 As").arg (name), @@ -920,7 +930,7 @@ void variable_editor::transposeContent (void) { - QString name = m_tab_widget->tabText (m_tab_widget->currentIndex ()); + QString name = real_var_name (m_tab_widget->currentIndex ()); emit command_requested (QString ("%1 = %1';").arg (name)); emit updated (); } @@ -928,7 +938,7 @@ void variable_editor::up (void) { - QString name = m_tab_widget->tabText (m_tab_widget->currentIndex ()); + QString name = real_var_name (m_tab_widget->currentIndex ()); // FIXME: is there a better way? if (name.endsWith (')') || name.endsWith ('}')) { @@ -1035,7 +1045,7 @@ QString variable_editor::selected_to_octave (void) { - QString name = m_tab_widget->tabText (m_tab_widget->currentIndex ()); + QString name = real_var_name (m_tab_widget->currentIndex ()); QTableView *view = get_table_data (m_tab_widget).m_table; QItemSelectionModel *sel = view->selectionModel (); diff -r fbdefffeaa21 -r ca4ab27152a9 libgui/src/variable-editor.h --- a/libgui/src/variable-editor.h Fri Sep 08 16:02:35 2017 -0700 +++ b/libgui/src/variable-editor.h Sun Sep 10 01:56:36 2017 +0200 @@ -123,6 +123,9 @@ QList octave_to_coords (QString&); + // Get the real variable name from the tab text + QString real_var_name (int index); + // Convert selection to an Octave expression. QString selected_to_octave (void);