summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@digia.com>2013-05-23 21:27:07 +0200
committerFrederik Gladhorn <frederik.gladhorn@digia.com>2013-05-23 21:27:07 +0200
commitd3a8bc803cd7c4ce106038bfc4b37cdd6bb8e177 (patch)
tree3b6db0d4869f334d0eb4559c5ae457995cbe913e /src/widgets/itemviews
parentd934ddc297f6db94dbc548fe01da64350f13577d (diff)
parent47a7628023610904c6ac52e23fa289f75f349b4e (diff)
Merge remote-tracking branch 'origin/stable' into dev
Conflicts: src/corelib/io/qdatastream.cpp src/corelib/io/qdatastream.h src/corelib/json/qjsonwriter.cpp src/plugins/platforms/cocoa/qcocoawindow.mm src/plugins/platforms/xcb/qxcbkeyboard.cpp Change-Id: I46fef1455f5a9f2ce1ec394a3c65881093c51b62
Diffstat (limited to 'src/widgets/itemviews')
-rw-r--r--src/widgets/itemviews/qitemdelegate.cpp44
-rw-r--r--src/widgets/itemviews/qstyleditemdelegate.cpp44
2 files changed, 68 insertions, 20 deletions
diff --git a/src/widgets/itemviews/qitemdelegate.cpp b/src/widgets/itemviews/qitemdelegate.cpp
index 7d8512adc4..c040322ba1 100644
--- a/src/widgets/itemviews/qitemdelegate.cpp
+++ b/src/widgets/itemviews/qitemdelegate.cpp
@@ -113,6 +113,7 @@ public:
static QString valueToText(const QVariant &value, const QStyleOptionViewItem &option);
+ bool tryFixup(QWidget *editor);
void _q_commitDataAndCloseEditor(QWidget *editor);
QItemEditorFactory *f;
@@ -386,6 +387,24 @@ 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.
@@ -1154,18 +1173,24 @@ 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:
- emit commitData(editor);
- emit closeEditor(editor, QAbstractItemDelegate::EditNextItem);
+ if (d->tryFixup(editor)) {
+ emit commitData(editor);
+ emit closeEditor(editor, EditNextItem);
+ }
return true;
case Qt::Key_Backtab:
- emit commitData(editor);
- emit closeEditor(editor, QAbstractItemDelegate::EditPreviousItem);
+ if (d->tryFixup(editor)) {
+ emit commitData(editor);
+ emit closeEditor(editor, EditPreviousItem);
+ }
return true;
case Qt::Key_Enter:
case Qt::Key_Return:
@@ -1176,11 +1201,9 @@ bool QItemDelegate::eventFilter(QObject *object, QEvent *event)
// before committing the data (e.g. so it can do
// validation/fixup of the input).
#endif // QT_NO_TEXTEDIT
-#ifndef QT_NO_LINEEDIT
- if (QLineEdit *e = qobject_cast<QLineEdit*>(editor))
- if (!e->hasAcceptableInput())
- return false;
-#endif // QT_NO_LINEEDIT
+ if (!d->tryFixup(editor))
+ return true;
+
QMetaObject::invokeMethod(this, "_q_commitDataAndCloseEditor",
Qt::QueuedConnection, Q_ARG(QWidget*, editor));
return false;
@@ -1211,8 +1234,9 @@ bool QItemDelegate::eventFilter(QObject *object, QEvent *event)
return false;
}
#endif
+ if (d->tryFixup(editor))
+ emit commitData(editor);
- emit commitData(editor);
emit closeEditor(editor, NoHint);
}
} else if (event->type() == QEvent::ShortcutOverride) {
diff --git a/src/widgets/itemviews/qstyleditemdelegate.cpp b/src/widgets/itemviews/qstyleditemdelegate.cpp
index b121800c31..7e1933ad1e 100644
--- a/src/widgets/itemviews/qstyleditemdelegate.cpp
+++ b/src/widgets/itemviews/qstyleditemdelegate.cpp
@@ -97,6 +97,7 @@ public:
return factory ? factory : QItemEditorFactory::defaultFactory();
}
+ bool tryFixup(QWidget *editor);
void _q_commitDataAndCloseEditor(QWidget *editor)
{
Q_Q(QStyledItemDelegate);
@@ -106,6 +107,24 @@ public:
QItemEditorFactory *factory;
};
+bool QStyledItemDelegatePrivate::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;
+}
+
/*!
\class QStyledItemDelegate
@@ -622,18 +641,24 @@ void QStyledItemDelegate::setItemEditorFactory(QItemEditorFactory *factory)
*/
bool QStyledItemDelegate::eventFilter(QObject *object, QEvent *event)
{
+ Q_D(QStyledItemDelegate);
+
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:
- emit commitData(editor);
- emit closeEditor(editor, QAbstractItemDelegate::EditNextItem);
+ if (d->tryFixup(editor)) {
+ emit commitData(editor);
+ emit closeEditor(editor, EditNextItem);
+ }
return true;
case Qt::Key_Backtab:
- emit commitData(editor);
- emit closeEditor(editor, QAbstractItemDelegate::EditPreviousItem);
+ if (d->tryFixup(editor)) {
+ emit commitData(editor);
+ emit closeEditor(editor, EditPreviousItem);
+ }
return true;
case Qt::Key_Enter:
case Qt::Key_Return:
@@ -644,11 +669,9 @@ bool QStyledItemDelegate::eventFilter(QObject *object, QEvent *event)
// before committing the data (e.g. so it can do
// validation/fixup of the input).
#endif // QT_NO_TEXTEDIT
-#ifndef QT_NO_LINEEDIT
- if (QLineEdit *e = qobject_cast<QLineEdit*>(editor))
- if (!e->hasAcceptableInput())
- return false;
-#endif // QT_NO_LINEEDIT
+ if (!d->tryFixup(editor))
+ return true;
+
QMetaObject::invokeMethod(this, "_q_commitDataAndCloseEditor",
Qt::QueuedConnection, Q_ARG(QWidget*, editor));
return false;
@@ -679,8 +702,9 @@ bool QStyledItemDelegate::eventFilter(QObject *object, QEvent *event)
return false;
}
#endif
+ if (d->tryFixup(editor))
+ emit commitData(editor);
- emit commitData(editor);
emit closeEditor(editor, NoHint);
}
} else if (event->type() == QEvent::ShortcutOverride) {