aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/diagram/branchstatement.cpp6
-rw-r--r--src/diagram/iteratorstatement.cpp8
-rw-r--r--src/diagram/scope.cpp57
-rw-r--r--src/diagram/statement.cpp20
-rw-r--r--src/diagram/structogram.cpp14
-rw-r--r--src/ui/mainwindow.cpp60
-rw-r--r--src/ui/metadatadialog.cpp31
-rw-r--r--src/ui/painter.cpp14
8 files changed, 178 insertions, 32 deletions
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;
+}