on a142f21 help sign in
unity8/plugins/Dash/abstractdashview.h
133 lines 4.5 kB history raw
1/*
2 * Copyright (C) 2013, 2014 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17#ifndef ABSTRACTDASHVIEW_H
18#define ABSTRACTDASHVIEW_H
20#include <QQuickItem>
22class QAbstractItemModel;
23class QQmlComponent;
24#pragma GCC diagnostic push
25#pragma GCC diagnostic ignored "-pedantic"
26#include <private/qqmldelegatemodel_p.h>
27#include <qqmlinfo.h>
28#pragma GCC diagnostic pop
30class AbstractDashView : public QQuickItem
32 Q_OBJECT
34 Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelChanged)
35 Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
36 Q_PROPERTY(qreal columnSpacing READ columnSpacing WRITE setColumnSpacing NOTIFY columnSpacingChanged)
37 Q_PROPERTY(qreal rowSpacing READ rowSpacing WRITE setRowSpacing NOTIFY rowSpacingChanged)
38 Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer NOTIFY cacheBufferChanged)
39 Q_PROPERTY(qreal displayMarginBeginning READ displayMarginBeginning
40 WRITE setDisplayMarginBeginning
41 NOTIFY displayMarginBeginningChanged)
42 Q_PROPERTY(qreal displayMarginEnd READ displayMarginEnd
43 WRITE setDisplayMarginEnd
44 NOTIFY displayMarginEndChanged)
46friend class VerticalJournalTest;
47friend class HorizontalJournalTest;
48friend class OrganicGridTest;
50public:
51 AbstractDashView();
53 QAbstractItemModel *model() const;
54 void setModel(QAbstractItemModel *model);
56 QQmlComponent *delegate() const;
57 void setDelegate(QQmlComponent *delegate);
59 qreal columnSpacing() const;
60 void setColumnSpacing(qreal columnSpacing);
62 qreal rowSpacing() const;
63 void setRowSpacing(qreal rowSpacing);
65 int cacheBuffer() const;
66 void setCacheBuffer(int);
68 qreal displayMarginBeginning() const;
69 void setDisplayMarginBeginning(qreal);
71 qreal displayMarginEnd() const;
72 void setDisplayMarginEnd(qreal);
74Q_SIGNALS:
75 void modelChanged();
76 void delegateChanged();
77 void columnSpacingChanged();
78 void rowSpacingChanged();
79 void cacheBufferChanged();
80 void displayMarginBeginningChanged();
81 void displayMarginEndChanged();
83protected Q_SLOTS:
84 void relayout();
86protected:
87 void updatePolish() override;
88 void componentComplete() override;
90 void releaseItem(QQuickItem *item);
91 void setImplicitHeightDirty();
93private Q_SLOTS:
94 void itemCreated(int modelIndex, QObject *object);
95 void onModelUpdated(const QQmlChangeSet &changeSet, bool reset);
96 void onHeightChanged();
98private:
99 void createDelegateModel();
100 void refill();
101 bool addVisibleItems(qreal fillFromY, qreal fillToY, bool asynchronous);
102 QQuickItem *createItem(int modelIndex, bool asynchronous);
104 virtual void findBottomModelIndexToAdd(int *modelIndex, qreal *yPos) = 0;
105 virtual void findTopModelIndexToAdd(int *modelIndex, qreal *yPos) = 0;
106 virtual void addItemToView(int modelIndex, QQuickItem *item) = 0;
107 virtual bool removeNonVisibleItems(qreal bufferFromY, qreal bufferToY) = 0;
108 virtual void cleanupExistingItems() = 0;
109 virtual void doRelayout() = 0;
110 virtual void updateItemCulling(qreal visibleFromY, qreal visibleToY) = 0;
111 virtual void calculateImplicitHeight() = 0;
112#if (QT_VERSION < QT_VERSION_CHECK(5, 4, 0))
113 virtual void processModelRemoves(const QVector<QQmlChangeSet::Remove> &removes) = 0;
114#else
115 virtual void processModelRemoves(const QVector<QQmlChangeSet::Change> &removes) = 0;
116#endif
118 QQmlDelegateModel *m_delegateModel;
120 // Index we are waiting because we requested it asynchronously
121 int m_asyncRequestedIndex;
123 int m_columnSpacing;
124 int m_rowSpacing;
125 int m_buffer;
126 qreal m_displayMarginBeginning;
127 qreal m_displayMarginEnd;
128 bool m_needsRelayout;
129 bool m_delegateValidated;
130 bool m_implicitHeightDirty;
131};
133#endif