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>
This commit is contained in:
Christian Kandeler
2023-10-17 13:22:14 +02:00
parent d16d1718f3
commit a60b43f028
4 changed files with 48 additions and 9 deletions

View File

@@ -12,3 +12,15 @@
#else
# define CORE_EXPORT Q_DECL_IMPORT
#endif
#if defined(WITH_TESTS)
# if defined(CORE_LIBRARY)
# define CORE_TEST_EXPORT Q_DECL_EXPORT
# elif defined(CORE_STATIC_LIBRARY)
# define CORE_TEST_EXPORT
# else
# define CORE_TEST_EXPORT Q_DECL_IMPORT
# endif
#else
# define CORE_TEST_EXPORT
#endif

View File

@@ -3,11 +3,13 @@
#pragma once
#include "core_global.h"
#include <utils/aspects.h>
namespace Core::Internal {
class SystemSettings final : public Utils::AspectContainer
class CORE_TEST_EXPORT SystemSettings final : public Utils::AspectContainer
{
public:
SystemSettings();
@@ -37,6 +39,6 @@ public:
Utils::BoolAspect askBeforeExit{this};
};
SystemSettings &systemSettings();
CORE_TEST_EXPORT SystemSettings &systemSettings();
} // Core::Internal

View File

@@ -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)));
}

View File

@@ -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;
}