diff options
Diffstat (limited to 'src/widgets/itemviews')
-rw-r--r-- | src/widgets/itemviews/qabstractitemview.cpp | 24 | ||||
-rw-r--r-- | src/widgets/itemviews/qabstractitemview.h | 1 | ||||
-rw-r--r-- | src/widgets/itemviews/qcolumnview.cpp | 6 | ||||
-rw-r--r-- | src/widgets/itemviews/qdirmodel.cpp | 17 | ||||
-rw-r--r-- | src/widgets/itemviews/qheaderview.cpp | 16 | ||||
-rw-r--r-- | src/widgets/itemviews/qitemdelegate.cpp | 2 | ||||
-rw-r--r-- | src/widgets/itemviews/qlistview.cpp | 3 | ||||
-rw-r--r-- | src/widgets/itemviews/qlistwidget.cpp | 18 | ||||
-rw-r--r-- | src/widgets/itemviews/qlistwidget.h | 11 | ||||
-rw-r--r-- | src/widgets/itemviews/qtablewidget.cpp | 18 | ||||
-rw-r--r-- | src/widgets/itemviews/qtablewidget.h | 10 | ||||
-rw-r--r-- | src/widgets/itemviews/qtreeview.cpp | 2 | ||||
-rw-r--r-- | src/widgets/itemviews/qtreewidget.cpp | 19 | ||||
-rw-r--r-- | src/widgets/itemviews/qtreewidget.h | 10 |
14 files changed, 119 insertions, 38 deletions
diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index 9870d9d49a..23e727e670 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -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 @@ -4418,8 +4431,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; } } diff --git a/src/widgets/itemviews/qabstractitemview.h b/src/widgets/itemviews/qabstractitemview.h index 6be776ec52..6a007da348 100644 --- a/src/widgets/itemviews/qabstractitemview.h +++ b/src/widgets/itemviews/qabstractitemview.h @@ -212,6 +212,7 @@ public: void openPersistentEditor(const QModelIndex &index); void closePersistentEditor(const QModelIndex &index); + bool isPersistentEditorOpen(const QModelIndex &index) const; void setIndexWidget(const QModelIndex &index, QWidget *widget); QWidget *indexWidget(const QModelIndex &index) const; diff --git a/src/widgets/itemviews/qcolumnview.cpp b/src/widgets/itemviews/qcolumnview.cpp index ea9bbb0fb9..d94f25de78 100644 --- a/src/widgets/itemviews/qcolumnview.cpp +++ b/src/widgets/itemviews/qcolumnview.cpp @@ -53,8 +53,6 @@ QT_BEGIN_NAMESPACE -#define ANIMATION_DURATION_MSEC 150 - /*! \since 4.3 \class QColumnView @@ -107,7 +105,6 @@ void QColumnViewPrivate::initialize() q->setTextElideMode(Qt::ElideMiddle); #ifndef QT_NO_ANIMATION QObject::connect(¤tAnimation, SIGNAL(finished()), q, SLOT(_q_changeCurrentColumn())); - currentAnimation.setDuration(ANIMATION_DURATION_MSEC); currentAnimation.setTargetObject(hbar); currentAnimation.setPropertyName("value"); currentAnimation.setEasingCurve(QEasingCurve::InOutQuad); @@ -330,7 +327,8 @@ void QColumnView::scrollTo(const QModelIndex &index, ScrollHint hint) } #ifndef QT_NO_ANIMATION - if (style()->styleHint(QStyle::SH_Widget_Animate, 0, this)) { + if (const int animationDuration = style()->styleHint(QStyle::SH_Widget_Animation_Duration, 0, this)) { + d->currentAnimation.setDuration(animationDuration); d->currentAnimation.setEndValue(newScrollbarValue); d->currentAnimation.start(); } else diff --git a/src/widgets/itemviews/qdirmodel.cpp b/src/widgets/itemviews/qdirmodel.cpp index 2cf76262e6..449850c42e 100644 --- a/src/widgets/itemviews/qdirmodel.cpp +++ b/src/widgets/itemviews/qdirmodel.cpp @@ -1309,22 +1309,7 @@ QString QDirModelPrivate::size(const QModelIndex &index) const // Nautilus - "9 items" (the number of children) } - // According to the Si standard KB is 1000 bytes, KiB is 1024 - // but on windows sizes are calulated by dividing by 1024 so we do what they do. - const quint64 kb = 1024; - const quint64 mb = 1024 * kb; - const quint64 gb = 1024 * mb; - const quint64 tb = 1024 * gb; - quint64 bytes = n->info.size(); - if (bytes >= tb) - return QFileSystemModel::tr("%1 TB").arg(QLocale().toString(qreal(bytes) / tb, 'f', 3)); - if (bytes >= gb) - return QFileSystemModel::tr("%1 GB").arg(QLocale().toString(qreal(bytes) / gb, 'f', 2)); - if (bytes >= mb) - return QFileSystemModel::tr("%1 MB").arg(QLocale().toString(qreal(bytes) / mb, 'f', 1)); - if (bytes >= kb) - return QFileSystemModel::tr("%1 KB").arg(QLocale().toString(bytes / kb)); - return QFileSystemModel::tr("%1 byte(s)").arg(QLocale().toString(bytes)); + return QLocale::system().formattedDataSize(n->info.size()); } QString QDirModelPrivate::type(const QModelIndex &index) const diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index 298270a785..463ed7e58c 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -2531,8 +2531,20 @@ void QHeaderView::mouseMoveEvent(QMouseEvent *e) if (handle != -1 && (sectionResizeMode(handle) == Interactive)) { if (!hasCursor) setCursor(d->orientation == Qt::Horizontal ? Qt::SplitHCursor : Qt::SplitVCursor); - } else if (hasCursor) { - unsetCursor(); + } else { + if (hasCursor) + unsetCursor(); +#ifndef QT_NO_STATUSTIP + int logical = logicalIndexAt(pos); + QString statusTip; + if (logical != -1) + statusTip = d->model->headerData(logical, d->orientation, Qt::StatusTipRole).toString(); + if (d->shouldClearStatusTip || !statusTip.isEmpty()) { + QStatusTipEvent tip(statusTip); + QCoreApplication::sendEvent(d->parent, &tip); + d->shouldClearStatusTip = !statusTip.isEmpty(); + } +#endif // !QT_NO_STATUSTIP } #endif return; diff --git a/src/widgets/itemviews/qitemdelegate.cpp b/src/widgets/itemviews/qitemdelegate.cpp index 68c02e9edb..d9caebec8a 100644 --- a/src/widgets/itemviews/qitemdelegate.cpp +++ b/src/widgets/itemviews/qitemdelegate.cpp @@ -988,7 +988,7 @@ QPixmap *QItemDelegate::selected(const QPixmap &pixmap, const QPalette &palette, painter.end(); QPixmap selected = QPixmap(QPixmap::fromImage(img)); - int n = (img.byteCount() >> 10) + 1; + int n = (img.sizeInBytes() >> 10) + 1; if (QPixmapCache::cacheLimit() < n) QPixmapCache::setCacheLimit(n); diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp index 9217fec10e..7f027595b7 100644 --- a/src/widgets/itemviews/qlistview.cpp +++ b/src/widgets/itemviews/qlistview.cpp @@ -657,8 +657,7 @@ QItemViewPaintPairs QListViewPrivate::draggablePaintPairs(const QModelIndexList for (const auto &index : indexes) { if (std::binary_search(visibleIndexes.cbegin(), visibleIndexes.cend(), index)) { const QRect current = q->visualRect(index); - QItemViewPaintPair p = { current, index }; - ret += p; + ret.append({current, index}); rect |= current; } } diff --git a/src/widgets/itemviews/qlistwidget.cpp b/src/widgets/itemviews/qlistwidget.cpp index 21747d4e6e..95ad3f82d0 100644 --- a/src/widgets/itemviews/qlistwidget.cpp +++ b/src/widgets/itemviews/qlistwidget.cpp @@ -1616,7 +1616,7 @@ void QListWidget::editItem(QListWidgetItem *item) Opens an editor for the given \a item. The editor remains open after editing. - \sa closePersistentEditor() + \sa closePersistentEditor(), isPersistentEditorOpen() */ void QListWidget::openPersistentEditor(QListWidgetItem *item) { @@ -1628,7 +1628,7 @@ void QListWidget::openPersistentEditor(QListWidgetItem *item) /*! Closes the persistent editor for the given \a item. - \sa openPersistentEditor() + \sa openPersistentEditor(), isPersistentEditorOpen() */ void QListWidget::closePersistentEditor(QListWidgetItem *item) { @@ -1638,6 +1638,20 @@ void QListWidget::closePersistentEditor(QListWidgetItem *item) } /*! + \since 5.10 + + Returns whether a persistent editor is open for item \a item. + + \sa openPersistentEditor(), closePersistentEditor() +*/ +bool QListWidget::isPersistentEditorOpen(QListWidgetItem *item) const +{ + Q_D(const QListWidget); + const QModelIndex index = d->listModel()->index(item); + return QAbstractItemView::isPersistentEditorOpen(index); +} + +/*! \since 4.1 Returns the widget displayed in the given \a item. diff --git a/src/widgets/itemviews/qlistwidget.h b/src/widgets/itemviews/qlistwidget.h index 8471645fb0..50f4e2ac84 100644 --- a/src/widgets/itemviews/qlistwidget.h +++ b/src/widgets/itemviews/qlistwidget.h @@ -239,6 +239,8 @@ public: void editItem(QListWidgetItem *item); void openPersistentEditor(QListWidgetItem *item); void closePersistentEditor(QListWidgetItem *item); + using QAbstractItemView::isPersistentEditorOpen; + bool isPersistentEditorOpen(QListWidgetItem *item) const; QWidget *itemWidget(QListWidgetItem *item) const; void setItemWidget(QListWidgetItem *item, QWidget *widget); @@ -251,6 +253,9 @@ public: bool isItemHidden(const QListWidgetItem *item) const; void setItemHidden(const QListWidgetItem *item, bool hide); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +protected: +#endif #if QT_CONFIG(draganddrop) void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE; #endif @@ -284,6 +289,12 @@ protected: virtual bool dropMimeData(int index, const QMimeData *data, Qt::DropAction action); virtual Qt::DropActions supportedDropActions() const; #endif + +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +public: +#else +protected: +#endif QList<QListWidgetItem*> items(const QMimeData *data) const; QModelIndex indexFromItem(QListWidgetItem *item) const; diff --git a/src/widgets/itemviews/qtablewidget.cpp b/src/widgets/itemviews/qtablewidget.cpp index 3ff75cc23b..bb1970e3ac 100644 --- a/src/widgets/itemviews/qtablewidget.cpp +++ b/src/widgets/itemviews/qtablewidget.cpp @@ -2220,7 +2220,7 @@ void QTableWidget::editItem(QTableWidgetItem *item) /*! Opens an editor for the give \a item. The editor remains open after editing. - \sa closePersistentEditor() + \sa closePersistentEditor(), isPersistentEditorOpen() */ void QTableWidget::openPersistentEditor(QTableWidgetItem *item) { @@ -2234,7 +2234,7 @@ void QTableWidget::openPersistentEditor(QTableWidgetItem *item) /*! Closes the persistent editor for \a item. - \sa openPersistentEditor() + \sa openPersistentEditor(), isPersistentEditorOpen() */ void QTableWidget::closePersistentEditor(QTableWidgetItem *item) { @@ -2246,6 +2246,20 @@ void QTableWidget::closePersistentEditor(QTableWidgetItem *item) } /*! + \since 5.10 + + Returns whether a persistent editor is open for item \a item. + + \sa openPersistentEditor(), closePersistentEditor() +*/ +bool QTableWidget::isPersistentEditorOpen(QTableWidgetItem *item) const +{ + Q_D(const QTableWidget); + const QModelIndex index = d->tableModel()->index(item); + return QAbstractItemView::isPersistentEditorOpen(index); +} + +/*! \since 4.1 Returns the widget displayed in the cell in the given \a row and \a column. diff --git a/src/widgets/itemviews/qtablewidget.h b/src/widgets/itemviews/qtablewidget.h index 3fecf194e4..9c231d5127 100644 --- a/src/widgets/itemviews/qtablewidget.h +++ b/src/widgets/itemviews/qtablewidget.h @@ -261,6 +261,8 @@ public: void editItem(QTableWidgetItem *item); void openPersistentEditor(QTableWidgetItem *item); void closePersistentEditor(QTableWidgetItem *item); + using QAbstractItemView::isPersistentEditorOpen; + bool isPersistentEditorOpen(QTableWidgetItem *item) const; QWidget *cellWidget(int row, int column) const; void setCellWidget(int row, int column, QWidget *widget); @@ -325,10 +327,18 @@ protected: #endif virtual bool dropMimeData(int row, int column, const QMimeData *data, Qt::DropAction action); virtual Qt::DropActions supportedDropActions() const; + +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +public: +#else +protected: +#endif QList<QTableWidgetItem*> items(const QMimeData *data) const; QModelIndex indexFromItem(QTableWidgetItem *item) const; QTableWidgetItem *itemFromIndex(const QModelIndex &index) const; + +protected: #if QT_CONFIG(draganddrop) void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE; #endif diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp index 2abb1a9c14..61721143ef 100644 --- a/src/widgets/itemviews/qtreeview.cpp +++ b/src/widgets/itemviews/qtreeview.cpp @@ -3043,7 +3043,7 @@ void QTreeViewPrivate::initialize() header->setDefaultAlignment(Qt::AlignLeft|Qt::AlignVCenter); q->setHeader(header); #ifndef QT_NO_ANIMATION - animationsEnabled = q->style()->styleHint(QStyle::SH_Widget_Animate, 0, q); + animationsEnabled = q->style()->styleHint(QStyle::SH_Widget_Animation_Duration, 0, q) > 0; QObject::connect(&animatedOperation, SIGNAL(finished()), q, SLOT(_q_endAnimatedOperation())); #endif //QT_NO_ANIMATION } diff --git a/src/widgets/itemviews/qtreewidget.cpp b/src/widgets/itemviews/qtreewidget.cpp index 337089056d..d7b46a0835 100644 --- a/src/widgets/itemviews/qtreewidget.cpp +++ b/src/widgets/itemviews/qtreewidget.cpp @@ -2906,7 +2906,7 @@ void QTreeWidget::editItem(QTreeWidgetItem *item, int column) /*! Opens a persistent editor for the \a item in the given \a column. - \sa closePersistentEditor() + \sa closePersistentEditor(), isPersistentEditorOpen() */ void QTreeWidget::openPersistentEditor(QTreeWidgetItem *item, int column) @@ -2921,7 +2921,7 @@ void QTreeWidget::openPersistentEditor(QTreeWidgetItem *item, int column) This function has no effect if no persistent editor is open for this combination of item and column. - \sa openPersistentEditor() + \sa openPersistentEditor(), isPersistentEditorOpen() */ void QTreeWidget::closePersistentEditor(QTreeWidgetItem *item, int column) @@ -2931,6 +2931,21 @@ void QTreeWidget::closePersistentEditor(QTreeWidgetItem *item, int column) } /*! + \since 5.10 + + Returns whether a persistent editor is open for item \a item in + column \a column. + + \sa openPersistentEditor(), closePersistentEditor() +*/ + +bool QTreeWidget::isPersistentEditorOpen(QTreeWidgetItem *item, int column) const +{ + Q_D(const QTreeWidget); + return QAbstractItemView::isPersistentEditorOpen(d->index(item, column)); +} + +/*! \since 4.1 Returns the widget displayed in the cell specified by \a item and the given \a column. diff --git a/src/widgets/itemviews/qtreewidget.h b/src/widgets/itemviews/qtreewidget.h index 3bdeae08d8..783627cde9 100644 --- a/src/widgets/itemviews/qtreewidget.h +++ b/src/widgets/itemviews/qtreewidget.h @@ -299,6 +299,8 @@ public: void editItem(QTreeWidgetItem *item, int column = 0); void openPersistentEditor(QTreeWidgetItem *item, int column = 0); void closePersistentEditor(QTreeWidgetItem *item, int column = 0); + using QAbstractItemView::isPersistentEditorOpen; + bool isPersistentEditorOpen(QTreeWidgetItem *item, int column = 0) const; QWidget *itemWidget(QTreeWidgetItem *item, int column) const; void setItemWidget(QTreeWidgetItem *item, int column, QWidget *widget); @@ -354,11 +356,19 @@ protected: virtual bool dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action); virtual Qt::DropActions supportedDropActions() const; + +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +public: +#else +protected: +#endif QList<QTreeWidgetItem*> items(const QMimeData *data) const; QModelIndex indexFromItem(const QTreeWidgetItem *item, int column = 0) const; QModelIndex indexFromItem(QTreeWidgetItem *item, int column = 0) const; // ### Qt 6: remove QTreeWidgetItem *itemFromIndex(const QModelIndex &index) const; + +protected: #if QT_CONFIG(draganddrop) void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE; #endif |