Commit 64e2ba87 authored by Jochen Becher's avatar Jochen Becher

Add modeling library

Modeling library implements the entities, diagrams and widget Ui for
ModelEditor plugin and tools. This is a 3rdparty library not following
the QtCreator coding style.

Change-Id: I981e38a10fff1c1792f285d5837553aa7596cd2f
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent 77661e37
INCLUDEPATH += $$PWD $$PWD/qtserialization/inc
include(qstringparser/qstringparser.pri)
include(qtserialization/qtserialization.pri)
include(qmt/qmt.pri)
/***************************************************************************
**
** Copyright (C) 2015 Jochen Becher
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "configcontroller.h"
#include "stereotypedefinitionparser.h"
#include "textscanner.h"
#include "stringtextsource.h"
#include "qmt/stereotype/stereotypecontroller.h"
#include <QDir>
#include <QFileInfo>
#include <QFile>
#include <QDebug>
namespace qmt {
struct ConfigController::ConfigControllerPrivate
{
ConfigControllerPrivate()
: _stereotype_controller(0)
{
}
StereotypeController *_stereotype_controller;
};
ConfigController::ConfigController(QObject *parent)
: QObject(parent),
d(new ConfigControllerPrivate)
{
}
ConfigController::~ConfigController()
{
delete d;
}
void ConfigController::setStereotypeController(StereotypeController *stereotype_controller)
{
d->_stereotype_controller = stereotype_controller;
}
void ConfigController::readStereotypeDefinitions(const QString &path)
{
StereotypeDefinitionParser parser;
connect(&parser, SIGNAL(iconParsed(StereotypeIcon)), this, SLOT(onStereotypeIconParsed(StereotypeIcon)));
connect(&parser, SIGNAL(toolbarParsed(Toolbar)), this, SLOT(onToolbarParsed(Toolbar)));
QDir dir(path);
dir.setNameFilters(QStringList() << QStringLiteral("*.def"));
foreach (const QString &file_name, dir.entryList(QDir::Files)) {
QFile file(QFileInfo(dir, file_name).absoluteFilePath());
if (file.open(QIODevice::ReadOnly)) {
QString text = QString::fromUtf8(file.readAll());
file.close();
StringTextSource source;
source.setSourceId(1);
source.setText(text);
try {
parser.parse(&source);
} catch (StereotypeDefinitionParserError x) {
qDebug() << x.getErrorMsg() << "in line" << x.getSourcePos().getLineNumber();
} catch (TextScannerError x) {
qDebug() << x.getErrorMsg() << "in line" << x.getSourcePos().getLineNumber();
} catch (...) {
}
}
}
}
void ConfigController::onStereotypeIconParsed(const StereotypeIcon &stereotype_icon)
{
d->_stereotype_controller->addStereotypeIcon(stereotype_icon);
}
void ConfigController::onToolbarParsed(const Toolbar &toolbar)
{
d->_stereotype_controller->addToolbar(toolbar);
}
} // namespace qmt
/***************************************************************************
**
** Copyright (C) 2015 Jochen Becher
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef QMT_CONFIGCONTROLLER_H
#define QMT_CONFIGCONTROLLER_H
#include <QObject>
#include "qmt/infrastructure/qmt_global.h"
namespace qmt {
class StereotypeController;
class StereotypeIcon;
class Toolbar;
class QMT_EXPORT ConfigController : public QObject
{
Q_OBJECT
struct ConfigControllerPrivate;
public:
explicit ConfigController(QObject *parent = 0);
~ConfigController();
public:
void setStereotypeController(StereotypeController *stereotype_controller);
public:
void readStereotypeDefinitions(const QString &path);
private slots:
void onStereotypeIconParsed(const StereotypeIcon &stereotype_icon);
void onToolbarParsed(const Toolbar &toolbar);
private:
ConfigControllerPrivate *d;
};
} // namespace qmt
#endif // QMT_CONFIGCONTROLLER_H
/***************************************************************************
**
** Copyright (C) 2015 Jochen Becher
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "sourcepos.h"
namespace qmt {
SourcePos::SourcePos()
: _source_id(-1),
_line_number(-1),
_column_number(-1)
{
}
SourcePos::SourcePos(int source_id, int line_number, int column_number)
: _source_id(source_id),
_line_number(line_number),
_column_number(column_number)
{
}
} // namespace qmt
/***************************************************************************
**
** Copyright (C) 2015 Jochen Becher
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef QMT_SOURCEPOS_H
#define QMT_SOURCEPOS_H
#include "qmt/infrastructure/qmt_global.h"
namespace qmt {
class QMT_EXPORT SourcePos
{
public:
SourcePos();
SourcePos(int source_id, int line_number, int column_number = -1);
public:
bool isValid() const { return _source_id >= 0 && _line_number >= 0; }
int getSourceId() const { return _source_id; }
int getLineNumber() const { return _line_number; }
bool hasColumnNumber() const { return _column_number >= 0; }
int getColumnNumber() const { return _column_number; }
private:
int _source_id;
int _line_number;
int _column_number;
};
} // namespace qmt
#endif // QMT_SOURCEPOS_H
/***************************************************************************
**
** Copyright (C) 2015 Jochen Becher
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef QMT_STEREOTYPEDEFINITIONPARSER_H
#define QMT_STEREOTYPEDEFINITIONPARSER_H
#include <QObject>
#include "qmt/infrastructure/exceptions.h"
#include "sourcepos.h"
namespace qmt {
class ITextSource;
class Token;
class StereotypeIcon;
class Toolbar;
class ShapeValueF;
class QMT_EXPORT StereotypeDefinitionParserError :
public Exception
{
public:
StereotypeDefinitionParserError(const QString &error_msg, const SourcePos &source_pos);
~StereotypeDefinitionParserError();
public:
SourcePos getSourcePos() const { return _source_pos; }
private:
SourcePos _source_pos;
};
class QMT_EXPORT StereotypeDefinitionParser : public QObject
{
Q_OBJECT
struct StereotypeDefinitionParserPrivate;
struct IconCommandParameter;
public:
explicit StereotypeDefinitionParser(QObject *parent = 0);
~StereotypeDefinitionParser();
signals:
void iconParsed(const StereotypeIcon &stereotype_icon);
void toolbarParsed(const Toolbar &toolbar);
public:
void parse(ITextSource *source);
private:
void parseFile();
void parseIcon();
void parseIconProperties(StereotypeIcon *stereotype_icon);
void parseToolbar();
void parseToolbarProperties(Toolbar *toolbar);
QString parseStringProperty();
int parseIntProperty();
qreal parseFloatProperty();
QString parseIdentifierProperty();
QList<QString> parseIdentifierListProperty();
bool parseBoolProperty();
QColor parseColorProperty();
void parseIconCommands(StereotypeIcon *stereotype_icon);
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 &source_pos);
void expectSemicolonOrEndOfLine();
bool nextIsComma();
void expectOperator(int op, const QString &op_name);
void expectComma();
void expectColon();
private:
StereotypeDefinitionParserPrivate *d;
};
}
#endif // QMT_STEREOTYPEDEFINITIONPARSER_H
/***************************************************************************
**
** Copyright (C) 2015 Jochen Becher
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "stringtextsource.h"
#include "sourcepos.h"
#include "qmt/infrastructure/qmtassert.h"
namespace qmt {
StringTextSource::StringTextSource()
: _source_id(-1),
_index(-1),
_line_number(-1),
_column_number(-1)
{
}
StringTextSource::~StringTextSource()
{
}
void StringTextSource::setText(const QString &text)
{
_text = text;
_index = 0;
_line_number = 1;
_column_number = 1;
}
void StringTextSource::setSourceId(int source_id)
{
_source_id = source_id;
}
SourceChar StringTextSource::readNextChar()
{
QMT_CHECK(_source_id >= 0);
QMT_CHECK(_index >= 0);
QMT_CHECK(_line_number >= 0);
QMT_CHECK(_column_number >= 0);
if (_index >= _text.length()) {
return SourceChar(QChar(), SourcePos(_source_id, _line_number, _column_number));
}
SourcePos pos(_source_id, _line_number, _column_number);
QChar ch(_text.at(_index));