2018-09-18 11:53:19 +02:00
|
|
|
|
#include "CodeGenerator.h"
|
|
|
|
|
|
#include "ui_CodeGenerator.h"
|
|
|
|
|
|
#include "codebuilder/CodeBuilder.h"
|
|
|
|
|
|
#include "codebuilder/DefaultConfigs.h"
|
|
|
|
|
|
#include "UserConfiguration.h"
|
|
|
|
|
|
#include <QTextStream>
|
|
|
|
|
|
|
2018-12-29 18:59:54 +01:00
|
|
|
|
CodeGenerator::CodeGenerator(IPluginContentWidgetContext *context, QWidget *parent) :
|
|
|
|
|
|
PluginContentWidget(context, parent),
|
2018-09-18 11:53:19 +02:00
|
|
|
|
ui(new Ui::CodeGenerator)
|
|
|
|
|
|
{
|
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
|
|
|
|
ui->generatedCodeEditor->setFont(UserConfiguration::instance()->codeFont());
|
|
|
|
|
|
ui->generatedCodeEditor->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CodeGenerator::~CodeGenerator()
|
|
|
|
|
|
{
|
|
|
|
|
|
delete ui;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-11-17 09:47:50 +01:00
|
|
|
|
void CodeGenerator::Init(std::shared_ptr<PgDatabaseCatalog> catalog, QString query,
|
|
|
|
|
|
std::shared_ptr<const Pgsql::Result> dbres)
|
2018-09-18 11:53:19 +02:00
|
|
|
|
{
|
2018-12-09 21:10:35 +01:00
|
|
|
|
m_catalog = std::move(catalog);
|
|
|
|
|
|
m_query = std::move(query);
|
|
|
|
|
|
m_dbres = std::move(dbres);
|
2018-09-18 11:53:19 +02:00
|
|
|
|
generateCode();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CodeGenerator::on_updateCodeButton_clicked()
|
|
|
|
|
|
{
|
|
|
|
|
|
generateCode();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CodeGenerator::generateCode()
|
|
|
|
|
|
{
|
|
|
|
|
|
QString struct_name = ui->structNameEdit->text();
|
|
|
|
|
|
|
|
|
|
|
|
QString buffer;
|
|
|
|
|
|
QTextStream stream(&buffer);
|
|
|
|
|
|
CodeBuilder builder;
|
2018-11-17 09:47:50 +01:00
|
|
|
|
builder.setLanguageConfig(getPglabCppLanguageConfig(m_catalog));
|
2018-09-18 11:53:19 +02:00
|
|
|
|
builder.GenCodeForExecutingQuery(stream, m_query, *m_dbres, struct_name);
|
|
|
|
|
|
stream.flush();
|
|
|
|
|
|
ui->generatedCodeEditor->setPlainText(buffer);
|
|
|
|
|
|
// QApplication::clipboard()->setText(buffer);
|
|
|
|
|
|
|
|
|
|
|
|
}
|