TextEditor: Re-work comment definition handling

No need for most of the machinery.

Change-Id: I9078174582d83da94c6c7f20282fd3a5f1742911
Reviewed-by: Christian Stenger <christian.stenger@digia.com>
Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
hjk
2014-07-30 16:01:34 +02:00
parent f3a83367d6
commit f6b48950ed
23 changed files with 65 additions and 155 deletions

View File

@@ -34,12 +34,30 @@
using namespace Utils;
CommentDefinition::CommentDefinition() :
isAfterWhiteSpaces(false),
singleLine(QLatin1String("//")),
multiLineStart(QLatin1String("/*")),
multiLineEnd(QLatin1String("*/"))
isAfterWhiteSpaces(false)
{}
void CommentDefinition::setStyle(Style style)
{
switch (style) {
case CppStyle:
singleLine = QLatin1String("//");
multiLineStart = QLatin1String("/*");
multiLineEnd = QLatin1String("*/");
break;
case HashStyle:
singleLine = QLatin1String("#");
multiLineStart.clear();
multiLineEnd.clear();
break;
}
}
bool CommentDefinition::isValid() const
{
return hasSingleLineStyle() || hasMultiLineStyle();
}
bool CommentDefinition::hasSingleLineStyle() const
{
return !singleLine.isEmpty();
@@ -50,13 +68,6 @@ bool CommentDefinition::hasMultiLineStyle() const
return !multiLineStart.isEmpty() && !multiLineEnd.isEmpty();
}
void CommentDefinition::clearCommentStyles()
{
singleLine.clear();
multiLineStart.clear();
multiLineEnd.clear();
}
static bool isComment(const QString &text, int index,
const QString &commentType)
{
@@ -76,7 +87,7 @@ static bool isComment(const QString &text, int index,
void Utils::unCommentSelection(QPlainTextEdit *edit, const CommentDefinition &definition)
{
if (!definition.hasSingleLineStyle() && !definition.hasMultiLineStyle())
if (!definition.isValid())
return;
QTextCursor cursor = edit->textCursor();