on xenial help sign in
Easier headerless categories
8e94bb1Albert Astals
plugins/Dash/listviewwithpageheader.cpp+9−35
@@ -141,8 +141,6 @@ void ListViewWithPageHeader::ListItem::setCulled(bool culled)
141void ListViewWithPageHeader::ListItem::setSectionItem(QQuickItem *sectionItem)
141void ListViewWithPageHeader::ListItem::setSectionItem(QQuickItem *sectionItem)
142{
142{
143 m_sectionItem = sectionItem;
143 m_sectionItem = sectionItem;
144− QQmlContext *context = QQmlEngine::contextForObject(m_item)->parentContext();
145− context->setContextProperty(QLatin1String("hasSectionHeader"), QVariant::fromValue<bool>(sectionItem != nullptr));
146}
144}
147
145
148ListViewWithPageHeader::ListViewWithPageHeader()
146ListViewWithPageHeader::ListViewWithPageHeader()
@@ -685,8 +683,6 @@ QQuickItem *ListViewWithPageHeader::getSectionItem(int modelIndex, bool alreadyI
685 return nullptr;
683 return nullptr;
686
684
687 const QString section = m_delegateModel->stringValue(modelIndex, m_sectionProperty);
685 const QString section = m_delegateModel->stringValue(modelIndex, m_sectionProperty);
688− if (section.isEmpty())
689− return nullptr;
690
686
691 if (modelIndex > 0) {
687 if (modelIndex > 0) {
692 const QString prevSection = m_delegateModel->stringValue(modelIndex - 1, m_sectionProperty);
688 const QString prevSection = m_delegateModel->stringValue(modelIndex - 1, m_sectionProperty);
@@ -877,7 +873,6 @@ void ListViewWithPageHeader::itemCreated(int modelIndex, QObject *object)
877 QQmlContext *context = QQmlEngine::contextForObject(item)->parentContext();
873 QQmlContext *context = QQmlEngine::contextForObject(item)->parentContext();
878 context->setContextProperty(QLatin1String("ListViewWithPageHeader"), this);
874 context->setContextProperty(QLatin1String("ListViewWithPageHeader"), this);
879 context->setContextProperty(QLatin1String("heightToClip"), QVariant::fromValue<int>(0));
875 context->setContextProperty(QLatin1String("heightToClip"), QVariant::fromValue<int>(0));
880− context->setContextProperty(QLatin1String("hasSectionHeader"), QVariant::fromValue<bool>(false));
881 if (modelIndex == m_asyncRequestedIndex) {
876 if (modelIndex == m_asyncRequestedIndex) {
882 createItem(modelIndex, false);
877 createItem(modelIndex, false);
883 refill();
878 refill();
@@ -931,17 +926,12 @@ void ListViewWithPageHeader::onModelUpdated(const QQmlChangeSet &changeSet, bool
931 const int visibleIndex = remove.index + i - m_firstVisibleIndex;
926 const int visibleIndex = remove.index + i - m_firstVisibleIndex;
932 if (visibleIndex >= 0 && visibleIndex < m_visibleItems.count()) {
927 if (visibleIndex >= 0 && visibleIndex < m_visibleItems.count()) {
933 ListItem *item = m_visibleItems[visibleIndex];
928 ListItem *item = m_visibleItems[visibleIndex];
934− // Pass the section item down if needed i.e. has no sectionItem because
929+ // Pass the section item down if needed
935− // had same section string (and not because it has no section at all)
936 if (item->sectionItem() && visibleIndex + 1 < m_visibleItems.count()) {
930 if (item->sectionItem() && visibleIndex + 1 < m_visibleItems.count()) {
937 ListItem *nextItem = m_visibleItems[visibleIndex + 1];
931 ListItem *nextItem = m_visibleItems[visibleIndex + 1];
938 if (!nextItem->sectionItem()) {
932 if (!nextItem->sectionItem()) {
939− const int modelIndex = remove.index + i;
940− const QString section = m_delegateModel->stringValue(modelIndex, m_sectionProperty);
941− if (!section.isEmpty()) {
942− nextItem->setSectionItem(item->sectionItem());
933+ nextItem->setSectionItem(item->sectionItem());
943− item->setSectionItem(nullptr);
934+ item->setSectionItem(nullptr);
944− }
945 }
935 }
946 }
936 }
947 releaseItem(item);
937 releaseItem(item);
@@ -1189,17 +1179,12 @@ void ListViewWithPageHeader::layout()
1189 // viewport is bigger than the start of the position of the first visible item
1179 // viewport is bigger than the start of the position of the first visible item
1190 // i.e. the first visible item starts before the viewport, or when the first
1180 // i.e. the first visible item starts before the viewport, or when the first
1191 // visible item starts just at the viewport start and it does not have its own section item
1181 // visible item starts just at the viewport start and it does not have its own section item
1192− const QString section = m_delegateModel->stringValue(modelIndex, m_sectionProperty);
1182+ if (topSectionStickPos > pos) {
1193− if (section.isEmpty()) {
1183+ showStickySectionItem = true;
1194− showStickySectionItem = false;
1184+ } else if (topSectionStickPos == pos) {
1185+ showStickySectionItem = !item->sectionItem();
1195 } else {
1186 } else {
1196− if (topSectionStickPos > pos) {
1197− showStickySectionItem = true;
1198− } else if (topSectionStickPos == pos) {
1199− showStickySectionItem = !item->sectionItem();
1200− } else {
1201− showStickySectionItem = false;
1187+ showStickySectionItem = false;
1202− }
1203 }
1188 }
1204 if (!showStickySectionItem) {
1189 if (!showStickySectionItem) {
1205 QQuickItemPrivate::get(m_topSectionItem)->setCulled(true);
1190 QQuickItemPrivate::get(m_topSectionItem)->setCulled(true);
@@ -1212,6 +1197,7 @@ void ListViewWithPageHeader::layout()
1212 }
1197 }
1213 } else {
1198 } else {
1214 // Update the top sticky section header
1199 // Update the top sticky section header
1200+ const QString section = m_delegateModel->stringValue(modelIndex, m_sectionProperty);
1215 QQmlContext *context = QQmlEngine::contextForObject(m_topSectionItem)->parentContext();
1201 QQmlContext *context = QQmlEngine::contextForObject(m_topSectionItem)->parentContext();
1216 context->setContextProperty(QLatin1String("section"), section);
1202 context->setContextProperty(QLatin1String("section"), section);
1217
1203
@@ -1255,18 +1241,6 @@ void ListViewWithPageHeader::layout()
1255 m_topSectionItem->setY(item->y() - m_topSectionItem->height());
1241 m_topSectionItem->setY(item->y() - m_topSectionItem->height());
1256 }
1242 }
1257 break;
1243 break;
1258− } else {
1259− // Is there no header because it's same section name or because has no section?
1260− // Because it is because we have no section (header) we still have to push it up
1261− const QString section = m_delegateModel->stringValue(firstReallyVisibleItem + 1, m_sectionProperty);
1262− if (section.isEmpty()) {
1263− if (m_topSectionItem->y() + m_topSectionItem->height() > item->y()) {
1264− m_topSectionItem->setY(item->y() - m_topSectionItem->height());
1265− QQmlContext *context = QQmlEngine::contextForObject(item->m_item)->parentContext();
1266− context->setContextProperty(QLatin1String("heightToClip"), QVariant::fromValue<int>(0));
1267− }
1268− break;
1269− }
1270 }
1244 }
1271 }
1245 }
1272 }
1246 }
qml/Dash/GenericScopeView.qml+2−1
@@ -148,7 +148,7 @@ FocusScope {
148 top: parent.top
148 top: parent.top
149 left: parent.left
149 left: parent.left
150 right: parent.right
150 right: parent.right
151− topMargin: hasSectionHeader ? 0 : units.gu(2)
151+ topMargin: section != "" ? 0 : units.gu(2)
152 }
152 }
153
153
154 source: {
154 source: {
@@ -327,6 +327,7 @@ FocusScope {
327 else
327 else
328 categoryView.expandedCategoryId = "";
328 categoryView.expandedCategoryId = "";
329 }
329 }
330+ height: section != "" ? units.gu(5) : 0
330 }
331 }
331
332
332 pageHeader: PageHeader {
333 pageHeader: PageHeader {
tests/plugins/Dash/tst_ListViewWithPageHeaderQML.qml+2−2
@@ -38,7 +38,7 @@ Rectangle {
38 move(indexFrom, indexTo, count);
38 move(indexFrom, indexTo, count);
39 }
39 }
40
40
41− ListElement { type: "Agressive"; size: 150 }
41+ ListElement { type: ""; size: 150 }
42 ListElement { type: "Regular"; size: 200 }
42 ListElement { type: "Regular"; size: 200 }
43 ListElement { type: "Mild"; size: 350 }
43 ListElement { type: "Mild"; size: 350 }
44 ListElement { type: "Bold"; size: 350 }
44 ListElement { type: "Bold"; size: 350 }
@@ -82,7 +82,7 @@ Rectangle {
82 id: sectionHeaderComponent
82 id: sectionHeaderComponent
83 Rectangle {
83 Rectangle {
84 color: "green"
84 color: "green"
85− height: listView.sectionHeaderHeight
85+ height: section != "" ? listView.sectionHeaderHeight : 0
86 Text { text: section; font.pixelSize: 34 }
86 Text { text: section; font.pixelSize: 34 }
87 anchors { left: parent.left; right: parent.right }
87 anchors { left: parent.left; right: parent.right }
88 }
88 }