24#include <private/qabstractitemdelegate_p.h>
25#include <private/qabstractitemmodel_p.h>
26#include <private/qtextengine_p.h>
72 const QRect &decorationRect,
const QRect &checkRect)
const;
74 const QRect &decorationRect,
const QRect &checkRect)
const;
93 const QRect &decorationRect,
const QRect &checkRect)
const
103 return q->textRectangle(
nullptr,
110 const QRect &decorationRect,
const QRect &checkRect)
const
115 const bool wrapText =
option.features & QStyleOptionViewItem::WrapText;
118 switch (
option.decorationPosition) {
119 case QStyleOptionViewItem::Left:
120 case QStyleOptionViewItem::Right:
123 case QStyleOptionViewItem::Top:
124 case QStyleOptionViewItem::Bottom:
130 if (!decorationRect.isNull())
131 rect.setWidth(
rect.width() - decorationRect.width() - 2 * textMargin);
132 if (!checkRect.isNull())
133 rect.setWidth(
rect.width() - checkRect.width() - 2 * textMargin);
151 line.setLineWidth(lineWidth);
154 widthUsed =
qMax(widthUsed,
line.naturalTextWidth());
328 return d->clipPainting;
334 d->clipPainting = clip;
367 const QStyleOptionViewItem &
option,
385 QRect decorationRect;
387 if (
value.isValid()) {
390 if (
value.userType() == QMetaType::QIcon) {
391 d->tmp.icon = qvariant_cast<QIcon>(
value);
392 d->tmp.mode =
d->iconMode(
option.state);
393 d->tmp.state =
d->iconState(
option.state);
395 d->tmp.mode,
d->tmp.state);
403 decorationRect =
QRect();
409 if (
value.isValid()) {
410 checkState = QtPrivate::legacyEnumValueFromModelData<Qt::CheckState>(
value);
419 displayRect =
d->displayRect(
index,
opt, decorationRect, checkRect);
424 doLayout(
opt, &checkRect, &decorationRect, &displayRect,
false);
454 return qvariant_cast<QSize>(
value);
459 doLayout(
option, &checkRect, &decorationRect, &displayRect,
true);
461 return (decorationRect|displayRect|checkRect).size();
473 const QStyleOptionViewItem &,
477 if (!
index.isValid())
501 QByteArray n = editor->metaObject()->userProperty().name();
506 editor->setProperty(
n,
v);
528 QByteArray n = editor->metaObject()->userProperty().name();
530 n =
d->editorFactory()->valuePropertyName(
542 const QStyleOptionViewItem &
option,
554 opt.showDecorationSelected =
true;
623 d->textOption.setTextDirection(
option.direction);
625 d->textLayout.setTextOption(
d->textOption);
626 d->textLayout.setFont(
option.font);
642 elided += QChar::LineSeparator;
650 d->textLayout.setText(elided);
662 d->textLayout.draw(
painter, layoutRect.
topLeft(), QList<QTextLayout::FormatRange>(),
666 d->textLayout.draw(
painter, layoutRect.
topLeft(), QList<QTextLayout::FormatRange>(),
680 if (!
d->tmp.icon.isNull()) {
682 d->tmp.mode,
d->tmp.state);
704 const QStyleOptionViewItem &
option,
711 o.QStyleOption::operator=(
option);
731 const QStyleOptionViewItem &
option,
767 const QStyleOptionViewItem &
option,
803 const bool hasCheck = checkRect->isValid();
804 const bool hasPixmap = pixmapRect->isValid();
806 const bool hasMargin = (hasText | hasPixmap | hasCheck);
807 const int frameHMargin = hasMargin ?
809 const int textMargin = hasText ? frameHMargin : 0;
810 const int pixmapMargin = hasPixmap ? frameHMargin : 0;
811 const int checkMargin = hasCheck ? frameHMargin : 0;
812 const int x =
option.rect.left();
813 const int y =
option.rect.top();
824 pm = pixmapRect->size();
825 pm.
rwidth() += 2 * pixmapMargin;
829 if (
option.decorationPosition == QStyleOptionViewItem::Left
830 ||
option.decorationPosition == QStyleOptionViewItem::Right) {
843 cw = checkRect->width() + 2 * checkMargin;
856 switch (
option.decorationPosition) {
857 case QStyleOptionViewItem::Top: {
870 case QStyleOptionViewItem::Bottom: {
883 case QStyleOptionViewItem::Left: {
892 case QStyleOptionViewItem::Right: {
902 qWarning(
"doLayout: decoration position is invalid");
909 checkRect->size(), check);
913 if (
option.showDecorationSelected)
937 case QMetaType::QIcon: {
941 case QMetaType::QColor: {
949 return qvariant_cast<QPixmap>(
variant);
955 ushort arr[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
'-',
ushort(
'0' +
enabled) };
961 *(--
ptr) =
'0' +
i % 16;
992 const int n = (
img.sizeInBytes() >> 10) + 1;
1013 switch (
value.userType()) {
1016 case QMetaType::QPixmap: {
1019 case QMetaType::QImage: {
1022 case QMetaType::QIcon: {
1028 case QMetaType::QColor:
1030 case QMetaType::QString:
1049 if (
value.isValid()) {
1069 d->textLayout.setTextOption(
d->textOption);
1070 d->textLayout.setFont(
font);
1076 return QRect(0, 0,
size.width() + 2 * textMargin,
size.height());
1110 return d->editorEventFilter(
object,
event);
1119 const QStyleOptionViewItem &
option,
1133 if (!
value.isValid())
1173 const QStyleOptionViewItem &
option)
const
1179 if (
value.isValid()){
1180 opt.font = qvariant_cast<QFont>(
value).resolve(
opt.font);
1186 if (
value.isValid())
1187 opt.displayAlignment = QtPrivate::legacyFlagValueFromModelData<Qt::Alignment>(
value);
1202#include "moc_qitemdelegate.cpp"
QString textForRole(Qt::ItemDataRole role, const QVariant &value, const QLocale &locale, int precision=6) const
The QAbstractItemDelegate class is used to display and edit data items from a model.
virtual Q_INVOKABLE bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Sets the role data for the item at index to value.
Qt::ItemFlags flags(const QModelIndex &index) const override
\reimp
static QStyle * style()
Returns the application's style object.
The QColor class provides colors based on RGB, HSV or CMYK values.
void setAlphaF(float alpha)
Sets the alpha of this color to alpha.
\reentrant \inmodule QtGui
QFont resolve(const QFont &) const
Returns a new QFont that has attributes copied from other that have not been previously set on this f...
The QIcon class provides scalable icons in different modes and states.
Mode
This enum type describes the mode for which a pixmap is intended to be used.
State
This enum describes the state for which a pixmap is intended to be used.
QSize actualSize(const QSize &size, Mode mode=Normal, State state=Off) const
Returns the actual size of the icon for the requested size, mode, and state.
@ Format_ARGB32_Premultiplied
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const &
const QItemEditorFactory * editorFactory() const
QString valueToText(const QVariant &value, const QStyleOptionViewItem &option) const
const QWidget * widget(const QStyleOptionViewItem &option) const
QSizeF doTextLayout(int lineWidth) const
static QString replaceNewLine(QString text)
QIcon::Mode iconMode(QStyle::State state) const
QIcon::State iconState(QStyle::State state) const
QRect displayRect(const QModelIndex &index, const QStyleOptionViewItem &option, const QRect &decorationRect, const QRect &checkRect) const
QRect textLayoutBounds(const QStyleOptionViewItem &option, const QRect &decorationRect, const QRect &checkRect) const
struct QItemDelegatePrivate::Icon tmp
The QItemDelegate class provides display and editing facilities for data items from a model.
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Renders the delegate using the given painter and style option for the item specified by index.
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
Gets data from the editor widget and stores it in the specified model at the item index.
void setEditorData(QWidget *editor, const QModelIndex &index) const override
Sets the data to be displayed and edited by the editor from the data model item specified by the mode...
virtual void drawCheck(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, Qt::CheckState state) const
Renders a check indicator within the rectangle specified by rect, using the given painter and style o...
QRect textRectangle(QPainter *painter, const QRect &rect, const QFont &font, const QString &text) const
QRect rect(const QStyleOptionViewItem &option, const QModelIndex &index, int role) const
~QItemDelegate()
Destroys the item delegate.
virtual void drawDisplay(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, const QString &text) const
Renders the item view text within the rectangle specified by rect using the given painter and style o...
QRect doCheck(const QStyleOptionViewItem &option, const QRect &bounding, const QVariant &variant) const
void setClipping(bool clip)
static QPixmap selectedPixmap(const QPixmap &pixmap, const QPalette &palette, bool enabled)
virtual void drawFocus(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect) const
Renders the region within the rectangle specified by rect, indicating that it has the focus,...
QItemDelegate(QObject *parent=nullptr)
Constructs an item delegate with the given parent.
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override
\reimp
void setItemEditorFactory(QItemEditorFactory *factory)
Sets the editor factory to be used by the item delegate to be the factory specified.
void doLayout(const QStyleOptionViewItem &option, QRect *checkRect, QRect *iconRect, QRect *textRect, bool hint) const
bool eventFilter(QObject *object, QEvent *event) override
Returns true if the given editor is a valid QWidget and the given event is handled; otherwise returns...
virtual void drawDecoration(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, const QPixmap &pixmap) const
Renders the decoration pixmap within the rectangle specified by rect using the given painter and styl...
void drawBackground(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Returns the widget used to edit the item specified by index for editing.
QItemEditorFactory * itemEditorFactory() const
Returns the editor factory used by the item delegate.
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Updates the editor for the item specified by index according to the style option given.
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
Returns the size needed by the delegate to display the item specified by index, taking into account t...
QPixmap decoration(const QStyleOptionViewItem &option, const QVariant &variant) const
QStyleOptionViewItem setOptions(const QModelIndex &index, const QStyleOptionViewItem &option) const
The QItemEditorFactory class provides widgets for editing item data in views and delegates.
static const QItemEditorFactory * defaultFactory()
Returns the default item editor factory.
virtual QWidget * createEditor(int userType, QWidget *parent) const
Creates an editor widget with the given parent for the specified userType of data,...
The QKeyEvent class describes a key event.
int key() const
Returns the code of the key that was pressed or released.
QObject * parent() const
Returns a pointer to the parent object.
The QPainter class performs low-level painting on widgets and other paint devices.
void drawRect(const QRectF &rect)
Draws the current rectangle with the current pen and brush.
void setClipRect(const QRectF &, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip region to the given rectangle using the given clip operation.
void setPen(const QColor &color)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void setBrushOrigin(int x, int y)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void restore()
Restores the current painter state (pops a saved state off the stack).
void setCompositionMode(CompositionMode mode)
Sets the composition mode to the given mode.
void save()
Saves the current painter state (pushes the state onto a stack).
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device.
QPoint brushOrigin() const
Returns the currently set brush origin.
@ CompositionMode_SourceAtop
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
The QPalette class contains color groups for each widget state.
void setBrush(ColorRole cr, const QBrush &brush)
Sets the brush for the given color role to the specified brush for all groups in the palette.
ColorGroup
\value Disabled \value Active \value Inactive \value Normal synonym for Active
static bool find(const QString &key, QPixmap *pixmap)
Looks for a cached pixmap associated with the given key in the cache.
static int cacheLimit()
Returns the cache limit (in kilobytes).
static bool insert(const QString &key, const QPixmap &pixmap)
Inserts a copy of the pixmap pixmap associated with the key into the cache.
static void setCacheLimit(int)
Sets the cache limit to n kilobytes.
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
\inmodule QtCore\reentrant
constexpr QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
constexpr void adjust(int x1, int y1, int x2, int y2) noexcept
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
constexpr int height() const noexcept
Returns the height of the rectangle.
constexpr bool isValid() const noexcept
Returns true if the rectangle is valid, otherwise returns false.
QRect intersected(const QRect &other) const noexcept
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
constexpr QRect adjusted(int x1, int y1, int x2, int y2) const noexcept
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
constexpr void setRect(int x, int y, int w, int h) noexcept
Sets the coordinates of the rectangle's top-left corner to ({x}, {y}), and its size to the given widt...
constexpr QSize size() const noexcept
Returns the size of the rectangle.
constexpr int width() const noexcept
Returns the width of the rectangle.
constexpr void setHeight(int h) noexcept
Sets the height of the rectangle to the given height.
QPointF position() const
Returns the position of the point in this event, relative to the widget or item that received the eve...
Qt::MouseButton button() const
Returns the button that caused the event.
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
constexpr int & rwidth() noexcept
Returns a reference to the width.
constexpr void setHeight(int h) noexcept
Sets the height to the given height.
QVariant data(const QModelIndex &item, int role=Qt::DisplayRole) const override
Returns the value for the specified item and role.
\macro QT_RESTRICTED_CAST_FROM_ASCII
qsizetype indexOf(QLatin1StringView s, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
QString & replace(qsizetype i, qsizetype len, QChar after)
QString mid(qsizetype position, qsizetype n=-1) const &
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
QChar * data()
Returns a pointer to the data stored in the QString.
\variable QStyleOption::palette
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
@ State_KeyboardFocusChange
static Qt::Alignment visualAlignment(Qt::LayoutDirection direction, Qt::Alignment alignment)
Transforms an alignment of Qt::AlignLeft or Qt::AlignRight without Qt::AlignAbsolute into Qt::AlignLe...
static QRect alignedRect(Qt::LayoutDirection direction, Qt::Alignment alignment, const QSize &size, const QRect &rectangle)
Returns a new rectangle of the specified size that is aligned to the given rectangle according to the...
virtual QRect subElementRect(SubElement subElement, const QStyleOption *option, const QWidget *widget=nullptr) const =0
Returns the sub-area for the given element as described in the provided style option.
@ PE_IndicatorItemViewItemCheck
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const =0
Returns the value of the given pixel metric.
@ SE_ItemViewItemCheckIndicator
virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=nullptr) const =0
Draws the given primitive element with the provided painter using the style options specified by opti...
QTextLine createLine()
Returns a new text line to be laid out if there is text to be inserted into the layout; otherwise ret...
void beginLayout()
Begins the layout process.
void endLayout()
Ends the layout process.
void * data()
Returns a pointer to the contained object as a generic void* that can be written to.
struct wl_display * display
Combined button and popup list for selecting options.
static QString wrapText(const QString &names, int optionNameMaxWidth, const QString &description)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static QString qPixmapSerial(quint64 i, bool enabled)
static ControlElement< T > * ptr(QWidget *widget)
constexpr const T & qMax(const T &a, const T &b)
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLfloat GLfloat GLfloat GLfloat h
GLdouble GLdouble GLdouble GLdouble q
static const struct TessellationWindingOrderTab cw[]
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
unsigned long long quint64
QSqlQueryModel * model
[16]
QItemEditorFactory * factory