From: Angus Leeming Date: Tue, 17 Jun 2003 00:30:47 +0000 (+0000) Subject: Fix memory leaks in the Qt math panel. X-Git-Tag: 1.6.10~16626 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=a0aa73cf1e9a305f839e376d7d7e1ef2dd4e0c72;p=features.git Fix memory leaks in the Qt math panel. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7176 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/ChangeLog b/src/ChangeLog index 7dc0eb2d0d..486e403a02 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2003-06-17 Angus Leeming + + * lfuns.h: + * LyXAction.C (init): new LFUN_DIALOG_SHOW. + + * lyxfunc.C (dispatch): invoke it. + 2003-06-16 Jean-Marc Lasgouttes * iterators.C (operator++, ParPosition): reintroduce some diff --git a/src/LyXAction.C b/src/LyXAction.C index bf89d50509..1522ffea0f 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -313,6 +313,7 @@ void LyXAction::init() { LFUN_REJECT_CHANGE, "reject-change", Noop }, { LFUN_ACCEPT_ALL_CHANGES, "accept-all-changes", Noop }, { LFUN_REJECT_ALL_CHANGES, "reject-all-changes", Noop }, + { LFUN_DIALOG_SHOW, "dialog-show", Noop }, { LFUN_DIALOG_SHOW_NEW_INSET, "dialog-show-new-inset", Noop }, { LFUN_DIALOG_SHOW_NEXT_INSET, "dialog-show-next-inset", Noop }, { LFUN_DIALOG_UPDATE, "dialog-update", Noop }, diff --git a/src/frontends/Dialogs.C b/src/frontends/Dialogs.C index 82cac2cb64..08dfde0335 100644 --- a/src/frontends/Dialogs.C +++ b/src/frontends/Dialogs.C @@ -95,6 +95,7 @@ void Dialogs::show(string const & name, string const & data) if (!dialog) return; + // FIXME! Should check that the dialog is NOT an inset dialog. dialog->show(data); } @@ -105,6 +106,7 @@ void Dialogs::show(string const & name, string const & data, InsetBase * inset) if (!dialog) return; + // FIXME! Should check that the dialog IS an inset dialog. dialog->show(data); open_insets_[name] = inset; } diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index c29b44a7c7..25c821bf04 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,7 @@ +2003-06-17 Angus Leeming + + * ControlMath2.[Ch] (showDialog): new member function. + 2003-06-12 Angus Leeming * ControlMath2.[Ch]: new files. A work in progress towards a clean diff --git a/src/frontends/controllers/ControlMath2.C b/src/frontends/controllers/ControlMath2.C index a51b5d23bf..4552d7851a 100644 --- a/src/frontends/controllers/ControlMath2.C +++ b/src/frontends/controllers/ControlMath2.C @@ -63,3 +63,9 @@ void ControlMath2::dispatchToggleDisplay() const kernel().dispatch(FuncRequest(LFUN_MATH_DISPLAY)); } + +void ControlMath2::showDialog(string const & name) const +{ + kernel().dispatch(FuncRequest(LFUN_DIALOG_SHOW, name)); +} + diff --git a/src/frontends/controllers/ControlMath2.h b/src/frontends/controllers/ControlMath2.h index 93455cd71a..d493d0b5b4 100644 --- a/src/frontends/controllers/ControlMath2.h +++ b/src/frontends/controllers/ControlMath2.h @@ -41,6 +41,8 @@ public: void dispatchDelim(string const & str) const; /// switch between display and inline void dispatchToggleDisplay() const; + /// a request to launch dialog \param name. + void showDialog(string const & name) const; }; diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 01f7ea0243..a27a0947f7 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,14 @@ +2003-06-17 Angus Leeming + + * Dialogs.C (build): create "mathdelimiter" and "mathmatrix" dialogs. + + * QMath.[Ch]: add QMathMatrix and QMathDelimiter classes. + + * QDelimiterDialog.[Ch]: store a QMathDelimiter*, not a QMath*. + * QMathMatrixDialog.[Ch]: store a QMathMatrix*, not a QMath*. + + * QMathDialog.C (delimiterClicked, matrixClicked): fix memory leaks. + 2003-06-14 John Levon * ui/QPrintDialogBase.ui: make "OK" default diff --git a/src/frontends/qt2/Dialogs.C b/src/frontends/qt2/Dialogs.C index dfe4cd6ca9..4c75aff7f4 100644 --- a/src/frontends/qt2/Dialogs.C +++ b/src/frontends/qt2/Dialogs.C @@ -82,8 +82,9 @@ namespace { char const * const dialognames[] = { "about", "bibitem", "bibtex", "changes", "character", "citation", "error", "errorlist", "ert", "external", "file", -"float", "graphics", "include", "index", "label", "log", "math", "minipage", -"paragraph", "ref", "tabular", "tabularcreate", +"float", "graphics", "include", "index", "label", "log", +"math", "mathdelimiter", "mathmatrix", +"minipage", "paragraph", "ref", "tabular", "tabularcreate", #ifdef HAVE_LIBAIKSAURUS "thesaurus", @@ -198,6 +199,14 @@ Dialog * Dialogs::build(string const & name) dialog->setController(new ControlMath2(*dialog)); dialog->setView(new QMath(*dialog)); dialog->bc().bp(new IgnorantPolicy); + } else if (name == "mathdelimiter") { + dialog->setController(new ControlMath2(*dialog)); + dialog->setView(new QMathDelimiter(*dialog)); + dialog->bc().bp(new IgnorantPolicy); + } else if (name == "mathmatrix") { + dialog->setController(new ControlMath2(*dialog)); + dialog->setView(new QMathMatrix(*dialog)); + dialog->bc().bp(new IgnorantPolicy); } else if (name == "minipage") { dialog->setController(new ControlMinipage(*dialog)); dialog->setView(new QMinipage(*dialog)); diff --git a/src/frontends/qt2/QDelimiterDialog.C b/src/frontends/qt2/QDelimiterDialog.C index a328eccf4d..c2a50029fd 100644 --- a/src/frontends/qt2/QDelimiterDialog.C +++ b/src/frontends/qt2/QDelimiterDialog.C @@ -71,7 +71,7 @@ string fix_name(string const & str) } // namespace anon -QDelimiterDialog::QDelimiterDialog(QMath * form) +QDelimiterDialog::QDelimiterDialog(QMathDelimiter * form) : QDelimiterDialogBase(0, 0, false, 0), form_(form) { diff --git a/src/frontends/qt2/QDelimiterDialog.h b/src/frontends/qt2/QDelimiterDialog.h index b881635d4b..1953c0539c 100644 --- a/src/frontends/qt2/QDelimiterDialog.h +++ b/src/frontends/qt2/QDelimiterDialog.h @@ -16,14 +16,14 @@ #include "ui/QDelimiterDialogBase.h" #include "LString.h" -class QMath; +class QMathDelimiter; class IconPalette; class QLabel; class QDelimiterDialog : public QDelimiterDialogBase { Q_OBJECT public: - QDelimiterDialog(QMath * form); + QDelimiterDialog(QMathDelimiter * form); public slots: void ldelim_clicked(const string & str); void rdelim_clicked(const string & str); @@ -40,7 +40,7 @@ private: string right_; /// owning form - QMath * form_; + QMathDelimiter * form_; }; #endif // QDELIMITERDIALOG_H diff --git a/src/frontends/qt2/QMath.C b/src/frontends/qt2/QMath.C index f716081ced..28d55c980b 100644 --- a/src/frontends/qt2/QMath.C +++ b/src/frontends/qt2/QMath.C @@ -14,14 +14,16 @@ #include "gettext.h" #include "ControlMath2.h" #include "QMathDialog.h" +#include "QMathMatrixDialog.h" +#include "QDelimiterDialog.h" #include "QMath.h" -typedef QController > base_class; +typedef QController > math_base; QMath::QMath(Dialog & parent) - : base_class(parent, _("LyX: Math Panel")) + : math_base(parent, _("LyX: Math Panel")) {} @@ -29,3 +31,31 @@ void QMath::build_dialog() { dialog_.reset(new QMathDialog(this)); } + + +typedef QController > matrix_base; + + +QMathMatrix::QMathMatrix(Dialog & parent) + : matrix_base(parent, _("LyX: Insert Matrix")) +{} + + +void QMathMatrix::build_dialog() +{ + dialog_.reset(new QMathMatrixDialog(this)); +} + + +typedef QController > delimiter_base; + + +QMathDelimiter::QMathDelimiter(Dialog & parent) + : delimiter_base(parent, _("LyX: Insert Delimiter")) +{} + + +void QMathDelimiter::build_dialog() +{ + dialog_.reset(new QDelimiterDialog(this)); +} diff --git a/src/frontends/qt2/QMath.h b/src/frontends/qt2/QMath.h index 6b2a3dcf86..f6a467cddf 100644 --- a/src/frontends/qt2/QMath.h +++ b/src/frontends/qt2/QMath.h @@ -17,6 +17,8 @@ class ControlMath2; class QMathDialog; +class QMathMatrixDialog; +class QDelimiterDialog; class QMath : public QController > { public: @@ -31,4 +33,32 @@ private: virtual void build_dialog(); }; + +class QMathMatrix : public QController > { +public: + friend class QMathMatrixDialog; + + QMathMatrix(Dialog &); + +private: + virtual void apply() {} + virtual void update_contents() {} + /// Build the dialog. + virtual void build_dialog(); +}; + + +class QMathDelimiter : public QController > { +public: + friend class QDelimiterDialog; + + QMathDelimiter(Dialog &); + +private: + virtual void apply() {} + virtual void update_contents() {} + /// Build the dialog. + virtual void build_dialog(); +}; + #endif // QMATH_H diff --git a/src/frontends/qt2/QMathDialog.C b/src/frontends/qt2/QMathDialog.C index e8df28acac..fd25ec4b3b 100644 --- a/src/frontends/qt2/QMathDialog.C +++ b/src/frontends/qt2/QMathDialog.C @@ -21,8 +21,6 @@ #include "QMath.h" #include "iconpalette.h" -#include "QDelimiterDialog.h" -#include "QMathMatrixDialog.h" #include #include @@ -208,9 +206,7 @@ void QMathDialog::fracClicked() void QMathDialog::delimiterClicked() { - // FIXME: leak - QDelimiterDialog * d = new QDelimiterDialog(form_); - d->show(); + form_->controller().showDialog("mathdelimiter"); } @@ -235,9 +231,7 @@ void QMathDialog::functionSelected(const QString & str) void QMathDialog::matrixClicked() { - // FIXME: leak? - QMathMatrixDialog * d = new QMathMatrixDialog(form_); - d->show(); + form_->controller().showDialog("mathmatrix"); } diff --git a/src/frontends/qt2/QMathMatrixDialog.C b/src/frontends/qt2/QMathMatrixDialog.C index 75488a5650..8a2c54658d 100644 --- a/src/frontends/qt2/QMathMatrixDialog.C +++ b/src/frontends/qt2/QMathMatrixDialog.C @@ -31,7 +31,7 @@ static char h_align_str[80] = "c"; static char v_align_c[] = "tcb"; -QMathMatrixDialog::QMathMatrixDialog(QMath * form) +QMathMatrixDialog::QMathMatrixDialog(QMathMatrix * form) : QMathMatrixDialogBase(0, 0, false, 0), form_(form) { diff --git a/src/frontends/qt2/QMathMatrixDialog.h b/src/frontends/qt2/QMathMatrixDialog.h index e5a9cb3179..262a6fe708 100644 --- a/src/frontends/qt2/QMathMatrixDialog.h +++ b/src/frontends/qt2/QMathMatrixDialog.h @@ -17,12 +17,12 @@ #include "ui/QMathMatrixDialogBase.h" -class QMath; +class QMathMatrix; class QMathMatrixDialog : public QMathMatrixDialogBase { Q_OBJECT public: - QMathMatrixDialog(QMath * form); + QMathMatrixDialog(QMathMatrix * form); public slots: void slotOK(); void slotClose(); @@ -31,7 +31,7 @@ protected slots: virtual void rowsChanged(int); virtual void change_adaptor(); private: - QMath * form_; + QMathMatrix * form_; }; #endif // QMATHMATRIXDIALOG_H diff --git a/src/lfuns.h b/src/lfuns.h index 14dcb4be1a..a0f1cc1241 100644 --- a/src/lfuns.h +++ b/src/lfuns.h @@ -321,18 +321,19 @@ enum kb_action { LFUN_REJECT_ALL_CHANGES, // Levon 20021016 LFUN_INSERT_BIBITEM, // André 14 Feb 2003 // 245 + LFUN_DIALOG_SHOW, LFUN_DIALOG_SHOW_NEW_INSET, LFUN_DIALOG_SHOW_NEXT_INSET, LFUN_DIALOG_UPDATE, LFUN_DIALOG_HIDE, - LFUN_DIALOG_DISCONNECT_INSET, // 250 + LFUN_DIALOG_DISCONNECT_INSET, LFUN_INSET_APPLY, LFUN_INSET_INSERT, LFUN_INSET_MODIFY, LFUN_INSET_DIALOG_UPDATE, - LFUN_INSET_SETTINGS, // 255 + LFUN_INSET_SETTINGS, LFUN_PARAGRAPH_APPLY, LFUN_PARAGRAPH_UPDATE, LFUN_EXTERNAL_EDIT, diff --git a/src/lyxfunc.C b/src/lyxfunc.C index bf551cd8b5..c97fa8bc82 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -1408,6 +1408,10 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose) owner->getDialogs().showMathPanel(); break; + case LFUN_DIALOG_SHOW: + owner->getDialogs().show(argument); + break; + case LFUN_DIALOG_SHOW_NEW_INSET: { string const & name = argument; string data;