Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qcolumnview_p.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QCOLUMNVIEW_P_H
6#define QCOLUMNVIEW_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists for the convenience
13// of other Qt classes. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtWidgets/private/qtwidgetsglobal_p.h>
20#include "qcolumnview.h"
21
22#include <private/qabstractitemview_p.h>
23
24#include <QtCore/qabstractitemmodel.h>
25#if QT_CONFIG(animation)
26#include <QtCore/qpropertyanimation.h>
27#endif
28#include <QtWidgets/qabstractitemdelegate.h>
29#include <QtWidgets/qabstractitemview.h>
30#include <QtWidgets/qstyleditemdelegate.h>
31#include <qlistview.h>
32#include <qevent.h>
33#include <qscrollbar.h>
34
35#include <QtCore/private/qflatmap_p.h>
36
37#include <vector>
38
40
41QT_BEGIN_NAMESPACE
42
43class QColumnViewPreviewColumn : public QAbstractItemView {
44
45public:
46 explicit QColumnViewPreviewColumn(QWidget *parent) : QAbstractItemView(parent), previewWidget(nullptr) {
47 }
48
49 void setPreviewWidget(QWidget *widget) {
50 previewWidget = widget;
51 if (previewWidget)
52 setMinimumWidth(previewWidget->minimumWidth());
53 }
54
55 void resizeEvent(QResizeEvent * event) override{
56 if (!previewWidget)
57 return;
58 previewWidget->resize(
59 qMax(previewWidget->minimumWidth(), event->size().width()),
60 previewWidget->height());
61 QSize p = viewport()->size();
62 QSize v = previewWidget->size();
63 horizontalScrollBar()->setRange(0, v.width() - p.width());
64 horizontalScrollBar()->setPageStep(p.width());
65 verticalScrollBar()->setRange(0, v.height() - p.height());
66 verticalScrollBar()->setPageStep(p.height());
67
68 QAbstractScrollArea::resizeEvent(event);
69 }
70
71 void scrollContentsBy(int dx, int dy) override
72 {
73 if (!previewWidget)
74 return;
75 scrollDirtyRegion(dx, dy);
76 viewport()->scroll(dx, dy);
77
78 QAbstractItemView::scrollContentsBy(dx, dy);
79 }
80
81 QRect visualRect(const QModelIndex &) const override
82 {
83 return QRect();
84 }
85 void scrollTo(const QModelIndex &, ScrollHint) override
86 {
87 }
88 QModelIndex indexAt(const QPoint &) const override
89 {
90 return QModelIndex();
91 }
92 QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers) override
93 {
94 return QModelIndex();
95 }
96 int horizontalOffset () const override {
97 return 0;
98 }
99 int verticalOffset () const override {
100 return 0;
101 }
102 QRegion visualRegionForSelection(const QItemSelection &) const override
103 {
104 return QRegion();
105 }
106 bool isIndexHidden(const QModelIndex &) const override
107 {
108 return false;
109 }
110 void setSelection(const QRect &, QItemSelectionModel::SelectionFlags) override
111 {
112 }
113private:
114 QWidget *previewWidget;
115};
116
117class Q_AUTOTEST_EXPORT QColumnViewPrivate : public QAbstractItemViewPrivate
118{
119 Q_DECLARE_PUBLIC(QColumnView)
120
121public:
122 QColumnViewPrivate();
123 ~QColumnViewPrivate();
124 void initialize();
125
126 QAbstractItemView *createColumn(const QModelIndex &index, bool show);
127
128 void updateScrollbars();
129 void closeColumns(const QModelIndex &parent = QModelIndex(), bool build = false);
130 void disconnectView(QAbstractItemView *view);
131 void doLayout();
132 void setPreviewWidget(QWidget *widget);
133 QColumnViewPreviewColumn *createPreviewColumn();
134 void checkColumnCreation(const QModelIndex &parent);
135
136
137 void gripMoved(int offset);
138 void changeCurrentColumn();
139 void clicked(const QModelIndex &index);
140 void columnsInserted(const QModelIndex &parent, int start, int end) override;
141
142 QList<QAbstractItemView*> columns;
143 QList<int> columnSizes; // used during init and corner moving
144 bool showResizeGrips;
145 bool showPreviewColumn;
146 int offset;
147#if QT_CONFIG(animation)
148 QPropertyAnimation currentAnimation;
149 QMetaObject::Connection animationConnection;
150#endif
151 std::vector<QMetaObject::Connection> gripConnections;
152 using ViewConnections = std::array<QMetaObject::Connection, 6>;
153 QVarLengthFlatMap<QAbstractItemView *, ViewConnections, 4> viewConnections;
154
155 QWidget *previewWidget;
156 QAbstractItemView *previewColumn;
157};
158
159/*!
160 * This is a delegate that will paint the triangle
161 */
163{
164
165public:
166 explicit QColumnViewDelegate(QObject *parent = nullptr) : QStyledItemDelegate(parent) {}
168
169 void paint(QPainter *painter,
170 const QStyleOptionViewItem &option,
171 const QModelIndex &index) const override;
172};
173
174QT_END_NAMESPACE
175
176#endif //QCOLUMNVIEW_P_H
This is a delegate that will paint the triangle.
QColumnViewDelegate(QObject *parent=nullptr)
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
This pure abstract function must be reimplemented if you want to provide custom rendering.
QT_REQUIRE_CONFIG(columnview)