Unity 8
 All Classes Functions Properties
abstractdashview.h
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  */
16 
17 #ifndef ABSTRACTDASHVIEW_H
18 #define ABSTRACTDASHVIEW_H
19 
20 #include <QQuickItem>
21 
22 class QAbstractItemModel;
23 class 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
29 
30 class AbstractDashView : public QQuickItem
31 {
32  Q_OBJECT
33 
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(qreal displayMarginBeginning READ displayMarginBeginning
39  WRITE setDisplayMarginBeginning
40  NOTIFY displayMarginBeginningChanged)
41  Q_PROPERTY(qreal displayMarginEnd READ displayMarginEnd
42  WRITE setDisplayMarginEnd
43  NOTIFY displayMarginEndChanged)
44 
45 friend class VerticalJournalTest;
46 friend class HorizontalJournalTest;
47 friend class OrganicGridTest;
48 
49 public:
50  AbstractDashView();
51 
52  QAbstractItemModel *model() const;
53  void setModel(QAbstractItemModel *model);
54 
55  QQmlComponent *delegate() const;
56  void setDelegate(QQmlComponent *delegate);
57 
58  qreal columnSpacing() const;
59  void setColumnSpacing(qreal columnSpacing);
60 
61  qreal rowSpacing() const;
62  void setRowSpacing(qreal rowSpacing);
63 
64  qreal displayMarginBeginning() const;
65  void setDisplayMarginBeginning(qreal);
66 
67  qreal displayMarginEnd() const;
68  void setDisplayMarginEnd(qreal);
69 
70 Q_SIGNALS:
71  void modelChanged();
72  void delegateChanged();
73  void columnSpacingChanged();
74  void rowSpacingChanged();
75  void displayMarginBeginningChanged();
76  void displayMarginEndChanged();
77 
78 protected Q_SLOTS:
79  void relayout();
80 
81 protected:
82  void updatePolish() override;
83  void componentComplete() override;
84 
85  void releaseItem(QQuickItem *item);
86  void setImplicitHeightDirty();
87 
88 private Q_SLOTS:
89  void itemCreated(int modelIndex, QObject *object);
90  void onModelUpdated(const QQmlChangeSet &changeSet, bool reset);
91  void onHeightChanged();
92 
93 private:
94  void createDelegateModel();
95  void refill();
96  bool addVisibleItems(qreal fillFromY, qreal fillToY, bool asynchronous);
97  QQuickItem *createItem(int modelIndex, bool asynchronous);
98 
99  virtual void findBottomModelIndexToAdd(int *modelIndex, qreal *yPos) = 0;
100  virtual void findTopModelIndexToAdd(int *modelIndex, qreal *yPos) = 0;
101  virtual void addItemToView(int modelIndex, QQuickItem *item) = 0;
102  virtual bool removeNonVisibleItems(qreal bufferFromY, qreal bufferToY) = 0;
103  virtual void cleanupExistingItems() = 0;
104  virtual void doRelayout() = 0;
105  virtual void updateItemCulling(qreal visibleFromY, qreal visibleToY) = 0;
106  virtual void calculateImplicitHeight() = 0;
107  virtual void processModelRemoves(const QVector<QQmlChangeSet::Remove> &removes) = 0;
108 
109  QQmlDelegateModel *m_delegateModel;
110 
111  // Index we are waiting because we requested it asynchronously
112  int m_asyncRequestedIndex;
113 
114  int m_columnSpacing;
115  int m_rowSpacing;
116  qreal m_displayMarginBeginning;
117  qreal m_displayMarginEnd;
118  bool m_needsRelayout;
119  bool m_delegateValidated;
120  bool m_implicitHeightDirty;
121 };
122 
123 #endif