| 1 | // Copyright (C) 2016 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 | |
| 4 | #ifndef QCOMPLETER_H |
| 5 | #define QCOMPLETER_H |
| 6 | |
| 7 | #include <QtWidgets/qtwidgetsglobal.h> |
| 8 | #include <QtCore/qobject.h> |
| 9 | #include <QtCore/qpoint.h> |
| 10 | #include <QtCore/qstring.h> |
| 11 | #include <QtCore/qabstractitemmodel.h> |
| 12 | #include <QtCore/qrect.h> |
| 13 | |
| 14 | QT_REQUIRE_CONFIG(completer); |
| 15 | |
| 16 | QT_BEGIN_NAMESPACE |
| 17 | |
| 18 | class QCompleterPrivate; |
| 19 | class QAbstractItemView; |
| 20 | class QAbstractProxyModel; |
| 21 | class QWidget; |
| 22 | |
| 23 | class Q_WIDGETS_EXPORT QCompleter : public QObject |
| 24 | { |
| 25 | Q_OBJECT |
| 26 | Q_PROPERTY(QString completionPrefix READ completionPrefix WRITE setCompletionPrefix) |
| 27 | Q_PROPERTY(ModelSorting modelSorting READ modelSorting WRITE setModelSorting) |
| 28 | Q_PROPERTY(Qt::MatchFlags filterMode READ filterMode WRITE setFilterMode) |
| 29 | Q_PROPERTY(CompletionMode completionMode READ completionMode WRITE setCompletionMode) |
| 30 | Q_PROPERTY(int completionColumn READ completionColumn WRITE setCompletionColumn) |
| 31 | Q_PROPERTY(int completionRole READ completionRole WRITE setCompletionRole) |
| 32 | Q_PROPERTY(int maxVisibleItems READ maxVisibleItems WRITE setMaxVisibleItems) |
| 33 | Q_PROPERTY(Qt::CaseSensitivity caseSensitivity READ caseSensitivity WRITE setCaseSensitivity) |
| 34 | Q_PROPERTY(bool wrapAround READ wrapAround WRITE setWrapAround) |
| 35 | |
| 36 | public: |
| 37 | enum CompletionMode { |
| 38 | , |
| 39 | , |
| 40 | InlineCompletion |
| 41 | }; |
| 42 | Q_ENUM(CompletionMode) |
| 43 | |
| 44 | enum ModelSorting { |
| 45 | UnsortedModel = 0, |
| 46 | CaseSensitivelySortedModel, |
| 47 | CaseInsensitivelySortedModel |
| 48 | }; |
| 49 | Q_ENUM(ModelSorting) |
| 50 | |
| 51 | QCompleter(QObject *parent = nullptr); |
| 52 | QCompleter(QAbstractItemModel *model, QObject *parent = nullptr); |
| 53 | #if QT_CONFIG(stringlistmodel) |
| 54 | QCompleter(const QStringList& completions, QObject *parent = nullptr); |
| 55 | #endif |
| 56 | ~QCompleter() override; |
| 57 | |
| 58 | void setWidget(QWidget *widget); |
| 59 | QWidget *widget() const; |
| 60 | |
| 61 | void setModel(QAbstractItemModel *c); |
| 62 | QAbstractItemModel *model() const; |
| 63 | |
| 64 | void setCompletionMode(CompletionMode mode); |
| 65 | CompletionMode completionMode() const; |
| 66 | |
| 67 | void setFilterMode(Qt::MatchFlags filterMode); |
| 68 | Qt::MatchFlags filterMode() const; |
| 69 | |
| 70 | QAbstractItemView *() const; |
| 71 | void (QAbstractItemView *); |
| 72 | |
| 73 | void setCaseSensitivity(Qt::CaseSensitivity caseSensitivity); |
| 74 | Qt::CaseSensitivity caseSensitivity() const; |
| 75 | |
| 76 | void setModelSorting(ModelSorting sorting); |
| 77 | ModelSorting modelSorting() const; |
| 78 | |
| 79 | void setCompletionColumn(int column); |
| 80 | int completionColumn() const; |
| 81 | |
| 82 | void setCompletionRole(int role); |
| 83 | int completionRole() const; |
| 84 | |
| 85 | bool wrapAround() const; |
| 86 | |
| 87 | int maxVisibleItems() const; |
| 88 | void setMaxVisibleItems(int maxItems); |
| 89 | |
| 90 | int completionCount() const; |
| 91 | bool setCurrentRow(int row); |
| 92 | int currentRow() const; |
| 93 | |
| 94 | QModelIndex currentIndex() const; |
| 95 | QString currentCompletion() const; |
| 96 | |
| 97 | QAbstractItemModel *completionModel() const; |
| 98 | |
| 99 | QString completionPrefix() const; |
| 100 | |
| 101 | public Q_SLOTS: |
| 102 | void setCompletionPrefix(const QString &prefix); |
| 103 | void complete(const QRect& rect = QRect()); |
| 104 | void setWrapAround(bool wrap); |
| 105 | |
| 106 | public: |
| 107 | virtual QString pathFromIndex(const QModelIndex &index) const; |
| 108 | virtual QStringList splitPath(const QString &path) const; |
| 109 | |
| 110 | protected: |
| 111 | bool eventFilter(QObject *o, QEvent *e) override; |
| 112 | bool event(QEvent *) override; |
| 113 | |
| 114 | Q_SIGNALS: |
| 115 | void activated(const QString &text); |
| 116 | void activated(const QModelIndex &index); |
| 117 | void highlighted(const QString &text); |
| 118 | void highlighted(const QModelIndex &index); |
| 119 | |
| 120 | private: |
| 121 | Q_DISABLE_COPY(QCompleter) |
| 122 | Q_DECLARE_PRIVATE(QCompleter) |
| 123 | |
| 124 | Q_PRIVATE_SLOT(d_func(), void _q_complete(QModelIndex)) |
| 125 | Q_PRIVATE_SLOT(d_func(), void _q_completionSelected(const QItemSelection&)) |
| 126 | Q_PRIVATE_SLOT(d_func(), void _q_autoResizePopup()) |
| 127 | Q_PRIVATE_SLOT(d_func(), void _q_fileSystemModelDirectoryLoaded(const QString&)) |
| 128 | }; |
| 129 | |
| 130 | QT_END_NAMESPACE |
| 131 | |
| 132 | #endif // QCOMPLETER_H |
| 133 | |