| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2018 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtQuick 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 QQUICKTABLEVIEW_P_H |
| 41 | #define QQUICKTABLEVIEW_P_H |
| 42 | |
| 43 | // |
| 44 | // W A R N I N G |
| 45 | // ------------- |
| 46 | // |
| 47 | // This file is not part of the Qt API. It exists purely as an |
| 48 | // implementation detail. This header file may change from version to |
| 49 | // version without notice, or even be removed. |
| 50 | // |
| 51 | // We mean it. |
| 52 | // |
| 53 | |
| 54 | #include <private/qtquickglobal_p.h> |
| 55 | QT_REQUIRE_CONFIG(quick_tableview); |
| 56 | |
| 57 | #include <QtCore/qpointer.h> |
| 58 | #include <QtQuick/private/qtquickglobal_p.h> |
| 59 | #include <QtQuick/private/qquickflickable_p.h> |
| 60 | #include <QtQml/private/qqmlnullablevalue_p.h> |
| 61 | |
| 62 | QT_BEGIN_NAMESPACE |
| 63 | |
| 64 | class QQuickTableViewAttached; |
| 65 | class QQuickTableViewPrivate; |
| 66 | |
| 67 | class Q_QUICK_PRIVATE_EXPORT QQuickTableView : public QQuickFlickable |
| 68 | { |
| 69 | Q_OBJECT |
| 70 | |
| 71 | Q_PROPERTY(int rows READ rows NOTIFY rowsChanged) |
| 72 | Q_PROPERTY(int columns READ columns NOTIFY columnsChanged) |
| 73 | Q_PROPERTY(qreal rowSpacing READ rowSpacing WRITE setRowSpacing NOTIFY rowSpacingChanged) |
| 74 | Q_PROPERTY(qreal columnSpacing READ columnSpacing WRITE setColumnSpacing NOTIFY columnSpacingChanged) |
| 75 | Q_PROPERTY(QJSValue rowHeightProvider READ rowHeightProvider WRITE setRowHeightProvider NOTIFY rowHeightProviderChanged) |
| 76 | Q_PROPERTY(QJSValue columnWidthProvider READ columnWidthProvider WRITE setColumnWidthProvider NOTIFY columnWidthProviderChanged) |
| 77 | Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged) |
| 78 | Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) |
| 79 | Q_PROPERTY(bool reuseItems READ reuseItems WRITE setReuseItems NOTIFY reuseItemsChanged) |
| 80 | Q_PROPERTY(qreal contentWidth READ contentWidth WRITE setContentWidth NOTIFY contentWidthChanged) |
| 81 | Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight NOTIFY contentHeightChanged) |
| 82 | Q_PROPERTY(QQuickTableView *syncView READ syncView WRITE setSyncView NOTIFY syncViewChanged REVISION 14) |
| 83 | Q_PROPERTY(Qt::Orientations syncDirection READ syncDirection WRITE setSyncDirection NOTIFY syncDirectionChanged REVISION 14) |
| 84 | |
| 85 | QML_NAMED_ELEMENT(TableView) |
| 86 | QML_ADDED_IN_MINOR_VERSION(12) |
| 87 | QML_ATTACHED(QQuickTableViewAttached) |
| 88 | |
| 89 | public: |
| 90 | QQuickTableView(QQuickItem *parent = nullptr); |
| 91 | ~QQuickTableView() override; |
| 92 | int rows() const; |
| 93 | int columns() const; |
| 94 | |
| 95 | qreal rowSpacing() const; |
| 96 | void setRowSpacing(qreal spacing); |
| 97 | |
| 98 | qreal columnSpacing() const; |
| 99 | void setColumnSpacing(qreal spacing); |
| 100 | |
| 101 | QJSValue rowHeightProvider() const; |
| 102 | void setRowHeightProvider(const QJSValue &provider); |
| 103 | |
| 104 | QJSValue columnWidthProvider() const; |
| 105 | void setColumnWidthProvider(const QJSValue &provider); |
| 106 | |
| 107 | QVariant model() const; |
| 108 | void setModel(const QVariant &newModel); |
| 109 | |
| 110 | QQmlComponent *delegate() const; |
| 111 | void setDelegate(QQmlComponent *); |
| 112 | |
| 113 | bool reuseItems() const; |
| 114 | void setReuseItems(bool reuseItems); |
| 115 | |
| 116 | void setContentWidth(qreal width); |
| 117 | void setContentHeight(qreal height); |
| 118 | |
| 119 | QQuickTableView *syncView() const; |
| 120 | void setSyncView(QQuickTableView *view); |
| 121 | |
| 122 | Qt::Orientations syncDirection() const; |
| 123 | void setSyncDirection(Qt::Orientations direction); |
| 124 | |
| 125 | Q_INVOKABLE void forceLayout(); |
| 126 | |
| 127 | static QQuickTableViewAttached *qmlAttachedProperties(QObject *); |
| 128 | |
| 129 | Q_SIGNALS: |
| 130 | void rowsChanged(); |
| 131 | void columnsChanged(); |
| 132 | void rowSpacingChanged(); |
| 133 | void columnSpacingChanged(); |
| 134 | void rowHeightProviderChanged(); |
| 135 | void columnWidthProviderChanged(); |
| 136 | void modelChanged(); |
| 137 | void delegateChanged(); |
| 138 | void reuseItemsChanged(); |
| 139 | Q_REVISION(14) void syncViewChanged(); |
| 140 | Q_REVISION(14) void syncDirectionChanged(); |
| 141 | |
| 142 | protected: |
| 143 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; |
| 144 | void viewportMoved(Qt::Orientations orientation) override; |
| 145 | void componentComplete() override; |
| 146 | |
| 147 | protected: |
| 148 | QQuickTableView(QQuickTableViewPrivate &dd, QQuickItem *parent); |
| 149 | |
| 150 | private: |
| 151 | Q_DISABLE_COPY(QQuickTableView) |
| 152 | Q_DECLARE_PRIVATE(QQuickTableView) |
| 153 | |
| 154 | qreal minXExtent() const override; |
| 155 | qreal maxXExtent() const override; |
| 156 | qreal minYExtent() const override; |
| 157 | qreal maxYExtent() const override; |
| 158 | |
| 159 | Q_PRIVATE_SLOT(d_func(), void _q_componentFinalized()) |
| 160 | }; |
| 161 | |
| 162 | class Q_QUICK_PRIVATE_EXPORT QQuickTableViewAttached : public QObject |
| 163 | { |
| 164 | Q_OBJECT |
| 165 | Q_PROPERTY(QQuickTableView *view READ view NOTIFY viewChanged) |
| 166 | |
| 167 | public: |
| 168 | QQuickTableViewAttached(QObject *parent) |
| 169 | : QObject(parent) {} |
| 170 | |
| 171 | QQuickTableView *view() const { return m_view; } |
| 172 | void setView(QQuickTableView *newTableView) { |
| 173 | if (newTableView == m_view) |
| 174 | return; |
| 175 | m_view = newTableView; |
| 176 | Q_EMIT viewChanged(); |
| 177 | } |
| 178 | |
| 179 | Q_SIGNALS: |
| 180 | void viewChanged(); |
| 181 | void pooled(); |
| 182 | void reused(); |
| 183 | |
| 184 | private: |
| 185 | QPointer<QQuickTableView> m_view; |
| 186 | |
| 187 | friend class QQuickTableViewPrivate; |
| 188 | }; |
| 189 | |
| 190 | QT_END_NAMESPACE |
| 191 | |
| 192 | QML_DECLARE_TYPE(QQuickTableView) |
| 193 | |
| 194 | #endif // QQUICKTABLEVIEW_P_H |
| 195 | |