From b0310ddd163847beabf7da66c2190d0b9b5e6afb Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 26 Jan 2018 09:46:24 +0100 Subject: hellogles3 example: Fix start-up crash when using dynamic GL Move the instantiation of QGuiApplication to the top since it is required by QOpenGLContext::openGLModuleType(). Task-number: QTBUG-55671 Change-Id: I506cee193fe2ba48400851588a8ef079848bc2f4 Reviewed-by: Laszlo Agocs --- examples/opengl/hellogles3/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/opengl/hellogles3/main.cpp b/examples/opengl/hellogles3/main.cpp index a6c6398628..29b3b9617a 100644 --- a/examples/opengl/hellogles3/main.cpp +++ b/examples/opengl/hellogles3/main.cpp @@ -64,6 +64,8 @@ int main(int argc, char *argv[]) { + QGuiApplication app(argc, argv); + QSurfaceFormat fmt; fmt.setDepthBufferSize(24); @@ -79,8 +81,6 @@ int main(int argc, char *argv[]) QSurfaceFormat::setDefaultFormat(fmt); - QGuiApplication app(argc, argv); - GLWindow glWindow; glWindow.showMaximized(); -- cgit v1.2.3 From f5b1b10a1120ce5f9ffb43cc05fe4a0e39f43e36 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 24 Jan 2018 12:38:10 +0100 Subject: Android: Fix compilation with warnings-are-errors Variable was added in e2e874415e1f1c6a96915d9dc85dd31c61f73e24 but is not used anywhere. Change-Id: Iff1e7c20317bb489978eb77d24b8da12493d7e45 Reviewed-by: BogDan Vatra --- src/plugins/platforms/android/androidjniclipboard.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plugins/platforms/android/androidjniclipboard.cpp b/src/plugins/platforms/android/androidjniclipboard.cpp index 833996403c..d169035339 100644 --- a/src/plugins/platforms/android/androidjniclipboard.cpp +++ b/src/plugins/platforms/android/androidjniclipboard.cpp @@ -47,7 +47,6 @@ namespace QtAndroidClipboard { QAndroidPlatformClipboard *m_manager = nullptr; - static char const *const QtNativeClassName = "org/qtproject/qt5/android/QtNative"; static JNINativeMethod methods[] = { {"onClipboardDataChanged", "()V", (void *)onClipboardDataChanged} }; -- cgit v1.2.3 From 089969540f4877c778172ee0ccbd69960a179b43 Mon Sep 17 00:00:00 2001 From: Konstantin Tokarev Date: Fri, 26 Jan 2018 19:10:46 +0300 Subject: Remove traces of Growl in QSystemTrayIcon code and documentation Growl support was removed in Qt 5.8. Change-Id: I00a36cd955194ca8ceee52841a89ca579da01284 Reviewed-by: Jake Petroules --- src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm | 2 -- src/widgets/util/qsystemtrayicon.cpp | 7 +------ 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm index e756f0aeb0..f4c968ab57 100644 --- a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm +++ b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm @@ -72,8 +72,6 @@ ** ****************************************************************************/ -#define QT_MAC_SYSTEMTRAY_USE_GROWL - #include "qcocoasystemtrayicon.h" #ifndef QT_NO_SYSTEMTRAYICON diff --git a/src/widgets/util/qsystemtrayicon.cpp b/src/widgets/util/qsystemtrayicon.cpp index f7d048edcd..884bed2e68 100644 --- a/src/widgets/util/qsystemtrayicon.cpp +++ b/src/widgets/util/qsystemtrayicon.cpp @@ -107,9 +107,7 @@ static QIcon messageIcon2qIcon(QSystemTrayIcon::MessageIcon icon) \li All X11 desktop environments that implement the D-Bus \l{http://www.freedesktop.org/wiki/Specifications/StatusNotifierItem/StatusNotifierItem} specification, including recent versions of KDE and Unity. - \li All supported versions of \macos. Note that the Growl - notification system must be installed for - QSystemTrayIcon::showMessage() to display messages on \macos prior to 10.8 (Mountain Lion). + \li All supported versions of \macos. \endlist To check whether a system tray is present on the user's desktop, @@ -399,9 +397,6 @@ bool QSystemTrayIcon::supportsMessages() On Windows, the \a millisecondsTimeoutHint is usually ignored by the system when the application has focus. - On \macos, the Growl notification system must be installed for this function to - display messages. - Has been turned into a slot in Qt 5.2. \sa show(), supportsMessages() -- cgit v1.2.3 From b1a58b20ae109fac2756101fea4dcd8ee0b96531 Mon Sep 17 00:00:00 2001 From: Igor Mironchik Date: Thu, 25 Jan 2018 15:43:40 +0300 Subject: Fix missing update of QTreeView on setTreePosition() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There was missing update in setTreePosition() or better to say update was but in not that part of QTreeView that needed. Now QTreeView correctly updates and paints tree decoration in a new place on changing tree position. [ChangeLog][QtWidgets][QTreeView] Fixed missing update of QTreeView on changing tree position. Task-number: QTBUG-65980 Change-Id: Id79ab8fcb39d511245a551068640684dd2a10cb9 Reviewed-by: Thorbjørn Lund Martsum --- src/widgets/itemviews/qtreeview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp index 4795d9f1b1..8d27305071 100644 --- a/src/widgets/itemviews/qtreeview.cpp +++ b/src/widgets/itemviews/qtreeview.cpp @@ -987,7 +987,7 @@ void QTreeView::setTreePosition(int index) { Q_D(QTreeView); d->treePosition = index; - update(); + d->viewport->update(); } /*! -- cgit v1.2.3 From 6b1ecb1904c3f7281d90e672971f23d54bb76600 Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Wed, 13 Dec 2017 15:00:36 +0200 Subject: Android: Hide handler(s) if the cursor is not visible anymore On Android if the edit control is bigger than the remaining screen we resize it, this caused the handler(s) to remain outside the control. A better fix will be to ensure that the cursor/selection remains visible when the control is resized but I don't know if this is the desired behavior on all platforms. Task-number: QTBUG-62994 Task-number: QTBUG-58700 Change-Id: If43eb7bc1ecde426697694a8f26118e95fccb80c Reviewed-by: Paul Olav Tvete --- src/plugins/platforms/android/qandroidinputcontext.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/plugins/platforms/android/qandroidinputcontext.cpp b/src/plugins/platforms/android/qandroidinputcontext.cpp index fe4c5be4cb..fb33ad6e21 100644 --- a/src/plugins/platforms/android/qandroidinputcontext.cpp +++ b/src/plugins/platforms/android/qandroidinputcontext.cpp @@ -438,6 +438,16 @@ QAndroidInputContext::QAndroidInputContext() QObject::connect(QGuiApplication::inputMethod(), &QInputMethod::cursorRectangleChanged, this, &QAndroidInputContext::updateSelectionHandles); + QObject::connect(QGuiApplication::inputMethod(), &QInputMethod::anchorRectangleChanged, + this, &QAndroidInputContext::updateSelectionHandles); + QObject::connect(QGuiApplication::inputMethod(), &QInputMethod::inputItemClipRectangleChanged, this, [this]{ + auto im = qGuiApp->inputMethod(); + if (!im->inputItemClipRectangle().contains(im->anchorRectangle()) || + !im->inputItemClipRectangle().contains(im->cursorRectangle())) { + m_cursorHandleShown = CursorHandleNotShown; + updateSelectionHandles(); + } + }); } QAndroidInputContext::~QAndroidInputContext() -- cgit v1.2.3 From 626b33dca1dc0d95e80bf139c197fbb13d740277 Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Fri, 15 Dec 2017 10:52:10 +0200 Subject: Do not allow empty selections Allowing empty selections leads to strange behavior, it switches from selection handles to cursor handle. Change-Id: Ida69346e2a47b13c92cfd68a555d6b94422bb580 Reviewed-by: Paul Olav Tvete --- src/gui/kernel/qplatforminputcontext.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gui/kernel/qplatforminputcontext.cpp b/src/gui/kernel/qplatforminputcontext.cpp index 3f59116e9a..9771e6ba11 100644 --- a/src/gui/kernel/qplatforminputcontext.cpp +++ b/src/gui/kernel/qplatforminputcontext.cpp @@ -287,6 +287,8 @@ void QPlatformInputContext::setSelectionOnFocusObject(const QPointF &anchorPos, if (success) { int cursor = QInputMethod::queryFocusObject(Qt::ImCursorPosition, cursorPos * mapToLocal).toInt(&success); if (success) { + if (anchor == cursor && anchorPos != cursorPos) + return; QList imAttributes; imAttributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Selection, anchor, cursor - anchor, QVariant())); QInputMethodEvent event(QString(), imAttributes); -- cgit v1.2.3 From b1fb4f8261abe6372d446ee93846310191c070ce Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Fri, 15 Dec 2017 10:58:51 +0200 Subject: Move selection handles 1mm down This way the user will not cover with his finger the text with the cursor/selection. Set the tolerance to 0.5mm which is less then the width of the thinnest letters (e.g. i, I, l) Change-Id: Ia5d50bd3f4fe79c89d01b3d7f5e5c22e94e8158b Reviewed-by: Paul Olav Tvete --- .../org/qtproject/qt5/android/CursorHandle.java | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/android/jar/src/org/qtproject/qt5/android/CursorHandle.java b/src/android/jar/src/org/qtproject/qt5/android/CursorHandle.java index e6814c202d..abeab12f37 100644 --- a/src/android/jar/src/org/qtproject/qt5/android/CursorHandle.java +++ b/src/android/jar/src/org/qtproject/qt5/android/CursorHandle.java @@ -51,6 +51,7 @@ import android.graphics.drawable.Drawable; import android.view.MotionEvent; import android.widget.PopupWindow; import android.app.Activity; +import android.util.TypedValue; import android.view.ViewTreeObserver; /* This view represents one of the handle (selection or cursor handle) */ @@ -58,8 +59,8 @@ class CursorView extends ImageView { private CursorHandle mHandle; // The coordinare which where clicked - private int m_offsetX; - private int m_offsetY; + private float m_offsetX; + private float m_offsetY; CursorView (Context context, CursorHandle handle) { super(context); @@ -76,20 +77,18 @@ class CursorView extends ImageView public boolean onTouchEvent(MotionEvent ev) { switch (ev.getActionMasked()) { case MotionEvent.ACTION_DOWN: { - m_offsetX = Math.round(ev.getRawX()); - m_offsetY = Math.round(ev.getRawY()); + m_offsetX = ev.getRawX(); + m_offsetY = ev.getRawY() + getHeight() / 2; break; } case MotionEvent.ACTION_MOVE: { - mHandle.updatePosition(Math.round(ev.getRawX()) - m_offsetX, - Math.round(ev.getRawY()) - m_offsetY); + mHandle.updatePosition(Math.round(ev.getRawX() - m_offsetX), + Math.round(ev.getRawY() - m_offsetY)); break; } case MotionEvent.ACTION_UP: - break; - case MotionEvent.ACTION_CANCEL: break; } @@ -113,6 +112,7 @@ public class CursorHandle implements ViewTreeObserver.OnPreDrawListener private int m_lastY; int tolerance; private boolean m_rtl; + int m_yShift; public CursorHandle(Activity activity, View layout, int id, int attr, boolean rtl) { m_activity = activity; @@ -121,7 +121,8 @@ public class CursorHandle implements ViewTreeObserver.OnPreDrawListener m_layout = layout; DisplayMetrics metrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); - tolerance = Math.round(2 * metrics.density); + m_yShift = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, 1f, metrics); + tolerance = Math.min(1, (int)(m_yShift / 2f)); m_lastX = m_lastY = -1 - tolerance; m_rtl = rtl; } @@ -158,7 +159,7 @@ public class CursorHandle implements ViewTreeObserver.OnPreDrawListener m_layout.getLocationOnScreen(location); int x2 = x + location[0]; - int y2 = y + location[1]; + int y2 = y + location[1] + m_yShift; if (m_id == QtNative.IdCursorHandle) { x2 -= m_cursorView.getWidth() / 2 ; @@ -187,6 +188,7 @@ public class CursorHandle implements ViewTreeObserver.OnPreDrawListener // The handle was dragged by a given relative position public void updatePosition(int x, int y) { + y -= m_yShift; if (Math.abs(m_lastX - x) > tolerance || Math.abs(m_lastY - y) > tolerance) { QtNative.handleLocationChanged(m_id, x + m_posX, y + m_posY); m_lastX = x; -- cgit v1.2.3 From 5f924134ff48bc89defe4d6c2ccabeaea6b4450d Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Fri, 15 Dec 2017 11:08:16 +0200 Subject: Check selection handles position This patch fixes the strange behavior when selecting text. This patch (on a Left To Right text) makes sure that: - the left handle will select text only on the left & above of the right handle - the right handle will select text only on the right & below of the left handle For RTL is way more complicated: - the left handle is acuatually the right handle but on the left side and it acts as a right handle - the right handle is acuatually the left handle but on the right side and it acts as a left handle Change-Id: Ifca591398103199d5aef479f0a080161c9f44c0e Reviewed-by: Paul Olav Tvete --- .../platforms/android/qandroidinputcontext.cpp | 48 +++++++++++++++++++--- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/src/plugins/platforms/android/qandroidinputcontext.cpp b/src/plugins/platforms/android/qandroidinputcontext.cpp index fb33ad6e21..f548a1fa96 100644 --- a/src/plugins/platforms/android/qandroidinputcontext.cpp +++ b/src/plugins/platforms/android/qandroidinputcontext.cpp @@ -605,27 +605,63 @@ void QAndroidInputContext::handleLocationChanged(int handleId, int x, int y) double pixelDensity = window ? QHighDpiScaling::factor(window) : QHighDpiScaling::factor(QtAndroid::androidPlatformIntegration()->screen()); - QPoint point(x / pixelDensity, y / pixelDensity); - y -= leftRect.width() / 2; + QPointF point(x / pixelDensity, y / pixelDensity); + point.setY(point.y() - leftRect.width() / 2); if (handleId == 1) { setSelectionOnFocusObject(point, point); return; } - QInputMethodQueryEvent query(Qt::ImCursorPosition | Qt::ImAnchorPosition); + QInputMethodQueryEvent query(Qt::ImCursorPosition | Qt::ImAnchorPosition | Qt::ImCurrentSelection); QCoreApplication::sendEvent(m_focusObject, &query); int cpos = query.value(Qt::ImCursorPosition).toInt(); int anchor = query.value(Qt::ImAnchorPosition).toInt(); - + bool rtl = query.value(Qt::ImCurrentSelection).toString().isRightToLeft(); auto rightRect = im->anchorRectangle(); if (cpos > anchor) std::swap(leftRect, rightRect); + auto checkLeftHandle = [&rightRect](QPointF &handlePos) { + if (handlePos.y() > rightRect.center().y()) + handlePos.setY(rightRect.center().y()); // adjust Y handle pos + if (handlePos.y() >= rightRect.y() && handlePos.y() <= rightRect.bottom() && handlePos.x() >= rightRect.x()) + return false; // same line and wrong X pos ? + return true; + }; + + auto checkRtlRightHandle = [&rightRect](QPointF &handlePos) { + if (handlePos.y() > rightRect.center().y()) + handlePos.setY(rightRect.center().y()); // adjust Y handle pos + if (handlePos.y() >= rightRect.y() && handlePos.y() <= rightRect.bottom() && rightRect.x() >= handlePos.x()) + return false; // same line and wrong X pos ? + return true; + }; + + auto checkRightHandle = [&leftRect](QPointF &handlePos) { + if (handlePos.y() < leftRect.center().y()) + handlePos.setY(leftRect.center().y()); // adjust Y handle pos + if (handlePos.y() >= leftRect.y() && handlePos.y() <= leftRect.bottom() && leftRect.x() >= handlePos.x()) + return false; // same line and wrong X pos ? + return true; + }; + + auto checkRtlLeftHandle = [&leftRect](QPointF &handlePos) { + if (handlePos.y() < leftRect.center().y()) + handlePos.setY(leftRect.center().y()); // adjust Y handle pos + if (handlePos.y() >= leftRect.y() && handlePos.y() <= leftRect.bottom() && handlePos.x() >= leftRect.x()) + return false; // same line and wrong X pos ? + return true; + }; + if (handleId == 2) { - QPoint rightPoint(rightRect.center().toPoint()); + QPointF rightPoint(rightRect.center()); + if ((!rtl && !checkLeftHandle(point)) || (rtl && !checkRtlRightHandle(point))) + return; setSelectionOnFocusObject(point, rightPoint); } else if (handleId == 3) { - QPoint leftPoint(leftRect.center().toPoint()); + QPointF leftPoint(leftRect.center()); + if ((!rtl && !checkRightHandle(point)) || (rtl && !checkRtlLeftHandle(point))) + return; setSelectionOnFocusObject(leftPoint, point); } } -- cgit v1.2.3 From f3397ec659bc1288bebcb0dec11cc48cdd2c17bb Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Fri, 15 Dec 2017 14:30:14 +0200 Subject: Don't update the position if the handle was not first pressed Change-Id: If09a2ca954a3bfca00b5a0839fea2899e7576c1d Reviewed-by: Paul Olav Tvete --- src/android/jar/src/org/qtproject/qt5/android/CursorHandle.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/android/jar/src/org/qtproject/qt5/android/CursorHandle.java b/src/android/jar/src/org/qtproject/qt5/android/CursorHandle.java index abeab12f37..4f2c06644d 100644 --- a/src/android/jar/src/org/qtproject/qt5/android/CursorHandle.java +++ b/src/android/jar/src/org/qtproject/qt5/android/CursorHandle.java @@ -61,6 +61,7 @@ class CursorView extends ImageView // The coordinare which where clicked private float m_offsetX; private float m_offsetY; + private boolean m_pressed = false; CursorView (Context context, CursorHandle handle) { super(context); @@ -79,10 +80,13 @@ class CursorView extends ImageView case MotionEvent.ACTION_DOWN: { m_offsetX = ev.getRawX(); m_offsetY = ev.getRawY() + getHeight() / 2; + m_pressed = true; break; } case MotionEvent.ACTION_MOVE: { + if (!m_pressed) + return false; mHandle.updatePosition(Math.round(ev.getRawX() - m_offsetX), Math.round(ev.getRawY() - m_offsetY)); break; @@ -90,6 +94,7 @@ class CursorView extends ImageView case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: + m_pressed = false; break; } return true; -- cgit v1.2.3 From 5a05348fb6c3940449a9c2950bb65bdea2112a15 Mon Sep 17 00:00:00 2001 From: Frank Richter Date: Tue, 23 Jan 2018 14:06:53 +0100 Subject: examples: Add localserver feature check for localfortune examples Change-Id: I536645ddf0a5ead31a2658d03984c1226a7c39c8 Reviewed-by: Oswald Buddenhagen --- examples/corelib/ipc/ipc.pro | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/corelib/ipc/ipc.pro b/examples/corelib/ipc/ipc.pro index 101552cea9..68c88d75aa 100644 --- a/examples/corelib/ipc/ipc.pro +++ b/examples/corelib/ipc/ipc.pro @@ -3,4 +3,8 @@ requires(qtHaveModule(widgets)) TEMPLATE = subdirs qtConfig(sharedmemory): SUBDIRS = sharedmemory -qtHaveModule(network): SUBDIRS += localfortuneserver localfortuneclient +qtHaveModule(network) { + QT_FOR_CONFIG += network + + qtConfig(localserver): SUBDIRS += localfortuneserver localfortuneclient +} -- cgit v1.2.3 From 3adfcbf1ed9b63c3ce41d7417658db3836fd3530 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 21 Jan 2018 19:55:40 +0100 Subject: QHeaderView: properly restore section data after layoutChanged() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QHeaderView is doing a complete rebuild of the sections when the layout changed because everything could have happened. But since layoutChanged is also called during e.g. sorting, the old data must be restored when possible. Task-number: QTBUG-65478 Change-Id: I088d4d843cad362b97df6dc5e0dcb9819b13547f Reviewed-by: Thorbjørn Lund Martsum Reviewed-by: Richard Moe Gustavsen --- src/widgets/itemviews/qheaderview.cpp | 88 ++++++++++++++++------ src/widgets/itemviews/qheaderview_p.h | 11 +-- .../itemviews/qheaderview/tst_qheaderview.cpp | 13 +++- 3 files changed, 82 insertions(+), 30 deletions(-) diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index 0905a20812..e1aec3f4bd 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -351,7 +351,7 @@ void QHeaderView::setModel(QAbstractItemModel *model) if (model == this->model()) return; Q_D(QHeaderView); - d->persistentHiddenSections.clear(); + d->layoutChangePersistentSections.clear(); if (d->model && d->model != QAbstractItemModelPrivate::staticEmptyModel()) { if (d->orientation == Qt::Horizontal) { QObject::disconnect(d->model, SIGNAL(columnsInserted(QModelIndex,int,int)), @@ -2072,14 +2072,28 @@ void QHeaderViewPrivate::_q_layoutAboutToBeChanged() || model->columnCount(root) == 0) return; - if (hiddenSectionSize.count() == 0) - return; + layoutChangePersistentSections.clear(); + layoutChangePersistentSections.reserve(std::min(10, sectionItems.count())); + // after layoutChanged another section can be last stretched section + if (stretchLastSection) { + const int visual = visualIndex(lastSectionLogicalIdx); + sectionItems[visual].size = lastSectionSize; + } + for (int i = 0; i < sectionItems.size(); ++i) { + const auto &s = sectionItems.at(i); + // only add if the section is not default and not visually moved + if (s.size == defaultSectionSize && !s.isHidden && s.resizeMode == globalResizeMode) + continue; - for (int i = 0; i < sectionItems.count(); ++i) - if (isVisualIndexHidden(i)) // ### note that we are using column or row 0 - persistentHiddenSections.append(orientation == Qt::Horizontal - ? model->index(0, logicalIndex(i), root) - : model->index(logicalIndex(i), 0, root)); + // ### note that we are using column or row 0 + layoutChangePersistentSections.append({orientation == Qt::Horizontal + ? model->index(0, logicalIndex(i), root) + : model->index(logicalIndex(i), 0, root), + s}); + + if (layoutChangePersistentSections.size() > 1000) + break; + } } void QHeaderViewPrivate::_q_layoutChanged() @@ -2087,25 +2101,57 @@ void QHeaderViewPrivate::_q_layoutChanged() Q_Q(QHeaderView); viewport->update(); - const auto hiddenSections = persistentHiddenSections; - persistentHiddenSections.clear(); - - clear(); - q->initializeSections(); - invalidateCachedSizeHint(); + const auto oldPersistentSections = layoutChangePersistentSections; + layoutChangePersistentSections.clear(); - if (modelIsEmpty()) { + const int newCount = modelSectionCount(); + const int oldCount = sectionItems.size(); + if (newCount == 0) { + clear(); + if (oldCount != 0) + emit q->sectionCountChanged(oldCount, 0); return; } - for (const auto &index : hiddenSections) { - if (index.isValid()) { - const int logical = (orientation == Qt::Horizontal - ? index.column() - : index.row()); - q->setSectionHidden(logical, true); + // adjust section size + if (newCount != oldCount) { + const int min = qBound(0, oldCount, newCount - 1); + q->initializeSections(min, newCount - 1); + } + // reset sections + sectionItems.fill(SectionItem(defaultSectionSize, globalResizeMode), newCount); + + // all hidden sections are in oldPersistentSections + hiddenSectionSize.clear(); + + for (const auto &item : oldPersistentSections) { + const auto &index = item.index; + if (!index.isValid()) + continue; + + const int newLogicalIndex = (orientation == Qt::Horizontal + ? index.column() + : index.row()); + // the new visualIndices are already adjusted / reset by initializeSections() + const int newVisualIndex = visualIndex(newLogicalIndex); + auto &newSection = sectionItems[newVisualIndex]; + newSection = item.section; + + if (newSection.isHidden) { + // otherwise setSectionHidden will return without doing anything + newSection.isHidden = false; + q->setSectionHidden(newLogicalIndex, true); } } + + recalcSectionStartPos(); + length = headerLength(); + + if (stretchLastSection) { + // force rebuild of stretched section later on + lastSectionLogicalIdx = -1; + maybeRestorePrevLastSectionAndStretchLast(); + } } /*! diff --git a/src/widgets/itemviews/qheaderview_p.h b/src/widgets/itemviews/qheaderview_p.h index 8fc8b88aa5..c9c2cf8493 100644 --- a/src/widgets/itemviews/qheaderview_p.h +++ b/src/widgets/itemviews/qheaderview_p.h @@ -231,10 +231,6 @@ public: : model->rowCount(root)); } - inline bool modelIsEmpty() const { - return (model->rowCount(root) == 0 || model->columnCount(root) == 0); - } - inline void doDelayedResizeSections() { if (!delayedResize.isActive()) delayedResize.start(0, q_func()); @@ -304,7 +300,6 @@ public: QLabel *sectionIndicator; #endif QHeaderView::ResizeMode globalResizeMode; - QList persistentHiddenSections; mutable bool sectionStartposRecalc; int resizeContentsPrecision; // header sections @@ -335,6 +330,11 @@ public: }; QVector sectionItems; + struct LayoutChangeItem { + QPersistentModelIndex index; + SectionItem section; + }; + QVector layoutChangePersistentSections; void createSectionItems(int start, int end, int size, QHeaderView::ResizeMode mode); void removeSectionsFromSectionItems(int start, int end); @@ -388,6 +388,7 @@ public: }; Q_DECLARE_TYPEINFO(QHeaderViewPrivate::SectionItem, Q_PRIMITIVE_TYPE); +Q_DECLARE_TYPEINFO(QHeaderViewPrivate::LayoutChangeItem, Q_MOVABLE_TYPE); QT_END_NAMESPACE diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp index 90019a1798..6dae2cf8e4 100644 --- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp +++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp @@ -2251,10 +2251,6 @@ void tst_QHeaderView::QTBUG6058_reset() void tst_QHeaderView::QTBUG7833_sectionClicked() { - - - - QTableView tv; QStandardItemModel *sim = new QStandardItemModel(&tv); QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(&tv); @@ -2278,11 +2274,20 @@ void tst_QHeaderView::QTBUG7833_sectionClicked() tv.horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); tv.setModel(proxyModel); + const int section4Size = tv.horizontalHeader()->sectionSize(4) + 1; + tv.horizontalHeader()->resizeSection(4, section4Size); tv.setColumnHidden(5, true); tv.setColumnHidden(6, true); tv.horizontalHeader()->swapSections(8, 10); tv.sortByColumn(1, Qt::AscendingOrder); + QCOMPARE(tv.isColumnHidden(5), true); + QCOMPARE(tv.isColumnHidden(6), true); + QCOMPARE(tv.horizontalHeader()->sectionsMoved(), true); + QCOMPARE(tv.horizontalHeader()->logicalIndex(8), 10); + QCOMPARE(tv.horizontalHeader()->logicalIndex(10), 8); + QCOMPARE(tv.horizontalHeader()->sectionSize(4), section4Size); + QSignalSpy clickedSpy(tv.horizontalHeader(), SIGNAL(sectionClicked(int))); QSignalSpy pressedSpy(tv.horizontalHeader(), SIGNAL(sectionPressed(int))); -- cgit v1.2.3