From e74b984a0aca752459cd1596d27590f9a488b9d6 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 14 Jul 2019 11:46:10 +0800 Subject: [PATCH] Rely on Qt ownership to delete class members --- src/gui/previewselectdialog.cpp | 4 +--- src/gui/properties/propertieswidget.cpp | 13 ++----------- src/gui/properties/proptabbar.cpp | 5 ----- src/gui/properties/proptabbar.h | 2 +- src/gui/rss/feedlistwidget.cpp | 5 ----- src/gui/rss/feedlistwidget.h | 1 - src/gui/torrentcontentfiltermodel.cpp | 5 ----- src/gui/torrentcontentfiltermodel.h | 4 ++-- src/gui/transferlistwidget.cpp | 12 +++--------- 9 files changed, 9 insertions(+), 42 deletions(-) diff --git a/src/gui/previewselectdialog.cpp b/src/gui/previewselectdialog.cpp index 2ea6ebd1f..d6f139006 100644 --- a/src/gui/previewselectdialog.cpp +++ b/src/gui/previewselectdialog.cpp @@ -61,7 +61,7 @@ PreviewSelectDialog::PreviewSelectDialog(QWidget *parent, BitTorrent::TorrentHan Preferences *const pref = Preferences::instance(); // Preview list - m_previewListModel = new QStandardItemModel(0, NB_COLUMNS); + m_previewListModel = new QStandardItemModel(0, NB_COLUMNS, this); m_previewListModel->setHeaderData(NAME, Qt::Horizontal, tr("Name")); m_previewListModel->setHeaderData(SIZE, Qt::Horizontal, tr("Size")); m_previewListModel->setHeaderData(PROGRESS, Qt::Horizontal, tr("Progress")); @@ -118,8 +118,6 @@ PreviewSelectDialog::~PreviewSelectDialog() { saveWindowState(); - delete m_previewListModel; - delete m_listDelegate; delete m_ui; } diff --git a/src/gui/properties/propertieswidget.cpp b/src/gui/properties/propertieswidget.cpp index e011f3bce..9cd7e7b96 100644 --- a/src/gui/properties/propertieswidget.cpp +++ b/src/gui/properties/propertieswidget.cpp @@ -82,7 +82,7 @@ PropertiesWidget::PropertiesWidget(QWidget *parent) m_state = VISIBLE; // Set Properties list model - m_propListModel = new TorrentContentFilterModel(); + m_propListModel = new TorrentContentFilterModel(this); m_ui->filesList->setModel(m_propListModel); m_propListDelegate = new PropListDelegate(this); m_ui->filesList->setItemDelegate(m_propListDelegate); @@ -142,7 +142,7 @@ PropertiesWidget::PropertiesWidget(QWidget *parent) m_peerList = new PeerListWidget(this); m_ui->vBoxLayoutPeerPage->addWidget(m_peerList); // Tab bar - m_tabBar = new PropTabBar(); + m_tabBar = new PropTabBar(nullptr); m_tabBar->setContentsMargins(0, 5, 0, 0); m_ui->verticalLayout->addLayout(m_tabBar); connect(m_tabBar, &PropTabBar::tabChanged, m_ui->stackedProperties, &QStackedWidget::setCurrentIndex); @@ -168,17 +168,8 @@ PropertiesWidget::PropertiesWidget(QWidget *parent) PropertiesWidget::~PropertiesWidget() { - qDebug() << Q_FUNC_INFO << "ENTER"; - delete m_trackerList; - delete m_peerList; - delete m_speedWidget; - delete m_downloadedPieces; - delete m_piecesAvailability; - delete m_propListModel; - delete m_propListDelegate; delete m_tabBar; delete m_ui; - qDebug() << Q_FUNC_INFO << "EXIT"; } void PropertiesWidget::showPiecesAvailability(bool show) diff --git a/src/gui/properties/proptabbar.cpp b/src/gui/properties/proptabbar.cpp index edb2eaaa3..56dcf531d 100644 --- a/src/gui/properties/proptabbar.cpp +++ b/src/gui/properties/proptabbar.cpp @@ -107,11 +107,6 @@ PropTabBar::PropTabBar(QWidget *parent) btn->setFocusPolicy(Qt::NoFocus); } -PropTabBar::~PropTabBar() -{ - delete m_btnGroup; -} - int PropTabBar::currentIndex() const { return m_currentIndex; diff --git a/src/gui/properties/proptabbar.h b/src/gui/properties/proptabbar.h index aa73c51f4..b49cfa752 100644 --- a/src/gui/properties/proptabbar.h +++ b/src/gui/properties/proptabbar.h @@ -50,7 +50,7 @@ public: }; explicit PropTabBar(QWidget *parent = nullptr); - ~PropTabBar(); + int currentIndex() const; signals: diff --git a/src/gui/rss/feedlistwidget.cpp b/src/gui/rss/feedlistwidget.cpp index 954f6733b..20fc172c3 100644 --- a/src/gui/rss/feedlistwidget.cpp +++ b/src/gui/rss/feedlistwidget.cpp @@ -71,11 +71,6 @@ FeedListWidget::FeedListWidget(QWidget *parent) // setCurrentItem(m_unreadStickyItem); } -FeedListWidget::~FeedListWidget() -{ - delete m_unreadStickyItem; -} - void FeedListWidget::handleItemAdded(RSS::Item *rssItem) { auto parentItem = m_rssToTreeItemMapping.value( diff --git a/src/gui/rss/feedlistwidget.h b/src/gui/rss/feedlistwidget.h index ec82ea592..e3cd65411 100644 --- a/src/gui/rss/feedlistwidget.h +++ b/src/gui/rss/feedlistwidget.h @@ -47,7 +47,6 @@ class FeedListWidget : public QTreeWidget public: explicit FeedListWidget(QWidget *parent); - ~FeedListWidget(); QTreeWidgetItem *stickyUnreadItem() const; QList getAllOpenedFolders(QTreeWidgetItem *parent = nullptr) const; diff --git a/src/gui/torrentcontentfiltermodel.cpp b/src/gui/torrentcontentfiltermodel.cpp index 78f14dd49..abb22ed4b 100644 --- a/src/gui/torrentcontentfiltermodel.cpp +++ b/src/gui/torrentcontentfiltermodel.cpp @@ -44,11 +44,6 @@ TorrentContentFilterModel::TorrentContentFilterModel(QObject *parent) setSortCaseSensitivity(Qt::CaseInsensitive); } -TorrentContentFilterModel::~TorrentContentFilterModel() -{ - delete m_model; -} - TorrentContentModel *TorrentContentFilterModel::model() const { return m_model; diff --git a/src/gui/torrentcontentfiltermodel.h b/src/gui/torrentcontentfiltermodel.h index 72a701f65..dff54304d 100644 --- a/src/gui/torrentcontentfiltermodel.h +++ b/src/gui/torrentcontentfiltermodel.h @@ -41,7 +41,6 @@ class TorrentContentFilterModel : public QSortFilterProxyModel public: TorrentContentFilterModel(QObject *parent = nullptr); - ~TorrentContentFilterModel() override; TorrentContentModel *model() const; TorrentContentModelItem::ItemType itemType(const QModelIndex &index) const; @@ -60,8 +59,9 @@ protected: bool lessThan(const QModelIndex &left, const QModelIndex &right) const override; private: - TorrentContentModel *m_model; bool hasFiltered(const QModelIndex &folder) const; + + TorrentContentModel *m_model; }; #endif // TORRENTCONTENTFILTERMODEL_H diff --git a/src/gui/transferlistwidget.cpp b/src/gui/transferlistwidget.cpp index f86a56391..26727617b 100644 --- a/src/gui/transferlistwidget.cpp +++ b/src/gui/transferlistwidget.cpp @@ -114,7 +114,7 @@ TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *mainWindow) // Create transfer list model m_listModel = new TransferListModel(this); - m_sortFilterModel = new TransferListSortModel(); + m_sortFilterModel = new TransferListSortModel(this); m_sortFilterModel->setDynamicSortFilter(true); m_sortFilterModel->setSourceModel(m_listModel); m_sortFilterModel->setFilterKeyColumn(TransferListModel::TR_NAME); @@ -207,14 +207,8 @@ TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *mainWindow) TransferListWidget::~TransferListWidget() { - qDebug() << Q_FUNC_INFO << "ENTER"; // Save settings saveSettings(); - // Clean up - delete m_sortFilterModel; - delete m_listModel; - delete m_listDelegate; - qDebug() << Q_FUNC_INFO << "EXIT"; } TransferListModel *TransferListWidget::getSourceModel() const @@ -227,7 +221,7 @@ void TransferListWidget::previewFile(const QString &filePath) Utils::Gui::openPath(filePath); } -inline QModelIndex TransferListWidget::mapToSource(const QModelIndex &index) const +QModelIndex TransferListWidget::mapToSource(const QModelIndex &index) const { Q_ASSERT(index.isValid()); if (index.model() == m_sortFilterModel) @@ -235,7 +229,7 @@ inline QModelIndex TransferListWidget::mapToSource(const QModelIndex &index) con return index; } -inline QModelIndex TransferListWidget::mapFromSource(const QModelIndex &index) const +QModelIndex TransferListWidget::mapFromSource(const QModelIndex &index) const { Q_ASSERT(index.isValid()); Q_ASSERT(index.model() == m_sortFilterModel);