From a7e74749a1c4edb2f8bc34c79e9bd1562de86ee9 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Tue, 19 Dec 2017 01:54:28 +0100 Subject: Change to Qt5 conding conventions Data structure changes: - Structogram is no longer just a scope, because it needs to store metadata - All structures now use QString instead of std::string, to integrate better in the Qt framework New code: - MainWindow ui code, building layout - MetadataDialog to change the metadata stored in the Structogram - Painter is a widget (still unimplemented) to show the structogram on the GUI --- OrbitingYeti.pro | 19 +++++--- OrbitingYeti.pro.user | 2 +- forms/mainwindow.ui | 76 ++++++++++++++++++++++++++----- forms/metadatadialog.ui | 84 +++++++++++++++++++++++++++++++++++ forms/painter.ui | 21 +++++++++ include/diagram/branchstatement.h | 30 +++++++++++++ include/diagram/branchstatement.hpp | 35 --------------- include/diagram/iteratorstatement.h | 28 ++++++++++++ include/diagram/iteratorstatement.hpp | 32 ------------- include/diagram/scope.h | 57 ++++++++++++++++++++++++ include/diagram/scope.hpp | 59 ------------------------ include/diagram/statement.h | 63 ++++++++++++++++++++++++++ include/diagram/statement.hpp | 67 ---------------------------- include/diagram/structogram.h | 29 ++++++++++++ include/diagram/structogram.hpp | 17 ------- include/ui/mainwindow.h | 13 +++++- include/ui/metadatadialog.h | 26 +++++++++++ include/ui/painter.h | 22 +++++++++ src/diagram/branchstatement.cpp | 6 ++- src/diagram/iteratorstatement.cpp | 8 ++-- src/diagram/scope.cpp | 57 ++++++++++++++++-------- src/diagram/statement.cpp | 20 +++++++-- src/diagram/structogram.cpp | 14 ++++++ src/ui/mainwindow.cpp | 60 +++++++++++++++++++++++-- src/ui/metadatadialog.cpp | 31 +++++++++++++ src/ui/painter.cpp | 14 ++++++ 26 files changed, 628 insertions(+), 262 deletions(-) create mode 100644 forms/metadatadialog.ui create mode 100644 forms/painter.ui create mode 100644 include/diagram/branchstatement.h delete mode 100644 include/diagram/branchstatement.hpp create mode 100644 include/diagram/iteratorstatement.h delete mode 100644 include/diagram/iteratorstatement.hpp create mode 100644 include/diagram/scope.h delete mode 100644 include/diagram/scope.hpp create mode 100644 include/diagram/statement.h delete mode 100644 include/diagram/statement.hpp create mode 100644 include/diagram/structogram.h delete mode 100644 include/diagram/structogram.hpp create mode 100644 include/ui/metadatadialog.h create mode 100644 include/ui/painter.h create mode 100644 src/diagram/structogram.cpp create mode 100644 src/ui/metadatadialog.cpp create mode 100644 src/ui/painter.cpp diff --git a/OrbitingYeti.pro b/OrbitingYeti.pro index 6067137..2353696 100644 --- a/OrbitingYeti.pro +++ b/OrbitingYeti.pro @@ -31,14 +31,21 @@ SOURCES += \ src/diagram/iteratorstatement.cpp \ src/diagram/scope.cpp \ src/diagram/statement.cpp \ + src/diagram/structogram.cpp \ + src/ui/metadatadialog.cpp \ + src/ui/painter.cpp HEADERS += \ include/ui/mainwindow.h \ - include/diagram/branchstatement.hpp \ - include/diagram/iteratorstatement.hpp \ - include/diagram/scope.hpp \ - include/diagram/statement.hpp \ - include/diagram/structogram.hpp + include/diagram/structogram.h \ + include/diagram/statement.h \ + include/diagram/scope.h \ + include/diagram/iteratorstatement.h \ + include/diagram/branchstatement.h \ + include/ui/metadatadialog.h \ + include/ui/painter.h FORMS += \ - forms/mainwindow.ui + forms/mainwindow.ui \ + forms/metadatadialog.ui \ + forms/painter.ui diff --git a/OrbitingYeti.pro.user b/OrbitingYeti.pro.user index bc37fea..87582df 100644 --- a/OrbitingYeti.pro.user +++ b/OrbitingYeti.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index a41e446..86d6381 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -10,8 +10,14 @@ 601 + + + 0 + 0 + + - MainWindow + OrbitingYeti Qt::ToolButtonIconOnly @@ -21,22 +27,22 @@ true - + 0 0 - 824 - 548 + 10000 + 10000 Qt::LeftToRight - - + + QLayout::SetMaximumSize @@ -49,7 +55,8 @@ New Diagram - + + .. @@ -59,7 +66,8 @@ Open - + + .. @@ -69,7 +77,8 @@ Save - + + .. @@ -95,7 +104,15 @@ Refresh View - + + .. + + + + + + + Metadata @@ -105,7 +122,8 @@ New Statement - + + .. @@ -149,6 +167,7 @@ + @@ -174,9 +193,17 @@ + + + View + + + + + @@ -271,6 +298,33 @@ Settings + + + Close + + + + + true + + + true + + + Toolbar + + + + + true + + + true + + + Statusbar + + diff --git a/forms/metadatadialog.ui b/forms/metadatadialog.ui new file mode 100644 index 0000000..070242e --- /dev/null +++ b/forms/metadatadialog.ui @@ -0,0 +1,84 @@ + + + MetadataDialog + + + + 0 + 0 + 300 + 190 + + + + Set metadata + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + Title + + + + + + + + + + Author + + + + + + + + + + + + buttonBox + accepted() + MetadataDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + MetadataDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/forms/painter.ui b/forms/painter.ui new file mode 100644 index 0000000..1978a7c --- /dev/null +++ b/forms/painter.ui @@ -0,0 +1,21 @@ + + + + + Painter + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + diff --git a/include/diagram/branchstatement.h b/include/diagram/branchstatement.h new file mode 100644 index 0000000..6c5e416 --- /dev/null +++ b/include/diagram/branchstatement.h @@ -0,0 +1,30 @@ +#ifndef DIAGRAM_BRANCHSTATEMENT_H +#define DIAGRAM_BRANCHSTATEMENT_H + +#include "diagram/statement.h" + +#include +#include + +namespace samb { + +class BranchStatement : public Statement +{ +public: + BranchStatement(Type t, const QString &condition, pointer next); + + /* accessors */ + const std::map& branches() const { 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/branchstatement.hpp b/include/diagram/branchstatement.hpp deleted file mode 100644 index b7cc495..0000000 --- a/include/diagram/branchstatement.hpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * BranchStatement.hpp - * - * Created on: Nov 28, 2017 - * Author: naopross - */ - -#ifndef SRC_DIAGRAM_BRANCHSTATEMENT_HPP_ -#define SRC_DIAGRAM_BRANCHSTATEMENT_HPP_ - -#include "Statement.hpp" - -#include - -namespace samb { - -class BranchStatement: public Statement { -public: - BranchStatement(Type t, const std::string& condition, pointer next); - - /* accessors */ - const std::map& branches() const { return m_branches; } - std::size_t branchesCount() const { return m_branchesCount; } - - inline const std::string& condition() const { return text(); } - inline void condition(const std::string& condition) { return text(condition); } - -private: - std::map m_branches; - std::size_t m_branchesCount = 0; -}; - -} /* namespace samb */ - -#endif /* SRC_DIAGRAM_BRANCHSTATEMENT_HPP_ */ diff --git a/include/diagram/iteratorstatement.h b/include/diagram/iteratorstatement.h new file mode 100644 index 0000000..a8f6d59 --- /dev/null +++ b/include/diagram/iteratorstatement.h @@ -0,0 +1,28 @@ +#ifndef DIAGRAM_ITERATORSTATEMENT_H +#define DIAGRAM_ITERATORSTATEMENT_H + +#include "diagram/statement.h" +#include "diagram/scope.h" + +#include + +namespace samb { + +class IteratorStatement : public Statement +{ +public: + IteratorStatement(Type t, const QString &condition, pointer next); + + /* accessors */ + const Scope& inner() const { 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.hpp b/include/diagram/iteratorstatement.hpp deleted file mode 100644 index a14d78d..0000000 --- a/include/diagram/iteratorstatement.hpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * IteratorStatement.hpp - * - * Created on: Nov 28, 2017 - * Author: naopross - */ - -#ifndef SRC_DIAGRAM_ITERATORSTATEMENT_HPP_ -#define SRC_DIAGRAM_ITERATORSTATEMENT_HPP_ - -#include "Statement.hpp" -#include "Scope.hpp" - -namespace samb { - -class IteratorStatement: public Statement { -public: - IteratorStatement(Type t, const std::string& condition, pointer next); - - /* accessors */ - const Scope& inner() const { return m_inner; } - - inline const std::string& condition() const { return text(); } - inline void condition(const std::string& condition) { return text(condition); } - -private: - Scope m_inner; -}; - -} /* namespace samb */ - -#endif /* SRC_DIAGRAM_ITERATORSTATEMENT_HPP_ */ diff --git a/include/diagram/scope.h b/include/diagram/scope.h new file mode 100644 index 0000000..63698dd --- /dev/null +++ b/include/diagram/scope.h @@ -0,0 +1,57 @@ +#ifndef DIAGRAM_SCOPE_H +#define DIAGRAM_SCOPE_H + +#include "diagram/statement.h" + +#include + +namespace samb { + +/* The Scope is a forward-iterable object that contains statements. + * A scope is also a valid type of statement. + * + * The Scope object is used inside other complex types of statements such as + * BranchStatement or a IteratorStatement, to hold the statements within their + * scope. + */ +class Scope : public Statement +{ +public: + class iterator { + public: + explicit iterator(pointer statement); + ~iterator(); + + iterator& operator++(); + iterator& operator++(int); + + Statement& operator*() const; + Statement::pointer operator->() const; + + private: + Statement::pointer _current; + }; + + explicit Scope(const QString &label); + Scope(const QString &label, Statement::pointer first); + virtual ~Scope(); + + iterator insert_after(iterator it, Statement::pointer statement); + iterator erase_after(iterator it); + + /* accessors */ + std::size_t size() const { return _size; } + + /* iterator */ + iterator begin() { return iterator(_head); } + iterator end() { return iterator(_tail); } + +private: + Statement::pointer _head; + Statement::pointer _tail; + std::size_t _size = 0; +}; + +} /* namespace samb */ + +#endif /* SRC_DIAGRAM_SCOPE_HPP_ */ diff --git a/include/diagram/scope.hpp b/include/diagram/scope.hpp deleted file mode 100644 index bf85759..0000000 --- a/include/diagram/scope.hpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Created on: Nov 28, 2017 - * Author: naopross - */ - -#ifndef SRC_DIAGRAM_SCOPE_HPP_ -#define SRC_DIAGRAM_SCOPE_HPP_ - -#include "Statement.hpp" - -namespace samb { - -/* The Scope is a forward-iterable object that contains statements. - * A scope is also a valid type of statement. - * - * The Scope object is used inside other complex types of statements such as - * BranchStatement or a IteratorStatement, to hold the statements within their - * scope. - */ -class Scope : public Statement { -public: - class iterator { - public: - explicit iterator(pointer statement); - ~iterator(); - - iterator& operator++(); - iterator& operator++(int); - - Statement& operator*() const; - Statement::pointer operator->() const; - - private: - Statement::pointer m_current; - }; - - explicit Scope(std::string label); - Scope(std::string label, Statement::pointer first); - ~Scope(); - - iterator insert_after(iterator it, Statement::pointer statement); - iterator erase_after(iterator it); - - /* accessors */ - std::size_t size() const { return m_size; } - - /* iterator */ - iterator begin() { return iterator(m_head); } - iterator end() { return iterator(m_tail); } - -private: - Statement::pointer m_head; - Statement::pointer m_tail; - std::size_t m_size = 0; -}; - -} /* namespace samb */ - -#endif /* SRC_DIAGRAM_SCOPE_HPP_ */ diff --git a/include/diagram/statement.h b/include/diagram/statement.h new file mode 100644 index 0000000..5cce908 --- /dev/null +++ b/include/diagram/statement.h @@ -0,0 +1,63 @@ +#ifndef DIAGRAM_STATEMENT_H +#define DIAGRAM_STATEMENT_H + +#include +#include + +#include + +namespace samb { + +/* Possible types of statement, according to the NS diagram paper + * + * PROCESS : a statement that does something + * SCOPE : simple scope to isolate variables + * DECISION : splits the program in 2 branches based on a condition + * SWITCH : splits the program in n branches depending on a value + * WHILE : check first loop + * UNTIL : check last loop + * PARALLEL : parallel operations + */ + +/* This struct is a statement (link) of the iterable object Scope + * (linked list), that is also a common interface for the various types of + * statements. + */ +class Statement +{ +public: + using pointer = std::shared_ptr; + + enum Type { + PROCESS, + SCOPE, + DECISION, + SWITCH, + WHILE, + UNTIL, + PARALLEL, + }; + + const Type type; + + Statement(Type t, const QString &text); + Statement(Type t, const QString &text, pointer next); + virtual ~Statement(); + + bool operator==(const Statement& other) const; + + /* accessors */ + void next(pointer next) { _next = next; } + pointer next() const { return _next; } + + void text(const QString &text) { _text = text; } + const QString& text() const { return _text; } + +private: + QString _text; + pointer _next; +}; + +} /* namespace samb */ + +#endif /* DIAGRAM_STATEMENT_H */ diff --git a/include/diagram/statement.hpp b/include/diagram/statement.hpp deleted file mode 100644 index ab8c5b7..0000000 --- a/include/diagram/statement.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Statement.h - * - * Created on: Nov 23, 2017 - * Author: naopross - */ - -#ifndef SRC_DIAGRAM_STATEMENT_H_ -#define SRC_DIAGRAM_STATEMENT_H_ - -#include -#include - -namespace samb { - -/* Possible types of statement, according to the NS diagram paper - * - * PROCESS : a statement that does something - * SCOPE : simple scope to isolate variables - * DECISION : splits the program in 2 branches based on a condition - * SWITCH : splits the program in n branches depending on a value - * WHILE : check first loop - * UNTIL : check last loop - * PARALLEL : parallel operations - */ - -/* This struct is a statement (link) of the iterable object Scope - * (linked list), that is also a common interface for the various types of - * statements. - */ -class Statement { -public: - using pointer = std::shared_ptr; - - enum Type { - PROCESS, - SCOPE, - DECISION, - SWITCH, - WHILE, - UNTIL, - PARALLEL, - }; - - const Type type; - - Statement(Type t, const std::string& text); - Statement(Type t, const std::string& text, pointer next); - virtual ~Statement(); - - bool operator==(const Statement& other) const; - - /* accessors */ - void next(pointer next) { m_next = next; } - pointer next() const { return m_next; } - - void text(const std::string& text) { m_text = text; } - const std::string& text() const { return m_text; } - -private: - std::string m_text; - pointer m_next; -}; - -} /* namespace samb */ - -#endif /* SRC_DIAGRAM_STATEMENT_H_ */ diff --git a/include/diagram/structogram.h b/include/diagram/structogram.h new file mode 100644 index 0000000..6b2e0db --- /dev/null +++ b/include/diagram/structogram.h @@ -0,0 +1,29 @@ +#ifndef DIAGRAM_STRUCTOGRAM_H +#define DIAGRAM_STRUCTOGRAM_H + +#include "diagram/scope.h" + +#include + +namespace samb { + +class Structogram : public Scope +{ +public: + Structogram(const QString &title, const QString &author); + ~Structogram(); + + /* accessors */ + void title(const QString &title) { text(title); } + const QString& title() const { return text(); } + + void author(const QString &author) { _author = author; } + const QString& author() const { return _author; } + +private: + QString _author; +}; + +} + +#endif /* DIAGRAM_STRUCTOGRAM_H */ diff --git a/include/diagram/structogram.hpp b/include/diagram/structogram.hpp deleted file mode 100644 index 84a4b84..0000000 --- a/include/diagram/structogram.hpp +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Structogram.hpp - * - * Created on: Nov 28, 2017 - * Author: naopross - */ - -#ifndef SRC_DIAGRAM_STRUCTOGRAM_HPP_ -#define SRC_DIAGRAM_STRUCTOGRAM_HPP_ - -#include "Scope.hpp" - -namespace samb { - typedef Scope Structogram; -} - -#endif /* SRC_DIAGRAM_STRUCTOGRAM_HPP_ */ diff --git a/include/ui/mainwindow.h b/include/ui/mainwindow.h index a3948a9..0beb4a2 100644 --- a/include/ui/mainwindow.h +++ b/include/ui/mainwindow.h @@ -3,6 +3,8 @@ #include +#include "diagram/structogram.h" + namespace Ui { class MainWindow; } @@ -12,11 +14,18 @@ class MainWindow : public QMainWindow Q_OBJECT public: - explicit MainWindow(QWidget *parent = 0); + explicit MainWindow(samb::Structogram *structogram = nullptr, QWidget *parent = nullptr); ~MainWindow(); +private slots: + void on_newButton_clicked(); + void on_metadataButton_clicked(); + private: - Ui::MainWindow *ui; + Ui::MainWindow *_ui; + samb::Structogram *_structogram; + + void initData(); }; #endif // MAINWINDOW_H diff --git a/include/ui/metadatadialog.h b/include/ui/metadatadialog.h new file mode 100644 index 0000000..0ed2f17 --- /dev/null +++ b/include/ui/metadatadialog.h @@ -0,0 +1,26 @@ +#ifndef NEWDIALOG_H +#define NEWDIALOG_H + +#include + +namespace Ui { +class MetadataDialog; +} + +class MetadataDialog : public QDialog +{ + Q_OBJECT + +public: + explicit MetadataDialog(QWidget *parent = 0); + ~MetadataDialog(); + + void setMetadata(const QString& title, const QString& author); + QString title() const; + QString author() const; + +private: + Ui::MetadataDialog *_ui; +}; + +#endif // NEWDIALOG_H diff --git a/include/ui/painter.h b/include/ui/painter.h new file mode 100644 index 0000000..df62776 --- /dev/null +++ b/include/ui/painter.h @@ -0,0 +1,22 @@ +#ifndef PAINTER_H +#define PAINTER_H + +#include + +namespace Ui { +class Painter; +} + +class Painter : public QWidget +{ + Q_OBJECT + +public: + explicit Painter(QWidget *parent = 0); + ~Painter(); + +private: + Ui::Painter *_ui; +}; + +#endif // PAINTER_H diff --git a/src/diagram/branchstatement.cpp b/src/diagram/branchstatement.cpp index 2835f35..6511c6c 100644 --- a/src/diagram/branchstatement.cpp +++ b/src/diagram/branchstatement.cpp @@ -1,8 +1,10 @@ -#include "diagram/BranchStatement.hpp" +#include "diagram/branchstatement.h" using namespace samb; -BranchStatement::BranchStatement(Type t, const std::string& condition, pointer next): Statement(t, condition, next) { +BranchStatement::BranchStatement(Type t, const QString &condition, pointer next) : + Statement(t, condition, next) +{ switch (t) { case Statement::Type::DECISION: case Statement::Type::SWITCH: diff --git a/src/diagram/iteratorstatement.cpp b/src/diagram/iteratorstatement.cpp index 675d8eb..a68234b 100644 --- a/src/diagram/iteratorstatement.cpp +++ b/src/diagram/iteratorstatement.cpp @@ -1,9 +1,11 @@ -#include "diagram/IteratorStatement.hpp" +#include "diagram/iteratorstatement.h" using namespace samb; -IteratorStatement::IteratorStatement(Statement::Type t, const std::string& condition, Statement::pointer next) - : Statement(t, condition, next), m_inner("") { +IteratorStatement::IteratorStatement(Statement::Type t, const QString &condition, Statement::pointer next) : + Statement(t, condition, next), + _inner("") +{ switch (t) { case Statement::Type::WHILE: diff --git a/src/diagram/scope.cpp b/src/diagram/scope.cpp index a1074a3..5f6b4df 100644 --- a/src/diagram/scope.cpp +++ b/src/diagram/scope.cpp @@ -1,29 +1,35 @@ -#include "diagram/Scope.hpp" +#include "diagram/scope.h" using namespace samb; /* Scope::iterator */ -Scope::iterator::iterator(Statement::pointer statement): m_current(statement) { +Scope::iterator::iterator(Statement::pointer statement) : + _current(statement) +{ } -Scope::iterator::~iterator() { +Scope::iterator::~iterator() +{ } -Scope::iterator& Scope::iterator::operator++() { - if (m_current->next() == nullptr) { +Scope::iterator& Scope::iterator::operator++() +{ + if (_current->next() == nullptr) + { // TODO: remove throw throw std::logic_error("Statement::iterator::operator++() m_current->next() is nullptr"); } - m_current = m_current->next(); + _current = _current->next(); return *this; } -Scope::iterator& Scope::iterator::operator++(int) { +Scope::iterator& Scope::iterator::operator++(int) +{ static Scope::iterator old(*this); old = *this; @@ -31,26 +37,35 @@ Scope::iterator& Scope::iterator::operator++(int) { return old; } -Statement& Scope::iterator::operator*() const { - if (m_current == nullptr) { +Statement& Scope::iterator::operator*() const +{ + if (_current == nullptr) + { throw std::logic_error("Statement::iterator::operator*() m_current is nullptr"); } - return *m_current; + return *_current; } -Statement::pointer Scope::iterator::operator->() const { - return m_current; +Statement::pointer Scope::iterator::operator->() const +{ + return _current; } /* Scope */ -Scope::Scope(std::string label): Statement(Statement::Type::SCOPE, label, nullptr), m_head(nullptr), m_tail(nullptr) { +Scope::Scope(const QString &label) : + Statement(Statement::Type::SCOPE, label, nullptr), + _head(nullptr), _tail(nullptr) +{ } -Scope::Scope(std::string label, Statement::pointer first): Statement(Statement::Type::SCOPE, label, first), m_head(first), m_tail(first) { +Scope::Scope(const QString &label, Statement::pointer first) : + Statement(Statement::Type::SCOPE, label, first), + _head(first), _tail(first) +{ } @@ -58,21 +73,25 @@ Scope::~Scope() { } -Scope::iterator Scope::insert_after(Scope::iterator it, Statement::pointer statement) { - if (statement == nullptr) { +Scope::iterator Scope::insert_after(Scope::iterator it, Statement::pointer statement) +{ + if (statement == nullptr) + { throw std::invalid_argument("Statement::insert_after() cannot insert nullptr"); } statement->next(it->next()); it->next(statement); - m_size++; + _size++; return it; } -Scope::iterator Scope::erase_after(Scope::iterator it) { - if (it->next() == nullptr) { +Scope::iterator Scope::erase_after(Scope::iterator it) +{ + if (it->next() == nullptr) + { return end(); } diff --git a/src/diagram/statement.cpp b/src/diagram/statement.cpp index 9cbcdb4..eae5cd3 100644 --- a/src/diagram/statement.cpp +++ b/src/diagram/statement.cpp @@ -1,13 +1,25 @@ -#include "diagram/Statement.hpp" +#include "diagram/statement.h" using namespace samb; /* Statement */ -Statement::Statement(Type t, const std::string& text): type(t), m_text(text), m_next(nullptr) {} -Statement::Statement(Type t, const std::string& text, Statement::pointer p): type(t), m_text(text), m_next(p) {} +Statement::Statement(Type t, const QString &text) : + type(t), _text(text), _next(nullptr) +{ -Statement::~Statement() {} +} + +Statement::Statement(Type t, const QString &text, Statement::pointer p) : + type(t), _text(text), _next(p) +{ + +} + +Statement::~Statement() +{ + +} bool Statement::operator==(const Statement& other) const { // comparison by pointers diff --git a/src/diagram/structogram.cpp b/src/diagram/structogram.cpp new file mode 100644 index 0000000..517d26e --- /dev/null +++ b/src/diagram/structogram.cpp @@ -0,0 +1,14 @@ +#include "diagram/structogram.h" + +using namespace samb; + +Structogram::Structogram(const QString &title, const QString &author) : + Scope(title), _author(author) +{ + +} + +Structogram::~Structogram() +{ + +} diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 7e4ca77..5a60391 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -1,14 +1,66 @@ #include "ui/mainwindow.h" #include "ui_mainwindow.h" -MainWindow::MainWindow(QWidget *parent) : +#include "ui/metadatadialog.h" + +#include + +MainWindow::MainWindow(samb::Structogram *structogram, QWidget *parent) : QMainWindow(parent), - ui(new Ui::MainWindow) + _ui(new Ui::MainWindow), + _structogram(structogram) { - ui->setupUi(this); + _ui->setupUi(this); + initData(); } MainWindow::~MainWindow() { - delete ui; + delete _ui; +} + +/**** private slots ****/ + +void MainWindow::on_newButton_clicked() +{ + if (_structogram != nullptr) + { + // TODO: implement save dialog + std::cout << "TODO: implement save dialog" << std::endl; + + delete _structogram; + _structogram = nullptr; + } + + MetadataDialog *dialog = new MetadataDialog(this); + if (dialog->exec() == QDialog::Accepted) + { + _structogram = new samb::Structogram(dialog->title(), dialog->author()); + } + + delete dialog; +} + +void MainWindow::on_metadataButton_clicked() +{ + if (_structogram == nullptr) { return; } + + MetadataDialog *dialog = new MetadataDialog(this); + dialog->setMetadata(_structogram->title(), _structogram->author()); + + if (dialog->exec() == QDialog::Accepted) + { + _structogram->title(dialog->title()); + _structogram->author(dialog->author()); + } +} + +/**** private methods ****/ + +void MainWindow::initData() +{ + if (_structogram == nullptr) + { + _structogram = new samb::Structogram("", ""); + } } diff --git a/src/ui/metadatadialog.cpp b/src/ui/metadatadialog.cpp new file mode 100644 index 0000000..348f225 --- /dev/null +++ b/src/ui/metadatadialog.cpp @@ -0,0 +1,31 @@ +#include "ui/metadatadialog.h" +#include "ui_metadatadialog.h" + +MetadataDialog::MetadataDialog(QWidget *parent) : + QDialog(parent), + _ui(new Ui::MetadataDialog) +{ + _ui->setupUi(this); +} + +MetadataDialog::~MetadataDialog() +{ + delete _ui; +} + +void MetadataDialog::setMetadata(const QString& title, const QString& author) +{ + _ui->titleEdit->setText(title); + _ui->authorEdit->setText(author); +} + + +QString MetadataDialog::title() const +{ + return _ui->titleEdit->text(); +} + +QString MetadataDialog::author() const +{ + return _ui->authorEdit->text(); +} diff --git a/src/ui/painter.cpp b/src/ui/painter.cpp new file mode 100644 index 0000000..b04e389 --- /dev/null +++ b/src/ui/painter.cpp @@ -0,0 +1,14 @@ +#include "ui/painter.h" +#include "ui_painter.h" + +Painter::Painter(QWidget *parent) : + QWidget(parent), + _ui(new Ui::Painter) +{ + _ui->setupUi(this); +} + +Painter::~Painter() +{ + delete _ui; +} -- cgit v1.2.1