QtBase  v6.3.1
tst_qgraphicswidget.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21 ** included in the packaging of this file. Please review the following
22 ** information to ensure the GNU General Public License requirements will
23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24 **
25 ** $QT_END_LICENSE$
26 **
27 ****************************************************************************/
28 
29 
30 #include <QTest>
31 #include <qgraphicswidget.h>
32 #include <qgraphicsscene.h>
33 #include <qgraphicssceneevent.h>
34 #include <qgraphicsview.h>
35 #include <qstyleoption.h>
36 #include <qgraphicslinearlayout.h>
37 #include <qlineedit.h>
38 #include <qboxlayout.h>
39 #include <qaction.h>
40 #include <qwidgetaction.h>
41 #include <qcommonstyle.h>
42 #include <qstylefactory.h>
43 #include <qscreen.h>
44 #include <qsignalspy.h>
45 
47 
48 class EventSpy : public QObject
49 {
50  Q_OBJECT
51 public:
53  : _count(0), spied(type)
54  {
55  watched->installEventFilter(this);
56  }
57 
58  int count() const { return _count; }
59 
60 protected:
61  bool eventFilter(QObject *watched, QEvent *event) override
62  {
63  Q_UNUSED(watched);
64  if (event->type() == spied)
65  ++_count;
66  return false;
67  }
68 
69  int _count;
71 };
72 
73 class tst_QGraphicsWidget : public QObject {
75 
76 private slots:
77  void qgraphicswidget();
78 
79  void activation();
80  void boundingRect_data();
81  void boundingRect();
82  void dumpFocusChain_data();
83  void dumpFocusChain();
84  void focusWidget_data();
85  void focusWidget();
86  void focusWidget2();
87  void focusWidget3();
88  void focusPolicy_data();
89  void focusPolicy();
90  void font_data();
91  void font();
92  void fontPropagation();
93  void fontChangedEvent();
94  void fontPropagationWidgetItemWidget();
95  void fontPropagationSceneChange();
96  void geometry_data();
97  void geometry();
98  void geometryChanged();
99  void width();
100  void height();
101  void getContentsMargins_data();
102  void getContentsMargins();
103  void initStyleOption_data();
104  void initStyleOption();
105  void layout_data();
106  void layout();
107  void layoutDirection_data();
108  void layoutDirection();
109  void paint_data();
110  void paint();
111  void palettePropagation();
112  void parentWidget_data();
113  void parentWidget();
114  void resize_data();
115  void resize();
116  void setAttribute_data();
117  void setAttribute();
118  void setStyle_data();
119  void setStyle();
120  void setTabOrder_data();
121  void setTabOrder();
122  void setTabOrderAndReparent();
123  void topLevelWidget_data();
124  void topLevelWidget();
125  void unsetLayoutDirection_data();
126  void unsetLayoutDirection();
127  void focusNextPrevChild_data();
128  void focusNextPrevChild();
129  void verifyFocusChain();
130  void updateFocusChainWhenChildDie();
131  void sizeHint_data();
132  void sizeHint();
133  void consistentPosSizeGeometry_data();
134  void consistentPosSizeGeometry();
135  void setSizes_data();
136  void setSizes();
137  void closePopupOnOutsideClick();
138  void defaultSize();
139  void explicitMouseGrabber();
140  void implicitMouseGrabber();
141  void doubleClickAfterExplicitMouseGrab();
142  void popupMouseGrabber();
143  void windowFlags_data();
144  void windowFlags();
145  void shortcutsDeletion();
146  void painterStateProtectionOnWindowFrame();
147  void ensureClipping();
148  void widgetSendsGeometryChanges();
149  void respectHFW();
150  void addChildInpolishEvent();
151  void polishEvent();
152  void polishEvent2();
153  void autoFillBackground();
154  void initialShow();
155  void itemChangeEvents();
156  void itemSendGeometryPosChangesDeactivated();
157  void fontPropagatesResolveToChildren();
158  void fontPropagatesResolveToGrandChildren();
159  void fontPropagatesResolveInParentChange();
160  void fontPropagatesResolveViaNonWidget();
161  void fontPropagatesResolveFromScene();
162  void tabFocus();
163  void windowFrameSectionAt();
164 
165  // Task fixes
166  void task236127_bspTreeIndexFails();
167  void task243004_setStyleCrash();
168  void task250119_shortcutContext();
169  void QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems();
170  void QT_BUG_12056_tabFocusFirstUnsetWhenRemovingItems();
171  void QTBUG_45867_send_itemChildAddedChange_to_parent();
172 };
173 
174 // Subclass that exposes the protected functions.
176 public:
177  SubQGraphicsWidget(QGraphicsItem *parent = nullptr, Qt::WindowFlags windowFlags = { })
179  { }
180 
181  void initStyleOption(QStyleOption *option) const override
183 
186 
188  { return event(e); }
189 
192 
195 
198 
200  { return QGraphicsWidget::hideEvent(event); }
201 
203  { return QGraphicsWidget::itemChange(change, value); }
204 
206  { return QGraphicsWidget::moveEvent(event); }
207 
209  { return QGraphicsWidget::polishEvent(); }
210 
211  QVariant call_propertyChange(QString const& propertyName, QVariant const& value)
212  { return QGraphicsWidget::propertyChange(propertyName, value); }
213 
216 
219 
221  { return QGraphicsWidget::showEvent(event); }
222 
223  QSizeF call_sizeHint(Qt::SizeHint which, QSizeF const& constraint = QSizeF()) const
224  { return QGraphicsWidget::sizeHint(which, constraint); }
225 
227  { return QGraphicsWidget::updateGeometry(); }
228 
231 
234 
236  {
239  if (hasFocus()) {
241  painter->drawRect(rect());
242  }
243  //painter->drawText(QPointF(0,15), data(0).toString());
244  }
245 
246 protected:
247  bool event(QEvent *event) override
248  {
249  eventCount++;
251  }
252 };
253 
255 {
256 public:
257  SizeHinter(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = { },
258  const QSizeF &min = QSizeF(5,5),
259  const QSizeF &pref = QSizeF(50, 50),
260  const QSizeF &max = QSizeF(500, 500))
261  : QGraphicsWidget(parent, wFlags)
262  {
263  m_sizes[Qt::MinimumSize] = min;
264  m_sizes[Qt::PreferredSize] = pref;
265  m_sizes[Qt::MaximumSize] = max;
266 
267  }
268  void setSizeHint(Qt::SizeHint which, const QSizeF &newSizeHint)
269  {
270  m_sizes[which] = newSizeHint;
271  }
272 
273 protected:
274  QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const override
275  {
276  Q_UNUSED(constraint);
277  return m_sizes[which];
278  }
279 private:
280  QSizeF m_sizes[4];
281 };
282 
283 void tst_QGraphicsWidget::qgraphicswidget()
284 {
287 
288  QVERIFY(!widget.isWindow());
289  QCOMPARE(widget.boundingRect(), QRectF(0, 0, 0, 0));
290  QCOMPARE(widget.focusWidget(), nullptr);
292  QCOMPARE(widget.font(), QFont());
294  QCOMPARE(widget.layout(), nullptr);
297  QCOMPARE(widget.parentWidget(), nullptr);
299  QCOMPARE(widget.size(), QSizeF(0, 0));
300  QVERIFY(widget.style() != (QStyle*)0);
303  QCOMPARE(widget.type(), (int)QGraphicsWidget::Type);
304  QCOMPARE(widget.call_propertyChange(QString(), QVariant()), QVariant());
305  widget.call_sizeHint(Qt::PreferredSize, QSizeF());
306 
310 
311  QCOMPARE(child->minimumSize(), QSizeF(5, 5));
312 }
313 
314 void tst_QGraphicsWidget::activation()
315 {
317  QGraphicsWidget *window1 = new QGraphicsWidget(0, Qt::Window);
318  QGraphicsWidget *window2 = new QGraphicsWidget(0, Qt::Window);
320  QVERIFY(!window1->isActiveWindow());
321  QVERIFY(!window2->isActiveWindow());
322 
325  scene.addItem(window1);
326  scene.addItem(window2);
327 
329  QVERIFY(!window1->isActiveWindow());
330  QVERIFY(!window2->isActiveWindow());
331 
332  QEvent activateEvent(QEvent::WindowActivate);
333  QApplication::sendEvent(&scene, &activateEvent);
334 
336  QVERIFY(window1->isActiveWindow());
337  QVERIFY(!window2->isActiveWindow());
338 
339  scene.setActiveWindow(window1);
341  QVERIFY(window1->isActiveWindow());
342  QVERIFY(!window2->isActiveWindow());
343 
344  QEvent deactivateEvent(QEvent::WindowDeactivate);
345  QApplication::sendEvent(&scene, &deactivateEvent);
346 
348  QVERIFY(!window1->isActiveWindow());
349  QVERIFY(!window2->isActiveWindow());
350 }
351 
352 void tst_QGraphicsWidget::boundingRect_data()
353 {
354  QTest::addColumn<QSizeF>("size");
355  QTest::newRow("null") << QSizeF(0, 0);
356  QTest::newRow("avg") << QSizeF(10, 10);
357 }
358 
359 // QRectF boundingRect() const public
360 void tst_QGraphicsWidget::boundingRect()
361 {
362  QFETCH(QSizeF, size);
364  widget.resize(size);
366  QCOMPARE(widget.boundingRect(), QRectF(QPointF(0, 0), size));
367 }
368 
369 void tst_QGraphicsWidget::dumpFocusChain_data()
370 {
371  QTest::addColumn<bool>("scene");
372  QTest::addColumn<int>("children");
373  QTest::addColumn<bool>("setFocus");
374  QTest::newRow("empty world") << false << 0 << false;
375  QTest::newRow("one world") << true << 2 << false;
376  QTest::newRow("one world w/focus") << true << 2 << true;
377 }
378 
379 // void dumpFocusChain(QGraphicsScene* scene) public (static)
380 void tst_QGraphicsWidget::dumpFocusChain()
381 {
382  // ### this test is very strange...
383  QFETCH(bool, scene);
385  QGraphicsScene *theScene = nullptr;
386  if (scene) {
387  theScene = new QGraphicsScene(this);
388  theScene->addItem(parent);
389  }
390  QFETCH(int, children);
391  QFETCH(bool, setFocus);
392  for (int i = 0; i < children; ++i) {
394  if (setFocus) {
395  widget->setFlag(QGraphicsItem::ItemIsFocusable, true);
396  if (scene)
397  theScene->setFocusItem(widget);
398  }
399  }
400 
401  if (!scene)
402  delete parent;
403 }
404 
405 void tst_QGraphicsWidget::focusWidget_data()
406 {
407  QTest::addColumn<int>("childCount");
408  QTest::addColumn<int>("childWithFocus");
409  QTest::newRow("none") << 0 << 0;
410  QTest::newRow("first") << 3 << 0;
411  QTest::newRow("last") << 3 << 2;
412 }
413 
414 // QGraphicsWidget* focusWidget() const public
415 void tst_QGraphicsWidget::focusWidget()
416 {
418  QCOMPARE(parent->focusWidget(), nullptr);
420  QEvent windowActivate(QEvent::WindowActivate);
421  qApp->sendEvent(&scene, &windowActivate);
423 
424  QFETCH(int, childCount);
426  for (int i = 0; i < childCount; ++i) {
428  widget->setFlag(QGraphicsItem::ItemIsFocusable, true);
430  }
431  if (childCount > 0) {
432  QFETCH(int, childWithFocus);
433  SubQGraphicsWidget *widget = children[childWithFocus];
434  widget->setFocus();
436  QCOMPARE(parent->focusWidget(), static_cast<QGraphicsWidget*>(widget));
437  }
438 }
439 
440 void tst_QGraphicsWidget::focusWidget2()
441 {
443  QEvent windowActivate(QEvent::WindowActivate);
444  qApp->sendEvent(&scene, &windowActivate);
445 
447  EventSpy focusInSpy(widget, QEvent::FocusIn);
448  EventSpy focusOutSpy(widget, QEvent::FocusOut);
449 
451 
455 
456  QGraphicsWidget *subWidget = new QGraphicsWidget(widget);
457  QTRY_VERIFY(!subWidget->hasFocus());
458 
459  scene.setFocus();
460 
462  QTRY_VERIFY(!subWidget->hasFocus());
463 
464  widget->setFocus();
465 
467  QTRY_COMPARE(focusInSpy.count(), 1);
468  QTRY_VERIFY(!subWidget->hasFocus());
469 
470  QGraphicsWidget *otherSubWidget = new QGraphicsWidget;
471  EventSpy otherFocusInSpy(otherSubWidget, QEvent::FocusIn);
472  EventSpy otherFocusOutSpy(otherSubWidget, QEvent::FocusOut);
473 
474  otherSubWidget->setFocusPolicy(Qt::StrongFocus);
475  otherSubWidget->setParentItem(widget);
476 
479  QTRY_VERIFY(!subWidget->hasFocus());
480  QTRY_VERIFY(!otherSubWidget->hasFocus());
481 
482  widget->hide();
483  QTRY_VERIFY(!widget->hasFocus()); // lose but still has subfocus
484  QCOMPARE(focusInSpy.count(), 1);
485  QCOMPARE(focusOutSpy.count(), 1);
486 
487  widget->show();
488  QTRY_VERIFY(!widget->hasFocus()); // no regain
489  QCOMPARE(focusInSpy.count(), 1);
490  QCOMPARE(focusOutSpy.count(), 1);
491 
492  widget->hide();
493 
494  // try to setup subFocus on item that can't take focus
495  subWidget->setFocus();
496  QTRY_VERIFY(!subWidget->hasFocus());
497  QVERIFY(!scene.focusItem()); // but isn't the scene's focus item
498 
499  // try to setup subFocus on item that can take focus
500  otherSubWidget->setFocus();
501  QTRY_VERIFY(!otherSubWidget->hasFocus());
502  QCOMPARE(widget->focusWidget(), otherSubWidget);
503  QVERIFY(!scene.focusItem()); // but isn't the scene's focus item
504 
505  widget->show();
506 
507  QTRY_COMPARE(scene.focusItem(), (QGraphicsItem *)otherSubWidget); // but isn't the scene's focus item
508  QCOMPARE(otherFocusInSpy.count(), 1);
509  QCOMPARE(otherFocusOutSpy.count(), 0);
510 
511  delete otherSubWidget;
512 
513  QTRY_COMPARE(otherFocusOutSpy.count(), 1);
514  QVERIFY(!scene.focusItem());
516 }
517 
519 {
520 public:
524 protected:
525  void focusInEvent(QFocusEvent *fe) override
527  void focusOutEvent(QFocusEvent *fe) override
529 };
530 
531 void tst_QGraphicsWidget::focusWidget3()
532 {
534  QEvent windowActivate(QEvent::WindowActivate);
535  qApp->sendEvent(&scene, &windowActivate);
536 
538  FocusWatchWidget *subWidget = new FocusWatchWidget(widget);
539  subWidget->setFocusPolicy(Qt::StrongFocus);
540 
542  widget->show();
543 
545  QTRY_VERIFY(!subWidget->hasFocus());
546 
547  subWidget->setFocus();
548  QCOMPARE(subWidget->gotFocusInCount, 1);
549  QCOMPARE(subWidget->gotFocusOutCount, 0);
550  widget->hide();
551  QCOMPARE(subWidget->gotFocusOutCount, 1);
552 }
553 
555 void tst_QGraphicsWidget::focusPolicy_data()
556 {
557  QTest::addColumn<Qt::FocusPolicy>("focusPolicy1");
558  QTest::addColumn<Qt::FocusPolicy>("focusPolicy2");
559 
560  for (int i = 0; i < 25; ++i) {
562  switch(i % 5) {
563  case 0: data << Qt::TabFocus; break;
564  case 1: data << Qt::ClickFocus; break;
565  case 2: data << Qt::StrongFocus; break;
566  case 3: data << Qt::WheelFocus; break;
567  case 4: data << Qt::NoFocus; break;
568  }
569  switch(i / 5) {
570  case 0: data << Qt::TabFocus; break;
571  case 1: data << Qt::ClickFocus; break;
572  case 2: data << Qt::StrongFocus; break;
573  case 3: data << Qt::WheelFocus; break;
574  case 4: data << Qt::NoFocus; break;
575  }
576  }
577 }
578 
579 // Qt::FocusPolicy focusPolicy() const public
580 void tst_QGraphicsWidget::focusPolicy()
581 {
583  QEvent windowActivate(QEvent::WindowActivate);
584  qApp->sendEvent(&scene, &windowActivate);
585 
589 
590  QFETCH(Qt::FocusPolicy, focusPolicy1);
591  widget->setFocusPolicy(focusPolicy1);
592  QTRY_COMPARE(widget->focusPolicy(), focusPolicy1);
593  bool isFocusable = widget->flags() & QGraphicsItem::ItemIsFocusable;
594  bool wasFocusable = isFocusable;
595  QTRY_VERIFY(isFocusable == (focusPolicy1 != Qt::NoFocus));
596  widget->setFocus();
597  QTRY_COMPARE(widget->hasFocus(), isFocusable);
598 
599  QFETCH(Qt::FocusPolicy, focusPolicy2);
600  widget->setFocusPolicy(focusPolicy2);
601  QCOMPARE(widget->focusPolicy(), focusPolicy2);
602  isFocusable = widget->flags() & QGraphicsItem::ItemIsFocusable;
603  QVERIFY(isFocusable == (focusPolicy2 != Qt::NoFocus));
604  QCOMPARE(widget->hasFocus(), wasFocusable && isFocusable);
605 }
606 
607 void tst_QGraphicsWidget::font_data()
608 {
609  QTest::addColumn<QString>("fontName");
610  QTest::newRow("Helvetica") << "Helvetica";
611 }
612 
613 // QFont font() const public
614 void tst_QGraphicsWidget::font()
615 {
618  QCOMPARE(widget.font(), QFont());
619 
620  QFont font(fontName);
621  widget.setFont(font);
622  QCOMPARE(widget.font().family(), font.family());
623 }
624 
625 void tst_QGraphicsWidget::fontPropagatesResolveToChildren()
626 {
627  QGraphicsWidget *root = new QGraphicsWidget();
628  QGraphicsWidget *child1 = new QGraphicsWidget(root);
629 
631  scene.addItem(root);
632 
633  QFont font;
634  font.setItalic(true);
635  root->setFont(font);
636 
637  QGraphicsWidget *child2 = new QGraphicsWidget(root);
638  QGraphicsWidget *child3 = new QGraphicsWidget();
639  child3->setParentItem(root);
640 
642  view.setScene(&scene);
643  view.show();
645 
651 }
652 
653 void tst_QGraphicsWidget::fontPropagatesResolveToGrandChildren()
654 {
655  QGraphicsWidget *root = new QGraphicsWidget();
656  QGraphicsWidget *child1 = new QGraphicsWidget(root);
657  QGraphicsWidget *grandChild1 = new QGraphicsWidget(child1);
658 
660  scene.addItem(root);
661 
662  QFont font;
663  font.setItalic(true);
664  root->setFont(font);
665 
666  QGraphicsWidget *child2 = new QGraphicsWidget(root);
667  QGraphicsWidget *grandChild2 = new QGraphicsWidget(child2);
668  QGraphicsWidget *grandChild3 = new QGraphicsWidget(child2);
669 
670  QGraphicsWidget *child3 = new QGraphicsWidget();
671  QGraphicsWidget *grandChild4 = new QGraphicsWidget(child3);
672  QGraphicsWidget *grandChild5 = new QGraphicsWidget(child3);
673  child3->setParentItem(root);
674  grandChild5->setParentItem(child3);
675 
677  view.setScene(&scene);
678  view.show();
680 
682  QCOMPARE(grandChild1->font().resolveMask(), uint(QFont::StyleResolved));
683  QCOMPARE(grandChild2->font().resolveMask(), uint(QFont::StyleResolved));
684  QCOMPARE(grandChild3->font().resolveMask(), uint(QFont::StyleResolved));
685  QCOMPARE(grandChild4->font().resolveMask(), uint(QFont::StyleResolved));
686  QCOMPARE(grandChild5->font().resolveMask(), uint(QFont::StyleResolved));
687 }
688 
689 void tst_QGraphicsWidget::fontPropagatesResolveViaNonWidget()
690 {
691  QGraphicsWidget *root = new QGraphicsWidget();
692  QGraphicsPixmapItem *child1 = new QGraphicsPixmapItem(root);
693  QGraphicsWidget *grandChild1 = new QGraphicsWidget(child1);
694 
696  scene.addItem(root);
697 
698  QFont font;
699  font.setItalic(true);
700  root->setFont(font);
701 
702  QGraphicsPixmapItem *child2 = new QGraphicsPixmapItem(root);
703  QGraphicsWidget *grandChild2 = new QGraphicsWidget(child2);
704  QGraphicsWidget *grandChild3 = new QGraphicsWidget(child2);
705 
707  QGraphicsWidget *grandChild4 = new QGraphicsWidget(child3);
708  QGraphicsWidget *grandChild5 = new QGraphicsWidget(child3);
709  child3->setParentItem(root);
710  grandChild5->setParentItem(child3);
711 
713  view.setScene(&scene);
714  view.show();
716 
718  QCOMPARE(grandChild1->font().resolveMask(), uint(QFont::StyleResolved));
719  QCOMPARE(grandChild2->font().resolveMask(), uint(QFont::StyleResolved));
720  QCOMPARE(grandChild3->font().resolveMask(), uint(QFont::StyleResolved));
721  QCOMPARE(grandChild4->font().resolveMask(), uint(QFont::StyleResolved));
722  QCOMPARE(grandChild5->font().resolveMask(), uint(QFont::StyleResolved));
723 }
724 
725 void tst_QGraphicsWidget::fontPropagatesResolveFromScene()
726 {
727  QGraphicsWidget *root = new QGraphicsWidget();
728  QGraphicsWidget *child1 = new QGraphicsWidget(root);
729  QGraphicsWidget *grandChild1 = new QGraphicsWidget(child1);
730 
732  scene.addItem(root);
733 
734  QFont font;
735  font.setItalic(true);
736  scene.setFont(font);
737 
738  QGraphicsWidget *child2 = new QGraphicsWidget(root);
739  QGraphicsWidget *grandChild2 = new QGraphicsWidget(child2);
740  QGraphicsWidget *grandChild3 = new QGraphicsWidget(child2);
741 
742  QGraphicsWidget *child3 = new QGraphicsWidget();
743  QGraphicsWidget *grandChild4 = new QGraphicsWidget(child3);
744  QGraphicsWidget *grandChild5 = new QGraphicsWidget(child3);
745  child3->setParentItem(root);
746  grandChild5->setParentItem(child3);
747 
749  view.setScene(&scene);
750  view.show();
752 
758  QCOMPARE(grandChild1->font().resolveMask(), uint(QFont::StyleResolved));
759  QCOMPARE(grandChild2->font().resolveMask(), uint(QFont::StyleResolved));
760  QCOMPARE(grandChild3->font().resolveMask(), uint(QFont::StyleResolved));
761  QCOMPARE(grandChild4->font().resolveMask(), uint(QFont::StyleResolved));
762  QCOMPARE(grandChild5->font().resolveMask(), uint(QFont::StyleResolved));
763 }
764 
765 void tst_QGraphicsWidget::fontPropagatesResolveInParentChange()
766 {
767  QGraphicsWidget *root = new QGraphicsWidget();
768 
769  QGraphicsWidget *child1 = new QGraphicsWidget(root);
770  QGraphicsWidget *grandChild1 = new QGraphicsWidget(child1);
771 
772  QGraphicsWidget *child2 = new QGraphicsWidget(root);
773  QGraphicsWidget *grandChild2 = new QGraphicsWidget(child2);
774 
776  scene.addItem(root);
777 
778  QFont italicFont;
779  italicFont.setItalic(true);
780  child1->setFont(italicFont);
781 
782  QFont boldFont;
783  boldFont.setBold(true);
784  child2->setFont(boldFont);
785 
786  QVERIFY(grandChild1->font().italic());
787  QVERIFY(!grandChild1->font().bold());
788  QVERIFY(!grandChild2->font().italic());
789  QVERIFY(grandChild2->font().bold());
790 
791  QCOMPARE(grandChild1->font().resolveMask(), uint(QFont::StyleResolved));
792  QCOMPARE(grandChild2->font().resolveMask(), uint(QFont::WeightResolved));
793 
794  grandChild2->setParentItem(child1);
795 
797  view.setScene(&scene);
798  view.show();
800 
801  QVERIFY(grandChild1->font().italic());
802  QVERIFY(!grandChild1->font().bold());
803  QVERIFY(grandChild2->font().italic());
804  QVERIFY(!grandChild2->font().bold());
805 
806  QCOMPARE(grandChild1->font().resolveMask(), uint(QFont::StyleResolved));
807  QCOMPARE(grandChild2->font().resolveMask(), uint(QFont::StyleResolved));
808 
809 }
810 
811 void tst_QGraphicsWidget::fontPropagation()
812 {
813  QGraphicsWidget *root = new QGraphicsWidget;
814  QGraphicsWidget *child0 = new QGraphicsWidget(root);
815  QGraphicsWidget *child1 = new QGraphicsWidget(child0);
816  QGraphicsWidget *child2 = new QGraphicsWidget(child1);
818  scene.addItem(root);
819 
820  // Check that only the application fonts apply.
821  QFont appFont = QApplication::font();
822  QCOMPARE(scene.font(), appFont);
823  QCOMPARE(root->font(), appFont);
824  QCOMPARE(child0->font(), appFont);
825  QCOMPARE(child1->font(), appFont);
826 
827  // Set child0's Text, and set ToolTipBase on child1.
828  QFont boldFont;
829  boldFont.setBold(true);
830  child0->setFont(boldFont);
831  QFont italicFont;
832  italicFont.setItalic(true);
833  child1->setFont(italicFont);
834 
835  // Check that the above settings propagate correctly.
836  QCOMPARE(root->font(), appFont);
837  QCOMPARE(scene.font(), appFont);
838  QVERIFY(child0->font().bold());
839  QVERIFY(!child0->font().italic());
840  QVERIFY(child1->font().bold());
841  QVERIFY(child1->font().italic());
842  QVERIFY(child2->font().bold());
843  QVERIFY(child2->font().italic());
844 
845  QGraphicsWidget *child3 = new QGraphicsWidget(child2);
846  QVERIFY(child3->font().bold());
847  QVERIFY(child3->font().italic());
848 
849  QGraphicsWidget *child4 = new QGraphicsWidget;
850  child4->setParentItem(child3);
851  QVERIFY(child4->font().bold());
852  QVERIFY(child4->font().italic());
853 
854  // Replace the app font for child2. Button should propagate but Text
855  // should still be ignored. The previous ToolTipBase setting is gone.
856  QFont sizeFont;
857  sizeFont.setPointSize(43);
858  child1->setFont(sizeFont);
859 
860  // Check that the above settings propagate correctly.
861  QCOMPARE(root->font(), appFont);
862  QCOMPARE(scene.font(), appFont);
863  QVERIFY(child0->font().bold());
864  QVERIFY(!child0->font().italic());
865  QVERIFY(child1->font().bold());
866  QVERIFY(!child1->font().italic());
867  QCOMPARE(child1->font().pointSize(), 43);
868  QVERIFY(child2->font().bold());
869  QVERIFY(!child2->font().italic());
870  QCOMPARE(child2->font().pointSize(), 43);
871 }
872 
873 void tst_QGraphicsWidget::fontChangedEvent()
874 {
875  QGraphicsWidget *root = new QGraphicsWidget;
877  scene.addItem(root);
878 
879  // Check that only the application fonts apply.
880  QFont appFont = QApplication::font();
881  QCOMPARE(scene.font(), appFont);
882  QCOMPARE(root->font(), appFont);
883 
884  EventSpy rootSpyFont(root, QEvent::FontChange);
885  EventSpy rootSpyPolish(root, QEvent::Polish);
886  QTRY_COMPARE(rootSpyFont.count(), 0);
887  QTRY_COMPARE(rootSpyPolish.count(), 1);
888  //The font is still the same so no fontChangeEvent
889  QTRY_COMPARE(rootSpyFont.count(), 0);
890 
891  QFont font;
892  font.setPointSize(43);
893  root->setFont(font);
894  //The font changed
895  QTRY_COMPARE(rootSpyFont.count(), 1);
896 
897  //then roll back to the default one.
898  root->setFont(appFont);
899  //The font changed
900  QTRY_COMPARE(rootSpyFont.count(), 2);
901 }
902 
903 void tst_QGraphicsWidget::fontPropagationWidgetItemWidget()
904 {
907  QGraphicsWidget *widget2 = new QGraphicsWidget(rect);
908 
911 
912  QFont font;
913  font.setPointSize(43);
914  widget->setFont(font);
915 
916  QCOMPARE(widget2->font().pointSize(), 43);
918 
919  widget->setFont(QFont());
920 
921  QCOMPARE(widget2->font().pointSize(), qApp->font().pointSize());
922  QCOMPARE(widget2->font().resolveMask(), QFont().resolveMask());
923 }
924 
925 void tst_QGraphicsWidget::fontPropagationSceneChange()
926 {
929  QGraphicsWidget *widget2 = new QGraphicsWidget(rect);
930 
932  QGraphicsScene scene2;
933 
934  QFont font;
935  font.setPointSize(47);
936  scene.setFont(font);
937 
938  QFont font2;
939  font2.setPointSize(74);
940  scene2.setFont(font2);
941 
943  QCOMPARE(widget2->font().pointSize(), 47);
944  scene2.addItem(widget);
945  QCOMPARE(widget2->font().pointSize(), 74);
946 }
947 
948 void tst_QGraphicsWidget::geometry_data()
949 {
950  QTest::addColumn<QPointF>("pos");
951  QTest::addColumn<QSizeF>("size");
952  QTest::newRow("null, null") << QPointF() << QSizeF(0, 0);
953  QTest::newRow("null, normal") << QPointF() << QSizeF(10, 10);
954  QTest::newRow("neg, normal") << QPointF(-5, -5) << QSizeF(10, 10);
955 }
956 
957 // QRectF geometry() const public
958 void tst_QGraphicsWidget::geometry()
959 {
962  QSignalSpy spy(&widget, SIGNAL(geometryChanged()));
963  QFETCH(QPointF, pos);
964  QFETCH(QSizeF, size);
965  widget.setPos(pos);
966  widget.resize(size);
967  if (!size.isNull() && !pos.isNull())
968  QCOMPARE(spy.count(), 2);
969  if (!size.isNull() && pos.isNull())
970  QCOMPARE(spy.count(), 1);
972 }
973 
974 void tst_QGraphicsWidget::geometryChanged()
975 {
977  w.setGeometry(0, 0, 200, 200);
978  QCOMPARE(w.geometry(), QRectF(0, 0, 200, 200));
979  QSignalSpy spy(&w, SIGNAL(geometryChanged()));
980  w.setGeometry(0, 0, 100, 100);
981  QCOMPARE(spy.count(), 1);
982  QCOMPARE(w.geometry(), QRectF(0, 0, 100, 100));
983  w.setPos(10, 10);
984  QCOMPARE(spy.count(), 2);
985  QCOMPARE(w.geometry(), QRectF(10, 10, 100, 100));
986 
987 }
988 
989 void tst_QGraphicsWidget::width()
990 {
992  QCOMPARE(w.property("width").toReal(), qreal(0));
993  QSignalSpy spy(&w, SIGNAL(widthChanged()));
994  w.setProperty("width", qreal(50));
995  QCOMPARE(w.property("width").toReal(), qreal(50));
996  QCOMPARE(spy.count(), 1);
997  //calling old school setGeometry should work too
998  w.setGeometry(0, 0, 200, 200);
999  QCOMPARE(spy.count(), 2);
1000 }
1001 
1002 void tst_QGraphicsWidget::height()
1003 {
1005  QCOMPARE(w.property("height").toReal(), qreal(0));
1006  QSignalSpy spy(&w, SIGNAL(heightChanged()));
1007  w.setProperty("height", qreal(50));
1008  QCOMPARE(w.property("height").toReal(), qreal(50));
1009  QCOMPARE(spy.count(), 1);
1010  //calling old school setGeometry should work too
1011  w.setGeometry(0, 0, 200, 200);
1012  QCOMPARE(spy.count(), 2);
1013 }
1014 
1015 void tst_QGraphicsWidget::getContentsMargins_data()
1016 {
1017  QTest::addColumn<qreal>("left");
1018  QTest::addColumn<qreal>("top");
1019  QTest::addColumn<qreal>("right");
1020  QTest::addColumn<qreal>("bottom");
1021  QTest::newRow("null") << (qreal)0 << (qreal)0 << (qreal)0 << (qreal)0;
1022  QTest::newRow("something") << (qreal)10 << (qreal)5 << (qreal)3 << (qreal)7;
1023  QTest::newRow("real") << (qreal)1.7 << (qreal)5.9 << (qreal)3.2 << (qreal)9.7;
1024 }
1025 
1026 // void getContentsMargins(qreal* left, qreal* top, qreal* right, qreal* bottom) const public
1027 void tst_QGraphicsWidget::getContentsMargins()
1028 {
1029  qreal gleft;
1030  qreal gtop;
1031  qreal gright;
1032  qreal gbottom;
1033 
1035  widget.getContentsMargins(&gleft, &gtop, &gright, &gbottom);
1036  QCOMPARE(gleft, (qreal)0);
1037  QCOMPARE(gtop, (qreal)0);
1038  QCOMPARE(gright, (qreal)0);
1039  QCOMPARE(gbottom, (qreal)0);
1040 
1041  QFETCH(qreal, left);
1042  QFETCH(qreal, top);
1043  QFETCH(qreal, right);
1044  QFETCH(qreal, bottom);
1045  int oldEventCounts = widget.eventCount;
1047  QVERIFY(left == 0 || oldEventCounts != widget.eventCount);
1048  widget.getContentsMargins(&gleft, &gtop, &gright, &gbottom);
1049  QCOMPARE(gleft, left);
1050  QCOMPARE(gtop, top);
1051  QCOMPARE(gright, right);
1052  QCOMPARE(gbottom, bottom);
1053 }
1054 
1056 void tst_QGraphicsWidget::initStyleOption_data()
1057 {
1058  QTest::addColumn<bool>("enabled");
1059  QTest::addColumn<bool>("focus");
1060  QTest::addColumn<bool>("underMouse");
1061  QTest::addColumn<Qt::LayoutDirection>("layoutDirection");
1062  QTest::addColumn<QSizeF>("size");
1063  QTest::addColumn<QPalette>("palette");
1064  QTest::addColumn<QString>("fontName");
1065  QTest::newRow("none") << false << false << false << Qt::LeftToRight << QSizeF(0, 0) << QPalette() << QString();
1066  QTest::newRow("all") << true << true << true << Qt::RightToLeft << QSizeF(300, 300) << QPalette(Qt::magenta) << "Helvetica";
1067  QTest::newRow("rand") << true << false << false << Qt::RightToLeft << QSizeF(1, 0) << QPalette(Qt::darkCyan) << "Times";
1068 }
1069 
1070 // void initStyleOption(QStyleOption* option) const public
1071 void tst_QGraphicsWidget::initStyleOption()
1072 {
1075  view.resize(300, 300);
1076  view.show();
1078 
1079  view.setAlignment(Qt::AlignTop | Qt::AlignLeft);
1081  widget->setAcceptHoverEvents(true);
1083  scene.addItem(widget);
1084 
1085  QFETCH(QSizeF, size);
1086  widget->resize(size);
1087 
1088  QFETCH(bool, enabled);
1090  QFETCH(bool, focus);
1091  if (focus) {
1092  widget->setFlag(QGraphicsItem::ItemIsFocusable, true);
1093  widget->setFocus();
1094  QVERIFY(widget->hasFocus());
1095  }
1096  QFETCH(bool, underMouse);
1097  if (underMouse) {
1098  QCursor::setPos(view.viewport()->mapToGlobal(view.mapFromScene(widget->mapToScene(widget->boundingRect().center()))));
1099  QTest::qWait(100);
1100  }
1101 
1104 
1107 
1108  // The test
1109  widget->initStyleOption(&option);
1110 
1111  bool isEnabled = option.state & QStyle::State_Enabled;
1112  QCOMPARE(isEnabled, enabled);
1113  bool hasFocus = option.state & QStyle::State_HasFocus;
1114  QCOMPARE(hasFocus, focus);
1115  bool isUnderMouse = option.state & QStyle::State_MouseOver;
1116  QCOMPARE(isUnderMouse, underMouse);
1117  // if (layoutDirection != Qt::LeftToRight)
1118  //QEXPECT_FAIL("", "QApplicaiton::layoutDirection doesn't propagate to QGraphicsWidget", Continue);
1119  //QCOMPARE(option.direction, layoutDirection);
1120  QCOMPARE(option.rect, QRectF(QPointF(), size).toRect());
1121  QCOMPARE(option.palette, palette.resolve(QApplication::palette()));
1122  QCOMPARE(option.fontMetrics, QFontMetrics(widget->font()));
1123 }
1124 
1125 void tst_QGraphicsWidget::layout_data()
1126 {
1127  QTest::addColumn<int>("childCount");
1128  QTest::newRow("empty") << 0;
1129  QTest::newRow("10") << 10;
1130 }
1131 
1132 // QGraphicsLayout* layout() const public
1133 void tst_QGraphicsWidget::layout()
1134 {
1136  widget.setContentsMargins(10, 5, 50, 100);
1137  QCOMPARE(widget.layout(), nullptr);
1138  QFETCH(int, childCount);
1139 
1142  for (int i = 0; i < childCount; ++i) {
1144  layout->addItem(item);
1145  children.append(item);
1146  }
1147  QSignalSpy spy(&widget, SIGNAL(layoutChanged()));
1148  widget.setLayout(layout);
1149 
1150  QTRY_COMPARE(widget.layout(), static_cast<QGraphicsLayout*>(layout));
1151  for (int i = 0; i < children.count(); ++i) {
1154  QVERIFY(item->geometry() != QRectF(0, 0, -1, -1));
1155  }
1156  QCOMPARE(spy.count(), 1);
1157  // don't crash
1158  widget.setLayout(0);
1159 }
1160 
1161 void tst_QGraphicsWidget::layoutDirection_data()
1162 {
1163  QTest::addColumn<Qt::LayoutDirection>("layoutDirection");
1164  QTest::newRow("rtl") << Qt::RightToLeft;
1165  QTest::newRow("ltr") << Qt::LeftToRight;
1166 }
1167 
1168 // Qt::LayoutDirection layoutDirection() const public
1169 void tst_QGraphicsWidget::layoutDirection()
1170 {
1171  QFETCH(Qt::LayoutDirection, layoutDirection);
1175  scene.addItem(&widget);
1178 
1180  for (int i = 0; i < 10; ++i) {
1182  children.append(item);
1183  QCOMPARE(item->testAttribute(Qt::WA_SetLayoutDirection), false);
1184  }
1185  widget.setLayoutDirection(layoutDirection);
1187  view->show();
1189  for (int i = 0; i < children.count(); ++i) {
1190  QTRY_COMPARE(children[i]->layoutDirection(), layoutDirection);
1191  QTRY_COMPARE(children[i]->testAttribute(Qt::WA_SetLayoutDirection), false);
1192  view->update();
1193  QTRY_COMPARE(children[i]->m_painterLayoutDirection, layoutDirection);
1194  }
1195 }
1196 
1197 void tst_QGraphicsWidget::paint_data()
1198 {
1199  // currently QGraphicsWidget doesn't paint or do anything ...
1200 }
1201 
1202 // void paint(QPainter* painter, QStyleOptionGraphicsItem const* option, QWidget* widget) public
1203 void tst_QGraphicsWidget::paint()
1204 {
1206  QPainter painter;
1208  widget.paint(&painter, &option, 0); // check that widget = 0 works.
1209 }
1210 
1211 void tst_QGraphicsWidget::palettePropagation()
1212 {
1213  QGraphicsWidget *root = new QGraphicsWidget;
1214  QGraphicsWidget *child0 = new QGraphicsWidget(root);
1215  QGraphicsWidget *child1 = new QGraphicsWidget(child0);
1216  QGraphicsWidget *child2 = new QGraphicsWidget(child1);
1218  scene.addItem(root);
1219 
1220  // These colors are unlikely to be imposed on the default palette of
1221  // QWidget ;-).
1222  QColor overridePalText(42, 43, 44);
1223  QColor overridePalToolTipBase(45, 46, 47);
1224  QColor sysPalButton(99, 98, 97);
1225 
1226  // Check that only the application fonts apply.
1227  QPalette appPal = QApplication::palette();
1228  QCOMPARE(scene.palette(), appPal);
1229  QCOMPARE(root->palette(), appPal);
1230  QCOMPARE(child0->palette(), appPal);
1231  QCOMPARE(child1->palette(), appPal);
1232 
1233  // Set child0's Text, and set ToolTipBase on child1.
1234  QPalette textPalette;
1235  textPalette.setColor(QPalette::Text, overridePalText);
1236  child0->setPalette(textPalette);
1237  QPalette toolTipPalette;
1238  toolTipPalette.setColor(QPalette::ToolTipBase, overridePalToolTipBase);
1239  child1->setPalette(toolTipPalette);
1240 
1241  // Check that the above settings propagate correctly.
1242  QCOMPARE(root->palette(), appPal);
1243  QCOMPARE(scene.palette(), appPal);
1244  QCOMPARE(child0->palette().color(QPalette::Text), overridePalText);
1246  QCOMPARE(child1->palette().color(QPalette::Text), overridePalText);
1247  QCOMPARE(child1->palette().color(QPalette::ToolTipBase), overridePalToolTipBase);
1248  QCOMPARE(child2->palette().color(QPalette::Text), overridePalText);
1249  QCOMPARE(child2->palette().color(QPalette::ToolTipBase), overridePalToolTipBase);
1250 
1251  QGraphicsWidget *child3 = new QGraphicsWidget(child2);
1252  QCOMPARE(child3->palette().color(QPalette::Text), overridePalText);
1253  QCOMPARE(child3->palette().color(QPalette::ToolTipBase), overridePalToolTipBase);
1254 
1255  QGraphicsWidget *child4 = new QGraphicsWidget;
1256  child4->setParentItem(child3);
1257  QCOMPARE(child4->palette().color(QPalette::Text), overridePalText);
1258  QCOMPARE(child4->palette().color(QPalette::ToolTipBase), overridePalToolTipBase);
1259 
1260  // Replace the app palette for child2. Button should propagate but Text
1261  // should still be ignored. The previous ToolTipBase setting is gone.
1262  QPalette buttonPalette;
1263  buttonPalette.setColor(QPalette::Button, sysPalButton);
1264  child1->setPalette(buttonPalette);
1265 
1266  QCOMPARE(root->palette(), appPal);
1267  QCOMPARE(scene.palette(), appPal);
1268  QCOMPARE(child0->palette().color(QPalette::Text), overridePalText);
1270  QCOMPARE(child1->palette().color(QPalette::Text), overridePalText);
1272  QCOMPARE(child1->palette().color(QPalette::Button), sysPalButton);
1273  QCOMPARE(child2->palette().color(QPalette::Text), overridePalText);
1275  QCOMPARE(child2->palette().color(QPalette::Button), sysPalButton);
1276 }
1277 
1278 void tst_QGraphicsWidget::parentWidget_data()
1279 {
1280  QTest::addColumn<int>("childrenCount");
1281  QTest::newRow("0") << 0;
1282  QTest::newRow("1") << 1;
1283  QTest::newRow("10") << 10;
1284 }
1285 
1286 // QGraphicsWidget* parentWidget() const public
1287 void tst_QGraphicsWidget::parentWidget()
1288 {
1289  QFETCH(int, childrenCount);
1290  SubQGraphicsWidget standAlongWidget;
1291  QGraphicsLineItem standAlongItem;
1292 
1293  SubQGraphicsWidget widgetChild(&standAlongWidget);
1294  SubQGraphicsWidget itemChild(&standAlongItem);
1295 
1296  QCOMPARE(standAlongWidget.parentWidget(), nullptr);
1297  QCOMPARE(widgetChild.parentWidget(), static_cast<QGraphicsWidget*>(&standAlongWidget));
1298  QCOMPARE(itemChild.parentWidget(), nullptr);
1299 
1300  for (int i = 0; i < childrenCount; ++i) {
1301  SubQGraphicsWidget *item = new SubQGraphicsWidget(&standAlongWidget);
1302  QCOMPARE(item->parentWidget(), static_cast<QGraphicsWidget*>(&standAlongWidget));
1303  }
1304 }
1305 
1306 void tst_QGraphicsWidget::resize_data()
1307 {
1308  QTest::addColumn<QSizeF>("size");
1309  QTest::newRow("null") << QSizeF();
1310  QTest::newRow("10x10") << QSizeF(10, 10);
1311  QTest::newRow("10x-1") << QSizeF(10, -1);
1312 }
1313 
1314 // void resize(qreal w, qreal h) public
1315 void tst_QGraphicsWidget::resize()
1316 {
1317  QFETCH(QSizeF, size);
1319 
1320  int oldEventCounts = widget.eventCount;
1321  QSizeF oldSize = widget.size();
1322  widget.resize(size);
1323 
1325  QCOMPARE(widget.eventCount, oldEventCounts + ((oldSize == boundedSize) ? 0 : 1));
1326  QCOMPARE(widget.size(), boundedSize);
1327 }
1328 
1330 void tst_QGraphicsWidget::setAttribute_data()
1331 {
1332  QTest::addColumn<Qt::WidgetAttribute>("attribute");
1333  QTest::addColumn<bool>("supported");
1334  QTest::newRow("WA_SetLayoutDirection") << Qt::WA_SetLayoutDirection << true;
1335  QTest::newRow("WA_RightToLeft") << Qt::WA_RightToLeft << true;
1336  QTest::newRow("WA_SetStyle") << Qt::WA_SetStyle << true;
1337  QTest::newRow("WA_Resized") << Qt::WA_Resized << true;
1338 }
1339 
1340 // void setAttribute(Qt::WidgetAttribute attribute, bool on = true) public
1341 void tst_QGraphicsWidget::setAttribute()
1342 {
1344  QFETCH(bool, supported);
1347  QCOMPARE(widget.testAttribute(attribute), supported);
1348 }
1349 
1350 void tst_QGraphicsWidget::setStyle_data()
1351 {
1352  QTest::addColumn<QString>("style");
1353  QTest::newRow("null") << "";
1354  QTest::newRow("fusion") << "Fusion";
1355 }
1356 
1357 // void setStyle(QStyle* style) public
1358 void tst_QGraphicsWidget::setStyle()
1359 {
1360 #ifndef Q_NO_STYLE_FUSION
1362 
1363  int oldEventCounts = widget.eventCount;
1364 
1365  QFETCH(QString, style);
1366  if (!style.isEmpty()) {
1367  QStyle *fstyle = QStyleFactory::create(style);
1368  widget.setStyle(fstyle);
1369  QCOMPARE(widget.style(), static_cast<QStyle*>(fstyle));
1370  } else {
1371  widget.setStyle(0);
1372  QVERIFY(widget.style() != (QStyle *)0);
1373  }
1374  QCOMPARE(widget.eventCount, oldEventCounts + 1);
1376 
1377  // cleanup
1378  widget.setStyle(0);
1379 #else
1380  QSKIP("This test requires the Fusion style");
1381 #endif
1382 }
1383 
1384 void tst_QGraphicsWidget::setTabOrder_data()
1385 {
1386  QTest::addColumn<int>("childrenCount");
1387  QTest::newRow("0") << 0;
1388  QTest::newRow("1") << 1;
1389  QTest::newRow("10") << 10;
1390 }
1391 
1392 // void setTabOrder(QGraphicsWidget* first, QGraphicsWidget* second) public
1393 void tst_QGraphicsWidget::setTabOrder()
1394 {
1395  QFETCH(int, childrenCount);
1398  view.show();
1401 
1402  QGraphicsWidget *lastItem = nullptr;
1403  QTest::ignoreMessage(QtWarningMsg, "QGraphicsWidget::setTabOrder(0, 0) is undefined");
1405 
1407  for (int i = 0; i < childrenCount; ++i) {
1409  item->setFocusPolicy(Qt::TabFocus);
1410  children.append(item);
1411  scene.addItem(item);
1412  if (lastItem)
1414  lastItem = item;
1415  }
1416 
1417  if (!children.isEmpty()) {
1419  view.viewport()->setFocus();
1420  QTRY_VERIFY(view.viewport()->hasFocus());
1421  first->setFocus();
1422  QVERIFY(first->hasFocus());
1423  QVERIFY(scene.hasFocus());
1424  QVERIFY(view.viewport()->hasFocus());
1425 
1426  int currentItem = 0;
1427  while (currentItem < children.count() - 1) {
1428  QTest::keyPress(view.viewport(), Qt::Key_Tab);
1429  ++currentItem;
1430  QVERIFY(children[currentItem % children.size()]->hasFocus());
1431  }
1432  }
1433 }
1434 
1435 template <class Iterator>
1437  Iterator i1, Iterator i2,
1438  QByteArray *errorMessage)
1439 {
1440  QGraphicsScene *scene = view->scene();
1441  QGraphicsItem *oldFocusItem = scene->focusItem();
1442  Iterator last = i2 - 1;
1443  for (Iterator i = i1; i != i2; ++i) {
1444  QGraphicsItem *actualFocusItem = scene->focusItem();
1445  QGraphicsItem *expectedFocusItem = *i;
1446  if (actualFocusItem != expectedFocusItem) {
1447  *errorMessage = "Actual:" + actualFocusItem->data(0).toByteArray()
1448  + " expected:" + expectedFocusItem->data(0).toByteArray();
1449  scene->setFocusItem(oldFocusItem);
1450  return false;
1451  }
1452  if (i != last)
1453  QTest::keyPress(view, Qt::Key_Tab);
1454  }
1455  scene->setFocusItem(oldFocusItem);
1456  return true;
1457 }
1458 
1459 template <class Container>
1461  QByteArray *errorMessage)
1462 {
1463  return compareFocusChain(view, c.constBegin(), c.constEnd(), errorMessage);
1464 }
1465 
1466 void tst_QGraphicsWidget::setTabOrderAndReparent()
1467 {
1470  view.show();
1474 
1475  QGraphicsWidget *w[4];
1476  for (int i = 0; i < 3; ++i) {
1477  w[i] = new QGraphicsWidget;
1479  w[i]->setData(0, 'w' + QByteArray::number(i + 1));
1480  scene.addItem(w[i]);
1481  }
1482 
1483  w[0]->setFocus();
1484  QTRY_VERIFY(w[0]->hasFocus());
1485  QByteArray errorMessage;
1486  QVERIFY2(compareFocusChain(&view, w, w + 3, &errorMessage), errorMessage.constData());
1487 
1489  p->setData(0, QLatin1String("parent"));
1490  p->setFocusPolicy(Qt::StrongFocus);
1491 
1492  w[0]->setFocus();
1493  QVERIFY2(compareFocusChain(&view, w, w + 3, &errorMessage), errorMessage.constData());
1494 
1495  w[0]->setParentItem(p);
1496  w[1]->setFocus();
1497  QVERIFY2(compareFocusChain(&view, w + 1, w + 3, &errorMessage), errorMessage.constData());
1498 
1499  w[1]->setParentItem(p);
1500  w[2]->setFocus();
1501  QVERIFY2(compareFocusChain(&view, w + 2, w + 3, &errorMessage), errorMessage.constData());
1502  w[2]->setParentItem(p);
1503  QCOMPARE(scene.focusItem(), nullptr);
1504 
1505  scene.addItem(p);
1506  p->setFocus();
1507 
1508  QVERIFY2(compareFocusChain(&view, QGraphicsItemList() << p << w[0] << w[1] << w[2],
1509  &errorMessage), errorMessage.constData());
1510  delete p;
1511 
1512  for (int i = 0; i < 4; ++i) {
1513  w[i] = new QGraphicsWidget;
1515  w[i]->setData(0, 'w' + QByteArray::number(i + 1));
1516  scene.addItem(w[i]);
1517  }
1518 
1519  w[3]->setParentItem(w[0]);
1521  w[0]->setFocus();
1522  QVERIFY2(compareFocusChain(&view, QGraphicsItemList() << w[0] << w[3] << w[1] << w[2],
1523  &errorMessage), errorMessage.constData());
1524 
1525  p = new QGraphicsWidget;
1526  p->setData(0, QLatin1String("parent"));
1527  p->setFocusPolicy(Qt::StrongFocus);
1528 
1529  w[0]->setParentItem(p);
1530  w[1]->setFocus();
1531  QVERIFY2(compareFocusChain(&view, w + 1, w + 3, &errorMessage), errorMessage.constData());
1532 
1533  scene.addItem(p);
1534  w[1]->setFocus();
1535  QVERIFY2(compareFocusChain(&view, QGraphicsItemList() << w[1] << w[2] << p << w[0] << w[3],
1536  &errorMessage), errorMessage.constData());
1537 }
1538 
1539 void tst_QGraphicsWidget::topLevelWidget_data()
1540 {
1541  QTest::addColumn<QString>("str");
1542  QTest::newRow("test one") << "foo";
1543 }
1544 
1545 // QGraphicsWidget* topLevelWidget() const public
1546 void tst_QGraphicsWidget::topLevelWidget()
1547 {
1548  QFETCH(QString, str);
1551 }
1552 
1553 void tst_QGraphicsWidget::unsetLayoutDirection_data()
1554 {
1555  QTest::addColumn<Qt::LayoutDirection>("layoutDirection");
1556  QTest::newRow("rtl") << Qt::RightToLeft;
1557  QTest::newRow("ltr") << Qt::LeftToRight;
1558 }
1559 
1560 // void unsetLayoutDirection() public
1561 void tst_QGraphicsWidget::unsetLayoutDirection()
1562 {
1564  QFETCH(Qt::LayoutDirection, layoutDirection);
1567 
1569  for (int i = 0; i < 10; ++i) {
1571  children.append(item);
1572  }
1573  widget.setLayoutDirection(layoutDirection);
1576  for (int i = 0; i < children.count(); ++i) {
1577  QCOMPARE(children[i]->layoutDirection(), Qt::LeftToRight);
1578  }
1579 }
1580 
1581 void tst_QGraphicsWidget::focusNextPrevChild_data()
1582 {
1583  QTest::addColumn<QString>("str");
1584  QTest::newRow("test one") << "foo";
1585 }
1586 
1587 // bool focusNextPrevChild(bool next) protected
1588 void tst_QGraphicsWidget::focusNextPrevChild()
1589 {
1590  QFETCH(QString, str);
1592  // ### write test after just calling it stops crashing :)
1593  widget.call_focusNextPrevChild(true);
1594 }
1595 
1596 void tst_QGraphicsWidget::verifyFocusChain()
1597 {
1600  view.show();
1603 
1604  {
1605  // parent/child focus
1607  w->setFocusPolicy(Qt::StrongFocus);
1610  scene.addItem(w);
1611  w->setFocus();
1612  QVERIFY(w->hasFocus());
1613  w->call_focusNextPrevChild(true);
1614  QVERIFY(w1_1->hasFocus());
1615  delete w;
1616  }
1617 
1618  {
1619  // delete item in focus chain and verify chain
1627  scene.addItem(w);
1628  w1_1->setFocus();
1629  QVERIFY(w1_1->hasFocus());
1630  QCOMPARE(w->call_focusNextPrevChild(true), true);
1631  QVERIFY(w1_2->hasFocus());
1632  QCOMPARE(w->call_focusNextPrevChild(true), true);
1633  QVERIFY(w1_3->hasFocus());
1634  w1_1->setFocus();
1635  delete w1_2;
1636  w->call_focusNextPrevChild(true);
1637  QVERIFY(w1_3->hasFocus());
1638  delete w;
1639  }
1640  {
1641  // parent/child focus
1643  w->setFocusPolicy(Qt::StrongFocus);
1646  scene.addItem(w);
1647  w->setFocus();
1648  QVERIFY(w->hasFocus());
1649  w->call_focusNextPrevChild(true);
1650  QVERIFY(w1_1->hasFocus());
1651  delete w;
1652  }
1653  {
1654  // QTBUG-30923:
1655  // Child QGraphicsWidget with tabFocusFirst gets removed & deleted should not crash.
1656  // This case simulates what QtQuick1 does when you have QGraphicsObject based
1657  // item in different qml views that are loaded one after another.
1658  QGraphicsItem *parent1 = new QGraphicsRectItem(0); // root item
1659  scene.addItem(parent1);
1660  for (int i = 0; i < 2; i++) {
1661  SubQGraphicsWidget *w1 = new SubQGraphicsWidget(parent1);
1662  w1->setFocusPolicy(Qt::StrongFocus);
1663  w1->setFocus();
1664  QVERIFY(w1->hasFocus());
1665  scene.removeItem(w1);
1666  delete w1;
1668  }
1669  delete parent1;
1670  }
1671  {
1672  // remove the tabFocusFirst widget from the scene.
1675  window->setLayout(layout);
1676  QLineEdit *lineEdit = new QLineEdit;
1679  scene.setSceneRect(-20, -20, 200, 50);
1680  layout->addWidget(view);
1681  view->setMinimumSize(150, 50);
1683  w1_1->setData(0, "w1_1");
1684  w1_1->setGeometry(0,0,25, 25);
1686  scene.addItem(w1_1);
1688  w1_2->setData(0, "w1_2");
1689  w1_2->setGeometry(25,0,25, 25);
1691  scene.addItem(w1_2);
1692  window->show();
1695 
1696  lineEdit->setFocus();
1698  QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
1699  QTRY_VERIFY(w1_1->hasFocus());
1700  QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
1701  QTRY_VERIFY(w1_2->hasFocus());
1702 
1703  // remove the tabFocusFirst and insert new item
1704  delete w1_1; // calls _q_removeItemLater
1707  w1_3->setData(0, "w1_3");
1708  w1_3->setGeometry(50,0,25, 25);
1709  scene.addItem(w1_3);
1710  QTRY_VERIFY(w1_2->hasFocus());
1711  QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
1713  // tabFocusFirst should now point to w1_2
1714  QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
1715  QTRY_VERIFY(w1_2->hasFocus());
1716  QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
1717  QTRY_VERIFY(w1_3->hasFocus());
1718  scene.removeItem(w1_2); // does not call _q_removeItemLater
1719  delete w1_2; // calls _q_removeItemLater
1720 
1723  w1_4->setData(0, "w1_4");
1724  w1_4->setGeometry(75,0,25, 25);
1725  scene.addItem(w1_4);
1726  QTRY_VERIFY(w1_3->hasFocus());
1727  QByteArray errorMessage;
1728  const QGraphicsItemList expected = QGraphicsItemList() << w1_3 << w1_4;
1729  QTRY_VERIFY2(compareFocusChain(view, expected, &errorMessage), errorMessage.constData());
1730  QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
1732  // tabFocusFirst should now point to w1_3
1733  QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
1734  QTRY_VERIFY(w1_3->hasFocus());
1735  QTRY_VERIFY2(compareFocusChain(view, expected, &errorMessage), errorMessage.constData());
1736  }
1737 }
1738 
1739 void tst_QGraphicsWidget::updateFocusChainWhenChildDie()
1740 {
1741  const QRect availableGeometry = QGuiApplication::primaryScreen()->availableGeometry();
1744  view.resize(200, 150);
1745  view.move(availableGeometry.topLeft() + QPoint(50, 50));
1746  view.show();
1749 
1750  // delete item in focus chain with no focus and verify chain
1753  w->resize(50,50);
1754  w->resize(100,100);
1757  w->setFocusPolicy(Qt::StrongFocus);
1758  scene.addItem(w);
1759  scene.addItem(parent);
1760  w1_1->setFocus();
1761 
1762  QVERIFY(w1_1->hasFocus());
1763  QWidget myWidget(0);
1764  QLineEdit edit(&myWidget);
1765  (new QHBoxLayout(&myWidget))->addWidget(&edit);
1766  edit.setMinimumWidth(160); // Windows
1767  myWidget.move(availableGeometry.topLeft() + QPoint(350, 50));
1768  myWidget.show();
1769  edit.setFocus();
1771  delete w1_1;
1772  myWidget.hide();
1773  w->setParentItem(parent);
1774  //We don't crash perfect
1775  QVERIFY(w);
1776  const QPoint center(view.viewport()->width() / 2, view.viewport()->height() / 2);
1777  QTest::mouseMove(view.viewport(), center);
1778  QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, center);
1779 #ifdef Q_OS_MAC
1780  QEXPECT_FAIL("", "QTBUG-23699", Continue);
1781 #endif
1782  QTRY_COMPARE(qApp->activeWindow(), static_cast<QWidget *>(&view));
1783  QTRY_COMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(w));
1784 }
1785 
1786 void tst_QGraphicsWidget::sizeHint_data()
1787 {
1788  QTest::addColumn<bool>("layout");
1789  QTest::newRow("no layout") << false;
1790  QTest::newRow("layout") << true;
1791 }
1792 
1793 // QSizeF sizeHint(Qt::SizeHint which, QSizeF const& constraint = QSizeF()) const protected
1794 void tst_QGraphicsWidget::sizeHint()
1795 {
1796  QFETCH(bool, layout);
1798 
1799  if (layout) {
1801  widget.setLayout(layout);
1802  }
1803  widget.call_sizeHint(Qt::MinimumSize, QSizeF());
1804 }
1805 
1806 void tst_QGraphicsWidget::consistentPosSizeGeometry_data()
1807 {
1808  QTest::addColumn<QSizeF>("minSize");
1809  QTest::addColumn<QSizeF>("maxSize");
1810  QTest::addColumn<QRectF>("geometry");
1811  QTest::addColumn<QRectF>("expectedGeometry");
1812 
1813  QTest::newRow("size is valid") << QSizeF(0, 0) << QSizeF(200, 200) << QRectF(0, 0, 100, 100) << QRectF(0, 0, 100, 100);
1814  QTest::newRow("size is larger than max") << QSizeF(0, 0) << QSizeF(50, 50) << QRectF(0, 0, 100, 100) << QRectF(0, 0, 50, 50);
1815  QTest::newRow("size is smaller than min") << QSizeF(50, 50) << QSizeF(150, 150) << QRectF(0, 0, 10, 10) << QRectF(0, 0, 50, 50);
1816 }
1817 
1818 void tst_QGraphicsWidget::consistentPosSizeGeometry()
1819 {
1820  QFETCH(QSizeF, minSize);
1821  QFETCH(QSizeF, maxSize);
1822  QFETCH(QRectF, geometry);
1823  QFETCH(QRectF, expectedGeometry);
1824 
1828  scene.addItem(w);
1829  w->setMinimumSize(minSize);
1830  w->setMaximumSize(maxSize);
1831  w->setGeometry(geometry);
1832  QCOMPARE(w->geometry(), expectedGeometry);
1833  QCOMPARE(w->pos(), expectedGeometry.topLeft());
1834  QCOMPARE(w->size(), expectedGeometry.size());
1835 
1836  QRectF otherGeom = QRectF(QPointF(12.34,12.34), minSize);
1837  w->setGeometry(otherGeom);
1838  QCOMPARE(w->geometry(), otherGeom);
1839  QCOMPARE(w->pos(), otherGeom.topLeft());
1840  QCOMPARE(w->size(), otherGeom.size());
1841 
1842  w->setPos(geometry.topLeft());
1843  QCOMPARE(w->geometry().topLeft(), expectedGeometry.topLeft());
1844  QCOMPARE(w->pos(), expectedGeometry.topLeft());
1845 
1846  w->resize(geometry.size());
1847  QCOMPARE(w->geometry().size(), expectedGeometry.size());
1848  QCOMPARE(w->geometry(), expectedGeometry);
1849 
1850  view.show();
1851 
1852 }
1853 
1854 
1870 };
1871 
1873 
1875 
1876 void tst_QGraphicsWidget::setSizes_data()
1877 {
1878 
1879  QTest::addColumn<QList<Inst>>("inputInstructions");
1880  QTest::addColumn<QList<Inst>>("compareInstructions");
1881 
1882  QTest::newRow("minSize1") << (QList<Inst>()
1883  << Inst(Size, QSize(25, 25)) << Inst(MinimumSize, QSize(10, 10)))
1884  << (QList<Inst>() << Inst(Size, QSize(25, 25)));
1885  QTest::newRow("minSize2") << (QList<Inst>() << Inst(Size, QSizeF(20, 20))
1886  << Inst(MinimumSize, QSizeF(25, 25)))
1887  << (QList<Inst>() << Inst(Size, QSizeF(25, 25)));
1888  QTest::newRow("minWidth1") << (QList<Inst>()
1889  << Inst(Size, QSizeF(20, 20)) << Inst(MinimumWidth, 5.0))
1890  << (QList<Inst>() << Inst(Size, QSizeF(20, 20)));
1891  QTest::newRow("minWidth2") << (QList<Inst>()
1892  << Inst(Size, QSizeF(20, 20)) << Inst(MinimumWidth, 25.0))
1893  << (QList<Inst>() << Inst(Size, QSizeF(25, 20)));
1894  QTest::newRow("minHeight1") << (QList<Inst>()
1895  << Inst(Size, QSizeF(20, 20)) << Inst(MinimumHeight, 5.0))
1896  << (QList<Inst>() << Inst(Size, QSizeF(20, 20)));
1897  QTest::newRow("minHeight2") << (QList<Inst>()
1898  << Inst(Size, QSizeF(20, 20)) << Inst(MinimumHeight, 25.0))
1899  << (QList<Inst>() << Inst(Size, QSizeF(20, 25)));
1900  QTest::newRow("maxSize1") << (QList<Inst>() << Inst(Size, QSizeF(40, 40))
1901  << Inst(MaximumSize, QSizeF(30, 30)))
1902  << (QList<Inst>() << Inst(Size, QSizeF(30, 30)));
1903  QTest::newRow("maxSize2") << (QList<Inst>() << Inst(Size, QSizeF(40, 40))
1904  << Inst(MaximumSize, QSizeF(30, -1)))
1905  << (QList<Inst>() << Inst(Size, QSizeF(30, 40)));
1906  QTest::newRow("maxSize3") << (QList<Inst>() << Inst(Size, QSizeF(40, 40))
1907  << Inst(MaximumSize, QSizeF(-1, 30)))
1908  << (QList<Inst>() << Inst(Size, QSizeF(40, 30)));
1909  QTest::newRow("maxWidth1") << (QList<Inst>()
1910  << Inst(Size, QSizeF(40, 40)) << Inst(MaximumWidth, 30))
1911  << (QList<Inst>() << Inst(Size, QSizeF(30, 40)));
1912  QTest::newRow("maxHeight") << (QList<Inst>()
1913  << Inst(Size, QSizeF(40, 40)) << Inst(MaximumHeight, 20))
1914  << (QList<Inst>() << Inst(Size, QSizeF(40, 20)));
1915  QTest::newRow("unsetMinSize") << (QList<Inst>() << Inst(Size, QSizeF(40, 40))
1916  << Inst(MinimumSize, QSizeF(-1, -1)))
1917  << (QList<Inst>() << Inst(MinimumSize, QSizeF(5, 5)));
1918  QTest::newRow("unsetMaxSize") << (QList<Inst>() << Inst(Size, QSizeF(40, 40))
1919  << Inst(MaximumSize, QSizeF(-1, -1)))
1920  << (QList<Inst>() << Inst(MaximumSize, QSizeF(500, 500)));
1921  QTest::newRow("unsetMinSize, expand size to minimumSizeHint")
1922  << (QList<Inst>() << Inst(MinimumSize, QSize(0, 0)) << Inst(Size, QSize(1, 1))
1923  << Inst(MinimumSize, QSize(-1.0, -1.0)))
1924  << (QList<Inst>() << Inst(Size, QSize(5, 5)) << Inst(MinimumSize, QSize(5, 5)));
1925 }
1926 
1927 void tst_QGraphicsWidget::setSizes()
1928 {
1929  QFETCH(QList<Inst>, inputInstructions);
1930  QFETCH(QList<Inst>, compareInstructions);
1931 
1935  QSizeF min = QSizeF(10, 10);
1936  QSizeF pref = QSizeF(25, 25);
1937  QSizeF max = QSizeF(50, 50);
1938 
1939  int i;
1940  for (i = 0; i < inputInstructions.count(); ++i) {
1941  Inst input = inputInstructions.at(i);
1942 
1943  // defaults
1944  switch (input.first) {
1945  case MinimumSize:
1946  min = input.second.toSizeF();
1947  break;
1948  case PreferredSize:
1949  pref = input.second.toSizeF();
1950  break;
1951  case MaximumSize:
1952  max = input.second.toSizeF();
1953  break;
1954  case Size:
1955  widget->resize(input.second.toSizeF());
1956  break;
1957  case MinimumWidth:
1958  widget->setMinimumWidth(qreal(input.second.toDouble()));
1959  break;
1960  case PreferredWidth:
1961  widget->setPreferredWidth(qreal(input.second.toDouble()));
1962  break;
1963  case MaximumWidth:
1964  widget->setMaximumWidth(qreal(input.second.toDouble()));
1965  break;
1966  case MinimumHeight:
1967  widget->setMinimumHeight(qreal(input.second.toDouble()));
1968  break;
1969  case PreferredHeight:
1970  widget->setPreferredHeight(qreal(input.second.toDouble()));
1971  break;
1972  case MaximumHeight:
1973  widget->setMaximumHeight(qreal(input.second.toDouble()));
1974  break;
1975  case MinimumSizeHint:
1976  widget->setSizeHint(Qt::MinimumSize, input.second.toSizeF());
1977  break;
1978  case PreferredSizeHint:
1979  widget->setSizeHint(Qt::PreferredSize, input.second.toSizeF());
1980  break;
1981  case MaximumSizeHint:
1982  widget->setSizeHint(Qt::MaximumSize, input.second.toSizeF());
1983  break;
1984  default:
1985  qWarning("instruction not implemented");
1986  break;
1987  }
1988  }
1989 
1990  widget->setMinimumSize(min);
1991  widget->setPreferredSize(pref);
1992  widget->setMaximumSize(max);
1993 
1994  for (i = 0; i < compareInstructions.count(); ++i) {
1995  Inst input = compareInstructions.at(i);
1996  switch (input.first) {
1997  case MinimumSize:
1998  QTRY_COMPARE(widget->minimumSize(), input.second.toSizeF());
1999  break;
2000  case PreferredSize:
2001  QTRY_COMPARE(widget->preferredSize(), input.second.toSizeF());
2002  break;
2003  case MaximumSize:
2004  QTRY_COMPARE(widget->maximumSize(), input.second.toSizeF());
2005  break;
2006  case Size:
2007  QTRY_COMPARE(widget->size(), input.second.toSizeF());
2008  break;
2009  case MinimumWidth:
2010  QTRY_COMPARE(widget->minimumWidth(), qreal(input.second.toDouble()));
2011  break;
2012  case PreferredWidth:
2013  QTRY_COMPARE(widget->preferredWidth(), qreal(input.second.toDouble()));
2014  break;
2015  case MaximumWidth:
2016  QTRY_COMPARE(widget->maximumWidth(), qreal(input.second.toDouble()));
2017  break;
2018  default:
2019  qWarning("instruction not implemented");
2020  break;
2021  }
2022  }
2023  delete widget;
2024 }
2025 
2026 void tst_QGraphicsWidget::closePopupOnOutsideClick()
2027 {
2029  widget->resize(100, 100);
2030 
2032  scene.addItem(widget);
2033 
2035  event.ignore();
2036  event.setScenePos(QPointF(50, 50));
2037  qApp->sendEvent(&scene, &event);
2038 
2039  QVERIFY(widget->isVisible());
2040  QVERIFY(event.isAccepted());
2041 
2042  event.ignore();
2043  event.setScenePos(QPointF(150, 150));
2044  qApp->sendEvent(&scene, &event);
2045 
2046  QVERIFY(!widget->isVisible());
2047  QVERIFY(event.isAccepted());
2048 }
2049 
2050 void tst_QGraphicsWidget::task236127_bspTreeIndexFails()
2051 {
2053  QGraphicsWidget *widget2 = new QGraphicsWidget;
2054  widget->resize(10, 10);
2055  widget2->resize(10, 10);
2056  widget2->setZValue(1);
2057  QCOMPARE(widget2->zValue(), qreal(1));
2058  QCOMPARE(widget->zValue(), qreal(0));
2059  widget->setData(0, "widget");
2060  widget2->setData(0, "widget2");
2061 
2063  scene.addItem(widget);
2064  scene.addItem(widget2);
2065 
2067  view.show();
2069 
2070  QTRY_VERIFY(scene.items(QPointF(25, 25)).isEmpty());
2071  widget->setGeometry(0, 112, 360, 528);
2072  QTRY_COMPARE(scene.items(QPointF(15, 120)).value(0, nullptr), (QGraphicsItem *)widget);
2073  widget2->setGeometry(0, 573, 360, 67);
2074  QTRY_COMPARE(scene.items(QPointF(15, 120)).value(0, nullptr), (QGraphicsItem *)widget);
2075  QTRY_COMPARE(scene.items(QPointF(50, 585)).value(0, nullptr), (QGraphicsItem *)widget2);
2076 }
2077 
2078 void tst_QGraphicsWidget::defaultSize()
2079 {
2081  widget->setMinimumSize(40, 40);
2083  scene.addItem(widget);
2084 
2086  view.show();
2088  QSizeF initialSize = widget->size();
2089 
2090  widget->resize(initialSize);
2091  QCOMPARE(widget->geometry().size(), initialSize);
2092  widget->setVisible(false);
2093  widget->setMinimumSize(10, 10);
2094  widget->setPreferredSize(60, 60);
2095  widget->setMaximumSize(110, 110);
2096  widget->setVisible(true);
2097  // should still have its size set to initialsize
2098  QTRY_COMPARE(widget->geometry().size(), initialSize);
2099 
2100 }
2101 
2102 void tst_QGraphicsWidget::explicitMouseGrabber()
2103 {
2105  EventSpy widgetGrabEventSpy(widget, QEvent::GrabMouse);
2106  EventSpy widgetUngrabEventSpy(widget, QEvent::UngrabMouse);
2107 
2108  // Grab without scene
2109  QTest::ignoreMessage(QtWarningMsg, "QGraphicsItem::grabMouse: cannot grab mouse without scene");
2110  widget->grabMouse();
2111  QCOMPARE(widgetGrabEventSpy.count(), 0);
2112  QTest::ignoreMessage(QtWarningMsg, "QGraphicsItem::ungrabMouse: cannot ungrab mouse without scene");
2113  widget->ungrabMouse();
2114  QCOMPARE(widgetUngrabEventSpy.count(), 0);
2115 
2116  // Add to scene
2118  scene.addItem(widget);
2119 
2120  // Ungrab while not grabber
2121  QTest::ignoreMessage(QtWarningMsg, "QGraphicsItem::ungrabMouse: not a mouse grabber");
2122  widget->ungrabMouse();
2123 
2124  // Simple grab with scene
2126  widget->grabMouse();
2128  QCOMPARE(widgetGrabEventSpy.count(), 1);
2129  widget->ungrabMouse();
2130  QCOMPARE(scene.mouseGrabberItem(), nullptr);
2131  QCOMPARE(widgetUngrabEventSpy.count(), 1);
2132 
2133  // Grab while grabbing
2134  widget->grabMouse();
2135  QCOMPARE(widgetGrabEventSpy.count(), 2);
2136  QTest::ignoreMessage(QtWarningMsg, "QGraphicsItem::grabMouse: already a mouse grabber");
2137  widget->grabMouse();
2138  QCOMPARE(widgetGrabEventSpy.count(), 2);
2139  QCOMPARE(widgetUngrabEventSpy.count(), 1);
2140  widget->ungrabMouse();
2141  QCOMPARE(widgetUngrabEventSpy.count(), 2);
2142 
2143  // Add two more widgets to the scene
2144  QGraphicsWidget *widget2 = new QGraphicsWidget;
2145  scene.addItem(widget2);
2146  EventSpy widget2GrabEventSpy(widget2, QEvent::GrabMouse);
2147  EventSpy widget2UngrabEventSpy(widget2, QEvent::UngrabMouse);
2148  QGraphicsWidget *widget3 = new QGraphicsWidget;
2149  scene.addItem(widget3);
2150  EventSpy widget3GrabEventSpy(widget3, QEvent::GrabMouse);
2151  EventSpy widget3UngrabEventSpy(widget3, QEvent::UngrabMouse);
2152 
2153  widget->setData(0, "widget");
2154  widget2->setData(0, "widget2");
2155  widget3->setData(0, "widget3");
2156 
2157  // Simple nested grabbing
2158  widget->grabMouse();
2159  QCOMPARE(widgetGrabEventSpy.count(), 3);
2161  widget2->grabMouse();
2162  QCOMPARE(widgetUngrabEventSpy.count(), 3);
2163  QCOMPARE(widget2GrabEventSpy.count(), 1);
2165  widget3->grabMouse();
2166  QCOMPARE(widget2UngrabEventSpy.count(), 1);
2167  QCOMPARE(widget3GrabEventSpy.count(), 1);
2169  widget3->ungrabMouse();
2170  QCOMPARE(widget3UngrabEventSpy.count(), 1);
2171  QCOMPARE(widget2GrabEventSpy.count(), 2);
2173  widget2->ungrabMouse();
2174  QCOMPARE(widget2UngrabEventSpy.count(), 2);
2175  QCOMPARE(widgetGrabEventSpy.count(), 4);
2177  widget->ungrabMouse();
2178  QCOMPARE(scene.mouseGrabberItem(), nullptr);
2179 
2180  // Out of order ungrab
2181  widget->grabMouse();
2182  QCOMPARE(widgetGrabEventSpy.count(), 5);
2183  widget2->grabMouse();
2184  QCOMPARE(widget2GrabEventSpy.count(), 3);
2185  widget3->grabMouse();
2186  QCOMPARE(widget3GrabEventSpy.count(), 2);
2187  widget2->ungrabMouse();
2188  QCOMPARE(widget3UngrabEventSpy.count(), 2);
2189  QCOMPARE(widget2UngrabEventSpy.count(), 4);
2190  QCOMPARE(widgetGrabEventSpy.count(), 6);
2192 }
2193 
2194 void tst_QGraphicsWidget::implicitMouseGrabber()
2195 {
2198  widget->setFlag(QGraphicsItem::ItemIsMovable); // can grab mouse
2199  widget->resize(200, 200);
2200  EventSpy widgetGrabEventSpy(widget, QEvent::GrabMouse);
2201  EventSpy widgetUngrabEventSpy(widget, QEvent::UngrabMouse);
2202  scene.addItem(widget);
2203 
2205 
2206  // Click on an item, see if gain and lose implicit mouse grab.
2207  {
2209  event.ignore();
2210  event.setButton(Qt::LeftButton);
2211  event.setScenePos(QPointF(50, 50));
2212  qApp->sendEvent(&scene, &event);
2213  }
2215  QCOMPARE(widgetGrabEventSpy.count(), 1);
2216  {
2218  event.ignore();
2219  event.setButton(Qt::LeftButton);
2220  event.setScenePos(QPointF(50, 50));
2221  qApp->sendEvent(&scene, &event);
2222  }
2223  QCOMPARE(scene.mouseGrabberItem(), nullptr);
2224  QCOMPARE(widgetGrabEventSpy.count(), 1);
2225  QCOMPARE(widgetUngrabEventSpy.count(), 1);
2226 
2227  // Click on an item that already grabs the mouse. Shouldn't have any effect.
2228  widget->grabMouse();
2229  QCOMPARE(widgetGrabEventSpy.count(), 2);
2230  {
2232  event.ignore();
2233  event.setButton(Qt::LeftButton);
2234  event.setScenePos(QPointF(50, 50));
2235  qApp->sendEvent(&scene, &event);
2236  }
2238  QCOMPARE(widgetGrabEventSpy.count(), 2);
2239  {
2241  event.ignore();
2242  event.setButton(Qt::LeftButton);
2243  event.setScenePos(QPointF(50, 50));
2244  qApp->sendEvent(&scene, &event);
2245  }
2247  QCOMPARE(widgetGrabEventSpy.count(), 2);
2248  QCOMPARE(widgetUngrabEventSpy.count(), 1);
2249  widget->ungrabMouse();
2250  QCOMPARE(widgetUngrabEventSpy.count(), 2);
2251  QCOMPARE(scene.mouseGrabberItem(), nullptr);
2252 
2253  // Implicit mouse grabber tries to explicitly grab the mouse
2254  {
2256  event.ignore();
2257  event.setButton(Qt::LeftButton);
2258  event.setScenePos(QPointF(50, 50));
2259  qApp->sendEvent(&scene, &event);
2260  }
2262  QCOMPARE(widgetGrabEventSpy.count(), 3);
2263  widget->grabMouse();
2264  QCOMPARE(widgetUngrabEventSpy.count(), 2);
2265  {
2267  event.ignore();
2268  event.setButton(Qt::LeftButton);
2269  event.setScenePos(QPointF(50, 50));
2270  qApp->sendEvent(&scene, &event);
2271  }
2273  QCOMPARE(widgetGrabEventSpy.count(), 3);
2274  QCOMPARE(widgetUngrabEventSpy.count(), 2);
2275  widget->ungrabMouse();
2276  QCOMPARE(scene.mouseGrabberItem(), nullptr);
2277  QCOMPARE(widgetGrabEventSpy.count(), 3);
2278  QCOMPARE(widgetUngrabEventSpy.count(), 3);
2279 
2280  // Arrival of a new widget
2281  QGraphicsWidget *widget2 = new QGraphicsWidget;
2282  widget2->setFlag(QGraphicsItem::ItemIsMovable); // can grab mouse
2283  widget2->resize(200, 200);
2284  widget2->setPos(205, 0);
2285  EventSpy widget2GrabEventSpy(widget2, QEvent::GrabMouse);
2286  EventSpy widget2UngrabEventSpy(widget2, QEvent::UngrabMouse);
2287  scene.addItem(widget2);
2288 
2289  // Implicit grab while there's an explicit grab is not possible.
2290  widget->grabMouse();
2291  QCOMPARE(widgetGrabEventSpy.count(), 4);
2292  {
2294  event.ignore();
2295  event.setButton(Qt::LeftButton);
2296  event.setScenePos(QPointF(250, 50));
2297  qApp->sendEvent(&scene, &event);
2298  }
2300  QCOMPARE(widgetGrabEventSpy.count(), 4);
2301  QCOMPARE(widget2GrabEventSpy.count(), 0);
2302  QCOMPARE(widget2UngrabEventSpy.count(), 0);
2303 
2305  QCOMPARE(widgetUngrabEventSpy.count(), 4);
2306  QCOMPARE(scene.mouseGrabberItem(), nullptr);
2307 }
2308 
2310 {
2311 public:
2314  npress(0), nrelease(0), ndoubleClick(0),
2315  ngrab(0), nungrab(0)
2316  {
2317  }
2318  int npress;
2321  int ngrab;
2322  int nungrab;
2323 protected:
2324  bool sceneEvent(QEvent *event) override
2325  {
2326  switch (event->type()) {
2327  case QEvent::GrabMouse:
2328  ++ngrab;
2329  break;
2330  case QEvent::UngrabMouse:
2331  ++nungrab;
2332  break;
2333  default:
2334  break;
2335  }
2337  }
2338 
2340  {
2341  grabMouse();
2342  ++npress;
2343  }
2345  {
2346  ungrabMouse();
2347  ++nrelease;
2348  }
2350  {
2351  ++ndoubleClick;
2352  }
2353 };
2354 
2355 void tst_QGraphicsWidget::doubleClickAfterExplicitMouseGrab()
2356 {
2358  GrabOnPressItem *item = new GrabOnPressItem(QRectF(0, 0, 100, 100));
2359  scene.addItem(item);
2360 
2361  {
2363  event.setButton(Qt::LeftButton);
2364  event.setButtons(Qt::LeftButton);
2365  event.ignore();
2366  event.setScenePos(QPointF(50, 50));
2367  qApp->sendEvent(&scene, &event);
2368  }
2370  QCOMPARE(item->npress, 1);
2371  QCOMPARE(item->ngrab, 1);
2372  {
2374  event.setButton(Qt::LeftButton);
2375  event.setButtons({});
2376  event.ignore();
2377  event.setScenePos(QPointF(50, 50));
2378  qApp->sendEvent(&scene, &event);
2379  }
2380  QCOMPARE(scene.mouseGrabberItem(), nullptr);
2381  QCOMPARE(item->nrelease, 1);
2382  QCOMPARE(item->nungrab, 1);
2383  {
2385  event.setButton(Qt::LeftButton);
2386  event.setButtons(Qt::LeftButton);
2387  event.ignore();
2388  event.setScenePos(QPointF(50, 50));
2389  qApp->sendEvent(&scene, &event);
2390  }
2392  QCOMPARE(item->ndoubleClick, 1);
2393  QCOMPARE(item->ngrab, 2);
2394  {
2396  event.setButton(Qt::LeftButton);
2397  event.setButtons({});
2398  event.ignore();
2399  event.setScenePos(QPointF(50, 50));
2400  qApp->sendEvent(&scene, &event);
2401  }
2402  QCOMPARE(scene.mouseGrabberItem(), nullptr);
2403  QCOMPARE(item->nrelease, 2);
2404  QCOMPARE(item->nungrab, 2);
2405 }
2406 
2407 void tst_QGraphicsWidget::popupMouseGrabber()
2408 {
2411  widget->setFlag(QGraphicsItem::ItemIsMovable); // can grab mouse
2412  widget->resize(200, 200);
2413  EventSpy widgetGrabEventSpy(widget, QEvent::GrabMouse);
2414  EventSpy widgetUngrabEventSpy(widget, QEvent::UngrabMouse);
2415 
2416  // Simply adding a visible popup to the scene immediately grabs the mouse.
2417  scene.addItem(widget);
2418  QCOMPARE(widgetGrabEventSpy.count(), 1);
2420 
2421  // Hiding it loses the grab again.
2422  widget->hide();
2423  QCOMPARE(widgetUngrabEventSpy.count(), 1);
2424  QCOMPARE(scene.mouseGrabberItem(), nullptr);
2425 
2426  // Showing it grabs the mouse again
2427  widget->show();
2428  QCOMPARE(widgetGrabEventSpy.count(), 2);
2430 
2431  // Add two popups
2432  QGraphicsWidget *widget2 = new QGraphicsWidget(0, Qt::Popup);
2433  widget2->setFlag(QGraphicsItem::ItemIsMovable); // can grab mouse
2434  widget2->resize(200, 200);
2435  EventSpy widget2GrabEventSpy(widget2, QEvent::GrabMouse);
2436  EventSpy widget2UngrabEventSpy(widget2, QEvent::UngrabMouse);
2437  QGraphicsWidget *widget3 = new QGraphicsWidget(0, Qt::Popup);
2438  widget3->setFlag(QGraphicsItem::ItemIsMovable); // can grab mouse
2439  widget3->resize(200, 200);
2440  EventSpy widget3GrabEventSpy(widget3, QEvent::GrabMouse);
2441  EventSpy widget3UngrabEventSpy(widget3, QEvent::UngrabMouse);
2442 
2443  // Adding to the scene grabs
2444  scene.addItem(widget2);
2445  QCOMPARE(widgetUngrabEventSpy.count(), 2);
2446  QCOMPARE(widget2GrabEventSpy.count(), 1);
2448 
2449  // Adding to the scene grabs again
2450  scene.addItem(widget3);
2451  QCOMPARE(widget2UngrabEventSpy.count(), 1);
2452  QCOMPARE(widget3GrabEventSpy.count(), 1);
2454 
2455  // Hiding the topmost widget causes widget 2 to regain grab.
2456  widget3->hide();
2457  QCOMPARE(widget2GrabEventSpy.count(), 2);
2458  QCOMPARE(widget3UngrabEventSpy.count(), 1);
2460  widget3->show();
2461  QCOMPARE(widget2UngrabEventSpy.count(), 2);
2462  QCOMPARE(widget3GrabEventSpy.count(), 2);
2464 
2465  // Clicking outside the popup still causes it to close (despite that it's
2466  // an explicit mouse grabber).
2467  {
2469  event.ignore();
2470  event.setButton(Qt::LeftButton);
2471  event.setScenePos(QPointF(500, 500)); // outside
2472  qApp->sendEvent(&scene, &event);
2473  }
2474  QVERIFY(!widget3->isVisible());
2475  QCOMPARE(widget3UngrabEventSpy.count(), 2);
2476  QCOMPARE(widget2GrabEventSpy.count(), 3);
2478  QVERIFY(widget2->isVisible());
2479  QVERIFY(widget->isVisible());
2480  widget3->show();
2481  QCOMPARE(widget3GrabEventSpy.count(), 3);
2482  QCOMPARE(widget2UngrabEventSpy.count(), 3);
2484 
2485  // This is something of a curiosity. What happens if you call
2486  // ungrabMouse() on a popup? The answer is - it loses the grab. If you
2487  // hide and show the popup again, it will regain the grab.
2488  widget3->ungrabMouse();
2489  QCOMPARE(widget3UngrabEventSpy.count(), 3);
2490  QCOMPARE(widget2GrabEventSpy.count(), 4);
2492  widget3->hide();
2493  widget3->show();
2494  QCOMPARE(widget3GrabEventSpy.count(), 4);
2495  QCOMPARE(widget2UngrabEventSpy.count(), 4);
2497 }
2498 
2499 void tst_QGraphicsWidget::windowFlags_data()
2500 {
2501  QTest::addColumn<int>("inputFlags");
2502  QTest::addColumn<int>("outputFlags");
2503 
2504  QTest::newRow("nil") << 0 << 0;
2505 
2506  // Window types
2507  QTest::newRow("Qt::Window") << int(Qt::Window)
2510  QTest::newRow("Qt::SubWindow") << int(Qt::SubWindow)
2513  QTest::newRow("Qt::Dialog") << int(Qt::Dialog)
2516  QTest::newRow("Qt::Sheet") << int(Qt::Sheet)
2519  QTest::newRow("Qt::Tool") << int(Qt::Tool)
2521 
2522  // Custom window flags
2523  QTest::newRow("Qt::FramelessWindowHint") << int(Qt::FramelessWindowHint)
2524  << int(Qt::FramelessWindowHint);
2525  QTest::newRow("Qt::CustomizeWindowHint") << int(Qt::CustomizeWindowHint)
2526  << int(Qt::CustomizeWindowHint);
2527 }
2528 
2529 void tst_QGraphicsWidget::windowFlags()
2530 {
2531  QFETCH(int, inputFlags);
2532  QFETCH(int, outputFlags);
2533 
2534  // Construct with flags set already
2535  QGraphicsWidget widget(0, Qt::WindowFlags(inputFlags));
2536  QCOMPARE(widget.windowFlags(), Qt::WindowFlags(outputFlags));
2537 
2538  // Set flags after construction
2539  QGraphicsWidget widget2;
2540  widget2.setWindowFlags(Qt::WindowFlags(inputFlags));
2541  QCOMPARE(widget2.windowFlags(), Qt::WindowFlags(outputFlags));
2542 
2543  // Reset flags
2544  widget2.setWindowFlags({});
2545  QVERIFY(!widget2.windowFlags());
2546 
2547  // Set flags back again
2548  widget2.setWindowFlags(Qt::WindowFlags(inputFlags));
2549  QCOMPARE(widget2.windowFlags(), Qt::WindowFlags(outputFlags));
2550 
2551  // Construct with custom flags set already
2552  QGraphicsWidget widget3(0, Qt::WindowFlags(inputFlags | Qt::FramelessWindowHint));
2553  QCOMPARE(widget3.windowFlags(), Qt::WindowFlags(inputFlags | Qt::FramelessWindowHint));
2554 
2555  // Set custom flags after construction
2556  QGraphicsWidget widget4;
2557  widget4.setWindowFlags(Qt::WindowFlags(inputFlags | Qt::FramelessWindowHint));
2558  QCOMPARE(widget4.windowFlags(), Qt::WindowFlags(inputFlags | Qt::FramelessWindowHint));
2559 
2560  // Reset flags
2561  widget4.setWindowFlags({});
2562  QVERIFY(!widget4.windowFlags());
2563 
2564  // Set custom flags back again
2565  widget4.setWindowFlags(Qt::WindowFlags(inputFlags | Qt::FramelessWindowHint));
2566  QCOMPARE(widget4.windowFlags(), Qt::WindowFlags(inputFlags | Qt::FramelessWindowHint));
2567 
2568  QGraphicsWidget *widget5 = new QGraphicsWidget;
2569  widget5->setWindowFlags(Qt::WindowFlags(inputFlags));
2570  QCOMPARE(widget5->windowFlags(), Qt::WindowFlags(outputFlags));
2571  QGraphicsWidget window(nullptr, Qt::Window);
2572  widget5->setParentItem(&window);
2573  QCOMPARE(widget5->windowFlags(), Qt::WindowFlags(outputFlags));
2574 }
2575 
2576 void tst_QGraphicsWidget::shortcutsDeletion()
2577 {
2579  QGraphicsWidget *widget2 = new QGraphicsWidget;
2580  widget->setMinimumSize(40, 40);
2581  QWidgetAction *del = new QWidgetAction(widget);
2582  del->setIcon(QIcon("edit-delete"));
2583  del->setShortcut(Qt::Key_Delete);
2584  del->setShortcutContext(Qt::WidgetShortcut);
2585  widget2->addAction(del);
2586  widget2->addAction(del);
2587  delete widget;
2588 }
2589 
2591 {
2592 public:
2593  MessUpPainterWidget(QGraphicsItem * parent = nullptr, Qt::WindowFlags wFlags = { })
2594  : QGraphicsWidget(parent, wFlags)
2595  {}
2596 
2598  {
2599  QCOMPARE(painter->opacity(), 1.0);
2600  painter->setOpacity(0.0);
2602  }
2604  {
2605  QCOMPARE(painter->opacity(), 1.0);
2606  painter->drawRect(0, 0, 100, 100);
2608  }
2609 
2610 };
2611 
2612 void tst_QGraphicsWidget::painterStateProtectionOnWindowFrame()
2613 {
2615  QGraphicsScene scene(0, 0, 300, 300);
2617  scene.addItem(widget);
2618  view.show();
2620 }
2621 
2622 class ProxyStyle : public QCommonStyle
2623 {
2624 public:
2625  ProxyStyle(QStyle *proxyStyle) : QCommonStyle()
2626  {
2627  m_proxyStyle = proxyStyle;
2628  }
2629 
2630  int pixelMetric(QStyle::PixelMetric metric, const QStyleOption *option = 0, const QWidget *widget = 0) const override
2631  {
2632  return m_proxyStyle->pixelMetric(metric, option, widget);
2633  }
2634 
2635 private:
2636  QStyle *m_proxyStyle;
2637 };
2638 
2640 {
2641 public:
2642  StyledGraphicsWidget(bool useOwnStyle) : QGraphicsWidget(), m_style(0) {
2643  if (useOwnStyle) {
2644  QStyle *oldStyle = style();
2645  m_style = new ProxyStyle(oldStyle);
2646  setStyle(m_style);
2647  }
2648 
2649  style()->pixelMetric(QStyle::PM_SmallIconSize); // crash when style() is still in widgetStyles
2650  }
2651 
2653  delete m_style;
2654  }
2655 
2656 private:
2657  QStyle *m_style;
2658 };
2659 
2660 void tst_QGraphicsWidget::task243004_setStyleCrash()
2661 {
2662  QGraphicsItem *item1 = new StyledGraphicsWidget(true);
2663  delete item1; // item1 not removed from widgetStyles
2664 
2665  QGraphicsItem *item2 = new StyledGraphicsWidget(false);
2666  delete item2;
2667 }
2668 
2670 {
2671 public:
2673  : shortcutEvents(0)
2674  {
2676  resize(100, 100);
2677  }
2678 
2680 
2681 private:
2682  bool event(QEvent *event) override
2683  {
2684  if (event->type() == QEvent::Shortcut)
2685  shortcutEvents++;
2686  return QGraphicsWidget::event(event);
2687  }
2688 
2689  void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
2690  {
2691  if (hasFocus()) {
2693  painter->drawRect(rect());
2694  }
2696  painter->fillRect(rect().adjusted(2, 2, -2, -2), Qt::yellow);
2697  painter->drawRect(rect().adjusted(2, 2, -2, -2));
2698  }
2699 };
2700 
2701 void tst_QGraphicsWidget::task250119_shortcutContext()
2702 {
2705  view.setScene(&scene);
2706  view.show();
2709 
2710 
2711  // *** Event: ***
2712 
2713  GraphicsWidget_task250119 w_event;
2714  scene.addItem(&w_event);
2715 
2716  const int id = w_event.grabShortcut(Qt::Key_A, Qt::WidgetWithChildrenShortcut);
2717  w_event.setShortcutEnabled(id, true);
2718 
2719  w_event.setFocus();
2720  QTest::keyPress(&view, Qt::Key_A);
2721  QCOMPARE(w_event.shortcutEvents, 1);
2722 
2723  w_event.clearFocus();
2724  QTest::keyPress(&view, Qt::Key_A);
2725  QCOMPARE(w_event.shortcutEvents, 1);
2726 
2727  scene.removeItem(&w_event);
2728 
2729 
2730  // *** Signal: ***
2731 
2732  GraphicsWidget_task250119 w_signal;
2733  scene.addItem(&w_signal);
2734 
2735  QAction action(0);
2736  action.setShortcut(Qt::Key_B);
2737  action.setShortcutContext(Qt::WidgetWithChildrenShortcut);
2739 
2740  w_signal.addAction(&action);
2741 
2742  w_signal.setFocus();
2743  QTest::keyPress(&view, Qt::Key_B);
2744  QCOMPARE(spy.count(), 1);
2745 
2746  w_signal.clearFocus();
2747  QTest::keyPress(&view, Qt::Key_B);
2748  QCOMPARE(spy.count(), 1);
2749 
2750  scene.removeItem(&w_signal);
2751 }
2752 
2754 {
2755 public:
2757 protected:
2758  void drawItems(QPainter *painter, int numItems, QGraphicsItem *items[],
2759  const QStyleOptionGraphicsItem options[], QWidget *widget = 0) override
2760  {
2761  drawnItems.clear();
2762  for (int i = 0; i < numItems; ++i)
2763  drawnItems << items[i];
2764  QGraphicsScene::drawItems(painter, numItems, items, options, widget);
2765  }
2766 };
2767 
2768 class RectWidget : public QGraphicsWidget
2769 {
2770 public:
2771 
2773 
2775  {
2778  }
2779 
2781 };
2782 
2783 class RectItem : public QGraphicsItem
2784 {
2785 public:
2786 
2788 
2789  QRectF boundingRect() const override
2790  {return QRectF(10,10,50,50);}
2791 
2793  {
2796  }
2797 
2799 };
2800 
2801 void tst_QGraphicsWidget::ensureClipping()
2802 {
2804  scene.setSceneRect(-50, -50, 200, 200);
2805 
2806  //A root that clip children
2807  RectWidget *clipWidget = new RectWidget(Qt::black);
2808  scene.addItem(clipWidget);
2809 
2811 
2812  //a child
2813  RectWidget *childWidget = new RectWidget(Qt::red, clipWidget);
2814  clipWidget->setGeometry(QRectF(10, 10, 100, 100));
2815  childWidget->setGeometry(QRectF(25, 25, 50, 50));
2816 
2817  //We put a QGraphicsItem to be sure this one is also paint
2818  RectItem *childitem = new RectItem(Qt::blue, clipWidget);
2819 
2821  view.setOptimizationFlag(QGraphicsView::IndirectPainting);
2822  view.show();
2824 
2825  QList<QGraphicsItem *> expected;
2826  expected << clipWidget << childWidget << childitem;
2827  QTRY_VERIFY(scene.drawnItems.contains(clipWidget));
2828  QVERIFY(scene.drawnItems.contains(childWidget));
2829  QVERIFY(scene.drawnItems.contains(childitem));
2830 }
2831 
2832 class ItemChangeTester : public QGraphicsWidget
2833 {
2834 public:
2839 
2840  void clear()
2841  {
2842  changes.clear();
2843  values.clear();
2844  oldValues.clear();
2845  }
2849 protected:
2851  {
2852  changes << change;
2853  values << value;
2854  switch (change) {
2856  oldValues << pos();
2857  break;
2859  break;
2860  default:
2861  break;
2862  }
2863  return value;
2864  }
2865 };
2866 
2867 void tst_QGraphicsWidget::widgetSendsGeometryChanges()
2868 {
2870  widget.setFlags({});
2871  widget.clear();
2872 
2873  QPointF pos(10, 10);
2874  widget.setPos(pos);
2875 
2876  QCOMPARE(widget.pos(), pos);
2877  QCOMPARE(widget.changes.size(), 0);
2878 
2880  QCOMPARE(widget.changes.size(), 2);
2881 
2882  widget.setPos(QPointF());
2883  QCOMPARE(widget.changes.size(), 4);
2884 
2885  QCOMPARE(widget.pos(), QPointF());
2886 
2887  QRectF geometry(20, 20, 50, 50);
2888  widget.setGeometry(geometry);
2889  QCOMPARE(widget.changes.size(), 6);
2890 
2891  QCOMPARE(widget.geometry(), geometry);
2892 
2900 }
2901 
2903 {
2904 public:
2906  {
2907  QSizePolicy sp;
2908  sp.setHeightForWidth(true);
2909  setSizePolicy(sp);
2910  }
2911 
2913  {
2914  Q_UNUSED(option);
2915  Q_UNUSED(widget);
2916  qreal w = rect().width();
2917  QRectF box(0, 0, w, 2400/w);
2919  painter->drawLine(box.topLeft(), box.bottomRight());
2920  painter->drawLine(box.bottomLeft(), box.topRight());
2921  }
2922 
2923 protected:
2924  QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const override
2925  {
2926  qreal w = constraint.width();
2927  switch (which) {
2928  case Qt::MinimumSize:
2929  if (w >= 0 && constraint.height() < 0) {
2930  // keep the same area of 60x40 = 2400
2931  return QSizeF(w, 2400.0/w);
2932  } else {
2933  return QSizeF(10, 10);
2934  }
2935  break;
2936  case Qt::PreferredSize:
2937  return QSizeF(48.989794, 48.989794);
2938  default:
2939  break;
2940  }
2941  return QGraphicsWidget::sizeHint(which, constraint);
2942  }
2943 };
2944 
2945 void tst_QGraphicsWidget::respectHFW()
2946 {
2948  HFWWidget *window = new HFWWidget;
2949  scene.addItem(window);
2951  view->resize(400, 400);
2952  view->setSceneRect(-100, -100, 300,300);
2953 
2954  view->show();
2955  window->setGeometry(0, 0, 70, 70);
2957 
2958  { // here we go - simulate a interactive resize of the window
2959  QTest::mouseMove(view.data(), view->mapFromScene(71, 71)); // bottom right corner
2960 
2961  QTest::mousePress(view->viewport(), Qt::LeftButton, {}, view->mapFromScene(71, 71), 200);
2962  view->grabMouse();
2963  // move both mouse cursor and set correct event in order to emulate resize
2964  QTest::mouseMove(view->viewport(), view->mapFromScene(60, 30), 200);
2966  view->mapFromScene(60, 20),
2967  Qt::NoButton,
2969  Qt::NoModifier);
2970  QApplication::sendEvent(view->viewport(), &e);
2971  view->releaseMouse();
2972  }
2973  const QSizeF winSize = window->size();
2974  qreal minHFW = window->effectiveSizeHint(Qt::MinimumSize, QSizeF(winSize.width(), -1)).height();
2975 #ifdef Q_OS_DARWIN
2976  QEXPECT_FAIL("", "This test is known to fail on Apple platforms.", Continue);
2977 #endif
2978  QTRY_VERIFY(qAbs(minHFW - winSize.height()) < 1);
2979 }
2980 
2982 {
2983 public:
2984 
2986  QGraphicsWidget(parent), mColor(color)
2987  {
2988  }
2989 
2991  {
2992  painter->setBrush(QBrush(mColor));
2994  }
2995 
2996  void polishEvent() override
2997  {
2998  if (!parentWidget()) {
2999  //We add a child in the polish event for the parent
3000  PolishWidget *childWidget = new PolishWidget(Qt::black, this);
3001  childWidget->setGeometry(QRectF(10,10,30,30));
3002  }
3003 
3005  mColor = Qt::red;
3006  update();
3007  numberOfPolish++;
3008  }
3009 
3010  static int numberOfPolish;
3011 
3012 private:
3013  Qt::GlobalColor mColor;
3014 };
3015 
3017 
3018 void tst_QGraphicsWidget::addChildInpolishEvent()
3019 {
3021 
3022  PolishWidget *parentWidget = new PolishWidget(Qt::white);
3023  scene.addItem(parentWidget);
3024 
3026  view.resize(200, 200);
3027  view.show();
3030 }
3031 
3032 void tst_QGraphicsWidget::polishEvent()
3033 {
3034  class MyGraphicsWidget : public QGraphicsWidget
3035  { public:
3036  void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override
3037  { events << QEvent::Paint; }
3038  void polishEvent() override
3039  { events << QEvent::Polish; }
3040  QList<QEvent::Type> events;
3041  };
3042 
3044 
3046  scene.addItem(widget);
3047 
3049  view.show();
3051 
3052  // Make sure the item is painted.
3053  QTRY_VERIFY(widget->events.contains(QEvent::Paint));
3054 
3055  // Make sure the item got polish before paint.
3056  QCOMPARE(widget->events.at(0), QEvent::Polish);
3057 }
3058 
3059 void tst_QGraphicsWidget::polishEvent2()
3060 {
3061  class MyGraphicsWidget : public QGraphicsWidget
3062  { public:
3063  void polishEvent() override
3064  { events << QEvent::Polish; }
3065  QList<QEvent::Type> events;
3066  };
3067 
3069 
3071  widget->hide();
3072  scene.addItem(widget);
3073 
3074  widget->events.clear();
3075 
3076  // Make sure the item got polish event.
3077  QTRY_VERIFY(widget->events.contains(QEvent::Polish));
3078 }
3079 
3080 void tst_QGraphicsWidget::autoFillBackground()
3081 {
3083  QCOMPARE(widget->autoFillBackground(), false);
3086 
3087  const QColor color(Qt::red);
3088  const QRect rect(0, 0, 1, 1);
3089 
3091  scene.addItem(widget);
3093 
3095  palette.setColor(QPalette::Window, color);
3097 
3099  QPainter painter;
3100  painter.begin(&image);
3102  painter.end();
3103  QCOMPARE(image.pixel(0, 0), color.rgb());
3104 }
3105 
3106 void tst_QGraphicsWidget::initialShow()
3107 {
3108  class MyGraphicsWidget : public QGraphicsWidget
3109  { public:
3110  MyGraphicsWidget() : repaints(0) {}
3111  int repaints;
3112  void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget*) override { ++repaints; }
3113  void polishEvent() override { update(); }
3114  };
3115 
3116  // Don't let paint events triggered by the windowing system
3117  // influence our test case. We're only interested in knowing
3118  // whether a QGraphicsWidget generates an additional repaint
3119  // on the initial show. Hence create a dummy scenario to find out
3120  // how many repaints we should expect.
3121  QGraphicsScene dummyScene(0, 0, 200, 200);
3122  dummyScene.addItem(new QGraphicsRectItem(0, 0, 100, 100));
3123 
3124  QScopedPointer<QGraphicsView> dummyView(new QGraphicsView(&dummyScene));
3125  dummyView->setWindowFlags(Qt::X11BypassWindowManagerHint);
3126  EventSpy paintSpy(dummyView->viewport(), QEvent::Paint);
3127  dummyView->show();
3128  qApp->setActiveWindow(dummyView.data());
3129  QVERIFY(QTest::qWaitForWindowActive(dummyView.data()));
3130  const int expectedRepaintCount = paintSpy.count();
3131  dummyView.reset();
3132 
3134  widget->resize(100, 100);
3135 
3136  QGraphicsScene scene(0, 0, 200, 200);
3137  scene.addItem(widget);
3138 
3140  view.setWindowFlags(view.windowFlags()|Qt::X11BypassWindowManagerHint);
3141  view.show();
3142  qApp->setActiveWindow(&view);
3144 
3145  QTRY_COMPARE(widget->repaints, expectedRepaintCount);
3146 }
3147 
3148 void tst_QGraphicsWidget::itemChangeEvents()
3149 {
3150  class TestGraphicsWidget : public QGraphicsWidget
3151  { public:
3153  QHash<QEvent::Type, QVariant> valueDuringEvents;
3154  bool event(QEvent *event) override {
3155  Q_UNUSED(event);
3156  switch (event->type()) {
3157  case QEvent::EnabledChange: {
3158  valueDuringEvents.insert(QEvent::EnabledChange, isEnabled());
3159  break;
3160  }
3162  valueDuringEvents.insert(QEvent::ParentAboutToChange, QVariant::fromValue(parentItem()));
3163  break;
3164  }
3165  case QEvent::ParentChange: {
3166  valueDuringEvents.insert(QEvent::ParentChange, QVariant::fromValue(parentItem()));
3167  break;
3168  }
3169 #ifndef QT_NO_CURSOR
3170  case QEvent::CursorChange: {
3171  valueDuringEvents.insert(QEvent::CursorChange, int(cursor().shape()));
3172  break;
3173  }
3174 #endif
3175  case QEvent::ToolTipChange: {
3176  valueDuringEvents.insert(QEvent::ToolTipChange, toolTip());
3177  break;
3178  }
3179  default: {
3180  break;
3181  }
3182  }
3183  return true;
3184  }
3185  void showEvent(QShowEvent *event) override {
3186  Q_UNUSED(event);
3187  valueDuringEvents.insert(QEvent::Show, isVisible());
3188  }
3189  void hideEvent(QHideEvent *event) override {
3190  Q_UNUSED(event);
3191  valueDuringEvents.insert(QEvent::Hide, isVisible());
3192  }
3193  };
3194 
3198  scene.addItem(parent);
3199  view.show();
3201 
3204  // ParentAboutToChange should be triggered before the parent has changed
3205  QTRY_COMPARE(qvariant_cast<QGraphicsItem *>(item->valueDuringEvents.value(QEvent::ParentAboutToChange)),
3206  static_cast<QGraphicsItem *>(0));
3207  // ParentChange should be triggered after the parent has changed
3208  QTRY_COMPARE(qvariant_cast<QGraphicsItem *>(item->valueDuringEvents.value(QEvent::ParentChange)),
3209  static_cast<QGraphicsItem *>(parent));
3210 
3211  // ShowEvent should be triggered before the item is shown
3212  QTRY_VERIFY(!item->valueDuringEvents.value(QEvent::Show).toBool());
3213 
3214  // HideEvent should be triggered after the item is hidden
3215  QVERIFY(item->isVisible());
3216  item->setVisible(false);
3217  QVERIFY(!item->isVisible());
3218  QTRY_VERIFY(!item->valueDuringEvents.value(QEvent::Hide).toBool());
3219 
3220 #ifndef QT_NO_CURSOR
3221  // CursorChange should be triggered after the cursor has changed
3223  QTRY_COMPARE(item->valueDuringEvents.value(QEvent::CursorChange).toInt(), int(item->cursor().shape()));
3224 #endif
3225 
3226  // ToolTipChange should be triggered after the tooltip has changed
3227  item->setToolTip("tooltipText");
3228  QTRY_COMPARE(item->valueDuringEvents.value(QEvent::ToolTipChange).toString(), item->toolTip());
3229 
3230  // EnabledChange should be triggered after the enabled state has changed
3231  QVERIFY(item->isEnabled());
3232  item->setEnabled(false);
3233  QVERIFY(!item->isEnabled());
3234  QTRY_VERIFY(!item->valueDuringEvents.value(QEvent::EnabledChange).toBool());
3235 }
3236 
3237 void tst_QGraphicsWidget::itemSendGeometryPosChangesDeactivated()
3238 {
3242  scene.addItem(item);
3243  view.show();
3245  item->setGeometry(QRectF(0, 0, 50, 50));
3246  QTRY_COMPARE(item->geometry(), QRectF(0, 0, 50, 50));
3247 
3249  item->setGeometry(QRectF(0, 0, 60, 60));
3250  QCOMPARE(item->geometry(), QRectF(0, 0, 60, 60));
3251  QCOMPARE(item->pos(), QPointF(0, 0));
3252  item->setPos(QPointF(10, 10));
3253  QCOMPARE(item->pos(), QPointF(10, 10));
3254  QCOMPARE(item->geometry(), QRectF(10, 10, 60, 60));
3255 
3257  item->setGeometry(QRectF(0, 0, 60, 60));
3258  QCOMPARE(item->geometry(), QRectF(0, 0, 60, 60));
3259  QCOMPARE(item->pos(), QPointF(0, 0));
3260  item->setPos(QPointF(10, 10)); QCOMPARE(item->pos(), QPointF(10, 10));
3261  QCOMPARE(item->geometry(), QRectF(10, 10, 60, 60));
3262 }
3263 
3265 {
3266  Q_OBJECT
3267 public:
3271 };
3272 
3273 void verifyTabFocus(QGraphicsScene *scene, const QList<QGraphicsWidget *> &chain, bool wrapsAround)
3274 {
3275  QKeyEvent tabEvent(QEvent::KeyPress, Qt::Key_Tab, {});
3276  QKeyEvent backtabEvent(QEvent::KeyPress, Qt::Key_Backtab, {});
3277 
3278  for (int i = 0; i < chain.size(); ++i)
3279  chain.at(i)->clearFocus();
3280 
3281  int n = chain.size() * (wrapsAround ? 3 : 1);
3282  for (int i = 0; i < n; ++i)
3283  {
3284  qApp->sendEvent(scene, &tabEvent);
3285  QVERIFY(chain.at(i % chain.size())->hasFocus());
3286  QCOMPARE(scene->focusItem(), chain.at(i % chain.size()));
3287  }
3288  for (int i = n - 2; i >= 0; --i)
3289  {
3290  qApp->sendEvent(scene, &backtabEvent);
3291  QVERIFY(chain.at(i % chain.size())->hasFocus());
3292  QCOMPARE(scene->focusItem(), chain.at(i % chain.size()));
3293  }
3294 }
3295 
3296 void tst_QGraphicsWidget::tabFocus()
3297 {
3299  scene.setFocus();
3300 
3301  QEvent activate(QEvent::WindowActivate);
3302  qApp->sendEvent(&scene, &activate);
3303 
3304  TabFocusWidget *widget = new TabFocusWidget("1");
3305  scene.addItem(widget);
3307 
3308  TabFocusWidget *widget2 = new TabFocusWidget("2");
3309  scene.addItem(widget2);
3310  scene.setFocusItem(0);
3311  verifyTabFocus(&scene, QList<QGraphicsWidget *>() << widget << widget2, false);
3312 
3313  TabFocusWidget *widget3 = new TabFocusWidget("3");
3315  scene.addItem(widget3);
3316  QCOMPARE(scene.activePanel(), (QGraphicsItem *)widget3);
3317  scene.setActivePanel(0);
3318  scene.setFocusItem(0);
3319  verifyTabFocus(&scene, QList<QGraphicsWidget *>() << widget << widget2, false);
3320 
3321  scene.setActivePanel(widget3);
3322  QCOMPARE(scene.focusItem(), (QGraphicsItem *)widget3);
3323  verifyTabFocus(&scene, QList<QGraphicsWidget *>() << widget3, true);
3324 
3325  TabFocusWidget *widget4 = new TabFocusWidget("4");
3326  widget4->setParentItem(widget3);
3327  QVERIFY(widget3->hasFocus());
3328  widget3->clearFocus();
3329  QVERIFY(!widget3->focusItem());
3330  QCOMPARE(scene.activePanel(), (QGraphicsItem *)widget3);
3331  verifyTabFocus(&scene, QList<QGraphicsWidget *>() << widget3 << widget4, true);
3332 
3333  QGraphicsWidget *widget5 = new QGraphicsWidget; widget5->setData(0, QLatin1String("5"));
3334  widget5->setParentItem(widget3);
3335  verifyTabFocus(&scene, QList<QGraphicsWidget *>() << widget3 << widget4, true);
3336 
3337  widget5->setFocusPolicy(Qt::TabFocus);
3338  verifyTabFocus(&scene, QList<QGraphicsWidget *>() << widget3 << widget4 << widget5, true);
3339 
3340  TabFocusWidget *widget6 = new TabFocusWidget("6");
3341  widget6->setParentItem(widget4);
3342  verifyTabFocus(&scene, QList<QGraphicsWidget *>() << widget3 << widget4 << widget6 << widget5, true);
3343 
3344  TabFocusWidget *widget7 = new TabFocusWidget("7", widget6);
3345  verifyTabFocus(&scene, QList<QGraphicsWidget *>() << widget3 << widget4 << widget6 << widget7 << widget5, true);
3346 
3347  TabFocusWidget *widget8 = new TabFocusWidget("8", widget6);
3348  verifyTabFocus(&scene, QList<QGraphicsWidget *>() << widget3 << widget4 << widget6 << widget7 << widget8 << widget5, true);
3350  widget6->setActive(true);
3351  verifyTabFocus(&scene, QList<QGraphicsWidget *>() << widget6 << widget7 << widget8, true);
3352  widget3->setActive(true);
3353  verifyTabFocus(&scene, QList<QGraphicsWidget *>() << widget3 << widget4 << widget5, true);
3354  widget6->setFlag(QGraphicsItem::ItemIsPanel, false);
3355  verifyTabFocus(&scene, QList<QGraphicsWidget *>() << widget3 << widget4 << widget6 << widget7 << widget8 << widget5, true);
3356  scene.removeItem(widget6);
3357  verifyTabFocus(&scene, QList<QGraphicsWidget *>() << widget3 << widget4 << widget5, true);
3358  delete widget6;
3359 }
3360 
3361 void tst_QGraphicsWidget::windowFrameSectionAt()
3362 {
3364  widget.setWindowFrameMargins(5, 5, 5, 5);
3365  widget.setGeometry(0, 0, 200, 200);
3366 
3367  QCOMPARE(widget.call_windowFrameSectionAt(QPointF(50, 50)), Qt::NoSection);
3368  QCOMPARE(widget.call_windowFrameSectionAt(QPointF(-2, -2)), Qt::TopLeftSection);
3369  QCOMPARE(widget.call_windowFrameSectionAt(QPointF(-2, 10)), Qt::TopLeftSection);
3370  QCOMPARE(widget.call_windowFrameSectionAt(QPointF(-2, 30)), Qt::LeftSection);
3371  QCOMPARE(widget.call_windowFrameSectionAt(QPointF(-2, 170)), Qt::LeftSection);
3372  QCOMPARE(widget.call_windowFrameSectionAt(QPointF(-2, 198)), Qt::BottomLeftSection);
3373  QCOMPARE(widget.call_windowFrameSectionAt(QPointF(-2, 202)), Qt::BottomLeftSection);
3374 
3375  QCOMPARE(widget.call_windowFrameSectionAt(QPointF(202, -2)), Qt::TopRightSection);
3376  QCOMPARE(widget.call_windowFrameSectionAt(QPointF(202, 10)), Qt::TopRightSection);
3377  QCOMPARE(widget.call_windowFrameSectionAt(QPointF(202, 30)), Qt::RightSection);
3378  QCOMPARE(widget.call_windowFrameSectionAt(QPointF(202, 170)), Qt::RightSection);
3379  QCOMPARE(widget.call_windowFrameSectionAt(QPointF(202, 198)), Qt::BottomRightSection);
3380  QCOMPARE(widget.call_windowFrameSectionAt(QPointF(202, 202)), Qt::BottomRightSection);
3381 
3382  QCOMPARE(widget.call_windowFrameSectionAt(QPointF(50, -2)), Qt::TopSection);
3383  QCOMPARE(widget.call_windowFrameSectionAt(QPointF(50, 202)), Qt::BottomSection);
3384 }
3385 
3386 void tst_QGraphicsWidget::QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems()
3387 {
3389  QGraphicsWidget* parent1 = new QGraphicsWidget;
3390  QGraphicsWidget* child1_0 = new QGraphicsWidget;
3391  QGraphicsWidget* child1_1 = new QGraphicsWidget;
3392 
3393  QGraphicsWidget* parent2 = new QGraphicsWidget;
3394 
3395  // Add the parent and child to the scene.
3396  scene.addItem(parent1);
3397  child1_0->setParentItem(parent1);
3398  child1_1->setParentItem(parent1);
3399 
3400  // Hide and show the child.
3401  child1_0->setParentItem(NULL);
3402  scene.removeItem(child1_0);
3403 
3404  // Remove parent from the scene.
3405  scene.removeItem(parent1);
3406 
3407  delete child1_0;
3408  delete child1_1;
3409  delete parent1;
3410 
3411  // Add an item into the scene.
3412  scene.addItem(parent2);
3413 
3414  //This should not crash
3415 }
3416 void tst_QGraphicsWidget::QT_BUG_12056_tabFocusFirstUnsetWhenRemovingItems()
3417 {
3419  QGraphicsWidget* item1 = new QGraphicsWidget;
3420  QGraphicsWidget* item2 = new QGraphicsWidget;
3421  QGraphicsWidget* item3 = new QGraphicsWidget;
3422 
3423  scene.addItem(item1);
3424  scene.addItem(item2);
3425 
3426  scene.removeItem(item2);
3427  scene.removeItem(item1);
3428  delete item2;
3429  delete item1;
3430 
3431  scene.addItem(item3);
3432 
3433  //This should not crash
3434 }
3435 
3436 void tst_QGraphicsWidget::QTBUG_45867_send_itemChildAddedChange_to_parent()
3437 {
3438  class GraphicsItem : public QGraphicsItem
3439  {
3440  public:
3441  int m_itemChildAddedChangeNotificationsCount;
3442 
3443  GraphicsItem()
3444  : QGraphicsItem(),
3445  m_itemChildAddedChangeNotificationsCount(0)
3446  {
3447  }
3448 
3449  QRectF boundingRect() const override { return QRectF(); }
3450 
3451  void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override {}
3452 
3453  protected:
3454  QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) override
3455  {
3457  ++m_itemChildAddedChangeNotificationsCount;
3458  return QGraphicsItem::itemChange(change, value);
3459  }
3460  };
3461 
3462  GraphicsItem item;
3464  QCOMPARE(item.m_itemChildAddedChangeNotificationsCount, 1);
3465 }
3466 
3468 #include "tst_qgraphicswidget.moc"
small capitals from c petite p scientific i
[1]
Definition: afcover.h:80
Arabic default style
Definition: afstyles.h:94
void verifyTabFocus(QGraphicsScene *scene, const QList< QGraphicsWidget * > &chain, bool wrapsAround)
bool compareFocusChain(QGraphicsView *view, Iterator i1, Iterator i2, QByteArray *errorMessage)
@ PreferredWidth
@ PreferredSizeHint
@ MinimumSizeHint
@ MaximumSizeHint
@ PreferredHeight
QPair< int, QVariant > Inst
QList< QGraphicsItem * > QGraphicsItemList
#define value
[5]
void drawItems(QPainter *painter, int numItems, QGraphicsItem *items[], const QStyleOptionGraphicsItem options[], QWidget *widget=0) override
QList< QGraphicsItem * > drawnItems
EventSpy(QObject *watched, QEvent::Type type)
bool eventFilter(QObject *watched, QEvent *event) override
const QEvent::Type spied
int count() const
void focusOutEvent(QFocusEvent *fe) override
FocusWatchWidget(QGraphicsItem *parent=nullptr)
void focusInEvent(QFocusEvent *fe) override
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) override
void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override
GrabOnPressItem(const QRectF &rect)
void mousePressEvent(QGraphicsSceneMouseEvent *) override
bool sceneEvent(QEvent *event) override
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const override
QList< GraphicsItemChange > changes
QList< QVariant > values
QList< QVariant > oldValues
ItemChangeTester(QGraphicsItem *parent)
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
MessUpPainterWidget(QGraphicsItem *parent=nullptr, Qt::WindowFlags wFlags={ })
void polishEvent() override
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
PolishWidget(Qt::GlobalColor color, QGraphicsItem *parent=0)
int pixelMetric(QStyle::PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const override
ProxyStyle(QStyle *proxyStyle)
The QAction class provides an abstraction for user commands that can be added to different user inter...
Definition: qaction.h:65
void setIcon(const QIcon &icon)
Definition: qaction.cpp:585
static QPalette palette()
static QWidget * focusWidget()
static QFont font()
static QWidget * activeWindow()
static void setActiveWindow(QWidget *act)
void addWidget(QWidget *, int stretch=0, Qt::Alignment alignment=Qt::Alignment())
void addItem(QLayoutItem *) override
Definition: qboxlayout.cpp:832
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:66
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:85
const char * constData() const noexcept
Definition: qbytearray.h:144
static QByteArray number(int, int base=10)
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
The QCommonStyle class encapsulates the common Look and Feel of a GUI.
Definition: qcommonstyle.h:51
static bool sendEvent(QObject *receiver, QEvent *event)
static void processEvents(QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
static void setPos(int x, int y)
Definition: qcursor.cpp:276
Qt::CursorShape shape() const
Definition: qcursor.cpp:535
The QEvent class is the base class of all event classes. Event objects contain event parameters.
Definition: qcoreevent.h:58
@ ParentChange
Definition: qcoreevent.h:93
@ EnabledChange
Definition: qcoreevent.h:147
@ GraphicsSceneMouseRelease
Definition: qcoreevent.h:204
@ Hide
Definition: qcoreevent.h:90
@ FocusOut
Definition: qcoreevent.h:80
@ GraphicsSceneMousePress
Definition: qcoreevent.h:203
@ CursorChange
Definition: qcoreevent.h:241
@ UngrabMouse
Definition: qcoreevent.h:247
@ FontChange
Definition: qcoreevent.h:146
@ Shortcut
Definition: qcoreevent.h:170
@ MouseMove
Definition: qcoreevent.h:76
@ KeyPress
Definition: qcoreevent.h:77
@ Show
Definition: qcoreevent.h:89
@ Paint
Definition: qcoreevent.h:84
@ FocusIn
Definition: qcoreevent.h:79
@ ToolTipChange
Definition: qcoreevent.h:242
@ ParentAboutToChange
Definition: qcoreevent.h:94
@ WindowActivate
Definition: qcoreevent.h:96
@ GraphicsSceneMouseDoubleClick
Definition: qcoreevent.h:205
@ Polish
Definition: qcoreevent.h:124
@ WindowDeactivate
Definition: qcoreevent.h:97
@ GrabMouse
Definition: qcoreevent.h:246
The QFocusEvent class contains event parameters for widget focus events. \inmodule QtGui.
Definition: qevent.h:520
The QFont class specifies a query for a font used for drawing text.
Definition: qfont.h:56
QString family() const
Definition: qfont.cpp:821
void setPointSize(int)
Definition: qfont.cpp:1006
bool italic() const
Definition: qfont.h:338
@ SizeResolved
Definition: qfont.h:148
@ WeightResolved
Definition: qfont.h:151
@ StyleResolved
Definition: qfont.h:152
int pointSize() const
Definition: qfont.cpp:899
void setBold(bool)
Definition: qfont.h:335
void setItalic(bool b)
Definition: qfont.h:343
uint resolveMask() const
Definition: qfont.h:274
bool bold() const
Definition: qfont.h:331
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:56
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:83
friend class QGraphicsWidget
void setData(int key, const QVariant &value)
void update(const QRectF &rect=QRectF())
QGraphicsWidget * parentWidget() const
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value)
QPointF pos() const
@ ItemClipsChildrenToShape
Definition: qgraphicsitem.h:90
@ ItemSendsScenePositionChanges
@ ItemSendsGeometryChanges
Definition: qgraphicsitem.h:97
void setZValue(qreal z)
QCursor cursor() const
void setPos(const QPointF &pos)
bool isEnabled() const
bool hasFocus() const
void setParentItem(QGraphicsItem *parent)
qreal zValue() const
void setEnabled(bool enabled)
QVariant data(int key) const
void setFlag(GraphicsItemFlag flag, bool enabled=true)
void setActive(bool active)
void setVisible(bool visible)
bool isVisible() const
QGraphicsItem * focusItem() const
void setFocus(Qt::FocusReason focusReason=Qt::OtherFocusReason)
void setCursor(const QCursor &cursor)
virtual bool sceneEvent(QEvent *event)
The QGraphicsLayout class provides the base class for all layouts in Graphics View.
The QGraphicsLineItem class provides a line item that you can add to a QGraphicsScene.
The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Grap...
QPointF pos
the position of the item
QGraphicsObject * parent
the parent of the item
The QGraphicsPixmapItem class provides a pixmap item that you can add to a QGraphicsScene.
The QGraphicsRectItem class provides a rectangle item that you can add to a QGraphicsScene.
QRectF rect() const
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items.
QList< QGraphicsItem * > items(Qt::SortOrder order=Qt::DescendingOrder) const
void removeItem(QGraphicsItem *item)
void setFont(const QFont &font)
bool hasFocus() const
void addItem(QGraphicsItem *item)
void setFocusItem(QGraphicsItem *item, Qt::FocusReason focusReason=Qt::OtherFocusReason)
virtual void drawItems(QPainter *painter, int numItems, QGraphicsItem *items[], const QStyleOptionGraphicsItem options[], QWidget *widget=nullptr)
void setActivePanel(QGraphicsItem *item)
QGraphicsItem * activePanel() const
void setSceneRect(const QRectF &rect)
QPalette palette
the scene's default palette
void setActiveWindow(QGraphicsWidget *widget)
QFont font
the scene's default font
void setFocus(Qt::FocusReason focusReason=Qt::OtherFocusReason)
QGraphicsItem * focusItem() const
void render(QPainter *painter, const QRectF &target=QRectF(), const QRectF &source=QRectF(), Qt::AspectRatioMode aspectRatioMode=Qt::KeepAspectRatio)
QGraphicsItem * mouseGrabberItem() const
The QGraphicsSceneMouseEvent class provides mouse events in the graphics view framework.
The QGraphicsSceneMoveEvent class provides events for widget moving in the graphics view framework.
The QGraphicsSceneResizeEvent class provides events for widget resizing in the graphics view framewor...
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:60
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.
virtual void hideEvent(QHideEvent *event)
virtual bool focusNextPrevChild(bool next)
void setStyle(QStyle *style)
QStyle * style() const
void setFocusPolicy(Qt::FocusPolicy policy)
void setFont(const QFont &font)
virtual void moveEvent(QGraphicsSceneMoveEvent *event)
QRectF rect() const
Qt::WindowFlags windowFlags
the widget's window flags
virtual void polishEvent()
bool sceneEvent(QEvent *event) override
virtual void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=nullptr)
bool isActiveWindow() const
void setGeometry(const QRectF &rect) override
void resize(const QSizeF &size)
bool event(QEvent *event) override
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
virtual Qt::WindowFrameSection windowFrameSectionAt(const QPointF &pos) const
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=nullptr) override
QPalette palette
the widget's palette
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const override
virtual QVariant propertyChange(const QString &propertyName, const QVariant &value)
void setWindowFlags(Qt::WindowFlags wFlags)
virtual void changeEvent(QEvent *event)
QRectF boundingRect() const override
void addAction(QAction *action)
void focusOutEvent(QFocusEvent *event) override
QFont font
the widgets' font
virtual void showEvent(QShowEvent *event)
void setShortcutEnabled(int id, bool enabled=true)
virtual void initStyleOption(QStyleOption *option) const
void setPalette(const QPalette &palette)
int grabShortcut(const QKeySequence &sequence, Qt::ShortcutContext context=Qt::WindowShortcut)
void updateGeometry() override
void focusInEvent(QFocusEvent *event) override
virtual void resizeEvent(QGraphicsSceneResizeEvent *event)
static void setTabOrder(QGraphicsWidget *first, QGraphicsWidget *second)
QScreen * primaryScreen
the primary (or default) screen of the application.
static void setLayoutDirection(Qt::LayoutDirection direction)
The QHBoxLayout class lines up widgets horizontally.
Definition: qboxlayout.h:114
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qhash.h:773
iterator insert(const Key &key, const T &value)
Definition: qhash.h:1228
The QHideEvent class provides an event which is sent after a widget is hidden.
Definition: qevent.h:656
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:56
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:73
@ Format_RGB32
Definition: qimage.h:82
The QKeyEvent class describes a key event.
Definition: qevent.h:471
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
Definition: qstring.h:84
virtual QSize minimumSize() const =0
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:64
qsizetype size() const noexcept
Definition: qlist.h:414
bool isEmpty() const noexcept
Definition: qlist.h:418
const_reference at(qsizetype i) const noexcept
Definition: qlist.h:457
qsizetype count() const noexcept
Definition: qlist.h:415
T & first()
Definition: qlist.h:643
void append(parameter_type t)
Definition: qlist.h:469
void clear()
Definition: qlist.h:445
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:231
The QObject class is the base class of all Qt objects.
Definition: qobject.h:125
void installEventFilter(QObject *filterObj)
Definition: qobject.cpp:2235
const QObjectList & children() const
Definition: qobject.h:206
QObject * parent() const
Definition: qobject.h:409
virtual bool event(QEvent *event)
Definition: qobject.cpp:1329
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:82
Qt::LayoutDirection layoutDirection() const
Definition: qpainter.cpp:7367
void drawRect(const QRectF &rect)
Definition: qpainter.h:554
qreal opacity() const
Definition: qpainter.cpp:2044
void setPen(const QColor &color)
Definition: qpainter.cpp:3640
void drawLine(const QLineF &line)
Definition: qpainter.h:477
bool begin(QPaintDevice *)
Definition: qpainter.cpp:1709
void setOpacity(qreal opacity)
Definition: qpainter.cpp:2065
void setBrush(const QBrush &brush)
Definition: qpainter.cpp:3755
bool end()
Definition: qpainter.cpp:1877
void fillRect(const QRectF &, const QBrush &)
Definition: qpainter.cpp:6644
void drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize)
Definition: qpainter.cpp:3924
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:55
const QColor & color(ColorGroup cg, ColorRole cr) const
Definition: qpalette.h:101
void setColor(ColorGroup cg, ColorRole cr, const QColor &color)
Definition: qpalette.h:179
@ ToolTipBase
Definition: qpalette.h:92
@ Button
Definition: qpalette.h:86
@ Window
Definition: qpalette.h:87
@ Text
Definition: qpalette.h:87
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:61
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:242
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:52
The QRectF class defines a finite rectangle in the plane using floating point precision.
Definition: qrect.h:511
constexpr QPointF topLeft() const noexcept
Definition: qrect.h:538
constexpr QSizeF size() const noexcept
Definition: qrect.h:744
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:59
constexpr QPoint topLeft() const noexcept
Definition: qrect.h:248
constexpr QSize size() const noexcept
Definition: qrect.h:269
constexpr int width() const noexcept
Definition: qrect.h:263
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
QRect availableGeometry
the screen's available geometry in pixels
Definition: qscreen.h:82
The QShowEvent class provides an event that is sent when a widget is shown.
Definition: qevent.h:647
The QSizeF class defines the size of a two-dimensional object using floating point precision.
Definition: qsize.h:235
constexpr qreal width() const noexcept
Definition: qsize.h:349
constexpr QSizeF expandedTo(const QSizeF &) const noexcept
Definition: qsize.h:408
constexpr QSizeF boundedTo(const QSizeF &) const noexcept
Definition: qsize.h:413
constexpr qreal height() const noexcept
Definition: qsize.h:352
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:55
The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy.
Definition: qsizepolicy.h:54
The QString class provides a Unicode character string.
Definition: qstring.h:388
static QStyle * create(const QString &)
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
Definition: qstyle.h:65
@ State_MouseOver
Definition: qstyle.h:116
@ State_HasFocus
Definition: qstyle.h:111
@ State_Enabled
Definition: qstyle.h:103
PixelMetric
Definition: qstyle.h:449
@ PM_SmallIconSize
Definition: qstyle.h:529
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const =0
The QStyleOptionGraphicsItem class is used to describe the parameters needed to draw a QGraphicsItem.
Definition: qstyleoption.h:684
The QStyleOption class stores the parameters used by QStyle functions.
Definition: qstyleoption.h:75
The QVBoxLayout class lines up widgets vertically.
Definition: qboxlayout.h:127
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:95
static auto fromValue(const T &value) -> std::enable_if_t< std::is_copy_constructible_v< T >, QVariant >
Definition: qvariant.h:391
QByteArray toByteArray() const
Definition: qvariant.cpp:1519
The QWidgetAction class extends QAction by an interface for inserting custom widgets into action base...
Definition: qwidgetaction.h:53
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:133
void setAutoFillBackground(bool enabled)
Definition: qwidget.cpp:361
void setLayout(QLayout *)
Definition: qwidget.cpp:10146
void setAttribute(Qt::WidgetAttribute, bool on=true)
Definition: qwidget.cpp:11088
void setGeometry(int x, int y, int w, int h)
Definition: qwidget.h:919
Qt::LayoutDirection layoutDirection
the layout direction for this widget.
Definition: qwidget.h:204
Qt::WindowFlags windowFlags() const
Definition: qwidget.h:836
bool autoFillBackground
whether the widget background is filled automatically
Definition: qwidget.h:206
void setContentsMargins(int left, int top, int right, int bottom)
Definition: qwidget.cpp:7545
void setMinimumSize(const QSize &)
Definition: qwidget.h:865
QWidget * topLevelWidget() const
Definition: qwidget.h:343
void setSizePolicy(QSizePolicy)
void setStyle(QStyle *)
Definition: qwidget.cpp:2642
void setMinimumWidth(int minw)
Definition: qwidget.cpp:4118
QSize size
the size of the widget excluding any window frame
Definition: qwidget.h:147
QSize minimumSize
the widget's minimum size
Definition: qwidget.h:154
void setEnabled(bool)
Definition: qwidget.cpp:3368
QRect geometry
the geometry of the widget relative to its parent and excluding the window frame
Definition: qwidget.h:140
QLayout * layout() const
Definition: qwidget.cpp:10115
void setPalette(const QPalette &)
Definition: qwidget.cpp:4536
QPalette palette
the widget's palette
Definition: qwidget.h:166
QSize maximumSize
the widget's maximum size in pixels
Definition: qwidget.h:155
QPoint pos
the position of the widget within its parent widget
Definition: qwidget.h:145
QWidget * focusWidget() const
Definition: qwidget.cpp:6810
void setMaximumHeight(int maxh)
Definition: qwidget.cpp:4145
void setFocusPolicy(Qt::FocusPolicy policy)
Definition: qwidget.cpp:7773
void hide()
Definition: qwidget.cpp:8078
int minimumWidth
the widget's minimum width in pixels
Definition: qwidget.h:157
void setMinimumHeight(int minh)
Definition: qwidget.cpp:4127
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:150
void setFocus()
Definition: qwidget.h:454
void setLayoutDirection(Qt::LayoutDirection direction)
Definition: qwidget.cpp:4885
void show()
Definition: qwidget.cpp:7825
virtual void setVisible(bool visible)
Definition: qwidget.cpp:8198
void setMaximumSize(const QSize &)
Definition: qwidget.h:868
QStyle * style() const
Definition: qwidget.cpp:2612
int maximumWidth
the widget's maximum width in pixels
Definition: qwidget.h:161
void setFont(const QFont &)
Definition: qwidget.cpp:4673
QFont font
the font currently set for the widget
Definition: qwidget.h:167
void resize(int w, int h)
Definition: qwidget.h:916
bool hasFocus() const
Definition: qwidget.cpp:6430
Qt::FocusPolicy focusPolicy
the way the widget accepts keyboard focus
Definition: qwidget.h:174
QWidget * parentWidget() const
Definition: qwidget.h:937
void grabMouse()
Definition: qwidget.cpp:12550
bool isWindow() const
Definition: qwidget.h:844
bool isActiveWindow
whether this widget's window is the active window
Definition: qwidget.h:173
void unsetLayoutDirection()
Definition: qwidget.cpp:4903
bool isVisible() const
Definition: qwidget.h:907
bool testAttribute(Qt::WidgetAttribute) const
Definition: qwidget.h:943
void setMaximumWidth(int maxw)
Definition: qwidget.cpp:4136
RectItem(Qt::GlobalColor color, QGraphicsItem *parent=0)
QRectF boundingRect() const override
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
Qt::GlobalColor mColor
RectWidget(Qt::GlobalColor color, QGraphicsItem *parent=0)
Qt::GlobalColor mColor
void setGeometry(const QRectF &rect) override
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const override
SizeHinter(QGraphicsItem *parent=nullptr, Qt::WindowFlags wFlags={ }, const QSizeF &min=QSizeF(5, 5), const QSizeF &pref=QSizeF(50, 50), const QSizeF &max=QSizeF(500, 500))
void setSizeHint(Qt::SizeHint which, const QSizeF &newSizeHint)
StyledGraphicsWidget(bool useOwnStyle)
bool call_sceneEvent(QEvent *event)
bool event(QEvent *event) override
void call_focusInEvent(QFocusEvent *event)
void call_hideEvent(QHideEvent *event)
SubQGraphicsWidget(QGraphicsItem *parent=nullptr, Qt::WindowFlags windowFlags={ })
bool call_event(QEvent *e)
QVariant call_itemChange(QGraphicsItem::GraphicsItemChange change, QVariant const &value)
void initStyleOption(QStyleOption *option) const override
QVariant call_propertyChange(QString const &propertyName, QVariant const &value)
void call_focusOutEvent(QFocusEvent *event)
bool call_focusNextPrevChild(bool next)
void call_resizeEvent(QGraphicsSceneResizeEvent *event)
QSizeF call_sizeHint(Qt::SizeHint which, QSizeF const &constraint=QSizeF()) const
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
Qt::LayoutDirection m_painterLayoutDirection
Qt::WindowFrameSection call_windowFrameSectionAt(const QPointF &pos) const
void call_moveEvent(QGraphicsSceneMoveEvent *event)
void call_changeEvent(QEvent *event)
void call_showEvent(QShowEvent *event)
TabFocusWidget(const QString &name, QGraphicsItem *parent=nullptr)
[Window class definition]
Definition: window.h:64
QOpenGLWidget * widget
[1]
QString str
[2]
QPainter paint
bool focus
[0]
QCursor cursor
double e
QSignalSpy spy(myCustomObject, SIGNAL(mySignal(int, QString, double)))
[0]
QCOMPARE(spy.count(), 1)
rect
[4]
palette
#define NULL
Definition: ftobjs.h:61
short next
Definition: keywords.cpp:454
Q_TESTLIB_EXPORT QTestData & newRow(const char *dataTag)
Definition: qtestcase.cpp:2658
Q_GUI_EXPORT bool qWaitForWindowActive(QWindow *window, int timeout=5000)
Q_GUI_EXPORT bool qWaitForWindowExposed(QWindow *window, int timeout=5000)
void mouseMove(QWindow *window, QPoint pos=QPoint(), int delay=-1)
Definition: qtestmouse.h:175
Q_TESTLIB_EXPORT void ignoreMessage(QtMsgType type, const char *message)
Definition: qtestcase.cpp:2292
void mouseClick(QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey=Qt::KeyboardModifiers(), QPoint pos=QPoint(), int delay=-1)
Definition: qtestmouse.h:167
void mousePress(QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey=Qt::KeyboardModifiers(), QPoint pos=QPoint(), int delay=-1)
Definition: qtestmouse.h:159
Q_CORE_EXPORT void qWait(int ms)
Definition: qnamespace.h:55
@ AlignTop
Definition: qnamespace.h:178
@ AlignLeft
Definition: qnamespace.h:169
@ RelativeSize
Definition: qnamespace.h:1163
@ LeftButton
Definition: qnamespace.h:83
@ NoButton
Definition: qnamespace.h:82
WidgetAttribute
Definition: qnamespace.h:307
@ WA_SetLayoutDirection
Definition: qnamespace.h:348
@ WA_RightToLeft
Definition: qnamespace.h:347
@ WA_Resized
Definition: qnamespace.h:333
@ WA_SetStyle
Definition: qnamespace.h:381
@ WA_AcceptDrops
Definition: qnamespace.h:371
LayoutDirection
Definition: qnamespace.h:1462
@ LeftToRight
Definition: qnamespace.h:1463
@ RightToLeft
Definition: qnamespace.h:1464
FocusPolicy
Definition: qnamespace.h:131
@ WheelFocus
Definition: qnamespace.h:136
@ ClickFocus
Definition: qnamespace.h:134
@ NoFocus
Definition: qnamespace.h:132
@ TabFocus
Definition: qnamespace.h:133
@ StrongFocus
Definition: qnamespace.h:135
@ PointingHandCursor
Definition: qnamespace.h:1190
GlobalColor
Definition: qnamespace.h:58
@ darkCyan
Definition: qnamespace.h:75
@ white
Definition: qnamespace.h:62
@ blue
Definition: qnamespace.h:68
@ magenta
Definition: qnamespace.h:70
@ yellow
Definition: qnamespace.h:71
@ black
Definition: qnamespace.h:61
@ red
Definition: qnamespace.h:66
@ DotLine
Definition: qnamespace.h:1115
@ SolidLine
Definition: qnamespace.h:1113
@ DashLine
Definition: qnamespace.h:1114
@ Key_Tab
Definition: qnamespace.h:685
@ Key_B
Definition: qnamespace.h:573
@ Key_Backtab
Definition: qnamespace.h:686
@ Key_A
Definition: qnamespace.h:572
@ Key_Delete
Definition: qnamespace.h:691
@ NoModifier
Definition: qnamespace.h:1074
WindowFrameSection
Definition: qnamespace.h:1597
@ LeftSection
Definition: qnamespace.h:1599
@ NoSection
Definition: qnamespace.h:1598
@ BottomSection
Definition: qnamespace.h:1605
@ TopRightSection
Definition: qnamespace.h:1602
@ TopLeftSection
Definition: qnamespace.h:1600
@ BottomLeftSection
Definition: qnamespace.h:1606
@ BottomRightSection
Definition: qnamespace.h:1604
@ TopSection
Definition: qnamespace.h:1601
@ RightSection
Definition: qnamespace.h:1603
QTextStream & center(QTextStream &stream)
@ CustomizeWindowHint
Definition: qnamespace.h:264
@ FramelessWindowHint
Definition: qnamespace.h:250
@ WindowContextHelpButtonHint
Definition: qnamespace.h:256
@ Popup
Definition: qnamespace.h:236
@ Window
Definition: qnamespace.h:232
@ WindowMaximizeButtonHint
Definition: qnamespace.h:254
@ WindowMinimizeButtonHint
Definition: qnamespace.h:253
@ Dialog
Definition: qnamespace.h:233
@ Sheet
Definition: qnamespace.h:234
@ SubWindow
Definition: qnamespace.h:241
@ Tool
Definition: qnamespace.h:237
@ WindowTitleHint
Definition: qnamespace.h:251
@ X11BypassWindowManagerHint
Definition: qnamespace.h:249
@ WindowSystemMenuHint
Definition: qnamespace.h:252
SizeHint
Definition: qnamespace.h:1589
@ MaximumSize
Definition: qnamespace.h:1592
@ PreferredSize
Definition: qnamespace.h:1591
@ MinimumSize
Definition: qnamespace.h:1590
@ WidgetWithChildrenShortcut
Definition: qnamespace.h:1317
@ WidgetShortcut
Definition: qnamespace.h:1314
action
Definition: devices.py:78
Definition: image.cpp:51
#define QString()
Definition: parse-defines.h:51
std::pair< T1, T2 > QPair
Definition: qcontainerfwd.h:56
#define qApp
EGLOutputLayerEXT EGLint EGLAttrib value
EGLOutputLayerEXT EGLint attribute
QT_END_INCLUDE_NAMESPACE typedef double qreal
Definition: qglobal.h:341
unsigned int uint
Definition: qglobal.h:334
@ QtWarningMsg
Definition: qlogging.h:62
#define qWarning
Definition: qlogging.h:179
#define Q_DECLARE_METATYPE(TYPE)
Definition: qmetatype.h:1417
#define SIGNAL(a)
Definition: qobjectdefs.h:88
GLenum type
Definition: qopengl.h:270
GLenum GLsizei GLsizei GLint * values
[16]
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLdouble GLdouble GLdouble GLdouble top
GLdouble GLdouble right
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLint GLsizei width
GLuint color
[2]
GLint left
GLint GLint bottom
GLenum const void * fontName
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint name
GLint first
GLfloat n
GLsizei const GLint * box
GLeglImageOES image
struct _cl_event * event
Definition: qopenglext.h:2998
const GLubyte * c
Definition: qopenglext.h:12701
GLfloat GLfloat p
[1]
Definition: qopenglext.h:12698
GLuint GLenum option
Definition: qopenglext.h:5929
GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint GLdouble w1
Definition: qopenglext.h:12395
GLenum GLenum GLenum input
Definition: qopenglext.h:10816
QPointF qAbs(const QPointF &p)
Definition: qscroller.cpp:119
#define sp
#define QTEST_MAIN(TestObject)
Definition: qtest.h:664
#define QSKIP(statement,...)
Definition: qtestcase.h:222
#define QFETCH(Type, name)
Definition: qtestcase.h:230
#define QEXPECT_FAIL(dataIndex, comment, mode)
Definition: qtestcase.h:224
#define QTRY_COMPARE(expr, expected)
Definition: qtestcase.h:214
#define QVERIFY(statement)
Definition: qtestcase.h:64
#define QTRY_VERIFY(expr)
Definition: qtestcase.h:196
#define QVERIFY2(statement, description)
Definition: qtestcase.h:76
#define QTRY_VERIFY2(expr, messageExpression)
Definition: qtestcase.h:205
#define Q_OBJECT
Definition: qtmetamacros.h:158
#define slots
Definition: qtmetamacros.h:76
Q_UNUSED(salary)
[21]
QVBoxLayout * layout
QLineEdit * lineEdit
QGraphicsScene scene
[0]
QGraphicsItem * item
edit isVisible()
gridLayout addWidget(nameLabel, 0, 0)
QLayoutItem * child
[0]
QPainter painter(this)
[7]
aWidget window() -> setWindowTitle("New Window Title")
[2]
QQuickView * view
[0]
Definition: jquant2.c:237
QAction * triggered
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent