From 0fed833e55d6e76e9239d17659bc614e39c8cfc5 Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Tue, 22 Dec 2015 18:19:55 +0100 Subject: [PATCH] Move a connect in SqlTextEdit to avoid unnecessary slot calls Move the connect for updating the line number area width from the reload settings method to the constructor to make sure it's only called once. Otherwise there would be more and more unnecessary connections made whenever the settings are reloaded. --- src/MainWindow.cpp | 4 ++-- src/sqltextedit.cpp | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index fd3f9123..a91d7867 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -101,7 +101,7 @@ void MainWindow::init() ui->actionExecuteSql->setShortcuts(shortcuts); QShortcut* shortcutBrowseRefresh = new QShortcut(QKeySequence("Ctrl+R"), this); - QObject::connect(shortcutBrowseRefresh, SIGNAL(activated()), ui->buttonRefresh, SLOT(click())); + connect(shortcutBrowseRefresh, SIGNAL(activated()), ui->buttonRefresh, SLOT(click())); // Create the actions for the recently opened dbs list for(int i = 0; i < MaxRecentFiles; ++i) { @@ -214,7 +214,7 @@ void MainWindow::init() { // Check for a new release version, usually only enabled on windows m_NetworkManager = new QNetworkAccessManager(this); - QObject::connect(m_NetworkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(httpresponse(QNetworkReply*))); + connect(m_NetworkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(httpresponse(QNetworkReply*))); QUrl url("https://raw.githubusercontent.com/sqlitebrowser/sqlitebrowser/master/currentrelease"); m_NetworkManager->get(QNetworkRequest(url)); diff --git a/src/sqltextedit.cpp b/src/sqltextedit.cpp index 789d63ca..915f2dd9 100644 --- a/src/sqltextedit.cpp +++ b/src/sqltextedit.cpp @@ -50,6 +50,9 @@ SqlTextEdit::SqlTextEdit(QWidget* parent) : // Do rest of initialisation reloadSettings(); + + // Connect signals + connect(this, SIGNAL(linesChanged()), this, SLOT(updateLineNumberAreaWidth())); } SqlTextEdit::~SqlTextEdit() @@ -132,7 +135,6 @@ void SqlTextEdit::reloadSettings() setMarginsFont(marginsfont); setMarginLineNumbers(0, true); setMarginsBackgroundColor(Qt::lightGray); - connect(this, SIGNAL(linesChanged()), this, SLOT(updateLineNumberAreaWidth())); updateLineNumberAreaWidth(); // Highlight current line