Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/tools/assistant/lib/qhelpsearchquerywidget.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information ([email protected])
     4** All rights reserved.
     5** Contact: Nokia Corporation ([email protected])
    56**
    67** This file is part of the Qt Assistant of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you
     37** @nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    4444#include <QtCore/QDebug>
    4545
     46
    4647#include <QtCore/QObject>
    4748#include <QtCore/QStringList>
    48 
     49#include <QtCore/QtGlobal>
     50
     51#include <QtGui/QCompleter>
    4952#include <QtGui/QLabel>
    5053#include <QtGui/QLayout>
     
    6164
    6265private:
     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
    63103    QHelpSearchQueryWidgetPrivate()
    64         : QObject()
     104        : QObject(), simpleSearch(true),
     105          searchCompleter(new CompleterModel(this), this)
    65106    {
    66107        searchButton = 0;
     
    137178    }
    138179
     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
    139272private slots:
    140273    void showHideAdvancedSearch()
    141274    {
    142         bool hidden = advancedSearchWidget->isHidden();
    143         if (hidden) {
     275        if (simpleSearch) {
    144276            advancedSearchWidget->show();
    145277            showHideAdvancedSearchButton->setText((QLatin1String("-")));
     
    149281        }
    150282
    151         defaultQuery->setEnabled(!hidden);
     283        simpleSearch = !simpleSearch;
     284        defaultQuery->setEnabled(simpleSearch);
     285        enableOrDisableToolButtons();
     286    }
     287
     288    void searchRequested()
     289    {
     290        QList<QHelpSearchQuery> queryList;
     291#if !defined(QT_CLUCENE_SUPPORT)
     292        queryList.append(QHelpSearchQuery(QHelpSearchQuery::DEFAULT,
     293                                          QStringList(defaultQuery->text())));
     294
     295#else
     296        if (defaultQuery->isEnabled()) {
     297            queryList.append(QHelpSearchQuery(QHelpSearchQuery::DEFAULT,
     298                                              buildTermList(escapeString(defaultQuery->text()))));
     299        } else {
     300            const QRegExp exp(QLatin1String("\\s+"));
     301            QStringList lst = similarQuery->text().split(exp, QString::SkipEmptyParts);
     302            if (!lst.isEmpty()) {
     303                QStringList fuzzy;
     304                foreach (const QString term, lst)
     305                    fuzzy += buildTermList(escapeString(term));
     306                queryList.append(QHelpSearchQuery(QHelpSearchQuery::FUZZY, fuzzy));
     307            }
     308
     309            lst = withoutQuery->text().split(exp, QString::SkipEmptyParts);
     310            if (!lst.isEmpty()) {
     311                QStringList without;
     312                foreach (const QString term, lst)
     313                    without.append(escapeString(term));
     314                queryList.append(QHelpSearchQuery(QHelpSearchQuery::WITHOUT, without));
     315            }
     316
     317            if (!exactQuery->text().isEmpty()) {
     318                QString phrase = exactQuery->text().remove(QLatin1Char('\"'));
     319                phrase = escapeString(phrase.simplified());
     320                queryList.append(QHelpSearchQuery(QHelpSearchQuery::PHRASE, QStringList(phrase)));
     321            }
     322
     323            lst = allQuery->text().split(exp, QString::SkipEmptyParts);
     324            if (!lst.isEmpty()) {
     325                QStringList all;
     326                foreach (const QString term, lst)
     327                    all.append(escapeString(term));
     328                queryList.append(QHelpSearchQuery(QHelpSearchQuery::ALL, all));
     329            }
     330
     331            lst = atLeastQuery->text().split(exp, QString::SkipEmptyParts);
     332            if (!lst.isEmpty()) {
     333                QStringList atLeast;
     334                foreach (const QString term, lst)
     335                    atLeast += buildTermList(escapeString(term));
     336                queryList.append(QHelpSearchQuery(QHelpSearchQuery::ATLEAST, atLeast));
     337            }
     338        }
     339#endif
     340        QueryHistory &queryHist = simpleSearch ? simpleQueries : complexQueries;
     341        saveQuery(queryList, queryHist);
     342        queryHist.curQuery = queryHist.queries.size() - 1;
     343        if (queryHist.curQuery > 0)
     344            prevQueryButton->setEnabled(true);
     345        nextQueryButton->setEnabled(false);
     346    }
     347
     348    void nextQuery()
     349    {
     350        nextOrPrevQuery((simpleSearch ? simpleQueries : complexQueries).queries.size() - 1,
     351                        1, nextQueryButton, prevQueryButton);
     352    }
     353
     354    void prevQuery()
     355    {
     356        nextOrPrevQuery(0, -1, prevQueryButton, nextQueryButton);
    152357    }
    153358
     
    155360    friend class QHelpSearchQueryWidget;
    156361
     362
    157363    QPushButton *searchButton;
    158364    QWidget* advancedSearchWidget;
     
    164370    QLineEdit *allQuery;
    165371    QLineEdit *atLeastQuery;
     372
     373
     374
     375
     376
    166377};
    167378
     
    200411    QLabel *label = new QLabel(tr("Search for:"), this);
    201412    d->defaultQuery = new QLineEdit(this);
     413
     414
     415
     416
     417
     418
     419
     420
     421
    202422    d->searchButton = new QPushButton(tr("Search"), this);
    203423    hBoxLayout->addWidget(label);
    204424    hBoxLayout->addWidget(d->defaultQuery);
     425
     426
    205427    hBoxLayout->addWidget(d->searchButton);
    206428
    207429    vLayout->addLayout(hBoxLayout);
    208430
     431
     432
    209433    connect(d->searchButton, SIGNAL(clicked()), this, SIGNAL(search()));
    210434    connect(d->defaultQuery, SIGNAL(returnPressed()), this, SIGNAL(search()));
     
    237461    gLayout->addWidget(label, 0, 0);
    238462    d->similarQuery = new QLineEdit(this);
     463
    239464    gLayout->addWidget(d->similarQuery, 0, 1);
    240465
     
    242467    gLayout->addWidget(label, 1, 0);
    243468    d->withoutQuery = new QLineEdit(this);
     469
    244470    gLayout->addWidget(d->withoutQuery, 1, 1);
    245471
     
    247473    gLayout->addWidget(label, 2, 0);
    248474    d->exactQuery = new QLineEdit(this);
     475
    249476    gLayout->addWidget(d->exactQuery, 2, 1);
    250477
     
    252479    gLayout->addWidget(label, 3, 0);
    253480    d->allQuery = new QLineEdit(this);
     481
    254482    gLayout->addWidget(d->allQuery, 3, 1);
    255483
     
    257485    gLayout->addWidget(label, 4, 0);
    258486    d->atLeastQuery = new QLineEdit(this);
     487
    259488    gLayout->addWidget(d->atLeastQuery, 4, 1);
    260489
     
    270499        d, SLOT(showHideAdvancedSearch()));
    271500#endif
     501
    272502}
    273503
     
    286516QList<QHelpSearchQuery> QHelpSearchQueryWidget::query() const
    287517{
    288 #if !defined(QT_CLUCENE_SUPPORT)
    289     QList<QHelpSearchQuery> queryList;
    290     queryList.append(QHelpSearchQuery(QHelpSearchQuery::DEFAULT,
    291         QStringList(d->defaultQuery->text())));
    292 
    293     return queryList;
    294 #else
    295     QList<QHelpSearchQuery> queryList;
    296     if (d->defaultQuery->isEnabled()) {
    297         queryList.append(QHelpSearchQuery(QHelpSearchQuery::DEFAULT,
    298             d->buildTermList(d->escapeString(d->defaultQuery->text()))));
    299     } else {
    300         const QRegExp exp(QLatin1String("\\s+"));
    301         QStringList lst = d->similarQuery->text().split(exp, QString::SkipEmptyParts);
    302         if (!lst.isEmpty()) {
    303             QStringList fuzzy;
    304             foreach (const QString term, lst)
    305                 fuzzy += d->buildTermList(d->escapeString(term));
    306             queryList.append(QHelpSearchQuery(QHelpSearchQuery::FUZZY, fuzzy));
    307         }
    308 
    309         lst = d->withoutQuery->text().split(exp, QString::SkipEmptyParts);
    310         if (!lst.isEmpty()) {
    311             QStringList without;
    312             foreach (const QString term, lst)
    313                 without.append(d->escapeString(term));
    314             queryList.append(QHelpSearchQuery(QHelpSearchQuery::WITHOUT, without));
    315         }
    316 
    317         if (!d->exactQuery->text().isEmpty()) {
    318             QString phrase = d->exactQuery->text().remove(QLatin1Char('\"'));
    319             phrase = d->escapeString(phrase.simplified());
    320             queryList.append(QHelpSearchQuery(QHelpSearchQuery::PHRASE, QStringList(phrase)));
    321         }
    322 
    323         lst = d->allQuery->text().split(exp, QString::SkipEmptyParts);
    324         if (!lst.isEmpty()) {
    325             QStringList all;
    326             foreach (const QString term, lst)
    327                 all.append(d->escapeString(term));
    328             queryList.append(QHelpSearchQuery(QHelpSearchQuery::ALL, all));
    329         }
    330 
    331         lst = d->atLeastQuery->text().split(exp, QString::SkipEmptyParts);
    332         if (!lst.isEmpty()) {
    333             QStringList atLeast;
    334             foreach (const QString term, lst)
    335                 atLeast += d->buildTermList(d->escapeString(term));
    336             queryList.append(QHelpSearchQuery(QHelpSearchQuery::ATLEAST, atLeast));
    337         }
    338     }
    339     return queryList;
    340 #endif
     518    const QHelpSearchQueryWidgetPrivate::QueryHistory &queryHist =
     519        d->simpleSearch ? d->simpleQueries : d->complexQueries;
     520    return queryHist.queries.isEmpty() ?
     521        QList<QHelpSearchQuery>() : queryHist.queries.last();
    341522}
    342523
Note: See TracChangeset for help on using the changeset viewer.