From 7f686d7740cab02f92d158df487341dbc0513b61 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sat, 24 Jun 2017 10:23:13 +0200 Subject: Some MainWindow and WebViewTabBar cleanup --- src/mainwindow.cpp | 15 +++++++-------- src/mainwindow.h | 3 --- src/widgets/webviewtabbar.cpp | 11 +++++++++-- src/widgets/webviewtabbar.h | 8 +++++--- 4 files changed, 21 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 861f7cf..6944ac7 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -90,8 +90,7 @@ MainWindow::MainWindow(QUrl defaultUrl, QWidget *parent) : connect(tabBar, SIGNAL(currentTabChanged(WebView*)), this, SLOT(handleTabChanged(WebView*))); // Load profile - m_profile = qApp->profile(sSettings->value("browser.profile.default").toString()); - tabBar->setProfile(m_profile); + tabBar->setProfile(qApp->profile(sSettings->value("browser.profile.default").toString())); // loading bar ui->statusBar->addPermanentWidget(progressBar); @@ -181,8 +180,8 @@ void MainWindow::about() void MainWindow::setProfile(WebEngineProfile *profile) { - m_profile = profile; - tabBar->setProfile(m_profile); + Q_ASSERT(profile != nullptr); + tabBar->setProfile(profile); } void MainWindow::toggleFullscreen() @@ -201,7 +200,7 @@ void MainWindow::newWindow(const QUrl &url) void MainWindow::handleTabChanged(WebView *view) { - Q_ASSERT(view); + Q_ASSERT(view != nullptr); // centralWidget can be a nullptr if(centralWidget()) { @@ -235,15 +234,15 @@ void MainWindow::handleUrlChanged() void MainWindow::handleTitleUpdated(const QString &title) { - setWindowTitle(sSettings->value("window.title").toString().replace("title", title).replace("profile", m_profile->name())); + setWindowTitle(sSettings->value("window.title").toString().replace("title", title).replace("profile", tabBar->profile()->name())); } void MainWindow::profileAction() { - m_profile->dialog()->showProfile(); + tabBar->profile()->dialog()->showProfile(); } void MainWindow::cookiesAction() { - m_profile->dialog()->showCookies(); + tabBar->profile()->dialog()->showCookies(); } diff --git a/src/mainwindow.h b/src/mainwindow.h index a1cbcc0..ac2a335 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -70,9 +70,6 @@ private slots: void handleTitleUpdated(const QString &title); private: - WebEngineProfile *m_profile = nullptr; - - // ui Ui::MainWindow *ui; QToolBar *navigationToolBar, *tabToolBar; WebViewTabBar *tabBar; diff --git a/src/widgets/webviewtabbar.cpp b/src/widgets/webviewtabbar.cpp index d57e095..4d3a859 100644 --- a/src/widgets/webviewtabbar.cpp +++ b/src/widgets/webviewtabbar.cpp @@ -22,7 +22,7 @@ #include "browser.h" #include -WebViewTabBar::WebViewTabBar(QWebEngineProfile *profile, QWidget *parent) : +WebViewTabBar::WebViewTabBar(WebEngineProfile *profile, QWidget *parent) : QTabBar(parent) { m_profile = profile; @@ -96,8 +96,10 @@ int WebViewTabBar::addTab(const QUrl &url) return QTabBar::addTab("New Tab"); } -void WebViewTabBar::setProfile(QWebEngineProfile *profile) +void WebViewTabBar::setProfile(WebEngineProfile *profile) { + Q_ASSERT(profile != nullptr); + m_profile = profile; for(auto view : qAsConst(m_views)) { QWebEnginePage *page = new QWebEnginePage(profile); @@ -106,6 +108,11 @@ void WebViewTabBar::setProfile(QWebEngineProfile *profile) } } +WebEngineProfile *WebViewTabBar::profile() +{ + return m_profile; +} + WebView *WebViewTabBar::currentView() { return m_views.at(currentIndex()); diff --git a/src/widgets/webviewtabbar.h b/src/widgets/webviewtabbar.h index d1ccf81..31a3ab2 100644 --- a/src/widgets/webviewtabbar.h +++ b/src/widgets/webviewtabbar.h @@ -24,16 +24,18 @@ #include #include "webengine/webview.h" #include +#include "webengine/webengineprofile.h" class WebViewTabBar : public QTabBar { Q_OBJECT public: - explicit WebViewTabBar(QWebEngineProfile *profile, QWidget *parent = 0); + explicit WebViewTabBar(WebEngineProfile *profile = nullptr, QWidget *parent = 0); ~WebViewTabBar(); - void setProfile(QWebEngineProfile *profile); + void setProfile(WebEngineProfile *profile); + WebEngineProfile *profile(); QSignalMapper *signalMapper(); WebView *currentView(); @@ -62,7 +64,7 @@ private: QVector m_views; QSignalMapper *m_signalMapper; - QWebEngineProfile *m_profile; + WebEngineProfile *m_profile = nullptr; }; #endif // WEBVIEWTABBAR_H -- cgit v1.2.1