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;
|
m_cursor = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChangeSet::apply(QTextDocument *document)
|
||||||
|
{
|
||||||
|
QTextCursor c(document);
|
||||||
|
apply(&c);
|
||||||
|
}
|
||||||
|
|
||||||
QString ChangeSet::textAt(int pos, int length)
|
QString ChangeSet::textAt(int pos, int length)
|
||||||
{
|
{
|
||||||
if (m_string) {
|
if (m_string) {
|
||||||
|
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QTextCursor;
|
class QTextCursor;
|
||||||
|
class QTextDocument;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
@@ -76,6 +77,7 @@ public:
|
|||||||
|
|
||||||
void apply(QString *s);
|
void apply(QString *s);
|
||||||
void apply(QTextCursor *textCursor);
|
void apply(QTextCursor *textCursor);
|
||||||
|
void apply(QTextDocument *document);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// length-based API.
|
// length-based API.
|
||||||
|
@@ -76,8 +76,7 @@ static void applyRefactorings(QTextDocument *textDocument, TextEditorWidget *edi
|
|||||||
Utils::ChangeSet change = formatter.format(cppDocument->translationUnit()->ast());
|
Utils::ChangeSet change = formatter.format(cppDocument->translationUnit()->ast());
|
||||||
|
|
||||||
// Apply change
|
// Apply change
|
||||||
QTextCursor cursor(textDocument);
|
change.apply(textDocument);
|
||||||
change.apply(&cursor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------ CppCodeStyleSettingsWidget
|
// ------------------ CppCodeStyleSettingsWidget
|
||||||
|
@@ -135,8 +135,7 @@ public:
|
|||||||
{
|
{
|
||||||
Utils::ChangeSet change;
|
Utils::ChangeSet change;
|
||||||
change.insert(m_position, QLatin1String(text));
|
change.insert(m_position, QLatin1String(text));
|
||||||
QTextCursor cursor(m_textDocument);
|
change.apply(m_textDocument);
|
||||||
change.apply(&cursor);
|
|
||||||
m_position += text.length();
|
m_position += text.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -107,8 +107,7 @@ public:
|
|||||||
Utils::ChangeSet change = formatter.format(ast); // ChangeSet may be empty.
|
Utils::ChangeSet change = formatter.format(ast); // ChangeSet may be empty.
|
||||||
|
|
||||||
// Apply change
|
// Apply change
|
||||||
QTextCursor changeCursor(qtextDocument);
|
change.apply(qtextDocument);
|
||||||
change.apply(&changeCursor);
|
|
||||||
|
|
||||||
// Compare
|
// Compare
|
||||||
QCOMPARE(qtextDocument->toPlainText(), expectedSource);
|
QCOMPARE(qtextDocument->toPlainText(), expectedSource);
|
||||||
|
@@ -318,8 +318,7 @@ void QuickToolBar::removeProperty(const QString &propertyName)
|
|||||||
Utils::ChangeSet changeSet;
|
Utils::ChangeSet changeSet;
|
||||||
Rewriter rewriter(m_doc->source(), &changeSet, m_propertyOrder);
|
Rewriter rewriter(m_doc->source(), &changeSet, m_propertyOrder);
|
||||||
rewriter.removeBindingByName(initializer, propertyName);
|
rewriter.removeBindingByName(initializer, propertyName);
|
||||||
QTextCursor tc(m_editorWidget->document());
|
changeSet.apply(m_editorWidget->document());
|
||||||
changeSet.apply(&tc);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user