Move QDesktopWidget API used by QApplication into QDesktopWidget

QDesktopWidget is not a public class anymore and only exists for
compatibility reasons. So we might just as well move the only method
used by other classes out of QDesktopWidgetPrivate, and get rid of the
friend declarations and the access-to-private code in QApplication.

Change-Id: I74ff14233e59912e0930f98995f8af60dbadfdb6
Task-number: QTBUG-62094
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Volker Hilsheimer 2020-08-13 00:01:24 +02:00
parent c54a5b8380
commit 90436e54cc
3 changed files with 15 additions and 10 deletions

View File

@ -2556,8 +2556,7 @@ QWidget *QApplication::desktop(QScreen *screen)
}
if (!screen)
return qt_desktopWidget;
QDesktopWidgetPrivate *dwp = static_cast<QDesktopWidgetPrivate*>(qt_widget_private(qt_desktopWidget));
return dwp->widgetForScreen(screen);
return qt_desktopWidget->widgetForScreen(screen);
}
/*

View File

@ -107,6 +107,17 @@ QDesktopWidget::QDesktopWidget()
QDesktopWidget::~QDesktopWidget() = default;
/*!
\internal
Returns the Qt::Desktop type widget for \a qScreen.
*/
QWidget *QDesktopWidget::widgetForScreen(QScreen *qScreen) const
{
Q_D(const QDesktopWidget);
return d->screenWidgets.value(qScreen);
}
QT_END_NAMESPACE
#include "moc_qdesktopwidget_p.cpp"

View File

@ -68,25 +68,20 @@ public:
QDesktopWidget();
~QDesktopWidget();
QWidget *widgetForScreen(QScreen *qScreen) const;
private:
Q_DISABLE_COPY(QDesktopWidget)
Q_DECLARE_PRIVATE(QDesktopWidget)
friend class QApplication;
friend class QApplicationPrivate;
};
class QDesktopWidgetPrivate : public QWidgetPrivate {
class QDesktopWidgetPrivate : public QWidgetPrivate
{
Q_DECLARE_PUBLIC(QDesktopWidget)
public:
~QDesktopWidgetPrivate();
void updateScreens();
QWidget *widgetForScreen(QScreen *qScreen) const
{
return screenWidgets.value(qScreen);
}
QFlatMap<QScreen*, QWidget*> screenWidgets;
};