From 26b2cc89d398f9125706901ff3251e15926aea50 Mon Sep 17 00:00:00 2001 From: Guillaume Munch Date: Sun, 26 Feb 2017 22:15:49 +0100 Subject: [PATCH] Fix 18 memory leaks Also whitespace. --- src/frontends/qt4/GuiCitation.cpp | 8 +-- src/frontends/qt4/GuiCitation.h | 2 - src/frontends/qt4/GuiDocument.cpp | 81 ++++++++++++----------- src/frontends/qt4/GuiDocument.h | 7 +- src/frontends/qt4/GuiSelectionManager.cpp | 58 ++++++++-------- src/frontends/qt4/GuiSelectionManager.h | 36 +++++----- 6 files changed, 95 insertions(+), 97 deletions(-) diff --git a/src/frontends/qt4/GuiCitation.cpp b/src/frontends/qt4/GuiCitation.cpp index e2b5aa9d6c..ee125e43d2 100644 --- a/src/frontends/qt4/GuiCitation.cpp +++ b/src/frontends/qt4/GuiCitation.cpp @@ -140,7 +140,7 @@ GuiCitation::GuiCitation(GuiView & lv) connect(textAfterED, SIGNAL(returnPressed()), this, SLOT(on_okPB_clicked())); - selectionManager = new GuiSelectionManager(availableLV, selectedLV, + selectionManager = new GuiSelectionManager(this, availableLV, selectedLV, addPB, deletePB, upPB, downPB, &available_model_, &selected_model_, 1); connect(selectionManager, SIGNAL(selectionChanged()), this, SLOT(setCitedKeys())); @@ -172,12 +172,6 @@ GuiCitation::GuiCitation(GuiView & lv) } -GuiCitation::~GuiCitation() -{ - delete selectionManager; -} - - void GuiCitation::closeEvent(QCloseEvent * e) { clearSelection(); diff --git a/src/frontends/qt4/GuiCitation.h b/src/frontends/qt4/GuiCitation.h index 2fa4369105..6648141fc1 100644 --- a/src/frontends/qt4/GuiCitation.h +++ b/src/frontends/qt4/GuiCitation.h @@ -44,8 +44,6 @@ class GuiCitation : public DialogView, public Ui::CitationUi public: /// GuiCitation(GuiView & lv); - /// - ~GuiCitation(); private Q_SLOTS: void on_okPB_clicked(); diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 448943e45c..2293ce3acf 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -251,18 +251,19 @@ class ModuleSelectionManager : public GuiSelectionManager { public: /// - ModuleSelectionManager( - QTreeView * availableLV, - QListView * selectedLV, - QPushButton * addPB, - QPushButton * delPB, - QPushButton * upPB, - QPushButton * downPB, - GuiIdListModel * availableModel, - GuiIdListModel * selectedModel, - GuiDocument const * container) - : GuiSelectionManager(availableLV, selectedLV, addPB, delPB, - upPB, downPB, availableModel, selectedModel), container_(container) + ModuleSelectionManager(QObject * parent, + QTreeView * availableLV, + QListView * selectedLV, + QPushButton * addPB, + QPushButton * delPB, + QPushButton * upPB, + QPushButton * downPB, + GuiIdListModel * availableModel, + GuiIdListModel * selectedModel, + GuiDocument const * container) + : GuiSelectionManager(parent, availableLV, selectedLV, addPB, delPB, + upPB, downPB, availableModel, selectedModel), + container_(container) {} /// void updateProvidedModules(LayoutModuleList const & pm) @@ -451,7 +452,8 @@ void ModuleSelectionManager::updateDelPB() // ///////////////////////////////////////////////////////////////////// -PreambleModule::PreambleModule() : current_id_(0) +PreambleModule::PreambleModule(QWidget * parent) + : UiWidget(parent), current_id_(0) { // This is not a memory leak. The object will be destroyed // with this. @@ -517,7 +519,8 @@ void PreambleModule::closeEvent(QCloseEvent * e) ///////////////////////////////////////////////////////////////////// -LocalLayout::LocalLayout() : current_id_(0), validated_(false) +LocalLayout::LocalLayout(QWidget * parent) + : UiWidget(parent), current_id_(0), validated_(false) { connect(locallayoutTE, SIGNAL(textChanged()), this, SLOT(textChanged())); connect(validatePB, SIGNAL(clicked()), this, SLOT(validatePressed())); @@ -676,7 +679,7 @@ GuiDocument::GuiDocument(GuiView & lv) // text layout - textLayoutModule = new UiWidget; + textLayoutModule = new UiWidget(this); connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor())); connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)), @@ -749,7 +752,7 @@ GuiDocument::GuiDocument(GuiView & lv) // master/child handling - masterChildModule = new UiWidget; + masterChildModule = new UiWidget(this); connect(masterChildModule->childrenTW, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(includeonlyClicked(QTreeWidgetItem *, int))); @@ -771,7 +774,7 @@ GuiDocument::GuiDocument(GuiView & lv) // Formats - outputModule = new UiWidget; + outputModule = new UiWidget(this); connect(outputModule->defaultFormatCO, SIGNAL(activated(int)), this, SLOT(change_adaptor())); @@ -800,7 +803,7 @@ GuiDocument::GuiDocument(GuiView & lv) this, SLOT(change_adaptor())); // fonts - fontModule = new FontModule; + fontModule = new FontModule(this); connect(fontModule->osFontsCB, SIGNAL(clicked()), this, SLOT(change_adaptor())); connect(fontModule->osFontsCB, SIGNAL(toggled(bool)), @@ -875,7 +878,7 @@ GuiDocument::GuiDocument(GuiView & lv) // page layout - pageLayoutModule = new UiWidget; + pageLayoutModule = new UiWidget(this); connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(papersizeChanged(int))); connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), @@ -955,7 +958,7 @@ GuiDocument::GuiDocument(GuiView & lv) // margins - marginsModule = new UiWidget; + marginsModule = new UiWidget(this); connect(marginsModule->marginCB, SIGNAL(toggled(bool)), this, SLOT(setCustomMargins(bool))); connect(marginsModule->marginCB, SIGNAL(clicked()), @@ -1028,7 +1031,7 @@ GuiDocument::GuiDocument(GuiView & lv) // language & quote - langModule = new UiWidget; + langModule = new UiWidget(this); connect(langModule->languageCO, SIGNAL(activated(int)), this, SLOT(change_adaptor())); connect(langModule->languageCO, SIGNAL(activated(int)), @@ -1083,7 +1086,7 @@ GuiDocument::GuiDocument(GuiView & lv) // color - colorModule = new UiWidget; + colorModule = new UiWidget(this); connect(colorModule->fontColorPB, SIGNAL(clicked()), this, SLOT(changeFontColor())); connect(colorModule->delFontColorTB, SIGNAL(clicked()), @@ -1103,7 +1106,7 @@ GuiDocument::GuiDocument(GuiView & lv) // numbering - numberingModule = new UiWidget; + numberingModule = new UiWidget(this); connect(numberingModule->depthSL, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor())); connect(numberingModule->tocSL, SIGNAL(valueChanged(int)), @@ -1119,7 +1122,7 @@ GuiDocument::GuiDocument(GuiView & lv) setSectionResizeMode(numberingModule->tocTW->header(), QHeaderView::ResizeToContents); // biblio - biblioModule = new UiWidget; + biblioModule = new UiWidget(this); connect(biblioModule->citeEngineCO, SIGNAL(activated(int)), this, SLOT(citeEngineChanged(int))); connect(biblioModule->citeStyleCO, SIGNAL(activated(int)), @@ -1189,7 +1192,7 @@ GuiDocument::GuiDocument(GuiView & lv) // maths - mathsModule = new UiWidget; + mathsModule = new UiWidget(this); QStringList headers; headers << qt_("Package") << qt_("Load automatically") << qt_("Load always") << qt_("Do not load"); @@ -1257,7 +1260,7 @@ GuiDocument::GuiDocument(GuiView & lv) // latex class - latexModule = new UiWidget; + latexModule = new UiWidget(this); connect(latexModule->optionsLE, SIGNAL(textChanged(QString)), this, SLOT(change_adaptor())); connect(latexModule->defaultOptionsCB, SIGNAL(clicked()), @@ -1322,7 +1325,7 @@ GuiDocument::GuiDocument(GuiView & lv) // branches - branchesModule = new GuiBranches; + branchesModule = new GuiBranches(this); connect(branchesModule, SIGNAL(changed()), this, SLOT(change_adaptor())); connect(branchesModule, SIGNAL(renameBranches(docstring const &, docstring const &)), @@ -1332,32 +1335,34 @@ GuiDocument::GuiDocument(GuiView & lv) // preamble - preambleModule = new PreambleModule; + preambleModule = new PreambleModule(this); connect(preambleModule, SIGNAL(changed()), this, SLOT(change_adaptor())); - localLayout = new LocalLayout; + localLayout = new LocalLayout(this); connect(localLayout, SIGNAL(changed()), this, SLOT(change_adaptor())); // bullets - bulletsModule = new BulletsModule; + bulletsModule = new BulletsModule(this); connect(bulletsModule, SIGNAL(changed()), this, SLOT(change_adaptor())); // Modules - modulesModule = new UiWidget; + modulesModule = new UiWidget(this); modulesModule->availableLV->header()->setVisible(false); setSectionResizeMode(modulesModule->availableLV->header(), QHeaderView::ResizeToContents); modulesModule->availableLV->header()->setStretchLastSection(false); selectionManager = - new ModuleSelectionManager(modulesModule->availableLV, - modulesModule->selectedLV, - modulesModule->addPB, modulesModule->deletePB, - modulesModule->upPB, modulesModule->downPB, - availableModel(), selectedModel(), this); + new ModuleSelectionManager(this, modulesModule->availableLV, + modulesModule->selectedLV, + modulesModule->addPB, + modulesModule->deletePB, + modulesModule->upPB, + modulesModule->downPB, + availableModel(), selectedModel(), this); connect(selectionManager, SIGNAL(updateHook()), this, SLOT(updateModuleInfo())); connect(selectionManager, SIGNAL(selectionChanged()), @@ -1365,7 +1370,7 @@ GuiDocument::GuiDocument(GuiView & lv) // PDF support - pdfSupportModule = new UiWidget; + pdfSupportModule = new UiWidget(this); connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor())); connect(pdfSupportModule->titleLE, SIGNAL(textChanged(QString)), @@ -1421,7 +1426,7 @@ GuiDocument::GuiDocument(GuiView & lv) // listings - listingsModule = new UiWidget; + listingsModule = new UiWidget(this); connect(listingsModule->listingsED, SIGNAL(textChanged()), this, SLOT(change_adaptor())); connect(listingsModule->bypassCB, SIGNAL(clicked()), diff --git a/src/frontends/qt4/GuiDocument.h b/src/frontends/qt4/GuiDocument.h index 593a67a3d7..38f099a1ab 100644 --- a/src/frontends/qt4/GuiDocument.h +++ b/src/frontends/qt4/GuiDocument.h @@ -61,7 +61,7 @@ template class UiWidget : public QWidget, public UI { public: - UiWidget(QWidget * parent = 0) : QWidget(parent) { UI::setupUi(this); } + UiWidget(QWidget * parent) : QWidget(parent) { UI::setupUi(this); } }; @@ -306,7 +306,7 @@ class PreambleModule : public UiWidget { Q_OBJECT public: - PreambleModule(); + PreambleModule(QWidget * parent); void update(BufferParams const & params, BufferId id); void apply(BufferParams & params); @@ -329,7 +329,7 @@ class LocalLayout : public UiWidget { Q_OBJECT public: - LocalLayout(); + LocalLayout(QWidget * parent); void update(BufferParams const & params, BufferId id); void apply(BufferParams & params); bool isValid() const { return validated_; } @@ -357,6 +357,7 @@ class FontModule : public UiWidget { Q_OBJECT public: + FontModule(QWidget * parent) : UiWidget(parent) {} /// The roman font currently not selected by osFontsCB->isChecked() QString font_roman; /// The sans font currently not selected by osFontsCB->isChecked() diff --git a/src/frontends/qt4/GuiSelectionManager.cpp b/src/frontends/qt4/GuiSelectionManager.cpp index b90d0ea135..90f90731c5 100644 --- a/src/frontends/qt4/GuiSelectionManager.cpp +++ b/src/frontends/qt4/GuiSelectionManager.cpp @@ -41,21 +41,21 @@ namespace lyx { namespace frontend { -GuiSelectionManager::GuiSelectionManager( - QAbstractItemView * avail, - QAbstractItemView * sel, - QPushButton * add, - QPushButton * del, - QPushButton * up, - QPushButton * down, - QAbstractListModel * amod, - QAbstractItemModel * smod, - int const main_sel_col) - : availableLV(avail), selectedLV(sel), addPB(add), deletePB(del), - upPB(up), downPB(down), availableModel(amod), selectedModel(smod), - selectedHasFocus_(false), main_sel_col_(main_sel_col) +GuiSelectionManager::GuiSelectionManager(QObject * parent, + QAbstractItemView * avail, + QAbstractItemView * sel, + QPushButton * add, + QPushButton * del, + QPushButton * up, + QPushButton * down, + QAbstractListModel * amod, + QAbstractItemModel * smod, + int const main_sel_col) +: QObject(parent), availableLV(avail), selectedLV(sel), + addPB(add), deletePB(del), upPB(up), downPB(down), + availableModel(amod), selectedModel(smod), + selectedHasFocus_(false), main_sel_col_(main_sel_col) { - selectedLV->setModel(smod); availableLV->setModel(amod); selectedLV->setSelectionBehavior(QAbstractItemView::SelectRows); @@ -75,17 +75,17 @@ GuiSelectionManager::GuiSelectionManager( this, SLOT(selectedChanged(QItemSelection, QItemSelection))); connect(selectedLV->itemDelegate(), SIGNAL(commitData(QWidget*)), this, SLOT(selectedEdited())); - connect(addPB, SIGNAL(clicked()), + connect(addPB, SIGNAL(clicked()), this, SLOT(addPB_clicked())); - connect(deletePB, SIGNAL(clicked()), + connect(deletePB, SIGNAL(clicked()), this, SLOT(deletePB_clicked())); - connect(upPB, SIGNAL(clicked()), + connect(upPB, SIGNAL(clicked()), this, SLOT(upPB_clicked())); - connect(downPB, SIGNAL(clicked()), + connect(downPB, SIGNAL(clicked()), this, SLOT(downPB_clicked())); - connect(availableLV, SIGNAL(doubleClicked(QModelIndex)), + connect(availableLV, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(availableLV_doubleClicked(QModelIndex))); - + availableLV->installEventFilter(this); selectedLV->installEventFilter(this); } @@ -202,7 +202,7 @@ void GuiSelectionManager::availableChanged(const QModelIndex & idx, const QModel { if (!idx.isValid()) return; - + selectedHasFocus_ = false; updateHook(); } @@ -221,7 +221,7 @@ void GuiSelectionManager::selectedChanged(const QModelIndex & idx, const QModelI { if (!idx.isValid()) return; - + selectedHasFocus_ = true; updateHook(); } @@ -272,15 +272,15 @@ void GuiSelectionManager::addPB_clicked() QModelIndex const idxToAdd = selIdx.first(); QModelIndex const idx = selectedLV->currentIndex(); int const srows = selectedModel->rowCount(); - + QMap qm = availableModel->itemData(idxToAdd); insertRowToSelected(srows, qm); - + selectionChanged(); //signal if (idx.isValid()) selectedLV->setCurrentIndex(idx); - + updateHook(); } @@ -294,11 +294,11 @@ void GuiSelectionManager::deletePB_clicked() QModelIndex idx = selIdx.first(); selectedModel->removeRow(idx.row()); selectionChanged(); //signal - + int nrows = selectedLV->model()->rowCount(); if (idx.row() == nrows) //was last item on list idx = idx.sibling(idx.row() - 1, idx.column()); - + if (nrows > 1) selectedLV->setCurrentIndex(idx); else if (nrows == 1) @@ -357,7 +357,7 @@ void GuiSelectionManager::downPB_clicked() insertRowToSelected(pos + 1, qms); selectionChanged(); //signal - + selectedLV->setCurrentIndex(idx.sibling(idx.row() + 1, idx.column())); selectedHasFocus_ = true; updateHook(); @@ -368,7 +368,7 @@ void GuiSelectionManager::availableLV_doubleClicked(const QModelIndex & idx) { if (isSelected(idx) || !addPB->isEnabled()) return; - + if (idx.isValid()) selectedHasFocus_ = false; addPB_clicked(); diff --git a/src/frontends/qt4/GuiSelectionManager.h b/src/frontends/qt4/GuiSelectionManager.h index dae3f90d8d..68339ff162 100644 --- a/src/frontends/qt4/GuiSelectionManager.h +++ b/src/frontends/qt4/GuiSelectionManager.h @@ -29,9 +29,9 @@ namespace frontend { /** Class to manage a collection of widgets that allows selection * of items from a list of available items. Adapted from code originally - * written for GuiCitationDialog. + * written for GuiCitationDialog. * Note that this is a not a QWidget, though it could be converted to - * one. Rather, the managed widgets---see constructor for descripton + * one. Rather, the managed widgets---see constructor for descripton * of them---should be created independently, and then passed to the * constructor. */ @@ -41,23 +41,23 @@ class GuiSelectionManager : public QObject public: /// - GuiSelectionManager( - QAbstractItemView * availableLV, - QAbstractItemView * selectedLV, - QPushButton * addPB, - QPushButton * delPB, - QPushButton * upPB, - QPushButton * downPB, - QAbstractListModel * availableModel, - QAbstractItemModel * selectedModel, - int const main_sel_col = 0); + GuiSelectionManager(QObject * parent, + QAbstractItemView * availableLV, + QAbstractItemView * selectedLV, + QPushButton * addPB, + QPushButton * delPB, + QPushButton * upPB, + QPushButton * downPB, + QAbstractListModel * availableModel, + QAbstractItemModel * selectedModel, + int const main_sel_col = 0); /// Sets the state of the various push buttons, depending upon the /// state of the widgets. (E.g., "delete" is enabled only if the /// selection is non-empty.) - /// Note: this is separated out into updateAddPB(), etc, below, + /// Note: this is separated out into updateAddPB(), etc, below, /// for easy over-riding of these functions. void update(); - + /// Not strictly a matter of focus, which may be elsewhere, but /// whether selectedLV is `more focused' than availableLV. Intended /// to be used, for example, in displaying information about a @@ -69,9 +69,9 @@ public: QModelIndex getSelectedIndex(int const c = 0) const; Q_SIGNALS: - /// Emitted when the list of selected items has changed. + /// Emitted when the list of selected items has changed. void selectionChanged(); - /// Emitted when something has changed that might lead the containing + /// Emitted when something has changed that might lead the containing /// dialog to want to update---the focused subwidget or selected item. /// (Specifically, it is emitted by *_PB_clicked() and *_LV_clicked.) /// NOTE: No automatic update of the button state is done here. If you @@ -79,7 +79,7 @@ Q_SIGNALS: /// time, though, you will want to do a bit more processing first, so /// you can connect to some other function that itself calls updateView(). void updateHook(); - /// Emitted on Ctrl-Enter in the availableLV. Intended to be connected + /// Emitted on Ctrl-Enter in the availableLV. Intended to be connected /// to an "OK" event in the parent dialog. void okHook(); @@ -99,7 +99,7 @@ protected: /// QPushButton * addPB; /// - QPushButton * deletePB; + QPushButton * deletePB; /// QPushButton * upPB; /// -- 2.39.2