widgets/qlineedit_p.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtGui module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qlineedit.h" -
43#include "qlineedit_p.h" -
44 -
45#ifndef QT_NO_LINEEDIT -
46 -
47#include "qabstractitemview.h" -
48#include "qdrag.h" -
49#include "qclipboard.h" -
50#ifndef QT_NO_ACCESSIBILITY -
51#include "qaccessible.h" -
52#endif -
53#ifndef QT_NO_IM -
54#include "qinputmethod.h" -
55#include "qlist.h" -
56#endif -
57 -
58QT_BEGIN_NAMESPACE -
59 -
60const int QLineEditPrivate::verticalMargin(1); -
61const int QLineEditPrivate::horizontalMargin(2); -
62 -
63QRect QLineEditPrivate::adjustedControlRect(const QRect &rect) const -
64{ -
65 QRect widgetRect = !rect.isEmpty() ? rect : q_func()->rect();
evaluated: !rect.isEmpty()
TRUEFALSE
yes
Evaluation Count:7398
yes
Evaluation Count:278
278-7398
66 QRect cr = adjustedContentsRect();
executed (the execution status of this line is deduced): QRect cr = adjustedContentsRect();
-
67 int cix = cr.x() - hscroll + horizontalMargin;
executed (the execution status of this line is deduced): int cix = cr.x() - hscroll + horizontalMargin;
-
68 return widgetRect.translated(QPoint(cix, vscroll));
executed: return widgetRect.translated(QPoint(cix, vscroll));
Execution Count:7676
7676
69} -
70 -
71int QLineEditPrivate::xToPos(int x, QTextLine::CursorPosition betweenOrOn) const -
72{ -
73 QRect cr = adjustedContentsRect();
executed (the execution status of this line is deduced): QRect cr = adjustedContentsRect();
-
74 x-= cr.x() - hscroll + horizontalMargin;
executed (the execution status of this line is deduced): x-= cr.x() - hscroll + horizontalMargin;
-
75 return control->xToPos(x, betweenOrOn);
executed: return control->xToPos(x, betweenOrOn);
Execution Count:13
13
76} -
77 -
78QRect QLineEditPrivate::cursorRect() const -
79{ -
80 return adjustedControlRect(control->cursorRect());
executed: return adjustedControlRect(control->cursorRect());
Execution Count:5262
5262
81} -
82 -
83#ifndef QT_NO_COMPLETER -
84 -
85void QLineEditPrivate::_q_completionHighlighted(QString newText) -
86{ -
87 Q_Q(QLineEdit);
executed (the execution status of this line is deduced): QLineEdit * const q = q_func();
-
88 if (control->completer()->completionMode() != QCompleter::InlineCompletion) {
evaluated: control->completer()->completionMode() != QCompleter::InlineCompletion
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:13
12-13
89 q->setText(newText);
executed (the execution status of this line is deduced): q->setText(newText);
-
90 } else {
executed: }
Execution Count:12
12
91 int c = control->cursor();
executed (the execution status of this line is deduced): int c = control->cursor();
-
92 QString text = control->text();
executed (the execution status of this line is deduced): QString text = control->text();
-
93 q->setText(text.left(c) + newText.mid(c));
executed (the execution status of this line is deduced): q->setText(text.left(c) + newText.mid(c));
-
94 control->moveCursor(control->end(), false);
executed (the execution status of this line is deduced): control->moveCursor(control->end(), false);
-
95 control->moveCursor(c, true);
executed (the execution status of this line is deduced): control->moveCursor(c, true);
-
96 }
executed: }
Execution Count:13
13
97} -
98 -
99#endif // QT_NO_COMPLETER -
100 -
101void QLineEditPrivate::_q_handleWindowActivate() -
102{ -
103 Q_Q(QLineEdit);
executed (the execution status of this line is deduced): QLineEdit * const q = q_func();
-
104 if (!q->hasFocus() && control->hasSelectedText())
evaluated: !q->hasFocus()
TRUEFALSE
yes
Evaluation Count:131
yes
Evaluation Count:194
evaluated: control->hasSelectedText()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:129
2-194
105 control->deselect();
executed: control->deselect();
Execution Count:2
2
106}
executed: }
Execution Count:325
325
107 -
108void QLineEditPrivate::_q_textEdited(const QString &text) -
109{ -
110 Q_Q(QLineEdit);
executed (the execution status of this line is deduced): QLineEdit * const q = q_func();
-
111 emit q->textEdited(text);
executed (the execution status of this line is deduced): q->textEdited(text);
-
112#ifndef QT_NO_COMPLETER -
113 if (control->completer()
evaluated: control->completer()
TRUEFALSE
yes
Evaluation Count:77
yes
Evaluation Count:1745
77-1745
114 && control->completer()->completionMode() != QCompleter::InlineCompletion)
evaluated: control->completer()->completionMode() != QCompleter::InlineCompletion
TRUEFALSE
yes
Evaluation Count:68
yes
Evaluation Count:9
9-68
115 control->complete(-1); // update the popup on cut/paste/del
executed: control->complete(-1);
Execution Count:68
68
116#endif -
117}
executed: }
Execution Count:1822
1822
118 -
119void QLineEditPrivate::_q_cursorPositionChanged(int from, int to) -
120{ -
121 Q_Q(QLineEdit);
executed (the execution status of this line is deduced): QLineEdit * const q = q_func();
-
122 q->update();
executed (the execution status of this line is deduced): q->update();
-
123 emit q->cursorPositionChanged(from, to);
executed (the execution status of this line is deduced): q->cursorPositionChanged(from, to);
-
124}
executed: }
Execution Count:11650
11650
125 -
126#ifdef QT_KEYPAD_NAVIGATION -
127void QLineEditPrivate::_q_editFocusChange(bool e) -
128{ -
129 Q_Q(QLineEdit); -
130 q->setEditFocus(e); -
131} -
132#endif -
133 -
134void QLineEditPrivate::_q_selectionChanged() -
135{ -
136 Q_Q(QLineEdit);
executed (the execution status of this line is deduced): QLineEdit * const q = q_func();
-
137 if (control->preeditAreaText().isEmpty()) {
partially evaluated: control->preeditAreaText().isEmpty()
TRUEFALSE
yes
Evaluation Count:6979
no
Evaluation Count:0
0-6979
138 QStyleOptionFrameV2 opt;
executed (the execution status of this line is deduced): QStyleOptionFrameV2 opt;
-
139 q->initStyleOption(&opt);
executed (the execution status of this line is deduced): q->initStyleOption(&opt);
-
140 bool showCursor = control->hasSelectedText() ?
evaluated: control->hasSelectedText()
TRUEFALSE
yes
Evaluation Count:4123
yes
Evaluation Count:2856
2856-4123
141 q->style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, q):
executed (the execution status of this line is deduced): q->style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, q):
-
142 q->hasFocus();
executed (the execution status of this line is deduced): q->hasFocus();
-
143 setCursorVisible(showCursor);
executed (the execution status of this line is deduced): setCursorVisible(showCursor);
-
144 }
executed: }
Execution Count:6979
6979
145 -
146 emit q->selectionChanged();
executed (the execution status of this line is deduced): q->selectionChanged();
-
147#ifndef QT_NO_ACCESSIBILITY -
148 QAccessibleTextSelectionEvent ev(q, control->selectionStart(), control->selectionEnd());
executed (the execution status of this line is deduced): QAccessibleTextSelectionEvent ev(q, control->selectionStart(), control->selectionEnd());
-
149 ev.setCursorPosition(control->cursorPosition());
executed (the execution status of this line is deduced): ev.setCursorPosition(control->cursorPosition());
-
150 QAccessible::updateAccessibility(&ev);
executed (the execution status of this line is deduced): QAccessible::updateAccessibility(&ev);
-
151#endif -
152}
executed: }
Execution Count:6979
6979
153 -
154void QLineEditPrivate::_q_updateNeeded(const QRect &rect) -
155{ -
156 q_func()->update(adjustedControlRect(rect));
executed (the execution status of this line is deduced): q_func()->update(adjustedControlRect(rect));
-
157}
executed: }
Execution Count:2414
2414
158 -
159void QLineEditPrivate::init(const QString& txt) -
160{ -
161 Q_Q(QLineEdit);
executed (the execution status of this line is deduced): QLineEdit * const q = q_func();
-
162 control = new QWidgetLineControl(txt);
executed (the execution status of this line is deduced): control = new QWidgetLineControl(txt);
-
163 control->setParent(q);
executed (the execution status of this line is deduced): control->setParent(q);
-
164 control->setFont(q->font());
executed (the execution status of this line is deduced): control->setFont(q->font());
-
165 QObject::connect(control, SIGNAL(textChanged(QString)),
executed (the execution status of this line is deduced): QObject::connect(control, "2""textChanged(QString)",
-
166 q, SIGNAL(textChanged(QString)));
executed (the execution status of this line is deduced): q, "2""textChanged(QString)");
-
167 QObject::connect(control, SIGNAL(textEdited(QString)),
executed (the execution status of this line is deduced): QObject::connect(control, "2""textEdited(QString)",
-
168 q, SLOT(_q_textEdited(QString)));
executed (the execution status of this line is deduced): q, "1""_q_textEdited(QString)");
-
169 QObject::connect(control, SIGNAL(cursorPositionChanged(int,int)),
executed (the execution status of this line is deduced): QObject::connect(control, "2""cursorPositionChanged(int,int)",
-
170 q, SLOT(_q_cursorPositionChanged(int,int)));
executed (the execution status of this line is deduced): q, "1""_q_cursorPositionChanged(int,int)");
-
171 QObject::connect(control, SIGNAL(selectionChanged()),
executed (the execution status of this line is deduced): QObject::connect(control, "2""selectionChanged()",
-
172 q, SLOT(_q_selectionChanged()));
executed (the execution status of this line is deduced): q, "1""_q_selectionChanged()");
-
173 QObject::connect(control, SIGNAL(accepted()),
executed (the execution status of this line is deduced): QObject::connect(control, "2""accepted()",
-
174 q, SIGNAL(returnPressed()));
executed (the execution status of this line is deduced): q, "2""returnPressed()");
-
175 QObject::connect(control, SIGNAL(editingFinished()),
executed (the execution status of this line is deduced): QObject::connect(control, "2""editingFinished()",
-
176 q, SIGNAL(editingFinished()));
executed (the execution status of this line is deduced): q, "2""editingFinished()");
-
177#ifdef QT_KEYPAD_NAVIGATION -
178 QObject::connect(control, SIGNAL(editFocusChange(bool)), -
179 q, SLOT(_q_editFocusChange(bool))); -
180#endif -
181 QObject::connect(control, SIGNAL(cursorPositionChanged(int,int)),
executed (the execution status of this line is deduced): QObject::connect(control, "2""cursorPositionChanged(int,int)",
-
182 q, SLOT(updateMicroFocus()));
executed (the execution status of this line is deduced): q, "1""updateMicroFocus()");
-
183 -
184 QObject::connect(control, SIGNAL(textChanged(QString)),
executed (the execution status of this line is deduced): QObject::connect(control, "2""textChanged(QString)",
-
185 q, SLOT(updateMicroFocus()));
executed (the execution status of this line is deduced): q, "1""updateMicroFocus()");
-
186 -
187 // for now, going completely overboard with updates. -
188 QObject::connect(control, SIGNAL(selectionChanged()),
executed (the execution status of this line is deduced): QObject::connect(control, "2""selectionChanged()",
-
189 q, SLOT(update()));
executed (the execution status of this line is deduced): q, "1""update()");
-
190 -
191 QObject::connect(control, SIGNAL(displayTextChanged(QString)),
executed (the execution status of this line is deduced): QObject::connect(control, "2""displayTextChanged(QString)",
-
192 q, SLOT(update()));
executed (the execution status of this line is deduced): q, "1""update()");
-
193 -
194 QObject::connect(control, SIGNAL(updateNeeded(QRect)),
executed (the execution status of this line is deduced): QObject::connect(control, "2""updateNeeded(QRect)",
-
195 q, SLOT(_q_updateNeeded(QRect)));
executed (the execution status of this line is deduced): q, "1""_q_updateNeeded(QRect)");
-
196 -
197 QStyleOptionFrameV2 opt;
executed (the execution status of this line is deduced): QStyleOptionFrameV2 opt;
-
198 q->initStyleOption(&opt);
executed (the execution status of this line is deduced): q->initStyleOption(&opt);
-
199 control->setPasswordCharacter(q->style()->styleHint(QStyle::SH_LineEdit_PasswordCharacter, &opt, q));
executed (the execution status of this line is deduced): control->setPasswordCharacter(q->style()->styleHint(QStyle::SH_LineEdit_PasswordCharacter, &opt, q));
-
200#ifndef QT_NO_CURSOR -
201 q->setCursor(Qt::IBeamCursor);
executed (the execution status of this line is deduced): q->setCursor(Qt::IBeamCursor);
-
202#endif -
203 q->setFocusPolicy(Qt::StrongFocus);
executed (the execution status of this line is deduced): q->setFocusPolicy(Qt::StrongFocus);
-
204 q->setAttribute(Qt::WA_InputMethodEnabled);
executed (the execution status of this line is deduced): q->setAttribute(Qt::WA_InputMethodEnabled);
-
205 // Specifies that this widget can use more, but is able to survive on -
206 // less, horizontal space; and is fixed vertically. -
207 q->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed, QSizePolicy::LineEdit));
executed (the execution status of this line is deduced): q->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed, QSizePolicy::LineEdit));
-
208 q->setBackgroundRole(QPalette::Base);
executed (the execution status of this line is deduced): q->setBackgroundRole(QPalette::Base);
-
209 q->setAttribute(Qt::WA_KeyCompression);
executed (the execution status of this line is deduced): q->setAttribute(Qt::WA_KeyCompression);
-
210 q->setMouseTracking(true);
executed (the execution status of this line is deduced): q->setMouseTracking(true);
-
211 q->setAcceptDrops(true);
executed (the execution status of this line is deduced): q->setAcceptDrops(true);
-
212 -
213 q->setAttribute(Qt::WA_MacShowFocusRect);
executed (the execution status of this line is deduced): q->setAttribute(Qt::WA_MacShowFocusRect);
-
214}
executed: }
Execution Count:1077
1077
215 -
216QRect QLineEditPrivate::adjustedContentsRect() const -
217{ -
218 Q_Q(const QLineEdit);
executed (the execution status of this line is deduced): const QLineEdit * const q = q_func();
-
219 QStyleOptionFrameV2 opt;
executed (the execution status of this line is deduced): QStyleOptionFrameV2 opt;
-
220 q->initStyleOption(&opt);
executed (the execution status of this line is deduced): q->initStyleOption(&opt);
-
221 QRect r = q->style()->subElementRect(QStyle::SE_LineEditContents, &opt, q);
executed (the execution status of this line is deduced): QRect r = q->style()->subElementRect(QStyle::SE_LineEditContents, &opt, q);
-
222 r.setX(r.x() + leftTextMargin);
executed (the execution status of this line is deduced): r.setX(r.x() + leftTextMargin);
-
223 r.setY(r.y() + topTextMargin);
executed (the execution status of this line is deduced): r.setY(r.y() + topTextMargin);
-
224 r.setRight(r.right() - rightTextMargin);
executed (the execution status of this line is deduced): r.setRight(r.right() - rightTextMargin);
-
225 r.setBottom(r.bottom() - bottomTextMargin);
executed (the execution status of this line is deduced): r.setBottom(r.bottom() - bottomTextMargin);
-
226 return r;
executed: return r;
Execution Count:7689
7689
227} -
228 -
229void QLineEditPrivate::setCursorVisible(bool visible) -
230{ -
231 Q_Q(QLineEdit);
executed (the execution status of this line is deduced): QLineEdit * const q = q_func();
-
232 if ((bool)cursorVisible == visible)
evaluated: (bool)cursorVisible == visible
TRUEFALSE
yes
Evaluation Count:2685
yes
Evaluation Count:5292
2685-5292
233 return;
executed: return;
Execution Count:2685
2685
234 cursorVisible = visible;
executed (the execution status of this line is deduced): cursorVisible = visible;
-
235 if (control->inputMask().isEmpty())
evaluated: control->inputMask().isEmpty()
TRUEFALSE
yes
Evaluation Count:5260
yes
Evaluation Count:32
32-5260
236 q->update(cursorRect());
executed: q->update(cursorRect());
Execution Count:5260
5260
237 else -
238 q->update();
executed: q->update();
Execution Count:32
32
239} -
240 -
241void QLineEditPrivate::updatePasswordEchoEditing(bool editing) -
242{ -
243 Q_Q(QLineEdit);
executed (the execution status of this line is deduced): QLineEdit * const q = q_func();
-
244 control->updatePasswordEchoEditing(editing);
executed (the execution status of this line is deduced): control->updatePasswordEchoEditing(editing);
-
245 q->setAttribute(Qt::WA_InputMethodEnabled, shouldEnableInputMethod());
executed (the execution status of this line is deduced): q->setAttribute(Qt::WA_InputMethodEnabled, shouldEnableInputMethod());
-
246}
executed: }
Execution Count:2
2
247 -
248void QLineEditPrivate::resetInputMethod() -
249{ -
250 Q_Q(QLineEdit);
executed (the execution status of this line is deduced): QLineEdit * const q = q_func();
-
251 if (q->hasFocus() && qApp) {
evaluated: q->hasFocus()
TRUEFALSE
yes
Evaluation Count:245
yes
Evaluation Count:168
partially evaluated: (static_cast<QApplication *>(QCoreApplication::instance()))
TRUEFALSE
yes
Evaluation Count:245
no
Evaluation Count:0
0-245
252 qApp->inputMethod()->reset();
executed (the execution status of this line is deduced): (static_cast<QApplication *>(QCoreApplication::instance()))->inputMethod()->reset();
-
253 }
executed: }
Execution Count:245
245
254}
executed: }
Execution Count:413
413
255 -
256/*! -
257 This function is not intended as polymorphic usage. Just a shared code -
258 fragment that calls QInputMethod::invokeAction for this -
259 class. -
260*/ -
261bool QLineEditPrivate::sendMouseEventToInputContext( QMouseEvent *e ) -
262{ -
263#if !defined QT_NO_IM -
264 if ( control->composeMode() ) {
partially evaluated: control->composeMode()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:53
0-53
265 int tmp_cursor = xToPos(e->pos().x());
never executed (the execution status of this line is deduced): int tmp_cursor = xToPos(e->pos().x());
-
266 int mousePos = tmp_cursor - control->cursor();
never executed (the execution status of this line is deduced): int mousePos = tmp_cursor - control->cursor();
-
267 if ( mousePos < 0 || mousePos > control->preeditAreaText().length() )
never evaluated: mousePos < 0
never evaluated: mousePos > control->preeditAreaText().length()
0
268 mousePos = -1;
never executed: mousePos = -1;
0
269 -
270 if (mousePos >= 0) {
never evaluated: mousePos >= 0
0
271 if (e->type() == QEvent::MouseButtonRelease)
never evaluated: e->type() == QEvent::MouseButtonRelease
0
272 qApp->inputMethod()->invokeAction(QInputMethod::Click, mousePos);
never executed: (static_cast<QApplication *>(QCoreApplication::instance()))->inputMethod()->invokeAction(QInputMethod::Click, mousePos);
0
273 -
274 return true;
never executed: return true;
0
275 } -
276 }
never executed: }
0
277#else -
278 Q_UNUSED(e); -
279#endif -
280 -
281 return false;
executed: return false;
Execution Count:53
53
282} -
283 -
284#ifndef QT_NO_DRAGANDDROP -
285void QLineEditPrivate::drag() -
286{ -
287 Q_Q(QLineEdit);
never executed (the execution status of this line is deduced): QLineEdit * const q = q_func();
-
288 dndTimer.stop();
never executed (the execution status of this line is deduced): dndTimer.stop();
-
289 QMimeData *data = new QMimeData;
never executed (the execution status of this line is deduced): QMimeData *data = new QMimeData;
-
290 data->setText(control->selectedText());
never executed (the execution status of this line is deduced): data->setText(control->selectedText());
-
291 QDrag *drag = new QDrag(q);
never executed (the execution status of this line is deduced): QDrag *drag = new QDrag(q);
-
292 drag->setMimeData(data);
never executed (the execution status of this line is deduced): drag->setMimeData(data);
-
293 Qt::DropAction action = drag->start();
never executed (the execution status of this line is deduced): Qt::DropAction action = drag->start();
-
294 if (action == Qt::MoveAction && !control->isReadOnly() && drag->target() != q)
never evaluated: action == Qt::MoveAction
never evaluated: !control->isReadOnly()
never evaluated: drag->target() != q
0
295 control->removeSelection();
never executed: control->removeSelection();
0
296}
never executed: }
0
297 -
298#endif // QT_NO_DRAGANDDROP -
299 -
300QT_END_NAMESPACE -
301 -
302#endif -
303 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial