26#include <QApplication> 
   31  : QItemDelegate( parent )
 
   32  , mListModel( listModel )
 
   33  , mCurrentFeatureEdited( false )
 
   51  mFeatureSelectionModel = featureSelectionModel;
 
   56  mCurrentFeatureEdited = state;
 
   61  mEditSelectionModel = editSelectionModel;
 
   68  return QSize( option.rect.width(), std::max( height, option.fontMetrics.height() ) );
 
   73  const bool isEditSelection = mEditSelectionModel && mEditSelectionModel->isSelected( mListModel->
mapToMaster( index ) );
 
   75  QStyleOptionViewItem textOption = option;
 
   76  textOption.state |= QStyle::State_Enabled;
 
   77  if ( isEditSelection )
 
   79    textOption.state |= QStyle::State_Selected;
 
   81  drawBackground( painter, textOption, index );
 
   84  static QPixmap sSelectedIcon;
 
   85  if ( sSelectedIcon.isNull() )
 
   87  static QPixmap sDeselectedIcon;
 
   88  if ( sDeselectedIcon.isNull() )
 
   91  const QString text = index.model()->data( index, Qt::EditRole ).toString();
 
   95  const QStyleOptionViewItem iconOption;
 
   97  QRect iconLayoutBounds( option.rect.x(), option.rect.y(), option.rect.height(), option.rect.height() );
 
   99  QPixmap icon = mFeatureSelectionModel->
isSelected( index ) ? sSelectedIcon : sDeselectedIcon;
 
  104    icon = icon.scaledToHeight( option.rect.height(), Qt::SmoothTransformation );
 
  107  drawDecoration( painter, iconOption, iconLayoutBounds, icon );
 
  110  const QVariant conditionalIcon = index.model()->data( index, Qt::DecorationRole );
 
  111  if ( conditionalIcon.isValid() )
 
  113    const QPixmap pixmap = conditionalIcon.value< QPixmap >();
 
  114    iconLayoutBounds.moveLeft( iconLayoutBounds.x() + icon.width() + QFontMetrics( textOption.font ).horizontalAdvance( 
'X' ) );
 
  115    iconLayoutBounds.setTop( option.rect.y() + ( option.rect.height() - pixmap.height() ) / 2.0 );
 
  116    iconLayoutBounds.setHeight( pixmap.height() );
 
  117    drawDecoration( painter, iconOption, iconLayoutBounds, pixmap );
 
  121  const QRect textLayoutBounds( iconLayoutBounds.x() + iconLayoutBounds.width(), option.rect.y(), option.rect.width() - ( iconLayoutBounds.x() + iconLayoutBounds.width() ), option.rect.height() );
 
  124  const QVariant font = index.model()->data( index, Qt::FontRole );
 
  125  if ( font.isValid() )
 
  127    textOption.font = font.value< QFont >();
 
  129  const QVariant textColor = index.model()->data( index, Qt::ForegroundRole );
 
  130  if ( textColor.isValid() )
 
  132    textOption.palette.setColor( QPalette::Text, textColor.value< QColor >() );
 
  135  if ( featInfo.
isNew )
 
  137    textOption.font.setStyle( QFont::StyleItalic );
 
  138    textOption.palette.setColor( QPalette::Text, Qt::darkGreen );
 
  139    textOption.palette.setColor( QPalette::HighlightedText, Qt::darkGreen );
 
  141  else if ( featInfo.
isEdited || ( mCurrentFeatureEdited && isEditSelection ) )
 
  143    textOption.font.setStyle( QFont::StyleItalic );
 
  144    textOption.palette.setColor( QPalette::Text, Qt::red );
 
  145    textOption.palette.setColor( QPalette::HighlightedText, Qt::red );
 
  148  drawDisplay( painter, textOption, textLayoutBounds, text );
 
static QPixmap getThemePixmap(const QString &name, const QColor &foreColor=QColor(), const QColor &backColor=QColor(), int size=16)
Helper to get a theme icon as a pixmap.
 
virtual QModelIndex mapToMaster(const QModelIndex &proxyIndex) const
 
QgsFeatureListViewDelegate(QgsFeatureListModel *listModel, QObject *parent=nullptr)
 
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
 
void setEditSelectionModel(QItemSelectionModel *editSelectionModel)
 
static const int ICON_SIZE
 
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
 
void setCurrentFeatureEdited(bool state)
 
void setFeatureSelectionModel(QgsFeatureSelectionModel *featureSelectionModel)
 
Element positionToElement(QPoint pos)
 
virtual bool isSelected(QgsFeatureId fid)
Returns the selection status of a given feature id.
 
bool isEdited
True if feature has been edited.
 
bool isNew
True if feature is a newly added feature.