From 7f7e6fe30ef4f9ba4507b89174676f57c42c0000 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Sun, 26 Nov 2017 23:36:26 +0100 Subject: Implementation for Structogram iterator and Statement type The interator is not (yet) aware of the scope in which it is iterating. --- src/ui/AsciiRenderer.cpp | 23 +++++++++++++---------- src/ui/AsciiRenderer.h | 33 --------------------------------- src/ui/AsciiRenderer.hpp | 37 +++++++++++++++++++++++++++++++++++++ src/ui/Window.cpp | 21 +++++++++++++++++++++ src/ui/Window.hpp | 27 +++++++++++++++++++++++++++ 5 files changed, 98 insertions(+), 43 deletions(-) delete mode 100644 src/ui/AsciiRenderer.h create mode 100644 src/ui/AsciiRenderer.hpp create mode 100644 src/ui/Window.cpp create mode 100644 src/ui/Window.hpp (limited to 'src/ui') diff --git a/src/ui/AsciiRenderer.cpp b/src/ui/AsciiRenderer.cpp index 0f17d85..d06dadb 100644 --- a/src/ui/AsciiRenderer.cpp +++ b/src/ui/AsciiRenderer.cpp @@ -5,7 +5,7 @@ * Author: naopross */ -#include "AsciiRenderer.h" +#include "AsciiRenderer.hpp" #include @@ -38,10 +38,9 @@ void AsciiRenderer::drawText(std::string text, unsigned int width, std::string b unsigned int textWidth = width - before.length() - after.length(); - std::cout << before; - for (unsigned int i = 0; i < text.length(); i++) { - if (i % textWidth == 0) { + for (std::size_t i = 0; i < text.length(); i++) { + if (i % textWidth == 0 && i != 0) { std::cout << after << "\n" << before; } @@ -62,24 +61,24 @@ void AsciiRenderer::drawDecision(std::string condition, std::string trueText, st } void AsciiRenderer::render() { - const std::list& statements = m_structogram.getStatements(); - for (std::list::const_iterator it = statements.begin(); it != statements.end(); it++) { - Statement st = *it; - switch (st.type) { + for (Structogram::iterator it = m_structogram.begin(); it != m_structogram.end(); ++it) { + + switch (it->type) { case Statement::Type::PROCESS: drawLine(); - drawText(st.text); + drawText(it->text); + drawLine(); break; case Statement::Type::DECISION: - drawLine(); break; case Statement::Type::SWITCH: break; case Statement::Type::SCOPE: + std::cout << "Title: " << it->text << std::endl; break; case Statement::Type::WHILE: @@ -90,6 +89,10 @@ void AsciiRenderer::render() { case Statement::Type::PARALLEL: break; + + case Statement::END: + // do nothing + break; } } } diff --git a/src/ui/AsciiRenderer.h b/src/ui/AsciiRenderer.h deleted file mode 100644 index 4f9020a..0000000 --- a/src/ui/AsciiRenderer.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Renderer.h - * - * Created on: Nov 23, 2017 - * Author: naopross - */ - -#ifndef SRC_UI_ASCIIRENDERER_H_ -#define SRC_UI_ASCIIRENDERER_H_ - -#include "../diagram/Structogram.h" - -namespace samb { - -class AsciiRenderer { -private: - Structogram m_structogram; - const unsigned int m_width; - - void drawPadding(unsigned int amt); - void drawLine() const; - void drawText(std::string text, unsigned int width = 0, std::string before = "|", std::string after = "|") const; - void drawDecision(std::string condition, std::string trueText, std::string falseText, unsigned int width = 0) const; -public: - AsciiRenderer(Structogram& structogram, unsigned int width); - ~AsciiRenderer(); - - void render(); -}; - -} /* namespace samb */ - -#endif /* SRC_UI_ASCIIRENDERER_H_ */ diff --git a/src/ui/AsciiRenderer.hpp b/src/ui/AsciiRenderer.hpp new file mode 100644 index 0000000..76d6ff5 --- /dev/null +++ b/src/ui/AsciiRenderer.hpp @@ -0,0 +1,37 @@ +/* + * Renderer.h + * + * Created on: Nov 23, 2017 + * Author: naopross + */ + +#ifndef SRC_UI_ASCIIRENDERER_HPP_ +#define SRC_UI_ASCIIRENDERER_HPP_ + +#include "../diagram/Structogram.hpp" + +namespace samb { + +/* Sample renderer for debug, + * + * TODO: implement PdfRenderer, UiRenderer with a common interface + */ +class AsciiRenderer { +private: + Structogram m_structogram; + const unsigned int m_width; + + void drawPadding(unsigned int amt); + void drawLine() const; + void drawText(std::string text, unsigned int width = 0, std::string before = "|", std::string after = "|") const; + void drawDecision(std::string condition, std::string trueText, std::string falseText, unsigned int width = 0) const; +public: + AsciiRenderer(Structogram& structogram, unsigned int width); + ~AsciiRenderer(); + + void render(); +}; + +} /* namespace samb */ + +#endif /* SRC_UI_ASCIIRENDERER_HPP_ */ diff --git a/src/ui/Window.cpp b/src/ui/Window.cpp new file mode 100644 index 0000000..4572766 --- /dev/null +++ b/src/ui/Window.cpp @@ -0,0 +1,21 @@ +/* + * Window.cpp + * + * Created on: Nov 26, 2017 + * Author: naopross + */ + +#include "Window.hpp" + +namespace samb { + +Window::Window() { + // TODO Auto-generated constructor stub + +} + +Window::~Window() { + // TODO Auto-generated destructor stub +} + +} /* namespace samb */ diff --git a/src/ui/Window.hpp b/src/ui/Window.hpp new file mode 100644 index 0000000..5afad8c --- /dev/null +++ b/src/ui/Window.hpp @@ -0,0 +1,27 @@ +/* + * Window.hpp + * + * Created on: Nov 26, 2017 + * Author: naopross + */ + +#ifndef SRC_UI_WINDOW_HPP_ +#define SRC_UI_WINDOW_HPP_ + +#include + +namespace samb { + +class Window : public QWidget { +Q_OBJECT +public: + Window(); + virtual ~Window(); + +signals: +public slots: +}; + +} /* namespace samb */ + +#endif /* SRC_UI_WINDOW_HPP_ */ -- cgit v1.2.1