eric7/Graphics/ClassItem.py

branch
eric7
changeset 8805
6e3a15f98fd2
parent 8720
336f594ff5dd
child 8881
54e42bc2437a
equal deleted inserted replaced
8804:bf6eff477756 8805:6e3a15f98fd2
159 159
160 classAttributes = self.model.getClassAttributes() 160 classAttributes = self.model.getClassAttributes()
161 attrs = self.model.getInstanceAttributes() 161 attrs = self.model.getInstanceAttributes()
162 meths = self.model.getMethods() 162 meths = self.model.getMethods()
163 163
164 x = self.margin + self.rect().x() 164 x = self.margin + int(self.rect().x())
165 y = self.margin + self.rect().y() 165 y = self.margin + int(self.rect().y())
166 self.header = QGraphicsSimpleTextItem(self) 166 self.header = QGraphicsSimpleTextItem(self)
167 self.header.setBrush(self._colors[0]) 167 self.header.setBrush(self._colors[0])
168 self.header.setFont(boldFont) 168 self.header.setFont(boldFont)
169 self.header.setText(self.model.getName()) 169 self.header.setText(self.model.getName())
170 self.header.setPos(x, y) 170 self.header.setPos(x, y)
171 y += self.header.boundingRect().height() + self.margin 171 y += int(self.header.boundingRect().height()) + self.margin
172 172
173 if self.external: 173 if self.external:
174 self.classAttributes = None 174 self.classAttributes = None
175 else: 175 else:
176 txt = QCoreApplication.translate( 176 txt = QCoreApplication.translate(
183 self.classAttributes = QGraphicsSimpleTextItem(self) 183 self.classAttributes = QGraphicsSimpleTextItem(self)
184 self.classAttributes.setBrush(self._colors[0]) 184 self.classAttributes.setBrush(self._colors[0])
185 self.classAttributes.setFont(self.font) 185 self.classAttributes.setFont(self.font)
186 self.classAttributes.setText(txt) 186 self.classAttributes.setText(txt)
187 self.classAttributes.setPos(x, y) 187 self.classAttributes.setPos(x, y)
188 y += self.classAttributes.boundingRect().height() + self.margin 188 y += (int(self.classAttributes.boundingRect().height()) +
189 self.margin)
189 190
190 if not self.noAttrs and not self.external: 191 if not self.noAttrs and not self.external:
191 txt = QCoreApplication.translate( 192 txt = QCoreApplication.translate(
192 "ClassItem", "Instance Attributes:\n ") 193 "ClassItem", "Instance Attributes:\n ")
193 txt += ( 194 txt += (
198 self.attrs = QGraphicsSimpleTextItem(self) 199 self.attrs = QGraphicsSimpleTextItem(self)
199 self.attrs.setBrush(self._colors[0]) 200 self.attrs.setBrush(self._colors[0])
200 self.attrs.setFont(self.font) 201 self.attrs.setFont(self.font)
201 self.attrs.setText(txt) 202 self.attrs.setText(txt)
202 self.attrs.setPos(x, y) 203 self.attrs.setPos(x, y)
203 y += self.attrs.boundingRect().height() + self.margin 204 y += int(self.attrs.boundingRect().height()) + self.margin
204 else: 205 else:
205 self.attrs = None 206 self.attrs = None
206 207
207 if self.external: 208 if self.external:
208 txt = " " 209 txt = " "
224 Private method to calculate the size of the class item. 225 Private method to calculate the size of the class item.
225 """ 226 """
226 if self.model is None: 227 if self.model is None:
227 return 228 return
228 229
229 width = self.header.boundingRect().width() 230 width = int(self.header.boundingRect().width())
230 height = self.header.boundingRect().height() 231 height = int(self.header.boundingRect().height())
231 if self.classAttributes: 232 if self.classAttributes:
232 width = max(width, self.classAttributes.boundingRect().width()) 233 width = max(width,
234 int(self.classAttributes.boundingRect().width()))
233 height += ( 235 height += (
234 self.classAttributes.boundingRect().height() + self.margin 236 int(self.classAttributes.boundingRect().height()) + self.margin
235 ) 237 )
236 if self.attrs: 238 if self.attrs:
237 width = max(width, self.attrs.boundingRect().width()) 239 width = max(width,
238 height = height + self.attrs.boundingRect().height() + self.margin 240 int(self.attrs.boundingRect().width()))
241 height = (
242 height + int(self.attrs.boundingRect().height()) + self.margin
243 )
239 if self.meths: 244 if self.meths:
240 width = max(width, self.meths.boundingRect().width()) 245 width = max(width,
241 height += self.meths.boundingRect().height() 246 int(self.meths.boundingRect().width()))
247 height += int(self.meths.boundingRect().height())
242 248
243 self.setSize(width + 2 * self.margin, height + 2 * self.margin) 249 self.setSize(width + 2 * self.margin, height + 2 * self.margin)
244 250
245 def setModel(self, model): 251 def setModel(self, model):
246 """ 252 """
286 292
287 painter.setPen(pen) 293 painter.setPen(pen)
288 painter.setBrush(self.brush()) 294 painter.setBrush(self.brush())
289 painter.setFont(self.font) 295 painter.setFont(self.font)
290 296
291 offsetX = self.rect().x() 297 offsetX = int(self.rect().x())
292 offsetY = self.rect().y() 298 offsetY = int(self.rect().y())
293 w = self.rect().width() 299 w = int(self.rect().width())
294 h = self.rect().height() 300 h = int(self.rect().height())
295 301
296 painter.drawRect(offsetX, offsetY, w, h) 302 painter.drawRect(offsetX, offsetY, w, h)
297 y = self.margin + self.header.boundingRect().height() 303 y = self.margin + int(self.header.boundingRect().height())
298 painter.drawLine(offsetX, offsetY + y, offsetX + w - 1, offsetY + y) 304 painter.drawLine(offsetX, offsetY + y, offsetX + w - 1, offsetY + y)
299 if self.classAttributes: 305 if self.classAttributes:
300 y += self.margin + self.classAttributes.boundingRect().height() 306 y += (
307 self.margin +
308 int(self.classAttributes.boundingRect().height())
309 )
301 painter.drawLine(offsetX, offsetY + y, 310 painter.drawLine(offsetX, offsetY + y,
302 offsetX + w - 1, offsetY + y) 311 offsetX + w - 1, offsetY + y)
303 if self.attrs: 312 if self.attrs:
304 y += self.margin + self.attrs.boundingRect().height() 313 y += self.margin + int(self.attrs.boundingRect().height())
305 painter.drawLine(offsetX, offsetY + y, 314 painter.drawLine(offsetX, offsetY + y,
306 offsetX + w - 1, offsetY + y) 315 offsetX + w - 1, offsetY + y)
307 316
308 self.adjustAssociations() 317 self.adjustAssociations()
309 318

eric ide

mercurial