Qt 4.8
Public Functions | Private Functions | List of all members
QUnsortedModelEngine Class Reference

#include <qcompleter_p.h>

Inheritance diagram for QUnsortedModelEngine:
QCompletionEngine

Public Functions

QMatchData filter (const QString &, const QModelIndex &, int)
 
void filterOnDemand (int)
 
 QUnsortedModelEngine (QCompleterPrivate *c)
 
- Public Functions inherited from QCompletionEngine
void filter (const QStringList &parts)
 
QMatchData filterHistory ()
 
bool lookupCache (QString part, const QModelIndex &parent, QMatchData *m)
 
int matchCount () const
 
bool matchHint (QString, const QModelIndex &, QMatchData *)
 
 QCompletionEngine (QCompleterPrivate *c)
 
void saveInCache (QString, const QModelIndex &, const QMatchData &)
 
virtual ~QCompletionEngine ()
 

Private Functions

int buildIndices (const QString &str, const QModelIndex &parent, int n, const QIndexMapper &iv, QMatchData *m)
 

Additional Inherited Members

- Public Types inherited from QCompletionEngine
typedef QMap< QModelIndex, CacheItemCache
 
typedef QMap< QString, QMatchDataCacheItem
 
- Public Variables inherited from QCompletionEngine
QCompleterPrivatec
 
Cache cache
 
int cost
 
QMatchData curMatch
 
QModelIndex curParent
 
QStringList curParts
 
int curRow
 
QMatchData historyMatch
 

Detailed Description

Definition at line 182 of file qcompleter_p.h.

Constructors and Destructors

◆ QUnsortedModelEngine()

QUnsortedModelEngine::QUnsortedModelEngine ( QCompleterPrivate c)
inline

Definition at line 185 of file qcompleter_p.h.

185 : QCompletionEngine(c) { }
QCompletionEngine(QCompleterPrivate *c)
Definition: qcompleter_p.h:147

Functions

◆ buildIndices()

int QUnsortedModelEngine::buildIndices ( const QString str,
const QModelIndex parent,
int  n,
const QIndexMapper iv,
QMatchData m 
)
private

Definition at line 708 of file qcompleter.cpp.

710 {
711  Q_ASSERT(m->partial);
712  Q_ASSERT(n != -1 || m->exactMatchIndex == -1);
713  const QAbstractItemModel *model = c->proxy->sourceModel();
714  int i, count = 0;
715 
716  for (i = 0; i < indices.count() && count != n; ++i) {
717  QModelIndex idx = model->index(indices[i], c->column, parent);
718  QString data = model->data(idx, c->role).toString();
719  if (!data.startsWith(str, c->cs) || !(model->flags(idx) & Qt::ItemIsSelectable))
720  continue;
721  m->indices.append(indices[i]);
722  ++count;
723  if (m->exactMatchIndex == -1 && QString::compare(data, str, c->cs) == 0) {
724  m->exactMatchIndex = indices[i];
725  if (n == -1)
726  return indices[i];
727  }
728  }
729  return indices[i-1];
730 }
void append(int x)
Definition: qcompleter_p.h:118
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
The QString class provides a Unicode character string.
Definition: qstring.h:83
QCompleterPrivate * c
Definition: qcompleter_p.h:164
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index.
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const =0
Returns the index of the item in the model specified by the given row, column and parent index...
QAbstractItemModel * sourceModel() const
Returns the model that contains the data that is available through the proxy model.
static const char * data(const QByteArray &arr)
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const =0
Returns the data stored under the given role for the item referred to by the index.
The QAbstractItemModel class provides the abstract interface for item model classes.
int exactMatchIndex
Definition: qcompleter_p.h:137
int compare(const QString &s) const
Definition: qstring.cpp:5037
The QModelIndex class is used to locate data in a data model.
QCompletionModel * proxy
Definition: qcompleter_p.h:82
Qt::CaseSensitivity cs
Definition: qcompleter_p.h:87
QIndexMapper indices
Definition: qcompleter_p.h:135

◆ filter()

QMatchData QUnsortedModelEngine::filter ( const QString part,
const QModelIndex parent,
int  n 
)
virtual

Implements QCompletionEngine.

Definition at line 746 of file qcompleter.cpp.

