summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/kernel')
-rw-r--r--src/widgets/kernel/qboxlayout.cpp18
-rw-r--r--src/widgets/kernel/qformlayout.cpp22
-rw-r--r--src/widgets/kernel/qgridlayout.cpp23
-rw-r--r--src/widgets/kernel/qlayout.cpp41
-rw-r--r--src/widgets/kernel/qlayout_p.h2
-rw-r--r--src/widgets/kernel/qwidgetwindow_p.h11
-rw-r--r--src/widgets/kernel/qwindowcontainer.cpp10
-rw-r--r--src/widgets/kernel/qwindowcontainer_p.h11
8 files changed, 97 insertions, 41 deletions
diff --git a/src/widgets/kernel/qboxlayout.cpp b/src/widgets/kernel/qboxlayout.cpp
index 157fa55d2e..a186326551 100644
--- a/src/widgets/kernel/qboxlayout.cpp
+++ b/src/widgets/kernel/qboxlayout.cpp
@@ -51,20 +51,6 @@
QT_BEGIN_NAMESPACE
-/*
- Returns \c true if the \a widget can be added to the \a layout;
- otherwise returns \c false.
-*/
-static bool checkWidget(QLayout *layout, QWidget *widget)
-{
- if (!widget) {
- qWarning("QLayout: Cannot add null widget to %s/%s", layout->metaObject()->className(),
- layout->objectName().toLocal8Bit().data());
- return false;
- }
- return true;
-}
-
struct QBoxLayoutItem
{
QBoxLayoutItem(QLayoutItem *it, int stretch_ = 0)
@@ -958,6 +944,8 @@ void QBoxLayout::insertSpacerItem(int index, QSpacerItem *spacerItem)
void QBoxLayout::insertLayout(int index, QLayout *layout, int stretch)
{
Q_D(QBoxLayout);
+ if (!d->checkLayout(layout))
+ return;
if (!adoptLayout(layout))
return;
if (index < 0) // append
@@ -991,7 +979,7 @@ void QBoxLayout::insertWidget(int index, QWidget *widget, int stretch,
Qt::Alignment alignment)
{
Q_D(QBoxLayout);
- if (!checkWidget(this, widget))
+ if (!d->checkWidget(widget))
return;
addChildWidget(widget);
if (index < 0) // append
diff --git a/src/widgets/kernel/qformlayout.cpp b/src/widgets/kernel/qformlayout.cpp
index 239e1ce1e2..9f545b858a 100644
--- a/src/widgets/kernel/qformlayout.cpp
+++ b/src/widgets/kernel/qformlayout.cpp
@@ -1280,6 +1280,8 @@ void QFormLayout::addRow(QLayout *layout)
void QFormLayout::insertRow(int row, QWidget *label, QWidget *field)
{
Q_D(QFormLayout);
+ if ((label && !d->checkWidget(label)) || (field && !d->checkWidget(field)))
+ return;
row = d->insertRow(row);
if (label)
@@ -1295,6 +1297,8 @@ void QFormLayout::insertRow(int row, QWidget *label, QWidget *field)
void QFormLayout::insertRow(int row, QWidget *label, QLayout *field)
{
Q_D(QFormLayout);
+ if ((label && !d->checkWidget(label)) || (field && !d->checkLayout(field)))
+ return;
row = d->insertRow(row);
if (label)
@@ -1313,6 +1317,10 @@ void QFormLayout::insertRow(int row, QWidget *label, QLayout *field)
*/
void QFormLayout::insertRow(int row, const QString &labelText, QWidget *field)
{
+ Q_D(QFormLayout);
+ if (field && !d->checkWidget(field))
+ return;
+
QLabel *label = 0;
if (!labelText.isEmpty()) {
label = new QLabel(labelText);
@@ -1331,6 +1339,10 @@ void QFormLayout::insertRow(int row, const QString &labelText, QWidget *field)
*/
void QFormLayout::insertRow(int row, const QString &labelText, QLayout *field)
{
+ Q_D(QFormLayout);
+ if (field && !d->checkLayout(field))
+ return;
+
insertRow(row, labelText.isEmpty() ? 0 : new QLabel(labelText), field);
}
@@ -1344,11 +1356,8 @@ void QFormLayout::insertRow(int row, const QString &labelText, QLayout *field)
void QFormLayout::insertRow(int row, QWidget *widget)
{
Q_D(QFormLayout);
-
- if (!widget) {
- qWarning("QFormLayout: Cannot add null field to %s", qPrintable(objectName()));
+ if (!d->checkWidget(widget))
return;
- }
row = d->insertRow(row);
d->setWidget(row, SpanningRole, widget);
@@ -1365,11 +1374,8 @@ void QFormLayout::insertRow(int row, QWidget *widget)
void QFormLayout::insertRow(int row, QLayout *layout)
{
Q_D(QFormLayout);
-
- if (!layout) {
- qWarning("QFormLayout: Cannot add null field to %s", qPrintable(objectName()));
+ if (!d->checkLayout(layout))
return;
- }
row = d->insertRow(row);
d->setLayout(row, SpanningRole, layout);
diff --git a/src/widgets/kernel/qgridlayout.cpp b/src/widgets/kernel/qgridlayout.cpp
index 5434c40f97..6782e4a9f8 100644
--- a/src/widgets/kernel/qgridlayout.cpp
+++ b/src/widgets/kernel/qgridlayout.cpp
@@ -1430,20 +1430,6 @@ void QGridLayout::addItem(QLayoutItem *item, int row, int column, int rowSpan, i
invalidate();
}
-/*
- Returns \c true if the widget \a w can be added to the layout \a l;
- otherwise returns \c false.
-*/
-static bool checkWidget(QLayout *l, QWidget *w)
-{
- if (!w) {
- qWarning("QLayout: Cannot add null widget to %s/%s", l->metaObject()->className(),
- l->objectName().toLocal8Bit().data());
- return false;
- }
- return true;
-}
-
/*!
Adds the given \a widget to the cell grid at \a row, \a column. The
top-left position is (0, 0) by default.
@@ -1454,7 +1440,8 @@ static bool checkWidget(QLayout *l, QWidget *w)
*/
void QGridLayout::addWidget(QWidget *widget, int row, int column, Qt::Alignment alignment)
{
- if (!checkWidget(this, widget))
+ Q_D(QGridLayout);
+ if (!d->checkWidget(widget))
return;
if (row < 0 || column < 0) {
qWarning("QGridLayout: Cannot add %s/%s to %s/%s at row %d column %d",
@@ -1483,7 +1470,7 @@ void QGridLayout::addWidget(QWidget *widget, int fromRow, int fromColumn,
int rowSpan, int columnSpan, Qt::Alignment alignment)
{
Q_D(QGridLayout);
- if (!checkWidget(this, widget))
+ if (!d->checkWidget(widget))
return;
int toRow = (rowSpan < 0) ? -1 : fromRow + rowSpan - 1;
int toColumn = (columnSpan < 0) ? -1 : fromColumn + columnSpan - 1;
@@ -1518,6 +1505,8 @@ void QGridLayout::addWidget(QWidget *widget, int fromRow, int fromColumn,
void QGridLayout::addLayout(QLayout *layout, int row, int column, Qt::Alignment alignment)
{
Q_D(QGridLayout);
+ if (!d->checkLayout(layout))
+ return;
if (!adoptLayout(layout))
return;
QGridBox *b = new QGridBox(layout);
@@ -1538,6 +1527,8 @@ void QGridLayout::addLayout(QLayout *layout, int row, int column,
int rowSpan, int columnSpan, Qt::Alignment alignment)
{
Q_D(QGridLayout);
+ if (!d->checkLayout(layout))
+ return;
if (!adoptLayout(layout))
return;
QGridBox *b = new QGridBox(layout);
diff --git a/src/widgets/kernel/qlayout.cpp b/src/widgets/kernel/qlayout.cpp
index eb21a580b1..778514f47a 100644
--- a/src/widgets/kernel/qlayout.cpp
+++ b/src/widgets/kernel/qlayout.cpp
@@ -858,6 +858,47 @@ void QLayoutPrivate::reparentChildWidgets(QWidget *mw)
}
/*!
+ Returns \c true if the \a widget can be added to the \a layout;
+ otherwise returns \c false.
+*/
+bool QLayoutPrivate::checkWidget(QWidget *widget) const
+{
+ Q_Q(const QLayout);
+ if (!widget) {
+ qWarning("QLayout: Cannot add a null widget to %s/%s", q->metaObject()->className(),
+ qPrintable(q->objectName()));
+ return false;
+ }
+ if (widget == q->parentWidget()) {
+ qWarning("QLayout: Cannot add parent widget %s/%s to its child layout %s/%s",
+ widget->metaObject()->className(), qPrintable(widget->objectName()),
+ q->metaObject()->className(), qPrintable(q->objectName()));
+ return false;
+ }
+ return true;
+}
+
+/*!
+ Returns \c true if the \a otherLayout can be added to the \a layout;
+ otherwise returns \c false.
+*/
+bool QLayoutPrivate::checkLayout(QLayout *otherLayout) const
+{
+ Q_Q(const QLayout);
+ if (!otherLayout) {
+ qWarning("QLayout: Cannot add a null layout to %s/%s", q->metaObject()->className(),
+ qPrintable(q->objectName()));
+ return false;
+ }
+ if (otherLayout == q) {
+ qWarning("QLayout: Cannot add layout %s/%s to itself", q->metaObject()->className(),
+ qPrintable(q->objectName()));
+ return false;
+ }
+ return true;
+}
+
+/*!
This function is called from \c addWidget() functions in
subclasses to add \a w as a managed widget of a layout.
diff --git a/src/widgets/kernel/qlayout_p.h b/src/widgets/kernel/qlayout_p.h
index 2100d86aba..71e0f9bcd3 100644
--- a/src/widgets/kernel/qlayout_p.h
+++ b/src/widgets/kernel/qlayout_p.h
@@ -76,6 +76,8 @@ public:
void getMargin(int *result, int userMargin, QStyle::PixelMetric pm) const;
void doResize(const QSize &);
void reparentChildWidgets(QWidget *mw);
+ bool checkWidget(QWidget *widget) const;
+ bool checkLayout(QLayout *otherLayout) const;
static QWidgetItem *createWidgetItem(const QLayout *layout, QWidget *widget);
static QSpacerItem *createSpacerItem(const QLayout *layout, int w, int h, QSizePolicy::Policy hPolicy = QSizePolicy::Minimum, QSizePolicy::Policy vPolicy = QSizePolicy::Minimum);
diff --git a/src/widgets/kernel/qwidgetwindow_p.h b/src/widgets/kernel/qwidgetwindow_p.h
index 87ad7a4bd4..1db1a4b600 100644
--- a/src/widgets/kernel/qwidgetwindow_p.h
+++ b/src/widgets/kernel/qwidgetwindow_p.h
@@ -42,6 +42,17 @@
#ifndef QWIDGETWINDOW_P_H
#define QWIDGETWINDOW_P_H
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
#include <QtGui/qwindow.h>
#include <QtCore/private/qobject_p.h>
diff --git a/src/widgets/kernel/qwindowcontainer.cpp b/src/widgets/kernel/qwindowcontainer.cpp
index fa906a5aa2..065f6c86cf 100644
--- a/src/widgets/kernel/qwindowcontainer.cpp
+++ b/src/widgets/kernel/qwindowcontainer.cpp
@@ -92,8 +92,11 @@ public:
Q_Q(QWindowContainer);
QWidget *p = q->parentWidget();
while (p) {
- if (qobject_cast<QMdiSubWindow *>(p) != 0
- || qobject_cast<QAbstractScrollArea *>(p) != 0) {
+ if (
+#ifndef QT_NO_MDIAREA
+ qobject_cast<QMdiSubWindow *>(p) != 0 ||
+#endif
+ qobject_cast<QAbstractScrollArea *>(p) != 0) {
q->winId();
usesNativeWidgets = true;
break;
@@ -203,6 +206,7 @@ QWindowContainer::QWindowContainer(QWindow *embeddedWindow, QWidget *parent, Qt:
d->window = embeddedWindow;
d->window->setParent(&d->fakeParent);
+ setAcceptDrops(true);
connect(QGuiApplication::instance(), SIGNAL(focusWindowChanged(QWindow*)), this, SLOT(focusWindowChanged(QWindow*)));
}
@@ -295,6 +299,7 @@ bool QWindowContainer::event(QEvent *e)
}
}
break;
+#ifndef QT_NO_DRAGANDDROP
case QEvent::Drop:
case QEvent::DragMove:
case QEvent::DragLeave:
@@ -306,6 +311,7 @@ bool QWindowContainer::event(QEvent *e)
QCoreApplication::sendEvent(d->window, e);
e->accept();
return true;
+#endif
default:
break;
}
diff --git a/src/widgets/kernel/qwindowcontainer_p.h b/src/widgets/kernel/qwindowcontainer_p.h
index 014b163f97..45b3cc021f 100644
--- a/src/widgets/kernel/qwindowcontainer_p.h
+++ b/src/widgets/kernel/qwindowcontainer_p.h
@@ -42,6 +42,17 @@
#ifndef QWINDOWCONTAINER_H
#define QWINDOWCONTAINER_H
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
#include <QtWidgets/qwidget.h>
QT_BEGIN_NAMESPACE