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);
133 rect.setWidth(
rect.width() - checkRect.
width() - 2 * textMargin);
151 line.setLineWidth(lineWidth);
154 widthUsed =
qMax(widthUsed,
line.naturalTextWidth());
319 return d->clipPainting;
325 d->clipPainting = clip;
358 const QStyleOptionViewItem &
option,
376 QRect decorationRect;
378 if (
value.isValid()) {
381 if (
value.userType() == QMetaType::QIcon) {
382 d->tmp.icon = qvariant_cast<QIcon>(
value);
383 d->tmp.mode =
d->iconMode(
option.state);
384 d->tmp.state =
d->iconState(
option.state);
386 d->tmp.mode,
d->tmp.state);
394 decorationRect =
QRect();
400 if (
value.isValid()) {
401 checkState = QtPrivate::legacyEnumValueFromModelData<Qt::CheckState>(
value);
410 displayRect =
d->displayRect(
index,
opt, decorationRect, checkRect);
415 doLayout(
opt, &checkRect, &decorationRect, &displayRect,
false);
445 return qvariant_cast<QSize>(
value);
450 doLayout(
option, &checkRect, &decorationRect, &displayRect,
true);
452 return (decorationRect|displayRect|checkRect).size();
464 const QStyleOptionViewItem &,
468 if (!
index.isValid())
492 QByteArray n = editor->metaObject()->userProperty().name();
497 editor->setProperty(
n,
v);
519 QByteArray n = editor->metaObject()->userProperty().name();
521 n =
d->editorFactory()->valuePropertyName(
533 const QStyleOptionViewItem &
option,
545 opt.showDecorationSelected =
true;
614 d->textOption.setTextDirection(
option.direction);
616 d->textLayout.setTextOption(
d->textOption);
617 d->textLayout.setFont(
option.font);
641 d->textLayout.setText(elided);
671 if (!
d->tmp.icon.isNull()) {
673 d->tmp.mode,
d->tmp.state);
695 const QStyleOptionViewItem &
option,
702 o.QStyleOption::operator=(
option);
722 const QStyleOptionViewItem &
option,
758 const QStyleOptionViewItem &
option,
794 const bool hasCheck = checkRect->
isValid();
795 const bool hasPixmap = pixmapRect->
isValid();
797 const bool hasMargin = (hasText | hasPixmap | hasCheck);
798 const int frameHMargin = hasMargin ?
800 const int textMargin = hasText ? frameHMargin : 0;
801 const int pixmapMargin = hasPixmap ? frameHMargin : 0;
802 const int checkMargin = hasCheck ? frameHMargin : 0;
803 const int x =
option.rect.left();
804 const int y =
option.rect.top();
815 pm = pixmapRect->
size();
816 pm.
rwidth() += 2 * pixmapMargin;
820 if (
option.decorationPosition == QStyleOptionViewItem::Left
821 ||
option.decorationPosition == QStyleOptionViewItem::Right) {
834 cw = checkRect->
width() + 2 * checkMargin;
847 switch (
option.decorationPosition) {
848 case QStyleOptionViewItem::Top: {
861 case QStyleOptionViewItem::Bottom: {
874 case QStyleOptionViewItem::Left: {
883 case QStyleOptionViewItem::Right: {
893 qWarning(
"doLayout: decoration position is invalid");
900 checkRect->
size(), check);
904 if (
option.showDecorationSelected)
928 case QMetaType::QIcon: {
932 case QMetaType::QColor: {
940 return qvariant_cast<QPixmap>(
variant);
946 ushort arr[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
'-',
ushort(
'0' +
enabled) };
952 *(--
ptr) =
'0' +
i % 16;
975 color.setAlphaF(0.3f);
983 const int n = (
img.sizeInBytes() >> 10) + 1;
1004 switch (
value.userType()) {
1007 case QMetaType::QPixmap: {
1010 case QMetaType::QImage: {
1013 case QMetaType::QIcon: {
1019 case QMetaType::QColor:
1021 case QMetaType::QString:
1040 if (
value.isValid()) {
1060 d->textLayout.setTextOption(
d->textOption);
1061 d->textLayout.setFont(
font);
1067 return QRect(0, 0,
size.width() + 2 * textMargin,
size.height());
1101 return d->editorEventFilter(
object,
event);
1110 const QStyleOptionViewItem &
option,
1124 if (!
value.isValid())
1164 const QStyleOptionViewItem &
option)
const
1170 if (
value.isValid()){
1171 opt.font = qvariant_cast<QFont>(
value).resolve(
opt.font);
1177 if (
value.isValid())
1178 opt.displayAlignment = QtPrivate::legacyFlagValueFromModelData<Qt::Alignment>(
value);
1193#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.
\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
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.
constexpr bool isNull() const noexcept
Returns true if the rectangle is a null rectangle, 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.
bool contains(const QRect &r, bool proper=false) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
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 qreal width() const noexcept
Returns the width.
constexpr qreal height() const noexcept
Returns the height.
constexpr QSize boundedTo(const QSize &) const noexcept
Returns a size holding the minimum width and height of this size and the given otherSize.
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
QString & replace(qsizetype i, qsizetype len, QChar after)
QString mid(qsizetype position, qsizetype n=-1) const
Returns a string that contains n characters of this string, starting at the specified position index.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
static QString static QString qsizetype indexOf(QChar c, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
\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
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent