aboutsummaryrefslogtreecommitdiff
path: root/src/corelib/widgets/mcompleter.cpp
blob: 2f2abf7ad1dc36c16481a2147353b788e0b49b61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (directui@nokia.com)
**
** This file is part of libmeegotouch.
**
** If you have questions regarding the use of this file, please contact
** Nokia at directui@nokia.com.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

#include "mcompleter.h"
#include "mcompleter_p.h"
#include "mtextedit.h"
#include "mapplicationwindow.h"
#include "mscenemanager.h"
#include "mapplication.h"
#include "minputmethodstate.h"

#include <QDebug>
#include <QString>
#include <QTimer>
#include <QTextDocument>
#include <QAbstractItemModel>
#include <QStringListModel>

#include "mwidgetcreator.h"
M_REGISTER_WIDGET(MCompleter)

namespace
{
    //! default delimiters are comma and semicolon.
    const QString DefaultDelimiters(QString(",;") + QString(QChar::ObjectReplacementCharacter));
    //! default match regular expression
    const QString DefaultMatchRegularExpression("(%1.*)||(.*\\W%1.*)");
    //! default maximum hits is 10
    const int DefaultMaximumHits = 10;
    //! time interval for completer
    const int CompleterTimeInterval = 500;
}

MCompleterPrivate::MCompleterPrivate()
    : delimiters(DefaultDelimiters),
      hasOwnModel(false),
      completionModel(0),
      matchedModel(new MCompletionModel),
      completerTimer(new QTimer)
{
}

MCompleterPrivate::~MCompleterPrivate()
{
    delete matchedModel;
    delete completerTimer;
}

void MCompleterPrivate::init()
{
    Q_Q(MCompleter);
    q->model()->setMatchedModel(matchedModel);
    completerTimer->setInterval(CompleterTimeInterval);
    completerTimer->setSingleShot(true);

    bool connected = true;
    connected = q->connect(completerTimer, SIGNAL(timeout()),
                           q, SLOT(_q_complete()),
                           Qt::UniqueConnection) && connected;

    connected = q->connect(q, SIGNAL(confirmed(QString,QModelIndex)),
                           q, SIGNAL(confirmed(QString)),
                           Qt::UniqueConnection) && connected;

    connected = q->connect(q, SIGNAL(startCompleting(QString,QModelIndex)),
                           q, SIGNAL(startCompleting(QString)),
                           Qt::UniqueConnection) && connected;

    if (!connected) {
        qWarning("MCompleterPrivate::init() - Failed to connect signals!");
    }
}

void MCompleterPrivate::reset()
{
    Q_Q(MCompleter);
    if (q->model()->popupActive())
        return;
    q->model()->setCompletionPrefix("");
    q->model()->setMatchedIndex(-1);
    matchedIndexList.clear();
    matchedModel->setMatchedList(matchedIndexList);
    completerTimer->stop();
}

void MCompleterPrivate::fetchPrefix()
{
    Q_Q(MCompleter);
    q->model()->setCompletionPrefix("");

    QGraphicsScene *scene = 0;
    if (!q->widget())
        return;
    else
        scene = q->widget()->scene();

    if (!scene || q->widget() != scene->focusItem())
        return;

    // get surrounding text and cursor position
    QString text;
    int cursorPosition = -1;

    Qt::InputMethodQuery query = Qt::ImSurroundingText;
    QVariant queryResult = scene->inputMethodQuery(query);
    if (queryResult.isValid())
        text = queryResult.toString();
    query = Qt::ImCursorPosition;
    queryResult = scene->inputMethodQuery(query);
    if (queryResult.isValid())
        cursorPosition = queryResult.toInt();

    if (text.isEmpty() || cursorPosition == -1)
        return;

    QString prefix;
    //if not acceptMultipleEntries(), then don't give suggestions by setting an empty prefix
    if (!q->model()->acceptMultipleEntries()) {
        bool multiEntries = false;
        foreach(const QChar & c, delimiters) {
            if (text.indexOf(c) != -1) {
                multiEntries = true;
                break;
            }
        }
        if (!multiEntries)
            prefix = text;
    } else {
        // prefix is the text contains the cursor, and betweens delimiters.
        QString left, right;
        left = text.left(cursorPosition);
        right = text.mid(cursorPosition);
        int leftIndex = -1, rightIndex = right.length(), index = 0;
        foreach(const QChar & c, delimiters) {
            leftIndex = qMax(leftIndex, left.lastIndexOf(c));
            index = right.indexOf(c);
            if (index != -1)
                rightIndex = qMin(rightIndex, index);
        }
        leftIndex++;
        prefix = QString(left.mid(leftIndex) + right.left(rightIndex));
    }

    // trim for prefix
    QString trimSet = q->model()->charactersToTrimForCompletionPrefix();
    if (!prefix.isEmpty() && !trimSet.isEmpty()) {
        // trim left
        while (!prefix.isEmpty() && trimSet.contains(prefix.at(0))) {
            prefix = prefix.right(prefix.length() - 1);
        }
        // trim right
        while (!prefix.isEmpty() && trimSet.contains(prefix.at(prefix.length() - 1))) {
            prefix = prefix.left(prefix.length() - 1);
        }
    }

    q->model()->setCompletionPrefix(prefix);

    qDebug() << __PRETTY_FUNCTION__ << q->model()->completionPrefix();
}

