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 @@ ...@@ -42,7 +42,6 @@
#include <QDebug> #include <QDebug>
namespace qmt { namespace qmt {
class ConfigController::ConfigControllerPrivate class ConfigController::ConfigControllerPrivate
......
...@@ -40,35 +40,24 @@ class StereotypeController; ...@@ -40,35 +40,24 @@ class StereotypeController;
class StereotypeIcon; class StereotypeIcon;
class Toolbar; class Toolbar;
class QMT_EXPORT ConfigController : public QObject class QMT_EXPORT ConfigController : public QObject
{ {
Q_OBJECT Q_OBJECT
class ConfigControllerPrivate; class ConfigControllerPrivate;
public: public:
explicit ConfigController(QObject *parent = 0); explicit ConfigController(QObject *parent = 0);
~ConfigController(); ~ConfigController();
public:
void setStereotypeController(StereotypeController *stereotypeController); void setStereotypeController(StereotypeController *stereotypeController);
public:
void readStereotypeDefinitions(const QString &path); void readStereotypeDefinitions(const QString &path);
private slots: private slots:
void onStereotypeIconParsed(const StereotypeIcon &stereotypeIcon); void onStereotypeIconParsed(const StereotypeIcon &stereotypeIcon);
void onToolbarParsed(const Toolbar &toolbar); void onToolbarParsed(const Toolbar &toolbar);
private: private:
ConfigControllerPrivate *d; ConfigControllerPrivate *d;
}; };
......
...@@ -38,21 +38,13 @@ namespace qmt { ...@@ -38,21 +38,13 @@ namespace qmt {
class QMT_EXPORT SourcePos class QMT_EXPORT SourcePos
{ {
public: public:
SourcePos(); SourcePos();
SourcePos(int sourceId, int lineNumber, int columnNumber = -1); SourcePos(int sourceId, int lineNumber, int columnNumber = -1);
public:
bool isValid() const { return m_sourceId >= 0 && m_lineNumber >= 0; } bool isValid() const { return m_sourceId >= 0 && m_lineNumber >= 0; }
int sourceId() const { return m_sourceId; } int sourceId() const { return m_sourceId; }
int lineNumber() const { return m_lineNumber; } int lineNumber() const { return m_lineNumber; }
bool hasColumnNumber() const { return m_columnNumber >= 0; } bool hasColumnNumber() const { return m_columnNumber >= 0; }
int columnNumber() const { return m_columnNumber; } int columnNumber() const { return m_columnNumber; }
private: private:
......
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
#include "sourcepos.h" #include "sourcepos.h"
namespace qmt { namespace qmt {
class ITextSource; class ITextSource;
...@@ -45,111 +44,74 @@ class StereotypeIcon; ...@@ -45,111 +44,74 @@ class StereotypeIcon;
class Toolbar; class Toolbar;
class ShapeValueF; class ShapeValueF;
class QMT_EXPORT StereotypeDefinitionParserError : class QMT_EXPORT StereotypeDefinitionParserError : public Exception
public Exception
{ {
public: public:
StereotypeDefinitionParserError(const QString &errorMsg, const SourcePos &sourcePos); StereotypeDefinitionParserError(const QString &errorMsg, const SourcePos &sourcePos);
~StereotypeDefinitionParserError(); ~StereotypeDefinitionParserError();
public:
SourcePos sourcePos() const { return m_sourcePos; } SourcePos sourcePos() const { return m_sourcePos; }
private: private:
SourcePos m_sourcePos; SourcePos m_sourcePos;
}; };
class QMT_EXPORT StereotypeDefinitionParser : public QObject class QMT_EXPORT StereotypeDefinitionParser : public QObject
{ {
Q_OBJECT Q_OBJECT
class StereotypeDefinitionParserPrivate; class StereotypeDefinitionParserPrivate;
class IconCommandParameter; class IconCommandParameter;
public: public:
explicit StereotypeDefinitionParser(QObject *parent = 0); explicit StereotypeDefinitionParser(QObject *parent = 0);
~StereotypeDefinitionParser(); ~StereotypeDefinitionParser();
signals: signals:
void iconParsed(const StereotypeIcon &stereotypeIcon); void iconParsed(const StereotypeIcon &stereotypeIcon);
void toolbarParsed(const Toolbar &toolbar); void toolbarParsed(const Toolbar &toolbar);
public: public:
void parse(ITextSource *source); void parse(ITextSource *source);
private: private:
void parseFile(); void parseFile();
void parseIcon(); void parseIcon();
void parseIconProperties(StereotypeIcon *stereotypeIcon); void parseIconProperties(StereotypeIcon *stereotypeIcon);
void parseToolbar(); void parseToolbar();
void parseToolbarProperties(Toolbar *toolbar); void parseToolbarProperties(Toolbar *toolbar);
QString parseStringProperty(); QString parseStringProperty();
int parseIntProperty(); int parseIntProperty();
qreal parseFloatProperty(); qreal parseFloatProperty();
QString parseIdentifierProperty(); QString parseIdentifierProperty();
QList<QString> parseIdentifierListProperty(); QList<QString> parseIdentifierListProperty();
bool parseBoolProperty(); bool parseBoolProperty();
QColor parseColorProperty(); QColor parseColorProperty();
void parseIconCommands(StereotypeIcon *stereotypeIcon); void parseIconCommands(StereotypeIcon *stereotypeIcon);
QList<ShapeValueF> parseIconCommandParameters(const QList<IconCommandParameter> &parameters); QList<ShapeValueF> parseIconCommandParameters(const QList<IconCommandParameter> &parameters);
void parseToolbarCommands(Toolbar *toolbar); void parseToolbarCommands(Toolbar *toolbar);
QString parseStringExpression(); QString parseStringExpression();
qreal parseFloatExpression(); qreal parseFloatExpression();
int parseIntExpression(); int parseIntExpression();
QString parseIdentifierExpression(); QString parseIdentifierExpression();
bool parseBoolExpression(); bool parseBoolExpression();
QColor parseColorExpression(); QColor parseColorExpression();
Token readNextToken(); Token readNextToken();
qreal expectAbsoluteValue(const ShapeValueF &value, const SourcePos &sourcePos); qreal expectAbsoluteValue(const ShapeValueF &value, const SourcePos &sourcePos);
void expectSemicolonOrEndOfLine(); void expectSemicolonOrEndOfLine();
bool nextIsComma(); bool nextIsComma();
void expectOperator(int op, const QString &opName); void expectOperator(int op, const QString &opName);
void expectComma(); void expectComma();
void expectColon(); void expectColon();
private:
StereotypeDefinitionParserPrivate *d; StereotypeDefinitionParserPrivate *d;
}; };
} } // namespace qmt
#endif // QMT_STEREOTYPEDEFINITIONPARSER_H #endif // QMT_STEREOTYPEDEFINITIONPARSER_H
...@@ -67,9 +67,8 @@ SourceChar StringTextSource::readNextChar() ...@@ -67,9 +67,8 @@ SourceChar StringTextSource::readNextChar()
QMT_CHECK(m_lineNumber >= 0); QMT_CHECK(m_lineNumber >= 0);
QMT_CHECK(m_columnNumber >= 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)); return SourceChar(QChar(), SourcePos(m_sourceId, m_lineNumber, m_columnNumber));
}
SourcePos pos(m_sourceId, m_lineNumber, m_columnNumber); SourcePos pos(m_sourceId, m_lineNumber, m_columnNumber);
QChar ch(m_text.at(m_index)); QChar ch(m_text.at(m_index));
......
...@@ -37,37 +37,25 @@ ...@@ -37,37 +37,25 @@
namespace qmt { namespace qmt {
class QMT_EXPORT StringTextSource : class QMT_EXPORT StringTextSource : public ITextSource
public ITextSource
{ {
public: public:
StringTextSource(); StringTextSource();
~StringTextSource(); ~StringTextSource();
public: public:
void setText(const QString &text); void setText(const QString &text);
int sourceId() const { return m_sourceId; } int sourceId() const { return m_sourceId; }
void setSourceId(int sourceId); void setSourceId(int sourceId);
// ITextSource interface // ITextSource interface
public:
SourceChar readNextChar(); SourceChar readNextChar();
private: private:
QString m_text; QString m_text;
int m_sourceId; int m_sourceId;
int m_index; int m_index;
int m_lineNumber; int m_lineNumber;
int m_columnNumber; int m_columnNumber;
}; };
......
...@@ -88,9 +88,8 @@ TextScanner::~TextScanner() ...@@ -88,9 +88,8 @@ TextScanner::~TextScanner()
void TextScanner::setKeywords(const QList<QPair<QString, int> > &keywords) void TextScanner::setKeywords(const QList<QPair<QString, int> > &keywords)
{ {
d->m_keywordToSubtypeMap.clear(); d->m_keywordToSubtypeMap.clear();
foreach (const DefTuple &tuple, keywords) { foreach (const DefTuple &tuple, keywords)
d->m_keywordToSubtypeMap.insert(tuple.first.toLower(), tuple.second); d->m_keywordToSubtypeMap.insert(tuple.first.toLower(), tuple.second);
}
} }
void TextScanner::setOperators(const QList<QPair<QString, int> > &operators) void TextScanner::setOperators(const QList<QPair<QString, int> > &operators)
...@@ -102,13 +101,11 @@ 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) { foreach (const DefTuple &tuple, operators) {
QString op = tuple.first; QString op = tuple.first;
d->m_operatorToSubtypeMap.insert(op, tuple.second); 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_maxOperatorLength = op.length();
}
d->m_operatorFirstCharsSet.insert(op.at(0)); d->m_operatorFirstCharsSet.insert(op.at(0));
foreach (const QChar ch, op) { foreach (const QChar ch, op)
d->m_operatorCharsSet.insert(ch); d->m_operatorCharsSet.insert(ch);
}
} }
} }
...@@ -124,28 +121,26 @@ SourcePos TextScanner::sourcePos() const ...@@ -124,28 +121,26 @@ SourcePos TextScanner::sourcePos() const
Token TextScanner::read() Token TextScanner::read()
{ {
if (!d->m_unreadTokens.isEmpty()) { if (!d->m_unreadTokens.isEmpty())
return d->m_unreadTokens.pop(); return d->m_unreadTokens.pop();
}
skipWhitespaces(); skipWhitespaces();
SourceChar sourceChar = readChar(); SourceChar sourceChar = readChar();
if (sourceChar.ch == QLatin1Char('\'') || sourceChar.ch == QLatin1Char('\"')) { if (sourceChar.ch == QLatin1Char('\'') || sourceChar.ch == QLatin1Char('\"'))
return scanString(sourceChar); return scanString(sourceChar);
} else if (sourceChar.ch.isDigit()) { else if (sourceChar.ch.isDigit())
return scanNumber(sourceChar); return scanNumber(sourceChar);
} else if (sourceChar.ch.isLetter() || sourceChar.ch == QLatin1Char('_')) { else if (sourceChar.ch.isLetter() || sourceChar.ch == QLatin1Char('_'))
return scanIdentifier(sourceChar); return scanIdentifier(sourceChar);
} else if (sourceChar.ch == QLatin1Char('#')) { else if (sourceChar.ch == QLatin1Char('#'))
return scanColorIdentifier(sourceChar); 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); return Token(Token::TokenEndOfLine, QString(), sourceChar.pos);
} else if (sourceChar.ch.isNull()) { else if (sourceChar.ch.isNull())
return Token(Token::TokenEndOfInput, QString(), sourceChar.pos); 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); return scanOperator(sourceChar);
} else { else
throw TextScannerError(QStringLiteral("Unexpected character."), sourceChar.pos); throw TextScannerError(QStringLiteral("Unexpected character."), sourceChar.pos);
}
} }
void TextScanner::unread(const Token &token) void TextScanner::unread(const Token &token)
...@@ -156,11 +151,10 @@ void TextScanner::unread(const Token &token) ...@@ -156,11 +151,10 @@ void TextScanner::unread(const Token &token)
SourceChar TextScanner::readChar() SourceChar TextScanner::readChar()
{ {
SourceChar ch; SourceChar ch;
if (!d->m_unreadSourceChars.isEmpty()) { if (!d->m_unreadSourceChars.isEmpty())
ch = d->m_unreadSourceChars.pop(); ch = d->m_unreadSourceChars.pop();
} else { else
ch = d->m_source->readNextChar(); ch = d->m_source->readNextChar();
}
d->m_lastSourcePos = ch.pos; d->m_lastSourcePos = ch.pos;
return ch; return ch;
} }
...@@ -179,9 +173,8 @@ void TextScanner::skipWhitespaces() ...@@ -179,9 +173,8 @@ void TextScanner::skipWhitespaces()
if (secondSourceChar.ch == QLatin1Char('/')) { if (secondSourceChar.ch == QLatin1Char('/')) {
for (;;) { for (;;) {
SourceChar commentChar = readChar(); 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; break;
}
} }
} else { } else {
unreadChar(secondSourceChar); unreadChar(secondSourceChar);
...@@ -203,19 +196,18 @@ Token TextScanner::scanString(const SourceChar &delimiterChar) ...@@ -203,19 +196,18 @@ Token TextScanner::scanString(const SourceChar &delimiterChar)
return Token(Token::TokenString, text, delimiterChar.pos); return Token(Token::TokenString, text, delimiterChar.pos);
} else if (sourceChar.ch == QLatin1Char('\\')) { } else if (sourceChar.ch == QLatin1Char('\\')) {
sourceChar = readChar(); sourceChar = readChar();
if (sourceChar.ch == QLatin1Char('n')) { if (sourceChar.ch == QLatin1Char('n'))
text += QLatin1Char('\n'); text += QLatin1Char('\n');
} else if (sourceChar.ch == QLatin1Char('\\')) { else if (sourceChar.ch == QLatin1Char('\\'))
text += QLatin1Char('\\'); text += QLatin1Char('\\');
} else if (sourceChar.ch == QLatin1Char('t')) { else if (sourceChar.ch == QLatin1Char('t'))
text += QLatin1Char('\t'); text += QLatin1Char('\t');
} else if (sourceChar.ch == QLatin1Char('\"')) { else if (sourceChar.ch == QLatin1Char('\"'))
text += QLatin1Char('\"'); text += QLatin1Char('\"');
} else if (sourceChar.ch == QLatin1Char('\'')) { else if (sourceChar.ch == QLatin1Char('\''))
text += QLatin1Char('\''); text += QLatin1Char('\'');
} else { else
throw TextScannerError(QStringLiteral("Unexpected character after '\\' in string constant."), sourceChar.pos); throw TextScannerError(QStringLiteral("Unexpected character after '\\' in string constant."), sourceChar.pos);
}
} else if (sourceChar.ch == QChar::LineFeed || sourceChar.ch == QChar::CarriageReturn) { } else if (sourceChar.ch == QChar::LineFeed || sourceChar.ch == QChar::CarriageReturn) {
throw TextScannerError(QStringLiteral("Unexpected end of line in string constant."), sourceChar.pos); throw TextScannerError(QStringLiteral("Unexpected end of line in string constant."), sourceChar.pos);
} else { } else {
...@@ -230,18 +222,16 @@ Token TextScanner::scanNumber(const SourceChar &firstDigit) ...@@ -230,18 +222,16 @@ Token TextScanner::scanNumber(const SourceChar &firstDigit)
SourceChar sourceChar; SourceChar sourceChar;
for (;;) { for (;;) {
sourceChar = readChar(); sourceChar = readChar();
if (!sourceChar.ch.isDigit()) { if (!sourceChar.ch.isDigit())
break; break;
}
text += sourceChar.ch; text += sourceChar.ch;
} }
if (sourceChar.ch == QLatin1Char('.')) { if (sourceChar.ch == QLatin1Char('.')) {