1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3
4#############################################################################
5##
6## Copyright (C) 2016 The Qt Company Ltd.
7## Copyright (C) 2011 Thomas Perl <m@thp.io>
8## Contact: https://www.qt.io/licensing/
9##
10## This file is part of the test suite of Qt for Python.
11##
12## $QT_BEGIN_LICENSE:GPL-EXCEPT$
13## Commercial License Usage
14## Licensees holding valid commercial Qt licenses may use this file in
15## accordance with the commercial license agreement provided with the
16## Software or, alternatively, in accordance with the terms contained in
17## a written agreement between you and The Qt Company. For licensing terms
18## and conditions see https://www.qt.io/terms-conditions. For further
19## information use the contact form at https://www.qt.io/contact-us.
20##
21## GNU General Public License Usage
22## Alternatively, this file may be used under the terms of the GNU
23## General Public License version 3 as published by the Free Software
24## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
25## included in the packaging of this file. Please review the following
26## information to ensure the GNU General Public License requirements will
27## be met: https://www.gnu.org/licenses/gpl-3.0.html.
28##
29## $QT_END_LICENSE$
30##
31#############################################################################
32
33# Test case for PySide bug 814
34# http://bugs.pyside.org/show_bug.cgi?id=814
35# archive:
36# https://srinikom.github.io/pyside-bz-archive/814.html
37# 2011-04-08 Thomas Perl <m@thp.io>
38# Released under the same terms as PySide itself
39
40import os
41import sys
42import unittest
43
44sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
45from init_paths import init_test_paths
46init_test_paths(False)
47
48from helper.helper import adjust_filename
49from helper.timedqapplication import TimedQApplication
50
51from PySide2.QtCore import QUrl, QAbstractListModel, QModelIndex, Qt
52from PySide2.QtQuick import QQuickView
53
54class ListModel(QAbstractListModel):
55    def __init__(self):
56        QAbstractListModel.__init__(self)
57
58    def roleNames(self):
59        return { Qt.DisplayRole: b'pysideModelData' }
60
61    def rowCount(self, parent = QModelIndex()):
62        return 3
63
64    def data(self, index, role):
65        if index.isValid() and role == Qt.DisplayRole:
66            return 'blubb'
67        return None
68
69class TestBug814(TimedQApplication):
70    def testAbstractItemModelTransferToQML(self):
71        view = QQuickView()
72        model = ListModel()
73        view.rootContext().setContextProperty("pythonModel", model)
74        view.setSource(QUrl.fromLocalFile(adjust_filename('bug_814.qml', __file__)))
75        root = view.rootObject()
76        view.show()
77
78if __name__ == '__main__':
79    unittest.main()
80
81