diff --git a/comdel/display/schema_display.cpp b/comdel/display/schema_display.cpp index 80666d3..f415130 100644 --- a/comdel/display/schema_display.cpp +++ b/comdel/display/schema_display.cpp @@ -9,7 +9,7 @@ Schema::Schema() } -void Schema::setSchema(std::optional& schema) +void Schema::setSchema(std::optional schema) { scene.clear(); this->schema = schema; diff --git a/comdel/display/schema_display.h b/comdel/display/schema_display.h index 81d680e..6acd574 100644 --- a/comdel/display/schema_display.h +++ b/comdel/display/schema_display.h @@ -14,7 +14,7 @@ class Schema: public QGraphicsView public: Schema(); - void setSchema(std::optional& schema); + void setSchema(std::optional schema); private: QGraphicsScene scene; diff --git a/mainwindow.cpp b/mainwindow.cpp index b3759e1..83fb034 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -9,6 +9,8 @@ #include #include +#include +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) @@ -40,45 +42,60 @@ void MainWindow::setupUi() // setup central content libraryDisplay = new display::Library(); + + auto schemaParent = new QWidget(); + auto schemaLayout = new QVBoxLayout(); + schemaParent->setLayout(schemaLayout); + schemaDisplay = new display::Schema(); + schemaLayout->setMargin(0); + schemaLayout->addWidget(schemaDisplay, 1); layout->setMargin(0); layout->addWidget(libraryDisplay); - layout->addWidget(schemaDisplay, 1); - + layout->addWidget(schemaParent, 1); + log = new QPlainTextEdit(); + log->setFont(QFont("Courier")); + schemaLayout->addWidget(log); } void MainWindow::onTestModal() { QString filename = "/home/bbr/Documents/personal/projects/modeler/schema.csl"; + std::ostringstream buffer; + if(!filename.isEmpty()) { clear(); ParseContext parseContext; - auto schemaNode = loadSchemaFromFile(&parseContext, filename.toStdString().c_str(), std::cout); + auto schemaNode = loadSchemaFromFile(&parseContext, filename.toStdString().c_str(), buffer); if(schemaNode) { domain::SchemaCreator generator(signatures); library = generator.loadLibrary(*schemaNode->library); - for (auto& error : generator.getErrors()) { - parseContext.formatError(error, std::cout, "GENERATOR ERROR: "); - } - if(library) { schema = generator.loadSchema(*schemaNode, *library); - - for (auto& error : generator.getErrors()) { - parseContext.formatError(error, std::cout, "LIBRARY ERROR: "); - } } - libraryDisplay->setLibrary(library); - schemaDisplay->setSchema(schema); + for (auto& error : generator.getErrors()) { + parseContext.formatError(error, buffer, "ERROR: "); + } + + if(generator.getErrors().empty()) { + libraryDisplay->setLibrary(library); + schemaDisplay->setSchema(schema); + } else { + libraryDisplay->setLibrary(std::nullopt); + schemaDisplay->setSchema(std::nullopt); + } + } } + log->appendPlainText(QString::fromStdString(buffer.str())); + } void MainWindow::onLoadLibrary() { @@ -131,6 +148,8 @@ void MainWindow::onLoadSchema() { } } + + libraryDisplay->setLibrary(library); schemaDisplay->setSchema(schema); } diff --git a/mainwindow.h b/mainwindow.h index 200d0dc..c2ad269 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -9,6 +9,7 @@ #include #include +#include QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } @@ -40,5 +41,6 @@ private slots: private: Ui::MainWindow *ui; + QPlainTextEdit *log; }; #endif // MAIN_WINDOW_H