1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtWidgets module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QLISTVIEW_H
41#define QLISTVIEW_H
42
43#include <QtWidgets/qtwidgetsglobal.h>
44#include <QtWidgets/qabstractitemview.h>
45
46QT_REQUIRE_CONFIG(listview);
47
48QT_BEGIN_NAMESPACE
49
50class QListViewPrivate;
51
52class Q_WIDGETS_EXPORT QListView : public QAbstractItemView
53{
54 Q_OBJECT
55 Q_PROPERTY(Movement movement READ movement WRITE setMovement)
56 Q_PROPERTY(Flow flow READ flow WRITE setFlow)
57 Q_PROPERTY(bool isWrapping READ isWrapping WRITE setWrapping)
58 Q_PROPERTY(ResizeMode resizeMode READ resizeMode WRITE setResizeMode)
59 Q_PROPERTY(LayoutMode layoutMode READ layoutMode WRITE setLayoutMode)
60 Q_PROPERTY(int spacing READ spacing WRITE setSpacing)
61 Q_PROPERTY(QSize gridSize READ gridSize WRITE setGridSize)
62 Q_PROPERTY(ViewMode viewMode READ viewMode WRITE setViewMode)
63 Q_PROPERTY(int modelColumn READ modelColumn WRITE setModelColumn)
64 Q_PROPERTY(bool uniformItemSizes READ uniformItemSizes WRITE setUniformItemSizes)
65 Q_PROPERTY(int batchSize READ batchSize WRITE setBatchSize)
66 Q_PROPERTY(bool wordWrap READ wordWrap WRITE setWordWrap)
67 Q_PROPERTY(bool selectionRectVisible READ isSelectionRectVisible WRITE setSelectionRectVisible)
68 Q_PROPERTY(Qt::Alignment itemAlignment READ itemAlignment WRITE setItemAlignment)
69
70public:
71 enum Movement { Static, Free, Snap };
72 Q_ENUM(Movement)
73 enum Flow { LeftToRight, TopToBottom };
74 Q_ENUM(Flow)
75 enum ResizeMode { Fixed, Adjust };
76 Q_ENUM(ResizeMode)
77 enum LayoutMode { SinglePass, Batched };
78 Q_ENUM(LayoutMode)
79 enum ViewMode { ListMode, IconMode };
80 Q_ENUM(ViewMode)
81
82 explicit QListView(QWidget *parent = nullptr);
83 ~QListView();
84
85 void setMovement(Movement movement);
86 Movement movement() const;
87
88 void setFlow(Flow flow);
89 Flow flow() const;
90
91 void setWrapping(bool enable);
92 bool isWrapping() const;
93
94 void setResizeMode(ResizeMode mode);
95 ResizeMode resizeMode() const;
96
97 void setLayoutMode(LayoutMode mode);
98 LayoutMode layoutMode() const;
99
100 void setSpacing(int space);
101 int spacing() const;
102
103 void setBatchSize(int batchSize);
104 int batchSize() const;
105
106 void setGridSize(const QSize &size);
107 QSize gridSize() const;
108
109 void setViewMode(ViewMode mode);
110 ViewMode viewMode() const;
111
112 void clearPropertyFlags();
113
114 bool isRowHidden(int row) const;
115 void setRowHidden(int row, bool hide);
116
117 void setModelColumn(int column);
118 int modelColumn() const;
119
120 void setUniformItemSizes(bool enable);
121 bool uniformItemSizes() const;
122
123 void setWordWrap(bool on);
124 bool wordWrap() const;
125
126 void setSelectionRectVisible(bool show);
127 bool isSelectionRectVisible() const;
128
129 void setItemAlignment(Qt::Alignment alignment);
130 Qt::Alignment itemAlignment() const;
131
132 QRect visualRect(const QModelIndex &index) const override;
133 void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) override;
134 QModelIndex indexAt(const QPoint &p) const override;
135
136 void doItemsLayout() override;
137 void reset() override;
138 void setRootIndex(const QModelIndex &index) override;
139
140Q_SIGNALS:
141 void indexesMoved(const QModelIndexList &indexes);
142
143protected:
144 QListView(QListViewPrivate &, QWidget *parent = nullptr);
145
146 bool event(QEvent *e) override;
147
148 void scrollContentsBy(int dx, int dy) override;
149
150 void resizeContents(int width, int height);
151 QSize contentsSize() const;
152
153 void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>()) override;
154 void rowsInserted(const QModelIndex &parent, int start, int end) override;
155 void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) override;
156
157 void mouseMoveEvent(QMouseEvent *e) override;
158 void mouseReleaseEvent(QMouseEvent *e) override;
159#if QT_CONFIG(wheelevent)
160 void wheelEvent(QWheelEvent *e) override;
161#endif
162
163 void timerEvent(QTimerEvent *e) override;
164 void resizeEvent(QResizeEvent *e) override;
165#if QT_CONFIG(draganddrop)
166 void dragMoveEvent(QDragMoveEvent *e) override;
167 void dragLeaveEvent(QDragLeaveEvent *e) override;
168 void dropEvent(QDropEvent *e) override;
169 void startDrag(Qt::DropActions supportedActions) override;
170#endif // QT_CONFIG(draganddrop)
171
172 QStyleOptionViewItem viewOptions() const override;
173 void paintEvent(QPaintEvent *e) override;
174
175 int horizontalOffset() const override;
176 int verticalOffset() const override;
177 QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override;
178 QRect rectForIndex(const QModelIndex &index) const;
179 void setPositionForIndex(const QPoint &position, const QModelIndex &index);
180
181 void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) override;
182 QRegion visualRegionForSelection(const QItemSelection &selection) const override;
183 QModelIndexList selectedIndexes() const override;
184
185 void updateGeometries() override;
186
187 bool isIndexHidden(const QModelIndex &index) const override;
188
189 void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override;
190 void currentChanged(const QModelIndex &current, const QModelIndex &previous) override;
191
192 QSize viewportSizeHint() const override;
193
194private:
195 int visualIndex(const QModelIndex &index) const;
196
197 Q_DECLARE_PRIVATE(QListView)
198 Q_DISABLE_COPY(QListView)
199};
200
201QT_END_NAMESPACE
202
203#endif // QLISTVIEW_H
204

source code of qtbase/src/widgets/itemviews/qlistview.h