1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 Canonical Limited and/or its subsidiary(-ies). |
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 | #include "proxytestinnermodel.h" |
30 | |
31 | ProxyTestInnerModel::ProxyTestInnerModel() |
32 | { |
33 | append(s: "Adios" ); |
34 | append(s: "Hola" ); |
35 | append(s: "Halo" ); |
36 | } |
37 | |
38 | QModelIndex ProxyTestInnerModel::index(int row, int column, const QModelIndex &parent) const |
39 | { |
40 | if (parent.isValid()) |
41 | return QModelIndex(); |
42 | |
43 | return createIndex(arow: row, acolumn: column); |
44 | } |
45 | |
46 | QModelIndex ProxyTestInnerModel::parent(const QModelIndex & /*parent*/) const |
47 | { |
48 | return QModelIndex(); |
49 | } |
50 | |
51 | int ProxyTestInnerModel::rowCount(const QModelIndex &parent) const |
52 | { |
53 | if (parent.isValid()) |
54 | return 0; |
55 | |
56 | return m_values.count(); |
57 | } |
58 | |
59 | int ProxyTestInnerModel::columnCount(const QModelIndex &parent) const |
60 | { |
61 | if (parent.isValid()) |
62 | return 0; |
63 | |
64 | return 1; |
65 | } |
66 | |
67 | QVariant ProxyTestInnerModel::data(const QModelIndex &index, int role) const |
68 | { |
69 | if (role != Qt::DisplayRole) |
70 | return QVariant(); |
71 | |
72 | return m_values[index.row()]; |
73 | } |
74 | |
75 | void ProxyTestInnerModel::append(const QString &s) |
76 | { |
77 | beginInsertRows(parent: QModelIndex(), first: m_values.count(), last: m_values.count()); |
78 | m_values << s; |
79 | endInsertRows(); |
80 | } |
81 | |
82 | void ProxyTestInnerModel::setValue(int i, const QString &s) |
83 | { |
84 | m_values[i] = s; |
85 | Q_EMIT dataChanged(topLeft: index(row: i, column: 0), bottomRight: index(row: i, column: 0)); |
86 | } |
87 | |
88 | void ProxyTestInnerModel::moveTwoToZero() |
89 | { |
90 | beginMoveRows(sourceParent: QModelIndex(), sourceFirst: 2, sourceLast: 2, destinationParent: QModelIndex(), destinationRow: 0); |
91 | m_values.move(from: 2, to: 0); |
92 | endMoveRows(); |
93 | } |
94 | |
95 | void ProxyTestInnerModel::doStuff() |
96 | { |
97 | moveTwoToZero(); |
98 | setValue(i: 1, s: "Hilo" ); |
99 | } |
100 | |