| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/util/qcompleter.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 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 | - | |||||||||||||||||||||||||
| 40 | /*! | - | ||||||||||||||||||||||||
| 41 | \class QCompleter | - | ||||||||||||||||||||||||
| 42 | \brief The QCompleter class provides completions based on an item model. | - | ||||||||||||||||||||||||
| 43 | \since 4.2 | - | ||||||||||||||||||||||||
| 44 | - | |||||||||||||||||||||||||
| 45 | \inmodule QtWidgets | - | ||||||||||||||||||||||||
| 46 | - | |||||||||||||||||||||||||
| 47 | You can use QCompleter to provide auto completions in any Qt | - | ||||||||||||||||||||||||
| 48 | widget, such as QLineEdit and QComboBox. | - | ||||||||||||||||||||||||
| 49 | When the user starts typing a word, QCompleter suggests possible ways of | - | ||||||||||||||||||||||||
| 50 | completing the word, based on a word list. The word list is | - | ||||||||||||||||||||||||
| 51 | provided as a QAbstractItemModel. (For simple applications, where | - | ||||||||||||||||||||||||
| 52 | the word list is static, you can pass a QStringList to | - | ||||||||||||||||||||||||
| 53 | QCompleter's constructor.) | - | ||||||||||||||||||||||||
| 54 | - | |||||||||||||||||||||||||
| 55 | \tableofcontents | - | ||||||||||||||||||||||||
| 56 | - | |||||||||||||||||||||||||
| 57 | \section1 Basic Usage | - | ||||||||||||||||||||||||
| 58 | - | |||||||||||||||||||||||||
| 59 | A QCompleter is used typically with a QLineEdit or QComboBox. | - | ||||||||||||||||||||||||
| 60 | For example, here's how to provide auto completions from a simple | - | ||||||||||||||||||||||||
| 61 | word list in a QLineEdit: | - | ||||||||||||||||||||||||
| 62 | - | |||||||||||||||||||||||||
| 63 | \snippet code/src_gui_util_qcompleter.cpp 0 | - | ||||||||||||||||||||||||
| 64 | - | |||||||||||||||||||||||||
| 65 | A QFileSystemModel can be used to provide auto completion of file names. | - | ||||||||||||||||||||||||
| 66 | For example: | - | ||||||||||||||||||||||||
| 67 | - | |||||||||||||||||||||||||
| 68 | \snippet code/src_gui_util_qcompleter.cpp 1 | - | ||||||||||||||||||||||||
| 69 | - | |||||||||||||||||||||||||
| 70 | To set the model on which QCompleter should operate, call | - | ||||||||||||||||||||||||
| 71 | setModel(). By default, QCompleter will attempt to match the \l | - | ||||||||||||||||||||||||
| 72 | {completionPrefix}{completion prefix} (i.e., the word that the | - | ||||||||||||||||||||||||
| 73 | user has started typing) against the Qt::EditRole data stored in | - | ||||||||||||||||||||||||
| 74 | column 0 in the model case sensitively. This can be changed | - | ||||||||||||||||||||||||
| 75 | using setCompletionRole(), setCompletionColumn(), and | - | ||||||||||||||||||||||||
| 76 | setCaseSensitivity(). | - | ||||||||||||||||||||||||
| 77 | - | |||||||||||||||||||||||||
| 78 | If the model is sorted on the column and role that are used for completion, | - | ||||||||||||||||||||||||
| 79 | you can call setModelSorting() with either | - | ||||||||||||||||||||||||
| 80 | QCompleter::CaseSensitivelySortedModel or | - | ||||||||||||||||||||||||
| 81 | QCompleter::CaseInsensitivelySortedModel as the argument. On large models, | - | ||||||||||||||||||||||||
| 82 | this can lead to significant performance improvements, because QCompleter | - | ||||||||||||||||||||||||
| 83 | can then use binary search instead of linear search. The binary search only | - | ||||||||||||||||||||||||
| 84 | works when the filterMode is Qt::MatchStartsWith. | - | ||||||||||||||||||||||||
| 85 | - | |||||||||||||||||||||||||
| 86 | The model can be a \l{QAbstractListModel}{list model}, | - | ||||||||||||||||||||||||
| 87 | a \l{QAbstractTableModel}{table model}, or a | - | ||||||||||||||||||||||||
| 88 | \l{QAbstractItemModel}{tree model}. Completion on tree models | - | ||||||||||||||||||||||||
| 89 | is slightly more involved and is covered in the \l{Handling | - | ||||||||||||||||||||||||
| 90 | Tree Models} section below. | - | ||||||||||||||||||||||||
| 91 | - | |||||||||||||||||||||||||
| 92 | The completionMode() determines the mode used to provide completions to | - | ||||||||||||||||||||||||
| 93 | the user. | - | ||||||||||||||||||||||||
| 94 | - | |||||||||||||||||||||||||
| 95 | \section1 Iterating Through Completions | - | ||||||||||||||||||||||||
| 96 | - | |||||||||||||||||||||||||
| 97 | To retrieve a single candidate string, call setCompletionPrefix() | - | ||||||||||||||||||||||||
| 98 | with the text that needs to be completed and call | - | ||||||||||||||||||||||||
| 99 | currentCompletion(). You can iterate through the list of | - | ||||||||||||||||||||||||
| 100 | completions as below: | - | ||||||||||||||||||||||||
| 101 | - | |||||||||||||||||||||||||
| 102 | \snippet code/src_gui_util_qcompleter.cpp 2 | - | ||||||||||||||||||||||||
| 103 | - | |||||||||||||||||||||||||
| 104 | completionCount() returns the total number of completions for the | - | ||||||||||||||||||||||||
| 105 | current prefix. completionCount() should be avoided when possible, | - | ||||||||||||||||||||||||
| 106 | since it requires a scan of the entire model. | - | ||||||||||||||||||||||||
| 107 | - | |||||||||||||||||||||||||
| 108 | \section1 The Completion Model | - | ||||||||||||||||||||||||
| 109 | - | |||||||||||||||||||||||||
| 110 | completionModel() return a list model that contains all possible | - | ||||||||||||||||||||||||
| 111 | completions for the current completion prefix, in the order in which | - | ||||||||||||||||||||||||
| 112 | they appear in the model. This model can be used to display the current | - | ||||||||||||||||||||||||
| 113 | completions in a custom view. Calling setCompletionPrefix() automatically | - | ||||||||||||||||||||||||
| 114 | refreshes the completion model. | - | ||||||||||||||||||||||||
| 115 | - | |||||||||||||||||||||||||
| 116 | \section1 Handling Tree Models | - | ||||||||||||||||||||||||
| 117 | - | |||||||||||||||||||||||||
| 118 | QCompleter can look for completions in tree models, assuming | - | ||||||||||||||||||||||||
| 119 | that any item (or sub-item or sub-sub-item) can be unambiguously | - | ||||||||||||||||||||||||
| 120 | represented as a string by specifying the path to the item. The | - | ||||||||||||||||||||||||
| 121 | completion is then performed one level at a time. | - | ||||||||||||||||||||||||
| 122 | - | |||||||||||||||||||||||||
| 123 | Let's take the example of a user typing in a file system path. | - | ||||||||||||||||||||||||
| 124 | The model is a (hierarchical) QFileSystemModel. The completion | - | ||||||||||||||||||||||||
| 125 | occurs for every element in the path. For example, if the current | - | ||||||||||||||||||||||||
| 126 | text is \c C:\Wind, QCompleter might suggest \c Windows to | - | ||||||||||||||||||||||||
| 127 | complete the current path element. Similarly, if the current text | - | ||||||||||||||||||||||||
| 128 | is \c C:\Windows\Sy, QCompleter might suggest \c System. | - | ||||||||||||||||||||||||
| 129 | - | |||||||||||||||||||||||||
| 130 | For this kind of completion to work, QCompleter needs to be able to | - | ||||||||||||||||||||||||
| 131 | split the path into a list of strings that are matched at each level. | - | ||||||||||||||||||||||||
| 132 | For \c C:\Windows\Sy, it needs to be split as "C:", "Windows" and "Sy". | - | ||||||||||||||||||||||||
| 133 | The default implementation of splitPath(), splits the completionPrefix | - | ||||||||||||||||||||||||
| 134 | using QDir::separator() if the model is a QFileSystemModel. | - | ||||||||||||||||||||||||
| 135 | - | |||||||||||||||||||||||||
| 136 | To provide completions, QCompleter needs to know the path from an index. | - | ||||||||||||||||||||||||
| 137 | This is provided by pathFromIndex(). The default implementation of | - | ||||||||||||||||||||||||
| 138 | pathFromIndex(), returns the data for the \l{Qt::EditRole}{edit role} | - | ||||||||||||||||||||||||
| 139 | for list models and the absolute file path if the mode is a QFileSystemModel. | - | ||||||||||||||||||||||||
| 140 | - | |||||||||||||||||||||||||
| 141 | \sa QAbstractItemModel, QLineEdit, QComboBox, {Completer Example} | - | ||||||||||||||||||||||||
| 142 | */ | - | ||||||||||||||||||||||||
| 143 | - | |||||||||||||||||||||||||
| 144 | #include "qcompleter_p.h" | - | ||||||||||||||||||||||||
| 145 | - | |||||||||||||||||||||||||
| 146 | #ifndef QT_NO_COMPLETER | - | ||||||||||||||||||||||||
| 147 | - | |||||||||||||||||||||||||
| 148 | #include "QtWidgets/qscrollbar.h" | - | ||||||||||||||||||||||||
| 149 | #include "QtCore/qstringlistmodel.h" | - | ||||||||||||||||||||||||
| 150 | #include "QtWidgets/qdirmodel.h" | - | ||||||||||||||||||||||||
| 151 | #include "QtWidgets/qfilesystemmodel.h" | - | ||||||||||||||||||||||||
| 152 | #include "QtWidgets/qheaderview.h" | - | ||||||||||||||||||||||||
| 153 | #include "QtWidgets/qlistview.h" | - | ||||||||||||||||||||||||
| 154 | #include "QtWidgets/qapplication.h" | - | ||||||||||||||||||||||||
| 155 | #include "QtGui/qevent.h" | - | ||||||||||||||||||||||||
| 156 | #include "QtWidgets/qdesktopwidget.h" | - | ||||||||||||||||||||||||
| 157 | #include "QtWidgets/qlineedit.h" | - | ||||||||||||||||||||||||
| 158 | - | |||||||||||||||||||||||||
| 159 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
| 160 | - | |||||||||||||||||||||||||
| 161 | QCompletionModel::QCompletionModel(QCompleterPrivate *c, QObject *parent) | - | ||||||||||||||||||||||||
| 162 | : QAbstractProxyModel(*new QCompletionModelPrivate, parent), | - | ||||||||||||||||||||||||
| 163 | c(c), showAll(false) | - | ||||||||||||||||||||||||
| 164 | { | - | ||||||||||||||||||||||||
| 165 | createEngine(); | - | ||||||||||||||||||||||||
| 166 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 167 | - | |||||||||||||||||||||||||
| 168 | int QCompletionModel::columnCount(const QModelIndex &) const | - | ||||||||||||||||||||||||
| 169 | { | - | ||||||||||||||||||||||||
| 170 | Q_D(const QCompletionModel); | - | ||||||||||||||||||||||||
| 171 | return d->model->columnCount(); never executed: return d->model->columnCount(); | 0 | ||||||||||||||||||||||||
| 172 | } | - | ||||||||||||||||||||||||
| 173 | - | |||||||||||||||||||||||||
| 174 | void QCompletionModel::setSourceModel(QAbstractItemModel *source) | - | ||||||||||||||||||||||||
| 175 | { | - | ||||||||||||||||||||||||
| 176 | bool hadModel = (sourceModel() != 0); | - | ||||||||||||||||||||||||
| 177 | - | |||||||||||||||||||||||||
| 178 | if (hadModel)
| 0 | ||||||||||||||||||||||||
| 179 | QObject::disconnect(sourceModel(), 0, this, 0); never executed: QObject::disconnect(sourceModel(), 0, this, 0); | 0 | ||||||||||||||||||||||||
| 180 | - | |||||||||||||||||||||||||
| 181 | QAbstractProxyModel::setSourceModel(source); | - | ||||||||||||||||||||||||
| 182 | - | |||||||||||||||||||||||||
| 183 | if (source) {
| 0 | ||||||||||||||||||||||||
| 184 | // TODO: Optimize updates in the source model | - | ||||||||||||||||||||||||
| 185 | connect(source, SIGNAL(modelReset()), this, SLOT(invalidate())); | - | ||||||||||||||||||||||||
| 186 | connect(source, SIGNAL(destroyed()), this, SLOT(modelDestroyed())); | - | ||||||||||||||||||||||||
| 187 | connect(source, SIGNAL(layoutChanged()), this, SLOT(invalidate())); | - | ||||||||||||||||||||||||
| 188 | connect(source, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(rowsInserted())); | - | ||||||||||||||||||||||||
| 189 | connect(source, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(invalidate())); | - | ||||||||||||||||||||||||
| 190 | connect(source, SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(invalidate())); | - | ||||||||||||||||||||||||
| 191 | connect(source, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(invalidate())); | - | ||||||||||||||||||||||||
| 192 | connect(source, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(invalidate())); | - | ||||||||||||||||||||||||
| 193 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 194 | - | |||||||||||||||||||||||||
| 195 | invalidate(); | - | ||||||||||||||||||||||||
| 196 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 197 | - | |||||||||||||||||||||||||
| 198 | void QCompletionModel::createEngine() | - | ||||||||||||||||||||||||
| 199 | { | - | ||||||||||||||||||||||||
| 200 | bool sortedEngine = false; | - | ||||||||||||||||||||||||
| 201 | if (c->filterMode == Qt::MatchStartsWith) {
| 0 | ||||||||||||||||||||||||
| 202 | switch (c->sorting) { | - | ||||||||||||||||||||||||
| 203 | case QCompleter::UnsortedModel: never executed: case QCompleter::UnsortedModel: | 0 | ||||||||||||||||||||||||
| 204 | sortedEngine = false; | - | ||||||||||||||||||||||||
| 205 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 206 | case QCompleter::CaseSensitivelySortedModel: never executed: case QCompleter::CaseSensitivelySortedModel: | 0 | ||||||||||||||||||||||||
| 207 | sortedEngine = c->cs == Qt::CaseSensitive; | - | ||||||||||||||||||||||||
| 208 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 209 | case QCompleter::CaseInsensitivelySortedModel: never executed: case QCompleter::CaseInsensitivelySortedModel: | 0 | ||||||||||||||||||||||||
| 210 | sortedEngine = c->cs == Qt::CaseInsensitive; | - | ||||||||||||||||||||||||
| 211 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 212 | } | - | ||||||||||||||||||||||||
| 213 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 214 | - | |||||||||||||||||||||||||
| 215 | if (sortedEngine)
| 0 | ||||||||||||||||||||||||
| 216 | engine.reset(new QSortedModelEngine(c)); never executed: engine.reset(new QSortedModelEngine(c)); | 0 | ||||||||||||||||||||||||
| 217 | else | - | ||||||||||||||||||||||||
| 218 | engine.reset(new QUnsortedModelEngine(c)); never executed: engine.reset(new QUnsortedModelEngine(c)); | 0 | ||||||||||||||||||||||||
| 219 | } | - | ||||||||||||||||||||||||
| 220 | - | |||||||||||||||||||||||||
| 221 | QModelIndex QCompletionModel::mapToSource(const QModelIndex& index) const | - | ||||||||||||||||||||||||
| 222 | { | - | ||||||||||||||||||||||||
| 223 | Q_D(const QCompletionModel); | - | ||||||||||||||||||||||||
| 224 | if (!index.isValid())
| 0 | ||||||||||||||||||||||||
| 225 | return engine->curParent; never executed: return engine->curParent; | 0 | ||||||||||||||||||||||||
| 226 | - | |||||||||||||||||||||||||
| 227 | int row; | - | ||||||||||||||||||||||||
| 228 | QModelIndex parent = engine->curParent; | - | ||||||||||||||||||||||||
| 229 | if (!showAll) {
| 0 | ||||||||||||||||||||||||
| 230 | if (!engine->matchCount())
| 0 | ||||||||||||||||||||||||
| 231 | return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||||||||||||||
| 232 | Q_ASSERT(index.row() < engine->matchCount()); | - | ||||||||||||||||||||||||
| 233 | QIndexMapper& rootIndices = engine->historyMatch.indices; | - | ||||||||||||||||||||||||
| 234 | if (index.row() < rootIndices.count()) {
| 0 | ||||||||||||||||||||||||
| 235 | row = rootIndices[index.row()]; | - | ||||||||||||||||||||||||
| 236 | parent = QModelIndex(); | - | ||||||||||||||||||||||||
| 237 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 238 | row = engine->curMatch.indices[index.row() - rootIndices.count()]; | - | ||||||||||||||||||||||||
| 239 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 240 | } else { | - | ||||||||||||||||||||||||
| 241 | row = index.row(); | - | ||||||||||||||||||||||||
| 242 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 243 | - | |||||||||||||||||||||||||
| 244 | return d->model->index(row, index.column(), parent); never executed: return d->model->index(row, index.column(), parent); | 0 | ||||||||||||||||||||||||
| 245 | } | - | ||||||||||||||||||||||||
| 246 | - | |||||||||||||||||||||||||
| 247 | QModelIndex QCompletionModel::mapFromSource(const QModelIndex& idx) const | - | ||||||||||||||||||||||||
| 248 | { | - | ||||||||||||||||||||||||
| 249 | if (!idx.isValid())
| 0 | ||||||||||||||||||||||||
| 250 | return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||||||||||||||
| 251 | - | |||||||||||||||||||||||||
| 252 | int row = -1; | - | ||||||||||||||||||||||||
| 253 | if (!showAll) {
| 0 | ||||||||||||||||||||||||
| 254 | if (!engine->matchCount())
| 0 | ||||||||||||||||||||||||
| 255 | return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||||||||||||||
| 256 | - | |||||||||||||||||||||||||
| 257 | QIndexMapper& rootIndices = engine->historyMatch.indices; | - | ||||||||||||||||||||||||
| 258 | if (idx.parent().isValid()) {
| 0 | ||||||||||||||||||||||||
| 259 | if (idx.parent() != engine->curParent)
| 0 | ||||||||||||||||||||||||
| 260 | return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||||||||||||||
| 261 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 262 | row = rootIndices.indexOf(idx.row()); | - | ||||||||||||||||||||||||
| 263 | if (row == -1 && engine->curParent.isValid())
| 0 | ||||||||||||||||||||||||
| 264 | return QModelIndex(); // source parent and our parent don't match never executed: return QModelIndex(); | 0 | ||||||||||||||||||||||||
| 265 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 266 | - | |||||||||||||||||||||||||
| 267 | if (row == -1) {
| 0 | ||||||||||||||||||||||||
| 268 | QIndexMapper& indices = engine->curMatch.indices; | - | ||||||||||||||||||||||||
| 269 | engine->filterOnDemand(idx.row() - indices.last()); | - | ||||||||||||||||||||||||
| 270 | row = indices.indexOf(idx.row()) + rootIndices.count(); | - | ||||||||||||||||||||||||
| 271 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 272 | - | |||||||||||||||||||||||||
| 273 | if (row == -1)
| 0 | ||||||||||||||||||||||||
| 274 | return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||||||||||||||
| 275 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 276 | if (idx.parent() != engine->curParent)
| 0 | ||||||||||||||||||||||||
| 277 | return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||||||||||||||
| 278 | row = idx.row(); | - | ||||||||||||||||||||||||
| 279 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 280 | - | |||||||||||||||||||||||||
| 281 | return createIndex(row, idx.column()); never executed: return createIndex(row, idx.column()); | 0 | ||||||||||||||||||||||||
| 282 | } | - | ||||||||||||||||||||||||
| 283 | - | |||||||||||||||||||||||||
| 284 | bool QCompletionModel::setCurrentRow(int row) | - | ||||||||||||||||||||||||
| 285 | { | - | ||||||||||||||||||||||||
| 286 | if (row < 0 || !engine->matchCount())
| 0 | ||||||||||||||||||||||||
| 287 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 288 | - | |||||||||||||||||||||||||
| 289 | if (row >= engine->matchCount())
| 0 | ||||||||||||||||||||||||
| 290 | engine->filterOnDemand(row + 1 - engine->matchCount()); never executed: engine->filterOnDemand(row + 1 - engine->matchCount()); | 0 | ||||||||||||||||||||||||
| 291 | - | |||||||||||||||||||||||||
| 292 | if (row >= engine->matchCount()) // invalid row
| 0 | ||||||||||||||||||||||||
| 293 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 294 | - | |||||||||||||||||||||||||
| 295 | engine->curRow = row; | - | ||||||||||||||||||||||||
| 296 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 297 | } | - | ||||||||||||||||||||||||
| 298 | - | |||||||||||||||||||||||||
| 299 | QModelIndex QCompletionModel::currentIndex(bool sourceIndex) const | - | ||||||||||||||||||||||||
| 300 | { | - | ||||||||||||||||||||||||
| 301 | if (!engine->matchCount())
| 0 | ||||||||||||||||||||||||
| 302 | return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||||||||||||||
| 303 | - | |||||||||||||||||||||||||
| 304 | int row = engine->curRow; | - | ||||||||||||||||||||||||
| 305 | if (showAll)
| 0 | ||||||||||||||||||||||||
| 306 | row = engine->curMatch.indices[engine->curRow]; never executed: row = engine->curMatch.indices[engine->curRow]; | 0 | ||||||||||||||||||||||||
| 307 | - | |||||||||||||||||||||||||
| 308 | QModelIndex idx = createIndex(row, c->column); | - | ||||||||||||||||||||||||
| 309 | if (!sourceIndex)
| 0 | ||||||||||||||||||||||||
| 310 | return idx; never executed: return idx; | 0 | ||||||||||||||||||||||||
| 311 | return mapToSource(idx); never executed: return mapToSource(idx); | 0 | ||||||||||||||||||||||||
| 312 | } | - | ||||||||||||||||||||||||
| 313 | - | |||||||||||||||||||||||||
| 314 | QModelIndex QCompletionModel::index(int row, int column, const QModelIndex& parent) const | - | ||||||||||||||||||||||||
| 315 | { | - | ||||||||||||||||||||||||
| 316 | Q_D(const QCompletionModel); | - | ||||||||||||||||||||||||
| 317 | if (row < 0 || column < 0 || column >= columnCount(parent) || parent.isValid())
| 0 | ||||||||||||||||||||||||
| 318 | return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||||||||||||||
| 319 | - | |||||||||||||||||||||||||
| 320 | if (!showAll) {
| 0 | ||||||||||||||||||||||||
| 321 | if (!engine->matchCount())
| 0 | ||||||||||||||||||||||||
| 322 | return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||||||||||||||
| 323 | if (row >= engine->historyMatch.indices.count()) {
| 0 | ||||||||||||||||||||||||
| 324 | int want = row + 1 - engine->matchCount(); | - | ||||||||||||||||||||||||
| 325 | if (want > 0)
| 0 | ||||||||||||||||||||||||
| 326 | engine->filterOnDemand(want); never executed: engine->filterOnDemand(want); | 0 | ||||||||||||||||||||||||
| 327 | if (row >= engine->matchCount())
| 0 | ||||||||||||||||||||||||
| 328 | return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||||||||||||||
| 329 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 330 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 331 | if (row >= d->model->rowCount(engine->curParent))
| 0 | ||||||||||||||||||||||||
| 332 | return QModelIndex(); never executed: return QModelIndex(); | 0 | ||||||||||||||||||||||||
| 333 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 334 | - | |||||||||||||||||||||||||
| 335 | return createIndex(row, column); never executed: return createIndex(row, column); | 0 | ||||||||||||||||||||||||
| 336 | } | - | ||||||||||||||||||||||||
| 337 | - | |||||||||||||||||||||||||
| 338 | int QCompletionModel::completionCount() const | - | ||||||||||||||||||||||||
| 339 | { | - | ||||||||||||||||||||||||
| 340 | if (!engine->matchCount())
| 0 | ||||||||||||||||||||||||
| 341 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 342 | - | |||||||||||||||||||||||||
| 343 | engine->filterOnDemand(INT_MAX); | - | ||||||||||||||||||||||||
| 344 | return engine->matchCount(); never executed: return engine->matchCount(); | 0 | ||||||||||||||||||||||||
| 345 | } | - | ||||||||||||||||||||||||
| 346 | - | |||||||||||||||||||||||||
| 347 | int QCompletionModel::rowCount(const QModelIndex &parent) const | - | ||||||||||||||||||||||||
| 348 | { | - | ||||||||||||||||||||||||
| 349 | Q_D(const QCompletionModel); | - | ||||||||||||||||||||||||
| 350 | if (parent.isValid())
| 0 | ||||||||||||||||||||||||
| 351 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 352 | - | |||||||||||||||||||||||||
| 353 | if (showAll) {
| 0 | ||||||||||||||||||||||||
| 354 | // Show all items below current parent, even if we have no valid matches | - | ||||||||||||||||||||||||
| 355 | if (engine->curParts.count() != 1 && !engine->matchCount()
| 0 | ||||||||||||||||||||||||
| 356 | && !engine->curParent.isValid())
| 0 | ||||||||||||||||||||||||
| 357 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 358 | return d->model->rowCount(engine->curParent); never executed: return d->model->rowCount(engine->curParent); | 0 | ||||||||||||||||||||||||
| 359 | } | - | ||||||||||||||||||||||||
| 360 | - | |||||||||||||||||||||||||
| 361 | return completionCount(); never executed: return completionCount(); | 0 | ||||||||||||||||||||||||
| 362 | } | - | ||||||||||||||||||||||||
| 363 | - | |||||||||||||||||||||||||
| 364 | void QCompletionModel::setFiltered(bool filtered) | - | ||||||||||||||||||||||||
| 365 | { | - | ||||||||||||||||||||||||
| 366 | if (showAll == !filtered)
| 0 | ||||||||||||||||||||||||
| 367 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 368 | beginResetModel(); | - | ||||||||||||||||||||||||
| 369 | showAll = !filtered; | - | ||||||||||||||||||||||||
| 370 | endResetModel(); | - | ||||||||||||||||||||||||
| 371 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 372 | - | |||||||||||||||||||||||||
| 373 | bool QCompletionModel::hasChildren(const QModelIndex &parent) const | - | ||||||||||||||||||||||||
| 374 | { | - | ||||||||||||||||||||||||
| 375 | Q_D(const QCompletionModel); | - | ||||||||||||||||||||||||
| 376 | if (parent.isValid())
| 0 | ||||||||||||||||||||||||
| 377 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 378 | - | |||||||||||||||||||||||||
| 379 | if (showAll)
| 0 | ||||||||||||||||||||||||
| 380 | return d->model->hasChildren(mapToSource(parent)); never executed: return d->model->hasChildren(mapToSource(parent)); | 0 | ||||||||||||||||||||||||
| 381 | - | |||||||||||||||||||||||||
| 382 | if (!engine->matchCount())
| 0 | ||||||||||||||||||||||||
| 383 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 384 | - | |||||||||||||||||||||||||
| 385 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 386 | } | - | ||||||||||||||||||||||||
| 387 | - | |||||||||||||||||||||||||
| 388 | QVariant QCompletionModel::data(const QModelIndex& index, int role) const | - | ||||||||||||||||||||||||
| 389 | { | - | ||||||||||||||||||||||||
| 390 | Q_D(const QCompletionModel); | - | ||||||||||||||||||||||||
| 391 | return d->model->data(mapToSource(index), role); never executed: return d->model->data(mapToSource(index), role); | 0 | ||||||||||||||||||||||||
| 392 | } | - | ||||||||||||||||||||||||
| 393 | - | |||||||||||||||||||||||||
| 394 | void QCompletionModel::modelDestroyed() | - | ||||||||||||||||||||||||
| 395 | { | - | ||||||||||||||||||||||||
| 396 | QAbstractProxyModel::setSourceModel(0); // switch to static empty model | - | ||||||||||||||||||||||||
| 397 | invalidate(); | - | ||||||||||||||||||||||||
| 398 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 399 | - | |||||||||||||||||||||||||
| 400 | void QCompletionModel::rowsInserted() | - | ||||||||||||||||||||||||
| 401 | { | - | ||||||||||||||||||||||||
| 402 | invalidate(); | - | ||||||||||||||||||||||||
| 403 | emit rowsAdded(); | - | ||||||||||||||||||||||||
| 404 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 405 | - | |||||||||||||||||||||||||
| 406 | void QCompletionModel::invalidate() | - | ||||||||||||||||||||||||
| 407 | { | - | ||||||||||||||||||||||||
| 408 | engine->cache.clear(); | - | ||||||||||||||||||||||||
| 409 | filter(engine->curParts); | - | ||||||||||||||||||||||||
| 410 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 411 | - | |||||||||||||||||||||||||
| 412 | void QCompletionModel::filter(const QStringList& parts) | - | ||||||||||||||||||||||||
| 413 | { | - | ||||||||||||||||||||||||
| 414 | Q_D(QCompletionModel); | - | ||||||||||||||||||||||||
| 415 | beginResetModel(); | - | ||||||||||||||||||||||||
| 416 | engine->filter(parts); | - | ||||||||||||||||||||||||
| 417 | endResetModel(); | - | ||||||||||||||||||||||||
| 418 | - | |||||||||||||||||||||||||
| 419 | if (d->model->canFetchMore(engine->curParent))
| 0 | ||||||||||||||||||||||||
| 420 | d->model->fetchMore(engine->curParent); never executed: d->model->fetchMore(engine->curParent); | 0 | ||||||||||||||||||||||||
| 421 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 422 | - | |||||||||||||||||||||||||
| 423 | ////////////////////////////////////////////////////////////////////////////// | - | ||||||||||||||||||||||||
| 424 | void QCompletionEngine::filter(const QStringList& parts) | - | ||||||||||||||||||||||||
| 425 | { | - | ||||||||||||||||||||||||
| 426 | const QAbstractItemModel *model = c->proxy->sourceModel(); | - | ||||||||||||||||||||||||
| 427 | curParts = parts; | - | ||||||||||||||||||||||||
| 428 | if (curParts.isEmpty())
| 0 | ||||||||||||||||||||||||
| 429 | curParts.append(QString()); never executed: curParts.append(QString()); | 0 | ||||||||||||||||||||||||
| 430 | - | |||||||||||||||||||||||||
| 431 | curRow = -1; | - | ||||||||||||||||||||||||
| 432 | curParent = QModelIndex(); | - | ||||||||||||||||||||||||
| 433 | curMatch = QMatchData(); | - | ||||||||||||||||||||||||
| 434 | historyMatch = filterHistory(); | - | ||||||||||||||||||||||||
| 435 | - | |||||||||||||||||||||||||
| 436 | if (!model)
| 0 | ||||||||||||||||||||||||
| 437 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 438 | - | |||||||||||||||||||||||||
| 439 | QModelIndex parent; | - | ||||||||||||||||||||||||
| 440 | for (int i = 0; i < curParts.count() - 1; i++) {
| 0 | ||||||||||||||||||||||||
| 441 | QString part = curParts.at(i); | - | ||||||||||||||||||||||||
| 442 | int emi = filter(part, parent, -1).exactMatchIndex; | - | ||||||||||||||||||||||||
| 443 | if (emi == -1)
| 0 | ||||||||||||||||||||||||
| 444 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 445 | parent = model->index(emi, c->column, parent); | - | ||||||||||||||||||||||||
| 446 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 447 | - | |||||||||||||||||||||||||
| 448 | // Note that we set the curParent to a valid parent, even if we have no matches | - | ||||||||||||||||||||||||
| 449 | // When filtering is disabled, we show all the items under this parent | - | ||||||||||||||||||||||||
| 450 | curParent = parent; | - | ||||||||||||||||||||||||
| 451 | if (curParts.constLast().isEmpty())
| 0 | ||||||||||||||||||||||||
| 452 | curMatch = QMatchData(QIndexMapper(0, model->rowCount(curParent) - 1), -1, false); never executed: curMatch = QMatchData(QIndexMapper(0, model->rowCount(curParent) - 1), -1, false); | 0 | ||||||||||||||||||||||||
| 453 | else | - | ||||||||||||||||||||||||
| 454 | curMatch = filter(curParts.constLast(), curParent, 1); // build at least one never executed: curMatch = filter(curParts.constLast(), curParent, 1); | 0 | ||||||||||||||||||||||||
| 455 | curRow = curMatch.isValid() ? 0 : -1;
| 0 | ||||||||||||||||||||||||
| 456 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 457 | - | |||||||||||||||||||||||||
| 458 | QMatchData QCompletionEngine::filterHistory() | - | ||||||||||||||||||||||||
| 459 | { | - | ||||||||||||||||||||||||
| 460 | QAbstractItemModel *source = c->proxy->sourceModel(); | - | ||||||||||||||||||||||||
| 461 | if (curParts.count() <= 1 || c->proxy->showAll || !source)
| 0 | ||||||||||||||||||||||||
| 462 | return QMatchData(); never executed: return QMatchData(); | 0 | ||||||||||||||||||||||||
| 463 | - | |||||||||||||||||||||||||
| 464 | #ifndef QT_NO_DIRMODEL | - | ||||||||||||||||||||||||
| 465 | const bool isDirModel = (qobject_cast<QDirModel *>(source) != 0); | - | ||||||||||||||||||||||||
| 466 | #else | - | ||||||||||||||||||||||||
| 467 | const bool isDirModel = false; | - | ||||||||||||||||||||||||
| 468 | #endif | - | ||||||||||||||||||||||||
| 469 | Q_UNUSED(isDirModel) | - | ||||||||||||||||||||||||
| 470 | #ifndef QT_NO_FILESYSTEMMODEL | - | ||||||||||||||||||||||||
| 471 | const bool isFsModel = (qobject_cast<QFileSystemModel *>(source) != 0); | - | ||||||||||||||||||||||||
| 472 | #else | - | ||||||||||||||||||||||||
| 473 | const bool isFsModel = false; | - | ||||||||||||||||||||||||
| 474 | #endif | - | ||||||||||||||||||||||||
| 475 | Q_UNUSED(isFsModel) | - | ||||||||||||||||||||||||
| 476 | QVector<int> v; | - | ||||||||||||||||||||||||
| 477 | QIndexMapper im(v); | - | ||||||||||||||||||||||||
| 478 | QMatchData m(im, -1, true); | - | ||||||||||||||||||||||||
| 479 | - | |||||||||||||||||||||||||
| 480 | for (int i = 0; i < source->rowCount(); i++) {
| 0 | ||||||||||||||||||||||||
| 481 | QString str = source->index(i, c->column).data().toString(); | - | ||||||||||||||||||||||||
| 482 | if (str.startsWith(c->prefix, c->cs)
| 0 | ||||||||||||||||||||||||
| 483 | #if !defined(Q_OS_WIN) || defined(Q_OS_WINCE) | - | ||||||||||||||||||||||||
| 484 | && ((!isFsModel && !isDirModel) || QDir::toNativeSeparators(str) != QDir::separator())
| 0 | ||||||||||||||||||||||||
| 485 | #endif | - | ||||||||||||||||||||||||
| 486 | ) | - | ||||||||||||||||||||||||
| 487 | m.indices.append(i); never executed: m.indices.append(i); | 0 | ||||||||||||||||||||||||
| 488 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 489 | return m; never executed: return m; | 0 | ||||||||||||||||||||||||
| 490 | } | - | ||||||||||||||||||||||||
| 491 | - | |||||||||||||||||||||||||
| 492 | // Returns a match hint from the cache by chopping the search string | - | ||||||||||||||||||||||||
| 493 | bool QCompletionEngine::matchHint(QString part, const QModelIndex& parent, QMatchData *hint) | - | ||||||||||||||||||||||||
| 494 | { | - | ||||||||||||||||||||||||
| 495 | if (c->cs == Qt::CaseInsensitive)
| 0 | ||||||||||||||||||||||||
| 496 | part = part.toLower(); never executed: part = part.toLower(); | 0 | ||||||||||||||||||||||||
| 497 | - | |||||||||||||||||||||||||
| 498 | const CacheItem& map = cache[parent]; | - | ||||||||||||||||||||||||
| 499 | - | |||||||||||||||||||||||||
| 500 | QString key = part; | - | ||||||||||||||||||||||||
| 501 | while (!key.isEmpty()) {
| 0 | ||||||||||||||||||||||||
| 502 | key.chop(1); | - | ||||||||||||||||||||||||
| 503 | if (map.contains(key)) {
| 0 | ||||||||||||||||||||||||
| 504 | *hint = map[key]; | - | ||||||||||||||||||||||||
| 505 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 506 | } | - | ||||||||||||||||||||||||
| 507 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 508 | - | |||||||||||||||||||||||||
| 509 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 510 | } | - | ||||||||||||||||||||||||
| 511 | - | |||||||||||||||||||||||||
| 512 | bool QCompletionEngine::lookupCache(QString part, const QModelIndex& parent, QMatchData *m) | - | ||||||||||||||||||||||||
| 513 | { | - | ||||||||||||||||||||||||
| 514 | if (c->cs == Qt::CaseInsensitive)
| 0 | ||||||||||||||||||||||||
| 515 | part = part.toLower(); never executed: part = part.toLower(); | 0 | ||||||||||||||||||||||||
| 516 | const CacheItem& map = cache[parent]; | - | ||||||||||||||||||||||||
| 517 | if (!map.contains(part))
| 0 | ||||||||||||||||||||||||
| 518 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 519 | *m = map[part]; | - | ||||||||||||||||||||||||
| 520 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 521 | } | - | ||||||||||||||||||||||||
| 522 | - | |||||||||||||||||||||||||
| 523 | // When the cache size exceeds 1MB, it clears out about 1/2 of the cache. | - | ||||||||||||||||||||||||
| 524 | void QCompletionEngine::saveInCache(QString part, const QModelIndex& parent, const QMatchData& m) | - | ||||||||||||||||||||||||
| 525 | { | - | ||||||||||||||||||||||||
| 526 | if (c->filterMode == Qt::MatchEndsWith)
| 0 | ||||||||||||||||||||||||
| 527 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 528 | QMatchData old = cache[parent].take(part); | - | ||||||||||||||||||||||||
| 529 | cost = cost + m.indices.cost() - old.indices.cost(); | - | ||||||||||||||||||||||||
| 530 | if (cost * sizeof(int) > 1024 * 1024) {
| 0 | ||||||||||||||||||||||||
| 531 | QMap<QModelIndex, CacheItem>::iterator it1 = cache.begin(); | - | ||||||||||||||||||||||||
| 532 | while (it1 != cache.end()) {
| 0 | ||||||||||||||||||||||||
| 533 | CacheItem& ci = it1.value(); | - | ||||||||||||||||||||||||
| 534 | int sz = ci.count()/2; | - | ||||||||||||||||||||||||
| 535 | QMap<QString, QMatchData>::iterator it2 = ci.begin(); | - | ||||||||||||||||||||||||
| 536 | int i = 0; | - | ||||||||||||||||||||||||
| 537 | while (it2 != ci.end() && i < sz) {
| 0 | ||||||||||||||||||||||||
| 538 | cost -= it2.value().indices.cost(); | - | ||||||||||||||||||||||||
| 539 | it2 = ci.erase(it2); | - | ||||||||||||||||||||||||
| 540 | i++; | - | ||||||||||||||||||||||||
| 541 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 542 | if (ci.count() == 0) {
| 0 | ||||||||||||||||||||||||
| 543 | it1 = cache.erase(it1); | - | ||||||||||||||||||||||||
| 544 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 545 | ++it1; | - | ||||||||||||||||||||||||
| 546 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 547 | } | - | ||||||||||||||||||||||||
| 548 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 549 | - | |||||||||||||||||||||||||
| 550 | if (c->cs == Qt::CaseInsensitive)
| 0 | ||||||||||||||||||||||||
| 551 | part = part.toLower(); never executed: part = part.toLower(); | 0 | ||||||||||||||||||||||||
| 552 | cache[parent][part] = m; | - | ||||||||||||||||||||||||
| 553 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 554 | - | |||||||||||||||||||||||||
| 555 | /////////////////////////////////////////////////////////////////////////////////// | - | ||||||||||||||||||||||||
| 556 | QIndexMapper QSortedModelEngine::indexHint(QString part, const QModelIndex& parent, Qt::SortOrder order) | - | ||||||||||||||||||||||||
| 557 | { | - | ||||||||||||||||||||||||
| 558 | const QAbstractItemModel *model = c->proxy->sourceModel(); | - | ||||||||||||||||||||||||
| 559 | - | |||||||||||||||||||||||||
| 560 | if (c->cs == Qt::CaseInsensitive)
| 0 | ||||||||||||||||||||||||
| 561 | part = part.toLower(); never executed: part = part.toLower(); | 0 | ||||||||||||||||||||||||
| 562 | - | |||||||||||||||||||||||||
| 563 | const CacheItem& map = cache[parent]; | - | ||||||||||||||||||||||||
| 564 | - | |||||||||||||||||||||||||
| 565 | // Try to find a lower and upper bound for the search from previous results | - | ||||||||||||||||||||||||
| 566 | int to = model->rowCount(parent) - 1; | - | ||||||||||||||||||||||||
| 567 | int from = 0; | - | ||||||||||||||||||||||||
| 568 | const CacheItem::const_iterator it = map.lowerBound(part); | - | ||||||||||||||||||||||||
| 569 | - | |||||||||||||||||||||||||
| 570 | // look backward for first valid hint | - | ||||||||||||||||||||||||
| 571 | for(CacheItem::const_iterator it1 = it; it1-- != map.constBegin();) {
| 0 | ||||||||||||||||||||||||
| 572 | const QMatchData& value = it1.value(); | - | ||||||||||||||||||||||||
| 573 | if (value.isValid()) {
| 0 | ||||||||||||||||||||||||
| 574 | if (order == Qt::AscendingOrder) {
| 0 | ||||||||||||||||||||||||
| 575 | from = value.indices.last() + 1; | - | ||||||||||||||||||||||||
| 576 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 577 | to = value.indices.first() - 1; | - | ||||||||||||||||||||||||
| 578 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 579 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 580 | } | - | ||||||||||||||||||||||||
| 581 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 582 | - | |||||||||||||||||||||||||
| 583 | // look forward for first valid hint | - | ||||||||||||||||||||||||
| 584 | for(CacheItem::const_iterator it2 = it; it2 != map.constEnd(); ++it2) {
| 0 | ||||||||||||||||||||||||
| 585 | const QMatchData& value = it2.value(); | - | ||||||||||||||||||||||||
| 586 | if (value.isValid() && !it2.key().startsWith(part)) {
| 0 | ||||||||||||||||||||||||
| 587 | if (order == Qt::AscendingOrder) {
| 0 | ||||||||||||||||||||||||
| 588 | to = value.indices.first() - 1; | - | ||||||||||||||||||||||||
| 589 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 590 | from = value.indices.first() + 1; | - | ||||||||||||||||||||||||
| 591 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 592 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 593 | } | - | ||||||||||||||||||||||||
| 594 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 595 | - | |||||||||||||||||||||||||
| 596 | return QIndexMapper(from, to); never executed: return QIndexMapper(from, to); | 0 | ||||||||||||||||||||||||
| 597 | } | - | ||||||||||||||||||||||||
| 598 | - | |||||||||||||||||||||||||
| 599 | Qt::SortOrder QSortedModelEngine::sortOrder(const QModelIndex &parent) const | - | ||||||||||||||||||||||||
| 600 | { | - | ||||||||||||||||||||||||
| 601 | const QAbstractItemModel *model = c->proxy->sourceModel(); | - | ||||||||||||||||||||||||
| 602 | - | |||||||||||||||||||||||||
| 603 | int rowCount = model->rowCount(parent); | - | ||||||||||||||||||||||||
| 604 | if (rowCount < 2)
| 0 | ||||||||||||||||||||||||
| 605 | return Qt::AscendingOrder; never executed: return Qt::AscendingOrder; | 0 | ||||||||||||||||||||||||
| 606 | QString first = model->data(model->index(0, c->column, parent), c->role).toString(); | - | ||||||||||||||||||||||||
| 607 | QString last = model->data(model->index(rowCount - 1, c->column, parent), c->role).toString(); | - | ||||||||||||||||||||||||
| 608 | return QString::compare(first, last, c->cs) <= 0 ? Qt::AscendingOrder : Qt::DescendingOrder; never executed: return QString::compare(first, last, c->cs) <= 0 ? Qt::AscendingOrder : Qt::DescendingOrder; | 0 | ||||||||||||||||||||||||
| 609 | } | - | ||||||||||||||||||||||||
| 610 | - | |||||||||||||||||||||||||
| 611 | QMatchData QSortedModelEngine::filter(const QString& part, const QModelIndex& parent, int) | - | ||||||||||||||||||||||||
| 612 | { | - | ||||||||||||||||||||||||
| 613 | const QAbstractItemModel *model = c->proxy->sourceModel(); | - | ||||||||||||||||||||||||
| 614 | - | |||||||||||||||||||||||||
| 615 | QMatchData hint; | - | ||||||||||||||||||||||||
| 616 | if (lookupCache(part, parent, &hint))
| 0 | ||||||||||||||||||||||||
| 617 | return hint; never executed: return hint; | 0 | ||||||||||||||||||||||||
| 618 | - | |||||||||||||||||||||||||
| 619 | QIndexMapper indices; | - | ||||||||||||||||||||||||
| 620 | Qt::SortOrder order = sortOrder(parent); | - | ||||||||||||||||||||||||
| 621 | - | |||||||||||||||||||||||||
| 622 | if (matchHint(part, parent, &hint)) {
| 0 | ||||||||||||||||||||||||
| 623 | if (!hint.isValid())
| 0 | ||||||||||||||||||||||||
| 624 | return QMatchData(); never executed: return QMatchData(); | 0 | ||||||||||||||||||||||||
| 625 | indices = hint.indices; | - | ||||||||||||||||||||||||
| 626 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 627 | indices = indexHint(part, parent, order); | - | ||||||||||||||||||||||||
| 628 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 629 | - | |||||||||||||||||||||||||
| 630 | // binary search the model within 'indices' for 'part' under 'parent' | - | ||||||||||||||||||||||||
| 631 | int high = indices.to() + 1; | - | ||||||||||||||||||||||||
| 632 | int low = indices.from() - 1; | - | ||||||||||||||||||||||||
| 633 | int probe; | - | ||||||||||||||||||||||||
| 634 | QModelIndex probeIndex; | - | ||||||||||||||||||||||||
| 635 | QString probeData; | - | ||||||||||||||||||||||||
| 636 | - | |||||||||||||||||||||||||
| 637 | while (high - low > 1)
| 0 | ||||||||||||||||||||||||
| 638 | { | - | ||||||||||||||||||||||||
| 639 | probe = (high + low) / 2; | - | ||||||||||||||||||||||||
| 640 | probeIndex = model->index(probe, c->column, parent); | - | ||||||||||||||||||||||||
| 641 | probeData = model->data(probeIndex, c->role).toString(); | - | ||||||||||||||||||||||||
| 642 | const int cmp = QString::compare(probeData, part, c->cs); | - | ||||||||||||||||||||||||
| 643 | if ((order == Qt::AscendingOrder && cmp >= 0)
| 0 | ||||||||||||||||||||||||
| 644 | || (order == Qt::DescendingOrder && cmp < 0)) {
| 0 | ||||||||||||||||||||||||
| 645 | high = probe; | - | ||||||||||||||||||||||||
| 646 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 647 | low = probe; | - | ||||||||||||||||||||||||
| 648 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 649 | } | - | ||||||||||||||||||||||||
| 650 | - | |||||||||||||||||||||||||
| 651 | if ((order == Qt::AscendingOrder && low == indices.to())
| 0 | ||||||||||||||||||||||||
| 652 | || (order == Qt::DescendingOrder && high == indices.from())) { // not found
| 0 | ||||||||||||||||||||||||
| 653 | saveInCache(part, parent, QMatchData()); | - | ||||||||||||||||||||||||
| 654 | return QMatchData(); never executed: return QMatchData(); | 0 | ||||||||||||||||||||||||
| 655 | } | - | ||||||||||||||||||||||||
| 656 | - | |||||||||||||||||||||||||
| 657 | probeIndex = model->index(order == Qt::AscendingOrder ? low+1 : high-1, c->column, parent); | - | ||||||||||||||||||||||||
| 658 | probeData = model->data(probeIndex, c->role).toString(); | - | ||||||||||||||||||||||||
| 659 | if (!probeData.startsWith(part, c->cs)) {
| 0 | ||||||||||||||||||||||||
| 660 | saveInCache(part, parent, QMatchData()); | - | ||||||||||||||||||||||||
| 661 | return QMatchData(); never executed: return QMatchData(); | 0 | ||||||||||||||||||||||||
| 662 | } | - | ||||||||||||||||||||||||
| 663 | - | |||||||||||||||||||||||||
| 664 | const bool exactMatch = QString::compare(probeData, part, c->cs) == 0; | - | ||||||||||||||||||||||||
| 665 | int emi = exactMatch ? (order == Qt::AscendingOrder ? low+1 : high-1) : -1;
| 0 | ||||||||||||||||||||||||
| 666 | - | |||||||||||||||||||||||||
| 667 | int from = 0; | - | ||||||||||||||||||||||||
| 668 | int to = 0; | - | ||||||||||||||||||||||||
| 669 | if (order == Qt::AscendingOrder) {
| 0 | ||||||||||||||||||||||||
| 670 | from = low + 1; | - | ||||||||||||||||||||||||
| 671 | high = indices.to() + 1; | - | ||||||||||||||||||||||||
| 672 | low = from; | - | ||||||||||||||||||||||||
| 673 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 674 | to = high - 1; | - | ||||||||||||||||||||||||
| 675 | low = indices.from() - 1; | - | ||||||||||||||||||||||||
| 676 | high = to; | - | ||||||||||||||||||||||||
| 677 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 678 | - | |||||||||||||||||||||||||
| 679 | while (high - low > 1)
| 0 | ||||||||||||||||||||||||
| 680 | { | - | ||||||||||||||||||||||||
| 681 | probe = (high + low) / 2; | - | ||||||||||||||||||||||||
| 682 | probeIndex = model->index(probe, c->column, parent); | - | ||||||||||||||||||||||||
| 683 | probeData = model->data(probeIndex, c->role).toString(); | - | ||||||||||||||||||||||||
| 684 | const bool startsWith = probeData.startsWith(part, c->cs); | - | ||||||||||||||||||||||||
| 685 | if ((order == Qt::AscendingOrder && startsWith)
| 0 | ||||||||||||||||||||||||
| 686 | || (order == Qt::DescendingOrder && !startsWith)) {
| 0 | ||||||||||||||||||||||||
| 687 | low = probe; | - | ||||||||||||||||||||||||
| 688 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 689 | high = probe; | - | ||||||||||||||||||||||||
| 690 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 691 | } | - | ||||||||||||||||||||||||
| 692 | - | |||||||||||||||||||||||||
| 693 | QMatchData m(order == Qt::AscendingOrder ? QIndexMapper(from, high - 1) : QIndexMapper(low+1, to), emi, false); | - | ||||||||||||||||||||||||
| 694 | saveInCache(part, parent, m); | - | ||||||||||||||||||||||||
| 695 | return m; never executed: return m; | 0 | ||||||||||||||||||||||||
| 696 | } | - | ||||||||||||||||||||||||
| 697 | - | |||||||||||||||||||||||||
| 698 | //////////////////////////////////////////////////////////////////////////////////////// | - | ||||||||||||||||||||||||
| 699 | int QUnsortedModelEngine::buildIndices(const QString& str, const QModelIndex& parent, int n, | - | ||||||||||||||||||||||||
| 700 | const QIndexMapper& indices, QMatchData* m) | - | ||||||||||||||||||||||||
| 701 | { | - | ||||||||||||||||||||||||
| 702 | Q_ASSERT(m->partial); | - | ||||||||||||||||||||||||
| 703 | Q_ASSERT(n != -1 || m->exactMatchIndex == -1); | - | ||||||||||||||||||||||||
| 704 | const QAbstractItemModel *model = c->proxy->sourceModel(); | - | ||||||||||||||||||||||||
| 705 | int i, count = 0; | - | ||||||||||||||||||||||||
| 706 | - | |||||||||||||||||||||||||
| 707 | for (i = 0; i < indices.count() && count != n; ++i) {
| 0 | ||||||||||||||||||||||||
| 708 | QModelIndex idx = model->index(indices[i], c->column, parent); | - | ||||||||||||||||||||||||
| 709 | - | |||||||||||||||||||||||||
| 710 | if (!(model->flags(idx) & Qt::ItemIsSelectable))
| 0 | ||||||||||||||||||||||||
| 711 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 712 | - | |||||||||||||||||||||||||
| 713 | QString data = model->data(idx, c->role).toString(); | - | ||||||||||||||||||||||||
| 714 | - | |||||||||||||||||||||||||
| 715 | switch (c->filterMode) { | - | ||||||||||||||||||||||||
| 716 | case Qt::MatchStartsWith: never executed: case Qt::MatchStartsWith: | 0 | ||||||||||||||||||||||||
| 717 | if (!data.startsWith(str, c->cs))
| 0 | ||||||||||||||||||||||||
| 718 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 719 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 720 | case Qt::MatchContains: never executed: case Qt::MatchContains: | 0 | ||||||||||||||||||||||||
| 721 | if (!data.contains(str, c->cs))
| 0 | ||||||||||||||||||||||||
| 722 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 723 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 724 | case Qt::MatchEndsWith: never executed: case Qt::MatchEndsWith: | 0 | ||||||||||||||||||||||||
| 725 | if (!data.endsWith(str, c->cs))
| 0 | ||||||||||||||||||||||||
| 726 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 727 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 728 | case Qt::MatchExactly: never executed: case Qt::MatchExactly: | 0 | ||||||||||||||||||||||||
| 729 | case Qt::MatchFixedString: never executed: case Qt::MatchFixedString: | 0 | ||||||||||||||||||||||||
| 730 | case Qt::MatchCaseSensitive: never executed: case Qt::MatchCaseSensitive: | 0 | ||||||||||||||||||||||||
| 731 | case Qt::MatchRegExp: never executed: case Qt::MatchRegExp: | 0 | ||||||||||||||||||||||||
| 732 | case Qt::MatchWildcard: never executed: case Qt::MatchWildcard: | 0 | ||||||||||||||||||||||||
| 733 | case Qt::MatchWrap: never executed: case Qt::MatchWrap: | 0 | ||||||||||||||||||||||||
| 734 | case Qt::MatchRecursive: never executed: case Qt::MatchRecursive: | 0 | ||||||||||||||||||||||||
| 735 | Q_UNREACHABLE(); | - | ||||||||||||||||||||||||
| 736 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 737 | } | - | ||||||||||||||||||||||||
| 738 | m->indices.append(indices[i]); | - | ||||||||||||||||||||||||
| 739 | ++count; | - | ||||||||||||||||||||||||
| 740 | if (m->exactMatchIndex == -1 && QString::compare(data, str, c->cs) == 0) {
| 0 | ||||||||||||||||||||||||
| 741 | m->exactMatchIndex = indices[i]; | - | ||||||||||||||||||||||||
| 742 | if (n == -1)
| 0 | ||||||||||||||||||||||||
| 743 | return indices[i]; never executed: return indices[i]; | 0 | ||||||||||||||||||||||||
| 744 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 745 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 746 | return indices[i-1]; never executed: return indices[i-1]; | 0 | ||||||||||||||||||||||||
| 747 | } | - | ||||||||||||||||||||||||
| 748 | - | |||||||||||||||||||||||||
| 749 | void QUnsortedModelEngine::filterOnDemand(int n) | - | ||||||||||||||||||||||||
| 750 | { | - | ||||||||||||||||||||||||
| 751 | Q_ASSERT(matchCount()); | - | ||||||||||||||||||||||||
| 752 | if (!curMatch.partial)
| 0 | ||||||||||||||||||||||||
| 753 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 754 | Q_ASSERT(n >= -1); | - | ||||||||||||||||||||||||
| 755 | const QAbstractItemModel *model = c->proxy->sourceModel(); | - | ||||||||||||||||||||||||
| 756 | int lastRow = model->rowCount(curParent) - 1; | - | ||||||||||||||||||||||||
| 757 | QIndexMapper im(curMatch.indices.last() + 1, lastRow); | - | ||||||||||||||||||||||||
| 758 | int lastIndex = buildIndices(curParts.constLast(), curParent, n, im, &curMatch); | - | ||||||||||||||||||||||||
| 759 | curMatch.partial = (lastRow != lastIndex); | - | ||||||||||||||||||||||||
| 760 | saveInCache(curParts.constLast(), curParent, curMatch); | - | ||||||||||||||||||||||||
| 761 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 762 | - | |||||||||||||||||||||||||
| 763 | QMatchData QUnsortedModelEngine::filter(const QString& part, const QModelIndex& parent, int n) | - | ||||||||||||||||||||||||
| 764 | { | - | ||||||||||||||||||||||||
| 765 | QMatchData hint; | - | ||||||||||||||||||||||||
| 766 | - | |||||||||||||||||||||||||
| 767 | QVector<int> v; | - | ||||||||||||||||||||||||
| 768 | QIndexMapper im(v); | - | ||||||||||||||||||||||||
| 769 | QMatchData m(im, -1, true); | - | ||||||||||||||||||||||||
| 770 | - | |||||||||||||||||||||||||
| 771 | const QAbstractItemModel *model = c->proxy->sourceModel(); | - | ||||||||||||||||||||||||
| 772 | bool foundInCache = lookupCache(part, parent, &m); | - | ||||||||||||||||||||||||
| 773 | - | |||||||||||||||||||||||||
| 774 | if (!foundInCache) {
| 0 | ||||||||||||||||||||||||
| 775 | if (matchHint(part, parent, &hint) && !hint.isValid())
| 0 | ||||||||||||||||||||||||
| 776 | return QMatchData(); never executed: return QMatchData(); | 0 | ||||||||||||||||||||||||
| 777 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 778 | - | |||||||||||||||||||||||||
| 779 | if (!foundInCache && !hint.isValid()) {
| 0 | ||||||||||||||||||||||||
| 780 | const int lastRow = model->rowCount(parent) - 1; | - | ||||||||||||||||||||||||
| 781 | QIndexMapper all(0, lastRow); | - | ||||||||||||||||||||||||
| 782 | int lastIndex = buildIndices(part, parent, n, all, &m); | - | ||||||||||||||||||||||||
| 783 | m.partial = (lastIndex != lastRow); | - | ||||||||||||||||||||||||
| 784 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 785 | if (!foundInCache) { // build from hint as much as we can
| 0 | ||||||||||||||||||||||||
| 786 | buildIndices(part, parent, INT_MAX, hint.indices, &m); | - | ||||||||||||||||||||||||
| 787 | m.partial = hint.partial; | - | ||||||||||||||||||||||||
| 788 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 789 | if (m.partial && ((n == -1 && m.exactMatchIndex == -1) || (m.indices.count() < n))) {
| 0 | ||||||||||||||||||||||||
| 790 | // need more and have more | - | ||||||||||||||||||||||||
| 791 | const int lastRow = model->rowCount(parent) - 1; | - | ||||||||||||||||||||||||
| 792 | QIndexMapper rest(hint.indices.last() + 1, lastRow); | - | ||||||||||||||||||||||||
| 793 | int want = n == -1 ? -1 : n - m.indices.count();
| 0 | ||||||||||||||||||||||||
| 794 | int lastIndex = buildIndices(part, parent, want, rest, &m); | - | ||||||||||||||||||||||||
| 795 | m.partial = (lastRow != lastIndex); | - | ||||||||||||||||||||||||
| 796 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 797 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 798 | - | |||||||||||||||||||||||||
| 799 | saveInCache(part, parent, m); | - | ||||||||||||||||||||||||
| 800 | return m; never executed: return m; | 0 | ||||||||||||||||||||||||
| 801 | } | - | ||||||||||||||||||||||||
| 802 | - | |||||||||||||||||||||||||
| 803 | /////////////////////////////////////////////////////////////////////////////// | - | ||||||||||||||||||||||||
| 804 | QCompleterPrivate::QCompleterPrivate() | - | ||||||||||||||||||||||||
| 805 | : widget(0), proxy(0), popup(0), filterMode(Qt::MatchStartsWith), cs(Qt::CaseSensitive), | - | ||||||||||||||||||||||||
| 806 | role(Qt::EditRole), column(0), maxVisibleItems(7), sorting(QCompleter::UnsortedModel), | - | ||||||||||||||||||||||||
| 807 | wrap(true), eatFocusOut(true), hiddenBecauseNoMatch(false) | - | ||||||||||||||||||||||||
| 808 | { | - | ||||||||||||||||||||||||
| 809 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 810 | - | |||||||||||||||||||||||||
| 811 | void QCompleterPrivate::init(QAbstractItemModel *m) | - | ||||||||||||||||||||||||
| 812 | { | - | ||||||||||||||||||||||||
| 813 | Q_Q(QCompleter); | - | ||||||||||||||||||||||||
| 814 | proxy = new QCompletionModel(this, q); | - | ||||||||||||||||||||||||
| 815 | QObject::connect(proxy, SIGNAL(rowsAdded()), q, SLOT(_q_autoResizePopup())); | - | ||||||||||||||||||||||||
| 816 | q->setModel(m); | - | ||||||||||||||||||||||||
| 817 | #ifdef QT_NO_LISTVIEW | - | ||||||||||||||||||||||||
| 818 | q->setCompletionMode(QCompleter::InlineCompletion); | - | ||||||||||||||||||||||||
| 819 | #else | - | ||||||||||||||||||||||||
| 820 | q->setCompletionMode(QCompleter::PopupCompletion); | - | ||||||||||||||||||||||||
| 821 | #endif // QT_NO_LISTVIEW | - | ||||||||||||||||||||||||
| 822 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 823 | - | |||||||||||||||||||||||||
| 824 | void QCompleterPrivate::setCurrentIndex(QModelIndex index, bool select) | - | ||||||||||||||||||||||||
| 825 | { | - | ||||||||||||||||||||||||
| 826 | Q_Q(QCompleter); | - | ||||||||||||||||||||||||
| 827 | if (!q->popup())
| 0 | ||||||||||||||||||||||||
| 828 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 829 | if (!select) {
| 0 | ||||||||||||||||||||||||
| 830 | popup->selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate); | - | ||||||||||||||||||||||||
| 831 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 832 | if (!index.isValid())
| 0 | ||||||||||||||||||||||||
| 833 | popup->selectionModel()->clear(); never executed: popup->selectionModel()->clear(); | 0 | ||||||||||||||||||||||||
| 834 | else | - | ||||||||||||||||||||||||
| 835 | popup->selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select never executed: popup->selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select | QItemSelectionModel::Rows); | 0 | ||||||||||||||||||||||||
| 836 | | QItemSelectionModel::Rows); never executed: popup->selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select | QItemSelectionModel::Rows); | 0 | ||||||||||||||||||||||||
| 837 | } | - | ||||||||||||||||||||||||
| 838 | index = popup->selectionModel()->currentIndex(); | - | ||||||||||||||||||||||||
| 839 | if (!index.isValid())
| 0 | ||||||||||||||||||||||||
| 840 | popup->scrollToTop(); never executed: popup->scrollToTop(); | 0 | ||||||||||||||||||||||||
| 841 | else | - | ||||||||||||||||||||||||
| 842 | popup->scrollTo(index, QAbstractItemView::PositionAtTop); never executed: popup->scrollTo(index, QAbstractItemView::PositionAtTop); | 0 | ||||||||||||||||||||||||
| 843 | } | - | ||||||||||||||||||||||||
| 844 | - | |||||||||||||||||||||||||
| 845 | void QCompleterPrivate::_q_completionSelected(const QItemSelection& selection) | - | ||||||||||||||||||||||||
| 846 | { | - | ||||||||||||||||||||||||
| 847 | QModelIndex index; | - | ||||||||||||||||||||||||
| 848 | if (!selection.indexes().isEmpty())
| 0 | ||||||||||||||||||||||||
| 849 | index = selection.indexes().first(); never executed: index = selection.indexes().first(); | 0 | ||||||||||||||||||||||||
| 850 | - | |||||||||||||||||||||||||
| 851 | _q_complete(index, true); | - | ||||||||||||||||||||||||
| 852 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 853 | - | |||||||||||||||||||||||||
| 854 | void QCompleterPrivate::_q_complete(QModelIndex index, bool highlighted) | - | ||||||||||||||||||||||||
| 855 | { | - | ||||||||||||||||||||||||
| 856 | Q_Q(QCompleter); | - | ||||||||||||||||||||||||
| 857 | QString completion; | - | ||||||||||||||||||||||||
| 858 | - | |||||||||||||||||||||||||
| 859 | if (!index.isValid() || (!proxy->showAll && (index.row() >= proxy->engine->matchCount()))) {
| 0 | ||||||||||||||||||||||||
| 860 | completion = prefix; | - | ||||||||||||||||||||||||
| 861 | index = QModelIndex(); | - | ||||||||||||||||||||||||
| 862 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 863 | if (!(index.flags() & Qt::ItemIsEnabled))
| 0 | ||||||||||||||||||||||||
| 864 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 865 | QModelIndex si = proxy->mapToSource(index); | - | ||||||||||||||||||||||||
| 866 | si = si.sibling(si.row(), column); // for clicked() | - | ||||||||||||||||||||||||
| 867 | completion = q->pathFromIndex(si); | - | ||||||||||||||||||||||||
| 868 | #ifndef QT_NO_DIRMODEL | - | ||||||||||||||||||||||||
| 869 | // add a trailing separator in inline | - | ||||||||||||||||||||||||
| 870 | if (mode == QCompleter::InlineCompletion) {
| 0 | ||||||||||||||||||||||||
| 871 | if (qobject_cast<QDirModel *>(proxy->sourceModel()) && QFileInfo(completion).isDir())
| 0 | ||||||||||||||||||||||||
| 872 | completion += QDir::separator(); never executed: completion += QDir::separator(); | 0 | ||||||||||||||||||||||||
| 873 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 874 | #endif | - | ||||||||||||||||||||||||
| 875 | #ifndef QT_NO_FILESYSTEMMODEL | - | ||||||||||||||||||||||||
| 876 | // add a trailing separator in inline | - | ||||||||||||||||||||||||
| 877 | if (mode == QCompleter::InlineCompletion) {
| 0 | ||||||||||||||||||||||||
| 878 | if (qobject_cast<QFileSystemModel *>(proxy->sourceModel()) && QFileInfo(completion).isDir())
| 0 | ||||||||||||||||||||||||
| 879 | completion += QDir::separator(); never executed: completion += QDir::separator(); | 0 | ||||||||||||||||||||||||
| 880 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 881 | #endif | - | ||||||||||||||||||||||||
| 882 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 883 | - | |||||||||||||||||||||||||
| 884 | if (highlighted) {
| 0 | ||||||||||||||||||||||||
| 885 | emit q->highlighted(index); | - | ||||||||||||||||||||||||
| 886 | emit q->highlighted(completion); | - | ||||||||||||||||||||||||
| 887 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 888 | emit q->activated(index); | - | ||||||||||||||||||||||||
| 889 | emit q->activated(completion); | - | ||||||||||||||||||||||||
| 890 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 891 | } | - | ||||||||||||||||||||||||
| 892 | - | |||||||||||||||||||||||||
| 893 | void QCompleterPrivate::_q_autoResizePopup() | - | ||||||||||||||||||||||||
| 894 | { | - | ||||||||||||||||||||||||
| 895 | if (!popup || !popup->isVisible())
| 0 | ||||||||||||||||||||||||
| 896 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 897 | showPopup(popupRect); | - | ||||||||||||||||||||||||
| 898 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 899 | - | |||||||||||||||||||||||||
| 900 | void QCompleterPrivate::showPopup(const QRect& rect) | - | ||||||||||||||||||||||||
| 901 | { | - | ||||||||||||||||||||||||
| 902 | const QRect screen = QApplication::desktop()->availableGeometry(widget); | - | ||||||||||||||||||||||||
| 903 | Qt::LayoutDirection dir = widget->layoutDirection(); | - | ||||||||||||||||||||||||
| 904 | QPoint pos; | - | ||||||||||||||||||||||||
| 905 | int rh, w; | - | ||||||||||||||||||||||||
| 906 | int h = (popup->sizeHintForRow(0) * qMin(maxVisibleItems, popup->model()->rowCount()) + 3) + 3; | - | ||||||||||||||||||||||||
| 907 | QScrollBar *hsb = popup->horizontalScrollBar(); | - | ||||||||||||||||||||||||
| 908 | if (hsb && hsb->isVisible())
| 0 | ||||||||||||||||||||||||
| 909 | h += popup->horizontalScrollBar()->sizeHint().height(); never executed: h += popup->horizontalScrollBar()->sizeHint().height(); | 0 | ||||||||||||||||||||||||
| 910 | - | |||||||||||||||||||||||||
| 911 | if (rect.isValid()) {
| 0 | ||||||||||||||||||||||||
| 912 | rh = rect.height(); | - | ||||||||||||||||||||||||
| 913 | w = rect.width(); | - | ||||||||||||||||||||||||
| 914 | pos = widget->mapToGlobal(dir == Qt::RightToLeft ? rect.bottomRight() : rect.bottomLeft()); | - | ||||||||||||||||||||||||
| 915 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 916 | rh = widget->height(); | - | ||||||||||||||||||||||||
| 917 | pos = widget->mapToGlobal(QPoint(0, widget->height() - 2)); | - | ||||||||||||||||||||||||
| 918 | w = widget->width(); | - | ||||||||||||||||||||||||
| 919 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 920 | - | |||||||||||||||||||||||||
| 921 | if (w > screen.width())
| 0 | ||||||||||||||||||||||||
| 922 | w = screen.width(); never executed: w = screen.width(); | 0 | ||||||||||||||||||||||||
| 923 | if ((pos.x() + w) > (screen.x() + screen.width()))
| 0 | ||||||||||||||||||||||||
| 924 | pos.setX(screen.x() + screen.width() - w); never executed: pos.setX(screen.x() + screen.width() - w); | 0 | ||||||||||||||||||||||||
| 925 | if (pos.x() < screen.x())
| 0 | ||||||||||||||||||||||||
| 926 | pos.setX(screen.x()); never executed: pos.setX(screen.x()); | 0 | ||||||||||||||||||||||||
| 927 | - | |||||||||||||||||||||||||
| 928 | int top = pos.y() - rh - screen.top() + 2; | - | ||||||||||||||||||||||||
| 929 | int bottom = screen.bottom() - pos.y(); | - | ||||||||||||||||||||||||
| 930 | h = qMax(h, popup->minimumHeight()); | - | ||||||||||||||||||||||||
| 931 | if (h > bottom) {
| 0 | ||||||||||||||||||||||||
| 932 | h = qMin(qMax(top, bottom), h); | - | ||||||||||||||||||||||||
| 933 | - | |||||||||||||||||||||||||
| 934 | if (top > bottom)
| 0 | ||||||||||||||||||||||||
| 935 | pos.setY(pos.y() - h - rh + 2); never executed: pos.setY(pos.y() - h - rh + 2); | 0 | ||||||||||||||||||||||||
| 936 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 937 | - | |||||||||||||||||||||||||
| 938 | popup->setGeometry(pos.x(), pos.y(), w, h); | - | ||||||||||||||||||||||||
| 939 | - | |||||||||||||||||||||||||
| 940 | if (!popup->isVisible())
| 0 | ||||||||||||||||||||||||
| 941 | popup->show(); never executed: popup->show(); | 0 | ||||||||||||||||||||||||
| 942 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 943 | - | |||||||||||||||||||||||||
| 944 | void QCompleterPrivate::_q_fileSystemModelDirectoryLoaded(const QString &path) | - | ||||||||||||||||||||||||
| 945 | { | - | ||||||||||||||||||||||||
| 946 | Q_Q(QCompleter); | - | ||||||||||||||||||||||||
| 947 | // Slot called when QFileSystemModel has finished loading. | - | ||||||||||||||||||||||||
| 948 | // If we hide the popup because there was no match because the model was not loaded yet, | - | ||||||||||||||||||||||||
| 949 | // we re-start the completion when we get the results | - | ||||||||||||||||||||||||
| 950 | if (hiddenBecauseNoMatch
| 0 | ||||||||||||||||||||||||
| 951 | && prefix.startsWith(path) && prefix != (path + QLatin1Char('/'))
| 0 | ||||||||||||||||||||||||
| 952 | && widget) {
| 0 | ||||||||||||||||||||||||
| 953 | q->complete(); | - | ||||||||||||||||||||||||
| 954 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 955 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 956 | - | |||||||||||||||||||||||||
| 957 | /*! | - | ||||||||||||||||||||||||
| 958 | Constructs a completer object with the given \a parent. | - | ||||||||||||||||||||||||
| 959 | */ | - | ||||||||||||||||||||||||
| 960 | QCompleter::QCompleter(QObject *parent) | - | ||||||||||||||||||||||||
| 961 | : QObject(*new QCompleterPrivate(), parent) | - | ||||||||||||||||||||||||
| 962 | { | - | ||||||||||||||||||||||||
| 963 | Q_D(QCompleter); | - | ||||||||||||||||||||||||
| 964 | d->init(); | - | ||||||||||||||||||||||||
| 965 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 966 | - | |||||||||||||||||||||||||
| 967 | /*! | - | ||||||||||||||||||||||||
| 968 | Constructs a completer object with the given \a parent that provides completions | - | ||||||||||||||||||||||||
| 969 | from the specified \a model. | - | ||||||||||||||||||||||||
| 970 | */ | - | ||||||||||||||||||||||||
| 971 | QCompleter::QCompleter(QAbstractItemModel *model, QObject *parent) | - | ||||||||||||||||||||||||
| 972 | : QObject(*new QCompleterPrivate(), parent) | - | ||||||||||||||||||||||||
| 973 | { | - | ||||||||||||||||||||||||
| 974 | Q_D(QCompleter); | - | ||||||||||||||||||||||||
| 975 | d->init(model); | - | ||||||||||||||||||||||||
| 976 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 977 | - | |||||||||||||||||||||||||
| 978 | #ifndef QT_NO_STRINGLISTMODEL | - | ||||||||||||||||||||||||
| 979 | /*! | - | ||||||||||||||||||||||||
| 980 | Constructs a QCompleter object with the given \a parent that uses the specified | - | ||||||||||||||||||||||||
| 981 | \a list as a source of possible completions. | - | ||||||||||||||||||||||||
| 982 | */ | - | ||||||||||||||||||||||||
| 983 | QCompleter::QCompleter(const QStringList& list, QObject *parent) | - | ||||||||||||||||||||||||
| 984 | : QObject(*new QCompleterPrivate(), parent) | - | ||||||||||||||||||||||||
| 985 | { | - | ||||||||||||||||||||||||
| 986 | Q_D(QCompleter); | - | ||||||||||||||||||||||||
| 987 | d->init(new QStringListModel(list, this)); | - | ||||||||||||||||||||||||
| 988 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 989 | #endif // QT_NO_STRINGLISTMODEL | - | ||||||||||||||||||||||||
| 990 | - | |||||||||||||||||||||||||
| 991 | /*! | - | ||||||||||||||||||||||||
| 992 | Destroys the completer object. | - | ||||||||||||||||||||||||
| 993 | */ | - | ||||||||||||||||||||||||
| 994 | QCompleter::~QCompleter() | - | ||||||||||||||||||||||||
| 995 | { | - | ||||||||||||||||||||||||
| 996 | } | - | ||||||||||||||||||||||||
| 997 | - | |||||||||||||||||||||||||
| 998 | /*! | - | ||||||||||||||||||||||||
| 999 | Sets the widget for which completion are provided for to \a widget. This | - | ||||||||||||||||||||||||
| 1000 | function is automatically called when a QCompleter is set on a QLineEdit | - | ||||||||||||||||||||||||
| 1001 | using QLineEdit::setCompleter() or on a QComboBox using | - | ||||||||||||||||||||||||
| 1002 | QComboBox::setCompleter(). The widget needs to be set explicitly when | - | ||||||||||||||||||||||||
| 1003 | providing completions for custom widgets. | - | ||||||||||||||||||||||||
| 1004 | - | |||||||||||||||||||||||||
| 1005 | \sa widget(), setModel(), setPopup() | - | ||||||||||||||||||||||||
| 1006 | */ | - | ||||||||||||||||||||||||
| 1007 | void QCompleter::setWidget(QWidget *widget) | - | ||||||||||||||||||||||||
| 1008 | { | - | ||||||||||||||||||||||||
| 1009 | Q_D(QCompleter); | - | ||||||||||||||||||||||||
| 1010 | if (d->widget)
| 0 | ||||||||||||||||||||||||
| 1011 | d->widget->removeEventFilter(this); never executed: d->widget->removeEventFilter(this); | 0 | ||||||||||||||||||||||||
| 1012 | d->widget = widget; | - | ||||||||||||||||||||||||
| 1013 | if (d->widget)
| 0 | ||||||||||||||||||||||||
| 1014 | d->widget->installEventFilter(this); never executed: d->widget->installEventFilter(this); | 0 | ||||||||||||||||||||||||
| 1015 | if (d->popup) {
| 0 | ||||||||||||||||||||||||
| 1016 | d->popup->hide(); | - | ||||||||||||||||||||||||
| 1017 | d->popup->setFocusProxy(d->widget); | - | ||||||||||||||||||||||||
| 1018 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1019 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1020 | - | |||||||||||||||||||||||||
| 1021 | /*! | - | ||||||||||||||||||||||||
| 1022 | Returns the widget for which the completer object is providing completions. | - | ||||||||||||||||||||||||
| 1023 | - | |||||||||||||||||||||||||
| 1024 | \sa setWidget() | - | ||||||||||||||||||||||||
| 1025 | */ | - | ||||||||||||||||||||||||
| 1026 | QWidget *QCompleter::widget() const | - | ||||||||||||||||||||||||
| 1027 | { | - | ||||||||||||||||||||||||
| 1028 | Q_D(const QCompleter); | - | ||||||||||||||||||||||||
| 1029 | return d->widget; never executed: return d->widget; | 0 | ||||||||||||||||||||||||
| 1030 | } | - | ||||||||||||||||||||||||
| 1031 | - | |||||||||||||||||||||||||
| 1032 | /*! | - | ||||||||||||||||||||||||
| 1033 | Sets the model which provides completions to \a model. The \a model can | - | ||||||||||||||||||||||||
| 1034 | be list model or a tree model. If a model has been already previously set | - | ||||||||||||||||||||||||
| 1035 | and it has the QCompleter as its parent, it is deleted. | - | ||||||||||||||||||||||||
| 1036 | - | |||||||||||||||||||||||||
| 1037 | For convenience, if \a model is a QFileSystemModel, QCompleter switches its | - | ||||||||||||||||||||||||
| 1038 | caseSensitivity to Qt::CaseInsensitive on Windows and Qt::CaseSensitive | - | ||||||||||||||||||||||||
| 1039 | on other platforms. | - | ||||||||||||||||||||||||
| 1040 | - | |||||||||||||||||||||||||
| 1041 | \sa completionModel(), modelSorting, {Handling Tree Models} | - | ||||||||||||||||||||||||
| 1042 | */ | - | ||||||||||||||||||||||||
| 1043 | void QCompleter::setModel(QAbstractItemModel *model) | - | ||||||||||||||||||||||||
| 1044 | { | - | ||||||||||||||||||||||||
| 1045 | Q_D(QCompleter); | - | ||||||||||||||||||||||||
| 1046 | QAbstractItemModel *oldModel = d->proxy->sourceModel(); | - | ||||||||||||||||||||||||
| 1047 | #ifndef QT_NO_FILESYSTEMMODEL | - | ||||||||||||||||||||||||
| 1048 | if (qobject_cast<const QFileSystemModel *>(oldModel))
| 0 | ||||||||||||||||||||||||
| 1049 | setCompletionRole(Qt::EditRole); // QTBUG-54642, clear FileNameRole set by QFileSystemModel never executed: setCompletionRole(Qt::EditRole); | 0 | ||||||||||||||||||||||||
| 1050 | #endif | - | ||||||||||||||||||||||||
| 1051 | d->proxy->setSourceModel(model); | - | ||||||||||||||||||||||||
| 1052 | if (d->popup)
| 0 | ||||||||||||||||||||||||
| 1053 | setPopup(d->popup); // set the model and make new connections never executed: setPopup(d->popup); | 0 | ||||||||||||||||||||||||
| 1054 | if (oldModel && oldModel->QObject::parent() == this)
| 0 | ||||||||||||||||||||||||
| 1055 | delete oldModel; never executed: delete oldModel; | 0 | ||||||||||||||||||||||||
| 1056 | #ifndef QT_NO_DIRMODEL | - | ||||||||||||||||||||||||
| 1057 | if (qobject_cast<QDirModel *>(model)) {
| 0 | ||||||||||||||||||||||||
| 1058 | #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) | - | ||||||||||||||||||||||||
| 1059 | setCaseSensitivity(Qt::CaseInsensitive); | - | ||||||||||||||||||||||||
| 1060 | #else | - | ||||||||||||||||||||||||
| 1061 | setCaseSensitivity(Qt::CaseSensitive); | - | ||||||||||||||||||||||||
| 1062 | #endif | - | ||||||||||||||||||||||||
| 1063 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1064 | #endif // QT_NO_DIRMODEL | - | ||||||||||||||||||||||||
| 1065 | #ifndef QT_NO_FILESYSTEMMODEL | - | ||||||||||||||||||||||||
| 1066 | QFileSystemModel *fsModel = qobject_cast<QFileSystemModel *>(model); | - | ||||||||||||||||||||||||
| 1067 | if (fsModel) {
| 0 | ||||||||||||||||||||||||
| 1068 | #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) | - | ||||||||||||||||||||||||
| 1069 | setCaseSensitivity(Qt::CaseInsensitive); | - | ||||||||||||||||||||||||
| 1070 | #else | - | ||||||||||||||||||||||||
| 1071 | setCaseSensitivity(Qt::CaseSensitive); | - | ||||||||||||||||||||||||
| 1072 | #endif | - | ||||||||||||||||||||||||
| 1073 | setCompletionRole(QFileSystemModel::FileNameRole); | - | ||||||||||||||||||||||||
| 1074 | connect(fsModel, SIGNAL(directoryLoaded(QString)), this, SLOT(_q_fileSystemModelDirectoryLoaded(QString))); | - | ||||||||||||||||||||||||
| 1075 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1076 | #endif // QT_NO_FILESYSTEMMODEL | - | ||||||||||||||||||||||||
| 1077 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1078 | - | |||||||||||||||||||||||||
| 1079 | /*! | - | ||||||||||||||||||||||||
| 1080 | Returns the model that provides completion strings. | - | ||||||||||||||||||||||||
| 1081 | - | |||||||||||||||||||||||||
| 1082 | \sa completionModel() | - | ||||||||||||||||||||||||
| 1083 | */ | - | ||||||||||||||||||||||||
| 1084 | QAbstractItemModel *QCompleter::model() const | - | ||||||||||||||||||||||||
| 1085 | { | - | ||||||||||||||||||||||||
| 1086 | Q_D(const QCompleter); | - | ||||||||||||||||||||||||
| 1087 | return d->proxy->sourceModel(); never executed: return d->proxy->sourceModel(); | 0 | ||||||||||||||||||||||||
| 1088 | } | - | ||||||||||||||||||||||||
| 1089 | - | |||||||||||||||||||||||||
| 1090 | /*! | - | ||||||||||||||||||||||||
| 1091 | \enum QCompleter::CompletionMode | - | ||||||||||||||||||||||||
| 1092 | - | |||||||||||||||||||||||||
| 1093 | This enum specifies how completions are provided to the user. | - | ||||||||||||||||||||||||
| 1094 | - | |||||||||||||||||||||||||
| 1095 | \value PopupCompletion Current completions are displayed in a popup window. | - | ||||||||||||||||||||||||
| 1096 | \value InlineCompletion Completions appear inline (as selected text). | - | ||||||||||||||||||||||||
| 1097 | \value UnfilteredPopupCompletion All possible completions are displayed in a popup window with the most likely suggestion indicated as current. | - | ||||||||||||||||||||||||
| 1098 | - | |||||||||||||||||||||||||
| 1099 | \sa setCompletionMode() | - | ||||||||||||||||||||||||
| 1100 | */ | - | ||||||||||||||||||||||||
| 1101 | - | |||||||||||||||||||||||||
| 1102 | /*! | - | ||||||||||||||||||||||||
| 1103 | \property QCompleter::completionMode | - | ||||||||||||||||||||||||
| 1104 | \brief how the completions are provided to the user | - | ||||||||||||||||||||||||
| 1105 | - | |||||||||||||||||||||||||
| 1106 | The default value is QCompleter::PopupCompletion. | - | ||||||||||||||||||||||||
| 1107 | */ | - | ||||||||||||||||||||||||
| 1108 | void QCompleter::setCompletionMode(QCompleter::CompletionMode mode) | - | ||||||||||||||||||||||||
| 1109 | { | - | ||||||||||||||||||||||||
| 1110 | Q_D(QCompleter); | - | ||||||||||||||||||||||||
| 1111 | d->mode = mode; | - | ||||||||||||||||||||||||
| 1112 | d->proxy->setFiltered(mode != QCompleter::UnfilteredPopupCompletion); | - | ||||||||||||||||||||||||
| 1113 | - | |||||||||||||||||||||||||
| 1114 | if (mode == QCompleter::InlineCompletion) {
| 0 | ||||||||||||||||||||||||
| 1115 | if (d->widget)
| 0 | ||||||||||||||||||||||||
| 1116 | d->widget->removeEventFilter(this); never executed: d->widget->removeEventFilter(this); | 0 | ||||||||||||||||||||||||
| 1117 | if (d->popup) {
| 0 | ||||||||||||||||||||||||
| 1118 | d->popup->deleteLater(); | - | ||||||||||||||||||||||||
| 1119 | d->popup = 0; | - | ||||||||||||||||||||||||
| 1120 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1121 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1122 | if (d->widget)
| 0 | ||||||||||||||||||||||||
| 1123 | d->widget->installEventFilter(this); never executed: d->widget->installEventFilter(this); | 0 | ||||||||||||||||||||||||
| 1124 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1125 | } | - | ||||||||||||||||||||||||
| 1126 | - | |||||||||||||||||||||||||
| 1127 | QCompleter::CompletionMode QCompleter::completionMode() const | - | ||||||||||||||||||||||||
| 1128 | { | - | ||||||||||||||||||||||||
| 1129 | Q_D(const QCompleter); | - | ||||||||||||||||||||||||
| 1130 | return d->mode; never executed: return d->mode; | 0 | ||||||||||||||||||||||||
| 1131 | } | - | ||||||||||||||||||||||||
| 1132 | - | |||||||||||||||||||||||||
| 1133 | /*! | - | ||||||||||||||||||||||||
| 1134 | \property QCompleter::filterMode | - | ||||||||||||||||||||||||
| 1135 | \brief how the filtering is performed | - | ||||||||||||||||||||||||
| 1136 | \since 5.2 | - | ||||||||||||||||||||||||
| 1137 | - | |||||||||||||||||||||||||
| 1138 | If filterMode is set to Qt::MatchStartsWith, only those entries that start | - | ||||||||||||||||||||||||
| 1139 | with the typed characters will be displayed. Qt::MatchContains will display | - | ||||||||||||||||||||||||
| 1140 | the entries that contain the typed characters, and Qt::MatchEndsWith the | - | ||||||||||||||||||||||||
| 1141 | ones that end with the typed characters. | - | ||||||||||||||||||||||||
| 1142 | - | |||||||||||||||||||||||||
| 1143 | Currently, only these three modes are implemented. Setting filterMode to | - | ||||||||||||||||||||||||
| 1144 | any other Qt::MatchFlag will issue a warning, and no action will be | - | ||||||||||||||||||||||||
| 1145 | performed. | - | ||||||||||||||||||||||||
| 1146 | - | |||||||||||||||||||||||||
| 1147 | The default mode is Qt::MatchStartsWith. | - | ||||||||||||||||||||||||
| 1148 | */ | - | ||||||||||||||||||||||||
| 1149 | - | |||||||||||||||||||||||||
| 1150 | void QCompleter::setFilterMode(Qt::MatchFlags filterMode) | - | ||||||||||||||||||||||||
| 1151 | { | - | ||||||||||||||||||||||||
| 1152 | Q_D(QCompleter); | - | ||||||||||||||||||||||||
| 1153 | - | |||||||||||||||||||||||||
| 1154 | if (d->filterMode == filterMode)
| 0 | ||||||||||||||||||||||||
| 1155 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1156 | - | |||||||||||||||||||||||||
| 1157 | if (Q_UNLIKELY(filterMode != Qt::MatchStartsWith &&
| 0 | ||||||||||||||||||||||||
| 1158 | filterMode != Qt::MatchContains && | - | ||||||||||||||||||||||||
| 1159 | filterMode != Qt::MatchEndsWith)) { | - | ||||||||||||||||||||||||
| 1160 | qWarning("Unhandled QCompleter::filterMode flag is used."); | - | ||||||||||||||||||||||||
| 1161 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1162 | } | - | ||||||||||||||||||||||||
| 1163 | - | |||||||||||||||||||||||||
| 1164 | d->filterMode = filterMode; | - | ||||||||||||||||||||||||
| 1165 | d->proxy->createEngine(); | - | ||||||||||||||||||||||||
| 1166 | d->proxy->invalidate(); | - | ||||||||||||||||||||||||
| 1167 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1168 | - | |||||||||||||||||||||||||
| 1169 | Qt::MatchFlags QCompleter::filterMode() const | - | ||||||||||||||||||||||||
| 1170 | { | - | ||||||||||||||||||||||||
| 1171 | Q_D(const QCompleter); | - | ||||||||||||||||||||||||
| 1172 | return d->filterMode; never executed: return d->filterMode; | 0 | ||||||||||||||||||||||||
| 1173 | } | - | ||||||||||||||||||||||||
| 1174 | - | |||||||||||||||||||||||||
| 1175 | /*! | - | ||||||||||||||||||||||||
| 1176 | Sets the popup used to display completions to \a popup. QCompleter takes | - | ||||||||||||||||||||||||
| 1177 | ownership of the view. | - | ||||||||||||||||||||||||
| 1178 | - | |||||||||||||||||||||||||
| 1179 | A QListView is automatically created when the completionMode() is set to | - | ||||||||||||||||||||||||
| 1180 | QCompleter::PopupCompletion or QCompleter::UnfilteredPopupCompletion. The | - | ||||||||||||||||||||||||
| 1181 | default popup displays the completionColumn(). | - | ||||||||||||||||||||||||
| 1182 | - | |||||||||||||||||||||||||
| 1183 | Ensure that this function is called before the view settings are modified. | - | ||||||||||||||||||||||||
| 1184 | This is required since view's properties may require that a model has been | - | ||||||||||||||||||||||||
| 1185 | set on the view (for example, hiding columns in the view requires a model | - | ||||||||||||||||||||||||
| 1186 | to be set on the view). | - | ||||||||||||||||||||||||
| 1187 | - | |||||||||||||||||||||||||
| 1188 | \sa popup() | - | ||||||||||||||||||||||||
| 1189 | */ | - | ||||||||||||||||||||||||
| 1190 | void QCompleter::setPopup(QAbstractItemView *popup) | - | ||||||||||||||||||||||||
| 1191 | { | - | ||||||||||||||||||||||||
| 1192 | Q_D(QCompleter); | - | ||||||||||||||||||||||||
| 1193 | Q_ASSERT(popup != 0); | - | ||||||||||||||||||||||||
| 1194 | if (d->popup) {
| 0 | ||||||||||||||||||||||||
| 1195 | QObject::disconnect(d->popup->selectionModel(), 0, this, 0); | - | ||||||||||||||||||||||||
| 1196 | QObject::disconnect(d->popup, 0, this, 0); | - | ||||||||||||||||||||||||
| 1197 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1198 | if (d->popup != popup)
| 0 | ||||||||||||||||||||||||
| 1199 | delete d->popup; never executed: delete d->popup; | 0 | ||||||||||||||||||||||||
| 1200 | if (popup->model() != d->proxy)
| 0 | ||||||||||||||||||||||||
| 1201 | popup->setModel(d->proxy); never executed: popup->setModel(d->proxy); | 0 | ||||||||||||||||||||||||
| 1202 | popup->hide(); | - | ||||||||||||||||||||||||
| 1203 | - | |||||||||||||||||||||||||
| 1204 | Qt::FocusPolicy origPolicy = Qt::NoFocus; | - | ||||||||||||||||||||||||
| 1205 | if (d->widget)
| 0 | ||||||||||||||||||||||||
| 1206 | origPolicy = d->widget->focusPolicy(); never executed: origPolicy = d->widget->focusPolicy(); | 0 | ||||||||||||||||||||||||
| 1207 | popup->setParent(0, Qt::Popup); | - | ||||||||||||||||||||||||
| 1208 | popup->setFocusPolicy(Qt::NoFocus); | - | ||||||||||||||||||||||||
| 1209 | if (d->widget)
| 0 | ||||||||||||||||||||||||
| 1210 | d->widget->setFocusPolicy(origPolicy); never executed: d->widget->setFocusPolicy(origPolicy); | 0 | ||||||||||||||||||||||||
| 1211 | - | |||||||||||||||||||||||||
| 1212 | popup->setFocusProxy(d->widget); | - | ||||||||||||||||||||||||
| 1213 | popup->installEventFilter(this); | - | ||||||||||||||||||||||||
| 1214 | popup->setItemDelegate(new QCompleterItemDelegate(popup)); | - | ||||||||||||||||||||||||
| 1215 | #ifndef QT_NO_LISTVIEW | - | ||||||||||||||||||||||||
| 1216 | if (QListView *listView = qobject_cast<QListView *>(popup)) {
| 0 | ||||||||||||||||||||||||
| 1217 | listView->setModelColumn(d->column); | - | ||||||||||||||||||||||||
| 1218 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1219 | #endif | - | ||||||||||||||||||||||||
| 1220 | - | |||||||||||||||||||||||||
| 1221 | QObject::connect(popup, SIGNAL(clicked(QModelIndex)), | - | ||||||||||||||||||||||||
| 1222 | this, SLOT(_q_complete(QModelIndex))); | - | ||||||||||||||||||||||||
| 1223 | QObject::connect(this, SIGNAL(activated(QModelIndex)), | - | ||||||||||||||||||||||||
| 1224 | popup, SLOT(hide())); | - | ||||||||||||||||||||||||
| 1225 | - | |||||||||||||||||||||||||
| 1226 | QObject::connect(popup->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), | - | ||||||||||||||||||||||||
| 1227 | this, SLOT(_q_completionSelected(QItemSelection))); | - | ||||||||||||||||||||||||
| 1228 | d->popup = popup; | - | ||||||||||||||||||||||||
| 1229 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1230 | - | |||||||||||||||||||||||||
| 1231 | /*! | - | ||||||||||||||||||||||||
| 1232 | Returns the popup used to display completions. | - | ||||||||||||||||||||||||
| 1233 | - | |||||||||||||||||||||||||
| 1234 | \sa setPopup() | - | ||||||||||||||||||||||||
| 1235 | */ | - | ||||||||||||||||||||||||
| 1236 | QAbstractItemView *QCompleter::popup() const | - | ||||||||||||||||||||||||
| 1237 | { | - | ||||||||||||||||||||||||
| 1238 | Q_D(const QCompleter); | - | ||||||||||||||||||||||||
| 1239 | #ifndef QT_NO_LISTVIEW | - | ||||||||||||||||||||||||
| 1240 | if (!d->popup && completionMode() != QCompleter::InlineCompletion) {
| 0 | ||||||||||||||||||||||||
| 1241 | QListView *listView = new QListView; | - | ||||||||||||||||||||||||
| 1242 | listView->setEditTriggers(QAbstractItemView::NoEditTriggers); | - | ||||||||||||||||||||||||
| 1243 | listView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | - | ||||||||||||||||||||||||
| 1244 | listView->setSelectionBehavior(QAbstractItemView::SelectRows); | - | ||||||||||||||||||||||||
| 1245 | listView->setSelectionMode(QAbstractItemView::SingleSelection); | - | ||||||||||||||||||||||||
| 1246 | listView->setModelColumn(d->column); | - | ||||||||||||||||||||||||
| 1247 | QCompleter *that = const_cast<QCompleter*>(this); | - | ||||||||||||||||||||||||
| 1248 | that->setPopup(listView); | - | ||||||||||||||||||||||||
| 1249 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1250 | #endif // QT_NO_LISTVIEW | - | ||||||||||||||||||||||||
| 1251 | return d->popup; never executed: return d->popup; | 0 | ||||||||||||||||||||||||
| 1252 | } | - | ||||||||||||||||||||||||
| 1253 | - | |||||||||||||||||||||||||
| 1254 | /*! | - | ||||||||||||||||||||||||
| 1255 | \reimp | - | ||||||||||||||||||||||||
| 1256 | */ | - | ||||||||||||||||||||||||
| 1257 | bool QCompleter::event(QEvent *ev) | - | ||||||||||||||||||||||||
| 1258 | { | - | ||||||||||||||||||||||||
| 1259 | return QObject::event(ev); never executed: return QObject::event(ev); | 0 | ||||||||||||||||||||||||
| 1260 | } | - | ||||||||||||||||||||||||
| 1261 | - | |||||||||||||||||||||||||
| 1262 | /*! | - | ||||||||||||||||||||||||
| 1263 | \reimp | - | ||||||||||||||||||||||||
| 1264 | */ | - | ||||||||||||||||||||||||
| 1265 | bool QCompleter::eventFilter(QObject *o, QEvent *e) | - | ||||||||||||||||||||||||
| 1266 | { | - | ||||||||||||||||||||||||
| 1267 | Q_D(QCompleter); | - | ||||||||||||||||||||||||
| 1268 | - | |||||||||||||||||||||||||
| 1269 | if (d->eatFocusOut && o == d->widget && e->type() == QEvent::FocusOut) {
| 0 | ||||||||||||||||||||||||
| 1270 | d->hiddenBecauseNoMatch = false; | - | ||||||||||||||||||||||||
| 1271 | if (d->popup && d->popup->isVisible())
| 0 | ||||||||||||||||||||||||
| 1272 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 1273 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1274 | - | |||||||||||||||||||||||||
| 1275 | if (o != d->popup)
| 0 | ||||||||||||||||||||||||
| 1276 | return QObject::eventFilter(o, e); never executed: return QObject::eventFilter(o, e); | 0 | ||||||||||||||||||||||||
| 1277 | - | |||||||||||||||||||||||||
| 1278 | switch (e->type()) { | - | ||||||||||||||||||||||||
| 1279 | case QEvent::KeyPress: { never executed: case QEvent::KeyPress: | 0 | ||||||||||||||||||||||||
| 1280 | QKeyEvent *ke = static_cast<QKeyEvent *>(e); | - | ||||||||||||||||||||||||
| 1281 | - | |||||||||||||||||||||||||
| 1282 | QModelIndex curIndex = d->popup->currentIndex(); | - | ||||||||||||||||||||||||
| 1283 | QModelIndexList selList = d->popup->selectionModel()->selectedIndexes(); | - | ||||||||||||||||||||||||
| 1284 | - | |||||||||||||||||||||||||
| 1285 | const int key = ke->key(); | - | ||||||||||||||||||||||||
| 1286 | // In UnFilteredPopup mode, select the current item | - | ||||||||||||||||||||||||
| 1287 | if ((key == Qt::Key_Up || key == Qt::Key_Down) && selList.isEmpty() && curIndex.isValid()
| 0 | ||||||||||||||||||||||||
| 1288 | && d->mode == QCompleter::UnfilteredPopupCompletion) {
| 0 | ||||||||||||||||||||||||
| 1289 | d->setCurrentIndex(curIndex); | - | ||||||||||||||||||||||||
| 1290 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 1291 | } | - | ||||||||||||||||||||||||
| 1292 | - | |||||||||||||||||||||||||
| 1293 | // Handle popup navigation keys. These are hardcoded because up/down might make the | - | ||||||||||||||||||||||||
| 1294 | // widget do something else (lineedit cursor moves to home/end on mac, for instance) | - | ||||||||||||||||||||||||
| 1295 | switch (key) { | - | ||||||||||||||||||||||||
| 1296 | case Qt::Key_End: never executed: case Qt::Key_End: | 0 | ||||||||||||||||||||||||
| 1297 | case Qt::Key_Home: never executed: case Qt::Key_Home: | 0 | ||||||||||||||||||||||||
| 1298 | if (ke->modifiers() & Qt::ControlModifier)
| 0 | ||||||||||||||||||||||||
| 1299 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 1300 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1301 | - | |||||||||||||||||||||||||
| 1302 | case Qt::Key_Up: never executed: case Qt::Key_Up: | 0 | ||||||||||||||||||||||||
| 1303 | if (!curIndex.isValid()) {
| 0 | ||||||||||||||||||||||||
| 1304 | int rowCount = d->proxy->rowCount(); | - | ||||||||||||||||||||||||
| 1305 | QModelIndex lastIndex = d->proxy->index(rowCount - 1, d->column); | - | ||||||||||||||||||||||||
| 1306 | d->setCurrentIndex(lastIndex); | - | ||||||||||||||||||||||||
| 1307 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 1308 | } else if (curIndex.row() == 0) {
| 0 | ||||||||||||||||||||||||
| 1309 | if (d->wrap)
| 0 | ||||||||||||||||||||||||
| 1310 | d->setCurrentIndex(QModelIndex()); never executed: d->setCurrentIndex(QModelIndex()); | 0 | ||||||||||||||||||||||||
| 1311 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 1312 | } | - | ||||||||||||||||||||||||
| 1313 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 1314 | - | |||||||||||||||||||||||||
| 1315 | case Qt::Key_Down: never executed: case Qt::Key_Down: | 0 | ||||||||||||||||||||||||
| 1316 | if (!curIndex.isValid()) {
| 0 | ||||||||||||||||||||||||
| 1317 | QModelIndex firstIndex = d->proxy->index(0, d->column); | - | ||||||||||||||||||||||||
| 1318 | d->setCurrentIndex(firstIndex); | - | ||||||||||||||||||||||||
| 1319 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 1320 | } else if (curIndex.row() == d->proxy->rowCount() - 1) {
| 0 | ||||||||||||||||||||||||
| 1321 | if (d->wrap)
| 0 | ||||||||||||||||||||||||
| 1322 | d->setCurrentIndex(QModelIndex()); never executed: d->setCurrentIndex(QModelIndex()); | 0 | ||||||||||||||||||||||||
| 1323 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 1324 | } | - | ||||||||||||||||||||||||
| 1325 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 1326 | - | |||||||||||||||||||||||||
| 1327 | case Qt::Key_PageUp: never executed: case Qt::Key_PageUp: | 0 | ||||||||||||||||||||||||
| 1328 | case Qt::Key_PageDown: never executed: case Qt::Key_PageDown: | 0 | ||||||||||||||||||||||||
| 1329 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 1330 | } | - | ||||||||||||||||||||||||
| 1331 | - | |||||||||||||||||||||||||
| 1332 | // Send the event to the widget. If the widget accepted the event, do nothing | - | ||||||||||||||||||||||||
| 1333 | // If the widget did not accept the event, provide a default implementation | - | ||||||||||||||||||||||||
| 1334 | d->eatFocusOut = false; | - | ||||||||||||||||||||||||
| 1335 | (static_cast<QObject *>(d->widget))->event(ke); | - | ||||||||||||||||||||||||
| 1336 | d->eatFocusOut = true; | - | ||||||||||||||||||||||||
| 1337 | if (!d->widget || e->isAccepted() || !d->popup->isVisible()) {
| 0 | ||||||||||||||||||||||||
| 1338 | // widget lost focus, hide the popup | - | ||||||||||||||||||||||||
| 1339 | if (d->widget && (!d->widget->hasFocus()
| 0 | ||||||||||||||||||||||||
| 1340 | #ifdef QT_KEYPAD_NAVIGATION
| 0 | ||||||||||||||||||||||||
| 1341 | || (QApplication::keypadNavigationEnabled() && !d->widget->hasEditFocus())
| 0 | ||||||||||||||||||||||||
| 1342 | #endif
| 0 | ||||||||||||||||||||||||
| 1343 | ))
| 0 | ||||||||||||||||||||||||
| 1344 | d->popup->hide(); never executed: d->popup->hide(); | 0 | ||||||||||||||||||||||||
| 1345 | if (e->isAccepted())
| 0 | ||||||||||||||||||||||||
| 1346 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 1347 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1348 | - | |||||||||||||||||||||||||
| 1349 | // default implementation for keys not handled by the widget when popup is open | - | ||||||||||||||||||||||||
| 1350 | if (ke->matches(QKeySequence::Cancel)) {
| 0 | ||||||||||||||||||||||||
| 1351 | d->popup->hide(); | - | ||||||||||||||||||||||||
| 1352 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 1353 | } | - | ||||||||||||||||||||||||
| 1354 | - | |||||||||||||||||||||||||
| 1355 | switch (key) { | - | ||||||||||||||||||||||||
| 1356 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||
| 1357 | case Qt::Key_Select: | - | ||||||||||||||||||||||||
| 1358 | if (!QApplication::keypadNavigationEnabled()) | - | ||||||||||||||||||||||||
| 1359 | break; | - | ||||||||||||||||||||||||
| 1360 | #endif | - | ||||||||||||||||||||||||
| 1361 | case Qt::Key_Return: never executed: case Qt::Key_Return: | 0 | ||||||||||||||||||||||||
| 1362 | case Qt::Key_Enter: never executed: case Qt::Key_Enter: | 0 | ||||||||||||||||||||||||
| 1363 | case Qt::Key_Tab: never executed: case Qt::Key_Tab: | 0 | ||||||||||||||||||||||||
| 1364 | d->popup->hide(); | - | ||||||||||||||||||||||||
| 1365 | if (curIndex.isValid())
| 0 | ||||||||||||||||||||||||
| 1366 | d->_q_complete(curIndex); never executed: d->_q_complete(curIndex); | 0 | ||||||||||||||||||||||||
| 1367 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1368 | - | |||||||||||||||||||||||||
| 1369 | case Qt::Key_F4: never executed: case Qt::Key_F4: | 0 | ||||||||||||||||||||||||
| 1370 | if (ke->modifiers() & Qt::AltModifier)
| 0 | ||||||||||||||||||||||||
| 1371 | d->popup->hide(); never executed: d->popup->hide(); | 0 | ||||||||||||||||||||||||
| 1372 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1373 | - | |||||||||||||||||||||||||
| 1374 | case Qt::Key_Backtab: never executed: case Qt::Key_Backtab: | 0 | ||||||||||||||||||||||||
| 1375 | d->popup->hide(); | - | ||||||||||||||||||||||||
| 1376 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1377 | - | |||||||||||||||||||||||||
| 1378 | default: never executed: default: | 0 | ||||||||||||||||||||||||
| 1379 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1380 | } | - | ||||||||||||||||||||||||
| 1381 | - | |||||||||||||||||||||||||
| 1382 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 1383 | } | - | ||||||||||||||||||||||||
| 1384 | - | |||||||||||||||||||||||||
| 1385 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||
| 1386 | case QEvent::KeyRelease: { | - | ||||||||||||||||||||||||
| 1387 | QKeyEvent *ke = static_cast<QKeyEvent *>(e); | - | ||||||||||||||||||||||||
| 1388 | if (QApplication::keypadNavigationEnabled() && ke->key() == Qt::Key_Back) { | - | ||||||||||||||||||||||||
| 1389 | // Send the event to the 'widget'. This is what we did for KeyPress, so we need | - | ||||||||||||||||||||||||
| 1390 | // to do the same for KeyRelease, in case the widget's KeyPress event set | - | ||||||||||||||||||||||||
| 1391 | // up something (such as a timer) that is relying on also receiving the | - | ||||||||||||||||||||||||
| 1392 | // key release. I see this as a bug in Qt, and should really set it up for all | - | ||||||||||||||||||||||||
| 1393 | // the affected keys. However, it is difficult to tell how this will affect | - | ||||||||||||||||||||||||
| 1394 | // existing code, and I can't test for every combination! | - | ||||||||||||||||||||||||
| 1395 | d->eatFocusOut = false; | - | ||||||||||||||||||||||||
| 1396 | static_cast<QObject *>(d->widget)->event(ke); | - | ||||||||||||||||||||||||
| 1397 | d->eatFocusOut = true; | - | ||||||||||||||||||||||||
| 1398 | } | - | ||||||||||||||||||||||||
| 1399 | break; | - | ||||||||||||||||||||||||
| 1400 | } | - | ||||||||||||||||||||||||
| 1401 | #endif | - | ||||||||||||||||||||||||
| 1402 | - | |||||||||||||||||||||||||
| 1403 | case QEvent::MouseButtonPress: { never executed: case QEvent::MouseButtonPress: | 0 | ||||||||||||||||||||||||
| 1404 | #ifdef QT_KEYPAD_NAVIGATION | - | ||||||||||||||||||||||||
| 1405 | if (QApplication::keypadNavigationEnabled()) { | - | ||||||||||||||||||||||||
| 1406 | // if we've clicked in the widget (or its descendant), let it handle the click | - | ||||||||||||||||||||||||
| 1407 | QWidget *source = qobject_cast<QWidget *>(o); | - | ||||||||||||||||||||||||
| 1408 | if (source) { | - | ||||||||||||||||||||||||
| 1409 | QPoint pos = source->mapToGlobal((static_cast<QMouseEvent *>(e))->pos()); | - | ||||||||||||||||||||||||
| 1410 | QWidget *target = QApplication::widgetAt(pos); | - | ||||||||||||||||||||||||
| 1411 | if (target && (d->widget->isAncestorOf(target) || | - | ||||||||||||||||||||||||
| 1412 | target == d->widget)) { | - | ||||||||||||||||||||||||
| 1413 | d->eatFocusOut = false; | - | ||||||||||||||||||||||||
| 1414 | static_cast<QObject *>(target)->event(e); | - | ||||||||||||||||||||||||
| 1415 | d->eatFocusOut = true; | - | ||||||||||||||||||||||||
| 1416 | return true; | - | ||||||||||||||||||||||||
| 1417 | } | - | ||||||||||||||||||||||||
| 1418 | } | - | ||||||||||||||||||||||||
| 1419 | } | - | ||||||||||||||||||||||||
| 1420 | #endif | - | ||||||||||||||||||||||||
| 1421 | if (!d->popup->underMouse()) {
| 0 | ||||||||||||||||||||||||
| 1422 | d->popup->hide(); | - | ||||||||||||||||||||||||
| 1423 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 1424 | } | - | ||||||||||||||||||||||||
| 1425 | } | - | ||||||||||||||||||||||||
| 1426 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 1427 | - | |||||||||||||||||||||||||
| 1428 | case QEvent::InputMethod: never executed: case QEvent::InputMethod: | 0 | ||||||||||||||||||||||||
| 1429 | case QEvent::ShortcutOverride: never executed: case QEvent::ShortcutOverride: | 0 | ||||||||||||||||||||||||
| 1430 | QApplication::sendEvent(d->widget, e); | - | ||||||||||||||||||||||||
| 1431 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1432 | - | |||||||||||||||||||||||||
| 1433 | default: never executed: default: | 0 | ||||||||||||||||||||||||
| 1434 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 1435 | } | - | ||||||||||||||||||||||||
| 1436 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 1437 | } | - | ||||||||||||||||||||||||
| 1438 | - | |||||||||||||||||||||||||
| 1439 | /*! | - | ||||||||||||||||||||||||
| 1440 | For QCompleter::PopupCompletion and QCompletion::UnfilteredPopupCompletion | - | ||||||||||||||||||||||||
| 1441 | modes, calling this function displays the popup displaying the current | - | ||||||||||||||||||||||||
| 1442 | completions. By default, if \a rect is not specified, the popup is displayed | - | ||||||||||||||||||||||||
| 1443 | on the bottom of the widget(). If \a rect is specified the popup is | - | ||||||||||||||||||||||||
| 1444 | displayed on the left edge of the rectangle. | - | ||||||||||||||||||||||||
| 1445 | - | |||||||||||||||||||||||||
| 1446 | For QCompleter::InlineCompletion mode, the highlighted() signal is fired | - | ||||||||||||||||||||||||
| 1447 | with the current completion. | - | ||||||||||||||||||||||||
| 1448 | */ | - | ||||||||||||||||||||||||
| 1449 | void QCompleter::complete(const QRect& rect) | - | ||||||||||||||||||||||||
| 1450 | { | - | ||||||||||||||||||||||||
| 1451 | Q_D(QCompleter); | - | ||||||||||||||||||||||||
| 1452 | QModelIndex idx = d->proxy->currentIndex(false); | - | ||||||||||||||||||||||||
| 1453 | d->hiddenBecauseNoMatch = false; | - | ||||||||||||||||||||||||
| 1454 | if (d->mode == QCompleter::InlineCompletion) {
| 0 | ||||||||||||||||||||||||
| 1455 | if (idx.isValid())
| 0 | ||||||||||||||||||||||||
| 1456 | d->_q_complete(idx, true); never executed: d->_q_complete(idx, true); | 0 | ||||||||||||||||||||||||
| 1457 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1458 | } | - | ||||||||||||||||||||||||
| 1459 | - | |||||||||||||||||||||||||
| 1460 | Q_ASSERT(d->widget != 0); | - | ||||||||||||||||||||||||
| 1461 | if ((d->mode == QCompleter::PopupCompletion && !idx.isValid())
| 0 | ||||||||||||||||||||||||
| 1462 | || (d->mode == QCompleter::UnfilteredPopupCompletion && d->proxy->rowCount() == 0)) {
| 0 | ||||||||||||||||||||||||
| 1463 | if (d->popup)
| 0 | ||||||||||||||||||||||||
| 1464 | d->popup->hide(); // no suggestion, hide never executed: d->popup->hide(); | 0 | ||||||||||||||||||||||||
| 1465 | d->hiddenBecauseNoMatch = true; | - | ||||||||||||||||||||||||
| 1466 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1467 | } | - | ||||||||||||||||||||||||
| 1468 | - | |||||||||||||||||||||||||
| 1469 | popup(); | - | ||||||||||||||||||||||||
| 1470 | if (d->mode == QCompleter::UnfilteredPopupCompletion)
| 0 | ||||||||||||||||||||||||
| 1471 | d->setCurrentIndex(idx, false); never executed: d->setCurrentIndex(idx, false); | 0 | ||||||||||||||||||||||||
| 1472 | - | |||||||||||||||||||||||||
| 1473 | d->showPopup(rect); | - | ||||||||||||||||||||||||
| 1474 | d->popupRect = rect; | - | ||||||||||||||||||||||||
| 1475 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1476 | - | |||||||||||||||||||||||||
| 1477 | /*! | - | ||||||||||||||||||||||||
| 1478 | Sets the current row to the \a row specified. Returns \c true if successful; | - | ||||||||||||||||||||||||
| 1479 | otherwise returns \c false. | - | ||||||||||||||||||||||||
| 1480 | - | |||||||||||||||||||||||||
| 1481 | This function may be used along with currentCompletion() to iterate | - | ||||||||||||||||||||||||
| 1482 | through all the possible completions. | - | ||||||||||||||||||||||||
| 1483 | - | |||||||||||||||||||||||||
| 1484 | \sa currentCompletion(), completionCount() | - | ||||||||||||||||||||||||
| 1485 | */ | - | ||||||||||||||||||||||||
| 1486 | bool QCompleter::setCurrentRow(int row) | - | ||||||||||||||||||||||||
| 1487 | { | - | ||||||||||||||||||||||||
| 1488 | Q_D(QCompleter); | - | ||||||||||||||||||||||||
| 1489 | return d->proxy->setCurrentRow(row); never executed: return d->proxy->setCurrentRow(row); | 0 | ||||||||||||||||||||||||
| 1490 | } | - | ||||||||||||||||||||||||
| 1491 | - | |||||||||||||||||||||||||
| 1492 | /*! | - | ||||||||||||||||||||||||
| 1493 | Returns the current row. | - | ||||||||||||||||||||||||
| 1494 | - | |||||||||||||||||||||||||
| 1495 | \sa setCurrentRow() | - | ||||||||||||||||||||||||
| 1496 | */ | - | ||||||||||||||||||||||||
| 1497 | int QCompleter::currentRow() const | - | ||||||||||||||||||||||||
| 1498 | { | - | ||||||||||||||||||||||||
| 1499 | Q_D(const QCompleter); | - | ||||||||||||||||||||||||
| 1500 | return d->proxy->currentRow(); never executed: return d->proxy->currentRow(); | 0 | ||||||||||||||||||||||||
| 1501 | } | - | ||||||||||||||||||||||||
| 1502 | - | |||||||||||||||||||||||||
| 1503 | /*! | - | ||||||||||||||||||||||||
| 1504 | Returns the number of completions for the current prefix. For an unsorted | - | ||||||||||||||||||||||||
| 1505 | model with a large number of items this can be expensive. Use setCurrentRow() | - | ||||||||||||||||||||||||
| 1506 | and currentCompletion() to iterate through all the completions. | - | ||||||||||||||||||||||||
| 1507 | */ | - | ||||||||||||||||||||||||
| 1508 | int QCompleter::completionCount() const | - | ||||||||||||||||||||||||
| 1509 | { | - | ||||||||||||||||||||||||
| 1510 | Q_D(const QCompleter); | - | ||||||||||||||||||||||||
| 1511 | return d->proxy->completionCount(); never executed: return d->proxy->completionCount(); | 0 | ||||||||||||||||||||||||
| 1512 | } | - | ||||||||||||||||||||||||
| 1513 | - | |||||||||||||||||||||||||
| 1514 | /*! | - | ||||||||||||||||||||||||
| 1515 | \enum QCompleter::ModelSorting | - | ||||||||||||||||||||||||
| 1516 | - | |||||||||||||||||||||||||
| 1517 | This enum specifies how the items in the model are sorted. | - | ||||||||||||||||||||||||
| 1518 | - | |||||||||||||||||||||||||
| 1519 | \value UnsortedModel The model is unsorted. | - | ||||||||||||||||||||||||
| 1520 | \value CaseSensitivelySortedModel The model is sorted case sensitively. | - | ||||||||||||||||||||||||
| 1521 | \value CaseInsensitivelySortedModel The model is sorted case insensitively. | - | ||||||||||||||||||||||||
| 1522 | - | |||||||||||||||||||||||||
| 1523 | \sa setModelSorting() | - | ||||||||||||||||||||||||
| 1524 | */ | - | ||||||||||||||||||||||||
| 1525 | - | |||||||||||||||||||||||||
| 1526 | /*! | - | ||||||||||||||||||||||||
| 1527 | \property QCompleter::modelSorting | - | ||||||||||||||||||||||||
| 1528 | \brief the way the model is sorted | - | ||||||||||||||||||||||||
| 1529 | - | |||||||||||||||||||||||||
| 1530 | By default, no assumptions are made about the order of the items | - | ||||||||||||||||||||||||
| 1531 | in the model that provides the completions. | - | ||||||||||||||||||||||||
| 1532 | - | |||||||||||||||||||||||||
| 1533 | If the model's data for the completionColumn() and completionRole() is sorted in | - | ||||||||||||||||||||||||
| 1534 | ascending order, you can set this property to \l CaseSensitivelySortedModel | - | ||||||||||||||||||||||||
| 1535 | or \l CaseInsensitivelySortedModel. On large models, this can lead to | - | ||||||||||||||||||||||||
| 1536 | significant performance improvements because the completer object can | - | ||||||||||||||||||||||||
| 1537 | then use a binary search algorithm instead of linear search algorithm. | - | ||||||||||||||||||||||||
| 1538 | - | |||||||||||||||||||||||||
| 1539 | The sort order (i.e ascending or descending order) of the model is determined | - | ||||||||||||||||||||||||
| 1540 | dynamically by inspecting the contents of the model. | - | ||||||||||||||||||||||||
| 1541 | - | |||||||||||||||||||||||||
| 1542 | \b{Note:} The performance improvements described above cannot take place | - | ||||||||||||||||||||||||
| 1543 | when the completer's \l caseSensitivity is different to the case sensitivity | - | ||||||||||||||||||||||||
| 1544 | used by the model's when sorting. | - | ||||||||||||||||||||||||
| 1545 | - | |||||||||||||||||||||||||
| 1546 | \sa setCaseSensitivity(), QCompleter::ModelSorting | - | ||||||||||||||||||||||||
| 1547 | */ | - | ||||||||||||||||||||||||
| 1548 | void QCompleter::setModelSorting(QCompleter::ModelSorting sorting) | - | ||||||||||||||||||||||||
| 1549 | { | - | ||||||||||||||||||||||||
| 1550 | Q_D(QCompleter); | - | ||||||||||||||||||||||||
| 1551 | if (d->sorting == sorting)
| 0 | ||||||||||||||||||||||||
| 1552 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1553 | d->sorting = sorting; | - | ||||||||||||||||||||||||
| 1554 | d->proxy->createEngine(); | - | ||||||||||||||||||||||||
| 1555 | d->proxy->invalidate(); | - | ||||||||||||||||||||||||
| 1556 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1557 | - | |||||||||||||||||||||||||
| 1558 | QCompleter::ModelSorting QCompleter::modelSorting() const | - | ||||||||||||||||||||||||
| 1559 | { | - | ||||||||||||||||||||||||
| 1560 | Q_D(const QCompleter); | - | ||||||||||||||||||||||||
| 1561 | return d->sorting; never executed: return d->sorting; | 0 | ||||||||||||||||||||||||
| 1562 | } | - | ||||||||||||||||||||||||
| 1563 | - | |||||||||||||||||||||||||
| 1564 | /*! | - | ||||||||||||||||||||||||
| 1565 | \property QCompleter::completionColumn | - | ||||||||||||||||||||||||
| 1566 | \brief the column in the model in which completions are searched for. | - | ||||||||||||||||||||||||
| 1567 | - | |||||||||||||||||||||||||
| 1568 | If the popup() is a QListView, it is automatically setup to display | - | ||||||||||||||||||||||||
| 1569 | this column. | - | ||||||||||||||||||||||||
| 1570 | - | |||||||||||||||||||||||||
| 1571 | By default, the match column is 0. | - | ||||||||||||||||||||||||
| 1572 | - | |||||||||||||||||||||||||
| 1573 | \sa completionRole, caseSensitivity | - | ||||||||||||||||||||||||
| 1574 | */ | - | ||||||||||||||||||||||||
| 1575 | void QCompleter::setCompletionColumn(int column) | - | ||||||||||||||||||||||||
| 1576 | { | - | ||||||||||||||||||||||||
| 1577 | Q_D(QCompleter); | - | ||||||||||||||||||||||||
| 1578 | if (d->column == column)
| 0 | ||||||||||||||||||||||||
| 1579 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1580 | #ifndef QT_NO_LISTVIEW | - | ||||||||||||||||||||||||
| 1581 | if (QListView *listView = qobject_cast<QListView *>(d->popup))
| 0 | ||||||||||||||||||||||||
| 1582 | listView->setModelColumn(column); never executed: listView->setModelColumn(column); | 0 | ||||||||||||||||||||||||
| 1583 | #endif | - | ||||||||||||||||||||||||
| 1584 | d->column = column; | - | ||||||||||||||||||||||||
| 1585 | d->proxy->invalidate(); | - | ||||||||||||||||||||||||
| 1586 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1587 | - | |||||||||||||||||||||||||
| 1588 | int QCompleter::completionColumn() const | - | ||||||||||||||||||||||||
| 1589 | { | - | ||||||||||||||||||||||||
| 1590 | Q_D(const QCompleter); | - | ||||||||||||||||||||||||
| 1591 | return d->column; never executed: return d->column; | 0 | ||||||||||||||||||||||||
| 1592 | } | - | ||||||||||||||||||||||||
| 1593 | - | |||||||||||||||||||||||||
| 1594 | /*! | - | ||||||||||||||||||||||||
| 1595 | \property QCompleter::completionRole | - | ||||||||||||||||||||||||
| 1596 | \brief the item role to be used to query the contents of items for matching. | - | ||||||||||||||||||||||||
| 1597 | - | |||||||||||||||||||||||||
| 1598 | The default role is Qt::EditRole. | - | ||||||||||||||||||||||||
| 1599 | - | |||||||||||||||||||||||||
| 1600 | \sa completionColumn, caseSensitivity | - | ||||||||||||||||||||||||
| 1601 | */ | - | ||||||||||||||||||||||||
| 1602 | void QCompleter::setCompletionRole(int role) | - | ||||||||||||||||||||||||
| 1603 | { | - | ||||||||||||||||||||||||
| 1604 | Q_D(QCompleter); | - | ||||||||||||||||||||||||
| 1605 | if (d->role == role)
| 0 | ||||||||||||||||||||||||
| 1606 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1607 | d->role = role; | - | ||||||||||||||||||||||||
| 1608 | d->proxy->invalidate(); | - | ||||||||||||||||||||||||
| 1609 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1610 | - | |||||||||||||||||||||||||
| 1611 | int QCompleter::completionRole() const | - | ||||||||||||||||||||||||
| 1612 | { | - | ||||||||||||||||||||||||
| 1613 | Q_D(const QCompleter); | - | ||||||||||||||||||||||||
| 1614 | return d->role; never executed: return d->role; | 0 | ||||||||||||||||||||||||
| 1615 | } | - | ||||||||||||||||||||||||
| 1616 | - | |||||||||||||||||||||||||
| 1617 | /*! | - | ||||||||||||||||||||||||
| 1618 | \property QCompleter::wrapAround | - | ||||||||||||||||||||||||
| 1619 | \brief the completions wrap around when navigating through items | - | ||||||||||||||||||||||||
| 1620 | \since 4.3 | - | ||||||||||||||||||||||||
| 1621 | - | |||||||||||||||||||||||||
| 1622 | The default is true. | - | ||||||||||||||||||||||||
| 1623 | */ | - | ||||||||||||||||||||||||
| 1624 | void QCompleter::setWrapAround(bool wrap) | - | ||||||||||||||||||||||||
| 1625 | { | - | ||||||||||||||||||||||||
| 1626 | Q_D(QCompleter); | - | ||||||||||||||||||||||||
| 1627 | if (d->wrap == wrap)
| 0 | ||||||||||||||||||||||||
| 1628 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1629 | d->wrap = wrap; | - | ||||||||||||||||||||||||
| 1630 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1631 | - | |||||||||||||||||||||||||
| 1632 | bool QCompleter::wrapAround() const | - | ||||||||||||||||||||||||
| 1633 | { | - | ||||||||||||||||||||||||
| 1634 | Q_D(const QCompleter); | - | ||||||||||||||||||||||||
| 1635 | return d->wrap; never executed: return d->wrap; | 0 | ||||||||||||||||||||||||
| 1636 | } | - | ||||||||||||||||||||||||
| 1637 | - | |||||||||||||||||||||||||
| 1638 | /*! | - | ||||||||||||||||||||||||
| 1639 | \property QCompleter::maxVisibleItems | - | ||||||||||||||||||||||||
| 1640 | \brief the maximum allowed size on screen of the completer, measured in items | - | ||||||||||||||||||||||||
| 1641 | \since 4.6 | - | ||||||||||||||||||||||||
| 1642 | - | |||||||||||||||||||||||||
| 1643 | By default, this property has a value of 7. | - | ||||||||||||||||||||||||
| 1644 | */ | - | ||||||||||||||||||||||||
| 1645 | int QCompleter::maxVisibleItems() const | - | ||||||||||||||||||||||||
| 1646 | { | - | ||||||||||||||||||||||||
| 1647 | Q_D(const QCompleter); | - | ||||||||||||||||||||||||
| 1648 | return d->maxVisibleItems; never executed: return d->maxVisibleItems; | 0 | ||||||||||||||||||||||||
| 1649 | } | - | ||||||||||||||||||||||||
| 1650 | - | |||||||||||||||||||||||||
| 1651 | void QCompleter::setMaxVisibleItems(int maxItems) | - | ||||||||||||||||||||||||
| 1652 | { | - | ||||||||||||||||||||||||
| 1653 | Q_D(QCompleter); | - | ||||||||||||||||||||||||
| 1654 | if (Q_UNLIKELY(maxItems < 0)) {
| 0 | ||||||||||||||||||||||||
| 1655 | qWarning("QCompleter::setMaxVisibleItems: " | - | ||||||||||||||||||||||||
| 1656 | "Invalid max visible items (%d) must be >= 0", maxItems); | - | ||||||||||||||||||||||||
| 1657 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1658 | } | - | ||||||||||||||||||||||||
| 1659 | d->maxVisibleItems = maxItems; | - | ||||||||||||||||||||||||
| 1660 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1661 | - | |||||||||||||||||||||||||
| 1662 | /*! | - | ||||||||||||||||||||||||
| 1663 | \property QCompleter::caseSensitivity | - | ||||||||||||||||||||||||
| 1664 | \brief the case sensitivity of the matching | - | ||||||||||||||||||||||||
| 1665 | - | |||||||||||||||||||||||||
| 1666 | The default is Qt::CaseSensitive. | - | ||||||||||||||||||||||||
| 1667 | - | |||||||||||||||||||||||||
| 1668 | \sa completionColumn, completionRole, modelSorting | - | ||||||||||||||||||||||||
| 1669 | */ | - | ||||||||||||||||||||||||
| 1670 | void QCompleter::setCaseSensitivity(Qt::CaseSensitivity cs) | - | ||||||||||||||||||||||||
| 1671 | { | - | ||||||||||||||||||||||||
| 1672 | Q_D(QCompleter); | - | ||||||||||||||||||||||||
| 1673 | if (d->cs == cs)
| 0 | ||||||||||||||||||||||||
| 1674 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1675 | d->cs = cs; | - | ||||||||||||||||||||||||
| 1676 | d->proxy->createEngine(); | - | ||||||||||||||||||||||||
| 1677 | d->proxy->invalidate(); | - | ||||||||||||||||||||||||
| 1678 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1679 | - | |||||||||||||||||||||||||
| 1680 | Qt::CaseSensitivity QCompleter::caseSensitivity() const | - | ||||||||||||||||||||||||
| 1681 | { | - | ||||||||||||||||||||||||
| 1682 | Q_D(const QCompleter); | - | ||||||||||||||||||||||||
| 1683 | return d->cs; never executed: return d->cs; | 0 | ||||||||||||||||||||||||
| 1684 | } | - | ||||||||||||||||||||||||
| 1685 | - | |||||||||||||||||||||||||
| 1686 | /*! | - | ||||||||||||||||||||||||
| 1687 | \property QCompleter::completionPrefix | - | ||||||||||||||||||||||||
| 1688 | \brief the completion prefix used to provide completions. | - | ||||||||||||||||||||||||
| 1689 | - | |||||||||||||||||||||||||
| 1690 | The completionModel() is updated to reflect the list of possible | - | ||||||||||||||||||||||||
| 1691 | matches for \a prefix. | - | ||||||||||||||||||||||||
| 1692 | */ | - | ||||||||||||||||||||||||
| 1693 | void QCompleter::setCompletionPrefix(const QString &prefix) | - | ||||||||||||||||||||||||
| 1694 | { | - | ||||||||||||||||||||||||
| 1695 | Q_D(QCompleter); | - | ||||||||||||||||||||||||
| 1696 | d->prefix = prefix; | - | ||||||||||||||||||||||||
| 1697 | d->proxy->filter(splitPath(prefix)); | - | ||||||||||||||||||||||||
| 1698 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1699 | - | |||||||||||||||||||||||||
| 1700 | QString QCompleter::completionPrefix() const | - | ||||||||||||||||||||||||
| 1701 | { | - | ||||||||||||||||||||||||
| 1702 | Q_D(const QCompleter); | - | ||||||||||||||||||||||||
| 1703 | return d->prefix; never executed: return d->prefix; | 0 | ||||||||||||||||||||||||
| 1704 | } | - | ||||||||||||||||||||||||
| 1705 | - | |||||||||||||||||||||||||
| 1706 | /*! | - | ||||||||||||||||||||||||
| 1707 | Returns the model index of the current completion in the completionModel(). | - | ||||||||||||||||||||||||
| 1708 | - | |||||||||||||||||||||||||
| 1709 | \sa setCurrentRow(), currentCompletion(), model() | - | ||||||||||||||||||||||||
| 1710 | */ | - | ||||||||||||||||||||||||
| 1711 | QModelIndex QCompleter::currentIndex() const | - | ||||||||||||||||||||||||
| 1712 | { | - | ||||||||||||||||||||||||
| 1713 | Q_D(const QCompleter); | - | ||||||||||||||||||||||||
| 1714 | return d->proxy->currentIndex(false); never executed: return d->proxy->currentIndex(false); | 0 | ||||||||||||||||||||||||
| 1715 | } | - | ||||||||||||||||||||||||
| 1716 | - | |||||||||||||||||||||||||
| 1717 | /*! | - | ||||||||||||||||||||||||
| 1718 | Returns the current completion string. This includes the \l completionPrefix. | - | ||||||||||||||||||||||||
| 1719 | When used alongside setCurrentRow(), it can be used to iterate through | - | ||||||||||||||||||||||||
| 1720 | all the matches. | - | ||||||||||||||||||||||||
| 1721 | - | |||||||||||||||||||||||||
| 1722 | \sa setCurrentRow(), currentIndex() | - | ||||||||||||||||||||||||
| 1723 | */ | - | ||||||||||||||||||||||||
| 1724 | QString QCompleter::currentCompletion() const | - | ||||||||||||||||||||||||
| 1725 | { | - | ||||||||||||||||||||||||
| 1726 | Q_D(const QCompleter); | - | ||||||||||||||||||||||||
| 1727 | return pathFromIndex(d->proxy->currentIndex(true)); never executed: return pathFromIndex(d->proxy->currentIndex(true)); | 0 | ||||||||||||||||||||||||
| 1728 | } | - | ||||||||||||||||||||||||
| 1729 | - | |||||||||||||||||||||||||
| 1730 | /*! | - | ||||||||||||||||||||||||
| 1731 | Returns the completion model. The completion model is a read-only list model | - | ||||||||||||||||||||||||
| 1732 | that contains all the possible matches for the current completion prefix. | - | ||||||||||||||||||||||||
| 1733 | The completion model is auto-updated to reflect the current completions. | - | ||||||||||||||||||||||||
| 1734 | - | |||||||||||||||||||||||||
| 1735 | \note The return value of this function is defined to be an QAbstractItemModel | - | ||||||||||||||||||||||||
| 1736 | purely for generality. This actual kind of model returned is an instance of an | - | ||||||||||||||||||||||||
| 1737 | QAbstractProxyModel subclass. | - | ||||||||||||||||||||||||
| 1738 | - | |||||||||||||||||||||||||
| 1739 | \sa completionPrefix, model() | - | ||||||||||||||||||||||||
| 1740 | */ | - | ||||||||||||||||||||||||
| 1741 | QAbstractItemModel *QCompleter::completionModel() const | - | ||||||||||||||||||||||||
| 1742 | { | - | ||||||||||||||||||||||||
| 1743 | Q_D(const QCompleter); | - | ||||||||||||||||||||||||
| 1744 | return d->proxy; never executed: return d->proxy; | 0 | ||||||||||||||||||||||||
| 1745 | } | - | ||||||||||||||||||||||||
| 1746 | - | |||||||||||||||||||||||||
| 1747 | /*! | - | ||||||||||||||||||||||||
| 1748 | Returns the path for the given \a index. The completer object uses this to | - | ||||||||||||||||||||||||
| 1749 | obtain the completion text from the underlying model. | - | ||||||||||||||||||||||||
| 1750 | - | |||||||||||||||||||||||||
| 1751 | The default implementation returns the \l{Qt::EditRole}{edit role} of the | - | ||||||||||||||||||||||||
| 1752 | item for list models. It returns the absolute file path if the model is a | - | ||||||||||||||||||||||||
| 1753 | QFileSystemModel. | - | ||||||||||||||||||||||||
| 1754 | - | |||||||||||||||||||||||||
| 1755 | \sa splitPath() | - | ||||||||||||||||||||||||
| 1756 | */ | - | ||||||||||||||||||||||||
| 1757 | - | |||||||||||||||||||||||||
| 1758 | QString QCompleter::pathFromIndex(const QModelIndex& index) const | - | ||||||||||||||||||||||||
| 1759 | { | - | ||||||||||||||||||||||||
| 1760 | Q_D(const QCompleter); | - | ||||||||||||||||||||||||
| 1761 | if (!index.isValid())
| 0 | ||||||||||||||||||||||||
| 1762 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||||||||
| 1763 | - | |||||||||||||||||||||||||
| 1764 | QAbstractItemModel *sourceModel = d->proxy->sourceModel(); | - | ||||||||||||||||||||||||
| 1765 | if (!sourceModel)
| 0 | ||||||||||||||||||||||||
| 1766 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||||||||
| 1767 | bool isDirModel = false; | - | ||||||||||||||||||||||||
| 1768 | bool isFsModel = false; | - | ||||||||||||||||||||||||
| 1769 | #ifndef QT_NO_DIRMODEL | - | ||||||||||||||||||||||||
| 1770 | isDirModel = qobject_cast<QDirModel *>(d->proxy->sourceModel()) != 0; | - | ||||||||||||||||||||||||
| 1771 | #endif | - | ||||||||||||||||||||||||
| 1772 | #ifndef QT_NO_FILESYSTEMMODEL | - | ||||||||||||||||||||||||
| 1773 | isFsModel = qobject_cast<QFileSystemModel *>(d->proxy->sourceModel()) != 0; | - | ||||||||||||||||||||||||
| 1774 | #endif | - | ||||||||||||||||||||||||
| 1775 | if (!isDirModel && !isFsModel)
| 0 | ||||||||||||||||||||||||
| 1776 | return sourceModel->data(index, d->role).toString(); never executed: return sourceModel->data(index, d->role).toString(); | 0 | ||||||||||||||||||||||||
| 1777 | - | |||||||||||||||||||||||||
| 1778 | QModelIndex idx = index; | - | ||||||||||||||||||||||||
| 1779 | QStringList list; | - | ||||||||||||||||||||||||
| 1780 | do { | - | ||||||||||||||||||||||||
| 1781 | QString t; | - | ||||||||||||||||||||||||
| 1782 | if (isDirModel)
| 0 | ||||||||||||||||||||||||
| 1783 | t = sourceModel->data(idx, Qt::EditRole).toString(); never executed: t = sourceModel->data(idx, Qt::EditRole).toString(); | 0 | ||||||||||||||||||||||||
| 1784 | #ifndef QT_NO_FILESYSTEMMODEL | - | ||||||||||||||||||||||||
| 1785 | else | - | ||||||||||||||||||||||||
| 1786 | t = sourceModel->data(idx, QFileSystemModel::FileNameRole).toString(); never executed: t = sourceModel->data(idx, QFileSystemModel::FileNameRole).toString(); | 0 | ||||||||||||||||||||||||
| 1787 | #endif | - | ||||||||||||||||||||||||
| 1788 | list.prepend(t); | - | ||||||||||||||||||||||||
| 1789 | QModelIndex parent = idx.parent(); | - | ||||||||||||||||||||||||
| 1790 | idx = parent.sibling(parent.row(), index.column()); | - | ||||||||||||||||||||||||
| 1791 | } while (idx.isValid()); never executed: end of block
| 0 | ||||||||||||||||||||||||
| 1792 | - | |||||||||||||||||||||||||
| 1793 | #if !defined(Q_OS_WIN) || defined(Q_OS_WINCE) | - | ||||||||||||||||||||||||
| 1794 | if (list.count() == 1) // only the separator or some other text
| 0 | ||||||||||||||||||||||||
| 1795 | return list[0]; never executed: return list[0]; | 0 | ||||||||||||||||||||||||
| 1796 | list[0].clear() ; // the join below will provide the separator | - | ||||||||||||||||||||||||
| 1797 | #endif | - | ||||||||||||||||||||||||
| 1798 | - | |||||||||||||||||||||||||
| 1799 | return list.join(QDir::separator()); never executed: return list.join(QDir::separator()); | 0 | ||||||||||||||||||||||||
| 1800 | } | - | ||||||||||||||||||||||||
| 1801 | - | |||||||||||||||||||||||||
| 1802 | /*! | - | ||||||||||||||||||||||||
| 1803 | Splits the given \a path into strings that are used to match at each level | - | ||||||||||||||||||||||||
| 1804 | in the model(). | - | ||||||||||||||||||||||||
| 1805 | - | |||||||||||||||||||||||||
| 1806 | The default implementation of splitPath() splits a file system path based on | - | ||||||||||||||||||||||||
| 1807 | QDir::separator() when the sourceModel() is a QFileSystemModel. | - | ||||||||||||||||||||||||
| 1808 | - | |||||||||||||||||||||||||
| 1809 | When used with list models, the first item in the returned list is used for | - | ||||||||||||||||||||||||
| 1810 | matching. | - | ||||||||||||||||||||||||
| 1811 | - | |||||||||||||||||||||||||
| 1812 | \sa pathFromIndex(), {Handling Tree Models} | - | ||||||||||||||||||||||||
| 1813 | */ | - | ||||||||||||||||||||||||
| 1814 | QStringList QCompleter::splitPath(const QString& path) const | - | ||||||||||||||||||||||||
| 1815 | { | - | ||||||||||||||||||||||||
| 1816 | bool isDirModel = false; | - | ||||||||||||||||||||||||
| 1817 | bool isFsModel = false; | - | ||||||||||||||||||||||||
| 1818 | #ifndef QT_NO_DIRMODEL | - | ||||||||||||||||||||||||
| 1819 | Q_D(const QCompleter); | - | ||||||||||||||||||||||||
| 1820 | isDirModel = qobject_cast<QDirModel *>(d->proxy->sourceModel()) != 0; | - | ||||||||||||||||||||||||
| 1821 | #endif | - | ||||||||||||||||||||||||
| 1822 | #ifndef QT_NO_FILESYSTEMMODEL | - | ||||||||||||||||||||||||
| 1823 | #ifdef QT_NO_DIRMODEL | - | ||||||||||||||||||||||||
| 1824 | Q_D(const QCompleter); | - | ||||||||||||||||||||||||
| 1825 | #endif | - | ||||||||||||||||||||||||
| 1826 | isFsModel = qobject_cast<QFileSystemModel *>(d->proxy->sourceModel()) != 0; | - | ||||||||||||||||||||||||
| 1827 | #endif | - | ||||||||||||||||||||||||
| 1828 | - | |||||||||||||||||||||||||
| 1829 | if ((!isDirModel && !isFsModel) || path.isEmpty())
| 0 | ||||||||||||||||||||||||
| 1830 | return QStringList(completionPrefix()); never executed: return QStringList(completionPrefix()); | 0 | ||||||||||||||||||||||||
| 1831 | - | |||||||||||||||||||||||||
| 1832 | QString pathCopy = QDir::toNativeSeparators(path); | - | ||||||||||||||||||||||||
| 1833 | #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) | - | ||||||||||||||||||||||||
| 1834 | if (pathCopy == QLatin1String("\\") || pathCopy == QLatin1String("\\\\")) | - | ||||||||||||||||||||||||
| 1835 | return QStringList(pathCopy); | - | ||||||||||||||||||||||||
| 1836 | const bool startsWithDoubleSlash = pathCopy.startsWith(QLatin1String("\\\\")); | - | ||||||||||||||||||||||||
| 1837 | if (startsWithDoubleSlash) | - | ||||||||||||||||||||||||
| 1838 | pathCopy = pathCopy.mid(2); | - | ||||||||||||||||||||||||
| 1839 | #endif | - | ||||||||||||||||||||||||
| 1840 | - | |||||||||||||||||||||||||
| 1841 | const QChar sep = QDir::separator(); | - | ||||||||||||||||||||||||
| 1842 | QStringList parts = pathCopy.split(sep); | - | ||||||||||||||||||||||||
| 1843 | - | |||||||||||||||||||||||||
| 1844 | #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) | - | ||||||||||||||||||||||||
| 1845 | if (startsWithDoubleSlash) | - | ||||||||||||||||||||||||
| 1846 | parts[0].prepend(QLatin1String("\\\\")); | - | ||||||||||||||||||||||||
| 1847 | #else | - | ||||||||||||||||||||||||
| 1848 | if (pathCopy[0] == sep) // readd the "/" at the beginning as the split removed it
| 0 | ||||||||||||||||||||||||
| 1849 | parts[0] = QLatin1Char('/'); never executed: parts[0] = QLatin1Char('/'); | 0 | ||||||||||||||||||||||||
| 1850 | #endif | - | ||||||||||||||||||||||||
| 1851 | - | |||||||||||||||||||||||||
| 1852 | return parts; never executed: return parts; | 0 | ||||||||||||||||||||||||
| 1853 | } | - | ||||||||||||||||||||||||
| 1854 | - | |||||||||||||||||||||||||
| 1855 | /*! | - | ||||||||||||||||||||||||
| 1856 | \fn void QCompleter::activated(const QModelIndex& index) | - | ||||||||||||||||||||||||
| 1857 | - | |||||||||||||||||||||||||
| 1858 | This signal is sent when an item in the popup() is activated by the user. | - | ||||||||||||||||||||||||
| 1859 | (by clicking or pressing return). The item's \a index in the completionModel() | - | ||||||||||||||||||||||||
| 1860 | is given. | - | ||||||||||||||||||||||||
| 1861 | - | |||||||||||||||||||||||||
| 1862 | */ | - | ||||||||||||||||||||||||
| 1863 | - | |||||||||||||||||||||||||
| 1864 | /*! | - | ||||||||||||||||||||||||
| 1865 | \fn void QCompleter::activated(const QString &text) | - | ||||||||||||||||||||||||
| 1866 | - | |||||||||||||||||||||||||
| 1867 | This signal is sent when an item in the popup() is activated by the user (by | - | ||||||||||||||||||||||||
| 1868 | clicking or pressing return). The item's \a text is given. | - | ||||||||||||||||||||||||
| 1869 | - | |||||||||||||||||||||||||
| 1870 | */ | - | ||||||||||||||||||||||||
| 1871 | - | |||||||||||||||||||||||||
| 1872 | /*! | - | ||||||||||||||||||||||||
| 1873 | \fn void QCompleter::highlighted(const QModelIndex& index) | - | ||||||||||||||||||||||||
| 1874 | - | |||||||||||||||||||||||||
| 1875 | This signal is sent when an item in the popup() is highlighted by | - | ||||||||||||||||||||||||
| 1876 | the user. It is also sent if complete() is called with the completionMode() | - | ||||||||||||||||||||||||
| 1877 | set to QCompleter::InlineCompletion. The item's \a index in the completionModel() | - | ||||||||||||||||||||||||
| 1878 | is given. | - | ||||||||||||||||||||||||
| 1879 | */ | - | ||||||||||||||||||||||||
| 1880 | - | |||||||||||||||||||||||||
| 1881 | /*! | - | ||||||||||||||||||||||||
| 1882 | \fn void QCompleter::highlighted(const QString &text) | - | ||||||||||||||||||||||||
| 1883 | - | |||||||||||||||||||||||||
| 1884 | This signal is sent when an item in the popup() is highlighted by | - | ||||||||||||||||||||||||
| 1885 | the user. It is also sent if complete() is called with the completionMode() | - | ||||||||||||||||||||||||
| 1886 | set to QCompleter::InlineCompletion. The item's \a text is given. | - | ||||||||||||||||||||||||
| 1887 | */ | - | ||||||||||||||||||||||||
| 1888 | - | |||||||||||||||||||||||||
| 1889 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
| 1890 | - | |||||||||||||||||||||||||
| 1891 | #include "moc_qcompleter.cpp" | - | ||||||||||||||||||||||||
| 1892 | - | |||||||||||||||||||||||||
| 1893 | #include "moc_qcompleter_p.cpp" | - | ||||||||||||||||||||||||
| 1894 | - | |||||||||||||||||||||||||
| 1895 | #endif // QT_NO_COMPLETER | - | ||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |