Qt 4.8
Public Slots | Signals | Public Functions | Public Variables | List of all members
QCompletionModel Class Reference

#include <qcompleter_p.h>

Inheritance diagram for QCompletionModel:
QAbstractProxyModel QAbstractItemModel QObject

Public Slots

void invalidate ()
 
void modelDestroyed ()
 
void rowsInserted ()
 
- Public Slots inherited from QAbstractItemModel
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 

Signals

void rowsAdded ()
 
- Signals inherited from QAbstractItemModel
void columnsAboutToBeInserted (const QModelIndex &parent, int first, int last)
 This signal is emitted just before columns are inserted into the model. More...
 
void columnsAboutToBeMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn)
 This signal is emitted just before columns are moved within the model. More...
 
void columnsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
 This signal is emitted just before columns are removed from the model. More...
 
void columnsInserted (const QModelIndex &parent, int first, int last)
 This signal is emitted after columns have been inserted into the model. More...
 
void columnsMoved (const QModelIndex &parent, int start, int end, const QModelIndex &destination, int column)
 This signal is emitted after columns have been moved within the model. More...
 
void columnsRemoved (const QModelIndex &parent, int first, int last)
 This signal is emitted after columns have been removed from the model. More...
 
void dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight)
 This signal is emitted whenever the data in an existing item changes. More...
 
void headerDataChanged (Qt::Orientation orientation, int first, int last)
 This signal is emitted whenever a header is changed. More...
 
void layoutAboutToBeChanged ()
 This signal is emitted just before the layout of a model is changed. More...
 
void layoutChanged ()
 This signal is emitted whenever the layout of items exposed by the model has changed; for example, when the model has been sorted. More...
 
void modelAboutToBeReset ()
 This signal is emitted when reset() is called, before the model's internal state (e. More...
 
void modelReset ()
 This signal is emitted when reset() is called, after the model's internal state (e. More...
 
void rowsAboutToBeInserted (const QModelIndex &parent, int first, int last)
 This signal is emitted just before rows are inserted into the model. More...
 
void rowsAboutToBeMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
 This signal is emitted just before rows are moved within the model. More...
 
void rowsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
 This signal is emitted just before rows are removed from the model. More...
 
void rowsInserted (const QModelIndex &parent, int first, int last)
 This signal is emitted after rows have been inserted into the model. More...
 
void rowsMoved (const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row)
 This signal is emitted after rows have been moved within the model. More...
 
void rowsRemoved (const QModelIndex &parent, int first, int last)
 This signal is emitted after rows have been removed from the model. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

int columnCount (const QModelIndex &index=QModelIndex()) const
 Returns the number of columns for the children of the given parent. More...
 
int completionCount () const
 
void createEngine ()
 
QModelIndex currentIndex (bool) const
 
int currentRow () const
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const
 Reimplemented Function More...
 
void filter (const QStringList &parts)
 
bool hasChildren (const QModelIndex &parent=QModelIndex()) const
 Reimplemented Function More...
 
QModelIndex index (int row, int column, const QModelIndex &=QModelIndex()) const
 Returns the index of the item in the model specified by the given row, column and parent index. More...
 
QModelIndex mapFromSource (const QModelIndex &sourceIndex) const
 Reimplement this function to return the model index in the proxy model that corresponds to the sourceIndex from the source model. More...
 
QModelIndex mapToSource (const QModelIndex &proxyIndex) const
 Reimplement this function to return the model index in the source model that corresponds to the proxyIndex in the proxy model. More...
 
QModelIndex parent (const QModelIndex &=QModelIndex()) const
 Returns the parent of the model item with the given index. More...
 
 QCompletionModel (QCompleterPrivate *c, QObject *parent)
 
void resetModel ()
 
int rowCount (const QModelIndex &index=QModelIndex()) const
 Returns the number of rows under the given parent. More...
 
bool setCurrentRow (int row)
 
void setFiltered (bool)
 
void setSourceModel (QAbstractItemModel *sourceModel)
 Sets the given sourceModel to be processed by the proxy model. More...
 
