From 7ea534dd1c8bf72200a999cae554d842d9035ba9 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Mon, 1 Jan 2018 18:44:35 +0100 Subject: New StatementDialog, rename diagram classes Other changes: - Use raw pointer instead of smart pointers to manage resources - Initial Painter implementation --- include/debugtools.h | 4 ++-- include/diagram/branch.h | 32 ++++++++++++++++++++++++++++++++ include/diagram/branchstatement.h | 32 -------------------------------- include/diagram/iterator.h | 30 ++++++++++++++++++++++++++++++ include/diagram/iteratorstatement.h | 30 ------------------------------ include/diagram/scope.h | 11 ++++++++--- include/diagram/statement.h | 6 +++++- include/io/serializer.h | 4 ++-- include/ui/painter.h | 26 +++++++++++++++++++++----- include/ui/statementdialog.h | 22 ++++++++++++++++++++++ 10 files changed, 122 insertions(+), 75 deletions(-) create mode 100644 include/diagram/branch.h delete mode 100644 include/diagram/branchstatement.h create mode 100644 include/diagram/iterator.h delete mode 100644 include/diagram/iteratorstatement.h create mode 100644 include/ui/statementdialog.h (limited to 'include') diff --git a/include/debugtools.h b/include/debugtools.h index cd6940b..1b34a2e 100644 --- a/include/debugtools.h +++ b/include/debugtools.h @@ -3,8 +3,8 @@ #ifdef QT_NO_DEBUG -void debug_msg(...) {} -void debug_err(...) {} +#define debug_msg(msg) +#define debug_err(msg) #else #include diff --git a/include/diagram/branch.h b/include/diagram/branch.h new file mode 100644 index 0000000..2024d78 --- /dev/null +++ b/include/diagram/branch.h @@ -0,0 +1,32 @@ +#ifndef DIAGRAM_BRANCHSTATEMENT_H +#define DIAGRAM_BRANCHSTATEMENT_H + +#include "diagram/statement.h" + +#include +#include + +namespace samb { + +/* Implementation for Statement::DECISION, Statement::SWITCH + */ +class Branch : public Statement +{ +public: + Branch(Type t, const QString &condition, pointer next); + + /* accessors */ + std::map& branches() { return _branches; } + std::size_t branchesCount() const { return _branchesCount; } + + inline const QString& condition() const { return text(); } + inline void condition(const QString &condition) { return text(condition); } + +private: + std::map _branches; + std::size_t _branchesCount = 0; +}; + +} /* namespace samb */ + +#endif /* DIAGRAM_BRANCHSTATEMENT_H */ diff --git a/include/diagram/branchstatement.h b/include/diagram/branchstatement.h deleted file mode 100644 index 3d8c385..0000000 --- a/include/diagram/branchstatement.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef DIAGRAM_BRANCHSTATEMENT_H -#define DIAGRAM_BRANCHSTATEMENT_H - -#include "diagram/statement.h" - -#include -#include - -namespace samb { - -/* Implementation for Statement::DECISION, Statement::SWITCH - */ -class BranchStatement : public Statement -{ -public: - BranchStatement(Type t, const QString &condition, pointer next); - - /* accessors */ - std::map& branches() { return _branches; } - std::size_t branches_count() const { return _branchesCount; } - - inline const QString& condition() const { return text(); } - inline void condition(const QString &condition) { return text(condition); } - -private: - std::map _branches; - std::size_t _branchesCount = 0; -}; - -} /* namespace samb */ - -#endif /* DIAGRAM_BRANCHSTATEMENT_H */ diff --git a/include/diagram/iterator.h b/include/diagram/iterator.h new file mode 100644 index 0000000..71c6a34 --- /dev/null +++ b/include/diagram/iterator.h @@ -0,0 +1,30 @@ +#ifndef DIAGRAM_ITERATORSTATEMENT_H +#define DIAGRAM_ITERATORSTATEMENT_H + +#include "diagram/statement.h" +#include "diagram/scope.h" + +#include + +namespace samb { + +/* Implementation for Statement::WHILE Statement::UNTIL + */ +class Iterator : public Statement +{ +public: + Iterator(Type t, const QString &condition, pointer next); + + /* accessors */ + Scope& inner() { return _inner; } + + inline const QString& condition() const { return text(); } + inline void condition(const QString &condition) { return text(condition); } + +private: + Scope _inner; +}; + +} /* namespace samb */ + +#endif /* DIAGRAM_ITERATORSTATEMENT_H */ diff --git a/include/diagram/iteratorstatement.h b/include/diagram/iteratorstatement.h deleted file mode 100644 index e7fbba0..0000000 --- a/include/diagram/iteratorstatement.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef DIAGRAM_ITERATORSTATEMENT_H -#define DIAGRAM_ITERATORSTATEMENT_H - -#include "diagram/statement.h" -#include "diagram/scope.h" - -#include - -namespace samb { - -/* Implementation for Statement::WHILE Statement::UNTIL - */ -class IteratorStatement : public Statement -{ -public: - IteratorStatement(Type t, const QString &condition, pointer next); - - /* accessors */ - Scope& inner() { return _inner; } - - inline const QString& condition() const { return text(); } - inline void condition(const QString &condition) { return text(condition); } - -private: - Scope _inner; -}; - -} /* namespace samb */ - -#endif /* DIAGRAM_ITERATORSTATEMENT_H */ diff --git a/include/diagram/scope.h b/include/diagram/scope.h index 63698dd..8ae7e79 100644 --- a/include/diagram/scope.h +++ b/include/diagram/scope.h @@ -22,6 +22,9 @@ public: explicit iterator(pointer statement); ~iterator(); + bool operator==(const iterator &other) const; + bool operator!=(const iterator &other) const; + iterator& operator++(); iterator& operator++(int); @@ -32,7 +35,7 @@ public: Statement::pointer _current; }; - explicit Scope(const QString &label); + Scope(const QString &label); Scope(const QString &label, Statement::pointer first); virtual ~Scope(); @@ -43,8 +46,10 @@ public: std::size_t size() const { return _size; } /* iterator */ - iterator begin() { return iterator(_head); } - iterator end() { return iterator(_tail); } + iterator begin(); + const iterator begin() const; + iterator end(); + const iterator end() const; private: Statement::pointer _head; diff --git a/include/diagram/statement.h b/include/diagram/statement.h index 5cce908..1d44d6a 100644 --- a/include/diagram/statement.h +++ b/include/diagram/statement.h @@ -26,7 +26,8 @@ namespace samb { class Statement { public: - using pointer = std::shared_ptr; +// using pointer = std::shared_ptr; + using pointer = Statement*; enum Type { PROCESS, @@ -40,6 +41,9 @@ public: const Type type; + template + static pointer make(Type t, Args&& ...args); + Statement(Type t, const QString &text); Statement(Type t, const QString &text, pointer next); virtual ~Statement(); diff --git a/include/io/serializer.h b/include/io/serializer.h index 901d913..e6a9b32 100644 --- a/include/io/serializer.h +++ b/include/io/serializer.h @@ -11,8 +11,8 @@ public: explicit Serializer(); virtual ~Serializer(); - bool write(const samb::Structogram &structogram, QFileInfo into); - bool load(samb::Structogram &structogram, QFileInfo from); + bool write(const samb::Structogram &structogram, const QFileInfo &into); + bool load(samb::Structogram &structogram, const QFileInfo &from); }; #endif // SERIALIZER_H diff --git a/include/ui/painter.h b/include/ui/painter.h index df62776..0a2accc 100644 --- a/include/ui/painter.h +++ b/include/ui/painter.h @@ -1,11 +1,15 @@ #ifndef PAINTER_H #define PAINTER_H -#include +#include "diagram/statement.h" +#include "diagram/structogram.h" -namespace Ui { -class Painter; -} +#include +#include +#include +#include +#include +#include class Painter : public QWidget { @@ -15,8 +19,20 @@ public: explicit Painter(QWidget *parent = 0); ~Painter(); + void structogram(samb::Structogram **structogram) { _structogram = structogram; } + const samb::Structogram structogram() const { return **_structogram; } + +protected: + void paintEvent(QPaintEvent *event); + private: - Ui::Painter *_ui; + samb::Structogram **_structogram = nullptr; + QFont _font; + QFontMetrics _fontMetrics; + + int _margin = 10; + + void drawStatement(QPainter &qp, samb::Statement &statement, const QRect &rect); }; #endif // PAINTER_H diff --git a/include/ui/statementdialog.h b/include/ui/statementdialog.h new file mode 100644 index 0000000..658ea53 --- /dev/null +++ b/include/ui/statementdialog.h @@ -0,0 +1,22 @@ +#ifndef STATEMENTDIALOG_H +#define STATEMENTDIALOG_H + +#include + +namespace Ui { +class StatementDialog; +} + +class StatementDialog : public QDialog +{ + Q_OBJECT + +public: + explicit StatementDialog(QWidget *parent = 0); + ~StatementDialog(); + +private: + Ui::StatementDialog *ui; +}; + +#endif // STATEMENTDIALOG_H -- cgit v1.2.1