23 #include <QHBoxLayout> 24 #include <QPushButton> 26 #include <QApplication> 27 #include <QMouseEvent> 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 static QPixmap sSelectedIcon;
74 if ( sSelectedIcon.isNull() )
76 static QPixmap sDeselectedIcon;
77 if ( sDeselectedIcon.isNull() )
80 QString text = index.model()->data( index, Qt::EditRole ).toString();
83 bool isEditSelection = mEditSelectionModel && mEditSelectionModel->isSelected( mListModel->
mapToMaster( index ) );
86 QStyleOptionViewItem iconOption;
88 QRect iconLayoutBounds( option.rect.x(), option.rect.y(), option.rect.height(), option.rect.height() );
90 QPixmap icon = mFeatureSelectionModel->
isSelected( index ) ? sSelectedIcon : sDeselectedIcon;
95 icon = icon.scaledToHeight( option.rect.height(), Qt::SmoothTransformation );
99 QRect textLayoutBounds( iconLayoutBounds.x() + iconLayoutBounds.width(), option.rect.y(), option.rect.width() - ( iconLayoutBounds.x() + iconLayoutBounds.width() ), option.rect.height() );
101 QStyleOptionViewItem textOption = option;
102 textOption.state |= QStyle::State_Enabled;
103 if ( isEditSelection )
105 textOption.state |= QStyle::State_Selected;
108 if ( featInfo.
isNew )
110 textOption.font.setStyle( QFont::StyleItalic );
111 textOption.palette.setColor( QPalette::Text, Qt::darkGreen );
112 textOption.palette.setColor( QPalette::HighlightedText, Qt::darkGreen );
114 else if ( featInfo.
isEdited || ( mCurrentFeatureEdited && isEditSelection ) )
116 textOption.font.setStyle( QFont::StyleItalic );
117 textOption.palette.setColor( QPalette::Text, Qt::red );
118 textOption.palette.setColor( QPalette::HighlightedText, Qt::red );
121 drawDisplay( painter, textOption, textLayoutBounds, text );
122 drawDecoration( painter, iconOption, iconLayoutBounds, icon );
virtual bool isSelected(QgsFeatureId fid)
Returns the selection status of a given feature id.
virtual QModelIndex mapToMaster(const QModelIndex &proxyIndex) const
static QPixmap getThemePixmap(const QString &name)
Helper to get a theme icon as a pixmap.
bool isEdited
True if feature has been edited.
static const int ICON_SIZE
void setFeatureSelectionModel(QgsFeatureSelectionModel *featureSelectionModel)
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
QgsFeatureListViewDelegate(QgsFeatureListModel *listModel, QObject *parent=nullptr)
void setCurrentFeatureEdited(bool state)
bool isNew
True if feature is a newly added feature.
Element positionToElement(QPoint pos)
void setEditSelectionModel(QItemSelectionModel *editSelectionModel)