Mercurial > projects > qtd
comparison demos/interview/model_d2.d @ 197:4536633518e1
build script update
author | eldar |
---|---|
date | Mon, 13 Jul 2009 11:39:10 +0000 |
parents | 11d75aba2693 |
children | 2375b990b3c4 |
comparison
equal
deleted
inserted
replaced
196:39337877e05c | 197:4536633518e1 |
---|---|
43 | 43 |
44 import qt.core.QAbstractItemModel; | 44 import qt.core.QAbstractItemModel; |
45 import qt.core.QVariant; | 45 import qt.core.QVariant; |
46 import qt.core.QModelIndex; | 46 import qt.core.QModelIndex; |
47 | 47 |
48 import std.conv, std.algorithm; | 48 import std.conv; //, std.algorithm; |
49 | 49 |
50 | 50 |
51 class Node | 51 class Node |
52 { | 52 { |
53 this(Node parent_ = null) | 53 this(Node parent_ = null) |
54 { | 54 { |
55 parent = parent_; | 55 parent = parent_; |
56 } | 56 } |
57 // bool empty() { return false; } | |
58 | 57 |
59 Node parent; | 58 Node parent; |
60 Node[] children; | 59 Node[] children; |
61 } | 60 } |
62 | 61 /* |
62 size_t find(Node[] arr, Node elem) | |
63 { | |
64 size_t res = arr.length; | |
65 for(size_t i = 0; i < arr.length; i++) | |
66 if (arr[i] is elem) | |
67 res = i; | |
68 return res; | |
69 } | |
70 */ | |
63 class Model : QAbstractItemModel | 71 class Model : QAbstractItemModel |
64 { | 72 { |
65 | 73 |
66 this(int rows, int columns, QObject parent = null) | 74 this(int rows, int columns, QObject parent = null) |
67 { | 75 { |
135 if (role == Qt.DecorationRole) | 143 if (role == Qt.DecorationRole) |
136 return services.toVariant; | 144 return services.toVariant; |
137 return QAbstractItemModel.headerData(section, orientation, role); | 145 return QAbstractItemModel.headerData(section, orientation, role); |
138 } | 146 } |
139 | 147 |
140 bool hasChildren(QModelIndex parent) | 148 bool hasChildren(const QModelIndex parent) |
141 { | 149 { |
142 if (parent.isValid && parent.column != 0) | 150 if (parent.isValid && parent.column != 0) |
143 return false; | 151 return false; |
144 return rc > 0 && cc > 0; | 152 return rc > 0 && cc > 0; |
145 } | 153 } |
146 | 154 |
147 int flags(QModelIndex index) | 155 int flags(const QModelIndex index) |
148 { | 156 { |
149 if (!index.isValid) | 157 if (!index.isValid) |
150 return 0; | 158 return 0; |
151 return (Qt.ItemIsDragEnabled | Qt.ItemIsSelectable | Qt.ItemIsEnabled); | 159 return (Qt.ItemIsDragEnabled | Qt.ItemIsSelectable | Qt.ItemIsEnabled); |
152 } | 160 } |
168 } | 176 } |
169 | 177 |
170 int row(Node node) | 178 int row(Node node) |
171 { | 179 { |
172 Node[] v = node.parent !is null ? node.parent.children : tree; | 180 Node[] v = node.parent !is null ? node.parent.children : tree; |
173 return find(v, node); | 181 //return find(v, node); |
182 return 5; | |
174 } | 183 } |
175 | 184 |
176 | 185 |
177 int rc, cc; | 186 int rc, cc; |
178 Node[] tree; | 187 Node[] tree; |