on ab2f849 help sign in
unity8/plugins/Dash/abstractdashview.h
128 lines 4.3 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 <private/qquickitemchangelistener_p.h>
27#include <qqmlinfo.h>
29class AbstractDashView : public QQuickItem, public QQuickItemChangeListener
31 Q_OBJECT
33 Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelChanged)
34 Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
35 Q_PROPERTY(qreal columnSpacing READ columnSpacing WRITE setColumnSpacing NOTIFY columnSpacingChanged)
36 Q_PROPERTY(qreal rowSpacing READ rowSpacing WRITE setRowSpacing NOTIFY rowSpacingChanged)
37 Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer NOTIFY cacheBufferChanged)
38 Q_PROPERTY(qreal displayMarginBeginning READ displayMarginBeginning
39 WRITE setDisplayMarginBeginning
40 NOTIFY displayMarginBeginningChanged)
41 Q_PROPERTY(qreal displayMarginEnd READ displayMarginEnd
42 WRITE setDisplayMarginEnd
43 NOTIFY displayMarginEndChanged)
45friend class VerticalJournalTest;
46friend class HorizontalJournalTest;
47friend class OrganicGridTest;
49public:
50 AbstractDashView();
52 QAbstractItemModel *model() const;
53 void setModel(QAbstractItemModel *model);
55 QQmlComponent *delegate() const;
56 void setDelegate(QQmlComponent *delegate);
58 qreal columnSpacing() const;
59 void setColumnSpacing(qreal columnSpacing);
61 qreal rowSpacing() const;
62 void setRowSpacing(qreal rowSpacing);
64 int cacheBuffer() const;
65 void setCacheBuffer(int);
67 qreal displayMarginBeginning() const;
68 void setDisplayMarginBeginning(qreal);
70 qreal displayMarginEnd() const;
71 void setDisplayMarginEnd(qreal);
73Q_SIGNALS:
74 void modelChanged();
75 void delegateChanged();
76 void columnSpacingChanged();
77 void rowSpacingChanged();
78 void cacheBufferChanged();
79 void displayMarginBeginningChanged();
80 void displayMarginEndChanged();
82protected Q_SLOTS:
83 void relayout();
85protected:
86 void updatePolish() override;
87 void componentComplete() override;
89 void releaseItem(QQuickItem *item);
90 void setImplicitHeightDirty();
92private Q_SLOTS:
93 void itemCreated(int modelIndex, QObject *object);
94 void onModelUpdated(const QQmlChangeSet &changeSet, bool reset);
95 void onHeightChanged();
97private:
98 void createDelegateModel();
99 void refill();
100 bool addVisibleItems(qreal fillFromY, qreal fillToY, bool asynchronous);
101 QQuickItem *createItem(int modelIndex, bool asynchronous);
103 virtual void findBottomModelIndexToAdd(int *modelIndex, qreal *yPos) = 0;
104 virtual void findTopModelIndexToAdd(int *modelIndex, qreal *yPos) = 0;
105 virtual void addItemToView(int modelIndex, QQuickItem *item) = 0;
106 virtual bool removeNonVisibleItems(qreal bufferFromY, qreal bufferToY) = 0;
107 virtual void cleanupExistingItems() = 0;
108 virtual void doRelayout() = 0;
109 virtual void updateItemCulling(qreal visibleFromY, qreal visibleToY) = 0;
110 virtual void calculateImplicitHeight() = 0;
111 virtual void processModelRemoves(const QVector<QQmlChangeSet::Change> &removes) = 0;
113 QQmlDelegateModel *m_delegateModel;
115 // Index we are waiting because we requested it asynchronously
116 int m_asyncRequestedIndex;
118 int m_columnSpacing;
119 int m_rowSpacing;
120 int m_buffer;
121 qreal m_displayMarginBeginning;
122 qreal m_displayMarginEnd;
123 bool m_needsRelayout;
124 bool m_delegateValidated;
125 bool m_implicitHeightDirty;
126};
128#endif