44 #ifndef QT_NO_ITEMVIEWS 66 #include <private/qobject_p.h> 67 #include <private/qdnd_p.h> 68 #include <private/qtextengine_p.h> 105 for (
int i = 0; i < text.
count(); ++i)
106 if (text.
at(i) == nl)
142 emit q->commitData(editor);
179 return QSizeF(widthUsed, height);
349 return d->clipPainting;
355 d->clipPainting = clip;
388 text = replaceNewLine(value.
toString());
430 opt.widget = v3 ? v3->
widget : 0;
442 QRect decorationRect;
449 d->tmp.mode =
d->iconMode(option.
state);
450 d->tmp.state =
d->iconState(option.
state);
452 d->tmp.mode,
d->tmp.state);
460 decorationRect =
QRect();
476 checkRect =
check(opt, opt.rect, value);
481 doLayout(opt, &checkRect, &decorationRect, &displayRect,
false);
486 drawCheck(painter, opt, checkRect, checkState);
510 return qvariant_cast<QSize>(value);
515 doLayout(option, &checkRect, &decorationRect, &displayRect,
true);
517 return (decorationRect|displayRect|checkRect).size();
554 #ifdef QT_NO_PROPERTIES 567 if (n ==
"dateTime") {
570 else if (editor->
inherits(
"QDateEdit"))
576 n =
d->editorFactory()->valuePropertyName(static_cast<QVariant::Type>(v.
userType()));
599 #ifdef QT_NO_PROPERTIES 609 n =
d->editorFactory()->valuePropertyName(
635 doLayout(opt, &checkRect, &pixmapRect, &textRect,
false);
700 QRect textRect = rect.
adjusted(textMargin, 0, -textMargin, 0);
703 d->textOption.setTextDirection(option.
direction);
705 d->textLayout.setTextOption(
d->textOption);
706 d->textLayout.setFont(option.
font);
709 QSizeF textLayoutSize =
d->doTextLayout(textRect.
width());
730 d->textLayout.setText(elided);
731 textLayoutSize =
d->doTextLayout(textRect.
width());
736 layoutSize, textRect);
758 if (!
d->tmp.icon.isNull()) {
760 d->tmp.mode,
d->tmp.state);
789 o.QStyleOption::operator=(option);
863 painter->
fillRect(option.
rect, qvariant_cast<QBrush>(value));
880 Q_ASSERT(checkRect && pixmapRect && textRect);
884 const bool hasCheck = checkRect->
isValid();
885 const bool hasPixmap = pixmapRect->
isValid();
886 const bool hasText = textRect->
isValid();
894 textRect->
adjust(-textMargin, 0, textMargin, 0);
895 if (textRect->
height() == 0 && (!hasPixmap || !hint)) {
902 pm = pixmapRect->
size();
903 pm.
rwidth() += 2 * pixmapMargin;
921 cw = checkRect->
width() + 2 * checkMargin;
924 check.
setRect(x + w - cw, y, cw, h);
926 check.
setRect(x + checkMargin, y, cw, h);
980 qWarning(
"doLayout: decoration position is invalid");
981 decoration = *pixmapRect;
1017 switch (variant.
type()) {
1024 pixmap.
fill(qvariant_cast<QColor>(variant));
1036 ushort arr[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
'-',
ushort(
'0' + enabled) };
1042 *(--
ptr) =
'0' + i % 16;
1095 return check(option, option.
rect, value);
1097 switch (value.
type()) {
1101 return QRect(
QPoint(0, 0), qvariant_cast<QPixmap>(value).size());
1103 return QRect(
QPoint(0, 0), qvariant_cast<QImage>(value).size());
1147 opt.QStyleOption::operator=(option);
1148 opt.
rect = bounding;
1164 d->textLayout.setTextOption(
d->textOption);
1165 d->textLayout.setFont(font);
1208 switch (static_cast<QKeyEvent *>(event)->key()) {
1219 #ifndef QT_NO_TEXTEDIT 1220 if (qobject_cast<QTextEdit *>(editor) || qobject_cast<QPlainTextEdit *>(editor))
1225 #endif // QT_NO_TEXTEDIT 1226 #ifndef QT_NO_LINEEDIT 1227 if (
QLineEdit *e = qobject_cast<QLineEdit*>(editor))
1228 if (!e->hasAcceptableInput())
1230 #endif // QT_NO_LINEEDIT 1253 #ifndef QT_NO_DRAGANDDROP 1285 Qt::ItemFlags flags = model->
flags(index);
1301 doLayout(option, &checkRect, &emptyRect, &emptyRect,
false);
1355 #include "moc_qitemdelegate.cpp" 1357 #endif // QT_NO_ITEMVIEWS The QVariant class acts like a union for the most common Qt data types.
static int cacheLimit()
Returns the cache limit (in kilobytes).
The QPainter class performs low-level painting on widgets and other paint devices.
The QColor class provides colors based on RGB, HSV or CMYK values.
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...
const QWidget * widget(const QStyleOptionViewItem &option) const
QImage toImage() const
Converts the pixmap to a QImage.
The QAbstractItemDelegate class is used to display and edit data items from a model.
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.
The QKeyEvent class describes a key event.
QRect adjusted(int x1, int y1, int x2, int y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
void setHeight(int h)
Sets the height of the rectangle to the given height.
QFont font
the font used for the item
Qt::Alignment decorationAlignment
the alignment of the decoration for the item
The QFontMetrics class provides font metrics information.
Q_GUI_EXPORT qint64 qt_pixmap_id(const QPixmap &pixmap)
QRect textRectangle(QPainter *painter, const QRect &rect, const QFont &font, const QString &text) const
The QItemEditorFactory class provides widgets for editing item data in views and delegates.
#define QT_END_NAMESPACE
This macro expands to.
void setPosition(const QPointF &pos)
Moves the line to position pos.
QPointer< QWidget > widget
QSize size() const
Returns the size of the pixmap.
const QChar at(int i) const
Returns the character at the given index position in the string.
void setItemEditorFactory(QItemEditorFactory *factory)
Sets the editor factory to be used by the item delegate to be the factory specified.
QVariant data(int role=Qt::DisplayRole) const
Returns the data for the given role for the item referred to by the index.
QSizeF doTextLayout(int lineWidth) const
bool isNull() const
Returns true if this is a NULL variant, false otherwise.
QStyle::State state
the style flags that are used when drawing the control
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...
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
qreal width() const
Returns the width.
The QByteArray class provides an array of bytes.
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...
The QPointF class defines a point in the plane using floating point precision.
qreal height() const
Returns the height.
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
Gets data from the editor widget and stores it in the specified model at the item index...
The QTextLine class represents a line of text inside a QTextLayout.
void restore()
Restores the current painter state (pops a saved state off the stack).
The QStyleOptionViewItemV4 class is used to describe the parameters necessary for drawing a frame in ...
Position decorationPosition
the position of the decoration for the item
bool setProperty(const char *name, const QVariant &value)
Sets the value of the object's name property to value.
State
This enum describes the state for which a pixmap is intended to be used.
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
QDateTime toDateTime() const
Returns the variant as a QDateTime if the variant has type() DateTime , Date , or String ; otherwise ...
static QString qPixmapSerial(quint64 i, bool enabled)
int left() const
Returns the x-coordinate of the rectangle's left edge.
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Sets the role data for the item at index to value.
int byteCount() const
Returns the number of bytes occupied by the image data.
int width() const
Returns the width of the rectangle.
Qt::TextElideMode textElideMode
where ellipsis should be added for text that is too long to fit into an item
#define Q_ARG(type, data)
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
Reimplemented Function
QRect intersected(const QRect &other) const
Returns the intersection of this rectangle and the given rectangle.
static QStyle * style()
Returns the application's style object.
void setLineWidth(qreal width)
Lays out the line with the given width.
void doLayout(const QStyleOptionViewItem &option, QRect *checkRect, QRect *iconRect, QRect *textRect, bool hint) const
int height() const
Returns the height of the rectangle.
The QString class provides a Unicode character string.
QFontMetrics fontMetrics
the font metrics that should be used when drawing text in the control
void setHeight(int h)
Sets the height to the given height.
T * qobject_cast(QObject *object)
QItemDelegate(QObject *parent=0)
Constructs an item delegate with the given parent.
The QVector class is a template class that provides a dynamic array.
The QObject class is the base class of all Qt objects.
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
const QColor & color(ColorGroup cg, ColorRole cr) const
Returns the color in the specified color group, used for the given color role.
void setBrushOrigin(int x, int y)
Sets the brush's origin to point (x, y).
bool isValid() const
Returns true if this text line is valid; otherwise returns false.
QSize boundedTo(const QSize &) const
Returns a size holding the minimum width and height of this size and the given otherSize.
The QSizeF class defines the size of a two-dimensional object using floating point precision...
The QChar class provides a 16-bit Unicode character.
QString toString(qlonglong i) const
Returns a localized string representation of i.
void save()
Saves the current painter state (pushes the state onto a stack).
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
QString elidedText(const QString &text, Qt::TextElideMode mode, int width, int flags=0) const
If the string text is wider than width, returns an elided version of the string (i.
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
static QPixmap * find(const QString &key)
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...
The QStyleOptionViewItemV2 class is used to describe the parameters necessary for drawing a frame in ...
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
QColor backgroundColor
the background color on which the focus rectangle is being drawn
QIcon::State iconState(QStyle::State state) const
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index.
int width() const
Returns the width.
#define QT_BEGIN_NAMESPACE
This macro expands to.
qlonglong toLongLong(bool *ok=0) const
Returns the variant as a long long int if the variant has type() LongLong , Bool , ByteArray , Char , Double , Int , String , UInt , or ULongLong ; otherwise returns 0.
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...
Q_GUI_EXPORT EGLDisplay display()
The QStyleOptionViewItemV3 class is used to describe the parameters necessary for drawing a frame in ...
ViewItemFeatures features
a bitwise OR of the features that describe this view item
QPixmap decoration(const QStyleOptionViewItem &option, const QVariant &variant) const
Returns the pixmap used to decorate the root of the item view.
QPoint brushOrigin() const
Returns the currently set brush origin.
bool canConvert(Type t) const
Returns true if the variant's type can be cast to the requested type, t.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QSize size() const
Returns the size of the rectangle.
Mode
This enum type describes the mode for which a pixmap is intended to be used.
void adjust(int x1, int y1, int x2, int y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
Updates the editor for the item specified by index according to the style option given.
virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const =0
Draws the given primitive element with the provided painter using the style options specified by opti...
The QStyleOptionFocusRect class is used to describe the parameters for drawing a focus rectangle with...
qulonglong toULongLong(bool *ok=0) const
Returns the variant as as an unsigned long long int if the variant has type() ULongLong ...
Q_CORE_EXPORT void qWarning(const char *,...)
bool showDecorationSelected
whether the decoration should be highlighted on selected items
The QImage class provides a hardware-independent image representation that allows direct access to th...
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Type
This enum type defines the types of variable that a QVariant can contain.
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
Returns the widget used to edit the item specified by index for editing.
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const =0
Returns the data stored under the given role for the item referred to by the index.
const T * ptr(const T &t)
void setClipping(bool clip)
bool inherits(const char *classname) const
Returns true if this object is an instance of a class that inherits className or a QObject subclass t...
Qt::MouseButton button() const
Returns the button that caused the event.
void commitData(QWidget *editor)
This signal must be emitted when the editor widget has completed editing the data, and wants to write it back into the model.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
void _q_commitDataAndCloseEditor(QWidget *editor)
bool contains(const QPoint &p, bool proper=false) const
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false...
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
QStyleOptionViewItem setOptions(const QModelIndex &index, const QStyleOptionViewItem &option) const
The QAbstractItemModel class provides the abstract interface for item model classes.
The QMouseEvent class contains parameters that describe a mouse event.
static QDragManager * self()
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
QDate date() const
Returns the date part of the datetime.
QPalette palette
the palette that should be used when painting the control
The QBrush class defines the fill pattern of shapes drawn by QPainter.
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
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...
static QString valueToText(const QVariant &value, const QStyleOptionViewItemV4 &option)
QDate toDate() const
Returns the variant as a QDate if the variant has type() Date , DateTime , or String ; otherwise retu...
int top() const
Returns the y-coordinate of the rectangle's top edge.
int width() const
Returns the width of the image.
The QTextLayout class is used to lay out and render text.
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...
void setEditorData(QWidget *editor, const QModelIndex &index) const
Sets the data to be displayed and edited by the editor from the data model item specified by the mode...
int userType() const
Returns the storage type of the value stored in the variant.
QIcon::Mode iconMode(QStyle::State state) const
#define Q_DECLARE_PUBLIC(Class)
virtual QRect subElementRect(SubElement subElement, const QStyleOption *option, const QWidget *widget=0) const =0
Returns the sub-area for the given element as described in the provided style option.
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
QRect rect(const QStyleOptionViewItem &option, const QModelIndex &index, int role) const
const QItemEditorFactory * editorFactory() const
int right() const
Returns the x-coordinate of the rectangle's right edge.
void setCompositionMode(CompositionMode mode)
Sets the composition mode to the given mode.
void closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint=NoHint)
This signal is emitted when the user has finished editing an item using the specified editor...
void setAlphaF(qreal alpha)
Sets the alpha of this color to alpha.
QRect check(const QStyleOptionViewItem &option, const QRect &bounding, const QVariant &variant) const
Note that on Mac, if /usr/include/AssertMacros.
The QFont class specifies a font used for drawing text.
T qstyleoption_cast(const QStyleOption *opt)
QTextLine createLine()
Returns a new text line to be laid out if there is text to be inserted into the layout; otherwise ret...
qreal naturalTextWidth() const
Returns the width of the line that is occupied by text.
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.
Type type() const
Returns the storage type of the value stored in the variant.
The QItemDelegate class provides display and editing facilities for data items from a model...
QObject * parent() const
Returns a pointer to the parent object.
void setRect(int x, int y, int w, int h)
Sets the coordinates of the rectangle's top-left corner to ({x}, {y}), and its size to the given widt...
Qt::Alignment displayAlignment
the alignment of the display value for the item
static bool insert(const QString &key, const QPixmap &pixmap)
Inserts a copy of the pixmap pixmap associated with the key into the cache.
The QPoint class defines a point in the plane using integer precision.
QPixmap * selected(const QPixmap &pixmap, const QPalette &palette, bool enabled) const
Returns the selected version of the given pixmap using the given palette.
The QModelIndex class is used to locate data in a data model.
QSize decorationSize
the size of the decoration for the item
~QItemDelegate()
Destroys the item delegate.
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
Returns the size needed by the delegate to display the item specified by index, taking into account t...
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
float toFloat(bool *ok=0) const
Returns the variant as a float if the variant has type() Double , QMetaType::Float ...
void setWidth(int w)
Sets the width of the rectangle to the given width.
void setPen(const QColor &color)
Sets the painter's pen to have style Qt::SolidLine, width 0 and the specified color.
int height() const
Returns the height.
Qt::LayoutDirection direction
the text layout direction that should be used when drawing text in the control
The QRect class defines a rectangle in the plane using integer precision.
static void setCacheLimit(int)
Sets the cache limit to n kilobytes.
The QTextOption class provides a description of general rich text properties.
int height() const
Returns the height of the image.
T qvariant_cast(const QVariant &)
double toDouble(bool *ok=0) const
Returns the variant as a double if the variant has type() Double , QMetaType::Float ...
void drawRect(const QRectF &rect)
Draws the current rectangle with the current pen and brush.
The QLineEdit widget is a one-line text editor.
QVariant property(const char *name) const
Returns the value of the object's name property.
The QPixmap class is an off-screen image representation that can be used as a paint device...
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...
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...
bool eventFilter(QObject *object, QEvent *event)
Returns true if the given editor is a valid QWidget and the given event is handled; otherwise returns...
static const QItemEditorFactory * defaultFactory()
Returns the default item editor factory.
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
The QSize class defines the size of a two-dimensional object using integer point precision.
QTime time() const
Returns the time part of the datetime.
QTime toTime() const
Returns the variant as a QTime if the variant has type() Time , DateTime , or String ; otherwise retu...
QItemEditorFactory * itemEditorFactory() const
Returns the editor factory used by the item delegate.
static QString replaceNewLine(QString text)
void endLayout()
Ends the layout process.
The QStyleOptionViewItem class is used to describe the parameters used to draw an item in a view widg...
void drawBackground(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Renders the item background for the given index, using the given painter and style option...
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
int height() const
Returns the height of the font.
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
QRect textLayoutBounds(const QStyleOptionViewItemV2 &options) const
static const KeyPair *const end
The QEvent class is the base class of all event classes.
Type type() const
Returns the event type.
static QWidget * focusWidget()
Returns the application widget that has the keyboard input focus, or 0 if no widget in this applicati...
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
struct QItemDelegatePrivate::Icon tmp
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Renders the delegate using the given painter and style option for the item specified by index...
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
QRect rect
the area that should be used for various calculations and painting
qreal height() const
Returns the line's height.
void beginLayout()
Begins the layout process.
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
int & rwidth()
Returns a reference to the width.
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
virtual QWidget * createEditor(QVariant::Type type, QWidget *parent) const
Creates an editor widget with the given parent for the specified type of data, and returns it as a QW...
QPoint topLeft() const
Returns the position of the rectangle's top-left corner.
The QPalette class contains color groups for each widget state.
The QIcon class provides scalable icons in different modes and states.