def load_file(self, f, **kwargs): products = list(f.by_type("IfcProduct")) types = set(map(lambda i: i.is_a(), products)) items = {} for t in types: def add(t): s = get_supertype(t) if s: add(s) s2, t2 = map(QString, (s, t)) if t2 not in items: itm = items[t2] = QtGui.QTreeWidgetItem( items.get(s2, self), [t2]) itm.setData(0, QtCore.Qt.UserRole, t2) self.children[s2].append(t2) add(t) for p in products: t = QString(p.is_a()) itm = items[p] = QtGui.QTreeWidgetItem(items.get(t, self), [p.Name or '<no name>']) itm.setData(0, QtCore.Qt.UserRole, t) self.children[t].append(p) self.product_to_item = dict( zip(items.keys(), map(self.indexFromItem, items.values()))) self.connect(self, QtCore.SIGNAL("clicked(const QModelIndex &)"), self.clicked) self.expandAll()
def load_file(self, f, **kwargs): products = list(f.by_type("IfcProduct")) + list( f.by_type("IfcProject")) parents = list(map(self.parent, products)) items = {} skipped = 0 ATTRS = self.ATTRIBUTES while len(items) + skipped < len(products): for product, parent in zip(products, parents): if parent is None and not product.is_a("IfcProject"): skipped += 1 continue if (parent is None or parent in items) and product not in items: sl = [] for attr in ATTRS: if attr == 'Entity': sl.append(product.is_a()) else: sl.append(getattr(product, attr) or '') itm = items[product] = QtGui.QTreeWidgetItem( items.get(parent, self), sl) itm.setData(0, QtCore.Qt.UserRole, product) self.children[parent].append(product) self.product_to_item = dict( zip(items.keys(), map(self.indexFromItem, items.values()))) self.connect(self, QtCore.SIGNAL("clicked(const QModelIndex &)"), self.clicked) self.expandAll()