Python PySide.QtCore.QModelIndex() Examples

The following are 27 code examples of PySide.QtCore.QModelIndex(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module PySide.QtCore , or try the search function .
Example #1
Source File: abstractModel.py    From public with GNU General Public License v2.0 6 votes vote down vote up
def removeRows(self, position, rows, parent=None):
        '''
        Remove rows from the model

        :param int position: position to start adding
        :param int rows: number of rows to remove
        :param QModelIndex parent: parent to remove from
        :returns: Success
        :rtype: bool
        '''
        if parent is None:
            parent = QtCore.QModelIndex()

        parentNode = self.getItem(parent)
        self.beginRemoveRows(parent, position, position + rows - 1)

        for row in xrange(rows):
            success = parentNode.removeChild(position)

        self.endRemoveRows()

        return success 
Example #2
Source File: abstractModel.py    From public with GNU General Public License v2.0 6 votes vote down vote up
def insertRows(self, items, position=None, parent=None):
        '''
        Add new rows to the model

        :param list items: items to add
        :param int position: position to start adding
        :param parent: parent to add to
        :type parent: QModelIndex or AbstractBaseMixin or None
        :returns: Success
        :rtype: bool
        '''
        parentNode, position = self.beginInsertion(len(items), position, parent)
        success = True
        for item in items:
            success *= parentNode.insertChild(position, item)
            position += 1

        self.endInsertRows()
        return bool(success) 
Example #3
Source File: abstractModel.py    From public with GNU General Public License v2.0 6 votes vote down vote up
def beginInsertion(self, rows, position, parent):
        '''
        Internal utility to help inserting from multiple calls

        :param int rows: number of rows to add
        :param int position: position to start adding
        :param parent: parent to add to
        :type parent: QModelIndex or AbstractBaseMixin or None
        :returns: tuple(parentNode, position)
        :rtype: tuple
        '''
        if isinstance(parent, QtCore.QModelIndex):
            parentNode = self.getItem(parent)

        if parent is None:
            parent = QtCore.QModelIndex()
            parentNode = self.__root

        if position is None:
            position = parentNode.childCount()

        position = parentNode.childCount() if position is None else position

        self.beginInsertRows(parent, position, int(position) + rows - 1)
        return (parentNode, position) 
Example #4
Source File: casc_plugin.py    From CASC with GNU General Public License v2.0 6 votes vote down vote up
def add_sub_signature(self, sub_sig_data, notes, index=None):
        element =  (sub_sig_data.get_save_data_tuple(), notes)
        if None == index:
            index = self.next_index
            self.next_index += 1

        pos = bisect.bisect(self.sub_signatures.keys(), index)
        if index not in self.sub_signatures:
            #   Add a new element
            self.beginInsertRows(QtCore.QModelIndex(), pos, pos)
            self.sub_signatures[index] = element
            sorted_data = sorted(self.sub_signatures.iteritems(), key=lambda x: x[0])
            self.sub_signatures = collections.OrderedDict(sorted_data)
            self.endInsertRows()

        else:
            #   Modify existing element
            self.sub_signatures[index] = element

        #   Add to IDB
        self.__set_array(element[0], notes, index)
        self.sub_signatures[index] = (element[0], notes)
        self.index_lookup_table.append(index) 
Example #5
Source File: abstractModel.py    From public with GNU General Public License v2.0 6 votes vote down vote up
def flags(self, index):
        '''
        Return the flags an index, if force flags is not set it will use
        the items own flags if it has them
        If index is None, it will return the model flags

        :param QModelIndex index: index to query
        :returns: flags
        :rtype: ItemFlags
        '''
        if index is None or self.__forceFlags:
            return self.__flags

        if not index.isValid():
            return self.__flags

        item = index.internalPointer()
        if item.hasCustomFlags:
            return item.flags()

        return self.__flags 
Example #6
Source File: treeview.py    From LCInterlocking with GNU Lesser General Public License v2.1 5 votes vote down vote up
def parent(self, index):
        if not index.isValid():
            return QtCore.QModelIndex()

        child_item = index.internalPointer()
        parent_item = child_item.parent()

        if parent_item == self.rootItem:
            return QtCore.QModelIndex()

        return self.createIndex(parent_item.row(), 0, parent_item) 
Example #7
Source File: qtpandas.py    From Computable with MIT License 5 votes vote down vote up
def rowCount(self, index=QModelIndex()):
        return self.df.shape[0] 
Example #8
Source File: treeview.py    From LCInterlocking with GNU Lesser General Public License v2.1 5 votes vote down vote up
def index(self, row, column, parent):
        if not self.hasIndex(row, column, parent):
            return QtCore.QModelIndex()

        if not parent.isValid():
            parent_item = self.rootItem
        else:
            parent_item = parent.internalPointer()

        child_item = parent_item.child(row)
        if child_item:
            return self.createIndex(row, column, child_item)
        else:
            return QtCore.QModelIndex() 
Example #9
Source File: treeview.py    From LCInterlocking with GNU Lesser General Public License v2.1 5 votes vote down vote up
def append_part(self, name, label, is_link=False):
        row = self.rootItem.child_count() - 1
        self.beginInsertRows(QtCore.QModelIndex(), row, row)
        part_type = TreeItem.PART_LINK if is_link else TreeItem.PART
        self.rootItem.append_child(TreeItem(part_type, [name, label], self.rootItem))
        self.endInsertRows()
        self.dataChanged.emit(QtCore.QModelIndex(), QtCore.QModelIndex())
        return self.index(self.rootItem.child_count()-1, 0, QtCore.QModelIndex()) 
Example #10
Source File: abstractModel.py    From public with GNU General Public License v2.0 5 votes vote down vote up
def selectedIndex(self):
        '''
        Return the selected index

        :returns: selected index
        :rtype: QModelIndex
        '''
        return self.view.selectionModel().currentIndex() 
Example #11
Source File: abstractModel.py    From public with GNU General Public License v2.0 5 votes vote down vote up
def createChild(self, parentItem=None):
        '''
        Create a new child under the parent item
        simply calls parent.createChild() while maintaining the model

        :param parentItem: item to add to
        :type parentItem: QModelIndex or AbstractBaseMixin or None
        :returns: New child
        :rtype: object
        '''
        rootNode, _ = self.beginInsertion(1, None, parentItem)
        parent = parentItem or rootNode
        item = parent.createChild()
        self.endInsertRows()
        return item 
Example #12
Source File: abstractModel.py    From public with GNU General Public License v2.0 5 votes vote down vote up
def getItem(self, index):
        '''
        Return the internal item at the index

        :param QModelIndex index: index to query
        :returns: Item object
        :rtype: object
        '''
        if index.isValid():
            item = index.internalPointer()
            if item:
                return item

        return self.__root 
Example #13
Source File: abstractModel.py    From public with GNU General Public License v2.0 5 votes vote down vote up
def parent(self, index):
        item = self.getItem(index)
        parentItem = item.getParent()

        if not parentItem or parentItem == self.__root:
            return QtCore.QModelIndex()

        return self.createIndex(parentItem.row(), 0, parentItem) 
Example #14
Source File: abstractModel.py    From public with GNU General Public License v2.0 5 votes vote down vote up
def columnCount(self, parent):
        '''
        Return number of columns for the item

        :param QModelIndex parent: index to query
        :returns: number of columns
        :rtype: int
        '''
        return len(self.__headers) 
Example #15
Source File: abstractModel.py    From public with GNU General Public License v2.0 5 votes vote down vote up
def rowCount(self, parent):
        '''
        Return number of rows for the item

        :param QModelIndex parent: index to query
        :returns: number of rows
        :rtype: int
        '''
        if parent.isValid():
            item = parent.internalPointer()

        else:
            item = self.__root

        return item.childCount() 
Example #16
Source File: abstractModel.py    From public with GNU General Public License v2.0 5 votes vote down vote up
def getCustomRole(self, model, index, role):
        '''
        Return data for a custom Qt Role

        :param QAbstractItemModel model: Active model
        :param QModelIndex index: Active index
        :param QRole role: Active role
        '''
        return None 
Example #17
Source File: casc_plugin.py    From CASC with GNU General Public License v2.0 5 votes vote down vote up
def columnCount(self, index=QtCore.QModelIndex()):
        return 4 
Example #18
Source File: casc_plugin.py    From CASC with GNU General Public License v2.0 5 votes vote down vote up
def rowCount(self, index=QtCore.QModelIndex()):
        return len(self.sub_signatures) 
Example #19
Source File: stringswindow.py    From MARA_Framework with GNU Lesser General Public License v3.0 5 votes vote down vote up
def __init__(self, parent=None, win=None, session=None):
        super(StringsValueWindow, self).__init__(parent)
        self.mainwin = win
        self.session = session
        self.title = "Strings"

        self.reverse_strings = {}

        self.proxyModel = QtGui.QSortFilterProxyModel()
        self.proxyModel.setDynamicSortFilter(True)

        self.model = QtGui.QStandardItemModel(self.session.get_nb_strings(), 4, self)

        self.model.setHeaderData(0, QtCore.Qt.Horizontal, "String")
        self.model.setHeaderData(1, QtCore.Qt.Horizontal, "Usage")
        self.model.setHeaderData(2, QtCore.Qt.Horizontal, "Filename")
        self.model.setHeaderData(3, QtCore.Qt.Horizontal, "Digest")

        row = 0
        for digest, filename, strings_analysis in self.session.get_strings():
            for string_value in strings_analysis:
                self.model.setData(self.model.index(row, 0, QtCore.QModelIndex()), repr(string_value))
                self.model.setData(self.model.index(row, 1, QtCore.QModelIndex()), len(strings_analysis[string_value].get_xref_from()))
                self.model.setData(self.model.index(row, 2, QtCore.QModelIndex()), filename)
                self.model.setData(self.model.index(row, 3, QtCore.QModelIndex()), digest)
                self.reverse_strings[repr(string_value) + digest] = strings_analysis[string_value]
                row += 1

        self.proxyModel.setSourceModel(self.model)


        self.setRootIsDecorated(False)
        self.setAlternatingRowColors(True)
        self.setModel(self.proxyModel)
        self.setSortingEnabled(True)
        self.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)

        self.doubleClicked.connect(self.slotDoubleClicked) 
