summaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/dialogs/ddlpreviewdialog.cpp
blob: f3863c8f473651e4ae041b7b700b9e10a11120be (plain) (blame)
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
#include "ddlpreviewdialog.h"
#include "ui_ddlpreviewdialog.h"
#include "services/codeformatter.h"
#include "uiconfig.h"
#include "sqlitestudio.h"
#include "db/db.h"
#include "common/dialogsizehandler.h"

DdlPreviewDialog::DdlPreviewDialog(Db* db, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DdlPreviewDialog),
    db(db)
{
    ui->setupUi(this);
    DialogSizeHandler::applyFor(this);
}

DdlPreviewDialog::~DdlPreviewDialog()
{
    delete ui;
}

void DdlPreviewDialog::setDdl(const QString& ddl)
{
    QString formatted = SQLITESTUDIO->getCodeFormatter()->format("sql", ddl, db);
    ui->ddlEdit->setPlainText(formatted);
}

void DdlPreviewDialog::setDdl(const QStringList& ddlList)
{
    QStringList fixedList;
    QString newDdl;
    for (const QString& ddl : ddlList)
    {
        newDdl = ddl.trimmed();
        if (!newDdl.endsWith(";"))
            newDdl.append(";");

        fixedList << SQLITESTUDIO->getCodeFormatter()->format("sql", newDdl, db);
    }
    setDdl(fixedList.join("\n"));
}

void DdlPreviewDialog::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
        case QEvent::LanguageChange:
            ui->retranslateUi(this);
            break;
        default:
            break;
    }
}

void DdlPreviewDialog::accept()
{
    CFG_UI.General.DontShowDdlPreview.set(ui->dontShowAgainCheck->isChecked());
    QDialog::accept();
}