comparison demos/interview/model.d @ 202:57c3714ed282

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