77
88import numpy
99from AnyQt .QtWidgets import (
10- QTableView , QListWidget , QSplitter , QStyledItemDelegate ,
11- QToolTip , QStyle , QApplication , QSizePolicy )
10+ QTableView , QListWidget , QSplitter , QToolTip , QStyle , QApplication ,
11+ QSizePolicy
12+ )
1213from AnyQt .QtGui import QPainter , QStandardItem , QPen , QColor
1314from AnyQt .QtCore import (
1415 Qt , QSize , QRect , QRectF , QPoint , QLocale ,
3233from Orange .widgets .utils .sql import check_sql_input
3334from Orange .widgets .utils .state_summary import format_summary_details
3435from Orange .widgets .utils .colorpalettes import LimitedDiscretePalette
36+ from Orange .widgets .utils .itemdelegates import DataDelegate
3537
3638
3739# Input slot for the Predictors channel
@@ -703,7 +705,14 @@ def showEvent(self, event):
703705 QTimer .singleShot (0 , self ._update_splitter )
704706
705707
706- class DataItemDelegate (QStyledItemDelegate ):
708+ class DataItemDelegate (DataDelegate ):
709+ def __init__ (
710+ self , * args ,
711+ roles = (Qt .DisplayRole , Qt .TextAlignmentRole , Qt .BackgroundRole ),
712+ ** kwargs
713+ ):
714+ super ().__init__ (* args , roles = roles , ** kwargs )
715+
707716 def initStyleOption (self , option , index ):
708717 super ().initStyleOption (option , index )
709718 if self .parent ().selectionModel ().isSelected (index ):
@@ -712,7 +721,7 @@ def initStyleOption(self, option, index):
712721 | QStyle .State_Active
713722
714723
715- class PredictionsItemDelegate (QStyledItemDelegate ):
724+ class PredictionsItemDelegate (DataDelegate ):
716725 """
717726 A Item Delegate for custom formatting of predictions/probabilities
718727 """
@@ -787,9 +796,8 @@ def sizeHint(self, option, index):
787796 height = sh .height () + metrics .leading () + 2 * margin
788797 return QSize (sh .width (), height )
789798
790- @staticmethod
791- def distribution (index ):
792- value = index .data (Qt .DisplayRole )
799+ def distribution (self , index ):
800+ value = self .cachedData (index , Qt .DisplayRole )
793801 if isinstance (value , tuple ) and len (value ) == 2 :
794802 _ , dist = value
795803 return dist
@@ -816,20 +824,15 @@ def paint(self, painter, option, index):
816824 QStyle .PM_FocusFrameHMargin , option , option .widget ) + 1
817825 bottommargin = min (margin , 1 )
818826 rect = option .rect .adjusted (margin , margin , - margin , - bottommargin )
819-
827+ option . text = ""
820828 textrect = style .subElementRect (
821829 QStyle .SE_ItemViewItemText , option , option .widget )
822830 # Are the margins included in the subElementRect?? -> No!
823831 textrect = textrect .adjusted (margin , margin , - margin , - bottommargin )
824-
825- text = option .fontMetrics .elidedText (
826- text , option .textElideMode , textrect .width ())
827-
828832 spacing = max (metrics .leading (), 1 )
829833
830834 distheight = rect .height () - metrics .height () - spacing
831- distheight = numpy .clip (distheight , 2 , metrics .height ())
832-
835+ distheight = min (max (distheight , 2 ), metrics .height ())
833836 painter .save ()
834837 painter .setClipRect (option .rect )
835838 painter .setFont (option .font )
@@ -840,12 +843,6 @@ def paint(self, painter, option, index):
840843 style .drawPrimitive (
841844 QStyle .PE_PanelItemViewItem , option , painter , option .widget )
842845
843- if option .state & QStyle .State_Selected :
844- color = option .palette .highlightedText ().color ()
845- else :
846- color = option .palette .text ().color ()
847- painter .setPen (QPen (color ))
848-
849846 textrect = textrect .adjusted (0 , 0 , 0 , - distheight - spacing )
850847 distrect = QRect (
851848 textrect .bottomLeft () + QPoint (0 , spacing ),
@@ -854,9 +851,8 @@ def paint(self, painter, option, index):
854851 self .drawDistBar (painter , distrect , dist )
855852 painter .restore ()
856853 if text :
857- style .drawItemText (
858- painter , textrect , option .displayAlignment , option .palette ,
859- option .state & QStyle .State_Enabled , text )
854+ option .text = text
855+ self .drawViewItemText (style , painter , option , textrect )
860856
861857 def drawDistBar (self , painter , rect , distribution ):
862858 painter .save ()
0 commit comments