aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Lind <jussi.lind@nokia.com>2010-07-01 15:06:21 +0300
committerTomas Junnonen <tomas.junnonen@nokia.com>2010-08-02 16:29:59 +0300
commit73e6adb379450b2d892237fbe466d95a9a2dc9ba (patch)
treeda6a1adb9e771b107f7fa24861aa63d8a07b8a73
parentd026925e44dd159da90318b76b7ea176ac3f651b (diff)
Changes: Unit tests for hide()/show() added, Doxygen comments modified.
RevBy: Antti Kervinen
-rw-r--r--src/corelib/widgets/core/mwidget.cpp3
-rw-r--r--src/corelib/widgets/core/mwidget.h26
-rw-r--r--tests/ut_mwidget/ut_mwidget.cpp65
-rw-r--r--tests/ut_mwidget/ut_mwidget.h3
4 files changed, 83 insertions, 14 deletions
diff --git a/src/corelib/widgets/core/mwidget.cpp b/src/corelib/widgets/core/mwidget.cpp
index dddaa330..2724f29d 100644
--- a/src/corelib/widgets/core/mwidget.cpp
+++ b/src/corelib/widgets/core/mwidget.cpp
@@ -474,9 +474,8 @@ void MWidget::setVisible(bool visible)
// Propagate visibility events
QGraphicsView *graphicsView = d->fetchGraphicsView();
- QRectF visibleSceneRect;
if (graphicsView) {
- visibleSceneRect = graphicsView->sceneRect();
+ QRectF visibleSceneRect = graphicsView->sceneRect();
// show() called: resolve visibility
if (visible) {
diff --git a/src/corelib/widgets/core/mwidget.h b/src/corelib/widgets/core/mwidget.h
index fafce782..ee97d973 100644
--- a/src/corelib/widgets/core/mwidget.h
+++ b/src/corelib/widgets/core/mwidget.h
@@ -171,30 +171,32 @@ public Q_SLOTS:
Q_SIGNALS:
/*!
- * A signal that is emitted when the widget has entered the visible area of the display or
- * the page containing the widget is not obscured anymore by another window / page.
- * Note!: this is different from Qt's visibilityChanged(), which is emitted due to show() and hide().
+ * A signal that is emitted when:
+ * - the widget has entered the visible area of the display
+ * - the page containing the widget is not obscured anymore by another window / page
+ * - the widget is explicitly shown with show() or setVisible(true) and is on the display area.
+ * Note!: the stacking order of widgets is not taken into account
*/
void displayEntered();
/*!
- * A signal that is emitted when the widget has left the visible area of the display or
- * the page containing the widget has become obscured by another window / page.
- * Note!: this is different from Qt's visibilityChanged(), which is emitted due to show() and hide().
+ * A signal that is emitted when:
+ * - the widget has left the visible area of the display
+ * - the page containing the widget has become obscured by another window / page
+ * - the widget is explicitly hidden with hide() or setVisible(false).
+ * Note!: the stacking order of widgets is not taken into account
*/
void displayExited();
protected:
/*!
- * A handler that is called when the widget has entered the visible area of the display or
- * the page containing the widget is not obscured anymore by another window / page.
+ * A handler that is called just before displayEntered() is emitted.
*/
virtual void enterDisplayEvent();
/*!
- * A handler that is called when the widget has left the visible area of the display or
- * the page containing the widget has become obscured by another window / page.
+ * A handler that is called just before displayExited() is emitted.
*/
virtual void exitDisplayEvent();
@@ -202,8 +204,8 @@ protected:
* This event handler allows a widget to notify subscribers (and its children) about
* changes in its presence on the display. enterDisplayEvent() and exitDisplayEvent()
* convenience handlers are called by the default implementation. MOnDisplayChangeEvent
- * may be sent e.g. if the widget gets panned out of display or the window gets obscured
- * by another window.
+ * may be sent e.g. if the widget gets panned out of display, the widget is explicitly
+ * hidden/shown or the window gets obscured by another window.
*/
virtual void onDisplayChangeEvent(MOnDisplayChangeEvent *event);
diff --git a/tests/ut_mwidget/ut_mwidget.cpp b/tests/ut_mwidget/ut_mwidget.cpp
index 0ecb343b..b34237b5 100644
--- a/tests/ut_mwidget/ut_mwidget.cpp
+++ b/tests/ut_mwidget/ut_mwidget.cpp
@@ -23,6 +23,8 @@
#include "mpannablewidget.h"
#include "mwidgetcontroller.h"
#include "mondisplaychangeevent.h"
+#include "mlayout.h"
+#include "mlinearlayoutpolicy.h"
/* ## Removing Stubs ##
#include "mpannableviewport_stub.h"
@@ -176,6 +178,69 @@ void Ut_MWidget::testExitedDisplay()
disconnect(widget, SIGNAL(displayExited()), this, SLOT(dummySlot()));
}
+void Ut_MWidget::testShowHideSimple()
+{
+ QGraphicsScene scene;
+ QGraphicsView view(&scene);
+
+ view.resize(500, 500);
+ view.show();
+
+ scene.addItem(widget);
+
+ widget->setGeometry(10, 10, 50, 50);
+
+ m_dummySlotCalled = false;
+ connect(widget, SIGNAL(displayEntered()), this, SLOT(dummySlot()));
+ widget->show();
+ QVERIFY(m_dummySlotCalled == true);
+ disconnect(widget, SIGNAL(displayEntered()), this, SLOT(dummySlot()));
+
+ m_dummySlotCalled = false;
+ connect(widget, SIGNAL(displayExited()), this, SLOT(dummySlot()));
+ widget->hide();
+ QVERIFY(m_dummySlotCalled == true);
+ disconnect(widget, SIGNAL(displayExited()), this, SLOT(dummySlot()));
+
+ scene.removeItem(widget);
+}
+
+void Ut_MWidget::testShowHidePropagation()
+{
+ QGraphicsScene scene;
+ QGraphicsView view(&scene);
+
+ view.resize(500, 500);
+ view.show();
+
+ MWidget * topLevel = new MWidget;
+ topLevel->setGeometry(10, 10, 50, 50);
+ widget->setGeometry(10, 10, 50, 50);
+
+ MLayout layout;
+ MLinearLayoutPolicy policy(&layout, Qt::Vertical);
+
+ policy.addItem(widget);
+ layout.setPolicy(&policy);
+ topLevel->setLayout(&layout);
+
+ scene.addItem(topLevel);
+
+ m_dummySlotCalled = false;
+ connect(widget, SIGNAL(displayEntered()), this, SLOT(dummySlot()));
+ topLevel->show();
+ QVERIFY(m_dummySlotCalled == true);
+ disconnect(widget, SIGNAL(displayEntered()), this, SLOT(dummySlot()));
+
+ m_dummySlotCalled = false;
+ connect(widget, SIGNAL(displayExited()), this, SLOT(dummySlot()));
+ topLevel->hide();
+ QVERIFY(m_dummySlotCalled == true);
+ disconnect(widget, SIGNAL(displayExited()), this, SLOT(dummySlot()));
+
+ scene.removeItem(topLevel);
+}
+
void Ut_MWidget::dummySlot()
{
m_dummySlotCalled = true;
diff --git a/tests/ut_mwidget/ut_mwidget.h b/tests/ut_mwidget/ut_mwidget.h
index 77097a8e..90c790a5 100644
--- a/tests/ut_mwidget/ut_mwidget.h
+++ b/tests/ut_mwidget/ut_mwidget.h
@@ -50,6 +50,9 @@ private slots:
void testEnteredDisplay();
void testExitedDisplay();
+ void testShowHideSimple();
+ void testShowHidePropagation();
+
protected slots:
void dummySlot();
};