2009-06-01 09:55:11 +00:00
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2009-05-17
|
2015-01-03 21:30:57 +00:00
|
|
|
# Copyright 2015 Hardcoded Software (http://www.hardcoded.net)
|
2020-01-01 02:16:27 +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
|
|
|
|
2013-10-20 19:15:09 +00:00
|
|
|
from PyQt5.QtCore import Qt, QAbstractTableModel
|
|
|
|
from PyQt5.QtWidgets import QHeaderView, QTableView
|
2020-07-29 19:42:44 +00:00
|
|
|
from PyQt5.QtGui import QFont, QBrush
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2011-11-01 19:44:18 +00:00
|
|
|
from hscommon.trans import trget
|
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
tr = trget("ui")
|
2011-01-21 12:57:54 +00:00
|
|
|
|
2020-06-29 23:02:56 +00:00
|
|
|
HEADER = [tr("Selected"), tr("Reference")]
|
2009-06-01 09:55:11 +00:00
|
|
|
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
class DetailsModel(QAbstractTableModel):
|
2020-07-29 19:42:44 +00:00
|
|
|
def __init__(self, model, app, **kwargs):
|
2013-10-20 19:53:59 +00:00
|
|
|
super().__init__(**kwargs)
|
2010-02-05 20:09:04 +00:00
|
|
|
self.model = model
|
2020-07-29 19:42:44 +00:00
|
|
|
self.prefs = app.prefs
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
def columnCount(self, parent):
|
|
|
|
return len(HEADER)
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
def data(self, index, role):
|
|
|
|
if not index.isValid():
|
2010-02-05 20:09:04 +00:00
|
|
|
return None
|
2020-06-29 23:19:25 +00:00
|
|
|
# Skip first value "Attribute"
|
|
|
|
column = index.column() + 1
|
2009-06-01 09:55:11 +00:00
|
|
|
row = index.row()
|
2020-06-30 02:20:27 +00:00
|
|
|
|
2020-06-30 16:32:20 +00:00
|
|
|
ignored_fields = ["Dupe Count"]
|
2021-08-15 09:10:18 +00:00
|
|
|
if (
|
|
|
|
self.model.row(row)[0] in ignored_fields
|
|
|
|
or self.model.row(row)[1] == "---"
|
|
|
|
or self.model.row(row)[2] == "---"
|
|
|
|
):
|
2020-06-30 02:20:27 +00:00
|
|
|
if role != Qt.DisplayRole:
|
|
|
|
return None
|
|
|
|
return self.model.row(row)[column]
|
|
|
|
|
|
|
|
if role == Qt.DisplayRole:
|
|
|
|
return self.model.row(row)[column]
|
|
|
|
if role == Qt.ForegroundRole and self.model.row(row)[1] != self.model.row(row)[2]:
|
2020-07-29 19:42:44 +00:00
|
|
|
return QBrush(self.prefs.details_table_delta_foreground_color)
|
2020-06-30 02:20:27 +00:00
|
|
|
if role == Qt.FontRole and self.model.row(row)[1] != self.model.row(row)[2]:
|
2020-07-01 01:05:59 +00:00
|
|
|
font = QFont(self.model.view.font()) # or simply QFont()
|
2020-06-30 02:20:27 +00:00
|
|
|
font.setBold(True)
|
|
|
|
return font
|
2020-07-01 01:05:59 +00:00
|
|
|
return None # QVariant()
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
def headerData(self, section, orientation, role):
|
2021-08-15 09:10:18 +00:00
|
|
|
if orientation == Qt.Horizontal and role == Qt.DisplayRole and section < len(HEADER):
|
2010-02-05 20:09:04 +00:00
|
|
|
return HEADER[section]
|
2021-08-15 09:10:18 +00:00
|
|
|
elif orientation == Qt.Vertical and role == Qt.DisplayRole and section < self.model.row_count():
|
2020-06-30 02:20:27 +00:00
|
|
|
# Read "Attribute" cell for horizontal header
|
2020-06-29 23:02:56 +00:00
|
|
|
return self.model.row(section)[0]
|
2010-02-05 20:09:04 +00:00
|
|
|
return None
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
def rowCount(self, parent):
|
2010-02-05 20:09:04 +00:00
|
|
|
return self.model.row_count()
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
|
|
|
|
class DetailsTable(QTableView):
|
|
|
|
def __init__(self, *args):
|
|
|
|
QTableView.__init__(self, *args)
|
|
|
|
self.setAlternatingRowColors(True)
|
|
|
|
self.setSelectionBehavior(QTableView.SelectRows)
|
2020-06-30 02:20:27 +00:00
|
|
|
self.setSelectionMode(QTableView.NoSelection)
|
2009-06-01 09:55:11 +00:00
|
|
|
self.setShowGrid(False)
|
2020-05-07 03:08:07 +00:00
|
|
|
self.setWordWrap(False)
|
2020-06-29 23:19:25 +00:00
|
|
|
self.setCornerButtonEnabled(False)
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
def setModel(self, model):
|
|
|
|
QTableView.setModel(self, model)
|
|
|
|
# The model needs to be set to set header stuff
|
|
|
|
hheader = self.horizontalHeader()
|
|
|
|
hheader.setHighlightSections(False)
|
2020-06-29 23:02:56 +00:00
|
|
|
hheader.setSectionResizeMode(0, QHeaderView.Stretch)
|
2013-10-20 19:15:09 +00:00
|
|
|
hheader.setSectionResizeMode(1, QHeaderView.Stretch)
|
2009-06-01 09:55:11 +00:00
|
|
|
vheader = self.verticalHeader()
|
2020-06-29 23:02:56 +00:00
|
|
|
vheader.setVisible(True)
|
2009-06-01 09:55:11 +00:00
|
|
|
vheader.setDefaultSectionSize(18)
|
2020-06-29 23:19:25 +00:00
|
|
|
# hardcoded value above is not ideal, perhaps resize to contents first?
|
2020-06-29 23:02:56 +00:00
|
|
|
# vheader.setSectionResizeMode(QHeaderView.ResizeToContents)
|
|
|
|
vheader.setSectionResizeMode(QHeaderView.Fixed)
|
|
|
|
vheader.setSectionsMovable(True)
|