示例#1
0
    def data(self, index, role):
        ''' PyQt API Method -- See the PyQt documentation for a description '''
        if not index.isValid():
            return QVariant()

        node = index.internalPointer().node

        # Foreground Coloring
        if role == Qt.ForegroundRole:
            if node.get('inherited'):
                return QVariant(QColor(Qt.darkBlue))
            return QVariant()  # = default color

        # Display
        elif role == Qt.DisplayRole:
            if index.column() == 0:
                if node.get('type') == 'selectable':
                    return QVariant(
                        node.get('return_value') or node.get('name')
                        or node.tag)
                return QVariant(node.get('name') or node.tag)
            elif index.column() == 1:
                if node.get('type') == "password":
                    return QVariant(QString("*********"))
                # hide the text value for checkable nodes
                elif node.tag == 'selectable' or node.get('type') == 'boolean':
                    return QVariant()
                elif node.text:
                    return QVariant(node.text.strip())
                return QVariant()
        elif role == Qt.ToolTipRole:
            if index.column(
            ) == 0 and self.project:  # don't need to worry about inheritance when there is no project
                if node.get('inherited'):
                    return QVariant('Inherited value from file: %s' %
                                    node.get('inherited'))
                elif self.project.is_shadowing(node):
                    prototype_node = self.project.get_prototype_node(node)
                    return QVariant('Original value defined in file: %s' %
                                    prototype_node.get('inherited'))
                else:
                    return QVariant('Value is defined in this file.')

#        elif role == Qt.FontRole:
#            if index.column() == 0:
#                if node.tag == 'model':
#                    font = QFont()
#                    font.setPointSize(14)
#                    return QVariant(font)

# CK: Experimenting with making shadowing nodes bold to differentiate them from local nodes
#        elif role == Qt.FontRole:
#            f = QFont()
#            if self.project is not None:
#                f.setBold(self.project.is_shadowing(node))
#            return QVariant(f)

# Icons
        elif role == Qt.DecorationRole:
            if index.column() == 0:
                return QVariant(IconLibrary.icon_for_type(node.tag))

        # Checkboxes
        elif role == Qt.CheckStateRole and index.column() == 1:
            if node.tag == 'selectable' or node.get('type') == 'boolean':
                return QVariant(Qt.Checked if (
                    node.text.strip() == 'True') else Qt.Unchecked)

        # Unhandled index/role
        return QVariant()
示例#2
0
    def data(self, index, role):
        ''' PyQt API Method -- See the PyQt documentation for a description '''
        if not index.isValid():
            return QVariant()

        node = index.internalPointer().node

        # Foreground Coloring
        if role == Qt.ForegroundRole:
            if node.get('inherited'):
                return QVariant(QColor(Qt.darkBlue))
            return QVariant() # = default color

        # Display
        elif role == Qt.DisplayRole:
            if index.column() == 0:
                if node.get('type') == 'selectable':
                    return QVariant(node.get('return_value') or node.get('name') or node.tag)
                return QVariant(node.get('name') or node.tag)
            elif index.column() == 1:
                if node.get('type') == "password":
                    return QVariant(QString("*********"))
                # hide the text value for checkable nodes
                elif node.tag == 'selectable' or node.get('type') == 'boolean':
                    return QVariant()
                elif node.text:
                    return QVariant(node.text.strip())
                return QVariant()
        elif role == Qt.ToolTipRole:
            if index.column() == 0 and self.project: # don't need to worry about inheritance when there is no project
                if node.get('inherited'):
                    return QVariant('Inherited value from file: %s' % node.get('inherited'))
                elif self.project.is_shadowing(node):
                    prototype_node = self.project.get_prototype_node(node)
                    return QVariant('Original value defined in file: %s' % prototype_node.get('inherited'))
                else:
                    return QVariant('Value is defined in this file.')

#        elif role == Qt.FontRole:
#            if index.column() == 0:
#                if node.tag == 'model':
#                    font = QFont()
#                    font.setPointSize(14)
#                    return QVariant(font)

# CK: Experimenting with making shadowing nodes bold to differentiate them from local nodes
#        elif role == Qt.FontRole:
#            f = QFont()
#            if self.project is not None:
#                f.setBold(self.project.is_shadowing(node))
#            return QVariant(f)

        # Icons
        elif role == Qt.DecorationRole:
            if index.column() == 0:
                return QVariant(IconLibrary.icon_for_type(node.tag))

        # Checkboxes
        elif role == Qt.CheckStateRole and index.column() == 1:
            if node.tag == 'selectable' or node.get('type') == 'boolean':
                return QVariant(Qt.Checked if (node.text.strip() == 'True') else Qt.Unchecked)

        # Unhandled index/role
        return QVariant()
