Hide better the private API QTextCursor constructors
Both constructors were taking a pointer, so they participated in overload resolution along with QTextDocument and QTextFrame pointers. Instead, make them take references and move them to the private section of QTextCursor. That necessitated adding a method to QTextCursorPrivate to access that private constructor from non-friend classes. Change-Id: I7e6338336dd6468ead24ffff1410e3bc534d77dd Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>bb10
parent
a44e4a6cfe
commit
d921a9bd15
|
|
@ -1072,8 +1072,8 @@ QTextCursor::QTextCursor(const QTextBlock &block)
|
|||
/*!
|
||||
\internal
|
||||
*/
|
||||
QTextCursor::QTextCursor(QTextDocumentPrivate *p, int pos)
|
||||
: d(new QTextCursorPrivate(p))
|
||||
QTextCursor::QTextCursor(QTextDocumentPrivate &p, int pos)
|
||||
: d(new QTextCursorPrivate(&p))
|
||||
{
|
||||
d->adjusted_anchor = d->anchor = d->position = pos;
|
||||
|
||||
|
|
|
|||
|
|
@ -61,10 +61,8 @@ class Q_GUI_EXPORT QTextCursor
|
|||
public:
|
||||
QTextCursor();
|
||||
explicit QTextCursor(QTextDocument *document);
|
||||
QTextCursor(QTextDocumentPrivate *p, int pos);
|
||||
explicit QTextCursor(QTextFrame *frame);
|
||||
explicit QTextCursor(const QTextBlock &block);
|
||||
explicit QTextCursor(QTextCursorPrivate *d);
|
||||
QTextCursor(const QTextCursor &cursor);
|
||||
#ifdef Q_COMPILER_RVALUE_REFS
|
||||
QTextCursor &operator=(QTextCursor &&other) Q_DECL_NOTHROW { swap(other); return *this; }
|
||||
|
|
@ -221,8 +219,12 @@ public:
|
|||
QTextDocument *document() const;
|
||||
|
||||
private:
|
||||
QTextCursor(QTextDocumentPrivate &p, int pos);
|
||||
explicit QTextCursor(QTextCursorPrivate *d);
|
||||
|
||||
QSharedDataPointer<QTextCursorPrivate> d;
|
||||
friend class QTextCursorPrivate;
|
||||
friend class QTextDocumentPrivate;
|
||||
friend class QTextDocumentFragmentPrivate;
|
||||
friend class QTextCopyHelper;
|
||||
friend class QWidgetTextControlPrivate;
|
||||
|
|
|
|||
|
|
@ -100,6 +100,9 @@ public:
|
|||
|
||||
void aboutToRemoveCell(int from, int to);
|
||||
|
||||
static QTextCursor fromPosition(QTextDocumentPrivate *d, int pos)
|
||||
{ return QTextCursor(*d, pos); }
|
||||
|
||||
QTextDocumentPrivate *priv;
|
||||
qreal x;
|
||||
int position;
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
|
||||
#include "qtextdocument.h"
|
||||
#include <qtextformat.h>
|
||||
#include "qtextcursor_p.h"
|
||||
#include "qtextdocumentlayout_p.h"
|
||||
#include "qtextdocumentfragment.h"
|
||||
#include "qtextdocumentfragment_p.h"
|
||||
|
|
@ -1273,7 +1274,7 @@ static bool findInBlock(const QTextBlock &block, const QString &expression, int
|
|||
}
|
||||
}
|
||||
//we have a hit, return the cursor for that.
|
||||
*cursor = QTextCursor(block.docHandle(), block.position() + idx);
|
||||
*cursor = QTextCursorPrivate::fromPosition(block.docHandle(), block.position() + idx);
|
||||
cursor->setPosition(cursor->position() + expression.length(), QTextCursor::KeepAnchor);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -1391,7 +1392,7 @@ static bool findInBlock(const QTextBlock &block, const QRegExp &expression, int
|
|||
}
|
||||
}
|
||||
//we have a hit, return the cursor for that.
|
||||
*cursor = QTextCursor(block.docHandle(), block.position() + idx);
|
||||
*cursor = QTextCursorPrivate::fromPosition(block.docHandle(), block.position() + idx);
|
||||
cursor->setPosition(cursor->position() + expr.matchedLength(), QTextCursor::KeepAnchor);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -1519,7 +1520,7 @@ static bool findInBlock(const QTextBlock &block, const QRegularExpression &expre
|
|||
}
|
||||
}
|
||||
//we have a hit, return the cursor for that.
|
||||
*cursor = QTextCursor(block.docHandle(), block.position() + idx);
|
||||
*cursor = QTextCursorPrivate::fromPosition(block.docHandle(), block.position() + idx);
|
||||
cursor->setPosition(cursor->position() + match.capturedLength(), QTextCursor::KeepAnchor);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1704,7 +1704,7 @@ bool QTextDocumentPrivate::ensureMaximumBlockCount()
|
|||
beginEditBlock();
|
||||
|
||||
const int blocksToRemove = blocks.numNodes() - maximumBlockCount;
|
||||
QTextCursor cursor(this, 0);
|
||||
QTextCursor cursor(*this, 0);
|
||||
cursor.movePosition(QTextCursor::NextBlock, QTextCursor::KeepAnchor, blocksToRemove);
|
||||
|
||||
unreachableCharacterCount += cursor.selectionEnd() - cursor.selectionStart();
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
|
||||
#include "qtextobject.h"
|
||||
#include "qtextobject_p.h"
|
||||
#include "qtextcursor_p.h"
|
||||
#include "qtextdocument.h"
|
||||
#include "qtextformat_p.h"
|
||||
#include "qtextdocument_p.h"
|
||||
|
|
@ -461,7 +462,7 @@ QTextFrame *QTextFrame::parentFrame() const
|
|||
QTextCursor QTextFrame::firstCursorPosition() const
|
||||
{
|
||||
Q_D(const QTextFrame);
|
||||
return QTextCursor(d->pieceTable, firstPosition());
|
||||
return QTextCursorPrivate::fromPosition(d->pieceTable, firstPosition());
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -472,7 +473,7 @@ QTextCursor QTextFrame::firstCursorPosition() const
|
|||
QTextCursor QTextFrame::lastCursorPosition() const
|
||||
{
|
||||
Q_D(const QTextFrame);
|
||||
return QTextCursor(d->pieceTable, lastPosition());
|
||||
return QTextCursorPrivate::fromPosition(d->pieceTable, lastPosition());
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@
|
|||
#include "qtextcursor.h"
|
||||
#include "qtextformat.h"
|
||||
#include <qdebug.h>
|
||||
#include "qtextcursor_p.h"
|
||||
#include "qtexttable_p.h"
|
||||
#include "qvarlengtharray.h"
|
||||
|
||||
|
|
@ -220,7 +221,7 @@ int QTextTableCell::columnSpan() const
|
|||
*/
|
||||
QTextCursor QTextTableCell::firstCursorPosition() const
|
||||
{
|
||||
return QTextCursor(table->d_func()->pieceTable, firstPosition());
|
||||
return QTextCursorPrivate::fromPosition(table->d_func()->pieceTable, firstPosition());
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -230,7 +231,7 @@ QTextCursor QTextTableCell::firstCursorPosition() const
|
|||
*/
|
||||
QTextCursor QTextTableCell::lastCursorPosition() const
|
||||
{
|
||||
return QTextCursor(table->d_func()->pieceTable, lastPosition());
|
||||
return QTextCursorPrivate::fromPosition(table->d_func()->pieceTable, lastPosition());
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1103,10 +1104,10 @@ void QTextTable::mergeCells(int row, int column, int numRows, int numCols)
|
|||
if (nextPos > pos) {
|
||||
if (needsParagraph) {
|
||||
needsParagraph = false;
|
||||
QTextCursor(p, insertPos++).insertBlock();
|
||||
QTextCursorPrivate::fromPosition(p, insertPos++).insertBlock();
|
||||
p->move(pos + 1, insertPos, nextPos - pos);
|
||||
} else if (rowHasText) {
|
||||
QTextCursor(p, insertPos++).insertText(QLatin1String(" "));
|
||||
QTextCursorPrivate::fromPosition(p, insertPos++).insertText(QLatin1String(" "));
|
||||
p->move(pos + 1, insertPos, nextPos - pos);
|
||||
} else {
|
||||
p->move(pos, insertPos, nextPos - pos);
|
||||
|
|
@ -1282,7 +1283,7 @@ QTextCursor QTextTable::rowStart(const QTextCursor &c) const
|
|||
int row = cell.row();
|
||||
QTextDocumentPrivate *p = d->pieceTable;
|
||||
QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), d->grid[row*d->nCols]);
|
||||
return QTextCursor(p, it.position());
|
||||
return QTextCursorPrivate::fromPosition(p, it.position());
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -1304,7 +1305,7 @@ QTextCursor QTextTable::rowEnd(const QTextCursor &c) const
|
|||
int fragment = row < d->nRows ? d->grid[row*d->nCols] : d->fragment_end;
|
||||
QTextDocumentPrivate *p = d->pieceTable;
|
||||
QTextDocumentPrivate::FragmentIterator it(&p->fragmentMap(), fragment);
|
||||
return QTextCursor(p, it.position() - 1);
|
||||
return QTextCursorPrivate::fromPosition(p, it.position() - 1);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -2,4 +2,4 @@ CONFIG += testcase
|
|||
CONFIG += parallel_test
|
||||
TARGET = tst_qtextcursor
|
||||
SOURCES += tst_qtextcursor.cpp
|
||||
QT += testlib
|
||||
QT += core-private gui-private testlib
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@
|
|||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
|
||||
#include <qtextdocument.h>
|
||||
#include <qtexttable.h>
|
||||
#include <qvariant.h>
|
||||
|
|
@ -45,6 +44,8 @@
|
|||
#include <qtextobject.h>
|
||||
#include <qdebug.h>
|
||||
|
||||
#include <private/qtextcursor_p.h>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QTextDocument)
|
||||
|
||||
class tst_QTextCursor : public QObject
|
||||
|
|
@ -1292,7 +1293,7 @@ void tst_QTextCursor::anchorInitialized1()
|
|||
void tst_QTextCursor::anchorInitialized2()
|
||||
{
|
||||
cursor.insertBlock();
|
||||
cursor = QTextCursor(cursor.block().docHandle(), 1);
|
||||
cursor = QTextCursorPrivate::fromPosition(cursor.block().docHandle(), 1);
|
||||
QCOMPARE(cursor.position(), 1);
|
||||
QCOMPARE(cursor.anchor(), 1);
|
||||
QCOMPARE(cursor.selectionStart(), 1);
|
||||
|
|
|
|||
Loading…
Reference in New Issue