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
|
2020-07-15 19:43:01 +00:00
|
|
|
from PyQt5.QtWidgets import QHeaderView, QTableView
|
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
|
|
|
|
|
|
|
HEADER = [tr("Attribute"), 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):
|
2013-10-20 19:53:59 +00:00
|
|
|
def __init__(self, model, **kwargs):
|
|
|
|
super().__init__(**kwargs)
|
2010-02-05 20:09:04 +00:00
|
|
|
self.model = model
|
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
|
2009-06-01 09:55:11 +00:00
|
|
|
if role != Qt.DisplayRole:
|
2010-02-05 20:09:04 +00:00
|
|
|
return None
|
2009-06-01 09:55:11 +00:00
|
|
|
column = index.column()
|
|
|
|
row = index.row()
|
2010-02-05 20:09:04 +00:00
|
|
|
return self.model.row(row)[column]
|
2020-01-01 02:16:27 +00:00
|
|
|
|
2009-06-01 09:55:11 +00:00
|
|
|
def headerData(self, section, orientation, role):
|
2020-01-01 02:16:27 +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]
|
|
|
|
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-29 20:31:43 +00:00
|
|
|
self.setSelectionMode(QTableView.SingleSelection)
|
2009-06-01 09:55:11 +00:00
|
|
|
self.setShowGrid(False)
|
2020-05-07 03:08:07 +00:00
|
|
|
self.setWordWrap(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)
|
|
|
|
hheader.setStretchLastSection(False)
|
|
|
|
hheader.resizeSection(0, 100)
|
2020-05-01 16:22:25 +00:00
|
|
|
hheader.setSectionResizeMode(0, QHeaderView.Interactive)
|
2013-10-20 19:15:09 +00:00
|
|
|
hheader.setSectionResizeMode(1, QHeaderView.Stretch)
|
|
|
|
hheader.setSectionResizeMode(2, QHeaderView.Stretch)
|
2009-06-01 09:55:11 +00:00
|
|
|
vheader = self.verticalHeader()
|
|
|
|
vheader.setVisible(False)
|
|
|
|
vheader.setDefaultSectionSize(18)
|