forked from qt-creator/qt-creator
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:
@@ -12,3 +12,15 @@
|
|||||||
#else
|
#else
|
||||||
# define CORE_EXPORT Q_DECL_IMPORT
|
# define CORE_EXPORT Q_DECL_IMPORT
|
||||||
#endif
|
#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
|
||||||
|
|||||||
@@ -3,11 +3,13 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "core_global.h"
|
||||||
|
|
||||||
#include <utils/aspects.h>
|
#include <utils/aspects.h>
|
||||||
|
|
||||||
namespace Core::Internal {
|
namespace Core::Internal {
|
||||||
|
|
||||||
class SystemSettings final : public Utils::AspectContainer
|
class CORE_TEST_EXPORT SystemSettings final : public Utils::AspectContainer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SystemSettings();
|
SystemSettings();
|
||||||
@@ -37,6 +39,6 @@ public:
|
|||||||
Utils::BoolAspect askBeforeExit{this};
|
Utils::BoolAspect askBeforeExit{this};
|
||||||
};
|
};
|
||||||
|
|
||||||
SystemSettings &systemSettings();
|
CORE_TEST_EXPORT SystemSettings &systemSettings();
|
||||||
|
|
||||||
} // Core::Internal
|
} // Core::Internal
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "formeditor.h"
|
#include "formeditor.h"
|
||||||
|
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
|
#include <coreplugin/systemsettings.h>
|
||||||
#include <coreplugin/testdatadir.h>
|
#include <coreplugin/testdatadir.h>
|
||||||
#include <cppeditor/builtineditordocumentprocessor.h>
|
#include <cppeditor/builtineditordocumentprocessor.h>
|
||||||
#include <cppeditor/cppmodelmanager.h>
|
#include <cppeditor/cppmodelmanager.h>
|
||||||
@@ -215,6 +216,21 @@ namespace Internal {
|
|||||||
/// header and source files are correctly updated.
|
/// header and source files are correctly updated.
|
||||||
void FormEditorPlugin::test_gotoslot()
|
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);
|
QFETCH(QStringList, files);
|
||||||
(GoToSlotTestCase(Utils::transform(files, FilePath::fromString)));
|
(GoToSlotTestCase(Utils::transform(files, FilePath::fromString)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,8 +56,6 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
enum { indentation = 4 };
|
|
||||||
|
|
||||||
Q_LOGGING_CATEGORY(log, "qtc.designer", QtWarningMsg);
|
Q_LOGGING_CATEGORY(log, "qtc.designer", QtWarningMsg);
|
||||||
|
|
||||||
using namespace Designer::Internal;
|
using namespace Designer::Internal;
|
||||||
@@ -624,12 +622,23 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName,
|
|||||||
Overview o;
|
Overview o;
|
||||||
const QString className = o.prettyName(cl->name());
|
const QString className = o.prettyName(cl->name());
|
||||||
const QString definition = location.prefix() + "void " + className + "::"
|
const QString definition = location.prefix() + "void " + className + "::"
|
||||||
+ functionNameWithParameterNames + "\n{\n" + QString(indentation, ' ') + "\n}\n"
|
+ functionNameWithParameterNames + "\n{\n\n}\n"
|
||||||
+ location.suffix();
|
+ location.suffix();
|
||||||
editor->insert(definition);
|
const RefactoringFilePtr file = refactoring.file(location.filePath());
|
||||||
Core::EditorManager::openEditorAt({location.filePath(),
|
const int insertionPos = Utils::Text::positionInText(file->document(),
|
||||||
int(location.line() + location.prefix().count('\n') + 2),
|
location.line(), location.column());
|
||||||
indentation});
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user