Qt 4.8
qabstractitemdelegate.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qabstractitemdelegate.h"
43 
44 #ifndef QT_NO_ITEMVIEWS
45 #include <qabstractitemmodel.h>
46 #include <qabstractitemview.h>
47 #include <qfontmetrics.h>
48 #include <qwhatsthis.h>
49 #include <qtooltip.h>
50 #include <qevent.h>
51 #include <qstring.h>
52 #include <qdebug.h>
53 #include <private/qtextengine_p.h>
54 
56 
185  : QObject(parent)
186 {
187 
188 }
189 
199  : QObject(dd, parent)
200 {
201 
202 }
203 
208 {
209 
210 }
211 
253  const QStyleOptionViewItem &,
254  const QModelIndex &) const
255 {
256  return 0;
257 }
258 
270  const QModelIndex &) const
271 {
272  // do nothing
273 }
274 
286  const QModelIndex &) const
287 {
288  // do nothing
289 }
290 
302  const QStyleOptionViewItem &,
303  const QModelIndex &) const
304 {
305  // do nothing
306 }
307 
323  const QStyleOptionViewItem &,
324  const QModelIndex &)
325 {
326  // do nothing
327  return false;
328 }
329 
348  Qt::TextElideMode mode, const QString &text)
349 {
350  return fontMetrics.elidedText(text, mode, width);
351 }
352 
371 // ### Qt 5: Make this a virtual non-slot function
373  QAbstractItemView *view,
374  const QStyleOptionViewItem &option,
375  const QModelIndex &index)
376 {
377  Q_UNUSED(option);
378 
379  if (!event || !view)
380  return false;
381  switch (event->type()) {
382 #ifndef QT_NO_TOOLTIP
383  case QEvent::ToolTip: {
384  QHelpEvent *he = static_cast<QHelpEvent*>(event);
385  QVariant tooltip = index.data(Qt::ToolTipRole);
386  if (tooltip.canConvert<QString>()) {
387  QToolTip::showText(he->globalPos(), tooltip.toString(), view);
388  return true;
389  }
390  break;}
391 #endif
392 #ifndef QT_NO_WHATSTHIS
393  case QEvent::QueryWhatsThis: {
394  if (index.data(Qt::WhatsThisRole).isValid())
395  return true;
396  break; }
397  case QEvent::WhatsThis: {
398  QHelpEvent *he = static_cast<QHelpEvent*>(event);
399  QVariant whatsthis = index.data(Qt::WhatsThisRole);
400  if (whatsthis.canConvert<QString>()) {
401  QWhatsThis::showText(he->globalPos(), whatsthis.toString(), view);
402  return true;
403  }
404  break ; }
405 #endif
406  default:
407  break;
408  }
409  return false;
410 }
411 
413 
414 #endif // QT_NO_ITEMVIEWS
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
virtual void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
Updates the geometry of the editor for the item with the given index, according to the rectangle spec...
QVariant data(int role=Qt::DisplayRole) const
Returns the data for the given role for the item referred to by the index.
QAbstractItemDelegate(QObject *parent=0)
Creates a new abstract item delegate with the given parent.
TextElideMode
Definition: qnamespace.h:263
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
bool helpEvent(QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index)
Whenever a help event occurs, this function is called with the event view option and the index that c...
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
Sets the data for the item at the given index in the model to the contents of the given editor...
virtual ~QAbstractItemDelegate()
Destroys the abstract item delegate.
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.
virtual bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
When editing of an item starts, this function is called with the event that triggered the editing...
virtual QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
Returns the editor to be used for editing the data item with the given index.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
bool canConvert(Type t) const
Returns true if the variant&#39;s type can be cast to the requested type, t.
Definition: qvariant.cpp:2886
The QAbstractItemModel class provides the abstract interface for item model classes.
The QAbstractItemView class provides the basic functionality for item view classes.
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
The QModelIndex class is used to locate data in a data model.
const QPoint & globalPos() const
Returns the mouse cursor position when the event was generated in global coordinates.
Definition: qevent.h:598
quint16 index
The QStyleOptionViewItem class is used to describe the parameters used to draw an item in a view widg...
Definition: qstyleoption.h:539
virtual void setEditorData(QWidget *editor, const QModelIndex &index) const
Sets the contents of the given editor to the data for the item at the given index.
static void showText(const QPoint &pos, const QString &text, QWidget *w=0)
Shows text as a "What&#39;s This?" window, at global position pos.
Definition: qwhatsthis.cpp:754
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
static QString elidedText(const QFontMetrics &fontMetrics, int width, Qt::TextElideMode mode, const QString &text)
Use QFontMetrics::elidedText() instead.
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
#define text
Definition: qobjectdefs.h:80
static void showText(const QPoint &pos, const QString &text, QWidget *w=0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qtooltip.cpp:497
The QHelpEvent class provides an event that is used to request helpful information about a particular...
Definition: qevent.h:586