File: tableprimarykeypanel.cpp

package info (click to toggle)
sqlitestudio 3.4.21%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 54,880 kB
  • sloc: ansic: 406,208; cpp: 123,872; yacc: 2,692; tcl: 497; sh: 462; xml: 426; makefile: 19
file content (84 lines) | stat: -rw-r--r-- 2,421 bytes parent folder | download
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
77
78
79
80
81
82
83
84
#include "tableprimarykeypanel.h"
#include "ui_tablepkanduniquepanel.h"
#include "uiutils.h"
#include <QDebug>

TablePrimaryKeyPanel::TablePrimaryKeyPanel(QWidget *parent) :
    TablePrimaryKeyAndUniquePanel(parent)
{
}

void TablePrimaryKeyPanel::storeConfiguration()
{
    TablePrimaryKeyAndUniquePanel::storeConfiguration();

    if (constraint.isNull())
        return;

    // Type
    SqliteCreateTable::Constraint* constr = dynamic_cast<SqliteCreateTable::Constraint*>(constraint.data());
    constr->type = SqliteCreateTable::Constraint::PRIMARY_KEY;

    // Autoincr
    constr->autoincrKw = ui->autoIncrCheckBox->isChecked();
}


void TablePrimaryKeyPanel::readConstraint()
{
    TablePrimaryKeyAndUniquePanel::readConstraint();

    if (constraint.isNull())
        return;

    SqliteCreateTable::Constraint* constr = dynamic_cast<SqliteCreateTable::Constraint*>(constraint.data());

    // Autoincr
    if (constr->autoincrKw)
        ui->autoIncrCheckBox->setChecked(true);
}

void TablePrimaryKeyPanel::updateState()
{
    TablePrimaryKeyAndUniquePanel::updateState();

    // Autoincr
    QStringList columns;
    QWidget* item = nullptr;
    QCheckBox* cb = nullptr;
    for (int i = 0; i < totalColumns; i++)
    {
        item = columnsLayout->itemAtPosition(i, 0)->widget();
        cb = qobject_cast<QCheckBox*>(item);
        if (cb->isChecked())
            columns << cb->property(UI_PROP_COLUMN).toString();
    }

    if (columns.size() != 1)
    {
        ui->autoIncrCheckBox->setChecked(false);
        ui->autoIncrCheckBox->setEnabled(false);
        return;
    }

    SqliteCreateTable* createTable = dynamic_cast<SqliteCreateTable*>(constraint->parentStatement());
    QString colName = columns.first();
    SqliteCreateTable::Column* column = createTable->getColumn(colName);
    if (!column)
    {
        qCritical() << "Could not find column when checking for AUTOINCREMENT checkbox state:" << colName
                    << "\nCreateTable statement:" << createTable->detokenize();
        ui->autoIncrCheckBox->setChecked(false);
        ui->autoIncrCheckBox->setEnabled(false);
        return;
    }

    if (!column->type || column->type->detokenize().trimmed().compare("INTEGER", Qt::CaseInsensitive) != 0)
    {
        ui->autoIncrCheckBox->setChecked(false);
        ui->autoIncrCheckBox->setEnabled(false);
        return;
    }

    ui->autoIncrCheckBox->setEnabled(true);
}