-
-
Notifications
You must be signed in to change notification settings - Fork 421
Expand file tree
/
Copy pathcode_generator_widget.cpp
More file actions
76 lines (61 loc) · 2.04 KB
/
code_generator_widget.cpp
File metadata and controls
76 lines (61 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "code_generator_widget.h"
#include <iostream>
#include <fstream>
#include <map>
#include <string>
CodeGeneratorWidget::CodeGeneratorWidget(QWidget *parent, Qt::WindowFlags f) : QDialog(parent,f)
{
setupUi(this);
code_hl=new SyntaxHighlighter(code_txt);
code_hl->loadConfiguration(GlobalAttributes::XML_HIGHLIGHT_CONF_PATH);
connect(close_btn, SIGNAL(clicked(void)), this, SLOT(close(void)));
connect(clear_btn, SIGNAL(clicked(void)), this, SLOT(doClearCode(void)));
connect(generate_btn, SIGNAL(clicked(void)), this, SLOT(doGenerateCode(void)));
this->generator = 0;
}
void CodeGeneratorWidget::setGenerator(BaseCodeGenerator *generator)
{
this->generator = generator;
}
void CodeGeneratorWidget::show(DatabaseModel *model, OperationList *op_list)
{
doClearCode();
this->setEnabled(model!=nullptr && op_list!=nullptr);
this->op_list = op_list;
this->model = model;
QDialog::show();
}
void CodeGeneratorWidget::doClearCode(void)
{
code_txt->setPlainText(QString("Ready.."));
}
void CodeGeneratorWidget::doGenerateCode(void)
{
std::map< std::string, std::string > files_to_generate;
std::map< std::string, std::string >::iterator it;
try
{
if(!op_list->isOperationChainStarted())
op_list->startOperationChain();
this->generator->generateCode(*model, *this, files_to_generate);
for(it = files_to_generate.begin(); it != files_to_generate.end(); ++it)
{
std::ofstream out_file("/tmp/" + it->first);
out_file << it->second;
out_file.close();
}
op_list->finishOperationChain();
}
catch(Exception &e)
{
if(op_list->isOperationChainStarted())
op_list->finishOperationChain();
op_list->undoOperation();
op_list->removeLastOperation();
throw Exception(e.getErrorMessage(), e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
}
}
void CodeGeneratorWidget::log(std::string text)
{
code_txt->setPlainText(QString::fromStdString(text));
}