void MCompleterPrivate::match(int maxHits)
{
    Q_Q(MCompleter);
    if (q->model()->completionPrefix().isEmpty())
        return;

    Qt::MatchFlags flags = Qt::MatchRegExp;
    //default match rule, the prefix should occur at the start, of just after one special character
    QString exp = QString(DefaultMatchRegularExpression).arg(q->model()->completionPrefix());
    QVariant var = QVariant(exp);

    matchedIndexList.clear();
    int row = 0;

    //all the columns are used to match
    QModelIndexList list;
    const int columnCount = completionModel->columnCount();
    for (int column = 0; column < columnCount; ++column) {
        list = completionModel->match(completionModel->index(row, column), Qt::DisplayRole, var, maxHits, flags);
        foreach(const QModelIndex & index, list) {
            if (!matchedIndexList.contains(index.row()))
                matchedIndexList << index.row();
        }
    }

    matchedModel->setMatchedList(matchedIndexList);
}

void MCompleterPrivate::_q_complete()
{
    Q_Q(MCompleter);
    if (!q->widget() || !q->widget()->scene())
        return;
    if (q->model()->popupActive() || (q->widget() != q->widget()->scene()->focusItem()))
        return;

    reset();
    fetchPrefix();
    if (q->model()->completionPrefix().isEmpty()) {
        //if no prefix, just reset and return
        if (q->isActive()) {
            reset();
            q->hideCompleter();
            resetFocus();
        }
        return;
    }

    emit q->startCompleting(q->model()->completionPrefix(),
                            completionModel->index(q->model()->matchedIndex(), q->valueColumnIndex()));
    pollModel(true);
}

QString MCompleterPrivate::trim(const QString &s)
{
    Q_Q(MCompleter);
    QString after = s;
    QString trimSet = q->model()->charactersToTrim();
    if (!trimSet.isEmpty()) {
        foreach(const QString & c, s) {
            if (trimSet.indexOf(c) == -1)
                break;
            else
                after = after.mid(1);
        }
        for (int i = after.length() - 1; i > 0; --i) {
            if (trimSet.indexOf(after[i]) == -1)
                break;
            else
                after = after.left(i);
        }
    }
    return after;
}

void MCompleterPrivate::setCompletionModel(QAbstractItemModel *m, bool own)
{
    Q_Q(MCompleter);
    if (m == completionModel)
        return;

    if (completionModel) {
        QObject::disconnect(completionModel, 0, q, 0);
    }
    if (hasOwnModel && completionModel) {
        matchedIndexList.clear();
        matchedModel->setSourceModel(0);
        delete completionModel;
    }

    completionModel = m;
    matchedModel->setSourceModel(completionModel);
    hasOwnModel = own;
    //default value column is the last column
    q->model()->setValueColumnIndex(completionModel->columnCount() - 1);
    QObject::connect(completionModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)),
                     q, SLOT(_q_pollModel()));
    QObject::connect(completionModel, SIGNAL(modelAboutToBeReset()),
                     q, SLOT(_q_modelAboutToBeReset()));
    QObject::connect(completionModel, SIGNAL(modelReset()),
                     q, SLOT(_q_pollModel()));
    QObject::connect(completionModel, SIGNAL(rowsInserted(QModelIndex, int, int)),
                     q, SLOT(_q_pollModel()));
    QObject::connect(completionModel, SIGNAL(rowsRemoved(QModelIndex, int, int)),
                     q, SLOT(_q_rowsRemoved(QModelIndex, int, int)));

    _q_modelUpdate();
}

