forked from qt-creator/qt-creator
Utils: add convenience function to ChangeSet
Creating a QTextCursor just for the ChangeSet gives no benefit for the calling code, but reduces the readability. Change-Id: I34acb6083b6f7ab54fce042e29cd6e80498338ef Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -318,6 +318,12 @@ void ChangeSet::apply(QTextCursor *textCursor)
|
||||
m_cursor = nullptr;
|
||||
}
|
||||
|
||||
void ChangeSet::apply(QTextDocument *document)
|
||||
{
|
||||
QTextCursor c(document);
|
||||
apply(&c);
|
||||
}
|
||||
|
||||
QString ChangeSet::textAt(int pos, int length)
|
||||
{
|
||||
if (m_string) {
|
||||
|
@@ -10,6 +10,7 @@
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QTextCursor;
|
||||
class QTextDocument;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Utils {
|
||||
@@ -76,6 +77,7 @@ public:
|
||||
|
||||
void apply(QString *s);
|
||||
void apply(QTextCursor *textCursor);
|
||||
void apply(QTextDocument *document);
|
||||
|
||||
private:
|
||||
// length-based API.
|
||||
|
@@ -76,8 +76,7 @@ static void applyRefactorings(QTextDocument *textDocument, TextEditorWidget *edi
|
||||
Utils::ChangeSet change = formatter.format(cppDocument->translationUnit()->ast());
|
||||
|
||||
// Apply change
|
||||
QTextCursor cursor(textDocument);
|
||||
change.apply(&cursor);
|
||||
change.apply(textDocument);
|
||||
}
|
||||
|
||||
// ------------------ CppCodeStyleSettingsWidget
|
||||
|
@@ -135,8 +135,7 @@ public:
|
||||
{
|
||||
Utils::ChangeSet change;
|
||||
change.insert(m_position, QLatin1String(text));
|
||||
QTextCursor cursor(m_textDocument);
|
||||
change.apply(&cursor);
|
||||
change.apply(m_textDocument);
|
||||
m_position += text.length();
|
||||
}
|
||||
|
||||
|
@@ -107,8 +107,7 @@ public:
|
||||
Utils::ChangeSet change = formatter.format(ast); // ChangeSet may be empty.
|
||||
|
||||
// Apply change
|
||||
QTextCursor changeCursor(qtextDocument);
|
||||
change.apply(&changeCursor);
|
||||
change.apply(qtextDocument);
|
||||
|
||||
// Compare
|
||||
QCOMPARE(qtextDocument->toPlainText(), expectedSource);
|
||||
|
@@ -318,8 +318,7 @@ void QuickToolBar::removeProperty(const QString &propertyName)
|
||||
Utils::ChangeSet changeSet;
|
||||
Rewriter rewriter(m_doc->source(), &changeSet, m_propertyOrder);
|
||||
rewriter.removeBindingByName(initializer, propertyName);
|
||||
QTextCursor tc(m_editorWidget->document());
|
||||
changeSet.apply(&tc);
|
||||
changeSet.apply(m_editorWidget->document());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user