23 #include <QHBoxLayout> 24 #include <QPushButton> 26 #include <QApplication> 27 #include <QMouseEvent> 32 , mFeatureSelectionModel( nullptr )
33 , mEditSelectionModel( nullptr )
34 , mListModel( listModel )
35 , mCurrentFeatureEdited( false )
53 mFeatureSelectionModel = featureSelectionModel;
58 mCurrentFeatureEdited = state;
63 mEditSelectionModel = editSelectionModel;
70 return QSize( option.rect.width(), qMax( height, option.fontMetrics.height() ) );
76 if ( selectedIcon.
isNull() )
79 if ( deselectedIcon.
isNull() )
85 bool isEditSelection = mEditSelectionModel && mEditSelectionModel->
isSelected( mListModel->
mapToMaster( index ) );
90 QRect iconLayoutBounds( option.rect.x(), option.rect.y(), option.rect.height(), option.rect.height() );
92 QPixmap icon = mFeatureSelectionModel->
isSelected( index ) ? selectedIcon : deselectedIcon;
97 icon = icon.
scaledToHeight( option.rect.height(), Qt::SmoothTransformation );
101 QRect textLayoutBounds( iconLayoutBounds.x() + iconLayoutBounds.width(), option.rect.y(), option.rect.width() - ( iconLayoutBounds.x() + iconLayoutBounds.width() ), option.rect.height() );
104 textOption.state |= QStyle::State_Enabled;
105 if ( isEditSelection )
107 textOption.state |= QStyle::State_Selected;
110 if ( featInfo.
isNew )
112 textOption.font.setStyle( QFont::StyleItalic );
113 textOption.palette.setColor( QPalette::Text, Qt::darkGreen );
114 textOption.palette.setColor( QPalette::HighlightedText, Qt::darkGreen );
116 else if ( featInfo.
isEdited || ( mCurrentFeatureEdited && isEditSelection ) )
118 textOption.font.setStyle( QFont::StyleItalic );
119 textOption.palette.setColor( QPalette::Text, Qt::red );
120 textOption.palette.setColor( QPalette::HighlightedText, Qt::red );
123 drawDisplay( painter, textOption, textLayoutBounds, text );
virtual bool isSelected(QgsFeatureId fid)
Returns the selection status of a given feature id.
virtual void drawDecoration(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, const QPixmap &pixmap) const
static QPixmap getThemePixmap(const QString &theName)
Helper to get a theme icon as a pixmap.
virtual QModelIndex mapToMaster(const QModelIndex &proxyIndex) const
static int const sIconSize
QPixmap scaledToHeight(int height, Qt::TransformationMode mode) const
virtual void drawDisplay(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, const QString &text) const
void setFeatureSelectionModel(QgsFeatureSelectionModel *featureSelectionModel)
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
QgsFeatureListViewDelegate(QgsFeatureListModel *listModel, QObject *parent=nullptr)
void setCurrentFeatureEdited(bool state)
virtual QVariant data(const QModelIndex &index, int role) const=0
const QAbstractItemModel * model() const
bool isSelected(const QModelIndex &index) const
Element positionToElement(QPoint pos)
void setEditSelectionModel(QItemSelectionModel *editSelectionModel)