Mercurial > octave
changeset 24701:e25ace769091
don't store label in variable editor model
* variable-editor-model.h, variable-editor-model.h
(variable_editor_model::m_label): Delete data member and all uses.
(variable_editor_model::update_description): Rename from update_label.
Accept description as argument.
(variable_editor_model::make_description_text): Rename from
make_label_text.
(base_ve_model::make_description_text): Rename from make_label_text.
Change all derived classes.
(variable_editor_model::description_updated): New signal.
* variable-editor.cc (variable_editor::edit_variable): Don't pass
label to model constructor. Connect model description_updated signal
to label setText slot.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 07 Feb 2018 12:06:18 -0500 |
parents | aaf7bcea71dd |
children | 15daa0b34826 |
files | libgui/src/variable-editor-model.cc libgui/src/variable-editor-model.h libgui/src/variable-editor.cc |
diffstat | 3 files changed, 21 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/variable-editor-model.cc Wed Feb 07 11:34:13 2018 +0100 +++ b/libgui/src/variable-editor-model.cc Wed Feb 07 12:06:18 2018 -0500 @@ -272,7 +272,7 @@ } QString -base_ve_model::make_label_text (void) const +base_ve_model::make_description_text (void) const { QString lbl_txt = QString::fromStdString (m_name); @@ -626,10 +626,10 @@ return QString::fromStdString (buf.str ()); } - QString make_label_text (void) const + QString make_description_text (void) const { return (QString ("unable to edit %1") - .arg (base_ve_model::make_label_text ())); + .arg (base_ve_model::make_description_text ())); } }; @@ -873,12 +873,10 @@ variable_editor_model::variable_editor_model (const QString& expr, const octave_value& val, - QLabel *label, QObject *parent) - : QAbstractTableModel (parent), m_label (label), - rep (create (expr, val)) + : QAbstractTableModel (parent), rep (create (expr, val)) { - update_label (); + update_description (); if (is_editable ()) { @@ -1217,11 +1215,7 @@ { invalidate (); - m_label->setTextFormat (Qt::PlainText); - - m_label->setText (msg); - - dynamic_cast<QWidget *> (parent ())->setVisible (false); + update_description (msg); } void @@ -1233,7 +1227,7 @@ delete old_rep; - update_label (); + update_description (); emit set_editable_signal (is_editable ()); } @@ -1249,9 +1243,8 @@ } void -variable_editor_model::update_label (void) +variable_editor_model::update_description (const QString& description) { - m_label->setTextFormat (Qt::PlainText); - - m_label->setText (make_label_text ()); + emit description_changed (description.isEmpty () + ? make_description_text () : description); }
--- a/libgui/src/variable-editor-model.h Wed Feb 07 11:34:13 2018 +0100 +++ b/libgui/src/variable-editor-model.h Wed Feb 07 12:06:18 2018 -0500 @@ -32,8 +32,6 @@ #include "ov.h" #include "pr-flt-fmt.h" -class QLabel; - class base_ve_model { @@ -100,7 +98,7 @@ int display_columns (void) const { return m_display_cols; } - virtual QString make_label_text (void) const; + virtual QString make_description_text (void) const; void reset (const octave_value& val); @@ -136,7 +134,7 @@ public: variable_editor_model (const QString &expr, const octave_value& val, - QLabel *label, QObject *parent = nullptr); + QObject *parent = nullptr); ~variable_editor_model (void) { @@ -267,6 +265,8 @@ void set_editable_signal (bool); + void description_changed (const QString& description); + private slots: void data_error (const QString& msg); @@ -279,9 +279,6 @@ private: - // Owned by parent, stored here for convenience. - QLabel *m_label; - base_ve_model *rep; void set_data_oct (const std::string& name, const std::string& expr, @@ -318,16 +315,16 @@ return rep->display_columns (); } - QString make_label_text (void) const + QString make_description_text (void) const { - return rep->make_label_text (); + return rep->make_description_text (); } void reset (const octave_value& val); void invalidate (void); - void update_label (void); + void update_description (const QString& description = QString ()); void evaluation_error (const std::string& expr) const; };
--- a/libgui/src/variable-editor.cc Wed Feb 07 11:34:13 2018 +0100 +++ b/libgui/src/variable-editor.cc Wed Feb 07 12:06:18 2018 -0500 @@ -331,11 +331,9 @@ QLabel *label = new QLabel (page); label->setTextFormat (Qt::PlainText); - label->setText (name); vbox->addWidget (label, 0, Qt::AlignTop); - variable_editor_model *model - = new variable_editor_model (name, val, label); + variable_editor_model *model = new variable_editor_model (name, val); QTableView *edit_view = make_edit_view (page, model); @@ -352,6 +350,9 @@ m_tab_widget->setCurrentIndex (tab_idx); + connect (model, SIGNAL (description_changed (const QString&)), + label, SLOT (setText (const QString&))); + connect (model, SIGNAL (dataChanged (const QModelIndex&, const QModelIndex&)), this, SLOT (callUpdate (const QModelIndex&, const QModelIndex&)));