source: trunk/src/gui/util/qcompleter_p.h@ 750

Last change on this file since 750 was 651, checked in by Dmitry A. Kuminov, 16 years ago

trunk: Merged in qt 4.6.2 sources.

File size: 8.2 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtGui module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
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.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QCOMPLETER_P_H
43#define QCOMPLETER_P_H
44
45
46//
47// W A R N I N G
48// -------------
49//
50// This file is not part of the Qt API. It exists purely as an
51// implementation detail. This header file may change from version to
52// version without notice, or even be removed.
53//
54// We mean it.
55//
56
57#include "private/qobject_p.h"
58
59#ifndef QT_NO_COMPLETER
60
61#include "QtGui/qtreeview.h"
62#include "QtGui/qabstractproxymodel.h"
63#include "qcompleter.h"
64#include "QtGui/qitemdelegate.h"
65#include "QtGui/qpainter.h"
66#include "private/qabstractproxymodel_p.h"
67
68QT_BEGIN_NAMESPACE
69
70class QCompletionModel;
71
72class QCompleterPrivate : public QObjectPrivate
73{
74 Q_DECLARE_PUBLIC(QCompleter)
75
76public:
77 QCompleterPrivate();
78 ~QCompleterPrivate() { delete popup; }
79 void init(QAbstractItemModel *model = 0);
80
81 QPointer<QWidget> widget;
82 QCompletionModel *proxy;
83 QAbstractItemView *popup;
84 QCompleter::CompletionMode mode;
85
86 QString prefix;
87 Qt::CaseSensitivity cs;
88 int role;
89 int column;
90 int maxVisibleItems;
91 QCompleter::ModelSorting sorting;
92 bool wrap;
93
94 bool eatFocusOut;
95 QRect popupRect;
96
97 void showPopup(const QRect&);
98 void _q_complete(QModelIndex, bool = false);
99 void _q_completionSelected(const QItemSelection&);
100 void _q_autoResizePopup();
101 void setCurrentIndex(QModelIndex, bool = true);
102};
103
104class QIndexMapper
105{
106public:
107 QIndexMapper() : v(false), f(0), t(-1) { }
108 QIndexMapper(int f, int t) : v(false), f(f), t(t) { }
109 QIndexMapper(QVector<int> vec) : v(true), vector(vec), f(-1), t(-1) { }
110
111 inline int count() const { return v ? vector.count() : t - f + 1; }
112 inline int operator[] (int index) const { return v ? vector[index] : f + index; }
113 inline int indexOf(int x) const { return v ? vector.indexOf(x) : ((t < f) ? -1 : x - f); }
114 inline bool isValid() const { return !isEmpty(); }
115 inline bool isEmpty() const { return v ? vector.isEmpty() : (t < f); }
116 inline void append(int x) { Q_ASSERT(v); vector.append(x); }
117 inline int first() const { return v ? vector.first() : f; }
118 inline int last() const { return v ? vector.last() : t; }
119 inline int from() const { Q_ASSERT(!v); return f; }
120 inline int to() const { Q_ASSERT(!v); return t; }
121 inline int cost() const { return vector.count()+2; }
122
123private:
124 bool v;
125 QVector<int> vector;
126 int f, t;
127};
128
129struct QMatchData {
130 QMatchData() : exactMatchIndex(-1) { }
131 QMatchData(const QIndexMapper& indices, int em, bool p) :
132 indices(indices), exactMatchIndex(em), partial(p) { }
133 QIndexMapper indices;
134 inline bool isValid() const { return indices.isValid(); }
135 int exactMatchIndex;