2009-06-01 09:55:11 +00:00
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2009-04-23
|
2013-04-28 14:35:51 +00:00
|
|
|
# Copyright 2013 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
|
|
|
|
2013-10-20 19:15:09 +00:00
|
|
|
from PyQt5.QtCore import Qt, pyqtSignal
|
|
|
|
from PyQt5.QtGui import QBrush, QFont, QFontMetrics, QColor
|
|
|
|
from PyQt5.QtWidgets import QTableView
|
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
|
|
|
class ResultsModel(Table):
|
2010-02-12 14:39:29 +00:00
|
|
|
def __init__(self, app, view):
|
2011-11-28 15:27:17 +00:00
|
|
|
model = app.model.result_table
|
2010-09-24 13:48:59 +00:00
|
|
|
Table.__init__(self, model, view)
|
2012-03-16 19:05:52 +00:00
|
|
|
view.horizontalHeader().setSortIndicator(1, Qt.AscendingOrder)
|
2011-09-23 14:29:25 +00:00
|
|
|
|
|
|
|
app.prefsChanged.connect(self.appPrefsChanged)
|
2011-11-28 15:27:17 +00:00
|
|
|
app.willSavePrefs.connect(self.appWillSavePrefs)
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2012-03-16 17:50:17 +00:00
|
|
|
def _getData(self, row, column, role):
|
2012-03-16 19:05:52 +00:00
|
|
|
if column.name == 'marked':
|
|
|
|
if role == Qt.CheckStateRole and row.markable:
|
|
|
|
return Qt.Checked if row.marked else Qt.Unchecked
|
|
|
|
return None
|
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
|
2011-11-28 15:27:17 +00:00
|
|
|
return data[column.name]
|
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)
|
2013-07-28 21:45:23 +00:00
|
|
|
elif row.is_cell_delta(column.name):
|
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:
|
2011-11-28 15:27:17 +00:00
|
|
|
if column.name == 'name':
|
|
|
|
return row.data[column.name]
|
2009-09-27 08:44:06 +00:00
|
|
|
return None
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2012-03-16 17:50:17 +00:00
|
|
|
def _getFlags(self, row, column):
|
2009-06-01 09:55:11 +00:00
|
|
|
flags = Qt.ItemIsEnabled | Qt.ItemIsSelectable
|
2012-03-16 19:05:52 +00:00
|
|
|
if column.name == 'marked':
|
2010-09-24 13:48:59 +00:00
|
|
|
if row.markable:
|
|
|
|
flags |= Qt.ItemIsUserCheckable
|
2012-03-19 20:20:51 +00:00
|
|
|
elif column.name == 'name':
|
|
|
|
flags |= Qt.ItemIsEditable
|
2009-06-01 09:55:11 +00:00
|
|
|
return flags
|
|
|
|
|
2012-03-16 17:50:17 +00:00
|
|
|
def _setData(self, row, column, value, role):
|
2009-06-01 09:55:11 +00:00
|
|
|
if role == Qt.CheckStateRole:
|
2012-03-16 19:05:52 +00:00
|
|
|
if column.name == 'marked':
|
|
|
|
row.marked = bool(value)
|
2009-06-01 09:55:11 +00:00
|
|
|
return True
|
2010-09-24 13:48:59 +00:00
|
|
|
elif role == Qt.EditRole:
|
2011-11-28 15:27:17 +00:00
|
|
|
if column.name == 'name':
|
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):
|
2011-11-28 15:27:17 +00:00
|
|
|
column = self.model.COLUMNS[column]
|
|
|
|
self.model.sort(column.name, 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)
|
|
|
|
|
2011-11-28 15:27:17 +00:00
|
|
|
def appWillSavePrefs(self):
|
|
|
|
self.model.columns.save_columns()
|
|
|
|
|
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() == ' ':
|
2012-03-04 14:55:21 +00:00
|
|
|
self.spacePressed.emit()
|
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):
|
2012-03-04 14:55:21 +00:00
|
|
|
self.doubleClicked.emit(None)
|
2009-06-19 11:14:27 +00:00
|
|
|
# We don't call the superclass' method because the default behavior is to rename the cell.
|
|
|
|
|
2012-03-04 14:55:21 +00:00
|
|
|
#--- Signals
|
|
|
|
spacePressed = pyqtSignal()
|