void MCompleterPrivate::pollModel(bool isResetFocus)
{
    Q_Q(MCompleter);

    // TODO #1: remove check for one of those signals once they have been merged.
    // TODO #2: Change the "<= 1" back to "<= 0", because this is only needed for
    //          the current signal forwarding!
    if ((q->receivers(SIGNAL(startCompleting(QString))) <= 0) &&
        (q->receivers(SIGNAL(startCompleting(QString, QModelIndex))) <= 1)) {
        //if no customized match slot, then use default match rule
        //limit the max hits to DefaultMaximumHits + 1 (+1 allow it to be larger than DefaultMaximumHits)
        match(DefaultMaximumHits + 1);
    } else {
        //if customized, then think all items inside model are matched
        matchedIndexList.clear();
        const int rowCount = completionModel->rowCount();
        for (int i = 0; i < rowCount; ++i)
            matchedIndexList << i;
        matchedModel->setMatchedList(matchedIndexList);
    }
    updateScene(isResetFocus);
}

void MCompleterPrivate::updateScene(bool isResetFocus)
{
    Q_Q(MCompleter);

    if (matchedModel->rowCount() > 0) {
        q->model()->setMatchedIndex(0);
        q->model()->setActive(true);
        q->widget()->sceneManager()->appearSceneWindowNow(q);
        emit q->shown();
    } else if (q->isActive()) {
        reset();
        q->hideCompleter();
        if (isResetFocus)
            resetFocus();
    }
}

void MCompleterPrivate::_q_modelUpdate()
{
    Q_Q(MCompleter);
    if (!completionModel)
        return;
    matchedIndexList.clear();
    matchedModel->setMatchedList(matchedIndexList);
    if (q->isActive())
        pollModel(false);
}

void MCompleterPrivate::_q_pollModel()
{
    pollModel(false);
}

void MCompleterPrivate::_q_modelAboutToBeReset()
{
    Q_Q(MCompleter);
    reset();
    q->hideCompleter();
}

void MCompleterPrivate::_q_rowsRemoved(const QModelIndex& parent, int start, int end)
{
    Q_UNUSED(parent);
    Q_Q(MCompleter);
    if (start < 0 || end < 0 || start > end) {
        qDebug() << "[MCompleterPrivate::onRowsRemoved] Invalid parameters!";
        return;
    }

    for (int i = start; i <= end; i++) {
        for (QList<int>::iterator it = matchedIndexList.begin(); it != matchedIndexList.end(); ++it) {
            if (*it == i) {
                matchedIndexList.erase(it);
                break;
            }
        }
    }
    matchedModel->setMatchedList(matchedIndexList);
    if (q->isActive())
        updateScene(true);
}

void MCompleterPrivate::resetFocus()
{
    Q_Q(MCompleter);

    if (!q->widget() || !q->widget()->scene()) {
        return;
    }

    // set the focus back to text widget if really lose focus
    if (q->widget()->scene()->focusItem() != q->widget()) {
        q->widget()->scene()->setFocusItem(q->widget());
        MInputMethodState::requestSoftwareInputPanel();
    }
}

MCompleter::MCompleter()
    : MSceneWindow(new MCompleterPrivate, new MCompleterModel,
                     MSceneWindow::Completer, "default")
{
    Q_D(MCompleter);
    d->init();
}

MCompleter::MCompleter(const QStringList &completionCandidates)
    : MSceneWindow(new MCompleterPrivate, new MCompleterModel,
                     MSceneWindow::Completer, "default")
{
    Q_D(MCompleter);
    d->setCompletionModel(new QStringListModel(completionCandidates), true);
    d->init();
}

MCompleter::MCompleter(QAbstractItemModel *completionCandidates)
    : MSceneWindow(new MCompleterPrivate, new MCompleterModel,
                     MSceneWindow::Completer, "default")
{
    Q_D(MCompleter);
    d->setCompletionModel(completionCandidates);
    d->init();
}

MCompleter::~MCompleter()
{
}

QString MCompleter::completionPrefix() const
{
    return model()->completionPrefix();
}

void MCompleter::setCandidateSourceModel(QAbstractItemModel *model)
{
    Q_D(MCompleter);
    hideCompleter();
    d->setCompletionModel(model);
}

QAbstractItemModel *MCompleter::candidateSourceModel() const
{
    Q_D(const MCompleter);
    return d->completionModel;
}

QAbstractItemModel *MCompleter::matchedCandidateModel() const
{
    Q_D(const MCompleter);

    return d->matchedModel;
}

void MCompleter::hideCompleter()
{
    if (isActive()) {
        // change active state to false before really hidden to notify view
        // to do necessary clear.
        model()->setActive(false);
        widget()->sceneManager()->disappearSceneWindowNow(this);
        emit hidden();
    }
}

void MCompleter::setWidget(MWidget *widget)
{
    //verify whether the widget supports inputmethod
    if (!widget || !(widget->flags() && QGraphicsItem::ItemAcceptsInputMethod)) {
        qWarning() << __PRETTY_FUNCTION__ << ": invalid MWidget pointer!\nThe valid MWidget must \
support inputmethod (flags() with QGraphicsItem::ItemAcceptsInputMethod); \
respond to inputMethodQuery() for Qt::ImCursorPosition and Qt::ImSurroundingText; \
and insert the confirmed completion when receiving the signal confirmed().";
        return;
    }

    if (this->widget()) {
        this->widget()->removeEventFilter(this);
    }
    widget->installEventFilter(this);

    model()->setTextWidget(widget);
}

MWidget *MCompleter::widget()
{
    return model()->textWidget();
}

void MCompleter::setValueColumnIndex(int column)
{
    Q_D(MCompleter);
    if (column < 0 || column >= d->completionModel->columnCount())
        return;
    else
        model()->setValueColumnIndex(column);
}

int MCompleter::valueColumnIndex() const
{
    return model()->valueColumnIndex();
}

void MCompleter::complete()
{
    Q_D(MCompleter);
    d->completerTimer->start();
}

void MCompleter::confirm()
{
    Q_D(MCompleter);
    if (!widget() || !isActive())
        return;

    //fetch prefix again, ensure the prefix is not null
    d->fetchPrefix();
    if (model()->completionPrefix().isEmpty())
        return;

    if (model()->matchedIndex() >= 0 && model()->matchedIndex() < d->matchedModel->rowCount()) {
        //inform widget about confirmed string
        int row = 0;
        const int column = model()->valueColumnIndex();
        QString value;
        if (d->matchedIndexList.count() > model()->matchedIndex())
            row = d->matchedIndexList.at(model()->matchedIndex());
        QVariant var = d->completionModel->data(d->completionModel->index(row, column));
        if (var.isValid())
            value = var.toString();

        emit confirmed(d->trim(value), d->completionModel->index(row, column));

        d->reset();
        hideCompleter();
        d->resetFocus();
    }
}

bool MCompleter::acceptMultipleEntries() const
{
    return model()->acceptMultipleEntries();
}

void MCompleter::setAcceptMultipleEntries(bool enable)
{
    model()->setAcceptMultipleEntries(enable);
}

bool MCompleter::isActive() const
{
    return model()->active() || model()->popupActive();
}

void MCompleter::queryAll()
{
    Q_D(MCompleter);

    if (!widget() || !widget()->scene()) {
        return;
    }

    if (model()->popupActive() || (widget() != widget()->scene()->focusItem())) {
        return;
    }

    // TODO #1: remove check for one of those signals once they have been merged.
    // TODO #2: Change the "> 1" back to "> 0", because this is only needed for
    //          the current signal forwarding!
    if ((receivers(SIGNAL(startCompleting(QString))) > 0) ||
        (receivers(SIGNAL(startCompleting(QString, QModelIndex))) > 1)) {
        return;
    }

    d->reset();
    d->fetchPrefix();

    if (model()->completionPrefix().isEmpty()) {
        return;
    }

    //if no customized match slot, then use default match rule. -1 to query all.
    d->match(-1);
}

void MCompleter::appear(MWindow *window, MSceneWindow::DeletionPolicy policy)
{
    MSceneWindow::appear(window, policy);
    model()->setActive(true);
}

void MCompleter::appear(MSceneWindow::DeletionPolicy policy)
{
    appear(0, policy);
}

void MCompleter::disappear()
{
    MSceneWindow::disappear();
    model()->setActive(false);
}