Example #20
Source File: xrefwindow.py    From MARA_Framework with GNU Lesser General Public License v3.0 5 votes vote down vote up
def __init__(self, parent=None, win=None, xrefs=None, headers=None):
        super(XrefValueWindow, self).__init__(parent)
        self.parent = parent
        self.mainwin = win
        self.xrefs = xrefs
        self.headers = headers

        self.reverse_strings = {}

        self.proxyModel = QtGui.QSortFilterProxyModel()
        self.proxyModel.setDynamicSortFilter(True)

        self.model = QtGui.QStandardItemModel(len(self.xrefs), len(self.headers), self)

        column = 0
        for header in headers:
            self.model.setHeaderData(column, QtCore.Qt.Horizontal, header)
            column += 1

        row = 0
        for ref in xrefs:
            for column in range(len(self.headers)):
                self.model.setData(self.model.index(row, column, QtCore.QModelIndex()), "%s" % ref[column])
            row += 1

        self.proxyModel.setSourceModel(self.model)

        self.setRootIsDecorated(False)
        self.setAlternatingRowColors(True)
        self.setModel(self.proxyModel)
        self.setSortingEnabled(True)
        self.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)

        self.doubleClicked.connect(self.slotDoubleClicked) 
Example #21
Source File: CanvasRbfEditor.py    From Fabric-RBF with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def doneEditing(self):
        # This block signals needs to happen first otherwise I have lose focus
        # problems again when there are no rows
        self.line.blockSignals(True)
        self.line.setHidden(True)
        newname = str(self.line.text())
        self.model().setHeaderData(self.sectionedit, Qt.Orientation.Vertical, newname)
        self.line.setText('')
        self.setCurrentIndex(QtCore.QModelIndex()) 
