forked from qt-creator/qt-creator
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:
@@ -132,25 +132,29 @@ private:
|
||||
QMetaObject::Connection m_updateSizeConnection;
|
||||
};
|
||||
|
||||
class TopLeftLocatorPopup : public LocatorPopup
|
||||
class TopLeftLocatorPopup final : public LocatorPopup
|
||||
{
|
||||
public:
|
||||
TopLeftLocatorPopup(LocatorWidget *locatorWidget)
|
||||
: LocatorPopup(locatorWidget, locatorWidget) {}
|
||||
: LocatorPopup(locatorWidget, locatorWidget) {
|
||||
doUpdateGeometry();
|
||||
}
|
||||
|
||||
protected:
|
||||
void updateGeometry() override;
|
||||
void doUpdateGeometry() override;
|
||||
void inputLostFocus() override;
|
||||
};
|
||||
|
||||
class CenteredLocatorPopup : public LocatorPopup
|
||||
class CenteredLocatorPopup final : public LocatorPopup
|
||||
{
|
||||
public:
|
||||
CenteredLocatorPopup(LocatorWidget *locatorWidget, QWidget *parent)
|
||||
: LocatorPopup(locatorWidget, parent) {}
|
||||
: LocatorPopup(locatorWidget, parent) {
|
||||
doUpdateGeometry();
|
||||
}
|
||||
|
||||
protected:
|
||||
void updateGeometry() override;
|
||||
void doUpdateGeometry() override;
|
||||
};
|
||||
|
||||
// =========== LocatorModel ===========
|
||||
@@ -297,22 +301,22 @@ void CompletionList::setModel(QAbstractItemModel *newModel)
|
||||
}
|
||||
}
|
||||
|
||||
void LocatorPopup::updateGeometry()
|
||||
void LocatorPopup::doUpdateGeometry()
|
||||
{
|
||||
m_tree->resizeHeaders();
|
||||
}
|
||||
|
||||
void TopLeftLocatorPopup::updateGeometry()
|
||||
void TopLeftLocatorPopup::doUpdateGeometry()
|
||||
{
|
||||
QTC_ASSERT(parentWidget(), return);
|
||||
const QSize size = preferredSize();
|
||||
const int border = m_tree->frameWidth();
|
||||
const QRect rect(parentWidget()->mapToGlobal(QPoint(-border, -size.height() - border)), size);
|
||||
setGeometry(rect);
|
||||
LocatorPopup::updateGeometry();
|
||||
LocatorPopup::doUpdateGeometry();
|
||||
}
|
||||
|
||||
void CenteredLocatorPopup::updateGeometry()
|
||||
void CenteredLocatorPopup::doUpdateGeometry()
|
||||
{
|
||||
QTC_ASSERT(parentWidget(), return);
|
||||
const QSize size = preferredSize();
|
||||
@@ -333,7 +337,7 @@ void CenteredLocatorPopup::updateGeometry()
|
||||
if (rect.left() < available.left())
|
||||
rect.moveLeft(available.left());
|
||||
setGeometry(rect);
|
||||
LocatorPopup::updateGeometry();
|
||||
LocatorPopup::doUpdateGeometry();
|
||||
}
|
||||
|
||||
void LocatorPopup::updateWindow()
|
||||
@@ -354,17 +358,17 @@ bool LocatorPopup::event(QEvent *event)
|
||||
updateWindow();
|
||||
else if (event->type() == QEvent::Show)
|
||||
// make sure the popup has correct position before it becomes visible
|
||||
updateGeometry();
|
||||
doUpdateGeometry();
|
||||
else if (event->type() == QEvent::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);
|
||||
}
|
||||
|
||||
bool LocatorPopup::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (watched == m_window && event->type() == QEvent::Resize)
|
||||
updateGeometry();
|
||||
doUpdateGeometry();
|
||||
return QWidget::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
@@ -427,8 +431,6 @@ LocatorPopup::LocatorPopup(LocatorWidget *locatorWidget, QWidget *parent)
|
||||
if (isVisible())
|
||||
locatorWidget->scheduleAcceptEntry(index);
|
||||
});
|
||||
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
CompletionList *LocatorPopup::completionList() const
|
||||
|
@@ -121,7 +121,7 @@ public:
|
||||
|
||||
protected:
|
||||
QSize preferredSize();
|
||||
virtual void updateGeometry();
|
||||
virtual void doUpdateGeometry();
|
||||
virtual void inputLostFocus();
|
||||
|
||||
QPointer<QWidget> m_window;
|
||||
|
Reference in New Issue
Block a user