Mercurial > projects > qtd
comparison demos/interview/model_d2.d @ 202:57c3714ed282
interview fixes, using override keyword
author | eldar |
---|---|
date | Mon, 13 Jul 2009 13:47:15 +0000 |
parents | aa3811034056 |
children |
comparison
equal
deleted
inserted
replaced
201:aa3811034056 | 202:57c3714ed282 |
---|---|
87 file = iconProvider.icon(QFileIconProvider.File); | 87 file = iconProvider.icon(QFileIconProvider.File); |
88 services = new QIcon(":/images/services.png"); | 88 services = new QIcon(":/images/services.png"); |
89 } | 89 } |
90 | 90 |
91 | 91 |
92 QModelIndex index(int row, int column, const QModelIndex parent) | 92 override QModelIndex index(int row, int column, const QModelIndex parent) |
93 { | 93 { |
94 if (row < rc && row >= 0 && column < cc && column >= 0) { | 94 if (row < rc && row >= 0 && column < cc && column >= 0) { |
95 Node p = cast(Node) parent.internalPointer(); | 95 Node p = cast(Node) parent.internalPointer(); |
96 Node n = getNode(row, p); | 96 Node n = getNode(row, p); |
97 if (n !is null) | 97 if (n !is null) |
98 return createIndex(row, column, cast(void*)n); | 98 return createIndex(row, column, cast(void*)n); |
99 } | 99 } |
100 return QModelIndex(); | 100 return QModelIndex(); |
101 } | 101 } |
102 | 102 |
103 QModelIndex parent(const QModelIndex child) | 103 override QModelIndex parent(const QModelIndex child) |
104 { | 104 { |
105 if (child.isValid()) { | 105 if (child.isValid()) { |
106 Node n = cast(Node) child.internalPointer(); | 106 Node n = cast(Node) child.internalPointer(); |
107 Node p = parent(n); | 107 Node p = parent(n); |
108 if (p !is null) | 108 if (p !is null) |
109 return createIndex(row(p), 0, cast(void*)p); | 109 return createIndex(row(p), 0, cast(void*)p); |
110 } | 110 } |
111 return QModelIndex(); | 111 return QModelIndex(); |
112 } | 112 } |
113 | 113 |
114 int rowCount(const QModelIndex parent) | 114 override int rowCount(const QModelIndex parent) |
115 { | 115 { |
116 return (parent.isValid() && parent.column() != 0) ? 0 : rc; | 116 return (parent.isValid() && parent.column() != 0) ? 0 : rc; |
117 } | 117 } |
118 | 118 |
119 int columnCount(const QModelIndex parent) | 119 override int columnCount(const QModelIndex parent) |
120 { | 120 { |
121 return cc; | 121 return cc; |
122 } | 122 } |
123 | 123 |
124 QVariant data(const QModelIndex index, int role) | 124 override QVariant data(const QModelIndex index, int role) |
125 { | 125 { |
126 if (!index.isValid) | 126 if (!index.isValid) |
127 return new QVariant; | 127 return new QVariant; |
128 if (role == Qt.DisplayRole) | 128 if (role == Qt.DisplayRole) |
129 return new QVariant("Item " ~ to!string(index.row) ~ ":" ~ to!string(index.column)); | 129 return new QVariant("Item " ~ to!string(index.row) ~ ":" ~ to!string(index.column)); |
134 return file.toVariant; | 134 return file.toVariant; |
135 } | 135 } |
136 return new QVariant; | 136 return new QVariant; |
137 } | 137 } |
138 | 138 |
139 QVariant headerData(int section, Qt.Orientation orientation, int role) | 139 override QVariant headerData(int section, Qt.Orientation orientation, int role) |
140 { | 140 { |
141 if (role == Qt.DisplayRole) | 141 if (role == Qt.DisplayRole) |
142 return new QVariant(to!string(section)); | 142 return new QVariant(to!string(section)); |
143 if (role == Qt.DecorationRole) | 143 if (role == Qt.DecorationRole) |
144 return services.toVariant; | 144 return services.toVariant; |
145 return QAbstractItemModel.headerData(section, orientation, role); | 145 return QAbstractItemModel.headerData(section, orientation, role); |
146 } | 146 } |
147 | 147 |
148 bool hasChildren(const QModelIndex parent) | 148 override bool hasChildren(const QModelIndex parent) |
149 { | 149 { |
150 if (parent.isValid && parent.column != 0) | 150 if (parent.isValid && parent.column != 0) |
151 return false; | 151 return false; |
152 return rc > 0 && cc > 0; | 152 return rc > 0 && cc > 0; |
153 } | 153 } |
154 | 154 |
155 int flags(const QModelIndex index) | 155 override int flags(const QModelIndex index) |
156 { | 156 { |
157 if (!index.isValid) | 157 if (!index.isValid) |
158 return 0; | 158 return 0; |
159 return (Qt.ItemIsDragEnabled | Qt.ItemIsSelectable | Qt.ItemIsEnabled); | 159 return (Qt.ItemIsDragEnabled | Qt.ItemIsSelectable | Qt.ItemIsEnabled); |
160 } | 160 } |