From d82d92d7dd71c1ef155b0dd5dea34c257fdad65c Mon Sep 17 00:00:00 2001 From: Frank Reininghaus Date: Wed, 13 Feb 2013 17:56:03 +0100 Subject: Improve the recently added test testMouseClickActivation The method to make sure that the first item is visible turned out to be less reliable than I thought. This could make the test hang forever. Moreover, this commit removes some trailing whitespace that had been added accidentally. --- src/tests/kitemlistcontrollertest.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/tests/kitemlistcontrollertest.cpp b/src/tests/kitemlistcontrollertest.cpp index 8044f9ac9..279096655 100644 --- a/src/tests/kitemlistcontrollertest.cpp +++ b/src/tests/kitemlistcontrollertest.cpp @@ -521,12 +521,9 @@ void KItemListControllerTest::testMouseClickActivation() adjustGeometryForColumnCount(5); // Make sure that the first item is visible in the view. - QTest::keyClick(m_container, Qt::Key_End, Qt::NoModifier); - QTest::keyClick(m_container, Qt::Key_Home, Qt::NoModifier); - while (m_view->firstVisibleIndex() > 0) { - QTest::qWait(50); - } - + m_view->setScrollOffset(0); + QCOMPARE(m_view->firstVisibleIndex(), 0); + const QPointF pos = m_view->itemContextRect(0).center(); // Save the "single click" setting. @@ -544,9 +541,9 @@ void KItemListControllerTest::testMouseClickActivation() mouseReleaseEvent.setPos(pos); mouseReleaseEvent.setButton(Qt::LeftButton); mouseReleaseEvent.setButtons(Qt::NoButton); - + QSignalSpy spyItemActivated(m_controller, SIGNAL(itemActivated(int))); - + // Default setting: single click activation. group.writeEntry("SingleClick", true, KConfig::Persistent|KConfig::Global); config.sync(); @@ -558,7 +555,7 @@ void KItemListControllerTest::testMouseClickActivation() m_view->event(&mouseReleaseEvent); QCOMPARE(spyItemActivated.count(), 1); spyItemActivated.clear(); - + // Set the global setting to "double click activation". group.writeEntry("SingleClick", false, KConfig::Persistent|KConfig::Global); config.sync(); @@ -570,7 +567,7 @@ void KItemListControllerTest::testMouseClickActivation() m_view->event(&mouseReleaseEvent); QCOMPARE(spyItemActivated.count(), 0); spyItemActivated.clear(); - + // Enforce single click activation in the controller. m_controller->setSingleClickActivationEnforced(true); m_view->event(&mousePressEvent); @@ -584,7 +581,7 @@ void KItemListControllerTest::testMouseClickActivation() m_view->event(&mouseReleaseEvent); QCOMPARE(spyItemActivated.count(), 0); spyItemActivated.clear(); - + // Set the global setting back to "single click activation". group.writeEntry("SingleClick", true, KConfig::Persistent|KConfig::Global); config.sync(); @@ -596,7 +593,7 @@ void KItemListControllerTest::testMouseClickActivation() m_view->event(&mouseReleaseEvent); QCOMPARE(spyItemActivated.count(), 1); spyItemActivated.clear(); - + // Enforce single click activation in the controller. m_controller->setSingleClickActivationEnforced(true); m_view->event(&mousePressEvent); -- cgit v1.3 From fc0c3f9d4e13d3c7ff3fb56e84458e62abf3ad4b Mon Sep 17 00:00:00 2001 From: Frank Reininghaus Date: Sun, 17 Feb 2013 11:21:00 +0100 Subject: Prevent repeated re-layouting of all items while previews are generated There was some code in KStandardItemListView::itemSizeHintUpdateRequired already that was supposed to prevent an expensive re-layouting of all items when a preview is received. However, it didn't quite work as intended because also the "iconOverlays" role changed. The new approach is to only re-layout if text of a visible role changes, because this is the only way how the space needed by an item might change (see KStandardItemListWidgetInformant::itemSizeHint()). BUG: 315315 FIXED-IN: 4.10.1 REVIEW: 108984 --- src/kitemviews/kstandarditemlistview.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/kitemviews/kstandarditemlistview.cpp b/src/kitemviews/kstandarditemlistview.cpp index 79eb86b89..bd4f6081f 100644 --- a/src/kitemviews/kstandarditemlistview.cpp +++ b/src/kitemviews/kstandarditemlistview.cpp @@ -104,17 +104,17 @@ void KStandardItemListView::initializeItemListWidget(KItemListWidget* item) bool KStandardItemListView::itemSizeHintUpdateRequired(const QSet& changedRoles) const { + // The only thing that can modify the item's size hint is the amount of space + // needed to display the text for the visible roles. // Even if the icons have a different size they are always aligned within // the area defined by KItemStyleOption.iconSize and hence result in no // change of the item-size. - const bool containsIconName = changedRoles.contains("iconName"); - const bool containsIconPixmap = changedRoles.contains("iconPixmap"); - const int count = changedRoles.count(); - - const bool iconChanged = (containsIconName && containsIconPixmap && count == 2) || - (containsIconName && count == 1) || - (containsIconPixmap && count == 1); - return !iconChanged; + foreach (const QByteArray& role, visibleRoles()) { + if (changedRoles.contains(role)) { + return true; + } + } + return false; } void KStandardItemListView::onItemLayoutChanged(ItemLayout current, ItemLayout previous) -- cgit v1.3 From ba314579113b9ce4b2856b446a17d7ea4ce22117 Mon Sep 17 00:00:00 2001 From: Frank Reininghaus Date: Sun, 17 Feb 2013 12:12:52 +0100 Subject: Another fix for KItemListControllerTest::testMouseClickActivation() One one machine, I see that changing the global "single click" setting fails. I don't know why that is the case, but I think we should better just skip the test in that case and not hang forever. --- src/tests/kitemlistcontrollertest.cpp | 44 +++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/tests/kitemlistcontrollertest.cpp b/src/tests/kitemlistcontrollertest.cpp index 279096655..d8f838873 100644 --- a/src/tests/kitemlistcontrollertest.cpp +++ b/src/tests/kitemlistcontrollertest.cpp @@ -548,9 +548,19 @@ void KItemListControllerTest::testMouseClickActivation() group.writeEntry("SingleClick", true, KConfig::Persistent|KConfig::Global); config.sync(); KGlobalSettings::self()->emitChange(KGlobalSettings::SettingsChanged, KGlobalSettings::SETTINGS_MOUSE); - while (!KGlobalSettings::singleClick()) { + + int iterations = 0; + const int maxIterations = 20; + while (!KGlobalSettings::singleClick() && iterations < maxIterations) { QTest::qWait(50); + ++iterations; + } + + if (!KGlobalSettings::singleClick()) { + // TODO: Try to find a way to make sure that changing the global setting works. + QSKIP("Failed to change the KGlobalSettings::singleClick() setting!", SkipSingle); } + m_view->event(&mousePressEvent); m_view->event(&mouseReleaseEvent); QCOMPARE(spyItemActivated.count(), 1); @@ -560,9 +570,18 @@ void KItemListControllerTest::testMouseClickActivation() group.writeEntry("SingleClick", false, KConfig::Persistent|KConfig::Global); config.sync(); KGlobalSettings::self()->emitChange(KGlobalSettings::SettingsChanged, KGlobalSettings::SETTINGS_MOUSE); - while (KGlobalSettings::singleClick()) { + + iterations = 0; + while (KGlobalSettings::singleClick() && iterations < maxIterations) { QTest::qWait(50); + ++iterations; + } + + if (KGlobalSettings::singleClick()) { + // TODO: Try to find a way to make sure that changing the global setting works. + QSKIP("Failed to change the KGlobalSettings::singleClick() setting!", SkipSingle); } + m_view->event(&mousePressEvent); m_view->event(&mouseReleaseEvent); QCOMPARE(spyItemActivated.count(), 0); @@ -586,9 +605,18 @@ void KItemListControllerTest::testMouseClickActivation() group.writeEntry("SingleClick", true, KConfig::Persistent|KConfig::Global); config.sync(); KGlobalSettings::self()->emitChange(KGlobalSettings::SettingsChanged, KGlobalSettings::SETTINGS_MOUSE); - while (!KGlobalSettings::singleClick()) { + + iterations = 0; + while (!KGlobalSettings::singleClick() && iterations < maxIterations) { QTest::qWait(50); + ++iterations; + } + + if (!KGlobalSettings::singleClick()) { + // TODO: Try to find a way to make sure that changing the global setting works. + QSKIP("Failed to change the KGlobalSettings::singleClick() setting!", SkipSingle); } + m_view->event(&mousePressEvent); m_view->event(&mouseReleaseEvent); QCOMPARE(spyItemActivated.count(), 1); @@ -606,8 +634,16 @@ void KItemListControllerTest::testMouseClickActivation() group.writeEntry("SingleClick", restoreKGlobalSettingsSingleClick, KConfig::Persistent|KConfig::Global); config.sync(); KGlobalSettings::self()->emitChange(KGlobalSettings::SettingsChanged, KGlobalSettings::SETTINGS_MOUSE); - while (KGlobalSettings::singleClick() != restoreKGlobalSettingsSingleClick) { + + iterations = 0; + while (KGlobalSettings::singleClick() != restoreKGlobalSettingsSingleClick && iterations < maxIterations) { QTest::qWait(50); + ++iterations; + } + + if (KGlobalSettings::singleClick() != restoreKGlobalSettingsSingleClick) { + // TODO: Try to find a way to make sure that changing the global setting works. + QSKIP("Failed to change the KGlobalSettings::singleClick() setting!", SkipSingle); } } -- cgit v1.3