summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews/qitemdelegate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/itemviews/qitemdelegate.cpp')
-rw-r--r--src/widgets/itemviews/qitemdelegate.cpp109
1 files changed, 3 insertions, 106 deletions
diff --git a/src/widgets/itemviews/qitemdelegate.cpp b/src/widgets/itemviews/qitemdelegate.cpp
index ef14ab8ed5..9303800e87 100644
--- a/src/widgets/itemviews/qitemdelegate.cpp
+++ b/src/widgets/itemviews/qitemdelegate.cpp
@@ -36,13 +36,7 @@
#ifndef QT_NO_ITEMVIEWS
#include <qabstractitemmodel.h>
#include <qapplication.h>
-#include <qpa/qplatformintegration.h>
-#include <qpa/qplatformdrag.h>
-#include <private/qguiapplication_p.h>
#include <qbrush.h>
-#include <qlineedit.h>
-#include <qtextedit.h>
-#include <qplaintextedit.h>
#include <qpainter.h>
#include <qpalette.h>
#include <qpoint.h>
@@ -58,8 +52,7 @@
#include <qitemeditorfactory.h>
#include <qmetaobject.h>
#include <qtextlayout.h>
-#include <private/qobject_p.h>
-#include <private/qdnd_p.h>
+#include <private/qabstractitemdelegate_p.h>
#include <private/qtextengine_p.h>
#include <qdebug.h>
#include <qlocale.h>
@@ -74,7 +67,7 @@
QT_BEGIN_NAMESPACE
-class QItemDelegatePrivate : public QObjectPrivate
+class QItemDelegatePrivate : public QAbstractItemDelegatePrivate
{
Q_DECLARE_PUBLIC(QItemDelegate)
@@ -105,9 +98,6 @@ public:
static QString valueToText(const QVariant &value, const QStyleOptionViewItem &option);
- bool tryFixup(QWidget *editor);
- void _q_commitDataAndCloseEditor(QWidget *editor);
-
QItemEditorFactory *f;
bool clipPainting;
@@ -129,13 +119,6 @@ public:
} tmp;
};
-void QItemDelegatePrivate::_q_commitDataAndCloseEditor(QWidget *editor)
-{
- Q_Q(QItemDelegate);
- emit q->commitData(editor);
- emit q->closeEditor(editor, QAbstractItemDelegate::SubmitModelCache);
-}
-
QRect QItemDelegatePrivate::textLayoutBounds(const QStyleOptionViewItem &option) const
{
QRect rect = option.rect;
@@ -379,24 +362,6 @@ QString QItemDelegatePrivate::valueToText(const QVariant &value, const QStyleOpt
return text;
}
-bool QItemDelegatePrivate::tryFixup(QWidget *editor)
-{
-#ifndef QT_NO_LINEEDIT
- if (QLineEdit *e = qobject_cast<QLineEdit*>(editor)) {
- if (!e->hasAcceptableInput()) {
- if (const QValidator *validator = e->validator()) {
- QString text = e->text();
- validator->fixup(text);
- e->setText(text);
- }
- return e->hasAcceptableInput();
- }
- }
-#endif // QT_NO_LINEEDIT
-
- return true;
-}
-
/*!
Renders the delegate using the given \a painter and style \a option for
the item specified by \a index.
@@ -1166,75 +1131,7 @@ QRect QItemDelegate::textRectangle(QPainter * /*painter*/, const QRect &rect,
bool QItemDelegate::eventFilter(QObject *object, QEvent *event)
{
Q_D(QItemDelegate);
-
- QWidget *editor = qobject_cast<QWidget*>(object);
- if (!editor)
- return false;
- if (event->type() == QEvent::KeyPress) {
- switch (static_cast<QKeyEvent *>(event)->key()) {
- case Qt::Key_Tab:
- if (d->tryFixup(editor)) {
- emit commitData(editor);
- emit closeEditor(editor, EditNextItem);
- }
- return true;
- case Qt::Key_Backtab:
- if (d->tryFixup(editor)) {
- emit commitData(editor);
- emit closeEditor(editor, EditPreviousItem);
- }
- return true;
- case Qt::Key_Enter:
- case Qt::Key_Return:
-#ifndef QT_NO_TEXTEDIT
- if (qobject_cast<QTextEdit *>(editor) || qobject_cast<QPlainTextEdit *>(editor))
- return false; // don't filter enter key events for QTextEdit
- // We want the editor to be able to process the key press
- // before committing the data (e.g. so it can do
- // validation/fixup of the input).
-#endif // QT_NO_TEXTEDIT
- if (!d->tryFixup(editor))
- return true;
-
- QMetaObject::invokeMethod(this, "_q_commitDataAndCloseEditor",
- Qt::QueuedConnection, Q_ARG(QWidget*, editor));
- return false;
- case Qt::Key_Escape:
- // don't commit data
- emit closeEditor(editor, QAbstractItemDelegate::RevertModelCache);
- return true;
- default:
- return false;
- }
- } else if (event->type() == QEvent::FocusOut || (event->type() == QEvent::Hide && editor->isWindow())) {
- //the Hide event will take care of he editors that are in fact complete dialogs
- if (!editor->isActiveWindow() || (QApplication::focusWidget() != editor)) {
- QWidget *w = QApplication::focusWidget();
- while (w) { // don't worry about focus changes internally in the editor
- if (w == editor)
- return false;
- w = w->parentWidget();
- }
-#ifndef QT_NO_DRAGANDDROP
- // The window may lose focus during an drag operation.
- // i.e when dragging involves the taskbar on Windows.
- QPlatformDrag *platformDrag = QGuiApplicationPrivate::instance()->platformIntegration()->drag();
- if (platformDrag && platformDrag->currentDrag()) {
- return false;
- }
-#endif
- if (d->tryFixup(editor))
- emit commitData(editor);
-
- emit closeEditor(editor, NoHint);
- }
- } else if (event->type() == QEvent::ShortcutOverride) {
- if (static_cast<QKeyEvent*>(event)->key() == Qt::Key_Escape) {
- event->accept();
- return true;
- }
- }
- return false;
+ return d->editorEventFilter(object, event);
}
/*!