summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/propertySplicing.qml10
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp1
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/testtypes.h41
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp53
-rw-r--r--tests/auto/declarative/qdeclarativegridview/data/gridview-noCurrent.qml52
-rw-r--r--tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp43
-rw-r--r--tests/auto/declarative/qdeclarativelistview/data/listview-noCurrent.qml50
-rw-r--r--tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp44
-rw-r--r--tests/auto/declarative/qdeclarativevisualdatamodel/data/modelproperties.qml17
-rw-r--r--tests/auto/declarative/qdeclarativevisualdatamodel/data/modelproperties2.qml17
-rw-r--r--tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp108
-rw-r--r--tests/auto/declarative/qmlvisual/qdeclarativetext/elide/elide2.qml2
-rw-r--r--tests/auto/declarative/qmlvisual/qdeclarativetext/elide/multilength.qml2
-rw-r--r--tests/auto/modeltest/dynamictreemodel.cpp7
-rw-r--r--tests/auto/qabstractitemmodel/tst_qabstractitemmodel.cpp6
-rw-r--r--tests/auto/qcompleter/tst_qcompleter.cpp159
-rw-r--r--tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp468
-rw-r--r--tests/auto/qnetworkreply/tst_qnetworkreply.cpp15
18 files changed, 1052 insertions, 43 deletions
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/propertySplicing.qml b/tests/auto/declarative/qdeclarativeecmascript/data/propertySplicing.qml
new file mode 100644
index 0000000..7deb84a
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/propertySplicing.qml
@@ -0,0 +1,10 @@
+import Qt.test 1.0
+import QtQuick 1.0
+
+MyDerivedObject {
+ property bool test: false
+
+ Component.onCompleted: {
+ test = intProperty()
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp b/tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp
index 810a0f7..94135f9 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp
+++ b/tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp
@@ -109,6 +109,7 @@ void registerTypes()
qmlRegisterExtendedType<MyBaseExtendedObject, BaseExtensionObject>("Qt.test", 1,0, "MyBaseExtendedObject");
qmlRegisterExtendedType<MyExtendedObject, ExtensionObject>("Qt.test", 1,0, "MyExtendedObject");
qmlRegisterType<MyTypeObject>("Qt.test", 1,0, "MyTypeObject");
+ qmlRegisterType<MyDerivedObject>("Qt.test", 1,0, "MyDerivedObject");
qmlRegisterType<NumberAssignment>("Qt.test", 1,0, "NumberAssignment");
qmlRegisterExtendedType<DefaultPropertyExtendedObject, DefaultPropertyExtensionObject>("Qt.test", 1,0, "DefaultPropertyExtendedObject");
qmlRegisterType<OverrideDefaultPropertyObject>("Qt.test", 1,0, "OverrideDefaultPropertyObject");
diff --git a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h
index 220318d..40451c3 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h
+++ b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h
@@ -562,8 +562,27 @@ signals:
};
Q_DECLARE_OPERATORS_FOR_FLAGS(MyTypeObject::MyFlags)
+class MyDerivedObject : public MyTypeObject
+{
+ Q_OBJECT
+public:
+ Q_INVOKABLE bool intProperty() const {
+ return true;
+ }
+};
+
Q_DECLARE_METATYPE(QScriptValue);
-class MyInvokableObject : public QObject
+class MyInvokableBaseObject : public QObject
+{
+ Q_OBJECT
+public:
+ inline ~MyInvokableBaseObject() = 0;
+
+ Q_INVOKABLE inline void method_inherited(int a);
+ Q_INVOKABLE inline void method_overload();
+};
+
+class MyInvokableObject : public MyInvokableBaseObject
{
Q_OBJECT
Q_ENUMS(TestEnum)
@@ -599,16 +618,34 @@ public:
Q_INVOKABLE void method_overload(int a) { invoke(16); m_actuals << a; }
Q_INVOKABLE void method_overload(int a, int b) { invoke(17); m_actuals << a << b; }
+ Q_INVOKABLE void method_overload(QString a) { invoke(18); m_actuals << a; }
- Q_INVOKABLE void method_with_enum(TestEnum e) { invoke(18); m_actuals << (int)e; }
+ Q_INVOKABLE void method_with_enum(TestEnum e) { invoke(19); m_actuals << (int)e; }
+
+ Q_INVOKABLE int method_default(int a, int b = 19) { invoke(20); m_actuals << a << b; return b; }
private:
+ friend class MyInvokableBaseObject;
void invoke(int idx) { if (m_invoked != -1) m_invokedError = true; m_invoked = idx;}
int m_invoked;
bool m_invokedError;
QVariantList m_actuals;
};
+MyInvokableBaseObject::~MyInvokableBaseObject() {}
+
+void MyInvokableBaseObject::method_inherited(int a)
+{
+ static_cast<MyInvokableObject *>(this)->invoke(-3);
+ static_cast<MyInvokableObject *>(this)->m_actuals << a;
+}
+
+// This is a hidden overload of the MyInvokableObject::method_overload() method
+void MyInvokableBaseObject::method_overload()
+{
+ static_cast<MyInvokableObject *>(this)->invoke(-2);
+}
+
class NumberAssignment : public QObject
{
Q_OBJECT
diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
index 02832f3..e4e5a54 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
+++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
@@ -139,6 +139,7 @@ private slots:
void strictlyEquals();
void compiled();
void numberAssignment();
+ void propertySplicing();
void bug1();
void bug2();
@@ -1709,7 +1710,6 @@ void tst_qdeclarativeecmascript::callQtInvokables()
QCOMPARE(o.actuals().at(0), QVariant(44));
QVERIFY(qvariant_cast<QScriptValue>(o.actuals().at(1)).isArray());
- // Test overloads - QML will always invoke the *last* method
o.reset();
QCOMPARE(engine->evaluate("object.method_overload()").isError(), true);
QCOMPARE(o.error(), false);
@@ -1717,10 +1717,11 @@ void tst_qdeclarativeecmascript::callQtInvokables()
QCOMPARE(o.actuals().count(), 0);
o.reset();
- QCOMPARE(engine->evaluate("object.method_overload(10)").isError(), true);
+ QCOMPARE(engine->evaluate("object.method_overload(10)").isUndefined(), true);
QCOMPARE(o.error(), false);
- QCOMPARE(o.invoked(), -1);
- QCOMPARE(o.actuals().count(), 0);
+ QCOMPARE(o.invoked(), 16);
+ QCOMPARE(o.actuals().count(), 1);
+ QCOMPARE(o.actuals().at(0), QVariant(10));
o.reset();
QCOMPARE(engine->evaluate("object.method_overload(10, 11)").isUndefined(), true);
@@ -1731,10 +1732,40 @@ void tst_qdeclarativeecmascript::callQtInvokables()
QCOMPARE(o.actuals().at(1), QVariant(11));
o.reset();
- QCOMPARE(engine->evaluate("object.method_with_enum(9)").isUndefined(), true);
+ QCOMPARE(engine->evaluate("object.method_overload(\"Hello\")").isUndefined(), true);
QCOMPARE(o.error(), false);
QCOMPARE(o.invoked(), 18);
QCOMPARE(o.actuals().count(), 1);
+ QCOMPARE(o.actuals().at(0), QVariant(QString("Hello")));
+
+ o.reset();
+ QCOMPARE(engine->evaluate("object.method_with_enum(9)").isUndefined(), true);
+ QCOMPARE(o.error(), false);
+ QCOMPARE(o.invoked(), 19);
+ QCOMPARE(o.actuals().count(), 1);
+ QCOMPARE(o.actuals().at(0), QVariant(9));
+
+ o.reset();
+ QVERIFY(engine->evaluate("object.method_default(10)").strictlyEquals(QScriptValue(19)));
+ QCOMPARE(o.error(), false);
+ QCOMPARE(o.invoked(), 20);
+ QCOMPARE(o.actuals().count(), 2);
+ QCOMPARE(o.actuals().at(0), QVariant(10));
+ QCOMPARE(o.actuals().at(1), QVariant(19));
+
+ o.reset();
+ QVERIFY(engine->evaluate("object.method_default(10, 13)").strictlyEquals(QScriptValue(13)));
+ QCOMPARE(o.error(), false);
+ QCOMPARE(o.invoked(), 20);
+ QCOMPARE(o.actuals().count(), 2);
+ QCOMPARE(o.actuals().at(0), QVariant(10));
+ QCOMPARE(o.actuals().at(1), QVariant(13));
+
+ o.reset();
+ QCOMPARE(engine->evaluate("object.method_inherited(9)").isUndefined(), true);
+ QCOMPARE(o.error(), false);
+ QCOMPARE(o.invoked(), -3);
+ QCOMPARE(o.actuals().count(), 1);
QCOMPARE(o.actuals().at(0), QVariant(9));
}
@@ -2175,6 +2206,18 @@ void tst_qdeclarativeecmascript::numberAssignment()
delete object;
}
+void tst_qdeclarativeecmascript::propertySplicing()
+{
+ QDeclarativeComponent component(&engine, TEST_FILE("propertySplicing.qml"));
+
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ QCOMPARE(object->property("test").toBool(), true);
+
+ delete object;
+}
+
// Test that assigning a null object works
// Regressed with: df1788b4dbbb2826ae63f26bdf166342595343f4
void tst_qdeclarativeecmascript::nullObjectBinding()
diff --git a/tests/auto/declarative/qdeclarativegridview/data/gridview-noCurrent.qml b/tests/auto/declarative/qdeclarativegridview/data/gridview-noCurrent.qml
new file mode 100644
index 0000000..1189649
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativegridview/data/gridview-noCurrent.qml
@@ -0,0 +1,52 @@
+import QtQuick 1.0
+
+Rectangle {
+ property int current: grid.currentIndex
+ width: 240
+ height: 320
+ color: "#ffffff"
+ resources: [
+ Component {
+ id: myDelegate
+ Rectangle {
+ id: wrapper
+ objectName: "wrapper"
+ width: 80
+ height: 60
+ border.color: "blue"
+ Text {
+ text: index
+ }
+ Text {
+ x: 40
+ text: wrapper.x + ", " + wrapper.y
+ }
+ Text {
+ y: 20
+ id: textName
+ objectName: "textName"
+ text: name
+ }
+ Text {
+ y: 40
+ id: textNumber
+ objectName: "textNumber"
+ text: number
+ }
+ color: GridView.isCurrentItem ? "lightsteelblue" : "white"
+ }
+ }
+ ]
+ GridView {
+ id: grid
+ objectName: "grid"
+ focus: true
+ width: 240
+ height: 320
+ currentIndex: -1
+ cellWidth: 80
+ cellHeight: 60
+ delegate: myDelegate
+ model: testModel
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp b/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp
index f7acd87..327bba2 100644
--- a/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp
+++ b/tests/auto/declarative/qdeclarativegridview/tst_qdeclarativegridview.cpp
@@ -71,6 +71,7 @@ private slots:
void moved();
void changeFlow();
void currentIndex();
+ void noCurrentIndex();
void defaultValues();
void properties();
void propertyChanges();
@@ -696,9 +697,51 @@ void tst_QDeclarativeGridView::currentIndex()
model.insertItem(0, "Foo", "1111");
QTRY_COMPARE(canvas->rootObject()->property("current").toInt(), 29);
+ // check removing highlight by setting currentIndex to -1;
+ gridview->setCurrentIndex(-1);
+
+ QCOMPARE(gridview->currentIndex(), -1);
+ QVERIFY(!gridview->highlightItem());
+ QVERIFY(!gridview->currentItem());
+
delete canvas;
}
+void tst_QDeclarativeGridView::noCurrentIndex()
+{
+ TestModel model;
+ for (int i = 0; i < 60; i++)
+ model.addItem("Item" + QString::number(i), QString::number(i));
+
+ QDeclarativeView *canvas = new QDeclarativeView(0);
+ canvas->setFixedSize(240,320);
+
+ QDeclarativeContext *ctxt = canvas->rootContext();
+ ctxt->setContextProperty("testModel", &model);
+
+ QString filename(SRCDIR "/data/gridview-noCurrent.qml");
+ canvas->setSource(QUrl::fromLocalFile(filename));
+
+ qApp->processEvents();
+
+ QDeclarativeGridView *gridview = findItem<QDeclarativeGridView>(canvas->rootObject(), "grid");
+ QVERIFY(gridview != 0);
+
+ QDeclarativeItem *contentItem = gridview->contentItem();
+ QVERIFY(contentItem != 0);
+
+ // current index should be -1
+ QCOMPARE(gridview->currentIndex(), -1);
+ QVERIFY(!gridview->currentItem());
+ QVERIFY(!gridview->highlightItem());
+ QCOMPARE(gridview->contentY(), 0.0);
+
+ gridview->setCurrentIndex(5);
+ QCOMPARE(gridview->currentIndex(), 5);
+ QVERIFY(gridview->currentItem());
+ QVERIFY(gridview->highlightItem());
+}
+
void tst_QDeclarativeGridView::changeFlow()
{
QDeclarativeView *canvas = createView();
diff --git a/tests/auto/declarative/qdeclarativelistview/data/listview-noCurrent.qml b/tests/auto/declarative/qdeclarativelistview/data/listview-noCurrent.qml
new file mode 100644
index 0000000..1997010
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativelistview/data/listview-noCurrent.qml
@@ -0,0 +1,50 @@
+import QtQuick 1.0
+
+Rectangle {
+ property int current: list.currentIndex
+ width: 240
+ height: 320
+ color: "#ffffff"
+ resources: [
+ Component {
+ id: myDelegate
+ Rectangle {
+ id: wrapper
+ objectName: "wrapper"
+ height: 20
+ width: 240
+ Text {
+ text: index
+ }
+ Text {
+ x: 30
+ id: textName
+ objectName: "textName"
+ text: name
+ }
+ Text {
+ x: 120
+ id: textNumber
+ objectName: "textNumber"
+ text: number
+ }
+ Text {
+ x: 200
+ text: wrapper.y
+ }
+ color: ListView.isCurrentItem ? "lightsteelblue" : "white"
+ }
+ }
+ ]
+ ListView {
+ id: list
+ objectName: "list"
+ focus: true
+ currentIndex: -1
+ width: 240
+ height: 320
+ delegate: myDelegate
+ highlightMoveSpeed: 1000
+ model: testModel
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp
index 2649c0d..080631c 100644
--- a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp
+++ b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp
@@ -85,6 +85,7 @@ private slots:
void itemList();
void currentIndex();
+ void noCurrentIndex();
void enforceRange();
void spacing();
void sections();
@@ -1087,9 +1088,52 @@ void tst_QDeclarativeListView::currentIndex()
model.insertItem(0, "Foo", "1111");
QTRY_COMPARE(canvas->rootObject()->property("current").toInt(), 29);
+ // check removing highlight by setting currentIndex to -1;
+ listview->setCurrentIndex(-1);
+
+ QCOMPARE(listview->currentIndex(), -1);
+ QVERIFY(!listview->highlightItem());
+ QVERIFY(!listview->currentItem());
+
delete canvas;
}
+void tst_QDeclarativeListView::noCurrentIndex()
+{
+ TestModel model;
+ for (int i = 0; i < 30; i++)
+ model.addItem("Item" + QString::number(i), QString::number(i));
+
+ QDeclarativeView *canvas = new QDeclarativeView(0);
+ canvas->setFixedSize(240,320);
+
+ QDeclarativeContext *ctxt = canvas->rootContext();
+ ctxt->setContextProperty("testModel", &model);
+
+ QString filename(SRCDIR "/data/listview-noCurrent.qml");
+ canvas->setSource(QUrl::fromLocalFile(filename));
+
+ qApp->processEvents();
+
+ QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list");
+ QTRY_VERIFY(listview != 0);
+
+ QDeclarativeItem *contentItem = listview->contentItem();
+ QTRY_VERIFY(contentItem != 0);
+
+ // current index should be -1 at startup
+ // and we should not have a currentItem or highlightItem
+ QCOMPARE(listview->currentIndex(), -1);
+ QCOMPARE(listview->contentY(), 0.0);
+ QVERIFY(!listview->highlightItem());
+ QVERIFY(!listview->currentItem());
+
+ listview->setCurrentIndex(2);
+ QCOMPARE(listview->currentIndex(), 2);
+ QVERIFY(listview->highlightItem());
+ QVERIFY(listview->currentItem());
+}
+
void tst_QDeclarativeListView::itemList()
{
QDeclarativeView *canvas = createView();
diff --git a/tests/auto/declarative/qdeclarativevisualdatamodel/data/modelproperties.qml b/tests/auto/declarative/qdeclarativevisualdatamodel/data/modelproperties.qml
new file mode 100644
index 0000000..8cd5763
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativevisualdatamodel/data/modelproperties.qml
@@ -0,0 +1,17 @@
+import QtQuick 1.0
+
+ListView {
+ model: myModel
+ delegate: Item {
+ objectName: "delegate"
+ property variant test1: name
+ property variant test2: model.name
+ property variant test3: modelData
+ property variant test4: model.modelData
+ property variant test5: modelData.name
+ property variant test6: model
+ property variant test7: index
+ property variant test8: model.index
+ property variant test9: model.modelData.name
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativevisualdatamodel/data/modelproperties2.qml b/tests/auto/declarative/qdeclarativevisualdatamodel/data/modelproperties2.qml
new file mode 100644
index 0000000..67721c9
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativevisualdatamodel/data/modelproperties2.qml
@@ -0,0 +1,17 @@
+import QtQuick 1.0
+
+ListView {
+ model: myModel
+ delegate: Item {
+ objectName: "delegate"
+ property variant test1: display
+ property variant test2: model.display
+ property variant test3: modelData
+ property variant test4: model.modelData
+ property variant test5: modelData.display
+ property variant test6: model
+ property variant test7: index
+ property variant test8: model.index
+ property variant test9: model.modelData.display
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp b/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp
index d73a872..0aad099 100644
--- a/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp
+++ b/tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp
@@ -120,6 +120,7 @@ private slots:
void childChanged();
void objectListModel();
void singleRole();
+ void modelProperties();
private:
QDeclarativeEngine engine;
@@ -364,6 +365,113 @@ void tst_qdeclarativevisualdatamodel::singleRole()
}
}
+void tst_qdeclarativevisualdatamodel::modelProperties()
+{
+ {
+ QDeclarativeView view;
+
+ SingleRoleModel model;
+
+ QDeclarativeContext *ctxt = view.rootContext();
+ ctxt->setContextProperty("myModel", &model);
+
+ view.setSource(QUrl::fromLocalFile(SRCDIR "/data/modelproperties.qml"));
+
+ QDeclarativeListView *listview = qobject_cast<QDeclarativeListView*>(view.rootObject());
+ QVERIFY(listview != 0);
+
+ QDeclarativeItem *contentItem = listview->contentItem();
+ QVERIFY(contentItem != 0);
+
+ QDeclarativeItem *delegate = findItem<QDeclarativeItem>(contentItem, "delegate", 1);
+ QCOMPARE(delegate->property("test1").toString(),QString("two"));
+ QCOMPARE(delegate->property("test2").toString(),QString("two"));
+ QCOMPARE(delegate->property("test3").toString(),QString("two"));
+ QCOMPARE(delegate->property("test4").toString(),QString("two"));
+ QVERIFY(!delegate->property("test9").isValid());
+ QCOMPARE(delegate->property("test5").toString(),QString(""));
+ QVERIFY(delegate->property("test6").value<QObject*>() != 0);
+ QCOMPARE(delegate->property("test7").toInt(),1);
+ QCOMPARE(delegate->property("test8").toInt(),1);
+ }
+
+ {
+ QDeclarativeView view;
+
+ QList<QObject*> dataList;
+ dataList.append(new DataObject("Item 1", "red"));
+ dataList.append(new DataObject("Item 2", "green"));
+ dataList.append(new DataObject("Item 3", "blue"));
+ dataList.append(new DataObject("Item 4", "yellow"));
+
+ QDeclarativeContext *ctxt = view.rootContext();
+ ctxt->setContextProperty("myModel", QVariant::fromValue(dataList));
+
+ view.setSource(QUrl::fromLocalFile(SRCDIR "/data/modelproperties.qml"));
+
+ QDeclarativeListView *listview = qobject_cast<QDeclarativeListView*>(view.rootObject());
+ QVERIFY(listview != 0);
+
+ QDeclarativeItem *contentItem = listview->contentItem();
+ QVERIFY(contentItem != 0);
+
+ QDeclarativeItem *delegate = findItem<QDeclarativeItem>(contentItem, "delegate", 1);
+ QCOMPARE(delegate->property("test1").toString(),QString("Item 2"));
+ QEXPECT_FAIL("", "QTBUG-13576", Continue);
+ QCOMPARE(delegate->property("test2").toString(),QString("Item 2"));
+ QVERIFY(qobject_cast<DataObject*>(delegate->property("test3").value<QObject*>()) != 0);
+ QVERIFY(qobject_cast<DataObject*>(delegate->property("test4").value<QObject*>()) != 0);
+ QCOMPARE(delegate->property("test5").toString(),QString("Item 2"));
+ QCOMPARE(delegate->property("test9").toString(),QString("Item 2"));
+ QVERIFY(delegate->property("test6").value<QObject*>() != 0);
+ QCOMPARE(delegate->property("test7").toInt(),1);
+ QCOMPARE(delegate->property("test8").toInt(),1);
+ }
+
+ {
+ QDeclarativeView view;
+
+ QStandardItemModel model;
+ initStandardTreeModel(&model);
+
+ view.rootContext()->setContextProperty("myModel", &model);
+
+ QUrl source(QUrl::fromLocalFile(SRCDIR "/data/modelproperties2.qml"));
+
+ //3 items, 3 warnings each
+ QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":11: ReferenceError: Can't find variable: modelData");
+ QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":11: ReferenceError: Can't find variable: modelData");
+ QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":11: ReferenceError: Can't find variable: modelData");
+ QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":9: ReferenceError: Can't find variable: modelData");
+ QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":9: ReferenceError: Can't find variable: modelData");
+ QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":9: ReferenceError: Can't find variable: modelData");
+ QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":15: TypeError: Result of expression 'model.modelData' [undefined] is not an object.");
+ QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":15: TypeError: Result of expression 'model.modelData' [undefined] is not an object.");
+ QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":15: TypeError: Result of expression 'model.modelData' [undefined] is not an object.");
+
+ view.setSource(source);
+
+ QDeclarativeListView *listview = qobject_cast<QDeclarativeListView*>(view.rootObject());
+ QVERIFY(listview != 0);
+
+ QDeclarativeItem *contentItem = listview->contentItem();
+ QVERIFY(contentItem != 0);
+
+ QDeclarativeItem *delegate = findItem<QDeclarativeItem>(contentItem, "delegate", 1);
+ QCOMPARE(delegate->property("test1").toString(),QString("Row 2 Item"));
+ QCOMPARE(delegate->property("test2").toString(),QString("Row 2 Item"));
+ QVERIFY(!delegate->property("test3").isValid());
+ QVERIFY(!delegate->property("test4").isValid());
+ QVERIFY(!delegate->property("test5").isValid());
+ QVERIFY(!delegate->property("test9").isValid());
+ QVERIFY(delegate->property("test6").value<QObject*>() != 0);
+ QCOMPARE(delegate->property("test7").toInt(),1);
+ QCOMPARE(delegate->property("test8").toInt(),1);
+ }
+
+ //### should also test QStringList and QVariantList
+}
+
template<typename T>
T *tst_qdeclarativevisualdatamodel::findItem(QGraphicsObject *parent, const QString &objectName, int index)
{
diff --git a/tests/auto/declarative/qmlvisual/qdeclarativetext/elide/elide2.qml b/tests/auto/declarative/qmlvisual/qdeclarativetext/elide/elide2.qml
index edf0cb5..b772982 100644
--- a/tests/auto/declarative/qmlvisual/qdeclarativetext/elide/elide2.qml
+++ b/tests/auto/declarative/qmlvisual/qdeclarativetext/elide/elide2.qml
@@ -5,7 +5,7 @@ Rectangle {
height: 100
Text {
- width: NumberAnimation { from: 500; to: 0; loops: Animation.Infinite; duration: 5000 }
+ NumberAnimation on width { from: 500; to: 0; loops: Animation.Infinite; duration: 5000 }
elide: Text.ElideRight
text: 'Here is some very long text that we should truncate when sizing window'
}
diff --git a/tests/auto/declarative/qmlvisual/qdeclarativetext/elide/multilength.qml b/tests/auto/declarative/qmlvisual/qdeclarativetext/elide/multilength.qml
index 6698421..3ef64ef 100644
--- a/tests/auto/declarative/qmlvisual/qdeclarativetext/elide/multilength.qml
+++ b/tests/auto/declarative/qmlvisual/qdeclarativetext/elide/multilength.qml
@@ -11,7 +11,7 @@ Rectangle {
anchors.centerIn: parent
Text {
id: myText
- width: NumberAnimation { from: 500; to: 0; loops: Animation.Infinite; duration: 1000 }
+ NumberAnimation on width { from: 500; to: 0; loops: Animation.Infinite; duration: 5000 }
elide: "ElideRight"
text: "Brevity is the soul of wit, and tediousness the limbs and outward flourishes.\x9CBrevity is a great charm of eloquence.\x9CBe concise!\x9CSHHHHHHHHHHHHHHHHHHHHHHHHHHHH"
}
diff --git a/tests/auto/modeltest/dynamictreemodel.cpp b/tests/auto/modeltest/dynamictreemodel.cpp
index b572eb1..fa634b6 100644
--- a/tests/auto/modeltest/dynamictreemodel.cpp
+++ b/tests/auto/modeltest/dynamictreemodel.cpp
@@ -63,6 +63,13 @@ QModelIndex DynamicTreeModel::index(int row, int column, const QModelIndex &pare
QList<QList<qint64> > childIdColumns = m_childItems.value(parent.internalId());
+ const qint64 grandParent = findParentId(parent.internalId());
+ if (grandParent >= 0) {
+ QList<QList<qint64> > parentTable = m_childItems.value(grandParent);
+ Q_ASSERT(parent.column() < parentTable.size());
+ QList<qint64> parentSiblings = parentTable.at(parent.column());
+ Q_ASSERT(parent.row() < parentSiblings.size());
+ }
if (childIdColumns.size() == 0)
return QModelIndex();
diff --git a/tests/auto/qabstractitemmodel/tst_qabstractitemmodel.cpp b/tests/auto/qabstractitemmodel/tst_qabstractitemmodel.cpp
index dbcccc9..b723253 100644
--- a/tests/auto/qabstractitemmodel/tst_qabstractitemmodel.cpp
+++ b/tests/auto/qabstractitemmodel/tst_qabstractitemmodel.cpp
@@ -1167,6 +1167,7 @@ void tst_QAbstractItemModel::testMoveToGrandParent_data()
// Moving everything from one parent to another
QTest::newRow("move12") << 0 << 9 << 10;
+ QTest::newRow("move13") << 0 << 9 << 0;
}
void tst_QAbstractItemModel::testMoveToGrandParent()
@@ -1314,6 +1315,11 @@ void tst_QAbstractItemModel::testMoveToSibling_data()
QTest::newRow("move09") << 8 << 8 << 4;
QTest::newRow("move10") << 8 << 8 << 5;
QTest::newRow("move11") << 8 << 8 << 6;
+
+ // Move such that the destination parent no longer valid after the move.
+ // The destination parent is always QMI(5, 0), but after this move the
+ // row count is 5, so (5, 0) (used internally in QAIM) no longer refers to a valid index.
+ QTest::newRow("move12") << 0 << 4 << 0;
}
void tst_QAbstractItemModel::testMoveToSibling()
diff --git a/tests/auto/qcompleter/tst_qcompleter.cpp b/tests/auto/qcompleter/tst_qcompleter.cpp
index 1590528..650c328 100644
--- a/tests/auto/qcompleter/tst_qcompleter.cpp
+++ b/tests/auto/qcompleter/tst_qcompleter.cpp
@@ -119,6 +119,8 @@ private slots:
void directoryModel_data();
void directoryModel();
+ void fileSystemModel_data();
+ void fileSystemModel();
void changingModel_data();
void changingModel();
@@ -149,15 +151,17 @@ private slots:
void task253125_lineEditCompletion_data();
void task253125_lineEditCompletion();
void task247560_keyboardNavigation();
+ void QTBUG_14292_filesystem();
private:
- void filter();
+ void filter(bool assync = false);
void testRowCount();
enum ModelType {
CASE_SENSITIVELY_SORTED_MODEL,
CASE_INSENSITIVELY_SORTED_MODEL,
DIRECTORY_MODEL,
- HISTORY_MODEL
+ HISTORY_MODEL,
+ FILESYSTEM_MODEL
};
void setSourceModel(ModelType);
@@ -233,12 +237,21 @@ void tst_QCompleter::setSourceModel(ModelType type)
completer->setModel(new QDirModel(completer));
completer->setCompletionColumn(0);
break;
+ case FILESYSTEM_MODEL:
+ completer->setCsvCompletion(false);
+ {
+ QFileSystemModel *m = new QFileSystemModel(completer);
+ m->setRootPath("/");
+ completer->setModel(m);
+ }
+ completer->setCompletionColumn(0);
+ break;
default:
qDebug() << "Invalid type";
}
}
-void tst_QCompleter::filter()
+void tst_QCompleter::filter(bool assync)
{
QFETCH(QString, filterText);
QFETCH(QString, step);
@@ -250,6 +263,9 @@ void tst_QCompleter::filter()
return;
}
+ int times = 0;
+retry:
+
completer->setCompletionPrefix(filterText);
for (int i = 0; i < step.length(); i++) {
@@ -265,9 +281,13 @@ void tst_QCompleter::filter()
completer->setCurrentRow(row);
}
- //QModelIndex si = completer->currentIndex();
- //QCOMPARE(completer->model()->data(si).toString(), completion);
- QVERIFY(0 == QString::compare(completer->currentCompletion(), completionText, completer->caseSensitivity()));
+ int r = QString::compare(completer->currentCompletion(), completionText, completer->caseSensitivity());
+ if (assync && r && times < 10) {
+ times++;
+ QTest::qWait(50*times);
+ goto retry;
+ }
+ QVERIFY(!r);
}
// Testing get/set functions
@@ -552,6 +572,7 @@ void tst_QCompleter::csMatchingOnCiSortedModel()
void tst_QCompleter::directoryModel_data()
{
delete completer;
+
completer = new CsvCompleter;
completer->setModelSorting(QCompleter::CaseSensitivelySortedModel);
setSourceModel(DIRECTORY_MODEL);
@@ -598,6 +619,57 @@ void tst_QCompleter::directoryModel()
filter();
}
+void tst_QCompleter::fileSystemModel_data()
+{
+ delete completer;
+ completer = new CsvCompleter;
+ completer->setModelSorting(QCompleter::CaseSensitivelySortedModel);
+ setSourceModel(FILESYSTEM_MODEL);
+ completer->setCaseSensitivity(Qt::CaseInsensitive);
+
+ QTest::addColumn<QString>("filterText");
+ QTest::addColumn<QString>("step");
+ QTest::addColumn<QString>("completion");
+ QTest::addColumn<QString>("completionText");
+
+ // NOTE: Add tests carefully, ensurely the paths exist on all systems
+ // Output is the sourceText; currentCompletionText()
+
+ for (int i = 0; i < 2; i++) {
+ if (i == 1)
+ QTest::newRow("FILTERING_OFF") << "FILTERING_OFF" << "" << "" << "";
+
+#if defined(Q_OS_WINCE)
+ QTest::newRow("()") << "" << "" << "/" << "/";
+ QTest::newRow("()") << "\\Program" << "" << "Program Files" << "\\Program Files";
+#elif defined(Q_OS_WIN)
+ QTest::newRow("()") << "C" << "" << "C:" << "C:";
+ QTest::newRow("()") << "C:\\Program" << "" << "Program Files" << "C:\\Program Files";
+#elif defined(Q_OS_SYMBIAN)
+ QTest::newRow("()") << "C" << "" << "C:" << "C:";
+ QTest::newRow("()") << "C:\\re" << "" << "resource" << "C:\\resource";
+#elif defined (Q_OS_MAC)
+ QTest::newRow("()") << "" << "" << "/" << "/";
+ QTest::newRow("(/a)") << "/a" << "" << "Applications" << "/Applications";
+// QTest::newRow("(/d)") << "/d" << "" << "Developer" << "/Developer";
+#else
+ QTest::newRow("()") << "" << "" << "/" << "/";
+#if !defined(Q_OS_IRIX) && !defined(Q_OS_AIX) && !defined(Q_OS_HPUX)
+ QTest::newRow("(/h)") << "/h" << "" << "home" << "/home";
+#endif
+ QTest::newRow("(/et)") << "/et" << "" << "etc" << "/etc";
+ QTest::newRow("(/etc/passw)") << "/etc/passw" << "" << "passwd" << "/etc/passwd";
+#endif
+ }
+}
+
+void tst_QCompleter::fileSystemModel()
+{
+ //QFileSystemModel is assync.
+ filter(true);
+}
+
+
void tst_QCompleter::changingModel_data()
{
}
@@ -1381,5 +1453,80 @@ void tst_QCompleter::task247560_keyboardNavigation()
QCOMPARE(edit.text(), QString("row 3 column 1"));
}
+void tst_QCompleter::QTBUG_14292_filesystem()
+{
+ QDir tmpDir = QDir::temp();
+ qsrand(QTime::currentTime().msec());
+ QString d = "tst_QCompleter_" + QString::number(qrand());
+ QVERIFY(tmpDir.mkdir(d));
+
+#if 0
+ struct Cleanup {
+ QString dir;
+ ~Cleanup() {
+ qDebug() << dir <<
+ QFile::remove(dir); }
+ } cleanup;
+ cleanup.dir = tmpDir.absolutePath()+"/" +d;
+#endif
+
+ QVERIFY(tmpDir.cd(d));
+ QVERIFY(tmpDir.mkdir("hello"));
+ QVERIFY(tmpDir.mkdir("holla"));
+
+ QLineEdit edit;
+ QCompleter comp;
+ QFileSystemModel model;
+ model.setRootPath(tmpDir.path());
+ comp.setModel(&model);
+ edit.setCompleter(&comp);
+
+ edit.show();
+ QApplication::setActiveWindow(&edit);
+ QTest::qWaitForWindowShown(&edit);
+ QTRY_VERIFY(QApplication::activeWindow() == &edit);
+ edit.setFocus();
+ QTRY_VERIFY(edit.hasFocus());
+
+ QVERIFY(!comp.popup()->isVisible());
+ edit.setText(tmpDir.path());
+ QTest::keyClick(&edit, '/');
+ QTRY_VERIFY(comp.popup()->isVisible());
+ QCOMPARE(comp.popup()->model()->rowCount(), 2);
+ QApplication::processEvents();
+ QTest::keyClick(&edit, 'h');
+ QCOMPARE(comp.popup()->model()->rowCount(), 2);
+ QTest::keyClick(&edit, 'e');
+ QCOMPARE(comp.popup()->model()->rowCount(), 1);
+ QTest::keyClick(&edit, 'r');
+ QTRY_VERIFY(!comp.popup()->isVisible());
+ QVERIFY(tmpDir.mkdir("hero"));
+ QTRY_VERIFY(comp.popup()->isVisible());
+ QCOMPARE(comp.popup()->model()->rowCount(), 1);
+ QTest::keyClick(comp.popup(), Qt::Key_Escape);
+ QTRY_VERIFY(!comp.popup()->isVisible());
+ QVERIFY(tmpDir.mkdir("nothingThere"));
+ //there is no reason creating a file should open a popup, it did in Qt 4.7.0
+ QTest::qWait(60);
+ QVERIFY(!comp.popup()->isVisible());
+
+ QTest::keyClick(&edit, Qt::Key_Backspace);
+ QTRY_VERIFY(comp.popup()->isVisible());
+ QCOMPARE(comp.popup()->model()->rowCount(), 2);
+ QTest::keyClick(&edit, 'm');
+ QTRY_VERIFY(!comp.popup()->isVisible());
+
+ QWidget w;
+ w.show();
+ QApplication::setActiveWindow(&w);
+ QTest::qWaitForWindowShown(&w);
+ QTRY_VERIFY(!edit.hasFocus() && !comp.popup()->hasFocus());
+
+ QVERIFY(tmpDir.mkdir("hemo"));
+ //there is no reason creating a file should open a popup, it did in Qt 4.7.0
+ QTest::qWait(60);
+ QVERIFY(!comp.popup()->isVisible());
+}
+
QTEST_MAIN(tst_QCompleter)
#include "tst_qcompleter.moc"
diff --git a/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp b/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp
index 5b03767..174e4aa 100644
--- a/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp
+++ b/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp
@@ -61,13 +61,19 @@ private slots:
void qgraphicsgridlayout();
void addItem_data();
void addItem();
+ void alignment_data();
void alignment();
void alignment2();
void alignment2_data();
+ void columnAlignment_data();
void columnAlignment();
+ void columnCount_data();
void columnCount();
+ void columnMaximumWidth_data();
void columnMaximumWidth();
+ void columnMinimumWidth_data();
void columnMinimumWidth();
+ void columnPreferredWidth_data();
void columnPreferredWidth();
void setColumnFixedWidth();
void columnSpacing();
@@ -78,12 +84,18 @@ private slots:
void horizontalSpacing();
void itemAt();
void removeAt();
+ void rowAlignment_data();
void rowAlignment();
+ void rowCount_data();
void rowCount();
+ void rowMaximumHeight_data();
void rowMaximumHeight();
+ void rowMinimumHeight_data();
void rowMinimumHeight();
+ void rowPreferredHeight_data();
void rowPreferredHeight();
void rowSpacing();
+ void rowStretchFactor_data();
void rowStretchFactor();
void setColumnSpacing_data();
void setColumnSpacing();
@@ -98,6 +110,7 @@ private slots:
void sizeHint();
void verticalSpacing_data();
void verticalSpacing();
+ void layoutDirection_data();
void layoutDirection();
void removeLayout();
void defaultStretchFactors_data();
@@ -107,12 +120,14 @@ private slots:
void avoidRecursionInInsertItem();
void styleInfoLeak();
void task236367_maxSizeHint();
+ void heightForWidth();
+ void heightForWidthWithSpanning();
};
class RectWidget : public QGraphicsWidget
{
public:
- RectWidget(QGraphicsItem *parent = 0) : QGraphicsWidget(parent){}
+ RectWidget(QGraphicsItem *parent = 0) : QGraphicsWidget(parent), m_fnConstraint(0) {}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
@@ -125,9 +140,12 @@ public:
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const
{
- if (m_sizeHints[which].isValid()) {
+ if (constraint.width() < 0 && constraint.height() < 0 && m_sizeHints[which].isValid()) {
return m_sizeHints[which];
}
+ if (m_fnConstraint) {
+ return m_fnConstraint(which, constraint);
+ }
return QGraphicsWidget::sizeHint(which, constraint);
}
@@ -136,7 +154,13 @@ public:
updateGeometry();
}
+ void setConstraintFunction(QSizeF (*fnConstraint)(Qt::SizeHint, const QSizeF &)) {
+ m_fnConstraint = fnConstraint;
+ }
+
QSizeF m_sizeHints[Qt::NSizeHints];
+ QSizeF (*m_fnConstraint)(Qt::SizeHint, const QSizeF &);
+
};
struct ItemDesc
@@ -146,7 +170,8 @@ struct ItemDesc
m_rowSpan(1),
m_colSpan(1),
m_sizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred)),
- m_align(0)
+ m_align(0),
+ m_fnConstraint(0)
{
}
@@ -213,8 +238,20 @@ struct ItemDesc
return (*this);
}
+ ItemDesc &heightForWidth(QSizeF (*fnConstraint)(Qt::SizeHint, const QSizeF &)) {
+ m_fnConstraint = fnConstraint;
+ m_constraintOrientation = Qt::Vertical;
+ return (*this);
+ }
+
void apply(QGraphicsGridLayout *layout, QGraphicsWidget *item) {
- item->setSizePolicy(m_sizePolicy);
+ QSizePolicy sp = m_sizePolicy;
+ if (m_fnConstraint) {
+ sp.setHeightForWidth(m_constraintOrientation == Qt::Vertical);
+ //sp.setWidthForHeight(m_constraintOrientation == Qt::Horizontal);
+ }
+
+ item->setSizePolicy(sp);
for (int i = 0; i < Qt::NSizeHints; ++i) {
if (!m_sizes[i].isValid())
continue;
@@ -233,6 +270,7 @@ struct ItemDesc
break;
}
}
+
layout->addItem(item, m_pos.first, m_pos.second, m_rowSpan, m_colSpan);
layout->setAlignment(item, m_align);
}
@@ -240,6 +278,7 @@ struct ItemDesc
void apply(QGraphicsGridLayout *layout, RectWidget *item) {
for (int i = 0; i < Qt::NSizeHints; ++i)
item->setSizeHint((Qt::SizeHint)i, m_sizeHints[i]);
+ item->setConstraintFunction(m_fnConstraint);
apply(layout, static_cast<QGraphicsWidget*>(item));
}
@@ -251,6 +290,9 @@ struct ItemDesc
QSizeF m_sizeHints[Qt::NSizeHints];
QSizeF m_sizes[Qt::NSizeHints];
Qt::Alignment m_align;
+
+ Qt::Orientation m_constraintOrientation;
+ QSizeF (*m_fnConstraint)(Qt::SizeHint, const QSizeF &);
};
typedef QList<ItemDesc> ItemList;
@@ -342,7 +384,7 @@ void tst_QGraphicsGridLayout::qgraphicsgridlayout()
layout.verticalSpacing();
}
-static void populateLayout(QGraphicsGridLayout *gridLayout, int width, int height)
+static void populateLayout(QGraphicsGridLayout *gridLayout, int width, int height, bool hasHeightForWidth = false)
{
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
@@ -351,6 +393,9 @@ static void populateLayout(QGraphicsGridLayout *gridLayout, int width, int heigh
item->setPreferredSize(25, 25);
item->setMaximumSize(50, 50);
gridLayout->addItem(item, y, x);
+ QSizePolicy policy = item->sizePolicy();
+ policy.setHeightForWidth(hasHeightForWidth);
+ item->setSizePolicy(policy);
}
}
}
@@ -367,18 +412,22 @@ static void populateLayout(QGraphicsGridLayout *gridLayout, int width, int heigh
* |xxxx|+---|---+|
* +----+----+----+
*/
-static void populateLayoutWithSpansAndHoles(QGraphicsGridLayout *gridLayout)
+static void populateLayoutWithSpansAndHoles(QGraphicsGridLayout *gridLayout, bool hasHeightForWidth = false)
{
QGraphicsWidget *item = new RectWidget();
item->setMinimumSize(10, 10);
item->setPreferredSize(25, 25);
item->setMaximumSize(50, 50);
+ QSizePolicy sizepolicy = item->sizePolicy();
+ sizepolicy.setHeightForWidth(hasHeightForWidth);
+ item->setSizePolicy(sizepolicy);
gridLayout->addItem(item, 0, 0, 1, 2);
item = new RectWidget();
item->setMinimumSize(10, 10);
item->setPreferredSize(25, 25);
item->setMaximumSize(50, 50);
+ item->setSizePolicy(sizepolicy);
gridLayout->addItem(item, 1, 1, 1, 2);
}
@@ -431,19 +480,28 @@ void tst_QGraphicsGridLayout::addItem()
delete layout;
}
+void tst_QGraphicsGridLayout::alignment_data()
+{
+ QTest::addColumn<bool>("hasHeightForWidth");
+
+ QTest::newRow("") << false;
+ QTest::newRow("hasHeightForWidth") << true;
+}
+
// public Qt::Alignment alignment(QGraphicsLayoutItem* item) const
void tst_QGraphicsGridLayout::alignment()
{
#ifdef Q_WS_MAC
QSKIP("Resizing a QGraphicsWidget to effectiveSizeHint(Qt::MaximumSize) is currently not supported on mac", SkipAll);
#endif
+ QFETCH(bool, hasHeightForWidth);
QGraphicsScene scene;
QGraphicsView view(&scene);
QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window);
QGraphicsGridLayout *layout = new QGraphicsGridLayout();
scene.addItem(widget);
widget->setLayout(layout);
- populateLayout(layout, 3, 2);
+ populateLayout(layout, 3, 2, hasHeightForWidth);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
@@ -495,6 +553,14 @@ void tst_QGraphicsGridLayout::alignment()
delete widget;
}
+void tst_QGraphicsGridLayout::columnAlignment_data()
+{
+ QTest::addColumn<bool>("hasHeightForWidth");
+
+ QTest::newRow("") << false;
+ QTest::newRow("hasHeightForWidth") << true;
+}
+
// public void setColumnAlignment(int column, Qt::Alignment alignment)
// public Qt::Alignment columnAlignment(int column) const
void tst_QGraphicsGridLayout::columnAlignment()
@@ -502,13 +568,14 @@ void tst_QGraphicsGridLayout::columnAlignment()
#ifdef Q_WS_MAC
QSKIP("Resizing a QGraphicsWidget to effectiveSizeHint(Qt::MaximumSize) is currently not supported on mac", SkipAll);
#endif
+ QFETCH(bool, hasHeightForWidth);
QGraphicsScene scene;
QGraphicsView view(&scene);
QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window);
QGraphicsGridLayout *layout = new QGraphicsGridLayout();
scene.addItem(widget);
widget->setLayout(layout);
- populateLayout(layout, 3, 2);
+ populateLayout(layout, 3, 2, hasHeightForWidth);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(1);
widget->setContentsMargins(0, 0, 0, 0);
@@ -554,9 +621,17 @@ void tst_QGraphicsGridLayout::columnAlignment()
delete widget;
}
+void tst_QGraphicsGridLayout::columnCount_data()
+{
+ QTest::addColumn<bool>("hasHeightForWidth");
+
+ QTest::newRow("") << false;
+ QTest::newRow("hasHeightForWidth") << true;
+}
// public int columnCount() const
void tst_QGraphicsGridLayout::columnCount()
{
+ QFETCH(bool, hasHeightForWidth);
QGraphicsScene scene;
QGraphicsView view(&scene);
QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window);
@@ -588,7 +663,7 @@ void tst_QGraphicsGridLayout::columnCount()
// ### Talk with Jasmin. Not sure if removeAt() should adjust columnCount().
widget->setLayout(0);
layout = new QGraphicsGridLayout();
- populateLayout(layout, 3, 2);
+ populateLayout(layout, 3, 2, hasHeightForWidth);
QCOMPARE(layout->columnCount(), 3);
layout->removeAt(5);
layout->removeAt(3);
@@ -603,16 +678,24 @@ void tst_QGraphicsGridLayout::columnCount()
delete widget;
}
+void tst_QGraphicsGridLayout::columnMaximumWidth_data()
+{
+ QTest::addColumn<bool>("hasHeightForWidth");
+
+ QTest::newRow("") << false;
+ QTest::newRow("hasHeightForWidth") << true;
+}
// public qreal columnMaximumWidth(int column) const
void tst_QGraphicsGridLayout::columnMaximumWidth()
{
+ QFETCH(bool, hasHeightForWidth);
QGraphicsScene scene;
QGraphicsView view(&scene);
QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window);
QGraphicsGridLayout *layout = new QGraphicsGridLayout();
scene.addItem(widget);
widget->setLayout(layout);
- populateLayout(layout, 3, 2);
+ populateLayout(layout, 3, 2, hasHeightForWidth);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
@@ -638,16 +721,24 @@ void tst_QGraphicsGridLayout::columnMaximumWidth()
delete widget;
}
+void tst_QGraphicsGridLayout::columnMinimumWidth_data()
+{
+ QTest::addColumn<bool>("hasHeightForWidth");
+
+ QTest::newRow("") << false;
+ QTest::newRow("hasHeightForWidth") << true;
+}
// public qreal columnMinimumWidth(int column) const
void tst_QGraphicsGridLayout::columnMinimumWidth()
{
+ QFETCH(bool, hasHeightForWidth);
QGraphicsScene scene;
QGraphicsView view(&scene);
QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window);
QGraphicsGridLayout *layout = new QGraphicsGridLayout();
scene.addItem(widget);
widget->setLayout(layout);
- populateLayout(layout, 3, 2);
+ populateLayout(layout, 3, 2, hasHeightForWidth);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
@@ -673,16 +764,24 @@ void tst_QGraphicsGridLayout::columnMinimumWidth()
delete widget;
}
+void tst_QGraphicsGridLayout::columnPreferredWidth_data()
+{
+ QTest::addColumn<bool>("hasHeightForWidth");
+
+ QTest::newRow("") << false;
+ QTest::newRow("hasHeightForWidth") << true;
+}
// public qreal columnPreferredWidth(int column) const
void tst_QGraphicsGridLayout::columnPreferredWidth()
{
+ QFETCH(bool, hasHeightForWidth);
QGraphicsScene scene;
QGraphicsView view(&scene);
QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window);
QGraphicsGridLayout *layout = new QGraphicsGridLayout();
scene.addItem(widget);
widget->setLayout(layout);
- populateLayout(layout, 3, 2);
+ populateLayout(layout, 3, 2, hasHeightForWidth);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
@@ -992,16 +1091,25 @@ void tst_QGraphicsGridLayout::removeAt()
delete widget;
}
+void tst_QGraphicsGridLayout::rowAlignment_data()
+{
+ QTest::addColumn<bool>("hasHeightForWidth");
+
+ QTest::newRow("") << false;
+ QTest::newRow("hasHeightForWidth") << true;
+}
+
// public Qt::Alignment rowAlignment(int row) const
void tst_QGraphicsGridLayout::rowAlignment()
{
+ QFETCH(bool, hasHeightForWidth);
QGraphicsScene scene;
QGraphicsView view(&scene);
QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window);
QGraphicsGridLayout *layout = new QGraphicsGridLayout();
scene.addItem(widget);
widget->setLayout(layout);
- populateLayout(layout, 2, 3);
+ populateLayout(layout, 2, 3, hasHeightForWidth);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(1);
widget->setContentsMargins(0, 0, 0, 0);
@@ -1051,17 +1159,26 @@ void tst_QGraphicsGridLayout::rowAlignment()
delete widget;
}
+void tst_QGraphicsGridLayout::rowCount_data()
+{
+ QTest::addColumn<bool>("hasHeightForWidth");
+
+ QTest::newRow("") << false;
+ QTest::newRow("hasHeightForWidth") << true;
+}
+
// public int rowCount() const
// public int columnCount() const
void tst_QGraphicsGridLayout::rowCount()
{
+ QFETCH(bool, hasHeightForWidth);
QGraphicsScene scene;
QGraphicsView view(&scene);
QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window);
QGraphicsGridLayout *layout = new QGraphicsGridLayout();
scene.addItem(widget);
widget->setLayout(layout);
- populateLayout(layout, 2, 3);
+ populateLayout(layout, 2, 3, hasHeightForWidth);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
widget->setContentsMargins(0, 0, 0, 0);
@@ -1071,23 +1188,32 @@ void tst_QGraphicsGridLayout::rowCount()
// with spans and holes...
widget->setLayout(0);
layout = new QGraphicsGridLayout();
- populateLayoutWithSpansAndHoles(layout);
+ populateLayoutWithSpansAndHoles(layout, hasHeightForWidth);
QCOMPARE(layout->rowCount(), 2);
QCOMPARE(layout->columnCount(), 3);
delete widget;
}
+void tst_QGraphicsGridLayout::rowMaximumHeight_data()
+{
+ QTest::addColumn<bool>("hasHeightForWidth");
+
+ QTest::newRow("") << false;
+ QTest::newRow("hasHeightForWidth") << true;
+}
+
// public qreal rowMaximumHeight(int row) const
void tst_QGraphicsGridLayout::rowMaximumHeight()
{
+ QFETCH(bool, hasHeightForWidth);
QGraphicsScene scene;
QGraphicsView view(&scene);
QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window);
QGraphicsGridLayout *layout = new QGraphicsGridLayout;
scene.addItem(widget);
widget->setLayout(layout);
- populateLayout(layout, 2, 3);
+ populateLayout(layout, 2, 3, hasHeightForWidth);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
@@ -1113,16 +1239,24 @@ void tst_QGraphicsGridLayout::rowMaximumHeight()
delete widget;
}
+void tst_QGraphicsGridLayout::rowMinimumHeight_data()
+{
+ QTest::addColumn<bool>("hasHeightForWidth");
+
+ QTest::newRow("") << false;
+ QTest::newRow("hasHeightForWidth") << true;
+}
// public qreal rowMinimumHeight(int row) const
void tst_QGraphicsGridLayout::rowMinimumHeight()
{
+ QFETCH(bool, hasHeightForWidth);
QGraphicsScene scene;
QGraphicsView view(&scene);
QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window);
QGraphicsGridLayout *layout = new QGraphicsGridLayout();
scene.addItem(widget);
widget->setLayout(layout);
- populateLayout(layout, 2, 3);
+ populateLayout(layout, 2, 3, hasHeightForWidth);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
@@ -1148,16 +1282,24 @@ void tst_QGraphicsGridLayout::rowMinimumHeight()
delete widget;
}
+void tst_QGraphicsGridLayout::rowPreferredHeight_data()
+{
+ QTest::addColumn<bool>("hasHeightForWidth");
+
+ QTest::newRow("") << false;
+ QTest::newRow("hasHeightForWidth") << true;
+}
// public qreal rowPreferredHeight(int row) const
void tst_QGraphicsGridLayout::rowPreferredHeight()
{
+ QFETCH(bool, hasHeightForWidth);
QGraphicsScene scene;
QGraphicsView view(&scene);
QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window);
QGraphicsGridLayout *layout = new QGraphicsGridLayout();
scene.addItem(widget);
widget->setLayout(layout);
- populateLayout(layout, 2, 3);
+ populateLayout(layout, 2, 3, hasHeightForWidth);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
@@ -1246,16 +1388,25 @@ void tst_QGraphicsGridLayout::rowSpacing()
}
+void tst_QGraphicsGridLayout::rowStretchFactor_data()
+{
+ QTest::addColumn<bool>("hasHeightForWidth");
+
+ QTest::newRow("") << false;
+ QTest::newRow("hasHeightForWidth") << true;
+}
+
// public int rowStretchFactor(int row) const
void tst_QGraphicsGridLayout::rowStretchFactor()
{
+ QFETCH(bool, hasHeightForWidth);
QGraphicsScene scene;
QGraphicsView view(&scene);
QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window);
QGraphicsGridLayout *layout = new QGraphicsGridLayout();
scene.addItem(widget);
widget->setLayout(layout);
- populateLayout(layout, 2, 3);
+ populateLayout(layout, 2, 3, hasHeightForWidth);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
@@ -1279,9 +1430,12 @@ void tst_QGraphicsGridLayout::setColumnSpacing_data()
{
QTest::addColumn<int>("column");
QTest::addColumn<qreal>("spacing");
- QTest::newRow("null") << 0 << qreal(0.0);
- QTest::newRow("10") << 0 << qreal(10.0);
+ QTest::addColumn<bool>("hasHeightForWidth");
+ QTest::newRow("null") << 0 << qreal(0.0) << false;
+ QTest::newRow("10") << 0 << qreal(10.0) << false;
+ QTest::newRow("null, hasHeightForWidth") << 0 << qreal(0.0) << true;
+ QTest::newRow("10, hasHeightForWidth") << 0 << qreal(10.0) << true;
}
// public void setColumnSpacing(int column, qreal spacing)
@@ -1289,6 +1443,7 @@ void tst_QGraphicsGridLayout::setColumnSpacing()
{
QFETCH(int, column);
QFETCH(qreal, spacing);
+ QFETCH(bool, hasHeightForWidth);
QGraphicsScene scene;
QGraphicsView view(&scene);
@@ -1296,7 +1451,7 @@ void tst_QGraphicsGridLayout::setColumnSpacing()
QGraphicsGridLayout *layout = new QGraphicsGridLayout();
scene.addItem(widget);
widget->setLayout(layout);
- populateLayout(layout, 3, 2);
+ populateLayout(layout, 3, 2, hasHeightForWidth);
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
qreal oldSpacing = layout->columnSpacing(column);
@@ -1333,9 +1488,12 @@ void tst_QGraphicsGridLayout::setRowSpacing_data()
{
QTest::addColumn<int>("row");
QTest::addColumn<qreal>("spacing");
- QTest::newRow("null") << 0 << qreal(0.0);
- QTest::newRow("10") << 0 << qreal(10.0);
+ QTest::addColumn<bool>("hasHeightForWidth");
+ QTest::newRow("null") << 0 << qreal(0.0) << false;
+ QTest::newRow("10") << 0 << qreal(10.0) << false;
+ QTest::newRow("null, hasHeightForWidth") << 0 << qreal(0.0) << true;
+ QTest::newRow("10, hasHeightForWidth") << 0 << qreal(10.0) << true;
}
// public void setRowSpacing(int row, qreal spacing)
@@ -1343,6 +1501,7 @@ void tst_QGraphicsGridLayout::setRowSpacing()
{
QFETCH(int, row);
QFETCH(qreal, spacing);
+ QFETCH(bool, hasHeightForWidth);
QGraphicsScene scene;
QGraphicsView view(&scene);
@@ -1350,7 +1509,7 @@ void tst_QGraphicsGridLayout::setRowSpacing()
QGraphicsGridLayout *layout = new QGraphicsGridLayout();
scene.addItem(widget);
widget->setLayout(layout);
- populateLayout(layout, 3, 2);
+ populateLayout(layout, 3, 2, hasHeightForWidth);
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
qreal oldSpacing = layout->rowSpacing(row);
@@ -1364,21 +1523,25 @@ void tst_QGraphicsGridLayout::setRowSpacing()
void tst_QGraphicsGridLayout::setSpacing_data()
{
QTest::addColumn<qreal>("spacing");
- QTest::newRow("zero") << qreal(0.0);
- QTest::newRow("17") << qreal(17.0);
+ QTest::addColumn<bool>("hasHeightForWidth");
+ QTest::newRow("zero") << qreal(0.0) << false;
+ QTest::newRow("17") << qreal(17.0) << false;
+ QTest::newRow("zero, hasHeightForWidth") << qreal(0.0) << true;
+ QTest::newRow("17, hasHeightForWidth") << qreal(17.0) << true;
}
// public void setSpacing(qreal spacing)
void tst_QGraphicsGridLayout::setSpacing()
{
QFETCH(qreal, spacing);
+ QFETCH(bool, hasHeightForWidth);
QGraphicsScene scene;
QGraphicsView view(&scene);
QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window);
QGraphicsGridLayout *layout = new QGraphicsGridLayout();
scene.addItem(widget);
widget->setLayout(layout);
- populateLayout(layout, 3, 2);
+ populateLayout(layout, 3, 2, hasHeightForWidth);
layout->setContentsMargins(0, 0, 0, 0);
QSizeF sh = layout->sizeHint(Qt::PreferredSize, QSizeF());
qreal oldVSpacing = layout->verticalSpacing();
@@ -1509,8 +1672,18 @@ void tst_QGraphicsGridLayout::verticalSpacing()
delete widget;
}
+void tst_QGraphicsGridLayout::layoutDirection_data()
+{
+ QTest::addColumn<bool>("hasHeightForWidth");
+
+ QTest::newRow("") << false;
+ QTest::newRow("hasHeightForWidth") << true;
+}
+
void tst_QGraphicsGridLayout::layoutDirection()
{
+ QFETCH(bool, hasHeightForWidth);
+
QGraphicsScene scene;
QGraphicsView view(&scene);
@@ -1533,6 +1706,12 @@ void tst_QGraphicsGridLayout::layoutDirection()
w4->setMinimumSize(30, 20);
layout->addItem(w4, 1, 1);
+ QSizePolicy policy = w1->sizePolicy();
+ policy.setHeightForWidth(hasHeightForWidth);
+ w1->setSizePolicy(policy);
+ w2->setSizePolicy(policy);
+ w4->setSizePolicy(policy);
+
layout->setAlignment(w2, Qt::AlignRight);
layout->setAlignment(w3, Qt::AlignLeft);
@@ -2116,6 +2295,17 @@ void tst_QGraphicsGridLayout::alignment2()
delete widget;
}
+static QSizeF hfw1(Qt::SizeHint, const QSizeF &constraint)
+{
+ QSizeF result(constraint);
+ if (constraint.width() < 0 && constraint.height() < 0) {
+ return QSizeF(50, 400);
+ } else if (constraint.width() >= 0) {
+ result.setHeight(20000./constraint.width());
+ }
+ return result;
+}
+
void tst_QGraphicsGridLayout::geometries_data()
{
@@ -2145,6 +2335,57 @@ void tst_QGraphicsGridLayout::geometries_data()
<< QRectF(0, 0, 60,10) << QRectF(0, 10, 60,10)
);
+ // change layout height and verify
+ QTest::newRow("hfw-h401") << (ItemList()
+ << ItemDesc(0,0)
+ .minSize(QSizeF(1,1))
+ .preferredSize(QSizeF(50,10))
+ .maxSize(QSizeF(100, 100))
+ << ItemDesc(0,1)
+ .minSize(QSizeF(1,1))
+ .preferredSize(QSizeF(50,10))
+ .maxSize(QSizeF(100, 100))
+ << ItemDesc(1,0)
+ .minSize(QSizeF(1,1))
+ .preferredSize(QSizeF(50,10))
+ .maxSize(QSizeF(100, 100))
+ << ItemDesc(1,1)
+ .minSize(QSizeF(40,-1))
+ .preferredSize(QSizeF(50,-1))
+ .maxSize(QSizeF(500, -1))
+ .heightForWidth(hfw1)
+ )
+ << QSizeF(100, 401)
+ << (RectList()
+ << QRectF(0, 0, 50, 1) << QRectF(50, 0, 50, 1)
+ << QRectF(0, 1, 50,100) << QRectF(50, 1, 50,400)
+ );
+
+ QTest::newRow("hfw-h410") << (ItemList()
+ << ItemDesc(0,0)
+ .minSize(QSizeF(1,1))
+ .preferredSize(QSizeF(50,10))
+ .maxSize(QSizeF(100, 100))
+ << ItemDesc(0,1)
+ .minSize(QSizeF(1,1))
+ .preferredSize(QSizeF(50,10))
+ .maxSize(QSizeF(100, 100))
+ << ItemDesc(1,0)
+ .minSize(QSizeF(1,1))
+ .preferredSize(QSizeF(50,10))
+ .maxSize(QSizeF(100, 100))
+ << ItemDesc(1,1)
+ .minSize(QSizeF(40,40))
+ .preferredSize(QSizeF(50,400))
+ .maxSize(QSizeF(500, 500))
+ .heightForWidth(hfw1)
+ )
+ << QSizeF(100, 410)
+ << (RectList()
+ << QRectF(0, 0, 50,10) << QRectF(50, 0, 50,10)
+ << QRectF(0, 10, 50,100) << QRectF(50, 10, 50,400)
+ );
+
}
void tst_QGraphicsGridLayout::geometries()
@@ -2215,6 +2456,177 @@ void tst_QGraphicsGridLayout::task236367_maxSizeHint()
QCOMPARE(widget->size(), QSizeF(w, h));
}
+/*
+static qreal hfw(qreal w)
+{
+ if (w == 0)
+ return 20000;
+ return 20000/w;
+}
+*/
+static QSizeF hfw(Qt::SizeHint /*which*/, const QSizeF &constraint)
+{
+ QSizeF result(constraint);
+ const qreal cw = constraint.width();
+ const qreal ch = constraint.height();
+ if (cw < 0 && ch < 0) {
+ return QSizeF(200, 100);
+ } else if (cw >= 0) {
+ result.setHeight(20000./cw);
+ } else if (cw == 0) {
+ result.setHeight(20000);
+ } else if (ch >= 0) {
+ result.setWidth(20000./ch);
+ } else if (ch == 0) {
+ result.setWidth(20000);
+ }
+
+ return result;
+}
+
+static qreal growthFactorBelowPreferredSize(qreal desired, qreal sumAvailable, qreal sumDesired)
+{
+ Q_ASSERT(sumDesired != 0.0);
+ return desired * qPow(sumAvailable / sumDesired, desired / sumDesired);
+}
+
+static void expectedWidth(qreal minSize1, qreal prefSize1,
+ qreal minSize2, qreal prefSize2,
+ qreal targetSize, qreal *width1, qreal *width2)
+{
+ qreal sumAvail,factor1,factor2;
+ // stretch behaviour is different below and above preferred size...
+ if (targetSize < prefSize1 + prefSize2) {
+ sumAvail = targetSize - minSize1 - minSize2;
+ const qreal desired1 = prefSize1 - minSize1;
+ const qreal desired2 = prefSize2 - minSize2;
+ const qreal sumDesired = desired1 + desired2;
+ factor1 = growthFactorBelowPreferredSize(desired1, sumAvail, sumDesired);
+ factor2 = growthFactorBelowPreferredSize(desired2, sumAvail, sumDesired);
+ const qreal sumFactors = factor1 + factor2;
+ *width1 = sumAvail*factor1/sumFactors + minSize1;
+ *width2 = sumAvail*factor2/sumFactors + minSize2;
+ } else {
+ sumAvail = targetSize - prefSize1 - prefSize2;
+ factor1 = prefSize1;
+ factor2 = prefSize2;
+ const qreal sumFactors = factor1 + factor2;
+ *width1 = sumAvail*factor1/sumFactors + prefSize1;
+ *width2 = sumAvail*factor2/sumFactors + prefSize2;
+ }
+}
+
+
+bool qFuzzyCompare(const QSizeF &a, const QSizeF &b)
+{
+ return qFuzzyCompare(a.width(), b.width()) && qFuzzyCompare(a.height(), b.height());
+}
+
+void tst_QGraphicsGridLayout::heightForWidth()
+{
+ QGraphicsWidget *widget = new QGraphicsWidget;
+ QGraphicsGridLayout *layout = new QGraphicsGridLayout;
+ widget->setLayout(layout);
+ layout->setContentsMargins(0, 0, 0, 0);
+ layout->setSpacing(0);
+ RectWidget *w00 = new RectWidget;
+ w00->setSizeHint(Qt::MinimumSize, QSizeF(1,1));
+ w00->setSizeHint(Qt::PreferredSize, QSizeF(10,10));
+ w00->setSizeHint(Qt::MaximumSize, QSizeF(100,100));
+ layout->addItem(w00, 0, 0);
+
+ RectWidget *w01 = new RectWidget;
+ w01->setSizeHint(Qt::MinimumSize, QSizeF(1,1));
+ w01->setSizeHint(Qt::PreferredSize, QSizeF(10,10));
+ w01->setSizeHint(Qt::MaximumSize, QSizeF(100,100));
+ layout->addItem(w01, 0, 1);
+
+ RectWidget *w10 = new RectWidget;
+ w10->setSizeHint(Qt::MinimumSize, QSizeF(1,1));
+ w10->setSizeHint(Qt::PreferredSize, QSizeF(10,10));
+ w10->setSizeHint(Qt::MaximumSize, QSizeF(100,100));
+ layout->addItem(w10, 1, 0);
+
+ RectWidget *w11 = new RectWidget;
+ w11->setSizeHint(Qt::MinimumSize, QSizeF(1,1));
+ w11->setSizeHint(Qt::MaximumSize, QSizeF(30000,30000));
+ w11->setConstraintFunction(hfw);
+ QSizePolicy sp(QSizePolicy::Preferred, QSizePolicy::Preferred);
+ sp.setHeightForWidth(true);
+ w11->setSizePolicy(sp);
+ layout->addItem(w11, 1, 1);
+
+ QSizeF prefSize = layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(-1, -1));
+ QCOMPARE(prefSize, QSizeF(10+200, 10+100));
+
+ QCOMPARE(layout->effectiveSizeHint(Qt::MinimumSize, QSizeF(2, -1)), QSizeF(2, 20001));
+ QCOMPARE(layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(2, -1)), QSizeF(2, 20010));
+ QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(2, -1)), QSizeF(2, 20100));
+ qreal width1;
+ qreal width2;
+ expectedWidth(1, 10, 1, 200, 20, &width1, &width2);
+ QSizeF expectedSize = hfw(Qt::MinimumSize, QSizeF(width2, -1)) + QSizeF(width1, 1);
+ QCOMPARE(layout->effectiveSizeHint(Qt::MinimumSize, QSizeF(20, -1)), expectedSize);
+ expectedSize.rheight()+=9;
+ QCOMPARE(layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(20, -1)), expectedSize);
+ expectedSize.rheight()+=90;
+ QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(20, -1)), expectedSize);
+
+ expectedWidth(1, 10, 1, 200, 300, &width1, &width2);
+ expectedSize = hfw(Qt::MinimumSize, QSizeF(width2, -1)) + QSizeF(width1, 1);
+ QCOMPARE(layout->effectiveSizeHint(Qt::MinimumSize, QSizeF(300, -1)), expectedSize);
+ expectedSize.rheight()+=9;
+ QCOMPARE(layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(300, -1)), expectedSize);
+ // the height of the hfw widget is shorter than the one to the left, which is 100, so
+ // the total height of the last row is 100 (which leaves the layout height to be 200)
+ QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(300, -1)), QSizeF(300, 200));
+
+ // the hfw item is shorter than the item to the left
+ expectedWidth(1, 10, 1, 200, 500, &width1, &width2);
+ expectedSize = hfw(Qt::MinimumSize, QSizeF(width2, -1)) + QSizeF(width1, 1);
+ QCOMPARE(layout->effectiveSizeHint(Qt::MinimumSize, QSizeF(500, -1)), expectedSize);
+ expectedSize.rheight()+=9;
+ QCOMPARE(layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(500, -1)), expectedSize);
+ // the height of the hfw widget is shorter than the one to the left, which is 100, so
+ // the total height of the last row is 100 (which leaves the layout height to be 200)
+ QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(500, -1)), QSizeF(500, 200));
+
+}
+
+void tst_QGraphicsGridLayout::heightForWidthWithSpanning()
+{
+ QGraphicsWidget *widget = new QGraphicsWidget;
+ QGraphicsGridLayout *layout = new QGraphicsGridLayout;
+ widget->setLayout(layout);
+ layout->setContentsMargins(0, 0, 0, 0);
+ layout->setSpacing(0);
+
+ RectWidget *w = new RectWidget;
+ w->setSizeHint(Qt::MinimumSize, QSizeF(1,1));
+ w->setSizeHint(Qt::MaximumSize, QSizeF(30000,30000));
+ w->setConstraintFunction(hfw);
+ QSizePolicy sp(QSizePolicy::Preferred, QSizePolicy::Preferred);
+ sp.setHeightForWidth(true);
+ w->setSizePolicy(sp);
+ layout->addItem(w, 0,0,2,2);
+
+ QCOMPARE(layout->effectiveSizeHint(Qt::MinimumSize, QSizeF(-1, -1)), QSizeF(1, 100));
+ QCOMPARE(layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(-1, -1)), QSizeF(200, 100));
+ QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(-1, -1)), QSizeF(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
+
+ QCOMPARE(layout->effectiveSizeHint(Qt::MinimumSize, QSizeF(200, -1)), QSizeF(200, 100));
+ QCOMPARE(layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(200, -1)), QSizeF(200, 100));
+ QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(200, -1)), QSizeF(200, QWIDGETSIZE_MAX));
+
+ QCOMPARE(layout->effectiveSizeHint(Qt::MinimumSize, QSizeF(2, -1)), QSizeF(2, 10000));
+ QCOMPARE(layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(2, -1)), QSizeF(2, 10000));
+ QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(2, -1)), QSizeF(2, QWIDGETSIZE_MAX));
+
+ QCOMPARE(layout->effectiveSizeHint(Qt::MinimumSize, QSizeF(200, -1)), QSizeF(200, 100));
+ QCOMPARE(layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(200, -1)), QSizeF(200, 100));
+ QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(200, -1)), QSizeF(200, QWIDGETSIZE_MAX));
+}
+
QTEST_MAIN(tst_QGraphicsGridLayout)
#include "tst_qgraphicsgridlayout.moc"
diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
index 306b5f8..88714e6 100644
--- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
@@ -291,6 +291,8 @@ private Q_SLOTS:
void qtbug12908compressedHttpReply();
+ void getFromUnreachableIp();
+
// NOTE: This test must be last!
void parentingRepliesToTheApp();
};
@@ -4301,6 +4303,19 @@ void tst_QNetworkReply::qtbug12908compressedHttpReply()
QCOMPARE(reply->error(), QNetworkReply::NoError);
}
+void tst_QNetworkReply::getFromUnreachableIp()
+{
+ QNetworkAccessManager manager;
+
+ QNetworkRequest request(QUrl("http://255.255.255.255/42/23/narf/narf/narf"));
+ QNetworkReplyPtr reply = manager.get(request);
+
+ connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
+ QTestEventLoop::instance().enterLoop(5);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+
+ QVERIFY(reply->error() != QNetworkReply::NoError);
+}
// NOTE: This test must be last testcase in tst_qnetworkreply!
void tst_QNetworkReply::parentingRepliesToTheApp()