def data(self, index, role): """ Return the data of this node, used to style the items :param index: :param role: :return: """ if not index.isValid(): return item = index.internalPointer() if role == Qt.DisplayRole: return item.text(index.column()) elif role == Qt.ToolTipRole: return item.tooltip(index.column()) elif role == STATUS_ROLE: return item.status elif role == Qt.ForegroundRole: if isinstance(item, RequestParentItem) and item.ssl_errors \ or isinstance(item, SslErrorsItem) \ or isinstance(index.parent().internalPointer(), SslErrorsItem): color = QColor(180, 65, 210) elif item.status in (PENDING, CANCELED): color = QColor(0, 0, 0, 100) elif item.status == ERROR: color = QColor(235, 10, 10) elif item.status == TIMEOUT: color = QColor(235, 10, 10) else: color = QColor(0, 0, 0) return QBrush(color) elif role == Qt.FontRole: f = QFont() if item.status == CANCELED: f.setStrikeOut(True) return f
def std_font_to_qfont(font): # pylint: disable=too-many-branches """ Converts STD font to QFont """ name = font.font_name style_name = None # we need to sometimes strip 'Italic' or 'Bold' suffixes from the font name stored in the ESRI object # in order to match against actual font families keep_scanning = True while name not in QFontDatabase().families() and keep_scanning: keep_scanning = False if name.lower().endswith(' italic'): name = name[:-len(' italic')] keep_scanning = True elif name.lower().endswith(' bold'): name = name[:-len(' bold')] keep_scanning = True elif name.lower().endswith(' black'): name = name[:-len(' black')] style_name = 'Black' res = QFont(name) res.setWeight(font.weight) if font.weight > 400: res.setBold(True) if font.italic: res.setItalic(True) # pretty annoying, but because qgis relies on style strings, we need to convert the raw bools to style names if possible... if res.italic() and not res.bold(): styles = QFontDatabase().styles(res.family()) for s in styles: if s.lower() in ['oblique', 'italic']: res.setStyleName(s) break elif res.italic() and res.bold(): styles = QFontDatabase().styles(res.family()) for s in styles: if ('oblique' in s.lower() or 'italic' in s.lower()) and 'bold' in s.lower(): res.setStyleName(s) break elif res.bold(): styles = QFontDatabase().styles(res.family()) for s in styles: if s.lower() == 'bold': res.setStyleName(s) break if style_name is not None and style_name in QFontDatabase().styles( res.family()): res.setStyleName(style_name) if font.underline: res.setUnderline(True) if font.strikethrough: res.setStrikeOut(True) res.setPointSizeF(font.size) return res