From c328e203e0d84177a0028d8ba5b0af4b82c16eeb Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 5 Feb 2010 00:29:13 +0100 Subject: QPointers --> QWeakPointers --- src/application.cpp | 53 +++++++++++++++++++++++++---------------- src/application.h | 12 +++++----- src/history/historymanager.cpp | 3 +-- src/mainwindow.cpp | 19 ++++++++------- src/sessionmanager.cpp | 4 ++-- src/settings/settingsdialog.cpp | 1 - src/tabbar.cpp | 29 ++++++++++------------ src/tabbar.h | 4 ++-- 8 files changed, 66 insertions(+), 59 deletions(-) (limited to 'src') diff --git a/src/application.cpp b/src/application.cpp index 05004f30..cfd4d060 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -64,10 +64,10 @@ #include -QPointer Application::s_historyManager; -QPointer Application::s_bookmarkProvider; -QPointer Application::s_sessionManager; -QPointer Application::s_adblockManager; +QWeakPointer Application::s_historyManager; +QWeakPointer Application::s_bookmarkProvider; +QWeakPointer Application::s_sessionManager; +QWeakPointer Application::s_adblockManager; Application::Application() @@ -80,12 +80,23 @@ Application::Application() Application::~Application() { - qDeleteAll(m_mainWindows); + foreach( QWeakPointer window, m_mainWindows) + { + delete window.data(); + window.clear(); + } - delete s_bookmarkProvider; - delete s_historyManager; - delete s_sessionManager; - delete s_adblockManager; + delete s_bookmarkProvider.data(); + s_bookmarkProvider.clear(); + + delete s_historyManager.data(); + s_historyManager.clear(); + + delete s_sessionManager.data(); + s_sessionManager.clear(); + + delete s_adblockManager.data(); + s_adblockManager.clear(); } @@ -145,7 +156,7 @@ int Application::newInstance() // is there a window open on the current desktop ? use it! for (int i = 0; i < m_mainWindows.size(); ++i) { - MainWindow *m = m_mainWindows.at(i); + MainWindow *m = m_mainWindows.at(i).data(); KWindowInfo w = KWindowInfo(m->winId(), NET::WMDesktop); if(w.isOnCurrentDesktop()) { @@ -210,7 +221,7 @@ MainWindow *Application::mainWindow() if(!active) { - return m_mainWindows.at(0); + return m_mainWindows.at(0).data(); } return active; } @@ -218,38 +229,38 @@ MainWindow *Application::mainWindow() HistoryManager *Application::historyManager() { - if (!s_historyManager) + if ( s_historyManager.isNull() ) { s_historyManager = new HistoryManager(); - QWebHistoryInterface::setDefaultInterface(s_historyManager); + QWebHistoryInterface::setDefaultInterface( s_historyManager.data() ); } - return s_historyManager; + return s_historyManager.data(); } BookmarkProvider *Application::bookmarkProvider() { - if (!s_bookmarkProvider) + if ( s_bookmarkProvider.isNull() ) { s_bookmarkProvider = new BookmarkProvider(instance()); } - return s_bookmarkProvider; + return s_bookmarkProvider.data(); } SessionManager *Application::sessionManager() { - if(!s_sessionManager) + if( s_sessionManager.isNull() ) { s_sessionManager = new SessionManager(instance()); } - return s_sessionManager; + return s_sessionManager.data(); } KIcon Application::icon(const KUrl &url) { - if(!Application::instance()->mainWindowList().isEmpty()) // avoid infinite loop at startup + if( !Application::instance()->mainWindowList().isEmpty() ) // avoid infinite loop at startup { if(url == KUrl("about:closedTabs")) @@ -355,11 +366,11 @@ MainWindowList Application::mainWindowList() AdBlockManager *Application::adblockManager() { - if(!s_adblockManager) + if( s_adblockManager.isNull() ) { s_adblockManager = new AdBlockManager(instance()); } - return s_adblockManager; + return s_adblockManager.data(); } diff --git a/src/application.h b/src/application.h index 4b951ded..0c3bd3f5 100644 --- a/src/application.h +++ b/src/application.h @@ -38,7 +38,7 @@ #include // Qt Includes -#include +#include #include // Forward Declarations @@ -52,7 +52,7 @@ class AdBlockManager; class WebView; -typedef QList< QPointer > MainWindowList; +typedef QList< QWeakPointer > MainWindowList; namespace Rekonq @@ -139,10 +139,10 @@ private slots: void loadResolvedUrl(ThreadWeaver::Job *); private: - static QPointer s_historyManager; - static QPointer s_bookmarkProvider; - static QPointer s_sessionManager; - static QPointer s_adblockManager; + static QWeakPointer s_historyManager; + static QWeakPointer s_bookmarkProvider; + static QWeakPointer s_sessionManager; + static QWeakPointer s_adblockManager; MainWindowList m_mainWindows; }; diff --git a/src/history/historymanager.cpp b/src/history/historymanager.cpp index 29bdb45b..db19a6b4 100644 --- a/src/history/historymanager.cpp +++ b/src/history/historymanager.cpp @@ -69,10 +69,9 @@ HistoryManager::HistoryManager(QObject *parent) , m_historyModel(0) , m_historyFilterModel(0) , m_historyTreeModel(0) - , m_completion(0) + , m_completion(new KCompletion) { // take care of the completion object - m_completion = new KCompletion; m_completion->setOrder( KCompletion::Weighted ); m_expiredTimer.setSingleShot(true); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index df600c05..ffc9f508 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -76,7 +76,7 @@ #include #include #include -#include +#include #include #include @@ -599,13 +599,14 @@ void MainWindow::preferences() return; // we didn't find an instance of this dialog, so lets create it - QPointer s = new SettingsDialog(this); + QWeakPointer s = new SettingsDialog(this); // keep us informed when the user changes settings - connect(s, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateBrowser())); + connect(s.data(), SIGNAL(settingsChanged(const QString&)), this, SLOT(updateBrowser())); - s->exec(); - delete s; + s.data()->exec(); + delete s.data(); + s.clear(); } @@ -1041,16 +1042,16 @@ void MainWindow::notifyMessage(const QString &msg, Rekonq::Notify status) void MainWindow::clearPrivateData() { - QPointer dialog = new KDialog(this, Qt::Sheet); - dialog->setButtons(KDialog::Ok | KDialog::Cancel); + QWeakPointer dialog = new KDialog(this, Qt::Sheet); + dialog.data()->setButtons(KDialog::Ok | KDialog::Cancel); Ui::ClearDataWidget clearWidget; QWidget widget; clearWidget.setupUi(&widget); - dialog->setMainWidget(&widget); + dialog.data()->setMainWidget(&widget); - if (dialog->exec() == KDialog::Accepted) + if (dialog.data()->exec() == KDialog::Accepted) { if(clearWidget.clearHistory->isChecked()) { diff --git a/src/sessionmanager.cpp b/src/sessionmanager.cpp index f4e7cd3e..f512e943 100644 --- a/src/sessionmanager.cpp +++ b/src/sessionmanager.cpp @@ -71,10 +71,10 @@ void SessionManager::saveSession() } QTextStream out(&sessionFile); MainWindowList wl = Application::instance()->mainWindowList(); - Q_FOREACH(QPointer w, wl) + Q_FOREACH(QWeakPointer w, wl) { out << "window\n"; - MainView *mv = w->mainView(); + MainView *mv = w.data()->mainView(); for (int i = 0 ; i < mv->count() ; i++) { out << mv->webTab(i)->url().toEncoded() << "\n"; diff --git a/src/settings/settingsdialog.cpp b/src/settings/settingsdialog.cpp index e37481aa..6fab5dcf 100644 --- a/src/settings/settingsdialog.cpp +++ b/src/settings/settingsdialog.cpp @@ -53,7 +53,6 @@ #include // Qt Includes -#include #include diff --git a/src/tabbar.cpp b/src/tabbar.cpp index 460a2464..5e1feb56 100644 --- a/src/tabbar.cpp +++ b/src/tabbar.cpp @@ -161,24 +161,21 @@ void TabBar::showTabPreview(int tab) int h = w*((0.0 + currentView->height())/currentView->width()); //delete previous tab preview - if (m_previewPopup) - { - delete m_previewPopup; - } - + m_previewPopup.clear(); + m_previewPopup = new KPassivePopup(this); - m_previewPopup->setFrameShape(QFrame::StyledPanel); - m_previewPopup->setFrameShadow(QFrame::Plain); - m_previewPopup->setFixedSize(w, h); + m_previewPopup.data()->setFrameShape(QFrame::StyledPanel); + m_previewPopup.data()->setFrameShadow(QFrame::Plain); + m_previewPopup.data()->setFixedSize(w, h); QLabel *l = new QLabel(); view->page()->setViewportSize(currentView->page()->viewportSize()); l->setPixmap(WebSnap::renderPreview(*(view->page()), w, h)); - m_previewPopup->setView(l); - m_previewPopup->layout()->setAlignment(Qt::AlignTop); - m_previewPopup->layout()->setMargin(0); + m_previewPopup.data()->setView(l); + m_previewPopup.data()->layout()->setAlignment(Qt::AlignTop); + m_previewPopup.data()->layout()->setMargin(0); QPoint pos( tabRect(tab).x() , tabRect(tab).y() + tabRect(tab).height() ); - m_previewPopup->show(mapToGlobal(pos)); + m_previewPopup.data()->show(mapToGlobal(pos)); } @@ -208,9 +205,9 @@ void TabBar::mouseMoveEvent(QMouseEvent *event) //if current tab or not found then hide previous tab preview if (tab==currentIndex() || tab==-1) { - if ( m_previewPopup) + if ( !m_previewPopup.isNull() ) { - m_previewPopup->hide(); + m_previewPopup.data()->hide(); } m_currentTabPreview = -1; } @@ -225,9 +222,9 @@ void TabBar::leaveEvent(QEvent *event) if (ReKonfig::alwaysShowTabPreviews()) { //if leave tabwidget then hide previous tab preview - if ( m_previewPopup) + if ( !m_previewPopup.isNull() ) { - m_previewPopup->hide(); + m_previewPopup.data()->hide(); } m_currentTabPreview = -1; } diff --git a/src/tabbar.h b/src/tabbar.h index f0476cbd..b57106dc 100644 --- a/src/tabbar.h +++ b/src/tabbar.h @@ -35,7 +35,7 @@ #include "rekonqprivate_export.h" // Qt Includes -#include +#include // KDE Includes #include @@ -99,7 +99,7 @@ private: */ int m_actualIndex; - QPointer m_previewPopup; + QWeakPointer m_previewPopup; int m_currentTabPreview; }; -- cgit v1.2.1