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 <vector>
36
38
39QT_BEGIN_NAMESPACE
40
41class QColumnViewPreviewColumn : public QAbstractItemView {
42
43public:
44 explicit QColumnViewPreviewColumn(QWidget *parent) : QAbstractItemView(parent), previewWidget(nullptr) {
45 }
46
47 void setPreviewWidget(QWidget *widget) {
48 previewWidget = widget;
49 if (previewWidget)
50 setMinimumWidth(previewWidget->minimumWidth());
51 }
52
53 void resizeEvent(QResizeEvent * event) override{
54 if (!previewWidget)
55 return;
56 previewWidget->resize(
57 qMax(previewWidget->minimumWidth(), event->size().width()),
58 previewWidget->height());
59 QSize p = viewport()->size();
60 QSize v = previewWidget->size();
61 horizontalScrollBar()->setRange(0, v.width() - p.width());
62 horizontalScrollBar()->setPageStep(p.width());
63 verticalScrollBar()->setRange(0, v.height() - p.height());
64 verticalScrollBar()->setPageStep(p.height());
65
66 QAbstractScrollArea::resizeEvent(event);
67 }
68
69 void scrollContentsBy(int dx, int dy) override
70 {
71 if (!previewWidget)
72 return;
73 scrollDirtyRegion(dx, dy);
74 viewport()->scroll(dx, dy);
75
76 QAbstractItemView::scrollContentsBy(dx, dy);
77 }
78
79 QRect visualRect(const QModelIndex &) const override
80 {
81 return QRect();
82 }
83 void scrollTo(const QModelIndex &, ScrollHint) override
84 {
85 }
86 QModelIndex indexAt(const QPoint &) const override
87 {
88 return QModelIndex();
89 }
90 QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers) override
91 {
92 return QModelIndex();
93 }
94 int horizontalOffset () const override {
95 return 0;
96 }
97 int verticalOffset () const override {
98 return 0;
99 }
100 QRegion visualRegionForSelection(const QItemSelection &) const override
101 {
102 return QRegion();
103 }
104 bool isIndexHidden(const QModelIndex &) const override
105 {
106 return false;
107 }
108 void setSelection(const QRect &, QItemSelectionModel::SelectionFlags) override
109 {
110 }
111private:
112 QWidget *previewWidget;
113};
114
115class Q_AUTOTEST_EXPORT QColumnViewPrivate : public QAbstractItemViewPrivate
116{
117 Q_DECLARE_PUBLIC(QColumnView)
118
119public:
120 QColumnViewPrivate();
121 ~QColumnViewPrivate();
122 void initialize();
123 void clearConnections();
124
125 QAbstractItemView *createColumn(const QModelIndex &index, bool show);
126
127 void updateScrollbars();
128 void closeColumns(const QModelIndex &parent = QModelIndex(), bool build = false);
129 void disconnectView(QAbstractItemView *view);
130 void doLayout();
131 void setPreviewWidget(QWidget *widget);
132 QColumnViewPreviewColumn *createPreviewColumn();
133 void checkColumnCreation(const QModelIndex &parent);
134
135
136 void gripMoved(int offset);
137 void changeCurrentColumn();
138 void clicked(const QModelIndex &index);
139 void columnsInserted(const QModelIndex &parent, int start, int end) override;
140
141 QList<QAbstractItemView*> columns;
142 QList<int> columnSizes; // used during init and corner moving
143 bool showResizeGrips;
144 bool showPreviewColumn;
145 int offset;
146#if QT_CONFIG(animation)
147 QPropertyAnimation currentAnimation;
148 QMetaObject::Connection animationConnection;
149#endif
150 std::vector<QMetaObject::Connection> gripConnections;
151 using ViewConnections = std::vector<QMetaObject::Connection>;
152 QHash<QAbstractItemView *, ViewConnections> viewConnections;
153
154 QWidget *previewWidget;
155 QAbstractItemView *previewColumn;
156};
157
158/*!
159 * This is a delegate that will paint the triangle
160 */
162{
163
164public:
165 explicit QColumnViewDelegate(QObject *parent = nullptr) : QStyledItemDelegate(parent) {}
167
168 void paint(QPainter *painter,
169 const QStyleOptionViewItem &option,
170 const QModelIndex &index) const override;
171};
172
173QT_END_NAMESPACE
174
175#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)