Commit 0ba4f52c authored by David Schulz's avatar David Schulz

Editor: Simplify completion settings.

Change-Id: If7840fcac0c620b97082229a9f93874dc7afe738
Reviewed-by: Nikolai Kosjar's avatarNikolai Kosjar <nikolai.kosjar@qt.io>
parent 509c977f
......@@ -27,86 +27,82 @@
#include <QSettings>
static const char groupPostfix[] = "Completion";
static const char caseSensitivityKey[] = "CaseSensitivity";
static const char completionTriggerKey[] = "CompletionTrigger";
static const char groupPostfix[] = "Completion";
static const char caseSensitivityKey[] = "CaseSensitivity";
static const char completionTriggerKey[] = "CompletionTrigger";
static const char automaticProposalTimeoutKey[] = "AutomaticProposalTimeout";
static const char autoInsertBracesKey[] = "AutoInsertBraces";
static const char surroundingAutoBracketsKey[] = "SurroundingAutoBrackets";
static const char autoInsertQuotesKey[] = "AutoInsertQuotes";
static const char surroundingAutoQuotesKey[] = "SurroundingAutoQuotes";
static const char partiallyCompleteKey[] = "PartiallyComplete";
static const char spaceAfterFunctionNameKey[] = "SpaceAfterFunctionName";
static const char autoSplitStringsKey[] = "AutoSplitStrings";
static const char autoInsertBracesKey[] = "AutoInsertBraces";
static const char surroundingAutoBracketsKey[] = "SurroundingAutoBrackets";
static const char autoInsertQuotesKey[] = "AutoInsertQuotes";
static const char surroundingAutoQuotesKey[] = "SurroundingAutoQuotes";
static const char partiallyCompleteKey[] = "PartiallyComplete";
static const char spaceAfterFunctionNameKey[] = "SpaceAfterFunctionName";
static const char autoSplitStringsKey[] = "AutoSplitStrings";
using namespace TextEditor;
CompletionSettings::CompletionSettings()
: m_caseSensitivity(CaseInsensitive)
, m_completionTrigger(AutomaticCompletion)
, m_automaticProposalTimeoutInMs(400)
, m_autoInsertBrackets(true)
, m_surroundingAutoBrackets(true)
, m_autoInsertQuotes(true)
, m_surroundingAutoQuotes(true)
, m_partiallyComplete(true)
, m_spaceAfterFunctionName(false)
, m_autoSplitStrings(true)
{
}
void CompletionSettings::toSettings(const QString &category, QSettings *s) const
{
QString group = QLatin1String(groupPostfix);
QString group(groupPostfix);
if (!category.isEmpty())
group.insert(0, category);
s->beginGroup(group);
s->setValue(QLatin1String(caseSensitivityKey), (int) m_caseSensitivity);
s->setValue(QLatin1String(completionTriggerKey), (int) m_completionTrigger);
s->setValue(QLatin1String(automaticProposalTimeoutKey), m_automaticProposalTimeoutInMs);
s->setValue(QLatin1String(autoInsertBracesKey), m_autoInsertBrackets);
s->setValue(QLatin1String(surroundingAutoBracketsKey), m_surroundingAutoBrackets);
s->setValue(QLatin1String(autoInsertQuotesKey), m_autoInsertQuotes);
s->setValue(QLatin1String(surroundingAutoQuotesKey), m_surroundingAutoQuotes);
s->setValue(QLatin1String(partiallyCompleteKey), m_partiallyComplete);
s->setValue(QLatin1String(spaceAfterFunctionNameKey), m_spaceAfterFunctionName);
s->setValue(QLatin1String(autoSplitStringsKey), m_autoSplitStrings);
s->setValue(caseSensitivityKey, (int) m_caseSensitivity);
s->setValue(completionTriggerKey, (int) m_completionTrigger);
s->setValue(automaticProposalTimeoutKey, m_automaticProposalTimeoutInMs);
s->setValue(autoInsertBracesKey, m_autoInsertBrackets);
s->setValue(surroundingAutoBracketsKey, m_surroundingAutoBrackets);
s->setValue(autoInsertQuotesKey, m_autoInsertQuotes);
s->setValue(surroundingAutoQuotesKey, m_surroundingAutoQuotes);
s->setValue(partiallyCompleteKey, m_partiallyComplete);
s->setValue(spaceAfterFunctionNameKey, m_spaceAfterFunctionName);
s->setValue(autoSplitStringsKey, m_autoSplitStrings);
s->endGroup();
}
void CompletionSettings::fromSettings(const QString &category, const QSettings *s)
{
QString group = QLatin1String(groupPostfix);
QString group(groupPostfix);
if (!category.isEmpty())
group.insert(0, category);
group += QLatin1Char('/');
group += '/';
*this = CompletionSettings(); // Assign defaults
m_caseSensitivity = (CaseSensitivity) s->value(group + QLatin1String(caseSensitivityKey), m_caseSensitivity).toInt();
m_completionTrigger = (CompletionTrigger) s->value(group + QLatin1String(completionTriggerKey), m_completionTrigger).toInt();
m_automaticProposalTimeoutInMs = s->value(group + QLatin1String(automaticProposalTimeoutKey), m_automaticProposalTimeoutInMs).toInt();
m_autoInsertBrackets = s->value(group + QLatin1String(autoInsertBracesKey), m_autoInsertBrackets).toBool();
m_surroundingAutoBrackets = s->value(group + QLatin1String(surroundingAutoBracketsKey), m_surroundingAutoBrackets).toBool();
m_autoInsertQuotes = s->value(group + QLatin1String(autoInsertQuotesKey), m_autoInsertQuotes).toBool();
m_surroundingAutoQuotes = s->value(group + QLatin1String(surroundingAutoQuotesKey), m_surroundingAutoQuotes).toBool();
m_partiallyComplete = s->value(group + QLatin1String(partiallyCompleteKey), m_partiallyComplete).toBool();
m_spaceAfterFunctionName = s->value(group + QLatin1String(spaceAfterFunctionNameKey), m_spaceAfterFunctionName).toBool();
m_autoSplitStrings = s->value(group + QLatin1String(autoSplitStringsKey), m_autoSplitStrings).toBool();
m_caseSensitivity = (CaseSensitivity)
s->value(group + caseSensitivityKey, m_caseSensitivity).toInt();
m_completionTrigger = (CompletionTrigger)
s->value(group + completionTriggerKey, m_completionTrigger).toInt();
m_automaticProposalTimeoutInMs =
s->value(group + automaticProposalTimeoutKey, m_automaticProposalTimeoutInMs).toInt();
m_autoInsertBrackets =
s->value(group + autoInsertBracesKey, m_autoInsertBrackets).toBool();
m_surroundingAutoBrackets =
s->value(group + surroundingAutoBracketsKey, m_surroundingAutoBrackets).toBool();
m_autoInsertQuotes =
s->value(group + autoInsertQuotesKey, m_autoInsertQuotes).toBool();
m_surroundingAutoQuotes =
s->value(group + surroundingAutoQuotesKey, m_surroundingAutoQuotes).toBool();
m_partiallyComplete =
s->value(group + partiallyCompleteKey, m_partiallyComplete).toBool();
m_spaceAfterFunctionName =
s->value(group + spaceAfterFunctionNameKey, m_spaceAfterFunctionName).toBool();
m_autoSplitStrings =
s->value(group + autoSplitStringsKey, m_autoSplitStrings).toBool();
}
bool CompletionSettings::equals(const CompletionSettings &cs) const
{
return m_caseSensitivity == cs.m_caseSensitivity
&& m_completionTrigger == cs.m_completionTrigger
&& m_automaticProposalTimeoutInMs == cs.m_automaticProposalTimeoutInMs
&& m_autoInsertBrackets == cs.m_autoInsertBrackets
&& m_surroundingAutoBrackets == cs.m_surroundingAutoBrackets
&& m_autoInsertQuotes == cs.m_autoInsertQuotes
&& m_surroundingAutoQuotes == cs.m_surroundingAutoQuotes
&& m_partiallyComplete == cs.m_partiallyComplete
&& m_spaceAfterFunctionName == cs.m_spaceAfterFunctionName
&& m_autoSplitStrings == cs.m_autoSplitStrings
return m_caseSensitivity == cs.m_caseSensitivity
&& m_completionTrigger == cs.m_completionTrigger
&& m_automaticProposalTimeoutInMs == cs.m_automaticProposalTimeoutInMs
&& m_autoInsertBrackets == cs.m_autoInsertBrackets
&& m_surroundingAutoBrackets == cs.m_surroundingAutoBrackets
&& m_autoInsertQuotes == cs.m_autoInsertQuotes
&& m_surroundingAutoQuotes == cs.m_surroundingAutoQuotes
&& m_partiallyComplete == cs.m_partiallyComplete
&& m_spaceAfterFunctionName == cs.m_spaceAfterFunctionName
&& m_autoSplitStrings == cs.m_autoSplitStrings
;
}
......@@ -51,23 +51,21 @@ enum CompletionTrigger {
class TEXTEDITOR_EXPORT CompletionSettings
{
public:
CompletionSettings();
void toSettings(const QString &category, QSettings *s) const;
void fromSettings(const QString &category, const QSettings *s);
bool equals(const CompletionSettings &bs) const;
CaseSensitivity m_caseSensitivity;
CompletionTrigger m_completionTrigger;
int m_automaticProposalTimeoutInMs;
bool m_autoInsertBrackets;
bool m_surroundingAutoBrackets;
bool m_autoInsertQuotes;
bool m_surroundingAutoQuotes;
bool m_partiallyComplete;
bool m_spaceAfterFunctionName;
bool m_autoSplitStrings;
CaseSensitivity m_caseSensitivity = CaseInsensitive;
CompletionTrigger m_completionTrigger = AutomaticCompletion;
int m_automaticProposalTimeoutInMs = 400;
bool m_autoInsertBrackets = true;
bool m_surroundingAutoBrackets = true;
bool m_autoInsertQuotes = true;
bool m_surroundingAutoQuotes = true;
bool m_partiallyComplete = true;
bool m_spaceAfterFunctionName = false;
bool m_autoSplitStrings = true;
};
inline bool operator==(const CompletionSettings &t1, const CompletionSettings &t2) { return t1.equals(t2); }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment