Exemple #1
0
void
Test_KCompletion::sortedOrder()
{
	KCompletion completion;
	completion.setSoundsEnabled(false);
	QSignalSpy spy1(&completion, SIGNAL(match(QString)));
	QSignalSpy spy3(&completion, SIGNAL(multipleMatches()));

	completion.setOrder(KCompletion::Sorted);
	QVERIFY(completion.order() == KCompletion::Sorted);

	completion.setItems(strings);
	QVERIFY(completion.items().count() == 4);

	completion.setCompletionMode(KGlobalSettings::CompletionShell);
	QCOMPARE(completion.makeCompletion("ca"), QString("carp"));
	QVERIFY(spy1.count() == 1);
	QCOMPARE(spy1.takeFirst().at(0).toString(), QString("carp"));
	QVERIFY(spy3.count() == 1); spy3.takeFirst();

	QSignalSpy spy2(&completion, SIGNAL(matches(QStringList)));
	completion.makeCompletion("ca");
	QCOMPARE(spy2.count(), 1);
	QVERIFY(spy3.count() == 0); // shouldn't be signaled on 2nd call

	QStringList matches = spy2.takeFirst().at(0).toStringList();
	QVERIFY(matches.count() == 2);
	QCOMPARE(matches[0], carp);
	QCOMPARE(matches[1], carpet);

	completion.setCompletionMode(KGlobalSettings::CompletionAuto);
	QCOMPARE(completion.makeCompletion("ca"), carp);
	QVERIFY(spy1.count() == 1);
	QCOMPARE(spy1.takeFirst().at(0).toString(), carp);
}
Exemple #2
0
QString OCompletion::makeCompletion( const QString& string )
{
    if ( myCompletionMode == OGlobalSettings::CompletionNone )
        return QString::null;

    //qDebug( "OCompletion: completing: %s", string );

    d->matches.clear();
    myRotationIndex = 0;
    myHasMultipleMatches = false;
    myLastMatch = myCurrentMatch;

    // in Shell-completion-mode, emit all matches when we get the same
    // complete-string twice
    if ( myCompletionMode == OGlobalSettings::CompletionShell &&
            string == myLastString ) {
        // Don't use d->matches since calling postProcessMatches()
        // on d->matches here would interfere with call to
        // postProcessMatch() during rotation

        findAllCompletions( string, &d->matches, myHasMultipleMatches );
        QStringList l = d->matches.list();
        postProcessMatches( &l );
        emit matches( l );

        if ( l.isEmpty() )
            doBeep( NoMatch );

        return QString::null;
    }

    QString completion;
    // in case-insensitive popup mode, we search all completions at once
    if ( myCompletionMode == OGlobalSettings::CompletionPopup ||
            myCompletionMode == OGlobalSettings::CompletionPopupAuto ) {
        findAllCompletions( string, &d->matches, myHasMultipleMatches );
        if ( !d->matches.isEmpty() )
            completion = d->matches.first();
    }
    else
        completion = findCompletion( string );

    if ( myHasMultipleMatches )
        emit multipleMatches();

    myLastString = string;
    myCurrentMatch = completion;

    postProcessMatch( &completion );

    if ( !string.isEmpty() ) { // only emit match when string != ""
        //qDebug( "OCompletion: Match: %s", completion );
        emit match( completion );
    }

    if ( completion.isNull() )
        doBeep( NoMatch );

    return completion;
}
void
Test_KCompletion::weightedOrder()
{
    KCompletion completion;
    completion.setSoundsEnabled(false);
    QSignalSpy spy1(&completion, SIGNAL(match(QString)));
    QSignalSpy spy3(&completion, SIGNAL(multipleMatches()));

    completion.setOrder(KCompletion::Weighted);
    QVERIFY(completion.order() == KCompletion::Weighted);

    completion.setItems(wstrings);
    QVERIFY(completion.items().count() == 4);

    completion.setCompletionMode(KCompletion::CompletionShell);
    QCOMPARE(completion.makeCompletion(QStringLiteral("ca")), QStringLiteral("carp"));
    spy1.takeFirst(); // empty the list
    QVERIFY(spy3.count() == 1); spy3.takeFirst();

    QSignalSpy spy2(&completion, SIGNAL(matches(QStringList)));
    completion.makeCompletion(QStringLiteral("ca"));
    QCOMPARE(spy2.count(), 1);
    QVERIFY(spy3.count() == 0); // shouldn't be signaled on 2nd call

    QStringList matches = spy2.takeFirst().at(0).toStringList();
    QVERIFY(matches.count() == 2);
    QCOMPARE(matches[0], carpet);
    QCOMPARE(matches[1], carp);

    completion.setCompletionMode(KCompletion::CompletionAuto);
    QCOMPARE(completion.makeCompletion(QStringLiteral("ca")), carpet);

    matches = completion.substringCompletion(QStringLiteral("ca"));
    QVERIFY(matches.count() == 3);
    QCOMPARE(matches[0], carpet);
    QCOMPARE(matches[1], coolcat);
    QCOMPARE(matches[2], carp);
}
Exemple #4
0
        disconnect(d->m_completion, SIGNAL(matches(const QStringList &)),
            this, SLOT(slotMatches(const QStringList &)));
        
        d->m_completion = 0;
        d->m_strings.clear();
        d->m_indexes.clear();
        d->m_reverseIndexes.clear();
    }
    
    d->m_completion = completion;
    
    connect(d->m_completion, SIGNAL(matches(const QStringList &)),
        this, SLOT(slotMatches(const QStringList &)));
    connect(d->m_completion, SIGNAL(match(const QString&)),
        this, SLOT(slotMatches()));
    connect(d->m_completion, SIGNAL(multipleMatches()),
        this, SLOT(slotMatches()));
    reset();
    
    // refill
    d->slotMatches();
}

QModelIndex KCompletionModel::index(int row, int column, const QModelIndex& parent) const
{   
    if (parent.isValid()) {
        return QModelIndex();
    }
    if (row < 0 || row >= d->m_strings.size() || column != 0) {
        return QModelIndex();
    }