]> git.lyx.org Git - features.git/commitdiff
Fix 18 memory leaks
authorGuillaume Munch <gm@lyx.org>
Sun, 26 Feb 2017 21:15:49 +0000 (22:15 +0100)
committerGuillaume Munch <gm@lyx.org>
Sun, 26 Feb 2017 21:16:10 +0000 (22:16 +0100)
Also whitespace.

src/frontends/qt4/GuiCitation.cpp
src/frontends/qt4/GuiCitation.h
src/frontends/qt4/GuiDocument.cpp
src/frontends/qt4/GuiDocument.h
src/frontends/qt4/GuiSelectionManager.cpp
src/frontends/qt4/GuiSelectionManager.h

index e2b5aa9d6c0ce8865d7ab9a5007bd26d57496ca7..ee125e43d29606fd393f7cb3c33a673b32f5a2c6 100644 (file)
@@ -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();
index 2fa436910586664f3b359ec7f25f3458f8e92e4b..6648141fc1ce6ed8a29c0cd72c33f663a8608b6c 100644 (file)
@@ -44,8 +44,6 @@ class GuiCitation : public DialogView, public Ui::CitationUi
 public:
        ///
        GuiCitation(GuiView & lv);
-       ///
-       ~GuiCitation();
 
 private Q_SLOTS:
        void on_okPB_clicked();
index 448943e45c817e50fec8d191a53103df615e0598..2293ce3acf31e4c17646d87a9535c90f7176edd1 100644 (file)
@@ -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<Ui::PreambleUi>(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<Ui::LocalLayoutUi>(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<Ui::TextLayoutUi>;
+       textLayoutModule = new UiWidget<Ui::TextLayoutUi>(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<Ui::MasterChildUi>;
+       masterChildModule = new UiWidget<Ui::MasterChildUi>(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<Ui::OutputUi>;
+       outputModule = new UiWidget<Ui::OutputUi>(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<Ui::PageLayoutUi>;
+       pageLayoutModule = new UiWidget<Ui::PageLayoutUi>(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<Ui::MarginsUi>;
+       marginsModule = new UiWidget<Ui::MarginsUi>(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<Ui::LanguageUi>;
+       langModule = new UiWidget<Ui::LanguageUi>(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<Ui::ColorUi>;
+       colorModule = new UiWidget<Ui::ColorUi>(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<Ui::NumberingUi>;
+       numberingModule = new UiWidget<Ui::NumberingUi>(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<Ui::BiblioUi>;
+       biblioModule = new UiWidget<Ui::BiblioUi>(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<Ui::MathsUi>;
+       mathsModule = new UiWidget<Ui::MathsUi>(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<Ui::LaTeXUi>;
+       latexModule = new UiWidget<Ui::LaTeXUi>(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<Ui::ModulesUi>;
+       modulesModule = new UiWidget<Ui::ModulesUi>(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<Ui::PDFSupportUi>;
+       pdfSupportModule = new UiWidget<Ui::PDFSupportUi>(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<Ui::ListingsSettingsUi>;
+       listingsModule = new UiWidget<Ui::ListingsSettingsUi>(this);
        connect(listingsModule->listingsED, SIGNAL(textChanged()),
                this, SLOT(change_adaptor()));
        connect(listingsModule->bypassCB, SIGNAL(clicked()),
index 593a67a3d7c2eb496921e71ee3565df067f0d3d7..38f099a1abc4dc32f8458bf6c4332e056747fe10 100644 (file)
@@ -61,7 +61,7 @@ template<class UI>
 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<Ui::PreambleUi>
 {
        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<Ui::LocalLayoutUi>
 {
        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<Ui::FontUi>
 {
        Q_OBJECT
 public:
+       FontModule(QWidget * parent) : UiWidget<Ui::FontUi>(parent) {}
        /// The roman font currently not selected by osFontsCB->isChecked()
        QString font_roman;
        /// The sans font currently not selected by osFontsCB->isChecked()
index b90d0ea1358dabae4b7c689f1d3a920efadba930..90f90731c56bfb050b885beb0fffc19bf1935dfb 100644 (file)
 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<int, QVariant> 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();
index dae3f90d8d05ec373ffd35c1373f82d23f46226e..68339ff1620686d0d147039416575b13e77cf972 100644 (file)
@@ -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;
        ///