Example #22
Source File: stringswindow.py    From AndroBugs_Framework with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, parent=None, win=None, session=None):
        super(StringsValueWindow, self).__init__(parent)
        self.mainwin = win
        self.session = session
        self.title = "Strings"

        self.reverse_strings = {}

        self.proxyModel = QtGui.QSortFilterProxyModel()
        self.proxyModel.setDynamicSortFilter(True)

        self.model = QtGui.QStandardItemModel(self.session.get_nb_strings(), 4, self)

        self.model.setHeaderData(0, QtCore.Qt.Horizontal, "String")
        self.model.setHeaderData(1, QtCore.Qt.Horizontal, "Usage")
        self.model.setHeaderData(2, QtCore.Qt.Horizontal, "Filename")
        self.model.setHeaderData(3, QtCore.Qt.Horizontal, "Digest")

        row = 0
        for digest, filename, strings_analysis in self.session.get_strings():
            for string_value in strings_analysis:
                self.model.setData(self.model.index(row, 0, QtCore.QModelIndex()), repr(string_value))
                self.model.setData(self.model.index(row, 1, QtCore.QModelIndex()), len(strings_analysis[string_value].get_xref_from()))
                self.model.setData(self.model.index(row, 2, QtCore.QModelIndex()), filename)
                self.model.setData(self.model.index(row, 3, QtCore.QModelIndex()), digest)
                self.reverse_strings[repr(string_value) + digest] = strings_analysis[string_value]
                row += 1

        self.proxyModel.setSourceModel(self.model)


        self.setRootIsDecorated(False)
        self.setAlternatingRowColors(True)
        self.setModel(self.proxyModel)
        self.setSortingEnabled(True)
        self.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)

        self.doubleClicked.connect(self.slotDoubleClicked) 
