Added log display

This commit is contained in:
Borna Rajkovic 2022-04-09 21:11:17 +02:00
parent 883eaeb10a
commit 23e63f7b6f
4 changed files with 36 additions and 15 deletions

View File

@ -9,7 +9,7 @@ Schema::Schema()
} }
void Schema::setSchema(std::optional<domain::Schema>& schema) void Schema::setSchema(std::optional<domain::Schema> schema)
{ {
scene.clear(); scene.clear();
this->schema = schema; this->schema = schema;

View File

@ -14,7 +14,7 @@ class Schema: public QGraphicsView
public: public:
Schema(); Schema();
void setSchema(std::optional<domain::Schema>& schema); void setSchema(std::optional<domain::Schema> schema);
private: private:
QGraphicsScene scene; QGraphicsScene scene;

View File

@ -9,6 +9,8 @@
#include <comdel/domain/schemacreator.h> #include <comdel/domain/schemacreator.h>
#include <iostream> #include <iostream>
#include <QPlainTextEdit>
#include <sstream>
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
@ -40,44 +42,59 @@ void MainWindow::setupUi()
// setup central content // setup central content
libraryDisplay = new display::Library(); libraryDisplay = new display::Library();
auto schemaParent = new QWidget();
auto schemaLayout = new QVBoxLayout();
schemaParent->setLayout(schemaLayout);
schemaDisplay = new display::Schema(); schemaDisplay = new display::Schema();
schemaLayout->setMargin(0);
schemaLayout->addWidget(schemaDisplay, 1);
layout->setMargin(0); layout->setMargin(0);
layout->addWidget(libraryDisplay); layout->addWidget(libraryDisplay);
layout->addWidget(schemaDisplay, 1); layout->addWidget(schemaParent, 1);
log = new QPlainTextEdit();
log->setFont(QFont("Courier"));
schemaLayout->addWidget(log);
} }
void MainWindow::onTestModal() { void MainWindow::onTestModal() {
QString filename = "/home/bbr/Documents/personal/projects/modeler/schema.csl"; QString filename = "/home/bbr/Documents/personal/projects/modeler/schema.csl";
std::ostringstream buffer;
if(!filename.isEmpty()) { if(!filename.isEmpty()) {
clear(); clear();
ParseContext parseContext; ParseContext parseContext;
auto schemaNode = loadSchemaFromFile(&parseContext, filename.toStdString().c_str(), std::cout); auto schemaNode = loadSchemaFromFile(&parseContext, filename.toStdString().c_str(), buffer);
if(schemaNode) { if(schemaNode) {
domain::SchemaCreator generator(signatures); domain::SchemaCreator generator(signatures);
library = generator.loadLibrary(*schemaNode->library); library = generator.loadLibrary(*schemaNode->library);
for (auto& error : generator.getErrors()) {
parseContext.formatError(error, std::cout, "GENERATOR ERROR: ");
}
if(library) { if(library) {
schema = generator.loadSchema(*schemaNode, *library); schema = generator.loadSchema(*schemaNode, *library);
}
for (auto& error : generator.getErrors()) { for (auto& error : generator.getErrors()) {
parseContext.formatError(error, std::cout, "LIBRARY ERROR: "); parseContext.formatError(error, buffer, "ERROR: ");
}
if(generator.getErrors().empty()) {
libraryDisplay->setLibrary(library);
schemaDisplay->setSchema(schema);
} else {
libraryDisplay->setLibrary(std::nullopt);
schemaDisplay->setSchema(std::nullopt);
}
} }
} }
libraryDisplay->setLibrary(library); log->appendPlainText(QString::fromStdString(buffer.str()));
schemaDisplay->setSchema(schema);
}
}
} }
@ -131,6 +148,8 @@ void MainWindow::onLoadSchema() {
} }
} }
libraryDisplay->setLibrary(library); libraryDisplay->setLibrary(library);
schemaDisplay->setSchema(schema); schemaDisplay->setSchema(schema);
} }

View File

@ -9,6 +9,7 @@
#include <comdel/domain/library.h> #include <comdel/domain/library.h>
#include <comdel/domain/schema.h> #include <comdel/domain/schema.h>
#include <QPlainTextEdit>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; } namespace Ui { class MainWindow; }
@ -40,5 +41,6 @@ private slots:
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
QPlainTextEdit *log;
}; };
#endif // MAIN_WINDOW_H #endif // MAIN_WINDOW_H