1 from builtins
import range
15 return str(self.text()).lower()<
str(other.text()).lower()
18 """ The TableView widget fills itself using a DataAccessor. 25 logging.debug(__name__ +
": __init__")
26 AbstractView.__init__(self)
27 QTableWidget.__init__(self, parent)
39 self.setSortingEnabled(
False)
40 self.verticalHeader().hide()
41 self.setSelectionMode(QTableWidget.SingleSelection)
42 self.setSelectionBehavior(QAbstractItemView.SelectRows)
43 self.setSizePolicy(QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding))
51 """ Set a list of columns that shall be shown. 56 """ Sets the DataAccessor from which the nodes are created. 58 You need to call updateContent() in order to make the changes visible. 60 if not isinstance(accessor, BasicDataAccessor):
61 raise TypeError(__name__ +
" requires data accessor of type BasicDataAccessor.")
62 AbstractView.setDataAccessor(self, accessor)
65 """ Stop all running operations. 70 """ Deletes all items in the TableView 73 QTableWidget.clear(self)
75 self.setSortingEnabled(
False)
79 """ Clear the TableView and refill it. 81 logging.debug(__name__ +
": updateContent")
93 for object
in objects:
95 while thread.isRunning():
96 if not Application.NO_PROCESS_EVENTS:
97 QCoreApplication.instance().processEvents()
101 properties+=[thread.returnValue()]
107 for ps
in properties:
109 if not property[1]
in ranking.keys():
110 ranking[property[1]]=1
111 if property[0]!=
"Category":
113 elif property[1]==
"Label":
114 ranking[property[1]]+=100000
115 elif property[1]==
"Name":
116 ranking[property[1]]+=10000
118 ranking[property[1]]+=1
119 self._columns.sort(
lambda x,y:
cmp(-ranking[x],-ranking[y]))
120 self.setColumnCount(len(self.
_columns))
121 self.setHorizontalHeaderLabels(self.
_columns)
123 for object
in objects:
128 if not Application.NO_PROCESS_EVENTS:
129 QCoreApplication.instance().processEvents()
137 self.resizeColumnToContents(i)
143 """ Create item for an object. 146 self.setRowCount(self.rowCount()+1)
147 height=Property.DEFAULT_HEIGHT
148 firstColumnDone=
False 149 for property
in properties:
150 if property!=
None and property[1]
in self.
_columns:
151 i=self._columns.index(property[1])
152 if property[0]
in [
"MultilineString",
"Double"]:
153 propertyWidget=PropertyView.propertyWidgetFromProperty(property)
154 if propertyWidget.properyHeight()>height:
155 height=propertyWidget.properyHeight()
156 text=
str(propertyWidget.value())
158 text=
str(property[2])
160 item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
162 self.setItem(row,i,item)
165 if not firstColumnDone:
166 item=QTableWidgetItem(
"")
167 item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
170 self.verticalHeader().resizeSection(row,height)
173 """ Emits signal selected that the TabController can connect to. 175 logging.debug(__name__ +
": itemSelectionChanged")
178 if self.item(self.currentRow(),self.
_firstColumn)!=
None:
179 self.emit(SIGNAL(
"selected"), self.item(self.currentRow(),self.
_firstColumn).object)
181 self.emit(SIGNAL(
"selected"),
None)
184 """ Mark an object in the TableView as selected. 185 Remember position an name of object in order to restore the selection. 187 logging.debug(__name__ +
": select")
189 for i
in range(self.rowCount()):
197 self.setCurrentItem(item)
201 """ Return the row containing the selected object. 202 First search for object by name. If it is not found use position. 204 for i
in range(self.rowCount()):
209 if self.rowCount()>0:
215 """ Restore selection. 217 logging.debug(__name__ +
": restoreSelection")
221 self.setCurrentCell(select,0)
225 """ Return currently selected object. 227 If selection unknown return first object. 240 QTableWidget.mousePressEvent(self,event)
241 if event.button()==Qt.RightButton:
242 self.emit(SIGNAL(
"mouseRightPressed"), event.globalPos())
def mousePressEvent(self, event)
def setDataAccessor(self, accessor)
def setColumns(self, columns)
def restoreSelection(self)
def setSorting(self, sort)
def allDataObjectChildren(self, objects=None)
def itemSelectionChanged(self)
def _createItem(self, object, properties)
def __init__(self, parent=None)