qcompleter.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the QtGui module of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** Commercial Usage
00011 ** Licensees holding valid Qt Commercial licenses may use this file in
00012 ** accordance with the Qt Commercial License Agreement provided with the
00013 ** Software or, alternatively, in accordance with the terms contained in
00014 ** a written agreement between you and Nokia.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
00027 **
00028 ** GNU General Public License Usage
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 **
00036 ** If you have questions regarding the use of this file, please contact
00037 ** Nokia at qt-info@nokia.com.
00038 ** $QT_END_LICENSE$
00039 **
00040 ****************************************************************************/
00041 
00042 #ifndef QCOMPLETER_H
00043 #define QCOMPLETER_H
00044 
00045 #include <QtCore/qobject.h>
00046 #include <QtCore/qpoint.h>
00047 #include <QtCore/qstring.h>
00048 #include <QtCore/qabstractitemmodel.h>
00049 #include <QtCore/qrect.h>
00050 
00051 QT_BEGIN_HEADER
00052 
00053 QT_BEGIN_NAMESPACE
00054 
00055 QT_MODULE(Gui)
00056 
00057 #ifndef QT_NO_COMPLETER
00058 
00059 class QCompleterPrivate;
00060 class QAbstractItemView;
00061 class QAbstractProxyModel;
00062 class QWidget;
00063 
00064 class Q_GUI_EXPORT QCompleter : public QObject
00065 {
00066     Q_OBJECT
00067     Q_PROPERTY(QString completionPrefix READ completionPrefix WRITE setCompletionPrefix)
00068     Q_PROPERTY(ModelSorting modelSorting READ modelSorting WRITE setModelSorting)
00069     Q_PROPERTY(CompletionMode completionMode READ completionMode WRITE setCompletionMode)
00070     Q_PROPERTY(int completionColumn READ completionColumn WRITE setCompletionColumn)
00071     Q_PROPERTY(int completionRole READ completionRole WRITE setCompletionRole)
00072     Q_PROPERTY(int maxVisibleItems READ maxVisibleItems WRITE setMaxVisibleItems)
00073     Q_PROPERTY(Qt::CaseSensitivity caseSensitivity READ caseSensitivity WRITE setCaseSensitivity)
00074     Q_PROPERTY(bool wrapAround READ wrapAround WRITE setWrapAround)
00075 
00076 public:
00077     enum CompletionMode {
00078         PopupCompletion,
00079         UnfilteredPopupCompletion,
00080         InlineCompletion
00081     };
00082 
00083     enum ModelSorting {
00084         UnsortedModel = 0,
00085         CaseSensitivelySortedModel,
00086         CaseInsensitivelySortedModel
00087     };
00088 
00089     QCompleter(QObject *parent = 0);
00090     QCompleter(QAbstractItemModel *model, QObject *parent = 0);
00091 #ifndef QT_NO_STRINGLISTMODEL
00092     QCompleter(const QStringList& completions, QObject *parent = 0);
00093 #endif
00094     ~QCompleter();
00095 
00096     void setWidget(QWidget *widget);
00097     QWidget *widget() const;
00098 
00099     void setModel(QAbstractItemModel *c);
00100     QAbstractItemModel *model() const;
00101 
00102     void setCompletionMode(CompletionMode mode);
00103     CompletionMode completionMode() const;
00104 
00105     QAbstractItemView *popup() const;
00106     void setPopup(QAbstractItemView *popup);
00107 
00108     void setCaseSensitivity(Qt::CaseSensitivity caseSensitivity);
00109     Qt::CaseSensitivity caseSensitivity() const;
00110 
00111     void setModelSorting(ModelSorting sorting);
00112     ModelSorting modelSorting() const;
00113 
00114     void setCompletionColumn(int column);
00115     int  completionColumn() const;
00116 
00117     void setCompletionRole(int role);
00118     int  completionRole() const;
00119 
00120     bool wrapAround() const;
00121 
00122     int maxVisibleItems() const;
00123     void setMaxVisibleItems(int maxItems);
00124 
00125     int completionCount() const;
00126     bool setCurrentRow(int row);
00127     int currentRow() const;
00128 
00129     QModelIndex currentIndex() const;
00130     QString currentCompletion() const;
00131 
00132     QAbstractItemModel *completionModel() const;
00133 
00134     QString completionPrefix() const;
00135 
00136 public Q_SLOTS:
00137     void setCompletionPrefix(const QString &prefix);
00138     void complete(const QRect& rect = QRect());
00139     void setWrapAround(bool wrap);
00140 
00141 public:
00142     virtual QString pathFromIndex(const QModelIndex &index) const;
00143     virtual QStringList splitPath(const QString &path) const;
00144 
00145 protected:
00146     bool eventFilter(QObject *o, QEvent *e);
00147     bool event(QEvent *);
00148 
00149 Q_SIGNALS:
00150     void activated(const QString &text);
00151     void activated(const QModelIndex &index);
00152     void highlighted(const QString &text);
00153     void highlighted(const QModelIndex &index);
00154 
00155 private:
00156     Q_DISABLE_COPY(QCompleter)
00157     Q_DECLARE_PRIVATE(QCompleter)
00158 
00159     Q_PRIVATE_SLOT(d_func(), void _q_complete(QModelIndex))
00160     Q_PRIVATE_SLOT(d_func(), void _q_completionSelected(const QItemSelection&))
00161     Q_PRIVATE_SLOT(d_func(), void _q_autoResizePopup())
00162     Q_PRIVATE_SLOT(d_func(), void _q_fileSystemModelDirectoryLoaded(const QString&))
00163 };
00164 
00165 #endif // QT_NO_COMPLETER
00166 
00167 QT_END_NAMESPACE
00168 
00169 QT_END_HEADER
00170 
00171 #endif // QCOMPLETER_H