Commit 53335c2f authored by Jochen Becher's avatar Jochen Becher

ModelEditor: Apply some source code formatting rules

1. Reduce 2 or more empty lines to a single empty line
2. Remove duplicate access specifiers
3. Remove lots of single empty lines between member declarations
4. Remove braces around single lines
5. List base classes on same line as class declaration
6. Ensure opening brace of class declaration is on next line
7. Add comment to end of namespace block

Change-Id: I95e2efa3abea806683e0943d54d6f203ad4af0e4
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent f3902fff
......@@ -42,7 +42,6 @@
#include <QDebug>
namespace qmt {
class ConfigController::ConfigControllerPrivate
......
......@@ -40,35 +40,24 @@ class StereotypeController;
class StereotypeIcon;
class Toolbar;
class QMT_EXPORT ConfigController : public QObject
{
Q_OBJECT
class ConfigControllerPrivate;
public:
explicit ConfigController(QObject *parent = 0);
~ConfigController();
public:
void setStereotypeController(StereotypeController *stereotypeController);
public:
void readStereotypeDefinitions(const QString &path);
private slots:
void onStereotypeIconParsed(const StereotypeIcon &stereotypeIcon);
void onToolbarParsed(const Toolbar &toolbar);
private:
ConfigControllerPrivate *d;
};
......
......@@ -38,21 +38,13 @@ namespace qmt {
class QMT_EXPORT SourcePos
{
public:
SourcePos();
SourcePos(int sourceId, int lineNumber, int columnNumber = -1);
public:
bool isValid() const { return m_sourceId >= 0 && m_lineNumber >= 0; }
int sourceId() const { return m_sourceId; }
int lineNumber() const { return m_lineNumber; }
bool hasColumnNumber() const { return m_columnNumber >= 0; }
int columnNumber() const { return m_columnNumber; }
private:
......
......@@ -36,7 +36,6 @@
#include "sourcepos.h"
namespace qmt {
class ITextSource;
......@@ -45,111 +44,74 @@ class StereotypeIcon;
class Toolbar;
class ShapeValueF;
class QMT_EXPORT StereotypeDefinitionParserError :
public Exception
class QMT_EXPORT StereotypeDefinitionParserError : public Exception
{
public:
StereotypeDefinitionParserError(const QString &errorMsg, const SourcePos &sourcePos);
~StereotypeDefinitionParserError();
public:
SourcePos sourcePos() const { return m_sourcePos; }
private:
SourcePos m_sourcePos;
};
class QMT_EXPORT StereotypeDefinitionParser : public QObject
{
Q_OBJECT
class StereotypeDefinitionParserPrivate;
class IconCommandParameter;
public:
explicit StereotypeDefinitionParser(QObject *parent = 0);
~StereotypeDefinitionParser();
signals:
void iconParsed(const StereotypeIcon &stereotypeIcon);
void toolbarParsed(const Toolbar &toolbar);
public:
void parse(ITextSource *source);
private:
void parseFile();
void parseIcon();
void parseIconProperties(StereotypeIcon *stereotypeIcon);
void parseToolbar();
void parseToolbarProperties(Toolbar *toolbar);
QString parseStringProperty();
int parseIntProperty();
qreal parseFloatProperty();
QString parseIdentifierProperty();
QList<QString> parseIdentifierListProperty();
bool parseBoolProperty();
QColor parseColorProperty();
void parseIconCommands(StereotypeIcon *stereotypeIcon);
QList<ShapeValueF> parseIconCommandParameters(const QList<IconCommandParameter> &parameters);
void parseToolbarCommands(Toolbar *toolbar);
QString parseStringExpression();
qreal parseFloatExpression();
int parseIntExpression();
QString parseIdentifierExpression();
bool parseBoolExpression();
QColor parseColorExpression();
Token readNextToken();
qreal expectAbsoluteValue(const ShapeValueF &value, const SourcePos &sourcePos);
void expectSemicolonOrEndOfLine();
bool nextIsComma();
void expectOperator(int op, const QString &opName);
void expectComma();
void expectColon();
private:
StereotypeDefinitionParserPrivate *d;
};
}
} // namespace qmt
#endif // QMT_STEREOTYPEDEFINITIONPARSER_H
......@@ -67,9 +67,8 @@ SourceChar StringTextSource::readNextChar()
QMT_CHECK(m_lineNumber >= 0);
QMT_CHECK(m_columnNumber >= 0);
if (m_index >= m_text.length()) {
if (m_index >= m_text.length())
return SourceChar(QChar(), SourcePos(m_sourceId, m_lineNumber, m_columnNumber));
}
SourcePos pos(m_sourceId, m_lineNumber, m_columnNumber);
QChar ch(m_text.at(m_index));
......
......@@ -37,37 +37,25 @@
namespace qmt {
class QMT_EXPORT StringTextSource :
public ITextSource
class QMT_EXPORT StringTextSource : public ITextSource
{
public:
StringTextSource();
~StringTextSource();
public:
void setText(const QString &text);
int sourceId() const { return m_sourceId; }
void setSourceId(int sourceId);
// ITextSource interface
public:
SourceChar readNextChar();
private:
QString m_text;
int m_sourceId;
int m_index;
int m_lineNumber;
int m_columnNumber;
};
......
......@@ -88,9 +88,8 @@ TextScanner::~TextScanner()
void TextScanner::setKeywords(const QList<QPair<QString, int> > &keywords)
{
d->m_keywordToSubtypeMap.clear();
foreach (const DefTuple &tuple, keywords) {
foreach (const DefTuple &tuple, keywords)
d->m_keywordToSubtypeMap.insert(tuple.first.toLower(), tuple.second);
}
}
void TextScanner::setOperators(const QList<QPair<QString, int> > &operators)
......@@ -102,13 +101,11 @@ void TextScanner::setOperators(const QList<QPair<QString, int> > &operators)
foreach (const DefTuple &tuple, operators) {
QString op = tuple.first;
d->m_operatorToSubtypeMap.insert(op, tuple.second);
if (op.length() > d->m_maxOperatorLength) {
if (op.length() > d->m_maxOperatorLength)
d->m_maxOperatorLength = op.length();
}
d->m_operatorFirstCharsSet.insert(op.at(0));
foreach (const QChar ch, op) {
foreach (const QChar ch, op)
d->m_operatorCharsSet.insert(ch);
}
}
}
......@@ -124,28 +121,26 @@ SourcePos TextScanner::sourcePos() const
Token TextScanner::read()
{
if (!d->m_unreadTokens.isEmpty()) {
if (!d->m_unreadTokens.isEmpty())
return d->m_unreadTokens.pop();
}
skipWhitespaces();
SourceChar sourceChar = readChar();
if (sourceChar.ch == QLatin1Char('\'') || sourceChar.ch == QLatin1Char('\"')) {
if (sourceChar.ch == QLatin1Char('\'') || sourceChar.ch == QLatin1Char('\"'))
return scanString(sourceChar);
} else if (sourceChar.ch.isDigit()) {
else if (sourceChar.ch.isDigit())
return scanNumber(sourceChar);
} else if (sourceChar.ch.isLetter() || sourceChar.ch == QLatin1Char('_')) {
else if (sourceChar.ch.isLetter() || sourceChar.ch == QLatin1Char('_'))
return scanIdentifier(sourceChar);
} else if (sourceChar.ch == QLatin1Char('#')) {
else if (sourceChar.ch == QLatin1Char('#'))
return scanColorIdentifier(sourceChar);
} else if (sourceChar.ch == QChar::LineFeed || sourceChar.ch == QChar::CarriageReturn) {
else if (sourceChar.ch == QChar::LineFeed || sourceChar.ch == QChar::CarriageReturn)
return Token(Token::TokenEndOfLine, QString(), sourceChar.pos);
} else if (sourceChar.ch.isNull()) {
else if (sourceChar.ch.isNull())
return Token(Token::TokenEndOfInput, QString(), sourceChar.pos);
} else if (d->m_operatorFirstCharsSet.contains(sourceChar.ch)) {
else if (d->m_operatorFirstCharsSet.contains(sourceChar.ch))
return scanOperator(sourceChar);
} else {
else
throw TextScannerError(QStringLiteral("Unexpected character."), sourceChar.pos);
}
}
void TextScanner::unread(const Token &token)
......@@ -156,11 +151,10 @@ void TextScanner::unread(const Token &token)
SourceChar TextScanner::readChar()
{
SourceChar ch;
if (!d->m_unreadSourceChars.isEmpty()) {
if (!d->m_unreadSourceChars.isEmpty())
ch = d->m_unreadSourceChars.pop();
} else {
else
ch = d->m_source->readNextChar();
}
d->m_lastSourcePos = ch.pos;
return ch;
}
......@@ -179,9 +173,8 @@ void TextScanner::skipWhitespaces()
if (secondSourceChar.ch == QLatin1Char('/')) {
for (;;) {
SourceChar commentChar = readChar();
if (commentChar.ch.isNull() || commentChar.ch == QChar::LineFeed || commentChar.ch == QChar::CarriageReturn) {
if (commentChar.ch.isNull() || commentChar.ch == QChar::LineFeed || commentChar.ch == QChar::CarriageReturn)
break;
}
}
} else {
unreadChar(secondSourceChar);
......@@ -203,19 +196,18 @@ Token TextScanner::scanString(const SourceChar &delimiterChar)
return Token(Token::TokenString, text, delimiterChar.pos);
} else if (sourceChar.ch == QLatin1Char('\\')) {
sourceChar = readChar();
if (sourceChar.ch == QLatin1Char('n')) {
if (sourceChar.ch == QLatin1Char('n'))
text += QLatin1Char('\n');
} else if (sourceChar.ch == QLatin1Char('\\')) {
else if (sourceChar.ch == QLatin1Char('\\'))
text += QLatin1Char('\\');
} else if (sourceChar.ch == QLatin1Char('t')) {
else if (sourceChar.ch == QLatin1Char('t'))
text += QLatin1Char('\t');
} else if (sourceChar.ch == QLatin1Char('\"')) {
else if (sourceChar.ch == QLatin1Char('\"'))
text += QLatin1Char('\"');
} else if (sourceChar.ch == QLatin1Char('\'')) {
else if (sourceChar.ch == QLatin1Char('\''))
text += QLatin1Char('\'');
} else {
else
throw TextScannerError(QStringLiteral("Unexpected character after '\\' in string constant."), sourceChar.pos);
}
} else if (sourceChar.ch == QChar::LineFeed || sourceChar.ch == QChar::CarriageReturn) {
throw TextScannerError(QStringLiteral("Unexpected end of line in string constant."), sourceChar.pos);
} else {
......@@ -230,18 +222,16 @@ Token TextScanner::scanNumber(const SourceChar &firstDigit)
SourceChar sourceChar;
for (;;) {
sourceChar = readChar();
if (!sourceChar.ch.isDigit()) {
if (!sourceChar.ch.isDigit())
break;
}
text += sourceChar.ch;
}
if (sourceChar.ch == QLatin1Char('.')) {
text += sourceChar.ch;
for (;;) {
sourceChar = readChar();
if (!sourceChar.ch.isDigit()) {
if (!sourceChar.ch.isDigit())
break;
}
text += sourceChar.ch;
}
unreadChar(sourceChar);
......@@ -261,9 +251,8 @@ Token TextScanner::scanIdentifier(const SourceChar &firstChar)
if (!sourceChar.ch.isLetterOrNumber() && sourceChar.ch != QLatin1Char('_')) {
unreadChar(sourceChar);
QString keyword = text.toLower();
if (d->m_keywordToSubtypeMap.contains(keyword)) {
if (d->m_keywordToSubtypeMap.contains(keyword))
return Token(Token::TokenKeyword, d->m_keywordToSubtypeMap.value(keyword), text, firstChar.pos);
}
return Token(Token::TokenIdentifier, text, firstChar.pos);
}
text += sourceChar.ch;
......
......@@ -43,75 +43,47 @@ class ITextSource;
class SourceChar;
class Token;
class QMT_EXPORT TextScannerError :
public Exception
class QMT_EXPORT TextScannerError : public Exception
{
public:
TextScannerError(const QString &errorMsg, const SourcePos &sourcePos);
~TextScannerError();
public:
SourcePos sourcePos() const { return m_sourcePos; }
private:
SourcePos m_sourcePos;
};
class QMT_EXPORT TextScanner : public QObject
{
Q_OBJECT
class TextScannerPrivate;
public:
explicit TextScanner(QObject *parent = 0);
~TextScanner();
signals:
public:
void setKeywords(const QList<QPair<QString, int> > &keywords);
void setOperators(const QList<QPair<QString, int> > &operators);
void setSource(ITextSource *textSource);
SourcePos sourcePos() const;
public:
Token read();
void unread(const Token &token);
private:
SourceChar readChar();
void unreadChar(const SourceChar &sourceChar);
void skipWhitespaces();
Token scanString(const SourceChar &delimiterChar);
Token scanNumber(const SourceChar &firstDigit);
Token scanIdentifier(const SourceChar &firstChar);
Token scanColorIdentifier(const SourceChar &firstChar);
Token scanOperator(const SourceChar &firstChar);
private:
TextScannerPrivate *d;
};
} // namespace qmt
......
......@@ -35,7 +35,6 @@
#include <QChar>
namespace qmt {
class SourceChar
......@@ -55,13 +54,11 @@ public:
class ITextSource
{
public:
virtual ~ITextSource() { }
virtual SourceChar readNextChar() = 0;
};
}
} // namespace qmt
#endif // QMT_TEXTSOURCE_H
......@@ -40,7 +40,6 @@ namespace qmt {
class Token
{
public:
enum Type {
TokenUndefined,
TokenEndOfInput,
......@@ -54,28 +53,18 @@ public:
TokenColor
};
public:
Token();
Token(Type type, const QString &text, const SourcePos &sourcePos);
Token(Type type, int subtype, const QString &text, const SourcePos &sourcePos);
~Token();
public:
Type type() const { return m_type; }
void setType(Type type);
int subtype() const { return m_subtype; }
void setSubtype(int subtype);
QString text() const { return m_text; }
void setText(const QString &text);
SourcePos sourcePos() const { return m_sourcePos; }
void setSourcePos(const SourcePos &sourcePos);
private:
......
......@@ -39,9 +39,7 @@ template<class T>
class Container
{
protected:
Container() { }
Container(const Container<T> &rhs)
: m_elements(rhs.m_elements)
{
......@@ -49,14 +47,11 @@ protected:
}
public:
~Container()
{
qDeleteAll(m_elements);
}
public:
Container &operator=(const Container<T> &rhs)
{
if (this != &rhs) {
......@@ -67,12 +62,8 @@ public: