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/src/gui/util/qcompleter.cpp

    r172 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtGui module 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 have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    159159QCompletionModel::QCompletionModel(QCompleterPrivate *c, QObject *parent)
    160160    : QAbstractProxyModel(*new QCompletionModelPrivate, parent),
    161       c(c), engine(0), showAll(false)
     161      c(c), showAll(false)
    162162{
    163163    createEngine();
     
    209209    }
    210210
    211     delete engine;
    212211    if (sortedEngine)
    213         engine = new QSortedModelEngine(c);
     212        engine.reset(new QSortedModelEngine(c));
    214213    else
    215         engine = new QUnsortedModelEngine(c);
     214        engine.reset(new QUnsortedModelEngine(c));
    216215}
    217216
     
    483482        QString str = source->index(i, c->column).data().toString();
    484483        if (str.startsWith(c->prefix, c->cs)
    485 #if !defined(Q_OS_OS2) && (!defined(Q_OS_WIN) || defined(Q_OS_WINCE))
     484#if (!defined(Q_OS_WIN) || defined(Q_OS_WINCE)) && !defined(Q_OS_SYMBIAN) && !defined(Q_OS_OS2)
    486485            && (!dirModel || QDir::toNativeSeparators(str) != QDir::separator())
    487486#endif
     
    773772QCompleterPrivate::QCompleterPrivate()
    774773: widget(0), proxy(0), popup(0), cs(Qt::CaseSensitive), role(Qt::EditRole), column(0),
    775   sorting(QCompleter::UnsortedModel), wrap(true), eatFocusOut(true)
     774  maxVisibleItems(7), sorting(QCompleter::UnsortedModel), wrap(true), eatFocusOut(true)
    776775{
    777776}
     
    825824    QString completion;
    826825
    827     if (!index.isValid() || (index.row() >= proxy->engine->matchCount())) {
     826    if (!index.isValid() || (!proxy->showAll && (index.row() >= proxy->engine->matchCount()))) {
    828827        completion = prefix;
    829828    } else {
     829        if (!(index.flags() & Qt::ItemIsEnabled))
     830            return;
    830831        QModelIndex si = proxy->mapToSource(index);
    831832        si = si.sibling(si.row(), column); // for clicked()
     
    862863    QPoint pos;
    863864    int rw, rh, w;
    864     int h = (popup->sizeHintForRow(0) * qMin(7, popup->model()->rowCount()) + 3) + 3;
     865    int h = (popup->sizeHintForRow(0) * qMin(maxVisibleItems, popup->model()->rowCount()) + 3) + 3;
    865866    QScrollBar *hsb = popup->horizontalScrollBar();
    866867    if (hsb && hsb->isVisible())
     
    988989#ifndef QT_NO_DIRMODEL
    989990    if (qobject_cast<QDirModel *>(model)) {
    990 #if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_OS2)
     991#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_SYMBIAN) || defined(Q_OS_OS2)
    991992        setCaseSensitivity(Qt::CaseInsensitive);
    992993#else
     
    10781079    if (popup->model() != d->proxy)
    10791080        popup->setModel(d->proxy);
    1080     popup->hide();
    1081     popup->setParent(0, Qt::Popup);
    1082 
    1083     Qt::FocusPolicy origPolicy;
     1081#ifdef Q_OS_MAC
     1082     popup->show();
     1083#else
     1084     popup->hide();
     1085#endif
     1086
     1087    Qt::FocusPolicy origPolicy = Qt::NoFocus;
    10841088    if (d->widget)
    10851089        origPolicy = d->widget->focusPolicy();
     1090    popup->setParent(0, Qt::Popup);
    10861091    popup->setFocusPolicy(Qt::NoFocus);
    10871092    if (d->widget)
     
    10991104    QObject::connect(popup, SIGNAL(clicked(QModelIndex)),
    11001105                     this, SLOT(_q_complete(QModelIndex)));
    1101     QObject::connect(popup, SIGNAL(clicked(QModelIndex)), popup, SLOT(hide()));
     1106    QObject::connect(this, SIGNAL(activated(QModelIndex)),
     1107                     popup, SLOT(hide()));
    11021108
    11031109    QObject::connect(popup->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
     
    11791185            if (!curIndex.isValid()) {
    11801186                int rowCount = d->proxy->rowCount();
    1181                 QModelIndex lastIndex = d->proxy->index(rowCount - 1, 0);
     1187                QModelIndex lastIndex = d->proxy->index(rowCount - 1, d->column);
    11821188                d->setCurrentIndex(lastIndex);
    11831189                return true;
     
    11911197        case Qt::Key_Down:
    11921198            if (!curIndex.isValid()) {
    1193                 QModelIndex firstIndex = d->proxy->index(0, 0);
     1199                QModelIndex firstIndex = d->proxy->index(0, d->column);
    11941200                d->setCurrentIndex(firstIndex);
    11951201                return true;
     
    15071513
    15081514/*!
     1515    \property QCompleter::maxVisibleItems
     1516    \brief the maximum allowed size on screen of the completer, measured in items
     1517    \since 4.6
     1518
     1519    By default, this property has a value of 7.
     1520*/
     1521int QCompleter::maxVisibleItems() const
     1522{
     1523    Q_D(const QCompleter);
     1524    return d->maxVisibleItems;
     1525}
     1526
     1527void QCompleter::setMaxVisibleItems(int maxItems)
     1528{
     1529    Q_D(QCompleter);
     1530    if (maxItems < 0) {
     1531        qWarning("QCompleter::setMaxVisibleItems: "
     1532                 "Invalid max visible items (%d) must be >= 0", maxItems);
     1533        return;
     1534    }
     1535    d->maxVisibleItems = maxItems;
     1536}
     1537
     1538/*!
    15091539    \property QCompleter::caseSensitivity
    15101540    \brief the case sensitivity of the matching
     
    15781608    that contains all the possible matches for the current completion prefix.
    15791609    The completion model is auto-updated to reflect the current completions.
     1610
     1611    \note The return value of this function is defined to be an QAbstractItemModel
     1612    purely for generality. This actual kind of model returned is an instance of an
     1613    QAbstractProxyModel subclass.
    15801614
    15811615    \sa completionPrefix, model()
     
    16211655    } while (idx.isValid());
    16221656
    1623 #if !defined(Q_OS_OS2) && (!defined(Q_OS_WIN) || defined(Q_OS_WINCE))
     1657#if (!defined(Q_OS_WIN) || defined(Q_OS_WINCE)) && !defined(Q_OS_SYMBIAN) && !defined(Q_OS_OS2)
    16241658    if (list.count() == 1) // only the separator or some other text
    16251659        return list[0];
     
    16551689    QString pathCopy = QDir::toNativeSeparators(path);
    16561690    QString sep = QDir::separator();
    1657 #if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_OS2)
     1691#if defined(Q_OS_SYMBIAN)
     1692    if (pathCopy == QLatin1String("\\"))
     1693        return QStringList(pathCopy);
     1694#elif (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_OS2)
    16581695    if (pathCopy == QLatin1String("\\") || pathCopy == QLatin1String("\\\\"))
    16591696        return QStringList(pathCopy);
     
    16651702#endif
    16661703
    1667     QRegExp re(QLatin1String("[") + QRegExp::escape(sep) + QLatin1String("]"));
     1704    QRegExp re(QLatin1Char('[') + QRegExp::escape(sep) + QLatin1Char(']'));
    16681705    QStringList parts = pathCopy.split(re);
    16691706
    1670 #if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_OS2)
     1707#if defined(Q_OS_SYMBIAN)
     1708    // Do nothing
     1709#elif (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_OS2)
    16711710    if (!doubleSlash.isEmpty())
    16721711        parts[0].prepend(doubleSlash);
Note: See TracChangeset for help on using the changeset viewer.