def __init__(self, parent=None):
self.setDynamicSortFilter(True)
self.setFilterKeyColumn(-1)
def __getattr__(self, name): # the existing "navModel" includes a couple functions
return getattr(self.sourceModel(), name)
'''
This is the primary window for the VQViv*Views if they want to include filtering
'''
window_title = '__undefined__'
view_type = None
def __init__(self, vw, vwqgui, *args, **kwargs):
self.view = self.view_type(vw, vwqgui, *args, **kwargs)
self.ffilt = VQFilterWidget(self)
layout = vq_basics.VBox(self.view, self.ffilt)
self.setLayout(layout)
self.ffilt.filterChanged.connect(self.textFilterChanged)
self.setWindowTitle(self.view.window_title)
def textFilterChanged(self):
regExp
= QtCore.
QRegExp(self.
ffilt.
text(),
self.ffilt.caseSensitivity(),
self.ffilt.patternSyntax())
self.view.filterModel.setFilterRegExp(regExp)
'''
A QT tree model that uses the tree API from visgraph
to hold the data...
'''
columns = ( 'A first column!', 'The Second Column!')
editable = None
dragable = False
def __init__(self, parent=None, columns=None):
if columns != None:
self.columns = columns
self.rootnode = VQTreeItem((), None)
if self.editable == None:
self.editable = [False,] * len(self.columns)
def vqEdited(self, pnode, col, value):
return value
def append(self, rowdata, parent=None):
if parent == None:
parent = self.rootnode
pidx = self.createIndex(parent.row(), 0, parent)
i = len(parent.children)
self.beginInsertRows(pidx, i, i)
node = parent.append(rowdata)
self.endInsertRows()
self.layoutChanged.emit()
return node
...
def sort(self, colnum, order=0):
cmpf = VQTreeSorter(colnum, order)
self.layoutAboutToBeChanged.emit()
self.rootnode.children.sort(cmp=cmpf)
self.layoutChanged.emit()
def flags(self, index):
if not index.isValid():
return 0
col = index.column()
if self.editable[col]:
flags |= QtCore.Qt.ItemIsEditable
if self.dragable:
flags |= QtCore.Qt.ItemIsDragEnabled
return flags
def columnCount(self, parent=None):
return len(self.columns)
def data(self, index, role):
if not index.isValid():
return None
item = index.internalPointer()
if role == QtCore.Qt.DisplayRole:
return item.data(index.column())
if role == QtCore.Qt.UserRole:
return item
return None
def setData(self, index, value, role=QtCore.Qt.EditRole):
node = index.internalPointer()
if not node:
return False
# If this is the edit role, fire the vqEdited thing
if role == QtCore.Qt.EditRole:
value = self.vqEdited(node, index.column(), value)
if value == None:
return False
node.rowdata[index.column()] = value
self.dataChanged.emit(index, index)
return True
def headerData(self, column, orientation, role):
if ( orientation == QtCore.Qt.Horizontal and
role == QtCore.Qt.DisplayRole):
return self.columns[column]
return None
def index(self, row, column, parent):
if not self.hasIndex(row, column, parent):
pitem = parent.internalPointer()
if not pitem:
pitem = self.rootnode
item = pitem.child(row)
if not item:
return self.createIndex(row, column, item)
def parent(self, index):
if not index.isValid():
item = index.internalPointer()
if not item:
pitem = item.parent
if pitem == self.rootnode:
if pitem == None:
return self.createIndex(pitem.row(), 0, pitem)
...
class VivFilterModel(QSortFilterProxyModel):
def __init__(self, parent=None):
QSortFilterProxyModel.__init__(self, parent=parent)
self.setDynamicSortFilter(True)
self.setFilterKeyColumn(-1)
def __getattr__(self, name): # the existing "navModel" includes a couple functions
return getattr(self.sourceModel(), name)
class VivFilterView(QWidget):
'''
This is the primary window for the VQViv*Views if they want to include filtering
'''
window_title = '__undefined__'
view_type = None
def __init__(self, vw, vwqgui, *args, **kwargs):
QWidget.__init__(self)
self.view = self.view_type(vw, vwqgui, *args, **kwargs)
self.ffilt = VQFilterWidget(self)
layout = vq_basics.VBox(self.view, self.ffilt)
self.setLayout(layout)
self.ffilt.filterChanged.connect(self.textFilterChanged)
self.setWindowTitle(self.view.window_title)
def textFilterChanged(self):
regExp = QtCore.QRegExp(self.ffilt.text(),
self.ffilt.caseSensitivity(),
self.ffilt.patternSyntax())
self.view.filterModel.setFilterRegExp(regExp)
class VQTreeModel(QtCore.QAbstractItemModel):
'''
A QT tree model that uses the tree API from visgraph
to hold the data...
'''
columns = ( 'A first column!', 'The Second Column!')
editable = None
dragable = False
def __init__(self, parent=None, columns=None):
if columns != None:
self.columns = columns
QtCore.QAbstractItemModel.__init__(self, parent=parent)
self.rootnode = VQTreeItem((), None)
if self.editable == None:
self.editable = [False,] * len(self.columns)
def vqEdited(self, pnode, col, value):
return value
def append(self, rowdata, parent=None):
if parent == None:
parent = self.rootnode
pidx = self.createIndex(parent.row(), 0, parent)
i = len(parent.children)
self.beginInsertRows(pidx, i, i)
node = parent.append(rowdata)
self.endInsertRows()
self.layoutChanged.emit()
return node
...
def sort(self, colnum, order=0):
cmpf = VQTreeSorter(colnum, order)
self.layoutAboutToBeChanged.emit()
self.rootnode.children.sort(cmp=cmpf)
self.layoutChanged.emit()
def flags(self, index):
if not index.isValid():
return 0
flags = QtCore.QAbstractItemModel.flags(self, index)
col = index.column()
if self.editable[col]:
flags |= QtCore.Qt.ItemIsEditable
if self.dragable:
flags |= QtCore.Qt.ItemIsDragEnabled
return flags
def columnCount(self, parent=None):
return len(self.columns)
def data(self, index, role):
if not index.isValid():
return None
item = index.internalPointer()
if role == QtCore.Qt.DisplayRole:
return item.data(index.column())
if role == QtCore.Qt.UserRole:
return item
return None
def setData(self, index, value, role=QtCore.Qt.EditRole):
node = index.internalPointer()
if not node:
return False
# If this is the edit role, fire the vqEdited thing
if role == QtCore.Qt.EditRole:
value = self.vqEdited(node, index.column(), value)
if value == None:
return False
node.rowdata[index.column()] = value
self.dataChanged.emit(index, index)
return True
def headerData(self, column, orientation, role):
if ( orientation == QtCore.Qt.Horizontal and
role == QtCore.Qt.DisplayRole):
return self.columns[column]
return None
def index(self, row, column, parent):
if not self.hasIndex(row, column, parent):
return QtCore.QModelIndex()
pitem = parent.internalPointer()
if not pitem:
pitem = self.rootnode
item = pitem.child(row)
if not item:
return QtCore.QModelIndex()
return self.createIndex(row, column, item)
def parent(self, index):
if not index.isValid():
return QtCore.QModelIndex()
item = index.internalPointer()
if not item:
return QtCore.QModelIndex()
pitem = item.parent
if pitem == self.rootnode:
return QtCore.QModelIndex()
if pitem == None:
return QtCore.QModelIndex()
return self.createIndex(pitem.row(), 0, pitem)
...
To copy to clipboard, switch view to plain text mode
class VQVivFunctionsViewPart(VQVivTreeView):
_viv_navcol = 0
window_title = 'Functions'
columns = ('Name','Address', 'Size', 'Ref Count')
def __init__(self, vw, vwqgui):
VQVivTreeView.__init__(self, vw, vwqgui, withfilter=True)
self.navModel = VivNavModel(self._viv_navcol, self, columns=self.columns)
self.filterModel = VivFilterModel()
self.filterModel.setSourceModel(self.navModel)
self.setModel(self.filterModel)
self.vqLoad()
self.vqSizeColumns()
class VQVivFunctionsView(VivFilterView):
view_type = VQVivFunctionsViewPart
def __init__(self, parent=None, cols=None, **kwargs):
QTreeView.__init__
(self, parent
=parent,
**kwargs
) self.setSortingEnabled(True)
self.setAlternatingRowColors(True)
if cols != None:
model = VQTreeModel(parent=self, columns=cols)
self.setModel( model )
def vqSizeColumns(self):
c = self.model().columnCount()
for i in xrange(c):
self.resizeColumnToContents(i)
def setModel(self, model):
model.dataChanged.connect( self.dataChanged )
model.rowsInserted.connect( self.rowsInserted )
class EnviNavModel(vq_tree.VQTreeModel):
dragable = True
def __init__(self, navcol, parent=None, columns=None):
vq_tree.VQTreeModel.__init__(self, parent=parent, columns=columns)
self.navcol = navcol
def mimeData(self, idx):
pnode = idx[0].internalPointer()
expr = pnode.rowdata[self.navcol]
mdata.setData('envi/expression',str(expr))
return mdata
class VQVivFunctionsViewPart(VQVivTreeView):
_viv_navcol = 0
window_title = 'Functions'
columns = ('Name','Address', 'Size', 'Ref Count')
def __init__(self, vw, vwqgui):
VQVivTreeView.__init__(self, vw, vwqgui, withfilter=True)
self.navModel = VivNavModel(self._viv_navcol, self, columns=self.columns)
self.filterModel = VivFilterModel()
self.filterModel.setSourceModel(self.navModel)
self.setModel(self.filterModel)
self.vqLoad()
self.vqSizeColumns()
class VQVivFunctionsView(VivFilterView):
view_type = VQVivFunctionsViewPart
class VQTreeView(QTreeView):
def __init__(self, parent=None, cols=None, **kwargs):
QTreeView.__init__(self, parent=parent, **kwargs)
self.setSortingEnabled(True)
self.setAlternatingRowColors(True)
if cols != None:
model = VQTreeModel(parent=self, columns=cols)
self.setModel( model )
def vqSizeColumns(self):
c = self.model().columnCount()
for i in xrange(c):
self.resizeColumnToContents(i)
def setModel(self, model):
model.dataChanged.connect( self.dataChanged )
model.rowsInserted.connect( self.rowsInserted )
return QTreeView.setModel(self, model)
class EnviNavModel(vq_tree.VQTreeModel):
dragable = True
def __init__(self, navcol, parent=None, columns=None):
vq_tree.VQTreeModel.__init__(self, parent=parent, columns=columns)
self.navcol = navcol
def mimeData(self, idx):
pnode = idx[0].internalPointer()
expr = pnode.rowdata[self.navcol]
mdata = QtCore.QMimeData()
mdata.setData('envi/expression',str(expr))
return mdata
To copy to clipboard, switch view to plain text mode
Bookmarks