- Public Functions inherited from QAbstractProxyModel
QModelIndex buddy (const QModelIndex &index) const
 Reimplemented Function More...
 
bool canFetchMore (const QModelIndex &parent) const
 Reimplemented Function More...
 
void fetchMore (const QModelIndex &parent)
 Reimplemented Function More...
 
Qt::ItemFlags flags (const QModelIndex &index) const
 Reimplemented Function More...
 
QVariant headerData (int section, Qt::Orientation orientation, int role) const
 Reimplemented Function More...
 
QMap< int, QVariantitemData (const QModelIndex &index) const
 Reimplemented Function More...
 
virtual QItemSelection mapSelectionFromSource (const QItemSelection &selection) const
 Returns a proxy selection mapped from the specified sourceSelection. More...
 
virtual QItemSelection mapSelectionToSource (const QItemSelection &selection) const
 Returns a source selection mapped from the specified proxySelection. More...
 
QMimeDatamimeData (const QModelIndexList &indexes) const
 Reimplemented Function More...
 
QStringList mimeTypes () const
 Reimplemented Function More...
 
 QAbstractProxyModel (QObject *parent=0)
 Constructs a proxy model with the given parent. More...
 
void revert ()
 Reimplemented Function More...
 
bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
 Reimplemented Function More...
 
bool setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole)
 Reimplemented Function More...
 
bool setItemData (const QModelIndex &index, const QMap< int, QVariant > &roles)
 Reimplemented Function More...
 
void sort (int column, Qt::SortOrder order=Qt::AscendingOrder)
 Reimplemented Function More...
 
QAbstractItemModelsourceModel () const
 Returns the model that contains the data that is available through the proxy model. More...
 
QSize span (const QModelIndex &index) const
 Reimplemented Function More...
 
bool submit ()
 Reimplemented Function More...
 
Qt::DropActions supportedDropActions () const
 Reimplemented Function More...
 
 ~QAbstractProxyModel ()
 Destroys the proxy model. More...
 
- Public Functions inherited from QAbstractItemModel
virtual bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
 Handles the data supplied by a drag and drop operation that ended with the given action. More...
 
bool hasIndex (int row, int column, const QModelIndex &parent=QModelIndex()) const
 Returns true if the model returns a valid QModelIndex for row and column with parent, otherwise returns false. More...
 
bool insertColumn (int column, const QModelIndex &parent=QModelIndex())
 Inserts a single column before the given column in the child items of the parent specified. More...
 
virtual bool insertColumns (int column, int count, const QModelIndex &parent=QModelIndex())
 On models that support this, inserts count new columns into the model before the given column. More...
 
bool insertRow (int row, const QModelIndex &parent=QModelIndex())
 Inserts a single row before the given row in the child items of the parent specified. More...
 
virtual bool insertRows (int row, int count, const QModelIndex &parent=QModelIndex())
 On models that support this, inserts count rows into the model before the given row. More...
 
