2009-06-01 09:55:11 +00:00
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2009-04-23
|
2015-01-03 21:30:57 +00:00
|
|
|
# Copyright 2015 Hardcoded Software (http://www.hardcoded.net)
|
2016-05-30 02:37:38 +00:00
|
|
|
#
|
|
|
|
# This software is licensed under the "GPLv3" License as described in the "LICENSE" file,
|
|
|
|
# which should be included with this package. The terms are also available at
|
2015-01-03 21:33:16 +00:00
|
|
|
# http://www.gnu.org/licenses/gpl-3.0.html
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2014-04-18 14:44:59 +00:00
|
|
|
from PyQt5.QtCore import Qt, pyqtSignal, QModelIndex
|
2020-07-22 19:38:03 +00:00
|
|
|
from PyQt5.QtGui import QBrush, QFont, QFontMetrics
|
2013-10-20 19:15:09 +00:00
|
|
|
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
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2010-09-24 13:48:59 +00:00
|
|
|
class ResultsModel(Table):
|
2013-10-20 19:53:59 +00:00
|
|
|
def __init__(self, app, view, **kwargs):
|
2011-11-28 15:27:17 +00:00
|
|
|
model = app.model.result_table
|
2013-10-20 19:53:59 +00:00
|
|
|
super().__init__(model, view, **kwargs)
|
2012-03-16 19:05:52 +00:00
|
|
|
view.horizontalHeader().setSortIndicator(1, Qt.AscendingOrder)
|
2016-05-30 02:37:38 +00:00
|
|
|
font = view.font()
|
|
|
|
font.setPointSize(app.prefs.tableFontSize)
|
|
|
|
self.view.setFont(font)
|
|
|
|
fm = QFontMetrics(font)
|
2020-01-01 02:16:27 +00:00
|
|
|
view.verticalHeader().setDefaultSectionSize(fm.height() + 2)
|
2016-05-30 02:37:38 +00:00
|
|
|
|
2011-11-28 15:27:17 +00:00
|
|
|
app.willSavePrefs.connect(self.appWillSavePrefs)
|
2020-04-26 23:36:27 +00:00
|
|
|
self.prefs = app.prefs
|
2016-05-30 02:37:38 +00:00
|
|
|
|
2012-03-16 17:50:17 +00:00
|
|
|
def _getData(self, row, column, role):
|
2020-01-01 02:16:27 +00:00
|
|
|
if column.name == "marked":
|
2016-05-30 02:37:38 +00:00
|
|
|
if role == Qt.CheckStateRole and row.markable:
|
2012-03-16 19:05:52 +00:00
|
|
|
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:
|
2020-07-22 19:38:03 +00:00
|
|
|
return QBrush(self.prefs.result_table_ref_foreground_color)
|
2013-07-28 21:45:23 +00:00
|
|
|
elif row.is_cell_delta(column.name):
|
2020-07-22 19:38:03 +00:00
|
|
|
return QBrush(self.prefs.result_table_delta_foreground_color)
|
2010-09-24 13:48:59 +00:00
|
|
|
elif role == Qt.FontRole:
|
|
|
|
font = QFont(self.view.font())
|
2020-04-26 23:36:27 +00:00
|
|
|
if self.prefs.reference_bold_font:
|
|
|
|
font.setBold(row.isref)
|
2010-09-24 13:48:59 +00:00
|
|
|
return font
|
2009-06-01 09:55:11 +00:00
|
|
|
elif role == Qt.EditRole:
|
2020-01-01 02:16:27 +00:00
|
|
|
if column.name == "name":
|
2011-11-28 15:27:17 +00:00
|
|
|
return row.data[column.name]
|
2009-09-27 08:44:06 +00:00
|
|
|
return None
|
2016-05-30 02:37:38 +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
|
2020-01-01 02:16:27 +00:00
|
|
|
if column.name == "marked":
|
2010-09-24 13:48:59 +00:00
|
|
|
if row.markable:
|
|
|
|
flags |= Qt.ItemIsUserCheckable
|
2020-01-01 02:16:27 +00:00
|
|
|
elif column.name == "name":
|
2012-03-19 20:20:51 +00:00
|
|
|
flags |= Qt.ItemIsEditable
|
2009-06-01 09:55:11 +00:00
|
|
|
return flags
|
2016-05-30 02:37:38 +00:00
|
|
|
|
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:
|
2020-01-01 02:16:27 +00:00
|
|
|
if column.name == "marked":
|
2012-03-16 19:05:52 +00:00
|
|
|
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:
|
2020-01-01 02:16:27 +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
|
2016-05-30 02:37:38 +00:00
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
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)
|
2016-05-30 02:37:38 +00:00
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
# --- Properties
|
2009-06-01 09:55:11 +00:00
|
|
|
@property
|
|
|
|
def power_marker(self):
|
2010-02-12 14:39:29 +00:00
|
|
|
return self.model.power_marker
|
2016-05-30 02:37:38 +00:00
|
|
|
|
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
|
2016-05-30 02:37:38 +00:00
|
|
|
|
2010-02-12 14:39:29 +00:00
|
|
|
@property
|
|
|
|
def delta_values(self):
|
|
|
|
return self.model.delta_values
|
2016-05-30 02:37:38 +00:00
|
|
|
|
2010-02-12 14:39:29 +00:00
|
|
|
@delta_values.setter
|
|
|
|
def delta_values(self, value):
|
|
|
|
self.model.delta_values = value
|
2016-05-30 02:37:38 +00:00
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
# --- Events
|
2011-11-28 15:27:17 +00:00
|
|
|
def appWillSavePrefs(self):
|
|
|
|
self.model.columns.save_columns()
|
2016-05-30 02:37:38 +00:00
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
# --- model --> view
|
2010-02-12 14:39:29 +00:00
|
|
|
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)
|
2016-05-30 02:37:38 +00:00
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2010-09-24 13:48:59 +00:00
|
|
|
class ResultsView(QTableView):
|
2020-01-01 02:16:27 +00:00
|
|
|
# --- Override
|
2009-06-01 09:55:11 +00:00
|
|
|
def keyPressEvent(self, event):
|
2020-01-01 02:16:27 +00:00
|
|
|
if event.text() == " ":
|
2012-03-04 14:55:21 +00:00
|
|
|
self.spacePressed.emit()
|
2009-06-01 09:55:11 +00:00
|
|
|
return
|
2013-10-20 19:53:59 +00:00
|
|
|
super().keyPressEvent(event)
|
2016-05-30 02:37:38 +00:00
|
|
|
|
2009-06-19 11:14:27 +00:00
|
|
|
def mouseDoubleClickEvent(self, event):
|
2014-04-18 14:44:59 +00:00
|
|
|
self.doubleClicked.emit(QModelIndex())
|
2009-06-19 11:14:27 +00:00
|
|
|
# We don't call the superclass' method because the default behavior is to rename the cell.
|
2016-05-30 02:37:38 +00:00
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
# --- Signals
|
2012-03-04 14:55:21 +00:00
|
|
|
spacePressed = pyqtSignal()
|