CppTools: Modernize

Change-Id: I78af9cd4ccddfa4ed744dce96b772ae5644c89d2
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Nikolai Kosjar
2019-02-07 10:09:21 +01:00
parent 69281bcdcf
commit 12f4b1ee86
15 changed files with 61 additions and 96 deletions

View File

@@ -50,7 +50,7 @@ namespace {
CursorInfo::Range toRange(const SemanticInfo::Use &use)
{
return CursorInfo::Range(use.line, use.column, use.length);
return {use.line, use.column, use.length};
}
CursorInfo::Range toRange(int tokenIndex, TranslationUnit *translationUnit)
@@ -60,10 +60,9 @@ CursorInfo::Range toRange(int tokenIndex, TranslationUnit *translationUnit)
if (column)
--column; // adjust the column position.
return CursorInfo::Range(
line,
return {line,
column + 1,
translationUnit->tokenAt(static_cast<unsigned>(tokenIndex)).utf16chars());
translationUnit->tokenAt(static_cast<unsigned>(tokenIndex)).utf16chars()};
}
CursorInfo::Range toRange(const QTextCursor &textCursor,
@@ -74,10 +73,9 @@ CursorInfo::Range toRange(const QTextCursor &textCursor,
cursor.setPosition(static_cast<int>(utf16offset));
const QTextBlock textBlock = cursor.block();
return CursorInfo::Range(
static_cast<unsigned>(textBlock.blockNumber() + 1),
return {static_cast<unsigned>(textBlock.blockNumber() + 1),
static_cast<unsigned>(cursor.position() - textBlock.position() + 1),
length);
length};
}
CursorInfo::Ranges toRanges(const SemanticUses &uses)
@@ -216,8 +214,8 @@ private:
bool good = false;
foreach (const CppTools::SemanticInfo::Use &use, uses) {
unsigned l = static_cast<unsigned>(m_line);
unsigned c = static_cast<unsigned>(m_column);
const auto l = static_cast<unsigned>(m_line);
const auto c = static_cast<unsigned>(m_column);
if (l == use.line && c >= use.column && c <= (use.column + use.length)) {
good = true;
break;

View File

@@ -51,6 +51,8 @@
#include <QStringListModel>
#include <QUuid>
#include <memory>
namespace CppTools {
using namespace Constants;
@@ -383,7 +385,7 @@ private:
}
}
QVariant data(const QModelIndex &fullIndex, int role = Qt::DisplayRole) const override final
QVariant data(const QModelIndex &fullIndex, int role = Qt::DisplayRole) const final
{
if (!fullIndex.isValid() || role == Qt::DecorationRole)
return QVariant();
@@ -447,7 +449,7 @@ private:
QModelIndex indexForTree(const ClazyChecksTree *tree) const {
if (!tree)
return QModelIndex();
return {};
QModelIndex result;
traverse(index(0, 0, QModelIndex()), [&](const QModelIndex &index){
@@ -989,11 +991,11 @@ static void setupTreeView(QTreeView *view, QAbstractItemModel *model, int expand
void ClangDiagnosticConfigsWidget::setupTabs()
{
m_clangBaseChecks.reset(new CppTools::Ui::ClangBaseChecks);
m_clangBaseChecks = std::make_unique<CppTools::Ui::ClangBaseChecks>();
m_clangBaseChecksWidget = new QWidget();
m_clangBaseChecks->setupUi(m_clangBaseChecksWidget);
m_clazyChecks.reset(new CppTools::Ui::ClazyChecks);
m_clazyChecks = std::make_unique<CppTools::Ui::ClazyChecks>();
m_clazyChecksWidget = new QWidget();
m_clazyChecks->setupUi(m_clazyChecksWidget);
m_clazySortFilterProxyModel = new ClazyChecksSortFilterModel(this);
@@ -1030,7 +1032,7 @@ void ClangDiagnosticConfigsWidget::setupTabs()
= codeModelSettings()->enableLowerClazyLevels() ? Qt::Checked : Qt::Unchecked;
m_clazyChecks->enableLowerLevelsCheckBox->setCheckState(checkEnableLowerClazyLevels);
m_tidyChecks.reset(new CppTools::Ui::TidyChecks);
m_tidyChecks = std::make_unique<CppTools::Ui::TidyChecks>();
m_tidyChecksWidget = new QWidget();
m_tidyChecks->setupUi(m_tidyChecksWidget);
setupTreeView(m_tidyChecks->checksPrefixesTree, m_tidyTreeModel.get());

View File

@@ -666,7 +666,7 @@ CodeFormatter::State CodeFormatter::state(int belowTop) const
if (belowTop < m_currentState.size())
return m_currentState.at(m_currentState.size() - 1 - belowTop);
else
return State();
return {};
}
int CodeFormatter::tokenIndex() const

View File

@@ -36,7 +36,7 @@
using namespace CppTools;
static Core::Id initialClangDiagnosticConfigId()
{ return Core::Id(Constants::CPP_CLANG_BUILTIN_CONFIG_ID_EVERYTHING_WITH_EXCEPTIONS); }
{ return {Constants::CPP_CLANG_BUILTIN_CONFIG_ID_EVERYTHING_WITH_EXCEPTIONS}; }
static CppCodeModelSettings::PCHUsage initialPchUsage()
{ return CppCodeModelSettings::PchUse_BuildSystem; }

View File

@@ -76,7 +76,7 @@ CppCodeStyleSettings CppCodeStylePreferences::currentCodeStyleSettings() const
QVariant v = currentValue();
if (!v.canConvert<CppCodeStyleSettings>()) {
// warning
return CppCodeStyleSettings();
return {};
}
return v.value<CppCodeStyleSettings>();
}

View File

@@ -67,30 +67,7 @@ using namespace CppTools;
// ------------------ CppCodeStyleSettingsWidget
CppCodeStyleSettings::CppCodeStyleSettings() :
indentBlockBraces(false)
, indentBlockBody(true)
, indentClassBraces(false)
, indentEnumBraces(false)
, indentNamespaceBraces(false)
, indentNamespaceBody(false)
, indentAccessSpecifiers(false)
, indentDeclarationsRelativeToAccessSpecifiers(true)
, indentFunctionBody(true)
, indentFunctionBraces(false)
, indentSwitchLabels(false)
, indentStatementsRelativeToSwitchLabels(true)
, indentBlocksRelativeToSwitchLabels(false)
, indentControlFlowRelativeToSwitchLabels(true)
, bindStarToIdentifier(true)
, bindStarToTypeName(false)
, bindStarToLeftSpecifier(false)
, bindStarToRightSpecifier(false)
, extraPaddingForConditionsIfConfusingAlign(true)
, alignAssignments(false)
, preferGetterNameWithoutGetPrefix(true)
{
}
CppCodeStyleSettings::CppCodeStyleSettings() = default;
void CppCodeStyleSettings::toSettings(const QString &category, QSettings *s) const
{
@@ -203,21 +180,20 @@ bool CppCodeStyleSettings::equals(const CppCodeStyleSettings &rhs) const
Utils::optional<CppCodeStyleSettings> CppCodeStyleSettings::currentProjectCodeStyle()
{
ProjectExplorer::Project *project = ProjectExplorer::ProjectTree::currentProject();
using OptSettings = Utils::optional<CppCodeStyleSettings>;
if (!project)
return OptSettings();
return {};
ProjectExplorer::EditorConfiguration *editorConfiguration = project->editorConfiguration();
QTC_ASSERT(editorConfiguration, return OptSettings());
QTC_ASSERT(editorConfiguration, return {});
TextEditor::ICodeStylePreferences *codeStylePreferences
= editorConfiguration->codeStyle(Constants::CPP_SETTINGS_ID);
QTC_ASSERT(codeStylePreferences, return OptSettings());
QTC_ASSERT(codeStylePreferences, return {});
auto cppCodeStylePreferences =
dynamic_cast<const CppCodeStylePreferences *>(codeStylePreferences);
if (!cppCodeStylePreferences)
return OptSettings();
return {};
return cppCodeStylePreferences->currentCodeStyleSettings();
}

View File

@@ -45,26 +45,26 @@ class CPPTOOLS_EXPORT CppCodeStyleSettings
public:
CppCodeStyleSettings();
bool indentBlockBraces;
bool indentBlockBody;
bool indentClassBraces;
bool indentEnumBraces;
bool indentNamespaceBraces;
bool indentNamespaceBody;
bool indentAccessSpecifiers;
bool indentDeclarationsRelativeToAccessSpecifiers;
bool indentFunctionBody;
bool indentFunctionBraces;
bool indentSwitchLabels;
bool indentStatementsRelativeToSwitchLabels;
bool indentBlocksRelativeToSwitchLabels;
bool indentControlFlowRelativeToSwitchLabels;
bool indentBlockBraces = false;
bool indentBlockBody = true;
bool indentClassBraces = false;
bool indentEnumBraces = false;
bool indentNamespaceBraces = false;
bool indentNamespaceBody = false;
bool indentAccessSpecifiers = false;
bool indentDeclarationsRelativeToAccessSpecifiers = true;
bool indentFunctionBody = true;
bool indentFunctionBraces = false;
bool indentSwitchLabels = false;
bool indentStatementsRelativeToSwitchLabels = true;
bool indentBlocksRelativeToSwitchLabels = false;
bool indentControlFlowRelativeToSwitchLabels = true;
// Formatting of pointer and reference declarations, see Overview::StarBindFlag.
bool bindStarToIdentifier;
bool bindStarToTypeName;
bool bindStarToLeftSpecifier;
bool bindStarToRightSpecifier;
bool bindStarToIdentifier = true;
bool bindStarToTypeName = false;
bool bindStarToLeftSpecifier = false;
bool bindStarToRightSpecifier = false;
// false: if (a &&
// b)
@@ -75,15 +75,15 @@ public:
// but always: while (a &&
// b)
// foo;
bool extraPaddingForConditionsIfConfusingAlign;
bool extraPaddingForConditionsIfConfusingAlign = true;
// false: a = a +
// b;
// true: a = a +
// b
bool alignAssignments;
bool alignAssignments = false;
bool preferGetterNameWithoutGetPrefix;
bool preferGetterNameWithoutGetPrefix = true;
void toSettings(const QString &category, QSettings *s) const;
void fromSettings(const QString &category, const QSettings *s);

View File

@@ -1737,9 +1737,8 @@ void InternalCppCompletionAssistProcessor::addClassMembersToCompletion(Scope *sc
else
addCompletionItem(member);
}
std::set<Class *>::const_iterator citEnd = nestedAnonymouses.end();
for (std::set<Class *>::const_iterator cit = nestedAnonymouses.begin(); cit != citEnd; ++cit)
addClassMembersToCompletion(*cit, staticLookup);
for (Class *klass : nestedAnonymouses)
addClassMembersToCompletion(klass, staticLookup);
}
bool InternalCppCompletionAssistProcessor::completeQtMethod(const QList<LookupItem> &results,

View File

@@ -179,7 +179,7 @@ CppCodeStyleSettings CppQtStyleIndenter::codeStyleSettings() const
{
if (m_cppCodeStylePreferences)
return m_cppCodeStylePreferences->currentCodeStyleSettings();
return CppCodeStyleSettings();
return {};
}
TextEditor::IndentationForBlock CppQtStyleIndenter::indentationForBlocks(

View File

@@ -198,12 +198,12 @@ Utils::ChangeSet::Range CppRefactoringFile::range(unsigned tokenIndex) const
unsigned line, column;
cppDocument()->translationUnit()->getPosition(token.utf16charsBegin(), &line, &column);
const int start = document()->findBlockByNumber(line - 1).position() + column - 1;
return Utils::ChangeSet::Range(start, start + token.utf16chars());
return {start, static_cast<int>(start + token.utf16chars())};
}
Utils::ChangeSet::Range CppRefactoringFile::range(AST *ast) const
{
return Utils::ChangeSet::Range(startOf(ast), endOf(ast));
return {startOf(ast), endOf(ast)};
}
int CppRefactoringFile::startOf(unsigned index) const

View File

@@ -42,12 +42,7 @@
using namespace CppTools;
using namespace CPlusPlus;
DoxygenGenerator::DoxygenGenerator()
: m_addLeadingAsterisks(true)
, m_generateBrief(true)
, m_startComment(true)
, m_style(QtStyle)
{}
DoxygenGenerator::DoxygenGenerator() = default;
void DoxygenGenerator::setStyle(DocumentationStyle style)
{

View File

@@ -85,10 +85,10 @@ private:
void assignCommentOffset(QTextCursor cursor);
QString offsetString() const;
bool m_addLeadingAsterisks;
bool m_generateBrief;
bool m_startComment;
DocumentationStyle m_style;
bool m_addLeadingAsterisks = true;
bool m_generateBrief = true;
bool m_startComment = true;
DocumentationStyle m_style = QtStyle;
CPlusPlus::Overview m_printer;
QString m_commentOffset;
};

View File

@@ -248,10 +248,7 @@ private:
} // end of anonymous namespace
InsertionLocation::InsertionLocation()
: m_line(0)
, m_column(0)
{}
InsertionLocation::InsertionLocation() = default;
InsertionLocation::InsertionLocation(const QString &fileName,
const QString &prefix,
@@ -316,11 +313,9 @@ class HighestValue
{
Key _key;
Value _value;
bool _set;
bool _set = false;
public:
HighestValue()
: _key(), _set(false)
{}
HighestValue() = default;
HighestValue(const Key &initialKey, const Value &initialValue)
: _key(initialKey)

View File

@@ -63,8 +63,8 @@ private:
QString m_fileName;
QString m_prefix;
QString m_suffix;
unsigned m_line;
unsigned m_column;
unsigned m_line = 0;
unsigned m_column = 0;
};
class CPPTOOLS_EXPORT InsertionPointLocator

View File

@@ -41,7 +41,7 @@ namespace CppTools {
class SearchSymbols: protected CPlusPlus::SymbolVisitor
{
public:
typedef SymbolSearcher::SymbolTypes SymbolTypes;
using SymbolTypes = SymbolSearcher::SymbolTypes;
static SymbolTypes AllTypes;