pgLab/pglab/CodeGenerator.cpp
eelke f4f2474a81 Moved definition of widget instance actions to the module so other parts of the system can no about them.
The plugin system will create the Action objects and bind them to the specified slots of the
specific widget instances.
2019-01-05 19:58:23 +01:00

50 lines
1.3 KiB
C++

#include "CodeGenerator.h"
#include "ui_CodeGenerator.h"
#include "codebuilder/CodeBuilder.h"
#include "codebuilder/DefaultConfigs.h"
#include "UserConfiguration.h"
#include <QTextStream>
CodeGenerator::CodeGenerator(IPluginContentWidgetContext *context, QWidget *parent) :
PluginContentWidget(context, parent),
ui(new Ui::CodeGenerator)
{
ui->setupUi(this);
ui->generatedCodeEditor->setFont(UserConfiguration::instance()->codeFont());
ui->generatedCodeEditor->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
}
CodeGenerator::~CodeGenerator()
{
delete ui;
}
void CodeGenerator::Init(std::shared_ptr<PgDatabaseCatalog> catalog, QString query,
std::shared_ptr<const Pgsql::Result> dbres)
{
m_catalog = std::move(catalog);
m_query = std::move(query);
m_dbres = std::move(dbres);
generateCode();
}
void CodeGenerator::on_updateCodeButton_clicked()
{
generateCode();
}
void CodeGenerator::generateCode()
{
QString struct_name = ui->structNameEdit->text();
QString buffer;
QTextStream stream(&buffer);
CodeBuilder builder;
builder.setLanguageConfig(getPglabCppLanguageConfig(m_catalog));
builder.GenCodeForExecutingQuery(stream, m_query, *m_dbres, struct_name);
stream.flush();
ui->generatedCodeEditor->setPlainText(buffer);
// QApplication::clipboard()->setText(buffer);
}