Example #23
Source File: xrefwindow.py    From AndroBugs_Framework with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, parent=None, win=None, xrefs=None, headers=None):
        super(XrefValueWindow, self).__init__(parent)
        self.parent = parent
        self.mainwin = win
        self.xrefs = xrefs
        self.headers = headers

        self.reverse_strings = {}

        self.proxyModel = QtGui.QSortFilterProxyModel()
        self.proxyModel.setDynamicSortFilter(True)

        self.model = QtGui.QStandardItemModel(len(self.xrefs), len(self.headers), self)

        column = 0
        for header in headers:
            self.model.setHeaderData(column, QtCore.Qt.Horizontal, header)
            column += 1

        row = 0
        for ref in xrefs:
            for column in range(len(self.headers)):
                self.model.setData(self.model.index(row, column, QtCore.QModelIndex()), "%s" % ref[column])
            row += 1

        self.proxyModel.setSourceModel(self.model)

        self.setRootIsDecorated(False)
        self.setAlternatingRowColors(True)
        self.setModel(self.proxyModel)
        self.setSortingEnabled(True)
        self.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)

        self.doubleClicked.connect(self.slotDoubleClicked) 
Example #24
Source File: stringswindow.py    From TimeMachine with GNU Lesser General Public License v3.0 5 votes vote down vote up
def __init__(self, parent=None, win=None, session=None):
        super(StringsValueWindow, self).__init__(parent)
        self.mainwin = win
        self.session = session
        self.title = "Strings"

        self.reverse_strings = {}

        self.proxyModel = QtGui.QSortFilterProxyModel()
        self.proxyModel.setDynamicSortFilter(True)

        self.model = QtGui.QStandardItemModel(self.session.get_nb_strings(), 4, self)

        self.model.setHeaderData(0, QtCore.Qt.Horizontal, "String")
        self.model.setHeaderData(1, QtCore.Qt.Horizontal, "Usage")
        self.model.setHeaderData(2, QtCore.Qt.Horizontal, "Filename")
        self.model.setHeaderData(3, QtCore.Qt.Horizontal, "Digest")

        row = 0
        for digest, filename, strings_analysis in self.session.get_strings():
            for string_value in strings_analysis:
                self.model.setData(self.model.index(row, 0, QtCore.QModelIndex()), repr(string_value))
                self.model.setData(self.model.index(row, 1, QtCore.QModelIndex()), len(strings_analysis[string_value].get_xref_from()))
                self.model.setData(self.model.index(row, 2, QtCore.QModelIndex()), filename)
                self.model.setData(self.model.index(row, 3, QtCore.QModelIndex()), digest)
                self.reverse_strings[repr(string_value) + digest] = strings_analysis[string_value]
                row += 1

        self.proxyModel.setSourceModel(self.model)


        self.setRootIsDecorated(False)
        self.setAlternatingRowColors(True)
        self.setModel(self.proxyModel)
        self.setSortingEnabled(True)
        self.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)

        self.doubleClicked.connect(self.slotDoubleClicked) 
