diff options
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/dialogs/newconstraintdialog.cpp')
| -rw-r--r-- | SQLiteStudio3/guiSQLiteStudio/dialogs/newconstraintdialog.cpp | 59 |
1 files changed, 41 insertions, 18 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/dialogs/newconstraintdialog.cpp b/SQLiteStudio3/guiSQLiteStudio/dialogs/newconstraintdialog.cpp index 36b400b..f34ff2e 100644 --- a/SQLiteStudio3/guiSQLiteStudio/dialogs/newconstraintdialog.cpp +++ b/SQLiteStudio3/guiSQLiteStudio/dialogs/newconstraintdialog.cpp @@ -50,6 +50,24 @@ SqliteStatement* NewConstraintDialog::getConstraint() return constrStatement; } +void NewConstraintDialog::disableMode(ConstraintDialog::Constraint constraintType) +{ + switch (constraintType) { + case ConstraintDialog::PK: + case ConstraintDialog::FK: + case ConstraintDialog::UNIQUE: + case ConstraintDialog::CHECK: + case ConstraintDialog::NOTNULL: + case ConstraintDialog::COLLATE: + case ConstraintDialog::DEFAULT: + case ConstraintDialog::GENERATED: + modeToButton[constraintType]->setEnabled(false); + break; + case ConstraintDialog::UNKNOWN: + break; + } +} + void NewConstraintDialog::changeEvent(QEvent *e) { QDialog::changeEvent(e); @@ -84,36 +102,32 @@ void NewConstraintDialog::init() void NewConstraintDialog::initTable() { - addButton(ICONS.CONSTRAINT_PRIMARY_KEY, tr("Primary Key", "new constraint dialog"), SLOT(createTablePk())); - if (createTable->dialect == Dialect::Sqlite3) - addButton(ICONS.CONSTRAINT_FOREIGN_KEY, tr("Foreign Key", "new constraint dialog"), SLOT(createTableFk())); - - addButton(ICONS.CONSTRAINT_UNIQUE, tr("Unique", "new constraint dialog"), SLOT(createTableUnique())); - addButton(ICONS.CONSTRAINT_CHECK, tr("Check", "new constraint dialog"), SLOT(createTableCheck())); + modeToButton[ConstraintDialog::Constraint::PK] = addButton(ICONS.CONSTRAINT_PRIMARY_KEY, tr("Primary Key", "new constraint dialog"), SLOT(createTablePk())); + modeToButton[ConstraintDialog::Constraint::FK] = addButton(ICONS.CONSTRAINT_FOREIGN_KEY, tr("Foreign Key", "new constraint dialog"), SLOT(createTableFk())); + modeToButton[ConstraintDialog::Constraint::UNIQUE] = addButton(ICONS.CONSTRAINT_UNIQUE, tr("Unique", "new constraint dialog"), SLOT(createTableUnique())); + modeToButton[ConstraintDialog::Constraint::CHECK] = addButton(ICONS.CONSTRAINT_CHECK, tr("Check", "new constraint dialog"), SLOT(createTableCheck())); } void NewConstraintDialog::initColumn() { - addButton(ICONS.CONSTRAINT_PRIMARY_KEY, tr("Primary Key", "new constraint dialog"), SLOT(createColumnPk())); - if (createTable->dialect == Dialect::Sqlite3) - addButton(ICONS.CONSTRAINT_FOREIGN_KEY, tr("Foreign Key", "new constraint dialog"), SLOT(createColumnFk())); - - addButton(ICONS.CONSTRAINT_UNIQUE, tr("Unique", "new constraint dialog"), SLOT(createColumnUnique())); - addButton(ICONS.CONSTRAINT_CHECK, tr("Check", "new constraint dialog"), SLOT(createColumnCheck())); - addButton(ICONS.CONSTRAINT_NOT_NULL, tr("Not NULL", "new constraint dialog"), SLOT(createColumnNotNull())); - if (createTable->dialect == Dialect::Sqlite3) - addButton(ICONS.CONSTRAINT_COLLATION, tr("Collate", "new constraint dialog"), SLOT(createColumnCollate())); - - addButton(ICONS.CONSTRAINT_DEFAULT, tr("Default", "new constraint dialog"), SLOT(createColumnDefault())); + modeToButton[ConstraintDialog::Constraint::PK] = addButton(ICONS.CONSTRAINT_PRIMARY_KEY, tr("Primary Key", "new constraint dialog"), SLOT(createColumnPk())); + modeToButton[ConstraintDialog::Constraint::FK] = addButton(ICONS.CONSTRAINT_FOREIGN_KEY, tr("Foreign Key", "new constraint dialog"), SLOT(createColumnFk())); + modeToButton[ConstraintDialog::Constraint::UNIQUE] = addButton(ICONS.CONSTRAINT_UNIQUE, tr("Unique", "new constraint dialog"), SLOT(createColumnUnique())); + modeToButton[ConstraintDialog::Constraint::CHECK] = addButton(ICONS.CONSTRAINT_CHECK, tr("Check", "new constraint dialog"), SLOT(createColumnCheck())); + modeToButton[ConstraintDialog::Constraint::NOTNULL] = addButton(ICONS.CONSTRAINT_NOT_NULL, tr("Not NULL", "new constraint dialog"), SLOT(createColumnNotNull())); + modeToButton[ConstraintDialog::Constraint::COLLATE] = addButton(ICONS.CONSTRAINT_COLLATION, tr("Collate", "new constraint dialog"), SLOT(createColumnCollate())); + modeToButton[ConstraintDialog::Constraint::GENERATED] = addButton(ICONS.CONSTRAINT_GENERATED, tr("Generated", "new constraint dialog"), SLOT(createColumnGenerated())); + modeToButton[ConstraintDialog::Constraint::DEFAULT] = addButton(ICONS.CONSTRAINT_DEFAULT, tr("Default", "new constraint dialog"), SLOT(createColumnDefault())); } -void NewConstraintDialog::addButton(const Icon& icon, const QString text, const char* slot) +QCommandLinkButton* NewConstraintDialog::addButton(const Icon& icon, const QString text, const char* slot) { QCommandLinkButton* btn = new QCommandLinkButton(); btn->setIcon(icon); btn->setText(text); connect(btn, SIGNAL(clicked()), this, slot); ui->container->layout()->addWidget(btn); + return btn; } int NewConstraintDialog::createColumnConstraint(ConstraintDialog::Constraint constraintType) @@ -142,6 +156,9 @@ int NewConstraintDialog::createColumnConstraint(ConstraintDialog::Constraint con case ConstraintDialog::DEFAULT: constraint->type = SqliteCreateTable::Column::Constraint::DEFAULT; break; + case ConstraintDialog::GENERATED: + constraint->type = SqliteCreateTable::Column::Constraint::GENERATED; + break; case ConstraintDialog::UNKNOWN: break; } @@ -172,6 +189,7 @@ int NewConstraintDialog::createTableConstraint(ConstraintDialog::Constraint cons case ConstraintDialog::NOTNULL: case ConstraintDialog::COLLATE: case ConstraintDialog::DEFAULT: + case ConstraintDialog::GENERATED: case ConstraintDialog::UNKNOWN: break; } @@ -258,6 +276,11 @@ void NewConstraintDialog::createColumnCollate() createColumnConstraint(ConstraintDialog::COLLATE); } +void NewConstraintDialog::createColumnGenerated() +{ + createColumnConstraint(ConstraintDialog::GENERATED); +} + int NewConstraintDialog::exec() { if (predefinedConstraintType == ConstraintDialog::UNKNOWN) |
