on 4d4ddfe help sign in
unity8/plugins/Dash/abstractdashview.h
127 lines 4.2 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;
25#include <private/qqmldelegatemodel_p.h>
26#include <qqmlinfo.h>
28class AbstractDashView : public QQuickItem
30 Q_OBJECT
32 Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelChanged)
33 Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
34 Q_PROPERTY(qreal columnSpacing READ columnSpacing WRITE setColumnSpacing NOTIFY columnSpacingChanged)
35 Q_PROPERTY(qreal rowSpacing READ rowSpacing WRITE setRowSpacing NOTIFY rowSpacingChanged)
36 Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer NOTIFY cacheBufferChanged)
37 Q_PROPERTY(qreal displayMarginBeginning READ displayMarginBeginning
38 WRITE setDisplayMarginBeginning
39 NOTIFY displayMarginBeginningChanged)
40 Q_PROPERTY(qreal displayMarginEnd READ displayMarginEnd
41 WRITE setDisplayMarginEnd
42 NOTIFY displayMarginEndChanged)
44friend class VerticalJournalTest;
45friend class HorizontalJournalTest;
46friend class OrganicGridTest;
48public:
49 AbstractDashView();
51 QAbstractItemModel *model() const;
52 void setModel(QAbstractItemModel *model);
54 QQmlComponent *delegate() const;
55 void setDelegate(QQmlComponent *delegate);
57 qreal columnSpacing() const;
58 void setColumnSpacing(qreal columnSpacing);
60 qreal rowSpacing() const;
61 void setRowSpacing(qreal rowSpacing);
63 int cacheBuffer() const;
64 void setCacheBuffer(int);
66 qreal displayMarginBeginning() const;
67 void setDisplayMarginBeginning(qreal);
69 qreal displayMarginEnd() const;
70 void setDisplayMarginEnd(qreal);
72Q_SIGNALS:
73 void modelChanged();
74 void delegateChanged();
75 void columnSpacingChanged();
76 void rowSpacingChanged();
77 void cacheBufferChanged();
78 void displayMarginBeginningChanged();
79 void displayMarginEndChanged();
81protected Q_SLOTS:
82 void relayout();
84protected:
85 void updatePolish() override;
86 void componentComplete() override;
88 void releaseItem(QQuickItem *item);
89 void setImplicitHeightDirty();
91private Q_SLOTS:
92 void itemCreated(int modelIndex, QObject *object);
93 void onModelUpdated(const QQmlChangeSet &changeSet, bool reset);
94 void onHeightChanged();
96private:
97 void createDelegateModel();
98 void refill();
99 bool addVisibleItems(qreal fillFromY, qreal fillToY, bool asynchronous);
100 QQuickItem *createItem(int modelIndex, bool asynchronous);
102 virtual void findBottomModelIndexToAdd(int *modelIndex, qreal *yPos) = 0;
103 virtual void findTopModelIndexToAdd(int *modelIndex, qreal *yPos) = 0;
104 virtual void addItemToView(int modelIndex, QQuickItem *item) = 0;
105 virtual bool removeNonVisibleItems(qreal bufferFromY, qreal bufferToY) = 0;
106 virtual void cleanupExistingItems() = 0;
107 virtual void doRelayout() = 0;
108 virtual void updateItemCulling(qreal visibleFromY, qreal visibleToY) = 0;
109 virtual void calculateImplicitHeight() = 0;
110 virtual void processModelRemoves(const QVector<QQmlChangeSet::Change> &removes) = 0;
112 QQmlDelegateModel *m_delegateModel;
114 // Index we are waiting because we requested it asynchronously
115 int m_asyncRequestedIndex;
117 int m_columnSpacing;
118 int m_rowSpacing;
119 int m_buffer;
120 qreal m_displayMarginBeginning;
121 qreal m_displayMarginEnd;
122 bool m_needsRelayout;
123 bool m_delegateValidated;
124 bool m_implicitHeightDirty;
125};
127#endif