747 {
748  QMatchData hint;
749 
750  QVector<int> v;
751  QIndexMapper im(v);
752  QMatchData m(im, -1, true);
753 
754  const QAbstractItemModel *model = c->proxy->sourceModel();
755  bool foundInCache = lookupCache(part, parent, &m);
756 
757  if (!foundInCache) {
758  if (matchHint(part, parent, &hint) && !hint.isValid())
759  return QMatchData();
760  }
761 
762  if (!foundInCache && !hint.isValid()) {
763  const int lastRow = model->rowCount(parent) - 1;
764  QIndexMapper all(0, lastRow);
765  int lastIndex = buildIndices(part, parent, n, all, &m);
766  m.partial = (lastIndex != lastRow);
767  } else {
768  if (!foundInCache) { // build from hint as much as we can
769  buildIndices(part, parent, INT_MAX, hint.indices, &m);
770  m.partial = hint.partial;
771  }
772  if (m.partial && ((n == -1 && m.exactMatchIndex == -1) || (m.indices.count() < n))) {
773  // need more and have more
774  const int lastRow = model->rowCount(parent) - 1;
775  QIndexMapper rest(hint.indices.last() + 1, lastRow);
776  int want = n == -1 ? -1 : n - m.indices.count();
777  int lastIndex = buildIndices(part, parent, want, rest, &m);
778  m.partial = (lastRow != lastIndex);
779  }
780  }
781 
782  saveInCache(part, parent, m);
783  return m;
784 }
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of rows under the given parent.
QCompleterPrivate * c
Definition: qcompleter_p.h:164
bool matchHint(QString, const QModelIndex &, QMatchData *)
Definition: qcompleter.cpp:504
bool isValid() const
Definition: qcompleter_p.h:136
QAbstractItemModel * sourceModel() const
Returns the model that contains the data that is available through the proxy model.
The QAbstractItemModel class provides the abstract interface for item model classes.
void saveInCache(QString, const QModelIndex &, const QMatchData &)
Definition: qcompleter.cpp:535
int last() const
Definition: qcompleter_p.h:120
QCompletionModel * proxy
Definition: qcompleter_p.h:82
int buildIndices(const QString &str, const QModelIndex &parent, int n, const QIndexMapper &iv, QMatchData *m)
Definition: qcompleter.cpp:708
QIndexMapper indices
Definition: qcompleter_p.h:135
#define INT_MAX
int count() const
Definition: qcompleter_p.h:113
bool lookupCache(QString part, const QModelIndex &parent, QMatchData *m)
Definition: qcompleter.cpp:523

◆ filterOnDemand()

void QUnsortedModelEngine::filterOnDemand ( int  n)
virtual

Reimplemented from QCompletionEngine.

Definition at line 732 of file qcompleter.cpp.

733 {
734  Q_ASSERT(matchCount());
735  if (!curMatch.partial)
736  return;
737  Q_ASSERT(n >= -1);
738  const QAbstractItemModel *model = c->proxy->sourceModel();
739  int lastRow = model->rowCount(curParent) - 1;
740  QIndexMapper im(curMatch.indices.last() + 1, lastRow);
741  int lastIndex = buildIndices(curParts.last(), curParent, n, im, &curMatch);
742  curMatch.partial = (lastRow != lastIndex);
744 }
QModelIndex curParent
Definition: qcompleter_p.h:166
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of rows under the given parent.
QStringList curParts
Definition: qcompleter_p.h:165
QCompleterPrivate * c
Definition: qcompleter_p.h:164
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QAbstractItemModel * sourceModel() const
Returns the model that contains the data that is available through the proxy model.
QMatchData curMatch
Definition: qcompleter_p.h:163
The QAbstractItemModel class provides the abstract interface for item model classes.
void saveInCache(QString, const QModelIndex &, const QMatchData &)
Definition: qcompleter.cpp:535
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
int last() const
Definition: qcompleter_p.h:120
QCompletionModel * proxy
Definition: qcompleter_p.h:82
int buildIndices(const QString &str, const QModelIndex &parent, int n, const QIndexMapper &iv, QMatchData *m)
Definition: qcompleter.cpp:708
int matchCount() const
Definition: qcompleter_p.h:161
QIndexMapper indices
Definition: qcompleter_p.h:135

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