From badb0bb96cc22c64210d140643fae521a78c6fdc Mon Sep 17 00:00:00 2001 From: Scott Kostyshak Date: Fri, 29 Jul 2016 13:06:49 -0400 Subject: [PATCH] Improve implementation of TabWorkArea::posIsTab() The Qt documentation states that tabAt() returns -1 if the position is not over a tab. This behavior has been consistent since Qt 4.3 [1]. This commit's improvement likely makes the code faster in two ways: (1) we do not need to loop through potentially all tabs (2) we only need to look up the tab index corresponding with one position posIsTab() is not currently used intensively so no practical gain in speed is achieved, but it protects against future use. [1] https://doc.qt.io/archives/4.3/qtabbar.html#tabAt --- src/frontends/qt4/GuiWorkArea.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp index b9e5e8ec87..9223964e42 100644 --- a/src/frontends/qt4/GuiWorkArea.cpp +++ b/src/frontends/qt4/GuiWorkArea.cpp @@ -1650,10 +1650,8 @@ void TabWorkArea::paintEvent(QPaintEvent * event) bool TabWorkArea::posIsTab(QPoint position) { - for (int i = 0; i < count(); ++i) - if (tabBar()->tabRect(i).contains(position)) - return true; - return false; + // tabAt returns -1 if tab does not covers position + return tabBar()->tabAt(position) > -1; } -- 2.39.2