summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews/qabstractitemview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/itemviews/qabstractitemview.cpp')
-rw-r--r--src/widgets/itemviews/qabstractitemview.cpp46
1 files changed, 39 insertions, 7 deletions
diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp
index 9870d9d49a..a07297863d 100644
--- a/src/widgets/itemviews/qabstractitemview.cpp
+++ b/src/widgets/itemviews/qabstractitemview.cpp
@@ -219,7 +219,7 @@ void QAbstractItemViewPrivate::_q_scrollerStateChanged()
q->selectionModel()->select(oldSelection, QItemSelectionModel::ClearAndSelect);
q->selectionModel()->setCurrentIndex(oldCurrent, QItemSelectionModel::NoUpdate);
}
- // fall through
+ Q_FALLTHROUGH();
default:
oldSelection = QItemSelection();
@@ -2194,7 +2194,7 @@ QAbstractItemViewPrivate::position(const QPoint &pos, const QRect &rect, const Q
{
QAbstractItemView::DropIndicatorPosition r = QAbstractItemView::OnViewport;
if (!overwrite) {
- const int margin = 2;
+ const int margin = qBound(2, qRound(qreal(rect.height()) / 5.5), 12);
if (pos.y() - rect.top() < margin) {
r = QAbstractItemView::AboveItem;
} else if (rect.bottom() - pos.y() < margin) {
@@ -2255,7 +2255,7 @@ void QAbstractItemView::focusInEvent(QFocusEvent *event)
/*!
This function is called with the given \a event when the widget
- looses the focus. By default, the event is ignored.
+ loses the focus. By default, the event is ignored.
\sa clearFocus(), focusInEvent()
*/
@@ -3135,7 +3135,7 @@ int QAbstractItemView::sizeHintForColumn(int column) const
Opens a persistent editor on the item at the given \a index.
If no editor exists, the delegate will create a new editor.
- \sa closePersistentEditor()
+ \sa closePersistentEditor(), isPersistentEditorOpen()
*/
void QAbstractItemView::openPersistentEditor(const QModelIndex &index)
{
@@ -3154,7 +3154,7 @@ void QAbstractItemView::openPersistentEditor(const QModelIndex &index)
/*!
Closes the persistent editor for the item at the given \a index.
- \sa openPersistentEditor()
+ \sa openPersistentEditor(), isPersistentEditorOpen()
*/
void QAbstractItemView::closePersistentEditor(const QModelIndex &index)
{
@@ -3169,6 +3169,19 @@ void QAbstractItemView::closePersistentEditor(const QModelIndex &index)
}
/*!
+ \since 5.10
+
+ Returns whether a persistent editor is open for the item at index \a index.
+
+ \sa openPersistentEditor(), closePersistentEditor()
+*/
+bool QAbstractItemView::isPersistentEditorOpen(const QModelIndex &index) const
+{
+ Q_D(const QAbstractItemView);
+ return d->editorForIndex(index).widget;
+}
+
+/*!
\since 4.1
Sets the given \a widget on the item at the given \a index, passing the
@@ -3204,12 +3217,14 @@ void QAbstractItemView::setIndexWidget(const QModelIndex &index, QWidget *widget
if (QWidget *oldWidget = indexWidget(index)) {
d->persistent.remove(oldWidget);
d->removeEditor(oldWidget);
+ oldWidget->removeEventFilter(this);
oldWidget->deleteLater();
}
if (widget) {
widget->setParent(viewport());
d->persistent.insert(widget);
d->addEditor(index, widget, true);
+ widget->installEventFilter(this);
widget->show();
dataChanged(index, index); // update the geometry
if (!d->delayedPendingLayout)
@@ -4418,8 +4433,7 @@ QItemViewPaintPairs QAbstractItemViewPrivate::draggablePaintPairs(const QModelIn
for (const auto &index : indexes) {
const QRect current = q->visualRect(index);
if (current.intersects(viewportRect)) {
- QItemViewPaintPair p = { current, index };
- ret += p;
+ ret.append({current, index});
rect |= current;
}
}
@@ -4487,6 +4501,24 @@ QModelIndexList QAbstractItemViewPrivate::selectedDraggableIndexes() const
return indexes;
}
+/*!
+ \reimp
+*/
+
+bool QAbstractItemView::eventFilter(QObject *object, QEvent *event)
+{
+ Q_D(QAbstractItemView);
+ if (object == this || object == viewport() || event->type() != QEvent::FocusIn)
+ return QAbstractScrollArea::eventFilter(object, event);
+ QWidget *widget = qobject_cast<QWidget *>(object);
+ // If it is not a persistent widget then we did not install
+ // the event filter on it, so assume a base implementation is
+ // filtering
+ if (!widget || !d->persistent.contains(widget))
+ return QAbstractScrollArea::eventFilter(object, event);
+ setCurrentIndex(d->indexForEditor(widget));
+ return false;
+}
QT_END_NAMESPACE