示例#3
0
    def data(self, index, role):
        ''' PyQt API Method -- See the PyQt documentation for a description '''
        if not index.isValid():
            return QVariant()

        item = index.internalPointer()
        node = item.node

        # Foreground Coloring
        if role == Qt.ForegroundRole:
            if node.get('inherited') or (is_comment(node) and node.getparent().get('inherited')):
                return QVariant(QColor(Qt.darkBlue))
            return QVariant() # = default color

        # Font
        elif role == Qt.FontRole:
            if item.hidden:
                font = QFont()
                font.setItalic(True)
                return QVariant(font)
            return QVariant() # = default

        # Display
        elif role == Qt.DisplayRole:
            if index.column() == 0:
                return QVariant(self._get_node_name(node))
            elif index.column() == 1:
                return QVariant(self._get_node_text(node))
        elif role == Qt.ToolTipRole:
            # don't need to worry about inheritance when there is no project
            if not self.project:
                return QVariant()
            
            if index.column() == 0:
                value = self._get_node_text(node)
                if value:
                    value = 'Value: %s\n' % value
                else:
                    value_list = self._get_item_children_text_list(item, 5)
                    if value_list:
                        value = '\n    '.join([''] + value_list)
                        value = 'Children:%s\n' % value
                
                inheritance = ''
                if node.get('inherited'):
                    inheritance = 'Inherited value from file: %s' % node.get('inherited')
                elif self.project.is_shadowing(node):
                    prototype_node = self.project.get_prototype_node(node)
                    shadowing_value = self._get_node_text(prototype_node)
                    if shadowing_value:
                        inheritance += 'Shadowing value: %s\n' % shadowing_value
                    inheritance += 'Original value defined in file: %s' % prototype_node.get('inherited')
                else:
                    inheritance = 'Value is defined in this file.'
                text = 'Name: %s\n%s%s' % (self._get_node_name(node), value, inheritance)
                return QVariant(text)
            elif index.column() == 1:
                return QVariant(self._get_node_text(node))

#        elif role == Qt.FontRole:
#            if index.column() == 0:
#                if node.tag == 'model':
#                    font = QFont()
#                    font.setPointSize(14)
#                    return QVariant(font)

# CK: Experimenting with making shadowing nodes bold to differentiate them from local nodes
#        elif role == Qt.FontRole:
#            f = QFont()
#            if self.project is not None:
#                f.setBold(self.project.is_shadowing(node))
#            return QVariant(f)

        # Icons
        elif role == Qt.DecorationRole:
            if index.column() == 0 and is_no_comment(node):
                return QVariant(IconLibrary.icon_for_type(node.tag))

        # Checkboxes
        elif role == Qt.CheckStateRole and index.column() == 1:
            if node.tag == 'selectable' or node.get('type') == 'boolean':
                return QVariant(Qt.Checked if (node.text.strip() == 'True') else Qt.Unchecked)

        # Unhandled index/role
        return QVariant()
示例#4
0
    def data(self, index, role):
        ''' PyQt API Method -- See the PyQt documentation for a description '''
        if not index.isValid():
            return QVariant()

        item = index.internalPointer()
        node = item.node

        # Foreground Coloring
        if role == Qt.ForegroundRole:
            if node.get('inherited') or (is_comment(node) and
                                         node.getparent().get('inherited')):
                return QVariant(QColor(Qt.darkBlue))
            return QVariant()  # = default color

        # Font
        elif role == Qt.FontRole:
            if item.hidden:
                font = QFont()
                font.setItalic(True)
                return QVariant(font)
            return QVariant()  # = default

        # Display
        elif role == Qt.DisplayRole:
            if index.column() == 0:
                return QVariant(self._get_node_name(node))
            elif index.column() == 1:
                return QVariant(self._get_node_text(node))
        elif role == Qt.ToolTipRole:
            # don't need to worry about inheritance when there is no project
            if not self.project:
                return QVariant()

            if index.column() == 0:
                value = self._get_node_text(node)
                if value:
                    value = 'Value: %s\n' % value
                else:
                    value_list = self._get_item_children_text_list(item, 5)
                    if value_list:
                        value = '\n    '.join([''] + value_list)
                        value = 'Children:%s\n' % value

                inheritance = ''
                if node.get('inherited'):
                    inheritance = 'Inherited value from file: %s' % node.get(
                        'inherited')
                elif self.project.is_shadowing(node):
                    prototype_node = self.project.get_prototype_node(node)
                    shadowing_value = self._get_node_text(prototype_node)
                    if shadowing_value:
                        inheritance += 'Shadowing value: %s\n' % shadowing_value
                    inheritance += 'Original value defined in file: %s' % prototype_node.get(
                        'inherited')
                else:
                    inheritance = 'Value is defined in this file.'
                text = 'Name: %s\n%s%s' % (self._get_node_name(node), value,
                                           inheritance)
                return QVariant(text)
            elif index.column() == 1:
                return QVariant(self._get_node_text(node))

#        elif role == Qt.FontRole:
#            if index.column() == 0:
#                if node.tag == 'model':
#                    font = QFont()
#                    font.setPointSize(14)
#                    return QVariant(font)

# CK: Experimenting with making shadowing nodes bold to differentiate them from local nodes
#        elif role == Qt.FontRole:
#            f = QFont()
#            if self.project is not None:
#                f.setBold(self.project.is_shadowing(node))
#            return QVariant(f)

# Icons
        elif role == Qt.DecorationRole:
            if index.column() == 0 and is_no_comment(node):
                return QVariant(IconLibrary.icon_for_type(node.tag))

        # Checkboxes
        elif role == Qt.CheckStateRole and index.column() == 1:
            if node.tag == 'selectable' or node.get('type') == 'boolean':
                return QVariant(Qt.Checked if (
                    node.text.strip() == 'True') else Qt.Unchecked)

        # Unhandled index/role
        return QVariant()