Example #25
Source File: xrefwindow.py    From TimeMachine with GNU Lesser General Public License v3.0 5 votes vote down vote up
def __init__(self, parent=None, win=None, xrefs=None, headers=None):
        super(XrefValueWindow, self).__init__(parent)
        self.parent = parent
        self.mainwin = win
        self.xrefs = xrefs
        self.headers = headers

        self.reverse_strings = {}

        self.proxyModel = QtGui.QSortFilterProxyModel()
        self.proxyModel.setDynamicSortFilter(True)

        self.model = QtGui.QStandardItemModel(len(self.xrefs), len(self.headers), self)

        column = 0
        for header in headers:
            self.model.setHeaderData(column, QtCore.Qt.Horizontal, header)
            column += 1

        row = 0
        for ref in xrefs:
            for column in range(len(self.headers)):
                self.model.setData(self.model.index(row, column, QtCore.QModelIndex()), "%s" % ref[column])
            row += 1

        self.proxyModel.setSourceModel(self.model)

        self.setRootIsDecorated(False)
        self.setAlternatingRowColors(True)
        self.setModel(self.proxyModel)
        self.setSortingEnabled(True)
        self.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)

        self.doubleClicked.connect(self.slotDoubleClicked) 
Example #26
Source File: qtpandas.py    From Computable with MIT License 5 votes vote down vote up
def columnCount(self, index=QModelIndex()):
        return self.df.shape[1] 
Example #27
Source File: PacketTableModel.py    From CANalyzat0r with GNU General Public License v3.0 4 votes vote down vote up
def appendRows(self, rowList, addAtFront=False, resolveDescriptions=True):
        """
        This allows appending a whole set of rows at once using the best possible speed

        :param rowList: List of raw data lists to append
        :param addAtFront: Values will be added to the front of ``self.dataList`` if this is True.
                           Else: They will be appended at the end
        :param resolveDescriptions: If this is set to true, the description for every packet will be resolved.
                                    Default: True

        :return: If ``resolveDescriptions`` is True, a list of known packet descriptions will be returned. If no
                 description for a particular packet can be resolved, an empty string will be inserted in the list
                 to keep indexes. Else None will be returned
        """

        self.emit(
            QtCore.SIGNAL("beginInsertRows()"), QtCore.QModelIndex(),
            self.rowCount(),
            self.rowCount() + len(rowList))
        descriptions = []

        for rowIdx in range(len(rowList)):
            # Only notify the layout after every X rows
            doEmit = rowIdx < 10 or rowIdx % 10000 == 0

            if doEmit:
                QtCore.QCoreApplication.processEvents()

            while len(rowList[rowIdx]) < self.columnCount():
                rowList[rowIdx].append("")

            if resolveDescriptions:
                descriptions.append(
                    self.appendRow(
                        rowList[rowIdx],
                        addAtFront,
                        emit=doEmit,
                        resolveDescription=True))
            else:
                self.appendRow(rowList[rowIdx], addAtFront, emit=doEmit)

            if doEmit:
                QtCore.QCoreApplication.processEvents()

        self.emit(QtCore.SIGNAL("endInsertRows()"))
        self.emit(QtCore.SIGNAL("layoutChanged()"))

        if resolveDescriptions:
            return descriptions

        else:
            return None