コード例 #1
0
/*
    ToolbarSearch is a search widget that also contains a small history
    and uses open-search for searching.
 */
ToolbarSearch::ToolbarSearch(QWidget *parent)
    : SearchLineEdit(parent)
    , m_suggestionsEnabled(true)
    , m_autosaver(new AutoSaver(this))
    , m_maxSavedSearches(10)
    , m_model(new QStandardItemModel(this))
    , m_suggestionsItem(0)
    , m_recentSearchesItem(0)
    , m_suggestTimer(0)
    , m_completer(0)
{
    connect(openSearchManager(), SIGNAL(currentEngineChanged()),
            this, SLOT(currentEngineChanged()));

    m_completer = new QCompleter(m_model, this);
    m_completer->setCompletionMode(QCompleter::UnfilteredPopupCompletion);
    setCompleter(m_completer);

    searchButton()->setShowMenuTriangle(true);

    connect(searchButton(), SIGNAL(clicked()),
            this, SLOT(showEnginesMenu()));
    connect(this, SIGNAL(returnPressed()),
            this, SLOT(searchNow()));

    load();

    currentEngineChanged();
}
コード例 #2
0
void tst_OpenSearchManager::setCurrentEngine()
{
    QFETCH(QString, name);
    QFETCH(QString, description);
    QFETCH(QString, searchUrlTemplate);
    QFETCH(bool, valid);

    SubOpenSearchManager manager;

    QCOMPARE(manager.enginesCount(), 1);

    QString oldCurrentEngineName = manager.currentEngineName();
    OpenSearchEngine *oldCurrentEngine = manager.currentEngine();

    QSignalSpy signalSpy(&manager, SIGNAL(currentEngineChanged()));

    OpenSearchEngine *engine = new OpenSearchEngine();
    engine->setName(name);
    engine->setDescription(description);
    engine->setSearchUrlTemplate(searchUrlTemplate);

    bool result = manager.addEngine(engine);
    QCOMPARE(result, valid);

    manager.setCurrentEngineName(name);
    QCOMPARE(manager.currentEngineName(), (valid ? name : oldCurrentEngineName));
    QCOMPARE(*manager.currentEngine(), (valid ? *engine : *oldCurrentEngine));
    QCOMPARE(signalSpy.count(), (valid ? 1 : 0));

    manager.removeEngine(engine->name());
    QCOMPARE(signalSpy.count(), (valid ? 2 : 0));
}