virtual QModelIndexList match (const QModelIndex &start, int role, const QVariant &value, int hits=1, Qt::MatchFlags flags=Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const
 Returns a list of indexes for the items in the column of the start index where data stored under the given role matches the specified value. More...
 
 QAbstractItemModel (QObject *parent=0)
 Constructs an abstract item model with the given parent. More...
 
bool removeColumn (int column, const QModelIndex &parent=QModelIndex())
 Removes the given column from the child items of the parent specified. More...
 
virtual bool removeColumns (int column, int count, const QModelIndex &parent=QModelIndex())
 On models that support this, removes count columns starting with the given column under parent parent from the model. More...
 
bool removeRow (int row, const QModelIndex &parent=QModelIndex())
 Removes the given row from the child items of the parent specified. More...
 
virtual bool removeRows (int row, int count, const QModelIndex &parent=QModelIndex())
 On models that support this, removes count rows starting with the given row under parent parent from the model. More...
 
const QHash< int, QByteArray > & roleNames () const
 Returns the model's role names. More...
 
void setSupportedDragActions (Qt::DropActions)
 Sets the supported drag actions for the items in the model. More...
 
QModelIndex sibling (int row, int column, const QModelIndex &idx) const
 Returns the sibling at row and column for the item at index, or an invalid QModelIndex if there is no sibling at that location. More...
 
Qt::DropActions supportedDragActions () const
 Returns the actions supported by the data in this model. More...
 
virtual ~QAbstractItemModel ()
 Destroys the abstract item model. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Public Variables

QCompleterPrivatec
 
QScopedPointer< QCompletionEngineengine
 
bool showAll
 

Additional Inherited Members

- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Slots inherited from QAbstractItemModel
void resetInternalData ()
 This slot is called just after the internal data of a model is cleared while it is being reset. More...
 
- Protected Functions inherited from QAbstractProxyModel
 QAbstractProxyModel (QAbstractProxyModelPrivate &, QObject *parent)
 
- Protected Functions inherited from QAbstractItemModel
void beginInsertColumns (const QModelIndex &parent, int first, int last)
 Begins a column insertion operation. More...
 
void beginInsertRows (const QModelIndex &parent, int first, int last)
 Begins a row insertion operation. More...
 
bool beginMoveColumns (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationColumn)
 Begins a column move operation. More...
 
bool beginMoveRows (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationRow)
 Begins a row move operation. More...
 
void beginRemoveColumns (const QModelIndex &parent, int first, int last)
 Begins a column removal operation. More...
 
void beginRemoveRows (const QModelIndex &parent, int first, int last)
 Begins a row removal operation. More...
 
void beginResetModel ()
 Begins a model reset operation. More...
 
void changePersistentIndex (const QModelIndex &from, const QModelIndex &to)
 Changes the QPersistentModelIndex that is equal to the given from model index to the given to model index. More...
 
void changePersistentIndexList (const QModelIndexList &from, const QModelIndexList &to)
 Changes the QPersistentModelIndexes that is equal to the indexes in the given from model index list to the given to model index list. More...
 
QModelIndex createIndex (int row, int column, void *data=0) const
 Creates a model index for the given row and column with the internal pointer ptr. More...
 
QModelIndex createIndex (int row, int column, int id) const
 Use QModelIndex QAbstractItemModel::createIndex(int row, int column, quint32 id) instead. More...
 
QModelIndex createIndex (int row, int column, quint32 id) const
 Creates a model index for the given row and column with the internal identifier, id. More...
 
bool decodeData (int row, int column, const QModelIndex &parent, QDataStream &stream)
 
void encodeData (const QModelIndexList &indexes, QDataStream &stream) const
 
void endInsertColumns ()
 Ends a column insertion operation. More...
 
void endInsertRows ()
 Ends a row insertion operation. More...
 
void endMoveColumns ()
 Ends a column move operation. More...
 
void endMoveRows ()
 Ends a row move operation. More...
 
void endRemoveColumns ()
 Ends a column removal operation. More...
 
void endRemoveRows ()
 Ends a row removal operation. More...
 
void endResetModel ()
 Completes a model reset operation. More...
 
QModelIndexList persistentIndexList () const
 Returns the list of indexes stored as persistent indexes in the model. More...
 
 QAbstractItemModel (QAbstractItemModelPrivate &dd, QObject *parent=0)
 
void reset ()
 Resets the model to its original state in any attached views. More...
 
void setRoleNames (const QHash< int, QByteArray > &roleNames)
 Sets the model's role names to roleNames. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 213 of file qcompleter_p.h.

Constructors and Destructors

◆ QCompletionModel()

QCompletionModel::QCompletionModel ( QCompleterPrivate c,
QObject parent 
)

Definition at line 163 of file qcompleter.cpp.

165  c(c), showAll(false)
166 {
167  createEngine();
168 }
QCompleterPrivate * c
Definition: qcompleter_p.h:240
QAbstractProxyModel(QObject *parent=0)
Constructs a proxy model with the given parent.

Functions

◆ columnCount()

int QCompletionModel::columnCount ( const QModelIndex parent = QModelIndex()) const
virtual

Returns the number of columns for the children of the given parent.

In most subclasses, the number of columns is independent of the parent.

For example:

int DomModel::columnCount(const QModelIndex &/*parent*/) const
{
return 3;
}
Note
When implementing a table based model, columnCount() should return 0 when the parent is valid.
See also
rowCount()

Implements QAbstractItemModel.

Definition at line 170 of file qcompleter.cpp.

Referenced by index().

171 {
172  Q_D(const QCompletionModel);
173  return d->model->columnCount();
174 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ completionCount()

int QCompletionModel::completionCount ( ) const

Definition at line 338 of file qcompleter.cpp.

Referenced by rowCount().

339 {
340  if (!engine->matchCount())
341  return 0;
342 
344  return engine->matchCount();
345 }
virtual void filterOnDemand(int)
Definition: qcompleter_p.h:158
QScopedPointer< QCompletionEngine > engine
Definition: qcompleter_p.h:241
int matchCount() const
Definition: qcompleter_p.h:161
#define INT_MAX

◆ createEngine()

void QCompletionModel::createEngine ( )

Definition at line 200 of file qcompleter.cpp.

Referenced by QCompletionModel().

201 {
202  bool sortedEngine = false;
203  switch (c->sorting) {
205  sortedEngine = false;
206  break;
208  sortedEngine = c->cs == Qt::CaseSensitive;
209  break;
211  sortedEngine = c->cs == Qt::CaseInsensitive;
212  break;
213  }
214 
215  if (sortedEngine)
217  else
219 }
QCompleterPrivate * c
Definition: qcompleter_p.h:240
void reset(T *other=0)
Deletes the existing object it is pointing to if any, and sets its pointer to other.
QScopedPointer< QCompletionEngine > engine
Definition: qcompleter_p.h:241
Qt::CaseSensitivity cs
Definition: qcompleter_p.h:87
QCompleter::ModelSorting sorting
Definition: qcompleter_p.h:91

◆ currentIndex()

QModelIndex QCompletionModel::currentIndex ( bool  sourceIndex) const

Definition at line 299 of file qcompleter.cpp.

300 {
301  if (!engine->matchCount())
302  return QModelIndex();
303 
304  int row = engine->curRow;
305  if (showAll)
307 
308  QModelIndex idx = createIndex(row, c->column);
309  if (!sourceIndex)
310  return idx;
311  return mapToSource(idx);
312 }
QCompleterPrivate * c
Definition: qcompleter_p.h:240
QModelIndex createIndex(int row, int column, void *data=0) const
Creates a model index for the given row and column with the internal pointer ptr. ...
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Reimplement this function to return the model index in the source model that corresponds to the proxy...
Definition: qcompleter.cpp:221
QMatchData curMatch
Definition: qcompleter_p.h:163
The QModelIndex class is used to locate data in a data model.
QScopedPointer< QCompletionEngine > engine
Definition: qcompleter_p.h:241
int matchCount() const
Definition: qcompleter_p.h:161
QIndexMapper indices
Definition: qcompleter_p.h:135

◆ currentRow()

int QCompletionModel::currentRow ( ) const
inline

Definition at line 224 of file qcompleter_p.h.

224 { return engine->curRow; }
QScopedPointer< QCompletionEngine > engine
Definition: qcompleter_p.h:241

◆ data()

QVariant QCompletionModel::data ( const QModelIndex proxyIndex,
int  role = Qt::DisplayRole 
) const
virtual

Reimplemented Function

Reimplemented from QAbstractProxyModel.

Definition at line 387 of file qcompleter.cpp.

Referenced by QUnsortedModelEngine::buildIndices().

388 {
389  Q_D(const QCompletionModel);
390  return d->model->data(mapToSource(index), role);
391 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Reimplement this function to return the model index in the source model that corresponds to the proxy...
Definition: qcompleter.cpp:221
QModelIndex index(int row, int column, const QModelIndex &=QModelIndex()) const
Returns the index of the item in the model specified by the given row, column and parent index...
Definition: qcompleter.cpp:314

◆ filter()

void QCompletionModel::filter ( const QStringList parts)

Definition at line 411 of file qcompleter.cpp.

Referenced by QCompletionEngine::filter(), and invalidate().

412 {
414  engine->filter(parts);
415  resetModel();
416 
417  if (d->model->canFetchMore(engine->curParent))
418  d->model->fetchMore(engine->curParent);
419 }
double d
Definition: qnumeric_p.h:62
QModelIndex curParent
Definition: qcompleter_p.h:166
void filter(const QStringList &parts)
Definition: qcompleter.cpp:438
#define Q_D(Class)
Definition: qglobal.h:2482
QScopedPointer< QCompletionEngine > engine
Definition: qcompleter_p.h:241

◆ hasChildren()

bool QCompletionModel::hasChildren ( const QModelIndex parent = QModelIndex()) const
virtual

Reimplemented Function

Since
4.8

Reimplemented from QAbstractProxyModel.

Definition at line 372 of file qcompleter.cpp.

373 {
374  Q_D(const QCompletionModel);
375  if (parent.isValid())
376  return false;
377 
378  if (showAll)
379  return d->model->hasChildren(mapToSource(parent));
380 
381  if (!engine->matchCount())
382  return false;
383 
384  return true;
385 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Reimplement this function to return the model index in the source model that corresponds to the proxy...
Definition: qcompleter.cpp:221
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
QScopedPointer< QCompletionEngine > engine
Definition: qcompleter_p.h:241
int matchCount() const
Definition: qcompleter_p.h:161

◆ index()

QModelIndex QCompletionModel::index ( int  row,
int  column,
const QModelIndex parent = QModelIndex() 
) const
virtual

Returns the index of the item in the model specified by the given row, column and parent index.

When reimplementing this function in a subclass, call createIndex() to generate model indexes that other components can use to refer to items in your model.

See also
createIndex()

Implements QAbstractItemModel.

Definition at line 314 of file qcompleter.cpp.

315 {
316  Q_D(const QCompletionModel);
317  if (row < 0 || column < 0 || column >= columnCount(parent) || parent.isValid())
318  return QModelIndex();
319 
320  if (!showAll) {
321  if (!engine->matchCount())
322  return QModelIndex();
323  if (row >= engine->historyMatch.indices.count()) {
324  int want = row + 1 - engine->matchCount();
325  if (want > 0)
326  engine->filterOnDemand(want);
327  if (row >= engine->matchCount())
328  return QModelIndex();
329  }
330  } else {
331  if (row >= d->model->rowCount(engine->curParent))
332  return QModelIndex();
333  }
334 
335  return createIndex(row, column);
336 }
double d
Definition: qnumeric_p.h:62
QModelIndex curParent
Definition: qcompleter_p.h:166
QModelIndex createIndex(int row, int column, void *data=0) const
Creates a model index for the given row and column with the internal pointer ptr. ...
#define Q_D(Class)
Definition: qglobal.h:2482
int columnCount(const QModelIndex &index=QModelIndex()) const
Returns the number of columns for the children of the given parent.
Definition: qcompleter.cpp:170
virtual void filterOnDemand(int)
Definition: qcompleter_p.h:158
QMatchData historyMatch
Definition: qcompleter_p.h:163
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QModelIndex class is used to locate data in a data model.
QScopedPointer< QCompletionEngine > engine
Definition: qcompleter_p.h:241
int matchCount() const
Definition: qcompleter_p.h:161
QIndexMapper indices
Definition: qcompleter_p.h:135
int count() const
Definition: qcompleter_p.h:113

◆ invalidate

void QCompletionModel::invalidate ( )
slot

Definition at line 405 of file qcompleter.cpp.

Referenced by modelDestroyed(), rowsInserted(), and setSourceModel().

406 {
407  engine->cache.clear();
409 }
QStringList curParts
Definition: qcompleter_p.h:165
void filter(const QStringList &parts)
Definition: qcompleter.cpp:411
QScopedPointer< QCompletionEngine > engine
Definition: qcompleter_p.h:241
void clear()
Removes all items from the map.
Definition: qmap.h:444

◆ mapFromSource()

QModelIndex QCompletionModel::mapFromSource ( const QModelIndex sourceIndex) const
virtual

Reimplement this function to return the model index in the proxy model that corresponds to the sourceIndex from the source model.

See also
mapToSource()

Implements QAbstractProxyModel.

Definition at line 247 of file qcompleter.cpp.

248 {
249  if (!idx.isValid())
250  return QModelIndex();
251 
252  int row = -1;
253  if (!showAll) {
254  if (!engine->matchCount())
255  return QModelIndex();
256 
257  QIndexMapper& rootIndices = engine->historyMatch.indices;
258  if (idx.parent().isValid()) {
259  if (idx.parent() != engine->curParent)
260  return QModelIndex();
261  } else {
262  row = rootIndices.indexOf(idx.row());
263  if (row == -1 && engine->curParent.isValid())
264  return QModelIndex(); // source parent and our parent don't match
265  }
266 
267  if (row == -1) {
268  QIndexMapper& indices = engine->curMatch.indices;
269  engine->filterOnDemand(idx.row() - indices.last());
270  row = indices.indexOf(idx.row()) + rootIndices.count();
271  }
272 
273  if (row == -1)
274  return QModelIndex();
275  } else {
276  if (idx.parent() != engine->curParent)
277  return QModelIndex();
278  row = idx.row();
279  }
280 
281  return createIndex(row, idx.column());
282 }
QModelIndex curParent
Definition: qcompleter_p.h:166
QModelIndex createIndex(int row, int column, void *data=0) const
Creates a model index for the given row and column with the internal pointer ptr. ...
virtual void filterOnDemand(int)
Definition: qcompleter_p.h:158
QMatchData curMatch
Definition: qcompleter_p.h:163
int row() const
Returns the row this model index refers to.
int indexOf(int x) const
Definition: qcompleter_p.h:115
QMatchData historyMatch
Definition: qcompleter_p.h:163
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QModelIndex class is used to locate data in a data model.
int last() const
Definition: qcompleter_p.h:120
QScopedPointer< QCompletionEngine > engine
Definition: qcompleter_p.h:241
int matchCount() const
Definition: qcompleter_p.h:161
QIndexMapper indices
Definition: qcompleter_p.h:135
int count() const
Definition: qcompleter_p.h:113

◆ mapToSource()

QModelIndex QCompletionModel::mapToSource ( const QModelIndex proxyIndex) const
virtual

Reimplement this function to return the model index in the source model that corresponds to the proxyIndex in the proxy model.

See also
mapFromSource()

Implements QAbstractProxyModel.

Definition at line 221 of file qcompleter.cpp.

Referenced by QCompleterPrivate::_q_complete(), currentIndex(), data(), and hasChildren().

222 {
223  Q_D(const QCompletionModel);
224  if (!index.isValid())
225  return engine->curParent;
226 
227  int row;
229  if (!showAll) {
230  if (!engine->matchCount())
231  return QModelIndex();
233  QIndexMapper& rootIndices = engine->historyMatch.indices;
234  if (index.row() < rootIndices.count()) {
235  row = rootIndices[index.row()];
236  parent = QModelIndex();
237  } else {
238  row = engine->curMatch.indices[index.row() - rootIndices.count()];
239  }
240  } else {
241  row = index.row();
242  }
243 
244  return d->model->index(row, index.column(), parent);
245 }
double d
Definition: qnumeric_p.h:62
QModelIndex curParent
Definition: qcompleter_p.h:166
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
QModelIndex index(int row, int column, const QModelIndex &=QModelIndex()) const
Returns the index of the item in the model specified by the given row, column and parent index...
Definition: qcompleter.cpp:314
QMatchData curMatch
Definition: qcompleter_p.h:163
int row() const
Returns the row this model index refers to.
QMatchData historyMatch
Definition: qcompleter_p.h:163
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
The QModelIndex class is used to locate data in a data model.
if(void) toggleToolbarShown
QScopedPointer< QCompletionEngine > engine
Definition: qcompleter_p.h:241
int matchCount() const
Definition: qcompleter_p.h:161
QIndexMapper indices
Definition: qcompleter_p.h:135
int column() const
Returns the column this model index refers to.

◆ modelDestroyed

void QCompletionModel::modelDestroyed ( )
slot

Definition at line 393 of file qcompleter.cpp.

Referenced by setSourceModel().

394 {
395  QAbstractProxyModel::setSourceModel(0); // switch to static empty model
396  invalidate();
397 }
virtual void setSourceModel(QAbstractItemModel *sourceModel)
Sets the given sourceModel to be processed by the proxy model.

◆ parent()

QModelIndex QCompletionModel::parent ( const QModelIndex index = QModelIndex()) const
inlinevirtual

Returns the parent of the model item with the given index.

Warning
This function is not part of the public interface.

If the item has no parent, an invalid QModelIndex is returned.

A common convention used in models that expose tree data structures is that only items in the first column have children. For that case, when reimplementing this function in a subclass the column of the returned QModelIndex would be 0.

When reimplementing this function in a subclass, be careful to avoid calling QModelIndex member functions, such as QModelIndex::parent(), since indexes belonging to your model will simply call your implementation, leading to infinite recursion.

See also
createIndex()

Implements QAbstractItemModel.

Definition at line 233 of file qcompleter_p.h.

233 { return QModelIndex(); }
The QModelIndex class is used to locate data in a data model.

◆ resetModel()

void QCompletionModel::resetModel ( )

Definition at line 421 of file qcompleter.cpp.

Referenced by filter(), and setFiltered().

422 {
423  if (rowCount() == 0) {
424  reset();
425  return;
426  }
427 
430  QModelIndexList empty;
431  for (int i = 0; i < piList.size(); i++)
432  empty.append(QModelIndex());
433  changePersistentIndexList(piList, empty);
435 }
QModelIndexList persistentIndexList() const
Returns the list of indexes stored as persistent indexes in the model.
void changePersistentIndexList(const QModelIndexList &from, const QModelIndexList &to)
Changes the QPersistentModelIndexes that is equal to the indexes in the given from model index list t...
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
void layoutAboutToBeChanged()
This signal is emitted just before the layout of a model is changed.
#define emit
Definition: qobjectdefs.h:76
void layoutChanged()
This signal is emitted whenever the layout of items exposed by the model has changed; for example...
The QModelIndex class is used to locate data in a data model.
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
int rowCount(const QModelIndex &index=QModelIndex()) const
Returns the number of rows under the given parent.
Definition: qcompleter.cpp:347
void reset()
Resets the model to its original state in any attached views.

◆ rowCount()

int QCompletionModel::rowCount ( const QModelIndex parent = QModelIndex()) const
virtual

Returns the number of rows under the given parent.

When the parent is valid it means that rowCount is returning the number of children of parent.

Note
When implementing a table based model, rowCount() should return 0 when the parent is valid.
See also
columnCount()

Implements QAbstractItemModel.

Definition at line 347 of file qcompleter.cpp.

Referenced by resetModel(), and QSortedModelEngine::sortOrder().

348 {
349  Q_D(const QCompletionModel);
350  if (parent.isValid())
351  return 0;
352 
353  if (showAll) {
354  // Show all items below current parent, even if we have no valid matches
355  if (engine->curParts.count() != 1 && !engine->matchCount()
356  && !engine->curParent.isValid())
357  return 0;
358  return d->model->rowCount(engine->curParent);
359  }
360 
361  return completionCount();
362 }
double d
Definition: qnumeric_p.h:62
QModelIndex curParent
Definition: qcompleter_p.h:166
QStringList curParts
Definition: qcompleter_p.h:165
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
#define Q_D(Class)
Definition: qglobal.h:2482
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
QScopedPointer< QCompletionEngine > engine
Definition: qcompleter_p.h:241
int completionCount() const
Definition: qcompleter.cpp:338
int matchCount() const
Definition: qcompleter_p.h:161

◆ rowsAdded

void QCompletionModel::rowsAdded ( )
signal

Referenced by rowsInserted().

◆ rowsInserted

void QCompletionModel::rowsInserted ( )
slot

Definition at line 399 of file qcompleter.cpp.

Referenced by setSourceModel().

400 {
401  invalidate();
402  emit rowsAdded();
403 }
#define emit
Definition: qobjectdefs.h:76

◆ setCurrentRow()

bool QCompletionModel::setCurrentRow ( int  row)

Definition at line 284 of file qcompleter.cpp.

285 {
286  if (row < 0 || !engine->matchCount())
287  return false;
288 
289  if (row >= engine->matchCount())
290  engine->filterOnDemand(row + 1 - engine->matchCount());
291 
292  if (row >= engine->matchCount()) // invalid row
293  return false;
294 
295  engine->curRow = row;
296  return true;
297 }
virtual void filterOnDemand(int)
Definition: qcompleter_p.h:158
QScopedPointer< QCompletionEngine > engine
Definition: qcompleter_p.h:241
int matchCount() const
Definition: qcompleter_p.h:161

◆ setFiltered()

void QCompletionModel::setFiltered ( bool  filtered)

Definition at line 364 of file qcompleter.cpp.

365 {
366  if (showAll == !filtered)
367  return;
368  showAll = !filtered;
369  resetModel();
370 }
QFuture< T > filtered(const Sequence &sequence, FilterFunction filterFunction)

◆ setSourceModel()

void QCompletionModel::setSourceModel ( QAbstractItemModel sourceModel)
virtual

Sets the given sourceModel to be processed by the proxy model.

Reimplemented from QAbstractProxyModel.

Definition at line 176 of file qcompleter.cpp.

177 {
178  bool hadModel = (sourceModel() != 0);
179 
180  if (hadModel)
181  QObject::disconnect(sourceModel(), 0, this, 0);
182 
184 
185  if (source) {
186  // TODO: Optimize updates in the source model
187  connect(source, SIGNAL(modelReset()), this, SLOT(invalidate()));
188  connect(source, SIGNAL(destroyed()), this, SLOT(modelDestroyed()));
189  connect(source, SIGNAL(layoutChanged()), this, SLOT(invalidate()));
190  connect(source, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(rowsInserted()));
191  connect(source, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(invalidate()));
192  connect(source, SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(invalidate()));
193  connect(source, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(invalidate()));
195  }
196 
197  invalidate();
198 }
virtual void setSourceModel(QAbstractItemModel *sourceModel)
Sets the given sourceModel to be processed by the proxy model.
#define SLOT(a)
Definition: qobjectdefs.h:226
void columnsInserted(const QModelIndex &parent, int first, int last)
This signal is emitted after columns have been inserted into the model.
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void destroyed(QObject *=0)
This signal is emitted immediately before the object obj is destroyed, and can not be blocked...
QAbstractItemModel * sourceModel() const
Returns the model that contains the data that is available through the proxy model.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
void layoutChanged()
This signal is emitted whenever the layout of items exposed by the model has changed; for example...
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
The QModelIndex class is used to locate data in a data model.
void modelReset()
This signal is emitted when reset() is called, after the model&#39;s internal state (e.
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
This signal is emitted whenever the data in an existing item changes.
void rowsRemoved(const QModelIndex &parent, int first, int last)
This signal is emitted after rows have been removed from the model.
void columnsRemoved(const QModelIndex &parent, int first, int last)
This signal is emitted after columns have been removed from the model.

Properties

◆ c

QCompleterPrivate* QCompletionModel::c

◆ engine

QScopedPointer<QCompletionEngine> QCompletionModel::engine

◆ showAll

bool QCompletionModel::showAll

The documentation for this class was generated from the following files: