Skip to content

Commit

Permalink
Merge pull request #682 from glubsy/details_table_tweaks
Browse files Browse the repository at this point in the history
Colorize details table differences, allow moving around of rows
  • Loading branch information
arsenetar authored Jul 29, 2020
2 parents d2235f9 + c973224 commit f02b66f
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 additions & 8 deletions qt/details_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@

from PyQt5.QtCore import Qt, QAbstractTableModel
from PyQt5.QtWidgets import QHeaderView, QTableView
from PyQt5.QtGui import QFont, QBrush, QColor

from hscommon.trans import trget

tr = trget("ui")

HEADER = [tr("Attribute"), tr("Selected"), tr("Reference")]
HEADER = [tr("Selected"), tr("Reference")]


class DetailsModel(QAbstractTableModel):
Expand All @@ -27,11 +28,27 @@ def columnCount(self, parent):
def data(self, index, role):
if not index.isValid():
return None
if role != Qt.DisplayRole:
return None
column = index.column()
# Skip first value "Attribute"
column = index.column() + 1
row = index.row()
return self.model.row(row)[column]

ignored_fields = ["Dupe Count"]
if (self.model.row(row)[0] in ignored_fields
or self.model.row(row)[1] == "---"
or self.model.row(row)[2] == "---"):
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]:
return QBrush(QColor(250, 20, 20)) # red
if role == Qt.FontRole and self.model.row(row)[1] != self.model.row(row)[2]:
font = QFont(self.model.view.font()) # or simply QFont()
font.setBold(True)
return font
return None # QVariant()

def headerData(self, section, orientation, role):
if (
Expand All @@ -40,6 +57,13 @@ def headerData(self, section, orientation, role):
and section < len(HEADER)
):
return HEADER[section]
elif (
orientation == Qt.Vertical
and role == Qt.DisplayRole
and section < self.model.row_count()
):
# Read "Attribute" cell for horizontal header
return self.model.row(section)[0]
return None

def rowCount(self, parent):
Expand All @@ -51,8 +75,10 @@ def __init__(self, *args):
QTableView.__init__(self, *args)
self.setAlternatingRowColors(True)
self.setSelectionBehavior(QTableView.SelectRows)
self.setSelectionMode(QTableView.NoSelection)
self.setShowGrid(False)
self.setWordWrap(False)
self.setCornerButtonEnabled(False)

def setModel(self, model):
QTableView.setModel(self, model)
Expand All @@ -61,9 +87,12 @@ def setModel(self, model):
hheader.setHighlightSections(False)
hheader.setStretchLastSection(False)
hheader.resizeSection(0, 100)
hheader.setSectionResizeMode(0, QHeaderView.Fixed)
hheader.setSectionResizeMode(0, QHeaderView.Stretch)
hheader.setSectionResizeMode(1, QHeaderView.Stretch)
hheader.setSectionResizeMode(2, QHeaderView.Stretch)
vheader = self.verticalHeader()
vheader.setVisible(False)
vheader.setVisible(True)
vheader.setDefaultSectionSize(18)
# hardcoded value above is not ideal, perhaps resize to contents first?
# vheader.setSectionResizeMode(QHeaderView.ResizeToContents)
vheader.setSectionResizeMode(QHeaderView.Fixed)
vheader.setSectionsMovable(True)

0 comments on commit f02b66f

Please sign in to comment.