qcompleter.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. #ifndef QCOMPLETER_H
  40. #define QCOMPLETER_H
  41. #include <QtCore/qobject.h>
  42. #include <QtCore/qpoint.h>
  43. #include <QtCore/qstring.h>
  44. #include <QtCore/qabstractitemmodel.h>
  45. #include <QtCore/qrect.h>
  46. QT_BEGIN_NAMESPACE
  47. #ifndef QT_NO_COMPLETER
  48. class QCompleterPrivate;
  49. class QAbstractItemView;
  50. class QAbstractProxyModel;
  51. class QWidget;
  52. class Q_WIDGETS_EXPORT QCompleter : public QObject
  53. {
  54. Q_OBJECT
  55. Q_PROPERTY(QString completionPrefix READ completionPrefix WRITE setCompletionPrefix)
  56. Q_PROPERTY(ModelSorting modelSorting READ modelSorting WRITE setModelSorting)
  57. Q_PROPERTY(Qt::MatchFlags filterMode READ filterMode WRITE setFilterMode)
  58. Q_PROPERTY(CompletionMode completionMode READ completionMode WRITE setCompletionMode)
  59. Q_PROPERTY(int completionColumn READ completionColumn WRITE setCompletionColumn)
  60. Q_PROPERTY(int completionRole READ completionRole WRITE setCompletionRole)
  61. Q_PROPERTY(int maxVisibleItems READ maxVisibleItems WRITE setMaxVisibleItems)
  62. Q_PROPERTY(Qt::CaseSensitivity caseSensitivity READ caseSensitivity WRITE setCaseSensitivity)
  63. Q_PROPERTY(bool wrapAround READ wrapAround WRITE setWrapAround)
  64. public:
  65. enum CompletionMode {
  66. PopupCompletion,
  67. UnfilteredPopupCompletion,
  68. InlineCompletion
  69. };
  70. enum ModelSorting {
  71. UnsortedModel = 0,
  72. CaseSensitivelySortedModel,
  73. CaseInsensitivelySortedModel
  74. };
  75. QCompleter(QObject *parent = Q_NULLPTR);
  76. QCompleter(QAbstractItemModel *model, QObject *parent = Q_NULLPTR);
  77. #ifndef QT_NO_STRINGLISTMODEL
  78. QCompleter(const QStringList& completions, QObject *parent = Q_NULLPTR);
  79. #endif
  80. ~QCompleter();
  81. void setWidget(QWidget *widget);
  82. QWidget *widget() const;
  83. void setModel(QAbstractItemModel *c);
  84. QAbstractItemModel *model() const;
  85. void setCompletionMode(CompletionMode mode);
  86. CompletionMode completionMode() const;
  87. void setFilterMode(Qt::MatchFlags filterMode);
  88. Qt::MatchFlags filterMode() const;
  89. QAbstractItemView *popup() const;
  90. void setPopup(QAbstractItemView *popup);
  91. void setCaseSensitivity(Qt::CaseSensitivity caseSensitivity);
  92. Qt::CaseSensitivity caseSensitivity() const;
  93. void setModelSorting(ModelSorting sorting);
  94. ModelSorting modelSorting() const;
  95. void setCompletionColumn(int column);
  96. int completionColumn() const;
  97. void setCompletionRole(int role);
  98. int completionRole() const;
  99. bool wrapAround() const;
  100. int maxVisibleItems() const;
  101. void setMaxVisibleItems(int maxItems);
  102. int completionCount() const;
  103. bool setCurrentRow(int row);
  104. int currentRow() const;
  105. QModelIndex currentIndex() const;
  106. QString currentCompletion() const;
  107. QAbstractItemModel *completionModel() const;
  108. QString completionPrefix() const;
  109. public Q_SLOTS:
  110. void setCompletionPrefix(const QString &prefix);
  111. void complete(const QRect& rect = QRect());
  112. void setWrapAround(bool wrap);
  113. public:
  114. virtual QString pathFromIndex(const QModelIndex &index) const;
  115. virtual QStringList splitPath(const QString &path) const;
  116. protected:
  117. bool eventFilter(QObject *o, QEvent *e) Q_DECL_OVERRIDE;
  118. bool event(QEvent *) Q_DECL_OVERRIDE;
  119. Q_SIGNALS:
  120. void activated(const QString &text);
  121. void activated(const QModelIndex &index);
  122. void highlighted(const QString &text);
  123. void highlighted(const QModelIndex &index);
  124. private:
  125. Q_DISABLE_COPY(QCompleter)
  126. Q_DECLARE_PRIVATE(QCompleter)
  127. Q_PRIVATE_SLOT(d_func(), void _q_complete(QModelIndex))
  128. Q_PRIVATE_SLOT(d_func(), void _q_completionSelected(const QItemSelection&))
  129. Q_PRIVATE_SLOT(d_func(), void _q_autoResizePopup())
  130. Q_PRIVATE_SLOT(d_func(), void _q_fileSystemModelDirectoryLoaded(const QString&))
  131. };
  132. #endif // QT_NO_COMPLETER
  133. QT_END_NAMESPACE
  134. #endif // QCOMPLETER_H