| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include "qstyleditemdelegate.h"
|
|---|
| 43 |
|
|---|
| 44 | #ifndef QT_NO_ITEMVIEWS
|
|---|
| 45 | #include <qabstractitemmodel.h>
|
|---|
| 46 | #include <qapplication.h>
|
|---|
| 47 | #include <qbrush.h>
|
|---|
| 48 | #include <qlineedit.h>
|
|---|
| 49 | #include <qtextedit.h>
|
|---|
| 50 | #include <qplaintextedit.h>
|
|---|
| 51 | #include <qpainter.h>
|
|---|
| 52 | #include <qpalette.h>
|
|---|
| 53 | #include <qpoint.h>
|
|---|
| 54 | #include <qrect.h>
|
|---|
| 55 | #include <qsize.h>
|
|---|
| 56 | #include <qstyle.h>
|
|---|
| 57 | #include <qdatetime.h>
|
|---|
| 58 | #include <qstyleoption.h>
|
|---|
| 59 | #include <qevent.h>
|
|---|
| 60 | #include <qpixmap.h>
|
|---|
| 61 | #include <qbitmap.h>
|
|---|
| 62 | #include <qpixmapcache.h>
|
|---|
| 63 | #include <qitemeditorfactory.h>
|
|---|
| 64 | #include <private/qitemeditorfactory_p.h>
|
|---|
| 65 | #include <qmetaobject.h>
|
|---|
| 66 | #include <qtextlayout.h>
|
|---|
| 67 | #include <private/qobject_p.h>
|
|---|
| 68 | #include <private/qdnd_p.h>
|
|---|
| 69 | #include <private/qtextengine_p.h>
|
|---|
| 70 | #include <private/qlayoutengine_p.h>
|
|---|
| 71 | #include <qdebug.h>
|
|---|
| 72 | #include <qlocale.h>
|
|---|
| 73 | #include <qdialog.h>
|
|---|
| 74 | #include <qtableview.h>
|
|---|
| 75 |
|
|---|
| 76 | #include <limits.h>
|
|---|
| 77 |
|
|---|
| 78 | QT_BEGIN_NAMESPACE
|
|---|
| 79 |
|
|---|
| 80 | class QStyledItemDelegatePrivate : public QObjectPrivate
|
|---|
| 81 | {
|
|---|
| 82 | Q_DECLARE_PUBLIC(QStyledItemDelegate)
|
|---|
| 83 |
|
|---|
| 84 | public:
|
|---|
| 85 | QStyledItemDelegatePrivate() : factory(0) { }
|
|---|
| 86 |
|
|---|
| 87 | static const QWidget *widget(const QStyleOptionViewItem &option)
|
|---|
| 88 | {
|
|---|
| 89 | if (const QStyleOptionViewItemV3 *v3 = qstyleoption_cast<const QStyleOptionViewItemV3 *>(&option))
|
|---|
| 90 | return v3->widget;
|
|---|
| 91 | return 0;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | const QItemEditorFactory *editorFactory() const
|
|---|
| 95 | {
|
|---|
| 96 | return factory ? factory : QItemEditorFactory::defaultFactory();
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | void _q_commitDataAndCloseEditor(QWidget *editor)
|
|---|
| 100 | {
|
|---|
| 101 | Q_Q(QStyledItemDelegate);
|
|---|
| 102 | emit q->commitData(editor);
|
|---|
| 103 | emit q->closeEditor(editor, QAbstractItemDelegate::SubmitModelCache);
|
|---|
| 104 | }
|
|---|
| 105 | QItemEditorFactory *factory;
|
|---|
| 106 | };
|
|---|
| 107 |
|
|---|
| 108 | /*!
|
|---|
| 109 | \class QStyledItemDelegate
|
|---|
| 110 |
|
|---|
| 111 | \brief The QStyledItemDelegate class provides display and editing facilities for
|
|---|
| 112 | data items from a model.
|
|---|
| 113 |
|
|---|
| 114 | \ingroup model-view
|
|---|
| 115 |
|
|---|
| 116 | \since 4.4
|
|---|
| 117 |
|
|---|
| 118 | When displaying data from models in Qt item views, e.g., a
|
|---|
| 119 | QTableView, the individual items are drawn by a delegate. Also,
|
|---|
| 120 | when an item is edited, it provides an editor widget, which is
|
|---|
| 121 | placed on top of the item view while editing takes place.
|
|---|
| 122 | QStyledItemDelegate is the default delegate for all Qt item
|
|---|
| 123 | views, and is installed upon them when they are created.
|
|---|
| 124 |
|
|---|
| 125 | The QStyledItemDelegate class is one of the \l{Model/View Classes}
|
|---|
| 126 | and is part of Qt's \l{Model/View Programming}{model/view
|
|---|
| 127 | framework}. The delegate allows the display and editing of items
|
|---|
|
|---|