[welcome] Allow delegate to pick the text role to display
This commit is contained in:
parent
3679bb45f0
commit
ab1c78ca23
@ -23,7 +23,7 @@ item_fontsize()
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
paintRequirement( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index )
|
paintRequirement( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index, int role )
|
||||||
{
|
{
|
||||||
QRect textRect = option.rect.adjusted( item_margin, item_margin, -item_margin, -item_margin );
|
QRect textRect = option.rect.adjusted( item_margin, item_margin, -item_margin, -item_margin );
|
||||||
QFont font = qApp->font();
|
QFont font = qApp->font();
|
||||||
@ -48,8 +48,7 @@ paintRequirement( QPainter* painter, const QStyleOptionViewItem& option, const Q
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
painter->drawText( textRect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, index.data( role ).toString() );
|
||||||
painter->drawText( textRect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, index.data().toString() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize
|
QSize
|
||||||
@ -82,7 +81,7 @@ ResultDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
|
|||||||
initStyleOption( &opt, index );
|
initStyleOption( &opt, index );
|
||||||
opt.text.clear();
|
opt.text.clear();
|
||||||
|
|
||||||
paintRequirement( painter, opt, index );
|
paintRequirement( painter, opt, index, m_textRole );
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
#include <QStyledItemDelegate>
|
#include <QStyledItemDelegate>
|
||||||
|
|
||||||
|
#include "modulesystem/RequirementsModel.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Class for drawing (un)satisfied requirements
|
* @brief Class for drawing (un)satisfied requirements
|
||||||
*/
|
*/
|
||||||
@ -19,10 +21,17 @@ class ResultDelegate : public QStyledItemDelegate
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using QStyledItemDelegate::QStyledItemDelegate;
|
using QStyledItemDelegate::QStyledItemDelegate;
|
||||||
|
ResultDelegate( QObject* parent, Calamares::RequirementsModel::Roles text )
|
||||||
|
: QStyledItemDelegate( parent )
|
||||||
|
, m_textRole( text )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const override;
|
QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const override;
|
||||||
void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const override;
|
void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const override;
|
||||||
|
|
||||||
|
int m_textRole = Calamares::RequirementsModel::Name;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PROGRESSTREEDELEGATE_H
|
#endif // PROGRESSTREEDELEGATE_H
|
||||||
|
Loading…
Reference in New Issue
Block a user