bool MCompleter::eventFilter(QObject *object, QEvent *e)
{
    Q_D(MCompleter);
    bool eaten = false;
    if (model()->active() && object == widget()) {
        switch (e->type()) {
        case QEvent::GraphicsSceneMouseRelease:
            //User relocates the cursor by tapping the text entry will hide completer
            d->reset();
            hideCompleter();
            d->resetFocus();
            break;
        case QEvent::KeyPress: {
            QKeyEvent *key = static_cast<QKeyEvent *>(e);
            switch (key->key()) {
            case Qt::Key_Return:
                //Enter key will insert the top hit
                confirm();
                eaten = true;
                break;
            default:
                break;
            }
            break;
        }
        default:
            break;
        }
    }
    return eaten;
}

QString MCompleter::charactersToTrim() const
{
    return model()->charactersToTrim();
}

void MCompleter::setCharactersToTrim(const QString &set)
{
    return model()->setCharactersToTrim(set);
}

QString MCompleter::charactersToTrimForCompletionPrefix() const
{
    return model()->charactersToTrimForCompletionPrefix();
}

void MCompleter::setCharactersToTrimForCompletionPrefix(const QString &str)
{
    return model()->setCharactersToTrimForCompletionPrefix(str);
}

MCompletionModel::MCompletionModel(QObject *parent)
    : QAbstractProxyModel(parent)
{
}

void MCompletionModel::setMatchedList(const QList<int>& indexList)
{
    if (QAbstractProxyModel::sourceModel() && (indexList.count() <= QAbstractProxyModel::sourceModel()->rowCount())) {
        this->indexList = indexList;
        QAbstractProxyModel::endResetModel();
    }
}

void MCompletionModel::setSourceModel(QAbstractItemModel *source)
{
    bool hadModel = (QAbstractProxyModel::sourceModel() != 0);

    if (hadModel)
        QObject::disconnect(QAbstractProxyModel::sourceModel(), 0, this, 0);

    QAbstractProxyModel::setSourceModel(source);

    if (source)
        connect(source, SIGNAL(destroyed()), this, SLOT(modelDestroyed()));
}

QModelIndex MCompletionModel::index(int row, int column, const QModelIndex &parent) const
{
    return hasIndex(row, column, parent) ? createIndex(row, column, 0) : QModelIndex();
}

QModelIndex MCompletionModel::mapToSource(const QModelIndex &index) const
{
    if (!index.isValid() || index.row() >= indexList.count())
        return QModelIndex();

    return createIndex(indexList.at(index.row()), index.column());
}

QModelIndex MCompletionModel::mapFromSource(const QModelIndex &index) const
{
    if (!index.isValid() || !indexList.contains(index.row()))
        return QModelIndex();

    return createIndex(indexList.indexOf(index.row()), 0);
}

QVariant MCompletionModel::data(const QModelIndex &index, int role) const
{
    QVariant var;
    int row = index.row();
    int column = index.column();
    if (!QAbstractProxyModel::sourceModel() || (row < 0)
            || (row >= indexList.count()) || (column != 0))
        return var;

    var = QAbstractProxyModel::sourceModel()->data(mapToSource(index), role);
    if (role == Qt::DisplayRole) {
        QString value;
        const int columnCount = QAbstractProxyModel::sourceModel()->columnCount();
        for (column = 0; column < columnCount; ++column) {
            var = QAbstractProxyModel::sourceModel()->data(mapToSource(createIndex(row, column)), role);
            if (var.isValid()) {
                //space between columns
                if (column > 0)
                    value += ' ';
                value += var.toString();
            }
        }
        if (!value.isEmpty())
            var = QVariant(value);
    }
    return var;
}

int MCompletionModel::columnCount(const QModelIndex &) const
{
    //FIXME: Do we need to display more columns? Now MPopupList can only display one column.
    if (QAbstractProxyModel::sourceModel())
        return 1;
    else
        return 0;
}

int MCompletionModel::rowCount(const QModelIndex &) const
{
    if (QAbstractProxyModel::sourceModel())
        return indexList.count();
    else
        return 0;
}

QModelIndex MCompletionModel::parent(const QModelIndex &) const
{
    return QModelIndex();
}

void MCompletionModel::modelDestroyed()
{
    // switch to static empty model
    QAbstractProxyModel::setSourceModel(0);
}

#include "moc_mcompleter.cpp"