2009-06-01 09:55:11 +00:00
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2009-04-23
|
2011-04-12 08:04:01 +00:00
|
|
|
# Copyright 2011 Hardcoded Software (http://www.hardcoded.net)
|
2009-08-05 08:59:46 +00:00
|
|
|
#
|
2010-09-30 10:17:41 +00:00
|
|
|
# This software is licensed under the "BSD" License as described in the "LICENSE" file,
|
2009-08-05 08:59:46 +00:00
|
|
|
# which should be included with this package. The terms are also available at
|
2010-09-30 10:17:41 +00:00
|
|
|
# http://www.hardcoded.net/licenses/bsd_license
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2011-09-23 14:29:25 +00:00
|
|
|
from PyQt4.QtCore import SIGNAL, Qt, QSize
|
|
|
|
from PyQt4.QtGui import QBrush, QFont, QFontMetrics, QTableView, QColor
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2010-09-24 13:48:59 +00:00
|
|
|
from qtlib.table import Table
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2010-09-24 13:48:59 +00:00
|
|
|
from core.gui.result_table import ResultTable as ResultTableModel
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2010-09-24 13:48:59 +00:00
|
|
|
class ResultsModel(Table):
|
2010-02-12 14:39:29 +00:00
|
|
|
def __init__(self, app, view):
|
2011-09-20 19:06:29 +00:00
|
|
|
model = ResultTableModel(self, app.model)
|
2011-09-21 14:26:58 +00:00
|
|
|
self._app = app.model
|
|
|
|
self._delta_columns = app.model.DELTA_COLUMNS
|
2010-09-24 13:48:59 +00:00
|
|
|
Table.__init__(self, model, view)
|
2010-02-12 14:39:29 +00:00
|
|
|
self.model.connect()
|
2011-09-23 14:29:25 +00:00
|
|
|
|
|
|
|
app.prefsChanged.connect(self.appPrefsChanged)
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
def columnCount(self, parent):
|
2011-09-21 14:26:58 +00:00
|
|
|
return len(self._app.COLUMNS)
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
def data(self, index, role):
|
|
|
|
if not index.isValid():
|
2009-09-27 08:44:06 +00:00
|
|
|
return None
|
2010-09-24 13:48:59 +00:00
|
|
|
row = self.model[index.row()]
|
2009-06-01 09:55:11 +00:00
|
|
|
if role == Qt.DisplayRole:
|
2010-09-24 13:48:59 +00:00
|
|
|
data = row.data_delta if self.model.delta_values else row.data
|
2009-09-27 08:44:06 +00:00
|
|
|
return data[index.column()]
|
2009-06-01 09:55:11 +00:00
|
|
|
elif role == Qt.CheckStateRole:
|
2010-09-24 13:48:59 +00:00
|
|
|
if index.column() == 0 and row.markable:
|
|
|
|
return Qt.Checked if row.marked else Qt.Unchecked
|
2009-06-01 09:55:11 +00:00
|
|
|
elif role == Qt.ForegroundRole:
|
2010-09-24 13:48:59 +00:00
|
|
|
if row.isref:
|
2009-09-27 08:44:06 +00:00
|
|
|
return QBrush(Qt.blue)
|
2010-02-12 14:39:29 +00:00
|
|
|
elif self.model.delta_values and index.column() in self._delta_columns:
|
2009-09-27 08:44:06 +00:00
|
|
|
return QBrush(QColor(255, 142, 40)) # orange
|
2010-09-24 13:48:59 +00:00
|
|
|
elif role == Qt.FontRole:
|
|
|
|
isBold = row.isref
|
|
|
|
font = QFont(self.view.font())
|
|
|
|
font.setBold(isBold)
|
|
|
|
return font
|
2009-06-01 09:55:11 +00:00
|
|
|
elif role == Qt.EditRole:
|
|
|
|
if index.column() == 0:
|
2010-09-24 13:48:59 +00:00
|
|
|
return row.data[index.column()]
|
2009-09-27 08:44:06 +00:00
|
|
|
return None
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
def flags(self, index):
|
|
|
|
if not index.isValid():
|
|
|
|
return Qt.ItemIsEnabled
|
|
|
|
flags = Qt.ItemIsEnabled | Qt.ItemIsSelectable
|
|
|
|
if index.column() == 0:
|
2010-09-24 13:48:59 +00:00
|
|
|
flags |= Qt.ItemIsEditable
|
|
|
|
row = self.model[index.row()]
|
|
|
|
if row.markable:
|
|
|
|
flags |= Qt.ItemIsUserCheckable
|
2009-06-01 09:55:11 +00:00
|
|
|
return flags
|
|
|
|
|
|
|
|
def headerData(self, section, orientation, role):
|
2011-09-23 14:29:25 +00:00
|
|
|
if role == Qt.DisplayRole:
|
|
|
|
if orientation == Qt.Horizontal and section < len(self._app.COLUMNS):
|
|
|
|
return self._app.COLUMNS[section].display
|
2009-09-27 08:44:06 +00:00
|
|
|
return None
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
def setData(self, index, value, role):
|
|
|
|
if not index.isValid():
|
|
|
|
return False
|
2010-09-24 13:48:59 +00:00
|
|
|
row = self.model[index.row()]
|
2009-06-01 09:55:11 +00:00
|
|
|
if role == Qt.CheckStateRole:
|
|
|
|
if index.column() == 0:
|
2010-09-24 13:48:59 +00:00
|
|
|
self._app.mark_dupe(row._dupe, value.toBool())
|
2009-06-01 09:55:11 +00:00
|
|
|
return True
|
2010-09-24 13:48:59 +00:00
|
|
|
elif role == Qt.EditRole:
|
2009-06-01 09:55:11 +00:00
|
|
|
if index.column() == 0:
|
2010-08-11 14:39:06 +00:00
|
|
|
value = str(value.toString())
|
2010-02-12 14:39:29 +00:00
|
|
|
return self.model.rename_selected(value)
|
2009-06-01 09:55:11 +00:00
|
|
|
return False
|
|
|
|
|
|
|
|
def sort(self, column, order):
|
2010-02-12 14:39:29 +00:00
|
|
|
self.model.sort(column, order == Qt.AscendingOrder)
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
#--- Properties
|
|
|
|
@property
|
|
|
|
def power_marker(self):
|
2010-02-12 14:39:29 +00:00
|
|
|
return self.model.power_marker
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
@power_marker.setter
|
|
|
|
def power_marker(self, value):
|
2010-02-12 14:39:29 +00:00
|
|
|
self.model.power_marker = value
|
|
|
|
|
|
|
|
@property
|
|
|
|
def delta_values(self):
|
|
|
|
return self.model.delta_values
|
|
|
|
|
|
|
|
@delta_values.setter
|
|
|
|
def delta_values(self, value):
|
|
|
|
self.model.delta_values = value
|
|
|
|
|
2011-09-23 14:29:25 +00:00
|
|
|
#--- Events
|
|
|
|
def appPrefsChanged(self, prefs):
|
|
|
|
font = self.view.font()
|
|
|
|
font.setPointSize(prefs.tableFontSize)
|
|
|
|
self.view.setFont(font)
|
|
|
|
fm = QFontMetrics(font)
|
|
|
|
self.view.verticalHeader().setDefaultSectionSize(fm.height()+2)
|
|
|
|
|
2010-02-12 14:39:29 +00:00
|
|
|
#--- model --> view
|
|
|
|
def invalidate_markings(self):
|
|
|
|
# redraw view
|
|
|
|
# HACK. this is the only way I found to update the widget without reseting everything
|
|
|
|
self.view.scroll(0, 1)
|
|
|
|
self.view.scroll(0, -1)
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
|
2010-09-24 13:48:59 +00:00
|
|
|
class ResultsView(QTableView):
|
2009-06-01 09:55:11 +00:00
|
|
|
#--- Override
|
|
|
|
def keyPressEvent(self, event):
|
|
|
|
if event.text() == ' ':
|
2010-02-12 14:39:29 +00:00
|
|
|
self.emit(SIGNAL('spacePressed()'))
|
2009-06-01 09:55:11 +00:00
|
|
|
return
|
2010-09-24 13:48:59 +00:00
|
|
|
QTableView.keyPressEvent(self, event)
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2009-06-19 11:14:27 +00:00
|
|
|
def mouseDoubleClickEvent(self, event):
|
|
|
|
self.emit(SIGNAL('doubleClicked()'))
|
|
|
|
# We don't call the superclass' method because the default behavior is to rename the cell.
|
|
|
|
|