Don't call virtual method from LocatorPopup's c'tor

Rename LocatorPopup::updateGeometry into doUpdateGeometry in order
to not clash with QWidget::updateGeometry.

Move a call to doUpdateGeometry from LocatorPopup's c'tor
into subclasses c'tors. Make subclasses final.

Change-Id: I601731e6c883631c3d484ed7f11d82a99bb1f731
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Jarek Kobus
2020-11-20 07:58:49 +01:00
parent 95685898a5
commit b77d661152
2 changed files with 19 additions and 17 deletions

View File

@@ -132,25 +132,29 @@ private:
QMetaObject::Connection m_updateSizeConnection; QMetaObject::Connection m_updateSizeConnection;
}; };
class TopLeftLocatorPopup : public LocatorPopup class TopLeftLocatorPopup final : public LocatorPopup
{ {
public: public:
TopLeftLocatorPopup(LocatorWidget *locatorWidget) TopLeftLocatorPopup(LocatorWidget *locatorWidget)
: LocatorPopup(locatorWidget, locatorWidget) {} : LocatorPopup(locatorWidget, locatorWidget) {
doUpdateGeometry();
}
protected: protected:
void updateGeometry() override; void doUpdateGeometry() override;
void inputLostFocus() override; void inputLostFocus() override;
}; };
class CenteredLocatorPopup : public LocatorPopup class CenteredLocatorPopup final : public LocatorPopup
{ {
public: public:
CenteredLocatorPopup(LocatorWidget *locatorWidget, QWidget *parent) CenteredLocatorPopup(LocatorWidget *locatorWidget, QWidget *parent)
: LocatorPopup(locatorWidget, parent) {} : LocatorPopup(locatorWidget, parent) {
doUpdateGeometry();
}
protected: protected:
void updateGeometry() override; void doUpdateGeometry() override;
}; };
// =========== LocatorModel =========== // =========== LocatorModel ===========
@@ -297,22 +301,22 @@ void CompletionList::setModel(QAbstractItemModel *newModel)
} }
} }
void LocatorPopup::updateGeometry() void LocatorPopup::doUpdateGeometry()
{ {
m_tree->resizeHeaders(); m_tree->resizeHeaders();
} }
void TopLeftLocatorPopup::updateGeometry() void TopLeftLocatorPopup::doUpdateGeometry()
{ {
QTC_ASSERT(parentWidget(), return); QTC_ASSERT(parentWidget(), return);
const QSize size = preferredSize(); const QSize size = preferredSize();
const int border = m_tree->frameWidth(); const int border = m_tree->frameWidth();
const QRect rect(parentWidget()->mapToGlobal(QPoint(-border, -size.height() - border)), size); const QRect rect(parentWidget()->mapToGlobal(QPoint(-border, -size.height() - border)), size);
setGeometry(rect); setGeometry(rect);
LocatorPopup::updateGeometry(); LocatorPopup::doUpdateGeometry();
} }
void CenteredLocatorPopup::updateGeometry() void CenteredLocatorPopup::doUpdateGeometry()
{ {
QTC_ASSERT(parentWidget(), return); QTC_ASSERT(parentWidget(), return);
const QSize size = preferredSize(); const QSize size = preferredSize();
@@ -333,7 +337,7 @@ void CenteredLocatorPopup::updateGeometry()
if (rect.left() < available.left()) if (rect.left() < available.left())
rect.moveLeft(available.left()); rect.moveLeft(available.left());
setGeometry(rect); setGeometry(rect);
LocatorPopup::updateGeometry(); LocatorPopup::doUpdateGeometry();
} }
void LocatorPopup::updateWindow() void LocatorPopup::updateWindow()
@@ -354,17 +358,17 @@ bool LocatorPopup::event(QEvent *event)
updateWindow(); updateWindow();
else if (event->type() == QEvent::Show) else if (event->type() == QEvent::Show)
// make sure the popup has correct position before it becomes visible // make sure the popup has correct position before it becomes visible
updateGeometry(); doUpdateGeometry();
else if (event->type() == QEvent::LayoutRequest) else if (event->type() == QEvent::LayoutRequest)
// completion list resizes after first items are shown --> LayoutRequest // completion list resizes after first items are shown --> LayoutRequest
QTimer::singleShot(0, this, &LocatorPopup::updateGeometry); QTimer::singleShot(0, this, &LocatorPopup::doUpdateGeometry);
return QWidget::event(event); return QWidget::event(event);
} }
bool LocatorPopup::eventFilter(QObject *watched, QEvent *event) bool LocatorPopup::eventFilter(QObject *watched, QEvent *event)
{ {
if (watched == m_window && event->type() == QEvent::Resize) if (watched == m_window && event->type() == QEvent::Resize)
updateGeometry(); doUpdateGeometry();
return QWidget::eventFilter(watched, event); return QWidget::eventFilter(watched, event);
} }
@@ -427,8 +431,6 @@ LocatorPopup::LocatorPopup(LocatorWidget *locatorWidget, QWidget *parent)
if (isVisible()) if (isVisible())
locatorWidget->scheduleAcceptEntry(index); locatorWidget->scheduleAcceptEntry(index);
}); });
updateGeometry();
} }
CompletionList *LocatorPopup::completionList() const CompletionList *LocatorPopup::completionList() const

View File

@@ -121,7 +121,7 @@ public:
protected: protected:
QSize preferredSize(); QSize preferredSize();
virtual void updateGeometry(); virtual void doUpdateGeometry();
virtual void inputLostFocus(); virtual void inputLostFocus();
QPointer<QWidget> m_window; QPointer<QWidget> m_window;