1818# TODO: Consider a wizard-like interface:
1919# * 1. Select encoding, delimiter, ... (preview is all text)
2020# * 2. Define column types (preview is parsed and rendered type appropriate)
21-
21+ from __future__ import annotations
2222import sys
2323import io
2424import enum
@@ -1370,19 +1370,10 @@ def rowsInserted(self, parent, start, end):
13701370 command |= QItemSelectionModel .Columns
13711371 smodel .select (selection , command )
13721372
1373- def setRowHints (self , hints ):
1374- # type: (Dict[int, TablePreview.RowSpec]) -> None
1375- for row , hint in hints .items ():
1376- current = self .itemDelegateForRow (row )
1377- if current is not None :
1378- current .deleteLater ()
1379- if hint == TablePreview .Header :
1380- delegate = HeaderItemDelegate (self )
1381- elif hint == TablePreview .Skipped :
1382- delegate = SkipItemDelegate (self )
1383- else :
1384- delegate = None
1385- self .setItemDelegateForRow (row , delegate )
1373+ def setRowHints (self , hints : dict [int , TablePreview .RowSpec ]) -> None :
1374+ model = self .model ()
1375+ for index , hint in hints .items ():
1376+ model .setHeaderData (index , Qt .Vertical , hint )
13861377
13871378 def sizeHint (self ):
13881379 sh = super ().sizeHint () # type: QSize
@@ -1433,7 +1424,9 @@ def initStyleOption(self, option, index):
14331424 if coltype == ColumnType .Numeric or coltype == ColumnType .Time :
14341425 option .displayAlignment = Qt .AlignRight | Qt .AlignVCenter
14351426
1436- if not self .validate (option .text ):
1427+ rowhint = model .headerData (index .row (), Qt .Vertical ,
1428+ TablePreviewModel .RowStateRole )
1429+ if not self .validate (option .text ) and rowhint is None :
14371430 option .palette .setBrush (
14381431 QPalette .All , QPalette .Text , QBrush (Qt .red , Qt .SolidPattern )
14391432 )
@@ -1442,6 +1435,20 @@ def initStyleOption(self, option, index):
14421435 QBrush (Qt .red , Qt .SolidPattern )
14431436 )
14441437
1438+ if rowhint == RowSpec .Skipped :
1439+ color = QColor (Qt .red )
1440+ base = option .palette .color (QPalette .Base )
1441+ if base .isValid () and base .value () > 127 :
1442+ # blend on 'light' base, not on dark (low contrast)
1443+ color .setAlphaF (0.2 )
1444+ option .backgroundBrush = QBrush (color , Qt .DiagCrossPattern )
1445+ elif rowhint == RowSpec .Header :
1446+ shadow = option .palette .color (QPalette .WindowText )
1447+ if shadow .isValid ():
1448+ shadow .setAlphaF (0.1 )
1449+ option .backgroundBrush = QBrush (shadow , Qt .SolidPattern )
1450+ option .displayAlignment = Qt .AlignCenter
1451+
14451452 def validate (self , value : str ) -> bool : # pylint: disable=no-self-use
14461453 return not is_surrogate_escaped (value )
14471454
@@ -1457,39 +1464,6 @@ def helpEvent(self, event, view, option, index):
14571464 return super ().helpEvent (event , view , option , index )
14581465
14591466
1460- class HeaderItemDelegate (PreviewItemDelegate ):
1461- """
1462- Paint the items with an alternate color scheme
1463- """
1464- NoFeatures = 0
1465- AutoDecorate = 1
1466-
1467- def __init__ (self , * args , ** kwargs ):
1468- super ().__init__ (* args , ** kwargs )
1469- self .__features = HeaderItemDelegate .NoFeatures
1470-
1471- def features (self ):
1472- return self .__features
1473-
1474- def initStyleOption (self , option , index ):
1475- # type: (QStyleOptionViewItem, QModelIndex) -> None
1476- super ().initStyleOption (option , index )
1477- palette = option .palette
1478- shadow = palette .color (QPalette .WindowText ) # type: QColor
1479- if shadow .isValid ():
1480- shadow .setAlphaF (0.1 )
1481- option .backgroundBrush = QBrush (shadow , Qt .SolidPattern )
1482- option .displayAlignment = Qt .AlignCenter
1483- model = index .model ()
1484- if option .icon .isNull () and \
1485- self .__features & HeaderItemDelegate .AutoDecorate :
1486- ctype = model .headerData (index .column (), Qt .Horizontal ,
1487- TablePreviewModel .ColumnTypeRole )
1488- option .icon = icon_for_column_type (ctype )
1489- if not option .icon .isNull ():
1490- option .features |= QStyleOptionViewItem .HasDecoration
1491-
1492-
14931467def icon_for_column_type (coltype ):
14941468 # type: (ColumnType) -> QIcon
14951469 if coltype == ColumnType .Numeric :
0 commit comments