author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 02 Feb 2010 00:43:10 +0200 | |
changeset 3 | 41300fa6a67c |
parent 0 | 1918ee327afb |
child 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 |
** All rights reserved. |
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
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 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
||
45 |
||
46 |
#include <qtextdocument.h> |
|
47 |
#include <qtexttable.h> |
|
48 |
#include <qvariant.h> |
|
49 |
#include <qtextdocumentfragment.h> |
|
50 |
#include <qabstracttextdocumentlayout.h> |
|
51 |
#include <qtextlayout.h> |
|
52 |
#include <qtextcursor.h> |
|
53 |
#include <qdebug.h> |
|
54 |
||
55 |
//TESTED_FILES=gui/text/qtextcursor.cpp gui/text/qtextcursor_p.h |
|
56 |
||
57 |
QT_FORWARD_DECLARE_CLASS(QTextDocument) |
|
58 |
||
59 |
class tst_QTextCursor : public QObject |
|
60 |
{ |
|
61 |
Q_OBJECT |
|
62 |
||
63 |
public: |
|
64 |
tst_QTextCursor(); |
|
65 |
||
66 |
||
67 |
public slots: |
|
68 |
void init(); |
|
69 |
void cleanup(); |
|
70 |
private slots: |
|
71 |
void navigation1(); |
|
72 |
void navigation2_data(); |
|
73 |
void navigation2(); |
|
74 |
void navigation3(); |
|
75 |
void navigation4(); |
|
76 |
void navigation5(); |
|
77 |
void navigation6(); |
|
78 |
void navigation7(); |
|
79 |
void navigation8(); |
|
80 |
void navigation9(); |
|
81 |
void navigation10(); |
|
82 |
void movePositionEndOfLine(); |
|
83 |
void insertBlock(); |
|
84 |
void insertWithBlockSeparator1(); |
|
85 |
void insertWithBlockSeparator2(); |
|
86 |
void insertWithBlockSeparator3(); |
|
87 |
void insertWithBlockSeparator4(); |
|
88 |
void clearObjectType1(); |
|
89 |
void clearObjectType2(); |
|
90 |
void clearObjectType3(); |
|
91 |
void comparisonOperators1(); |
|
92 |
void comparisonOperators2(); |
|
93 |
void selection1(); |
|
94 |
void dontCopyTableAttributes(); |
|
95 |
||
96 |
void checkFrame1(); |
|
97 |
void checkFrame2(); |
|
98 |
||
99 |
void tableMovement(); |
|
100 |
void selectionsInTable(); |
|
101 |
||
102 |
void insertBlockToUseCharFormat(); |
|
103 |
||
104 |
void selectedText(); |
|
105 |
||
106 |
void insertBlockShouldRemoveSelection(); |
|
107 |
void insertBlockShouldRemoveSelection2(); |
|
108 |
void mergeCellShouldUpdateSelection(); |
|
109 |
||
110 |
void joinPreviousEditBlock(); |
|
111 |
||
112 |
void setBlockFormatInTable(); |
|
113 |
||
114 |
void blockCharFormat(); |
|
115 |
void blockCharFormat2(); |
|
116 |
void blockCharFormat3(); |
|
117 |
void blockCharFormatOnSelection(); |
|
118 |
||
119 |
void anchorInitialized1(); |
|
120 |
void anchorInitialized2(); |
|
121 |
void anchorInitialized3(); |
|
122 |
||
123 |
void selectWord(); |
|
124 |
void selectWordWithSeparators_data(); |
|
125 |
void selectWordWithSeparators(); |
|
126 |
void startOfWord(); |
|
127 |
void selectBlock(); |
|
128 |
void selectVisually(); |
|
129 |
||
130 |
void insertText(); |
|
131 |
||
132 |
void insertFragmentShouldUseCurrentCharFormat(); |
|
133 |
||
134 |
void endOfLine(); |
|
135 |
||
136 |
void editBlocksDuringRemove(); |
|
137 |
||
138 |
void update_data(); |
|
139 |
void update(); |
|
140 |
||
141 |
void disallowSettingObjectIndicesOnCharFormats(); |
|
142 |
||
143 |
void blockAndColumnNumber(); |
|
144 |
||
145 |
void clearCells(); |
|
146 |
||
147 |
void task244408_wordUnderCursor_data(); |
|
148 |
void task244408_wordUnderCursor(); |
|
149 |
||
150 |
void adjustCursorsOnInsert(); |
|
151 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
152 |
void cursorPositionWithBlockUndoAndRedo(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
153 |
|
0 | 154 |
private: |
155 |
int blockCount(); |
|
156 |
||
157 |
QTextDocument *doc; |
|
158 |
QTextCursor cursor; |
|
159 |
}; |
|
160 |
||
161 |
Q_DECLARE_METATYPE(QList<QVariant>) |
|
162 |
||
163 |
tst_QTextCursor::tst_QTextCursor() |
|
164 |
{} |
|
165 |
||
166 |
void tst_QTextCursor::init() |
|
167 |
{ |
|
168 |
doc = new QTextDocument; |
|
169 |
cursor = QTextCursor(doc); |
|
170 |
} |
|
171 |
||
172 |
void tst_QTextCursor::cleanup() |
|
173 |
{ |
|
174 |
cursor = QTextCursor(); |
|
175 |
delete doc; |
|
176 |
doc = 0; |
|
177 |
} |
|
178 |
||
179 |
void tst_QTextCursor::navigation1() |
|
180 |
{ |
|
181 |
||
182 |
cursor.insertText("Hello World"); |
|
183 |
QVERIFY(doc->toPlainText() == "Hello World"); |
|
184 |
||
185 |
cursor.movePosition(QTextCursor::End); |
|
186 |
QVERIFY(cursor.position() == 11); |
|
187 |
cursor.deletePreviousChar(); |
|
188 |
QVERIFY(cursor.position() == 10); |
|
189 |
cursor.deletePreviousChar(); |
|
190 |
cursor.deletePreviousChar(); |
|
191 |
cursor.deletePreviousChar(); |
|
192 |
cursor.deletePreviousChar(); |
|
193 |
cursor.deletePreviousChar(); |
|
194 |
QVERIFY(doc->toPlainText() == "Hello"); |
|
195 |
||
196 |
QTextCursor otherCursor(doc); |
|
197 |
otherCursor.movePosition(QTextCursor::Start); |
|
198 |
otherCursor.movePosition(QTextCursor::Right); |
|
199 |
cursor = otherCursor; |
|
200 |
cursor.movePosition(QTextCursor::Right); |
|
201 |
QVERIFY(cursor != otherCursor); |
|
202 |
otherCursor.insertText("Hey"); |
|
203 |
QVERIFY(cursor.position() == 5); |
|
204 |
||
205 |
doc->undo(); |
|
206 |
QVERIFY(cursor.position() == 2); |
|
207 |
doc->redo(); |
|
208 |
QVERIFY(cursor.position() == 5); |
|
209 |
||
210 |
doc->undo(); |
|
211 |
||
212 |
doc->undo(); |
|
213 |
QVERIFY(doc->toPlainText() == "Hello World"); |
|
214 |
||
215 |
cursor.movePosition(QTextCursor::Start); |
|
216 |
cursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, 6); |
|
217 |
QVERIFY(cursor.position() == 6); |
|
218 |
otherCursor = cursor; |
|
219 |
otherCursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, 2); |
|
220 |
otherCursor.deletePreviousChar(); |
|
221 |
otherCursor.deletePreviousChar(); |
|
222 |
otherCursor.deletePreviousChar(); |
|
223 |
QVERIFY(cursor.position() == 5); |
|
224 |
||
225 |
cursor.movePosition(QTextCursor::End); |
|
226 |
cursor.insertBlock(); |
|
227 |
{ |
|
228 |
int oldPos = cursor.position(); |
|
229 |
cursor.movePosition(QTextCursor::End); |
|
230 |
QVERIFY(cursor.position() == oldPos); |
|
231 |
} |
|
232 |
QVERIFY(cursor.atBlockStart()); |
|
233 |
QVERIFY(cursor.position() == 9); |
|
234 |
||
235 |
QTextCharFormat fmt; |
|
236 |
fmt.setForeground(Qt::blue); |
|
237 |
cursor.insertText("Test", fmt); |
|
238 |
QVERIFY(fmt == cursor.charFormat()); |
|
239 |
QVERIFY(cursor.position() == 13); |
|
240 |
} |
|
241 |
||
242 |
void tst_QTextCursor::navigation2_data() |
|
243 |
{ |
|
244 |
QTest::addColumn<QStringList>("sl"); |
|
245 |
QTest::addColumn<QList<QVariant> >("movement"); |
|
246 |
QTest::addColumn<int>("finalPos"); |
|
247 |
||
248 |
QTest::newRow("startBlock1") << QStringList("Happy happy happy joy joy joy") |
|
249 |
<< (QList<QVariant>() << QVariant(QTextCursor::StartOfBlock)) << 0; |
|
250 |
QTest::newRow("endBlock1") << QStringList("Happy happy happy joy joy joy") |
|
251 |
<< (QList<QVariant>() << QVariant(QTextCursor::StartOfBlock) |
|
252 |
<< QVariant(QTextCursor::EndOfBlock)) << 29; |
|
253 |
QTest::newRow("startBlock2") << QStringList("Happy happy happy joy joy joy") |
|
254 |
<< (QList<QVariant>() << QVariant(QTextCursor::StartOfBlock) |
|
255 |
<< QVariant(QTextCursor::EndOfBlock) |
|
256 |
<< QVariant(QTextCursor::StartOfBlock)) << 0; |
|
257 |
QTest::newRow("endBlock2") << QStringList("Happy happy happy joy joy joy") |
|
258 |
<< (QList<QVariant>() << QVariant(QTextCursor::StartOfBlock) |
|
259 |
<< QVariant(QTextCursor::EndOfBlock) |
|
260 |
<< QVariant(QTextCursor::StartOfBlock) |
|
261 |
<< QVariant(QTextCursor::EndOfBlock) |
|
262 |
) << 29; |
|
263 |
QTest::newRow("multiBlock1") << (QStringList() << QString("Happy happy happy") |
|
264 |
<< QString("Joy Joy Joy")) |
|
265 |
<< (QList<QVariant>() << QVariant(QTextCursor::StartOfBlock)) |
|
266 |
<< 18; |
|
267 |
QTest::newRow("multiBlock2") << (QStringList() << QString("Happy happy happy") |
|
268 |
<< QString("Joy Joy Joy")) |
|
269 |
<< (QList<QVariant>() << QVariant(QTextCursor::StartOfBlock) |
|
270 |
<< QVariant(QTextCursor::EndOfBlock)) |
|
271 |
<< 29; |
|
272 |
QTest::newRow("multiBlock3") << (QStringList() << QString("Happy happy happy") |
|
273 |
<< QString("Joy Joy Joy")) |
|
274 |
<< (QList<QVariant>() << QVariant(QTextCursor::StartOfBlock) |
|
275 |
<< QVariant(QTextCursor::StartOfBlock)) |
|
276 |
<< 18; |
|
277 |
QTest::newRow("multiBlock4") << (QStringList() << QString("Happy happy happy") |
|
278 |
<< QString("Joy Joy Joy")) |
|
279 |
<< (QList<QVariant>() << QVariant(QTextCursor::Start) |
|
280 |
<< QVariant(QTextCursor::EndOfBlock)) |
|
281 |
<< 17; |
|
282 |
QTest::newRow("multiBlock5") << (QStringList() << QString("Happy happy happy") |
|
283 |
<< QString("Joy Joy Joy")) |
|
284 |
<< (QList<QVariant>() << QVariant(QTextCursor::Start) |
|
285 |
<< QVariant(QTextCursor::EndOfBlock) |
|
286 |
<< QVariant(QTextCursor::EndOfBlock)) |
|
287 |
<< 17; |
|
288 |
QTest::newRow("multiBlock6") << (QStringList() << QString("Happy happy happy") |
|
289 |
<< QString("Joy Joy Joy")) |
|
290 |
<< (QList<QVariant>() << QVariant(QTextCursor::End) |
|
291 |
<< QVariant(QTextCursor::StartOfBlock)) |
|
292 |
<< 18; |
|
293 |
QTest::newRow("multiBlock7") << (QStringList() << QString("Happy happy happy") |
|
294 |
<< QString("Joy Joy Joy")) |
|
295 |
<< (QList<QVariant>() << QVariant(QTextCursor::PreviousBlock)) |
|
296 |
<< 0; |
|
297 |
QTest::newRow("multiBlock8") << (QStringList() << QString("Happy happy happy") |
|
298 |
<< QString("Joy Joy Joy")) |
|
299 |
<< (QList<QVariant>() << QVariant(QTextCursor::PreviousBlock) |
|
300 |
<< QVariant(QTextCursor::EndOfBlock)) |
|
301 |
<< 17; |
|
302 |
QTest::newRow("multiBlock9") << (QStringList() << QString("Happy happy happy") |
|
303 |
<< QString("Joy Joy Joy")) |
|
304 |
<< (QList<QVariant>() << QVariant(QTextCursor::PreviousBlock) |
|
305 |
<< QVariant(QTextCursor::NextBlock)) |
|
306 |
<< 18; |
|
307 |
QTest::newRow("multiBlock10") << (QStringList() << QString("Happy happy happy") |
|
308 |
<< QString("Joy Joy Joy")) |
|
309 |
<< (QList<QVariant>() << QVariant(QTextCursor::PreviousBlock) |
|
310 |
<< QVariant(QTextCursor::NextBlock) |
|
311 |
<< QVariant(QTextCursor::NextBlock)) |
|
312 |
<< 18; |
|
313 |
QTest::newRow("multiBlock11") << (QStringList() << QString("Happy happy happy") |
|
314 |
<< QString("Joy Joy Joy")) |
|
315 |
<< (QList<QVariant>() << QVariant(QTextCursor::PreviousBlock) |
|
316 |
<< QVariant(QTextCursor::NextBlock) |
|
317 |
<< QVariant(QTextCursor::EndOfBlock)) |
|
318 |
<< 29; |
|
319 |
QTest::newRow("PreviousWord1") << (QStringList() << QString("Happy happy happy Joy Joy Joy")) |
|
320 |
<< (QList<QVariant>() << QVariant(QTextCursor::PreviousWord)) |
|
321 |
<< 26; |
|
322 |
QTest::newRow("PreviousWord2") << (QStringList() << QString("Happy happy happy Joy Joy Joy")) |
|
323 |
<< (QList<QVariant>() << QVariant(QTextCursor::PreviousWord) |
|
324 |
<< QVariant(QTextCursor::PreviousWord)) |
|
325 |
<< 22; |
|
326 |
QTest::newRow("EndWord1") << (QStringList() << QString("Happy happy happy Joy Joy Joy")) |
|
327 |
<< (QList<QVariant>() << QVariant(QTextCursor::PreviousWord) |
|
328 |
<< QVariant(QTextCursor::PreviousWord) |
|
329 |
<< QVariant(QTextCursor::EndOfWord)) |
|
330 |
<< 25; |
|
331 |
QTest::newRow("NextWord1") << (QStringList() << QString("Happy happy happy Joy Joy Joy")) |
|
332 |
<< (QList<QVariant>() << QVariant(QTextCursor::PreviousWord) |
|
333 |
<< QVariant(QTextCursor::PreviousWord) |
|
334 |
<< QVariant(QTextCursor::NextWord)) |
|
335 |
<< 26; |
|
336 |
QTest::newRow("NextWord2") << (QStringList() << QString("Happy happy happy Joy Joy Joy")) |
|
337 |
<< (QList<QVariant>() << QVariant(QTextCursor::Start) |
|
338 |
<< QVariant(QTextCursor::NextWord) |
|
339 |
<< QVariant(QTextCursor::EndOfWord)) |
|
340 |
<< 11; |
|
341 |
QTest::newRow("StartWord1") << (QStringList() << QString("Happy happy happy Joy Joy Joy")) |
|
342 |
<< (QList<QVariant>() << QVariant(QTextCursor::PreviousWord) |
|
343 |
<< QVariant(QTextCursor::PreviousWord) |
|
344 |
<< QVariant(QTextCursor::StartOfWord)) |
|
345 |
<< 22; |
|
346 |
QTest::newRow("StartWord3") << (QStringList() << QString("Happy happy happy Joy Joy Joy")) |
|
347 |
<< (QList<QVariant>() << QVariant(QTextCursor::Start) |
|
348 |
<< QVariant(QTextCursor::NextWord) |
|
349 |
<< QVariant(QTextCursor::EndOfWord) |
|
350 |
<< QVariant(QTextCursor::StartOfWord)) |
|
351 |
<< 6; |
|
352 |
||
353 |
QTest::newRow("PreviousCharacter") << (QStringList() << QString("Happy happy Joy Joy")) |
|
354 |
<< (QList<QVariant>() << QVariant(QTextCursor::PreviousCharacter) |
|
355 |
<< QVariant(QTextCursor::PreviousCharacter)) |
|
356 |
<< 17; |
|
357 |
} |
|
358 |
||
359 |
void tst_QTextCursor::navigation2() |
|
360 |
{ |
|
361 |
QFETCH(QStringList, sl); |
|
362 |
QFETCH(QList<QVariant>, movement); |
|
363 |
int i; |
|
364 |
for (i = 0; i < sl.size(); ++i) { |
|
365 |
cursor.insertText(sl.at(i)); |
|
366 |
if (i < sl.size() - 1) |
|
367 |
cursor.insertBlock(); |
|
368 |
} |
|
369 |
||
370 |
for (i = 0; i < movement.size(); ++i) |
|
371 |
cursor.movePosition(QTextCursor::MoveOperation(movement.at(i).toInt())); |
|
372 |
QTEST(cursor.position(), "finalPos"); |
|
373 |
} |
|
374 |
||
375 |
void tst_QTextCursor::navigation3() |
|
376 |
{ |
|
377 |
cursor.insertText("a"); |
|
378 |
cursor.deletePreviousChar(); |
|
379 |
QCOMPARE(cursor.position(), 0); |
|
380 |
QVERIFY(doc->toPlainText().isEmpty()); |
|
381 |
} |
|
382 |
||
383 |
void tst_QTextCursor::navigation4() |
|
384 |
{ |
|
385 |
cursor.insertText(" Test "); |
|
386 |
||
387 |
cursor.setPosition(4); |
|
388 |
cursor.movePosition(QTextCursor::EndOfWord); |
|
389 |
QCOMPARE(cursor.position(), 6); |
|
390 |
} |
|
391 |
||
392 |
void tst_QTextCursor::navigation5() |
|
393 |
{ |
|
394 |
cursor.insertText("Test"); |
|
395 |
cursor.insertBlock(); |
|
396 |
cursor.insertText("Test"); |
|
397 |
||
398 |
cursor.setPosition(0); |
|
399 |
cursor.movePosition(QTextCursor::EndOfBlock); |
|
400 |
QCOMPARE(cursor.position(), 4); |
|
401 |
} |
|
402 |
||
403 |
void tst_QTextCursor::navigation6() |
|
404 |
{ |
|
405 |
// triger creation of document layout, so that QTextLines are there |
|
406 |
doc->documentLayout(); |
|
407 |
doc->setTextWidth(1000); |
|
408 |
||
409 |
cursor.insertText("Test "); |
|
410 |
||
411 |
cursor.movePosition(QTextCursor::Start); |
|
412 |
cursor.movePosition(QTextCursor::EndOfLine); |
|
413 |
QCOMPARE(cursor.position(), 8); |
|
414 |
} |
|
415 |
||
416 |
void tst_QTextCursor::navigation7() |
|
417 |
{ |
|
418 |
QVERIFY(doc->isEmpty()); |
|
419 |
for (int i = QTextCursor::Start; i <= QTextCursor::WordRight; ++i) |
|
420 |
QVERIFY(!cursor.movePosition(QTextCursor::MoveOperation(i))); |
|
421 |
||
422 |
doc->setPlainText("Hello World"); |
|
423 |
cursor.movePosition(QTextCursor::Start); |
|
424 |
do { |
|
425 |
} while (cursor.movePosition(QTextCursor::NextCharacter)); |
|
426 |
QVERIFY(true /*reached*/); |
|
427 |
} |
|
428 |
||
429 |
void tst_QTextCursor::navigation8() |
|
430 |
{ |
|
431 |
cursor.insertList(QTextListFormat::ListDecimal); |
|
432 |
QCOMPARE(cursor.position(), 1); |
|
433 |
cursor.insertText("foo"); |
|
434 |
QCOMPARE(cursor.position(), 4); |
|
435 |
||
436 |
cursor.insertList(QTextListFormat::ListCircle); |
|
437 |
QCOMPARE(cursor.position(), 5); |
|
438 |
cursor.insertText("something"); |
|
439 |
QCOMPARE(cursor.position(), 14); |
|
440 |
||
441 |
cursor.movePosition(QTextCursor::PreviousCharacter); |
|
442 |
QCOMPARE(cursor.position(), 13); |
|
443 |
||
444 |
cursor.setPosition(2); |
|
445 |
cursor.movePosition(QTextCursor::NextCharacter); |
|
446 |
QCOMPARE(cursor.position(), 3); |
|
447 |
} |
|
448 |
||
449 |
void tst_QTextCursor::navigation9() |
|
450 |
{ |
|
451 |
cursor.insertText("Hello &-=+\t World"); |
|
452 |
cursor.movePosition(QTextCursor::PreviousWord); |
|
453 |
QCOMPARE(cursor.position(), 15); |
|
454 |
cursor.movePosition(QTextCursor::PreviousWord); |
|
455 |
QCOMPARE(cursor.position(), 7); |
|
456 |
cursor.movePosition(QTextCursor::PreviousWord); |
|
457 |
QCOMPARE(cursor.position(), 0); |
|
458 |
cursor.movePosition(QTextCursor::NextWord); |
|
459 |
QCOMPARE(cursor.position(), 7); |
|
460 |
cursor.movePosition(QTextCursor::NextWord); |
|
461 |
QCOMPARE(cursor.position(), 15); |
|
462 |
} |
|
463 |
||
464 |
void tst_QTextCursor::navigation10() |
|
465 |
{ |
|
466 |
doc->setHtml("<html><p>just a simple paragraph.</p>" |
|
467 |
"<table>" |
|
468 |
"<tr><td>Cell number 1</td><td>another cell</td><td></td><td>previous</br>is</br>empty</td></tr>" |
|
469 |
"<tr><td>row 2</td><td colspan=\"2\">foo bar</td><td>last cell</td></tr>" |
|
470 |
"<tr><td colspan=\"3\">row 3</td><td>a</td></tr>" |
|
471 |
"</table></html"); |
|
472 |
QCOMPARE(cursor.position(), 101); // end of document |
|
473 |
cursor.setPosition(0); |
|
474 |
QCOMPARE(cursor.position(), 0); |
|
475 |
bool ok = cursor.movePosition(QTextCursor::EndOfLine); |
|
476 |
QVERIFY(ok); |
|
477 |
QCOMPARE(cursor.position(), 24); |
|
478 |
ok = cursor.movePosition(QTextCursor::NextBlock); |
|
479 |
QCOMPARE(cursor.position(), 25); // cell 1 |
|
480 |
ok = cursor.movePosition(QTextCursor::NextCell); |
|
481 |
QVERIFY(ok); |
|
482 |
QCOMPARE(cursor.position(), 39); // another.. |
|
483 |
ok = cursor.movePosition(QTextCursor::NextCell); |
|
484 |
QVERIFY(ok); |
|
485 |
QCOMPARE(cursor.position(), 52); // empty |
|
486 |
ok = cursor.movePosition(QTextCursor::NextCell); |
|
487 |
QVERIFY(ok); |
|
488 |
QCOMPARE(cursor.position(), 53); // last on row 1 |
|
489 |
ok = cursor.movePosition(QTextCursor::NextCell); |
|
490 |
QVERIFY(ok); |
|
491 |
QCOMPARE(cursor.position(), 69); // row 2 |
|
492 |
ok = cursor.movePosition(QTextCursor::NextCell); |
|
493 |
QVERIFY(ok); |
|
494 |
QCOMPARE(cursor.position(), 75); |
|
495 |
ok = cursor.movePosition(QTextCursor::NextCell); |
|
496 |
QVERIFY(ok); |
|
497 |
QCOMPARE(cursor.position(), 83); |
|
498 |
ok = cursor.movePosition(QTextCursor::NextCell); |
|
499 |
QVERIFY(ok); |
|
500 |
QCOMPARE(cursor.position(), 93); // row 3 |
|
501 |
ok = cursor.movePosition(QTextCursor::NextCell); |
|
502 |
QVERIFY(ok); |
|
503 |
QCOMPARE(cursor.position(), 99); |
|
504 |
ok = cursor.movePosition(QTextCursor::NextCell); |
|
505 |
QVERIFY(ok == false); |
|
506 |
QCOMPARE(cursor.position(), 99); // didn't move. |
|
507 |
QVERIFY(cursor.currentTable()); |
|
508 |
||
509 |
// same thing in reverse... |
|
510 |
ok = cursor.movePosition(QTextCursor::PreviousCell); |
|
511 |
QVERIFY(ok); |
|
512 |
QCOMPARE(cursor.position(), 93); |
|
513 |
ok = cursor.movePosition(QTextCursor::PreviousCell); |
|
514 |
QVERIFY(ok); |
|
515 |
QCOMPARE(cursor.position(), 83); |
|
516 |
ok = cursor.movePosition(QTextCursor::PreviousCell); |
|
517 |
QVERIFY(ok); |
|
518 |
QCOMPARE(cursor.position(), 75); |
|
519 |
ok = cursor.movePosition(QTextCursor::PreviousCell); |
|
520 |
QVERIFY(ok); |
|
521 |
QCOMPARE(cursor.position(), 69); |
|
522 |
ok = cursor.movePosition(QTextCursor::PreviousCell); |
|
523 |
QVERIFY(ok); |
|
524 |
QCOMPARE(cursor.position(), 53); |
|
525 |
ok = cursor.movePosition(QTextCursor::PreviousCell); |
|
526 |
QVERIFY(ok); |
|
527 |
QCOMPARE(cursor.position(), 52); |
|
528 |
ok = cursor.movePosition(QTextCursor::PreviousCell); |
|
529 |
QVERIFY(ok); |
|
530 |
QCOMPARE(cursor.position(), 39); |
|
531 |
ok = cursor.movePosition(QTextCursor::PreviousCell); |
|
532 |
QVERIFY(ok); |
|
533 |
QCOMPARE(cursor.position(), 25); |
|
534 |
ok = cursor.movePosition(QTextCursor::PreviousCell); |
|
535 |
QVERIFY(!ok); |
|
536 |
QCOMPARE(cursor.position(), 25); // can't leave the table |
|
537 |
||
538 |
ok = cursor.movePosition(QTextCursor::NextRow); |
|
539 |
QVERIFY(ok); |
|
540 |
QCOMPARE(cursor.position(), 69); |
|
541 |
ok = cursor.movePosition(QTextCursor::NextRow); |
|
542 |
QVERIFY(ok); |
|
543 |
QCOMPARE(cursor.position(), 93); |
|
544 |
ok = cursor.movePosition(QTextCursor::NextRow); |
|
545 |
QVERIFY(!ok); |
|
546 |
QCOMPARE(cursor.position(), 93); // didn't move |
|
547 |
||
548 |
ok = cursor.movePosition(QTextCursor::PreviousRow); |
|
549 |
QVERIFY(ok); |
|
550 |
QCOMPARE(cursor.position(), 83); // last col in row 2 |
|
551 |
ok = cursor.movePosition(QTextCursor::PreviousRow); |
|
552 |
QVERIFY(ok); |
|
553 |
QCOMPARE(cursor.position(), 53); // last col in row 1 |
|
554 |
ok = cursor.movePosition(QTextCursor::PreviousRow); |
|
555 |
QVERIFY(!ok); |
|
556 |
QCOMPARE(cursor.position(), 53); |
|
557 |
||
558 |
// test usecase of jumping over a cell |
|
559 |
doc->clear(); |
|
560 |
doc->setHtml("<html><table>tr><td rowspan=\"2\">a</td><td>b</td></tr><tr><td>c</td></tr></table></html>"); |
|
561 |
cursor.setPosition(1); // a |
|
562 |
ok = cursor.movePosition(QTextCursor::NextCell); |
|
563 |
QVERIFY(ok); |
|
564 |
QCOMPARE(cursor.position(), 3); // b |
|
565 |
ok = cursor.movePosition(QTextCursor::NextCell); |
|
566 |
QVERIFY(ok); |
|
567 |
QCOMPARE(cursor.position(), 5); // c |
|
568 |
ok = cursor.movePosition(QTextCursor::PreviousCell); |
|
569 |
QVERIFY(ok); |
|
570 |
QCOMPARE(cursor.position(), 3); // b |
|
571 |
ok = cursor.movePosition(QTextCursor::PreviousCell); |
|
572 |
QVERIFY(ok); |
|
573 |
QCOMPARE(cursor.position(), 1); // a |
|
574 |
} |
|
575 |
||
576 |
void tst_QTextCursor::insertBlock() |
|
577 |
{ |
|
578 |
QTextBlockFormat fmt; |
|
579 |
fmt.setTopMargin(100); |
|
580 |
cursor.insertBlock(fmt); |
|
581 |
QVERIFY(cursor.position() == 1); |
|
582 |
QVERIFY(cursor.blockFormat() == fmt); |
|
583 |
} |
|
584 |
||
585 |
void tst_QTextCursor::insertWithBlockSeparator1() |
|
586 |
{ |
|
587 |
QString text = "Hello" + QString(QChar::ParagraphSeparator) + "World"; |
|
588 |
||
589 |
cursor.insertText(text); |
|
590 |
||
591 |
cursor.movePosition(QTextCursor::PreviousBlock); |
|
592 |
QVERIFY(cursor.position() == 0); |
|
593 |
||
594 |
cursor.movePosition(QTextCursor::NextBlock); |
|
595 |
QVERIFY(cursor.position() == 6); |
|
596 |
} |
|
597 |
||
598 |
void tst_QTextCursor::insertWithBlockSeparator2() |
|
599 |
{ |
|
600 |
cursor.insertText(QString(QChar::ParagraphSeparator)); |
|
601 |
QVERIFY(cursor.position() == 1); |
|
602 |
} |
|
603 |
||
604 |
void tst_QTextCursor::insertWithBlockSeparator3() |
|
605 |
{ |
|
606 |
cursor.insertText(QString(QChar::ParagraphSeparator) + "Hi" + QString(QChar::ParagraphSeparator)); |
|
607 |
QVERIFY(cursor.position() == 4); |
|
608 |
} |
|
609 |
||
610 |
void tst_QTextCursor::insertWithBlockSeparator4() |
|
611 |
{ |
|
612 |
cursor.insertText(QString(QChar::ParagraphSeparator) + QString(QChar::ParagraphSeparator)); |
|
613 |
QVERIFY(cursor.position() == 2); |
|
614 |
} |
|
615 |
||
616 |
void tst_QTextCursor::clearObjectType1() |
|
617 |
{ |
|
618 |
cursor.insertImage("test.png"); |
|
619 |
QVERIFY(cursor.charFormat().isValid()); |
|
620 |
QVERIFY(cursor.charFormat().isImageFormat()); |
|
621 |
cursor.insertText("Hey"); |
|
622 |
QVERIFY(cursor.charFormat().isValid()); |
|
623 |
QVERIFY(!cursor.charFormat().isImageFormat()); |
|
624 |
} |
|
625 |
||
626 |
void tst_QTextCursor::clearObjectType2() |
|
627 |
{ |
|
628 |
cursor.insertImage("test.png"); |
|
629 |
QVERIFY(cursor.charFormat().isValid()); |
|
630 |
QVERIFY(cursor.charFormat().isImageFormat()); |
|
631 |
cursor.insertBlock(); |
|
632 |
QVERIFY(cursor.charFormat().isValid()); |
|
633 |
QVERIFY(!cursor.charFormat().isImageFormat()); |
|
634 |
} |
|
635 |
||
636 |
void tst_QTextCursor::clearObjectType3() |
|
637 |
{ |
|
638 |
// like clearObjectType2 but tests different insertBlock overload |
|
639 |
cursor.insertImage("test.png"); |
|
640 |
QVERIFY(cursor.charFormat().isValid()); |
|
641 |
QVERIFY(cursor.charFormat().isImageFormat()); |
|
642 |
QTextBlockFormat bfmt; |
|
643 |
bfmt.setAlignment(Qt::AlignRight); |
|
644 |
cursor.insertBlock(bfmt); |
|
645 |
QVERIFY(cursor.charFormat().isValid()); |
|
646 |
QVERIFY(!cursor.charFormat().isImageFormat()); |
|
647 |
} |
|
648 |
||
649 |
void tst_QTextCursor::comparisonOperators1() |
|
650 |
{ |
|
651 |
cursor.insertText("Hello World"); |
|
652 |
||
653 |
cursor.movePosition(QTextCursor::PreviousWord); |
|
654 |
||
655 |
QTextCursor startCursor = cursor; |
|
656 |
startCursor.movePosition(QTextCursor::Start); |
|
657 |
||
658 |
QVERIFY(startCursor < cursor); |
|
659 |
||
660 |
QTextCursor midCursor = startCursor; |
|
661 |
midCursor.movePosition(QTextCursor::NextWord); |
|
662 |
||
663 |
QVERIFY(midCursor <= cursor); |
|
664 |
QVERIFY(midCursor == cursor); |
|
665 |
QVERIFY(midCursor >= cursor); |
|
666 |
||
667 |
QVERIFY(midCursor > startCursor); |
|
668 |
||
669 |
QVERIFY(midCursor != startCursor); |
|
670 |
QVERIFY(!(midCursor == startCursor)); |
|
671 |
||
672 |
QTextCursor nullCursor; |
|
673 |
||
674 |
QVERIFY(!(startCursor < nullCursor)); |
|
675 |
QVERIFY(!(nullCursor < nullCursor)); |
|
676 |
QVERIFY(nullCursor < startCursor); |
|
677 |
||
678 |
QVERIFY(nullCursor <= startCursor); |
|
679 |
QVERIFY(!(startCursor <= nullCursor)); |
|
680 |
||
681 |
QVERIFY(!(nullCursor >= startCursor)); |
|
682 |
QVERIFY(startCursor >= nullCursor); |
|
683 |
||
684 |
QVERIFY(!(nullCursor > startCursor)); |
|
685 |
QVERIFY(!(nullCursor > nullCursor)); |
|
686 |
QVERIFY(startCursor > nullCursor); |
|
687 |
} |
|
688 |
||
689 |
void tst_QTextCursor::comparisonOperators2() |
|
690 |
{ |
|
691 |
QTextDocument doc1; |
|
692 |
QTextDocument doc2; |
|
693 |
||
694 |
QTextCursor cursor1(&doc1); |
|
695 |
QTextCursor cursor2(&doc2); |
|
696 |
||
697 |
QVERIFY(cursor1 != cursor2); |
|
698 |
QVERIFY(cursor1 == QTextCursor(&doc1)); |
|
699 |
} |
|
700 |
||
701 |
void tst_QTextCursor::selection1() |
|
702 |
{ |
|
703 |
cursor.insertText("Hello World"); |
|
704 |
||
705 |
cursor.setPosition(0); |
|
706 |
cursor.clearSelection(); |
|
707 |
cursor.setPosition(4, QTextCursor::KeepAnchor); |
|
708 |
||
709 |
QCOMPARE(cursor.selectionStart(), 0); |
|
710 |
QCOMPARE(cursor.selectionEnd(), 4); |
|
711 |
} |
|
712 |
||
713 |
void tst_QTextCursor::dontCopyTableAttributes() |
|
714 |
{ |
|
715 |
/* when pressing 'enter' inside a cell it shouldn't |
|
716 |
* enlarge the table by adding another cell but just |
|
717 |
* extend the cell */ |
|
718 |
QTextTable *table = cursor.insertTable(2, 2); |
|
719 |
QVERIFY(cursor == table->cellAt(0, 0).firstCursorPosition()); |
|
720 |
cursor.insertBlock(); |
|
721 |
QCOMPARE(table->columns(), 2); |
|
722 |
} |
|
723 |
||
724 |
void tst_QTextCursor::checkFrame1() |
|
725 |
{ |
|
726 |
QVERIFY(cursor.position() == 0); |
|
727 |
QPointer<QTextFrame> frame = cursor.insertFrame(QTextFrameFormat()); |
|
728 |
QVERIFY(frame != 0); |
|
729 |
||
730 |
QTextFrame *root = frame->parentFrame(); |
|
731 |
QVERIFY(root != 0); |
|
732 |
||
733 |
QVERIFY(frame->firstPosition() == 1); |
|
734 |
QVERIFY(frame->lastPosition() == 1); |
|
735 |
QVERIFY(frame->parentFrame() != 0); |
|
736 |
QVERIFY(root->childFrames().size() == 1); |
|
737 |
||
738 |
QVERIFY(cursor.position() == 1); |
|
739 |
QVERIFY(cursor.selectionStart() == 1); |
|
740 |
QVERIFY(cursor.selectionEnd() == 1); |
|
741 |
||
742 |
doc->undo(); |
|
743 |
||
744 |
QVERIFY(!frame); |
|
745 |
QVERIFY(root->childFrames().size() == 0); |
|
746 |
||
747 |
QVERIFY(cursor.position() == 0); |
|
748 |
QVERIFY(cursor.selectionStart() == 0); |
|
749 |
QVERIFY(cursor.selectionEnd() == 0); |
|
750 |
||
751 |
doc->redo(); |
|
752 |
||
753 |
frame = doc->frameAt(1); |
|
754 |
||
755 |
QVERIFY(frame); |
|
756 |
QVERIFY(frame->firstPosition() == 1); |
|
757 |
QVERIFY(frame->lastPosition() == 1); |
|
758 |
QVERIFY(frame->parentFrame() != 0); |
|
759 |
QVERIFY(root->childFrames().size() == 1); |
|
760 |
||
761 |
QVERIFY(cursor.position() == 1); |
|
762 |
QVERIFY(cursor.selectionStart() == 1); |
|
763 |
QVERIFY(cursor.selectionEnd() == 1); |
|
764 |
||
765 |
// cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor); |
|
766 |
// QVERIFY(cursor.position() == 2); |
|
767 |
// QVERIFY(cursor.selectionStart() == 0); |
|
768 |
// QVERIFY(cursor.selectionEnd() == 2); |
|
769 |
} |
|
770 |
||
771 |
void tst_QTextCursor::checkFrame2() |
|
772 |
{ |
|
773 |
QVERIFY(cursor.position() == 0); |
|
774 |
cursor.insertText("A"); |
|
775 |
QVERIFY(cursor.position() == 1); |
|
776 |
cursor.movePosition(QTextCursor::Start, QTextCursor::KeepAnchor); |
|
777 |
||
778 |
QPointer<QTextFrame> frame = cursor.insertFrame(QTextFrameFormat()); |
|
779 |
QTextFrame *root = frame->parentFrame(); |
|
780 |
||
781 |
QVERIFY(frame->firstPosition() == 1); |
|
782 |
QVERIFY(frame->lastPosition() == 2); |
|
783 |
QVERIFY(frame->parentFrame() != 0); |
|
784 |
QVERIFY(root->childFrames().size() == 1); |
|
785 |
||
786 |
QVERIFY(cursor.position() == 1); |
|
787 |
QVERIFY(cursor.selectionStart() == 1); |
|
788 |
QVERIFY(cursor.selectionEnd() == 2); |
|
789 |
||
790 |
doc->undo(); |
|
791 |
||
792 |
QVERIFY(!frame); |
|
793 |
QVERIFY(root->childFrames().size() == 0); |
|
794 |
||
795 |
QVERIFY(cursor.position() == 0); |
|
796 |
QVERIFY(cursor.selectionStart() == 0); |
|
797 |
QVERIFY(cursor.selectionEnd() == 1); |
|
798 |
||
799 |
doc->redo(); |
|
800 |
||
801 |
frame = doc->frameAt(1); |
|
802 |
||
803 |
QVERIFY(frame); |
|
804 |
QVERIFY(frame->firstPosition() == 1); |
|
805 |
QVERIFY(frame->lastPosition() == 2); |
|
806 |
QVERIFY(frame->parentFrame() != 0); |
|
807 |
QVERIFY(root->childFrames().size() == 1); |
|
808 |
||
809 |
QVERIFY(cursor.position() == 1); |
|
810 |
QVERIFY(cursor.selectionStart() == 1); |
|
811 |
QVERIFY(cursor.selectionEnd() == 2); |
|
812 |
||
813 |
cursor.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor); |
|
814 |
QVERIFY(cursor.position() == 0); |
|
815 |
QVERIFY(cursor.selectionStart() == 0); |
|
816 |
QVERIFY(cursor.selectionEnd() == 3); |
|
817 |
} |
|
818 |
||
819 |
void tst_QTextCursor::insertBlockToUseCharFormat() |
|
820 |
{ |
|
821 |
QTextCharFormat fmt; |
|
822 |
fmt.setForeground(Qt::blue); |
|
823 |
cursor.insertText("Hello", fmt); |
|
824 |
QCOMPARE(cursor.charFormat().foreground().color(), QColor(Qt::blue)); |
|
825 |
||
826 |
cursor.insertBlock(); |
|
827 |
QCOMPARE(cursor.charFormat().foreground().color(), QColor(Qt::blue)); |
|
828 |
||
829 |
fmt.setForeground(Qt::red); |
|
830 |
cursor.insertText("Hello\nWorld", fmt); |
|
831 |
cursor.insertText("Blah"); |
|
832 |
QCOMPARE(cursor.charFormat().foreground().color(), QColor(Qt::red)); |
|
833 |
||
834 |
// ### we might want a testcase for createTable, too, as it calls insertBlock, too, |
|
835 |
// and we might want to have the char format copied (the one that gets inserted |
|
836 |
// as table separators, that are undeletable) |
|
837 |
} |
|
838 |
||
839 |
void tst_QTextCursor::tableMovement() |
|
840 |
{ |
|
841 |
QVERIFY(cursor.position() == 0); |
|
842 |
cursor.insertText("AA"); |
|
843 |
QVERIFY(cursor.position() == 2); |
|
844 |
cursor.movePosition(QTextCursor::Left); |
|
845 |
||
846 |
cursor.insertTable(3, 3); |
|
847 |
QCOMPARE(cursor.position(), 2); |
|
848 |
||
849 |
cursor.movePosition(QTextCursor::Down); |
|
850 |
QCOMPARE(cursor.position(), 5); |
|
851 |
||
852 |
cursor.movePosition(QTextCursor::Right); |
|
853 |
QCOMPARE(cursor.position(), 6); |
|
854 |
||
855 |
cursor.movePosition(QTextCursor::Up); |
|
856 |
QCOMPARE(cursor.position(), 3); |
|
857 |
||
858 |
cursor.movePosition(QTextCursor::Right); |
|
859 |
QCOMPARE(cursor.position(), 4); |
|
860 |
||
861 |
cursor.movePosition(QTextCursor::Right); |
|
862 |
QCOMPARE(cursor.position(), 5); |
|
863 |
||
864 |
cursor.movePosition(QTextCursor::Up); |
|
865 |
QCOMPARE(cursor.position(), 2); |
|
866 |
||
867 |
cursor.movePosition(QTextCursor::Up); |
|
868 |
QCOMPARE(cursor.position(), 0); |
|
869 |
||
870 |
} |
|
871 |
||
872 |
void tst_QTextCursor::selectionsInTable() |
|
873 |
{ |
|
874 |
QTextTable *table = cursor.insertTable(2, 2); |
|
875 |
table->cellAt(0, 0).firstCursorPosition().insertText("First"); |
|
876 |
table->cellAt(0, 1).firstCursorPosition().insertText("Second"); |
|
877 |
table->cellAt(1, 0).firstCursorPosition().insertText("Third"); |
|
878 |
table->cellAt(1, 1).firstCursorPosition().insertText("Fourth"); |
|
879 |
||
880 |
cursor = table->cellAt(0, 0).lastCursorPosition(); |
|
881 |
QVERIFY(cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor)); |
|
882 |
QVERIFY(cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor) == false); |
|
883 |
||
884 |
cursor = table->cellAt(1, 0).lastCursorPosition(); |
|
885 |
QVERIFY(cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor)); |
|
886 |
QVERIFY(cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor) == false); |
|
887 |
||
888 |
cursor = table->cellAt(0, 1).firstCursorPosition(); |
|
889 |
QVERIFY(cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor)); |
|
890 |
QVERIFY(cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor) == false); |
|
891 |
||
892 |
cursor = table->cellAt(1, 1).firstCursorPosition(); |
|
893 |
QVERIFY(cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor)); |
|
894 |
QVERIFY(cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor) == false); |
|
895 |
} |
|
896 |
||
897 |
void tst_QTextCursor::selectedText() |
|
898 |
{ |
|
899 |
cursor.insertText("Hello World"); |
|
900 |
cursor.movePosition(QTextCursor::Start); |
|
901 |
cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor); |
|
902 |
||
903 |
QCOMPARE(cursor.selectedText(), QString("Hello World")); |
|
904 |
} |
|
905 |
||
906 |
void tst_QTextCursor::insertBlockShouldRemoveSelection() |
|
907 |
{ |
|
908 |
cursor.insertText("Hello World"); |
|
909 |
cursor.movePosition(QTextCursor::Start); |
|
910 |
cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor); |
|
911 |
||
912 |
QVERIFY(cursor.hasSelection()); |
|
913 |
QCOMPARE(cursor.selectedText(), QString("Hello")); |
|
914 |
||
915 |
cursor.insertBlock(); |
|
916 |
||
917 |
QVERIFY(!cursor.hasSelection()); |
|
918 |
QVERIFY(doc->toPlainText().indexOf("Hello") == -1); |
|
919 |
} |
|
920 |
||
921 |
void tst_QTextCursor::insertBlockShouldRemoveSelection2() |
|
922 |
{ |
|
923 |
cursor.insertText("Hello World"); |
|
924 |
cursor.movePosition(QTextCursor::Start); |
|
925 |
cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor); |
|
926 |
||
927 |
QVERIFY(cursor.hasSelection()); |
|
928 |
QCOMPARE(cursor.selectedText(), QString("Hello")); |
|
929 |
||
930 |
QTextBlockFormat fmt = cursor.blockFormat(); |
|
931 |
cursor.insertBlock(fmt); |
|
932 |
||
933 |
QVERIFY(!cursor.hasSelection()); |
|
934 |
QVERIFY(doc->toPlainText().indexOf("Hello") == -1); |
|
935 |
} |
|
936 |
||
937 |
void tst_QTextCursor::mergeCellShouldUpdateSelection() |
|
938 |
{ |
|
939 |
QTextTable *table = cursor.insertTable(4, 4); |
|
940 |
cursor.setPosition(table->cellAt(0, 0).firstPosition()); |
|
941 |
cursor.setPosition(table->cellAt(3, 0).firstPosition(), QTextCursor::KeepAnchor); // aka bottom left |
|
942 |
int firstRow, numRows, firstColumn, numColumns; |
|
943 |
cursor.selectedTableCells(&firstRow, &numRows, &firstColumn, &numColumns); |
|
944 |
QCOMPARE(firstRow, 0); |
|
945 |
QCOMPARE(numRows, 4); |
|
946 |
QCOMPARE(firstColumn, 0); |
|
947 |
QCOMPARE(numColumns, 1); |
|
948 |
||
949 |
table->removeColumns(firstColumn, numColumns); |
|
950 |
||
951 |
QCOMPARE(cursor.anchor(), table->cellAt(0, 0).firstPosition()); |
|
952 |
QCOMPARE(cursor.position(), table->cellAt(0, 0).firstPosition()); |
|
953 |
QCOMPARE(cursor.position(), cursor.anchor()); // empty. I don't really care where it ends up. |
|
954 |
||
955 |
// prepare for another test with multiple cursors. |
|
956 |
// note we have a 4 rows, 3 cols table now. |
|
957 |
cursor.setPosition(table->cellAt(0, 0).firstPosition()); |
|
958 |
cursor.setPosition(table->cellAt(0, 2).firstPosition(), QTextCursor::KeepAnchor); |
|
959 |
||
960 |
// now create a selection of a whole row. |
|
961 |
QTextCursor c2 = table->cellAt(2, 0).firstCursorPosition(); |
|
962 |
c2.setPosition(table->cellAt(2, 2).firstPosition(), QTextCursor::KeepAnchor); |
|
963 |
||
964 |
// just for good measure, another one for a block of cells. |
|
965 |
QTextCursor c3 = table->cellAt(2, 1).firstCursorPosition(); |
|
966 |
c3.setPosition(table->cellAt(3, 2).firstPosition(), QTextCursor::KeepAnchor); |
|
967 |
||
968 |
table->removeRows(2, 1); |
|
969 |
||
970 |
QCOMPARE(cursor.anchor(), table->cellAt(0, 0).firstPosition()); |
|
971 |
QCOMPARE(cursor.position(), table->cellAt(0, 2).firstPosition()); |
|
972 |
||
973 |
QCOMPARE(c2.position(), c2.anchor()); // empty. I don't really care where it ends up. |
|
974 |
||
975 |
QCOMPARE(c3.anchor(), table->cellAt(2, 1).firstPosition()); |
|
976 |
QCOMPARE(c3.position(), table->cellAt(2, 2).firstPosition()); |
|
977 |
||
978 |
||
979 |
// prepare for another test where we remove a column |
|
980 |
// note we have a 3 rows, 3 cols table now. |
|
981 |
cursor.setPosition(table->cellAt(0, 0).firstPosition()); |
|
982 |
cursor.setPosition(table->cellAt(2, 1).firstPosition(), QTextCursor::KeepAnchor); |
|
983 |
||
984 |
c2.setPosition(table->cellAt(0, 1).firstPosition()); |
|
985 |
c2.setPosition(table->cellAt(2, 2).firstPosition(), QTextCursor::KeepAnchor); |
|
986 |
||
987 |
table->removeColumns(1, 1); |
|
988 |
||
989 |
QCOMPARE(cursor.anchor(), table->cellAt(0, 0).firstPosition()); |
|
990 |
QCOMPARE(cursor.position(), table->cellAt(2, 0).firstPosition()); |
|
991 |
||
992 |
QCOMPARE(c2.anchor(), table->cellAt(0, 1).firstPosition()); |
|
993 |
QCOMPARE(c2.position(), table->cellAt(2, 1).firstPosition()); |
|
994 |
||
995 |
// test for illegal cursor positions. |
|
996 |
// note we have a 3 rows, 2 cols table now. |
|
997 |
cursor.setPosition(table->cellAt(2, 0).firstPosition()); |
|
998 |
cursor.setPosition(table->cellAt(2, 1).firstPosition(), QTextCursor::KeepAnchor); |
|
999 |
||
1000 |
c2.setPosition(table->cellAt(0, 0).firstPosition()); |
|
1001 |
c2.setPosition(table->cellAt(2, 1).firstPosition(), QTextCursor::KeepAnchor); |
|
1002 |
||
1003 |
c3.setPosition(table->cellAt(2, 1).firstPosition()); |
|
1004 |
||
1005 |
table->removeRows(2, 1); |
|
1006 |
||
1007 |
QCOMPARE(cursor.anchor(), table->cellAt(1, 1).lastPosition()+1); |
|
1008 |
QCOMPARE(cursor.position(), cursor.anchor()); |
|
1009 |
||
1010 |
QCOMPARE(c2.anchor(), table->cellAt(0, 0).firstPosition()); |
|
1011 |
QCOMPARE(c2.position(), table->cellAt(1, 1).firstPosition()); |
|
1012 |
||
1013 |
QCOMPARE(c3.anchor(), table->cellAt(1, 1).firstPosition()); |
|
1014 |
QCOMPARE(c3.position(), table->cellAt(1, 1).firstPosition()); |
|
1015 |
} |
|
1016 |
||
1017 |
void tst_QTextCursor::joinPreviousEditBlock() |
|
1018 |
{ |
|
1019 |
cursor.beginEditBlock(); |
|
1020 |
cursor.insertText("Hello"); |
|
1021 |
cursor.insertText("World"); |
|
1022 |
cursor.endEditBlock(); |
|
1023 |
QVERIFY(doc->toPlainText().startsWith("HelloWorld")); |
|
1024 |
||
1025 |
cursor.joinPreviousEditBlock(); |
|
1026 |
cursor.insertText("Hey"); |
|
1027 |
cursor.endEditBlock(); |
|
1028 |
QVERIFY(doc->toPlainText().startsWith("HelloWorldHey")); |
|
1029 |
||
1030 |
doc->undo(); |
|
1031 |
QVERIFY(!doc->toPlainText().contains("HelloWorldHey")); |
|
1032 |
} |
|
1033 |
||
1034 |
void tst_QTextCursor::setBlockFormatInTable() |
|
1035 |
{ |
|
1036 |
// someone reported this on qt4-preview-feedback |
|
1037 |
QTextBlockFormat fmt; |
|
1038 |
fmt.setBackground(Qt::blue); |
|
1039 |
cursor.setBlockFormat(fmt); |
|
1040 |
||
1041 |
QTextTable *table = cursor.insertTable(2, 2); |
|
1042 |
cursor = table->cellAt(0, 0).firstCursorPosition(); |
|
1043 |
fmt.setBackground(Qt::red); |
|
1044 |
cursor.setBlockFormat(fmt); |
|
1045 |
||
1046 |
cursor.movePosition(QTextCursor::Start); |
|
1047 |
QVERIFY(cursor.blockFormat().background().color() == Qt::blue); |
|
1048 |
} |
|
1049 |
||
1050 |
void tst_QTextCursor::blockCharFormat2() |
|
1051 |
{ |
|
1052 |
QTextCharFormat fmt; |
|
1053 |
fmt.setForeground(Qt::green); |
|
1054 |
cursor.mergeBlockCharFormat(fmt); |
|
1055 |
||
1056 |
fmt.setForeground(Qt::red); |
|
1057 |
||
1058 |
cursor.insertText("Test", fmt); |
|
1059 |
cursor.movePosition(QTextCursor::Start); |
|
1060 |
cursor.insertText("Red"); |
|
1061 |
cursor.movePosition(QTextCursor::PreviousCharacter); |
|
1062 |
QVERIFY(cursor.charFormat().foreground().color() == Qt::red); |
|
1063 |
} |
|
1064 |
||
1065 |
void tst_QTextCursor::blockCharFormat3() |
|
1066 |
{ |
|
1067 |
QVERIFY(cursor.atBlockStart()); |
|
1068 |
QVERIFY(cursor.atBlockEnd()); |
|
1069 |
QVERIFY(cursor.atStart()); |
|
1070 |
||
1071 |
QTextCharFormat fmt; |
|
1072 |
fmt.setForeground(Qt::green); |
|
1073 |
cursor.setBlockCharFormat(fmt); |
|
1074 |
cursor.insertText("Test"); |
|
1075 |
cursor.movePosition(QTextCursor::Start); |
|
1076 |
cursor.movePosition(QTextCursor::NextCharacter); |
|
1077 |
QVERIFY(cursor.charFormat().foreground().color() == Qt::green); |
|
1078 |
||
1079 |
cursor.movePosition(QTextCursor::Start); |
|
1080 |
QVERIFY(cursor.charFormat().foreground().color() == Qt::green); |
|
1081 |
||
1082 |
fmt.setForeground(Qt::red); |
|
1083 |
cursor.setBlockCharFormat(fmt); |
|
1084 |
QVERIFY(cursor.blockCharFormat().foreground().color() == Qt::red); |
|
1085 |
||
1086 |
cursor.movePosition(QTextCursor::End); |
|
1087 |
cursor.movePosition(QTextCursor::Start); |
|
1088 |
QVERIFY(cursor.charFormat().foreground().color() == Qt::green); |
|
1089 |
||
1090 |
cursor.insertText("Test"); |
|
1091 |
QVERIFY(cursor.charFormat().foreground().color() == Qt::green); |
|
1092 |
||
1093 |
cursor.select(QTextCursor::Document); |
|
1094 |
cursor.removeSelectedText(); |
|
1095 |
QVERIFY(cursor.atBlockStart()); |
|
1096 |
QVERIFY(cursor.atBlockEnd()); |
|
1097 |
QVERIFY(cursor.atStart()); |
|
1098 |
||
1099 |
cursor.insertText("Test"); |
|
1100 |
QVERIFY(cursor.charFormat().foreground().color() == Qt::red); |
|
1101 |
} |
|
1102 |
||
1103 |
void tst_QTextCursor::blockCharFormat() |
|
1104 |
{ |
|
1105 |
QTextCharFormat fmt; |
|
1106 |
fmt.setForeground(Qt::blue); |
|
1107 |
cursor.insertBlock(QTextBlockFormat(), fmt); |
|
1108 |
cursor.insertText("Hm"); |
|
1109 |
||
1110 |
QVERIFY(cursor.blockCharFormat().foreground().color() == Qt::blue); |
|
1111 |
||
1112 |
fmt.setForeground(Qt::red); |
|
1113 |
||
1114 |
cursor.setBlockCharFormat(fmt); |
|
1115 |
QVERIFY(cursor.blockCharFormat().foreground().color() == Qt::red); |
|
1116 |
} |
|
1117 |
||
1118 |
void tst_QTextCursor::blockCharFormatOnSelection() |
|
1119 |
{ |
|
1120 |
QTextCharFormat fmt; |
|
1121 |
fmt.setForeground(Qt::blue); |
|
1122 |
cursor.insertBlock(QTextBlockFormat(), fmt); |
|
1123 |
||
1124 |
fmt.setForeground(Qt::green); |
|
1125 |
cursor.insertText("Hm", fmt); |
|
1126 |
||
1127 |
fmt.setForeground(Qt::red); |
|
1128 |
cursor.insertBlock(QTextBlockFormat(), fmt); |
|
1129 |
cursor.insertText("Ah"); |
|
1130 |
||
1131 |
fmt.setForeground(Qt::white); |
|
1132 |
cursor.insertBlock(QTextBlockFormat(), fmt); |
|
1133 |
cursor.insertText("bleh"); |
|
1134 |
||
1135 |
cursor.movePosition(QTextCursor::Start); |
|
1136 |
cursor.movePosition(QTextCursor::NextBlock); |
|
1137 |
QVERIFY(cursor.blockCharFormat().foreground().color() == Qt::blue); |
|
1138 |
cursor.movePosition(QTextCursor::NextBlock); |
|
1139 |
QVERIFY(cursor.blockCharFormat().foreground().color() == Qt::red); |
|
1140 |
cursor.movePosition(QTextCursor::NextBlock); |
|
1141 |
QVERIFY(cursor.blockCharFormat().foreground().color() == Qt::white); |
|
1142 |
||
1143 |
cursor.movePosition(QTextCursor::Start); |
|
1144 |
cursor.movePosition(QTextCursor::NextBlock); |
|
1145 |
cursor.movePosition(QTextCursor::NextBlock, QTextCursor::KeepAnchor); |
|
1146 |
||
1147 |
fmt.setForeground(Qt::cyan); |
|
1148 |
cursor.setBlockCharFormat(fmt); |
|
1149 |
||
1150 |
cursor.movePosition(QTextCursor::Start); |
|
1151 |
cursor.movePosition(QTextCursor::NextBlock); |
|
1152 |
QVERIFY(cursor.blockCharFormat().foreground().color() == Qt::cyan); |
|
1153 |
||
1154 |
cursor.movePosition(QTextCursor::Right); |
|
1155 |
cursor.movePosition(QTextCursor::Right); |
|
1156 |
QVERIFY(cursor.charFormat().foreground().color() == Qt::green); |
|
1157 |
||
1158 |
cursor.movePosition(QTextCursor::NextBlock); |
|
1159 |
QVERIFY(cursor.blockCharFormat().foreground().color() == Qt::cyan); |
|
1160 |
||
1161 |
cursor.movePosition(QTextCursor::NextBlock); |
|
1162 |
QVERIFY(cursor.blockCharFormat().foreground().color() == Qt::white); |
|
1163 |
} |
|
1164 |
||
1165 |
void tst_QTextCursor::anchorInitialized1() |
|
1166 |
{ |
|
1167 |
cursor.insertBlock(); |
|
1168 |
cursor = QTextCursor(cursor.block()); |
|
1169 |
QCOMPARE(cursor.position(), 1); |
|
1170 |
QCOMPARE(cursor.anchor(), 1); |
|
1171 |
QCOMPARE(cursor.selectionStart(), 1); |
|
1172 |
QCOMPARE(cursor.selectionEnd(), 1); |
|
1173 |
} |
|
1174 |
||
1175 |
void tst_QTextCursor::anchorInitialized2() |
|
1176 |
{ |
|
1177 |
cursor.insertBlock(); |
|
1178 |
cursor = QTextCursor(cursor.block().docHandle(), 1); |
|
1179 |
QCOMPARE(cursor.position(), 1); |
|
1180 |
QCOMPARE(cursor.anchor(), 1); |
|
1181 |
QCOMPARE(cursor.selectionStart(), 1); |
|
1182 |
QCOMPARE(cursor.selectionEnd(), 1); |
|
1183 |
} |
|
1184 |
||
1185 |
void tst_QTextCursor::anchorInitialized3() |
|
1186 |
{ |
|
1187 |
QTextFrame *frame = cursor.insertFrame(QTextFrameFormat()); |
|
1188 |
cursor = QTextCursor(frame); |
|
1189 |
QCOMPARE(cursor.position(), 1); |
|
1190 |
QCOMPARE(cursor.anchor(), 1); |
|
1191 |
QCOMPARE(cursor.selectionStart(), 1); |
|
1192 |
QCOMPARE(cursor.selectionEnd(), 1); |
|
1193 |
} |
|
1194 |
||
1195 |
void tst_QTextCursor::selectWord() |
|
1196 |
{ |
|
1197 |
cursor.insertText("first second third"); |
|
1198 |
cursor.insertBlock(); |
|
1199 |
cursor.insertText("words in second paragraph"); |
|
1200 |
||
1201 |
cursor.setPosition(9); |
|
1202 |
cursor.select(QTextCursor::WordUnderCursor); |
|
1203 |
QVERIFY(cursor.hasSelection()); |
|
1204 |
QCOMPARE(cursor.selectionStart(), 6); |
|
1205 |
QCOMPARE(cursor.selectionEnd(), 12); |
|
1206 |
||
1207 |
cursor.setPosition(5); |
|
1208 |
cursor.select(QTextCursor::WordUnderCursor); |
|
1209 |
QVERIFY(cursor.hasSelection()); |
|
1210 |
QCOMPARE(cursor.selectionStart(), 0); |
|
1211 |
QCOMPARE(cursor.selectionEnd(), 5); |
|
1212 |
||
1213 |
cursor.setPosition(6); |
|
1214 |
cursor.select(QTextCursor::WordUnderCursor); |
|
1215 |
QVERIFY(cursor.hasSelection()); |
|
1216 |
QCOMPARE(cursor.selectionStart(), 6); |
|
1217 |
QCOMPARE(cursor.selectionEnd(), 12); |
|
1218 |
||
1219 |
cursor.setPosition(14); |
|
1220 |
cursor.select(QTextCursor::WordUnderCursor); |
|
1221 |
QVERIFY(cursor.hasSelection()); |
|
1222 |
QCOMPARE(cursor.selectionStart(), 6); |
|
1223 |
QCOMPARE(cursor.selectionEnd(), 12); |
|
1224 |
||
1225 |
cursor.movePosition(QTextCursor::Start); |
|
1226 |
cursor.select(QTextCursor::WordUnderCursor); |
|
1227 |
QVERIFY(cursor.hasSelection()); |
|
1228 |
QCOMPARE(cursor.selectionStart(), 0); |
|
1229 |
QCOMPARE(cursor.selectionEnd(), 5); |
|
1230 |
||
1231 |
cursor.movePosition(QTextCursor::EndOfBlock); |
|
1232 |
cursor.select(QTextCursor::WordUnderCursor); |
|
1233 |
QVERIFY(cursor.hasSelection()); |
|
1234 |
QCOMPARE(cursor.selectionStart(), 17); |
|
1235 |
QCOMPARE(cursor.selectionEnd(), 22); |
|
1236 |
} |
|
1237 |
||
1238 |
void tst_QTextCursor::selectWordWithSeparators_data() |
|
1239 |
{ |
|
1240 |
QTest::addColumn<QString>("text"); |
|
1241 |
QTest::addColumn<int>("initialPosition"); |
|
1242 |
QTest::addColumn<QString>("expectedSelectedText"); |
|
1243 |
||
1244 |
QTest::newRow("dereference") << QString::fromLatin1("foo->bar()") << 1 << QString::fromLatin1("foo"); |
|
1245 |
QTest::newRow("funcsignature") << QString::fromLatin1("bar(int x);") << 1 << QString::fromLatin1("bar"); |
|
1246 |
QTest::newRow("def") << QString::fromLatin1("foo *f;") << 1 << QString::fromLatin1("foo"); |
|
1247 |
} |
|
1248 |
||
1249 |
void tst_QTextCursor::selectWordWithSeparators() |
|
1250 |
{ |
|
1251 |
QFETCH(QString, text); |
|
1252 |
QFETCH(int, initialPosition); |
|
1253 |
QFETCH(QString, expectedSelectedText); |
|
1254 |
||
1255 |
cursor.insertText(text); |
|
1256 |
cursor.setPosition(initialPosition); |
|
1257 |
cursor.select(QTextCursor::WordUnderCursor); |
|
1258 |
||
1259 |
QCOMPARE(cursor.selectedText(), expectedSelectedText); |
|
1260 |
} |
|
1261 |
||
1262 |
void tst_QTextCursor::startOfWord() |
|
1263 |
{ |
|
1264 |
cursor.insertText("first second"); |
|
1265 |
cursor.setPosition(7); |
|
1266 |
cursor.movePosition(QTextCursor::StartOfWord); |
|
1267 |
QCOMPARE(cursor.position(), 0); |
|
1268 |
} |
|
1269 |
||
1270 |
void tst_QTextCursor::selectBlock() |
|
1271 |
{ |
|
1272 |
cursor.insertText("foobar"); |
|
1273 |
QTextBlockFormat blockFmt; |
|
1274 |
blockFmt.setAlignment(Qt::AlignHCenter); |
|
1275 |
cursor.insertBlock(blockFmt); |
|
1276 |
cursor.insertText("blah"); |
|
1277 |
cursor.insertBlock(QTextBlockFormat()); |
|
1278 |
||
1279 |
cursor.movePosition(QTextCursor::PreviousBlock); |
|
1280 |
QCOMPARE(cursor.block().text(), QString("blah")); |
|
1281 |
||
1282 |
cursor.select(QTextCursor::BlockUnderCursor); |
|
1283 |
QVERIFY(cursor.hasSelection()); |
|
1284 |
||
1285 |
QTextDocumentFragment fragment(cursor); |
|
1286 |
doc->clear(); |
|
1287 |
cursor.insertFragment(fragment); |
|
1288 |
QCOMPARE(blockCount(), 2); |
|
1289 |
||
1290 |
cursor.movePosition(QTextCursor::Start); |
|
1291 |
cursor.movePosition(QTextCursor::NextBlock); |
|
1292 |
QVERIFY(cursor.blockFormat().alignment() == Qt::AlignHCenter); |
|
1293 |
QCOMPARE(cursor.block().text(), QString("blah")); |
|
1294 |
} |
|
1295 |
||
1296 |
void tst_QTextCursor::selectVisually() |
|
1297 |
{ |
|
1298 |
cursor.insertText("Foo\nlong line which is probably going to be cut in two when shown in a widget\nparagraph 3\n"); |
|
1299 |
||
1300 |
cursor.setPosition(6); // somewhere in the long paragraph. |
|
1301 |
cursor.select(QTextCursor::LineUnderCursor); |
|
1302 |
// since we are not yet layed-out, we expect the whole paragraph to be selected. |
|
1303 |
QCOMPARE(cursor.position(), 77); |
|
1304 |
QCOMPARE(cursor.anchor(), 4); |
|
1305 |
} |
|
1306 |
||
1307 |
void tst_QTextCursor::insertText() |
|
1308 |
{ |
|
1309 |
QString txt = "Foo\nBar\r\nMeep"; |
|
1310 |
txt += QChar::LineSeparator; |
|
1311 |
txt += "Baz"; |
|
1312 |
txt += QChar::ParagraphSeparator; |
|
1313 |
txt += "yoyodyne"; |
|
1314 |
cursor.insertText(txt); |
|
1315 |
QCOMPARE(blockCount(), 4); |
|
1316 |
cursor.movePosition(QTextCursor::Start); |
|
1317 |
QCOMPARE(cursor.block().text(), QString("Foo")); |
|
1318 |
cursor.movePosition(QTextCursor::NextBlock); |
|
1319 |
QCOMPARE(cursor.block().text(), QString("Bar")); |
|
1320 |
cursor.movePosition(QTextCursor::NextBlock); |
|
1321 |
QCOMPARE(cursor.block().text(), QString(QString("Meep") + QChar(QChar::LineSeparator) + QString("Baz"))); |
|
1322 |
cursor.movePosition(QTextCursor::NextBlock); |
|
1323 |
QCOMPARE(cursor.block().text(), QString("yoyodyne")); |
|
1324 |
} |
|
1325 |
||
1326 |
void tst_QTextCursor::insertFragmentShouldUseCurrentCharFormat() |
|
1327 |
{ |
|
1328 |
QTextDocumentFragment fragment = QTextDocumentFragment::fromPlainText("Hello World"); |
|
1329 |
QTextCharFormat fmt; |
|
1330 |
fmt.setFontUnderline(true); |
|
1331 |
||
1332 |
cursor.clearSelection(); |
|
1333 |
cursor.setCharFormat(fmt); |
|
1334 |
cursor.insertFragment(fragment); |
|
1335 |
cursor.movePosition(QTextCursor::Start); |
|
1336 |
cursor.movePosition(QTextCursor::NextCharacter); |
|
1337 |
QVERIFY(cursor.charFormat() == fmt); |
|
1338 |
} |
|
1339 |
||
1340 |
int tst_QTextCursor::blockCount() |
|
1341 |
{ |
|
1342 |
int cnt = 0; |
|
1343 |
for (QTextBlock blk = doc->begin(); blk.isValid(); blk = blk.next()) |
|
1344 |
++cnt; |
|
1345 |
return cnt; |
|
1346 |
} |
|
1347 |
||
1348 |
void tst_QTextCursor::endOfLine() |
|
1349 |
{ |
|
1350 |
doc->setPageSize(QSizeF(100000, INT_MAX)); |
|
1351 |
||
1352 |
QString text("First Line \nSecond Line "); |
|
1353 |
text.replace(QLatin1Char('\n'), QChar(QChar::LineSeparator)); |
|
1354 |
cursor.insertText(text); |
|
1355 |
||
1356 |
// ensure layouted |
|
1357 |
doc->documentLayout()->documentSize(); |
|
1358 |
||
1359 |
cursor.movePosition(QTextCursor::Start); |
|
1360 |
||
1361 |
QCOMPARE(cursor.block().layout()->lineCount(), 2); |
|
1362 |
||
1363 |
cursor.movePosition(QTextCursor::EndOfLine); |
|
1364 |
QCOMPARE(cursor.position(), 14); |
|
1365 |
cursor.movePosition(QTextCursor::NextCharacter); |
|
1366 |
QCOMPARE(cursor.position(), 15); |
|
1367 |
cursor.movePosition(QTextCursor::EndOfLine); |
|
1368 |
QCOMPARE(cursor.position(), 28); |
|
1369 |
} |
|
1370 |
||
1371 |
class CursorListener : public QObject |
|
1372 |
{ |
|
1373 |
Q_OBJECT |
|
1374 |
public: |
|
1375 |
CursorListener(QTextCursor *_cursor) : lastRecordedPosition(-1), lastRecordedAnchor(-1), recordingCount(0), cursor(_cursor) {} |
|
1376 |
||
1377 |
int lastRecordedPosition; |
|
1378 |
int lastRecordedAnchor; |
|
1379 |
int recordingCount; |
|
1380 |
||
1381 |
public slots: |
|
1382 |
void recordCursorPosition() |
|
1383 |
{ |
|
1384 |
lastRecordedPosition = cursor->position(); |
|
1385 |
lastRecordedAnchor = cursor->anchor(); |
|
1386 |
++recordingCount; |
|
1387 |
} |
|
1388 |
||
1389 |
private: |
|
1390 |
QTextCursor *cursor; |
|
1391 |
}; |
|
1392 |
||
1393 |
void tst_QTextCursor::editBlocksDuringRemove() |
|
1394 |
{ |
|
1395 |
CursorListener listener(&cursor); |
|
1396 |
||
1397 |
cursor.insertText("Hello World"); |
|
1398 |
cursor.movePosition(QTextCursor::Start, QTextCursor::KeepAnchor); |
|
1399 |
QCOMPARE(cursor.selectedText(), QString("Hello World")); |
|
1400 |
||
1401 |
connect(doc, SIGNAL(contentsChanged()), &listener, SLOT(recordCursorPosition())); |
|
1402 |
listener.recordingCount = 0; |
|
1403 |
cursor.deleteChar(); |
|
1404 |
||
1405 |
QCOMPARE(listener.recordingCount, 1); |
|
1406 |
QCOMPARE(listener.lastRecordedPosition, 0); |
|
1407 |
QCOMPARE(listener.lastRecordedAnchor, 0); |
|
1408 |
||
1409 |
QVERIFY(doc->toPlainText().isEmpty()); |
|
1410 |
} |
|
1411 |
||
1412 |
void tst_QTextCursor::update_data() |
|
1413 |
{ |
|
1414 |
QTest::addColumn<QString>("text"); |
|
1415 |
QTest::addColumn<int>("position"); |
|
1416 |
QTest::addColumn<int>("anchor"); |
|
1417 |
QTest::addColumn<int>("modifyPosition"); |
|
1418 |
QTest::addColumn<int>("modifyAnchor"); |
|
1419 |
QTest::addColumn<QString>("insertText"); |
|
1420 |
QTest::addColumn<int>("expectedPosition"); |
|
1421 |
QTest::addColumn<int>("expectedAnchor"); |
|
1422 |
||
1423 |
QString text("Hello big world"); |
|
1424 |
int charsToDelete = 3; |
|
1425 |
QTest::newRow("removeInsideSelection") |
|
1426 |
<< text |
|
1427 |
<< /*position*/ 0 |
|
1428 |
<< /*anchor*/ text.length() |
|
1429 |
// delete 'big' |
|
1430 |
<< 6 |
|
1431 |
<< 6 + charsToDelete |
|
1432 |
<< QString() // don't insert anything, just remove |
|
1433 |
<< /*expectedPosition*/ 0 |
|
1434 |
<< /*expectedAnchor*/ text.length() - charsToDelete |
|
1435 |
; |
|
1436 |
||
1437 |
text = "Hello big world"; |
|
1438 |
charsToDelete = 3; |
|
1439 |
QTest::newRow("removeInsideSelectionWithSwappedAnchorAndPosition") |
|
1440 |
<< text |
|
1441 |
<< /*position*/ text.length() |
|
1442 |
<< /*anchor*/ 0 |
|
1443 |
// delete 'big' |
|
1444 |
<< 6 |
|
1445 |
<< 6 + charsToDelete |
|
1446 |
<< QString() // don't insert anything, just remove |
|
1447 |
<< /*expectedPosition*/ text.length() - charsToDelete |
|
1448 |
<< /*expectedAnchor*/ 0 |
|
1449 |
; |
|
1450 |
||
1451 |
||
1452 |
text = "Hello big world"; |
|
1453 |
charsToDelete = 3; |
|
1454 |
QString textToInsert("small"); |
|
1455 |
QTest::newRow("replaceInsideSelection") |
|
1456 |
<< text |
|
1457 |
<< /*position*/ 0 |
|
1458 |
<< /*anchor*/ text.length() |
|
1459 |
// delete 'big' ... |
|
1460 |
<< 6 |
|
1461 |
<< 6 + charsToDelete |
|
1462 |
<< textToInsert // ... and replace 'big' with 'small' |
|
1463 |
<< /*expectedPosition*/ 0 |
|
1464 |
<< /*expectedAnchor*/ text.length() - charsToDelete + textToInsert.length() |
|
1465 |
; |
|
1466 |
||
1467 |
text = "Hello big world"; |
|
1468 |
charsToDelete = 3; |
|
1469 |
textToInsert = "small"; |
|
1470 |
QTest::newRow("replaceInsideSelectionWithSwappedAnchorAndPosition") |
|
1471 |
<< text |
|
1472 |
<< /*position*/ text.length() |
|
1473 |
<< /*anchor*/ 0 |
|
1474 |
// delete 'big' ... |
|
1475 |
<< 6 |
|
1476 |
<< 6 + charsToDelete |
|
1477 |
<< textToInsert // ... and replace 'big' with 'small' |
|
1478 |
<< /*expectedPosition*/ text.length() - charsToDelete + textToInsert.length() |
|
1479 |
<< /*expectedAnchor*/ 0 |
|
1480 |
; |
|
1481 |
||
1482 |
||
1483 |
text = "Hello big world"; |
|
1484 |
charsToDelete = 3; |
|
1485 |
QTest::newRow("removeBeforeSelection") |
|
1486 |
<< text |
|
1487 |
<< /*position*/ text.length() - 5 |
|
1488 |
<< /*anchor*/ text.length() |
|
1489 |
// delete 'big' |
|
1490 |
<< 6 |
|
1491 |
<< 6 + charsToDelete |
|
1492 |
<< QString() // don't insert anything, just remove |
|
1493 |
<< /*expectedPosition*/ text.length() - 5 - charsToDelete |
|
1494 |
<< /*expectedAnchor*/ text.length() - charsToDelete |
|
1495 |
; |
|
1496 |
||
1497 |
text = "Hello big world"; |
|
1498 |
charsToDelete = 3; |
|
1499 |
QTest::newRow("removeAfterSelection") |
|
1500 |
<< text |
|
1501 |
<< /*position*/ 0 |
|
1502 |
<< /*anchor*/ 4 |
|
1503 |
// delete 'big' |
|
1504 |
<< 6 |
|
1505 |
<< 6 + charsToDelete |
|
1506 |
<< QString() // don't insert anything, just remove |
|
1507 |
<< /*expectedPosition*/ 0 |
|
1508 |
<< /*expectedAnchor*/ 4 |
|
1509 |
; |
|
1510 |
||
1511 |
} |
|
1512 |
||
1513 |
void tst_QTextCursor::update() |
|
1514 |
{ |
|
1515 |
QFETCH(QString, text); |
|
1516 |
||
1517 |
doc->setPlainText(text); |
|
1518 |
||
1519 |
QFETCH(int, position); |
|
1520 |
QFETCH(int, anchor); |
|
1521 |
||
1522 |
cursor.setPosition(anchor); |
|
1523 |
cursor.setPosition(position, QTextCursor::KeepAnchor); |
|
1524 |
||
1525 |
QCOMPARE(cursor.position(), position); |
|
1526 |
QCOMPARE(cursor.anchor(), anchor); |
|
1527 |
||
1528 |
QFETCH(int, modifyPosition); |
|
1529 |
QFETCH(int, modifyAnchor); |
|
1530 |
||
1531 |
QTextCursor modifyCursor = cursor; |
|
1532 |
modifyCursor.setPosition(modifyAnchor); |
|
1533 |
modifyCursor.setPosition(modifyPosition, QTextCursor::KeepAnchor); |
|
1534 |
||
1535 |
QCOMPARE(modifyCursor.position(), modifyPosition); |
|
1536 |
QCOMPARE(modifyCursor.anchor(), modifyAnchor); |
|
1537 |
||
1538 |
QFETCH(QString, insertText); |
|
1539 |
modifyCursor.insertText(insertText); |
|
1540 |
||
1541 |
QFETCH(int, expectedPosition); |
|
1542 |
QFETCH(int, expectedAnchor); |
|
1543 |
||
1544 |
QCOMPARE(cursor.position(), expectedPosition); |
|
1545 |
QCOMPARE(cursor.anchor(), expectedAnchor); |
|
1546 |
} |
|
1547 |
||
1548 |
void tst_QTextCursor::disallowSettingObjectIndicesOnCharFormats() |
|
1549 |
{ |
|
1550 |
QTextCharFormat fmt; |
|
1551 |
fmt.setObjectIndex(42); |
|
1552 |
cursor.insertText("Hey", fmt); |
|
1553 |
QCOMPARE(cursor.charFormat().objectIndex(), -1); |
|
1554 |
||
1555 |
cursor.select(QTextCursor::Document); |
|
1556 |
cursor.mergeCharFormat(fmt); |
|
1557 |
QCOMPARE(doc->begin().begin().fragment().charFormat().objectIndex(), -1); |
|
1558 |
||
1559 |
cursor.select(QTextCursor::Document); |
|
1560 |
cursor.setCharFormat(fmt); |
|
1561 |
QCOMPARE(doc->begin().begin().fragment().charFormat().objectIndex(), -1); |
|
1562 |
||
1563 |
cursor.setBlockCharFormat(fmt); |
|
1564 |
QCOMPARE(cursor.blockCharFormat().objectIndex(), -1); |
|
1565 |
||
1566 |
cursor.movePosition(QTextCursor::End); |
|
1567 |
cursor.insertBlock(QTextBlockFormat(), fmt); |
|
1568 |
QCOMPARE(cursor.blockCharFormat().objectIndex(), -1); |
|
1569 |
||
1570 |
doc->clear(); |
|
1571 |
||
1572 |
QTextTable *table = cursor.insertTable(1, 1); |
|
1573 |
cursor.select(QTextCursor::Document); |
|
1574 |
cursor.setCharFormat(fmt); |
|
1575 |
||
1576 |
cursor = table->cellAt(0, 0).firstCursorPosition(); |
|
1577 |
QVERIFY(!cursor.isNull()); |
|
1578 |
QCOMPARE(cursor.blockCharFormat().objectIndex(), table->objectIndex()); |
|
1579 |
} |
|
1580 |
||
1581 |
void tst_QTextCursor::blockAndColumnNumber() |
|
1582 |
{ |
|
1583 |
QCOMPARE(QTextCursor().columnNumber(), 0); |
|
1584 |
QCOMPARE(QTextCursor().blockNumber(), 0); |
|
1585 |
||
1586 |
QCOMPARE(cursor.columnNumber(), 0); |
|
1587 |
QCOMPARE(cursor.blockNumber(), 0); |
|
1588 |
cursor.insertText("Hello"); |
|
1589 |
QCOMPARE(cursor.columnNumber(), 5); |
|
1590 |
QCOMPARE(cursor.blockNumber(), 0); |
|
1591 |
||
1592 |
cursor.insertBlock(); |
|
1593 |
QCOMPARE(cursor.columnNumber(), 0); |
|
1594 |
QCOMPARE(cursor.blockNumber(), 1); |
|
1595 |
cursor.insertText("Blah"); |
|
1596 |
QCOMPARE(cursor.blockNumber(), 1); |
|
1597 |
||
1598 |
// trigger a layout |
|
1599 |
doc->documentLayout(); |
|
1600 |
||
1601 |
cursor.insertBlock(); |
|
1602 |
QCOMPARE(cursor.columnNumber(), 0); |
|
1603 |
QCOMPARE(cursor.blockNumber(), 2); |
|
1604 |
cursor.insertText("Test"); |
|
1605 |
QCOMPARE(cursor.columnNumber(), 4); |
|
1606 |
QCOMPARE(cursor.blockNumber(), 2); |
|
1607 |
cursor.insertText(QString(QChar(QChar::LineSeparator))); |
|
1608 |
QCOMPARE(cursor.columnNumber(), 0); |
|
1609 |
QCOMPARE(cursor.blockNumber(), 2); |
|
1610 |
cursor.insertText("A"); |
|
1611 |
QCOMPARE(cursor.columnNumber(), 1); |
|
1612 |
QCOMPARE(cursor.blockNumber(), 2); |
|
1613 |
} |
|
1614 |
||
1615 |
void tst_QTextCursor::movePositionEndOfLine() |
|
1616 |
{ |
|
1617 |
cursor.insertText("blah\nblah\n"); |
|
1618 |
// Select part of the second line ("la") |
|
1619 |
cursor.setPosition(6); |
|
1620 |
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, 2); |
|
1621 |
QCOMPARE(cursor.selectedText(), QLatin1String("la")); |
|
1622 |
||
1623 |
// trigger a layout |
|
1624 |
doc->documentLayout(); |
|
1625 |
||
1626 |
// Remove "la" and append "something" to the end in one undo operation |
|
1627 |
cursor.beginEditBlock(); |
|
1628 |
cursor.removeSelectedText(); |
|
1629 |
QTextCursor c2(doc); |
|
1630 |
c2.setPosition(7); |
|
1631 |
c2.insertText("foo"); // append to doc without touching the cursor. |
|
1632 |
||
1633 |
QCOMPARE(cursor.position(), 6); |
|
1634 |
cursor.movePosition(QTextCursor::EndOfLine); // in an edit block visual movement is moved to the end of the paragraph |
|
1635 |
QCOMPARE(cursor.position(), 10); |
|
1636 |
cursor.endEditBlock(); |
|
1637 |
} |
|
1638 |
||
1639 |
void tst_QTextCursor::clearCells() |
|
1640 |
{ |
|
1641 |
QTextTable *table = cursor.insertTable(3, 5); |
|
1642 |
cursor.setPosition(table->cellAt(0,0).firstPosition()); // select cell 1 and cell 2 |
|
1643 |
cursor.setPosition(table->cellAt(0,1).firstPosition(), QTextCursor::KeepAnchor); |
|
1644 |
cursor.deleteChar(); // should clear the cells, and not crash ;) |
|
1645 |
} |
|
1646 |
||
1647 |
void tst_QTextCursor::task244408_wordUnderCursor_data() |
|
1648 |
{ |
|
1649 |
QTest::addColumn<QString>("input"); |
|
1650 |
QTest::addColumn<QString>("expected"); |
|
1651 |
QTest::newRow("trailingSpace") << QString::fromLatin1("foo ") << QString::fromLatin1(""); |
|
1652 |
QTest::newRow("noTrailingSpace") << QString::fromLatin1("foo") << QString::fromLatin1("foo"); |
|
1653 |
} |
|
1654 |
||
1655 |
void tst_QTextCursor::task244408_wordUnderCursor() |
|
1656 |
{ |
|
1657 |
QFETCH(QString, input); |
|
1658 |
QFETCH(QString, expected); |
|
1659 |
cursor.insertText(input); |
|
1660 |
cursor.movePosition(QTextCursor::End); |
|
1661 |
cursor.select(QTextCursor::WordUnderCursor); |
|
1662 |
QCOMPARE(cursor.selectedText(), expected); |
|
1663 |
} |
|
1664 |
||
1665 |
void tst_QTextCursor::adjustCursorsOnInsert() |
|
1666 |
{ |
|
1667 |
cursor.insertText("Some text before "); |
|
1668 |
int posBefore = cursor.position(); |
|
1669 |
cursor.insertText("selected text"); |
|
1670 |
int posAfter = cursor.position(); |
|
1671 |
cursor.insertText(" some text afterwards"); |
|
1672 |
||
1673 |
QTextCursor selection = cursor; |
|
1674 |
selection.setPosition(posBefore); |
|
1675 |
selection.setPosition(posAfter, QTextCursor::KeepAnchor); |
|
1676 |
||
1677 |
cursor.setPosition(posBefore-1); |
|
1678 |
cursor.insertText(QLatin1String("x")); |
|
1679 |
QCOMPARE(selection.anchor(), posBefore+1); |
|
1680 |
QCOMPARE(selection.position(), posAfter+1); |
|
1681 |
doc->undo(); |
|
1682 |
||
1683 |
cursor.setPosition(posBefore); |
|
1684 |
cursor.insertText(QLatin1String("x")); |
|
1685 |
QCOMPARE(selection.anchor(), posBefore+1); |
|
1686 |
QCOMPARE(selection.position(), posAfter+1); |
|
1687 |
doc->undo(); |
|
1688 |
||
1689 |
cursor.setPosition(posBefore+1); |
|
1690 |
cursor.insertText(QLatin1String("x")); |
|
1691 |
QCOMPARE(selection.anchor(), posBefore); |
|
1692 |
QCOMPARE(selection.position(), posAfter+1); |
|
1693 |
doc->undo(); |
|
1694 |
||
1695 |
cursor.setPosition(posAfter-1); |
|
1696 |
cursor.insertText(QLatin1String("x")); |
|
1697 |
QCOMPARE(selection.anchor(), posBefore); |
|
1698 |
QCOMPARE(selection.position(), posAfter+1); |
|
1699 |
doc->undo(); |
|
1700 |
||
1701 |
cursor.setPosition(posAfter); |
|
1702 |
cursor.insertText(QLatin1String("x")); |
|
1703 |
QCOMPARE(selection.anchor(), posBefore); |
|
1704 |
QCOMPARE(selection.position(), posAfter); |
|
1705 |
doc->undo(); |
|
1706 |
||
1707 |
cursor.setPosition(posAfter+1); |
|
1708 |
cursor.insertText(QLatin1String("x")); |
|
1709 |
QCOMPARE(selection.anchor(), posBefore); |
|
1710 |
QCOMPARE(selection.position(), posAfter); |
|
1711 |
doc->undo(); |
|
1712 |
||
1713 |
selection.setPosition(posAfter); |
|
1714 |
selection.setPosition(posBefore, QTextCursor::KeepAnchor); |
|
1715 |
||
1716 |
cursor.setPosition(posBefore-1); |
|
1717 |
cursor.insertText(QLatin1String("x")); |
|
1718 |
QCOMPARE(selection.position(), posBefore+1); |
|
1719 |
QCOMPARE(selection.anchor(), posAfter+1); |
|
1720 |
doc->undo(); |
|
1721 |
||
1722 |
cursor.setPosition(posBefore); |
|
1723 |
cursor.insertText(QLatin1String("x")); |
|
1724 |
QCOMPARE(selection.position(), posBefore+1); |
|
1725 |
QCOMPARE(selection.anchor(), posAfter+1); |
|
1726 |
doc->undo(); |
|
1727 |
||
1728 |
cursor.setPosition(posBefore+1); |
|
1729 |
cursor.insertText(QLatin1String("x")); |
|
1730 |
QCOMPARE(selection.position(), posBefore); |
|
1731 |
QCOMPARE(selection.anchor(), posAfter+1); |
|
1732 |
doc->undo(); |
|
1733 |
||
1734 |
cursor.setPosition(posAfter-1); |
|
1735 |
cursor.insertText(QLatin1String("x")); |
|
1736 |
QCOMPARE(selection.position(), posBefore); |
|
1737 |
QCOMPARE(selection.anchor(), posAfter+1); |
|
1738 |
doc->undo(); |
|
1739 |
||
1740 |
cursor.setPosition(posAfter); |
|
1741 |
cursor.insertText(QLatin1String("x")); |
|
1742 |
QCOMPARE(selection.position(), posBefore); |
|
1743 |
QCOMPARE(selection.anchor(), posAfter+1); |
|
1744 |
doc->undo(); |
|
1745 |
||
1746 |
cursor.setPosition(posAfter+1); |
|
1747 |
cursor.insertText(QLatin1String("x")); |
|
1748 |
QCOMPARE(selection.position(), posBefore); |
|
1749 |
QCOMPARE(selection.anchor(), posAfter); |
|
1750 |
doc->undo(); |
|
1751 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1752 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1753 |
void tst_QTextCursor::cursorPositionWithBlockUndoAndRedo() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1754 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1755 |
cursor.insertText("AAAABBBBCCCCDDDD"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1756 |
cursor.beginEditBlock(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1757 |
cursor.setPosition(12); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1758 |
int cursorPositionBefore = cursor.position(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1759 |
cursor.insertText("*"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1760 |
cursor.setPosition(8); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1761 |
cursor.insertText("*"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1762 |
cursor.setPosition(4); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1763 |
cursor.insertText("*"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1764 |
cursor.setPosition(0); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1765 |
cursor.insertText("*"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1766 |
int cursorPositionAfter = cursor.position(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1767 |
cursor.endEditBlock(); |
0 | 1768 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1769 |
QVERIFY(doc->toPlainText() == "*AAAA*BBBB*CCCC*DDDD"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1770 |
QCOMPARE(12, cursorPositionBefore); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1771 |
QCOMPARE(1, cursorPositionAfter); |
0 | 1772 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1773 |
doc->undo(&cursor); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1774 |
QVERIFY(doc->toPlainText() == "AAAABBBBCCCCDDDD"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1775 |
QCOMPARE(cursor.position(), cursorPositionBefore); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1776 |
doc->redo(&cursor); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1777 |
QVERIFY(doc->toPlainText() == "*AAAA*BBBB*CCCC*DDDD"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1778 |
QCOMPARE(cursor.position(), cursorPositionAfter); |
0 | 1779 |
} |
1780 |
||
1781 |
QTEST_MAIN(tst_QTextCursor) |
|
1782 |
#include "tst_qtextcursor.moc" |