aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/designer
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2023-10-17 13:22:14 +0200
committerChristian Kandeler <christian.kandeler@qt.io>2023-10-17 12:44:01 +0000
commita60b43f028360bd262d0465177f813b1670dbcd8 (patch)
treed16f4c6a178366823204b652aa604133a8f5b9a4 /src/plugins/designer
parentd16d1718f30e3481100f9629ae7acd7ac03a0c02 (diff)
Designer: Use proper formatting and indentation
... when inserting member functions via "go to slot". Fixes: QTCREATORBUG-11730 Change-Id: I5de6947069e2c376758d0a79f6d1d710882aee66 Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/designer')
-rw-r--r--src/plugins/designer/gotoslot_test.cpp16
-rw-r--r--src/plugins/designer/qtcreatorintegration.cpp23
2 files changed, 32 insertions, 7 deletions
diff --git a/src/plugins/designer/gotoslot_test.cpp b/src/plugins/designer/gotoslot_test.cpp
index f804c2259e3..49fccf58716 100644
--- a/src/plugins/designer/gotoslot_test.cpp
+++ b/src/plugins/designer/gotoslot_test.cpp
@@ -6,6 +6,7 @@
#include "formeditor.h"
#include <coreplugin/editormanager/editormanager.h>
+#include <coreplugin/systemsettings.h>
#include <coreplugin/testdatadir.h>
#include <cppeditor/builtineditordocumentprocessor.h>
#include <cppeditor/cppmodelmanager.h>
@@ -215,6 +216,21 @@ namespace Internal {
/// header and source files are correctly updated.
void FormEditorPlugin::test_gotoslot()
{
+ class SystemSettingsMgr {
+ public:
+ SystemSettingsMgr()
+ : m_saveAfterRefactor(Core::Internal::systemSettings().autoSaveAfterRefactoring.value())
+ {
+ Core::Internal::systemSettings().autoSaveAfterRefactoring.setValue(false);
+ }
+ ~SystemSettingsMgr()
+ {
+ Core::Internal::systemSettings().autoSaveAfterRefactoring.setValue(m_saveAfterRefactor);
+ }
+ private:
+ const bool m_saveAfterRefactor;
+ } systemSettingsMgr;
+
QFETCH(QStringList, files);
(GoToSlotTestCase(Utils::transform(files, FilePath::fromString)));
}
diff --git a/src/plugins/designer/qtcreatorintegration.cpp b/src/plugins/designer/qtcreatorintegration.cpp
index fb4c1afd5d6..01459ee0b06 100644
--- a/src/plugins/designer/qtcreatorintegration.cpp
+++ b/src/plugins/designer/qtcreatorintegration.cpp
@@ -56,8 +56,6 @@
#include <memory>
-enum { indentation = 4 };
-
Q_LOGGING_CATEGORY(log, "qtc.designer", QtWarningMsg);
using namespace Designer::Internal;
@@ -624,12 +622,23 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName,
Overview o;
const QString className = o.prettyName(cl->name());
const QString definition = location.prefix() + "void " + className + "::"
- + functionNameWithParameterNames + "\n{\n" + QString(indentation, ' ') + "\n}\n"
+ + functionNameWithParameterNames + "\n{\n\n}\n"
+ location.suffix();
- editor->insert(definition);
- Core::EditorManager::openEditorAt({location.filePath(),
- int(location.line() + location.prefix().count('\n') + 2),
- indentation});
+ const RefactoringFilePtr file = refactoring.file(location.filePath());
+ const int insertionPos = Utils::Text::positionInText(file->document(),
+ location.line(), location.column());
+ ChangeSet changeSet;
+ changeSet.insert(insertionPos, definition);
+ file->setChangeSet(changeSet);
+ file->apply();
+ const int indentationPos = file->document()->toPlainText().indexOf('}', insertionPos) - 1;
+ QTextCursor cursor(editor->textDocument()->document());
+ cursor.setPosition(indentationPos);
+ editor->textDocument()->autoIndent(cursor);
+ const int openPos = file->document()->toPlainText().indexOf('}', indentationPos) - 1;
+ int line, column;
+ Utils::Text::convertPosition(file->document(), openPos, &line, &column);
+ Core::EditorManager::openEditorAt({location.filePath(), line, column});
return true;
}