diff options
author | Nao Pross <naopross@thearcway.org> | 2017-12-19 01:54:28 +0100 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2017-12-19 01:54:28 +0100 |
commit | a7e74749a1c4edb2f8bc34c79e9bd1562de86ee9 (patch) | |
tree | 4282a5dfa9ef7d77823e3e8ef02a193c91e719d6 | |
parent | Moved to QtCreator project with QMake (diff) | |
download | OrbitingYeti-a7e74749a1c4edb2f8bc34c79e9bd1562de86ee9.tar.gz OrbitingYeti-a7e74749a1c4edb2f8bc34c79e9bd1562de86ee9.zip |
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
Diffstat (limited to '')
24 files changed, 539 insertions, 173 deletions
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 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE QtCreatorProject> -<!-- Written by QtCreator 4.4.1, 2017-12-18T22:58:46. --> +<!-- Written by QtCreator 4.4.1, 2017-12-19T00:24:50. --> <qtcreator> <data> <variable>EnvironmentId</variable> 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 @@ <height>601</height> </rect> </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="windowTitle"> - <string>MainWindow</string> + <string>OrbitingYeti</string> </property> <property name="toolButtonStyle"> <enum>Qt::ToolButtonIconOnly</enum> @@ -21,22 +27,22 @@ <bool>true</bool> </property> <property name="sizePolicy"> - <sizepolicy hsizetype="Maximum" vsizetype="Maximum"> + <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="maximumSize"> <size> - <width>824</width> - <height>548</height> + <width>10000</width> + <height>10000</height> </size> </property> <property name="layoutDirection"> <enum>Qt::LeftToRight</enum> </property> - <layout class="QVBoxLayout" name="verticalLayout_2"> - <item> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> <layout class="QVBoxLayout" name="verticalLayout"> <property name="sizeConstraint"> <enum>QLayout::SetMaximumSize</enum> @@ -49,7 +55,8 @@ <string>New Diagram</string> </property> <property name="icon"> - <iconset theme="document-new"/> + <iconset theme="document-new"> + <normaloff>.</normaloff>.</iconset> </property> </widget> </item> @@ -59,7 +66,8 @@ <string>Open</string> </property> <property name="icon"> - <iconset theme="document-open"/> + <iconset theme="document-open"> + <normaloff>.</normaloff>.</iconset> </property> </widget> </item> @@ -69,7 +77,8 @@ <string>Save</string> </property> <property name="icon"> - <iconset theme="document-save"/> + <iconset theme="document-save"> + <normaloff>.</normaloff>.</iconset> </property> </widget> </item> @@ -95,7 +104,15 @@ <string>Refresh View</string> </property> <property name="icon"> - <iconset theme="view-refresh"/> + <iconset theme="view-refresh"> + <normaloff>.</normaloff>.</iconset> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="metadataButton"> + <property name="text"> + <string>Metadata</string> </property> </widget> </item> @@ -105,7 +122,8 @@ <string>New Statement</string> </property> <property name="icon"> - <iconset theme="insert-object"/> + <iconset theme="insert-object"> + <normaloff>.</normaloff>.</iconset> </property> </widget> </item> @@ -149,6 +167,7 @@ <addaction name="actionSave"/> <addaction name="actionSave_As"/> <addaction name="actionOpen"/> + <addaction name="actionClose"/> <addaction name="menuExport"/> <addaction name="separator"/> <addaction name="actionSettings"/> @@ -174,9 +193,17 @@ </property> <addaction name="actionFont"/> </widget> + <widget class="QMenu" name="menuView"> + <property name="title"> + <string>View</string> + </property> + <addaction name="actionToolbar"/> + <addaction name="actionStatusbar"/> + </widget> <addaction name="menuFIle"/> <addaction name="menuEdit"/> <addaction name="menuStyle"/> + <addaction name="menuView"/> <addaction name="menuAbout"/> </widget> <widget class="QStatusBar" name="statusbar"/> @@ -271,6 +298,33 @@ <string>Settings</string> </property> </action> + <action name="actionClose"> + <property name="text"> + <string>Close</string> + </property> + </action> + <action name="actionToolbar"> + <property name="checkable"> + <bool>true</bool> + </property> + <property name="checked"> + <bool>true</bool> + </property> + <property name="text"> + <string>Toolbar</string> + </property> + </action> + <action name="actionStatusbar"> + <property name="checkable"> + <bool>true</bool> + </property> + <property name="checked"> + <bool>true</bool> + </property> + <property name="text"> + <string>Statusbar</string> + </property> + </action> </widget> <resources/> <connections/> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MetadataDialog</class> + <widget class="QDialog" name="MetadataDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>300</width> + <height>190</height> + </rect> + </property> + <property name="windowTitle"> + <string>Set metadata</string> + </property> + <layout class="QFormLayout" name="formLayout"> + <item row="5" column="1"> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLabel" name="titleLabel"> + <property name="text"> + <string>Title</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QLineEdit" name="titleEdit"/> + </item> + <item row="3" column="1"> + <widget class="QLabel" name="authorLabel"> + <property name="text"> + <string>Author</string> + </property> + </widget> + </item> + <item row="4" column="1"> + <widget class="QLineEdit" name="authorEdit"/> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>MetadataDialog</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>MetadataDialog</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + </connections> +</ui> 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 @@ +<ui version="4.0"> + <author/> + <comment/> + <exportmacro/> + <class>Painter</class> + <widget name="Painter" class="QWidget"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + </widget> + <pixmapfunction/> + <connections/> +</ui> 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 <map> +#include <QString> + +namespace samb { + +class BranchStatement : public Statement +{ +public: + BranchStatement(Type t, const QString &condition, pointer next); + + /* accessors */ + const std::map<QString, pointer>& 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<QString, pointer> _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 <map> - -namespace samb { - -class BranchStatement: public Statement { -public: - BranchStatement(Type t, const std::string& condition, pointer next); - - /* accessors */ - const std::map<std::string, pointer>& 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<std::string, pointer> 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 <QString> + +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.hpp b/include/diagram/scope.h index bf85759..63698dd 100644 --- a/include/diagram/scope.hpp +++ b/include/diagram/scope.h @@ -1,12 +1,9 @@ -/* - * Created on: Nov 28, 2017 - * Author: naopross - */ +#ifndef DIAGRAM_SCOPE_H +#define DIAGRAM_SCOPE_H -#ifndef SRC_DIAGRAM_SCOPE_HPP_ -#define SRC_DIAGRAM_SCOPE_HPP_ +#include "diagram/statement.h" -#include "Statement.hpp" +#include <QString> namespace samb { @@ -17,7 +14,8 @@ namespace samb { * BranchStatement or a IteratorStatement, to hold the statements within their * scope. */ -class Scope : public Statement { +class Scope : public Statement +{ public: class iterator { public: @@ -31,27 +29,27 @@ public: Statement::pointer operator->() const; private: - Statement::pointer m_current; + Statement::pointer _current; }; - explicit Scope(std::string label); - Scope(std::string label, Statement::pointer first); - ~Scope(); + 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 m_size; } + std::size_t size() const { return _size; } /* iterator */ - iterator begin() { return iterator(m_head); } - iterator end() { return iterator(m_tail); } + iterator begin() { return iterator(_head); } + iterator end() { return iterator(_tail); } private: - Statement::pointer m_head; - Statement::pointer m_tail; - std::size_t m_size = 0; + Statement::pointer _head; + Statement::pointer _tail; + std::size_t _size = 0; }; } /* namespace samb */ diff --git a/include/diagram/statement.hpp b/include/diagram/statement.h index ab8c5b7..5cce908 100644 --- a/include/diagram/statement.hpp +++ b/include/diagram/statement.h @@ -1,16 +1,11 @@ -/* - * Statement.h - * - * Created on: Nov 23, 2017 - * Author: naopross - */ - -#ifndef SRC_DIAGRAM_STATEMENT_H_ -#define SRC_DIAGRAM_STATEMENT_H_ +#ifndef DIAGRAM_STATEMENT_H +#define DIAGRAM_STATEMENT_H #include <string> #include <memory> +#include <QString> + namespace samb { /* Possible types of statement, according to the NS diagram paper @@ -28,7 +23,8 @@ namespace samb { * (linked list), that is also a common interface for the various types of * statements. */ -class Statement { +class Statement +{ public: using pointer = std::shared_ptr<Statement>; @@ -44,24 +40,24 @@ public: const Type type; - Statement(Type t, const std::string& text); - Statement(Type t, const std::string& text, pointer next); + 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) { m_next = next; } - pointer next() const { return m_next; } + void next(pointer next) { _next = next; } + pointer next() const { return _next; } - void text(const std::string& text) { m_text = text; } - const std::string& text() const { return m_text; } + void text(const QString &text) { _text = text; } + const QString& text() const { return _text; } private: - std::string m_text; - pointer m_next; + QString _text; + pointer _next; }; } /* namespace samb */ -#endif /* SRC_DIAGRAM_STATEMENT_H_ */ +#endif /* 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 <QString> + +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 <QMainWindow> +#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 <QDialog> + +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 <QWidget> + +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 <iostream> + +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; +} |