diff options
| author | 2021-12-17 07:06:30 -0500 | |
|---|---|---|
| committer | 2021-12-17 07:06:30 -0500 | |
| commit | 1fdc150116cad39aae5c5da407c3312b47a59e3a (patch) | |
| tree | 123c79a4d7ad2d45781ba03ce939f7539fb428d8 /SQLiteStudio3/guiSQLiteStudio/dialogs/columndialog.cpp | |
| parent | feda8a7db8d1d7c5439aa8f8feef7cc0dd2b59a0 (diff) | |
New upstream version 3.3.3+dfsg1.upstream/3.3.3+dfsg1
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/dialogs/columndialog.cpp')
| -rw-r--r-- | SQLiteStudio3/guiSQLiteStudio/dialogs/columndialog.cpp | 101 |
1 files changed, 72 insertions, 29 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/dialogs/columndialog.cpp b/SQLiteStudio3/guiSQLiteStudio/dialogs/columndialog.cpp index 8bf1698..ebf9253 100644 --- a/SQLiteStudio3/guiSQLiteStudio/dialogs/columndialog.cpp +++ b/SQLiteStudio3/guiSQLiteStudio/dialogs/columndialog.cpp @@ -62,6 +62,7 @@ void ColumnDialog::init() connect(ui->fkButton, SIGNAL(clicked()), this, SLOT(configureFk())); connect(ui->checkButton, SIGNAL(clicked()), this, SLOT(configureCheck())); connect(ui->defaultButton, SIGNAL(clicked()), this, SLOT(configureDefault())); + connect(ui->generatedButton, SIGNAL(clicked()), this, SLOT(configureGenerated())); connect(ui->notNullButton, SIGNAL(clicked()), this, SLOT(configureNotNull())); connect(ui->collateButton, SIGNAL(clicked()), this, SLOT(configureCollate())); connect(ui->uniqueButton, SIGNAL(clicked()), this, SLOT(configureUnique())); @@ -95,6 +96,7 @@ void ColumnDialog::createActions() createAction(ADD_CHECK, ICONS.CONSTRAINT_CHECK_ADD, tr("Add a check constraint", "column dialog"), this, SLOT(addCheck()), ui->constraintsToolbar); createAction(ADD_NOT_NULL, ICONS.CONSTRAINT_NOT_NULL_ADD, tr("Add a not null constraint", "column dialog"), this, SLOT(addNotNull()), ui->constraintsToolbar); createAction(ADD_COLLATE, ICONS.CONSTRAINT_COLLATION_ADD, tr("Add a collate constraint", "column dialog"), this, SLOT(addCollate()), ui->constraintsToolbar); + createAction(ADD_GENERATED, ICONS.CONSTRAINT_GENERATED_ADD, tr("Add a generated value constraint", "column dialog"), this, SLOT(addGenerated()), ui->constraintsToolbar); createAction(ADD_DEFAULT, ICONS.CONSTRAINT_DEFAULT_ADD, tr("Add a default constraint", "column dialog"), this, SLOT(addDefault()), ui->constraintsToolbar); } @@ -128,6 +130,7 @@ void ColumnDialog::updateState() ui->notNullButton->setEnabled(ui->notNullCheck->isChecked()); ui->checkButton->setEnabled(ui->checkCheck->isChecked()); ui->collateButton->setEnabled(ui->collateCheck->isChecked()); + ui->generatedButton->setEnabled(ui->generatedCheck->isChecked()); ui->defaultButton->setEnabled(ui->defaultCheck->isChecked()); updateConstraintsToolbarState(); } @@ -135,6 +138,9 @@ void ColumnDialog::updateState() void ColumnDialog::addConstraint(ConstraintDialog::Constraint mode) { NewConstraintDialog dialog(mode, column.data(), db, this); + for (ConstraintDialog::Constraint constraint : disabledConstraints) + dialog.disableMode(constraint); + if (dialog.exec() != QDialog::Accepted) return; @@ -160,6 +166,7 @@ void ColumnDialog::setupConstraintCheckBoxes() ui->notNullCheck->setIcon(ICONS.CONSTRAINT_NOT_NULL); ui->checkCheck->setIcon(ICONS.CONSTRAINT_CHECK); ui->collateCheck->setIcon(ICONS.CONSTRAINT_COLLATION); + ui->generatedCheck->setIcon(ICONS.CONSTRAINT_GENERATED); ui->defaultCheck->setIcon(ICONS.CONSTRAINT_DEFAULT); connect(ui->pkCheck, SIGNAL(clicked(bool)), this, SLOT(pkToggled(bool))); @@ -168,6 +175,7 @@ void ColumnDialog::setupConstraintCheckBoxes() connect(ui->notNullCheck, SIGNAL(clicked(bool)), this, SLOT(notNullToggled(bool))); connect(ui->checkCheck, SIGNAL(clicked(bool)), this, SLOT(checkToggled(bool))); connect(ui->collateCheck, SIGNAL(clicked(bool)), this, SLOT(collateToggled(bool))); + connect(ui->generatedCheck, SIGNAL(clicked(bool)), this, SLOT(generatedToggled(bool))); connect(ui->defaultCheck, SIGNAL(clicked(bool)), this, SLOT(defaultToggled(bool))); for (QCheckBox* cb : { @@ -177,6 +185,7 @@ void ColumnDialog::setupConstraintCheckBoxes() ui->notNullCheck, ui->checkCheck, ui->collateCheck, + ui->generatedCheck, ui->defaultCheck }) { @@ -293,15 +302,7 @@ void ColumnDialog::updateConstraintState(SqliteCreateTable::Column::Constraint* } QString errMsg = tr("Correct the constraint's configuration."); - if (db->getDialect() == Dialect::Sqlite2 && isUnofficialSqlite2Constraint(constraint)) - { - QString tooltip = tr("This constraint is not officially supported by SQLite 2,\nbut it's okay to use it."); - setValidStateWihtTooltip(toolButton, tooltip, result, errMsg); - } - else - { - setValidState(toolButton, result, errMsg); - } + setValidState(toolButton, result, errMsg); if (!result) { @@ -326,6 +327,8 @@ QCheckBox* ColumnDialog::getCheckBoxForConstraint(SqliteCreateTable::Column::Con return ui->defaultCheck; case SqliteCreateTable::Column::Constraint::COLLATE: return ui->collateCheck; + case SqliteCreateTable::Column::Constraint::GENERATED: + return ui->generatedCheck; case SqliteCreateTable::Column::Constraint::FOREIGN_KEY: return ui->fkCheck; case SqliteCreateTable::Column::Constraint::NULL_: @@ -352,6 +355,8 @@ QToolButton* ColumnDialog::getToolButtonForConstraint(SqliteCreateTable::Column: return ui->defaultButton; case SqliteCreateTable::Column::Constraint::COLLATE: return ui->collateButton; + case SqliteCreateTable::Column::Constraint::GENERATED: + return ui->generatedButton; case SqliteCreateTable::Column::Constraint::FOREIGN_KEY: return ui->fkButton; case SqliteCreateTable::Column::Constraint::NULL_: @@ -362,26 +367,6 @@ QToolButton* ColumnDialog::getToolButtonForConstraint(SqliteCreateTable::Column: return nullptr; } -bool ColumnDialog::isUnofficialSqlite2Constraint(SqliteCreateTable::Column::Constraint* constraint) -{ - switch (constraint->type) - { - case SqliteCreateTable::Column::Constraint::FOREIGN_KEY: - case SqliteCreateTable::Column::Constraint::COLLATE: - return true; - case SqliteCreateTable::Column::Constraint::PRIMARY_KEY: - case SqliteCreateTable::Column::Constraint::NOT_NULL: - case SqliteCreateTable::Column::Constraint::UNIQUE: - case SqliteCreateTable::Column::Constraint::CHECK: - case SqliteCreateTable::Column::Constraint::DEFAULT: - case SqliteCreateTable::Column::Constraint::NULL_: - case SqliteCreateTable::Column::Constraint::NAME_ONLY: - case SqliteCreateTable::Column::Constraint::DEFERRABLE_ONLY: - break; - } - return false; -} - void ColumnDialog::updateTypeValidations() { QString scaleErrorMsg = tr("Scale is not allowed for INTEGER PRIMARY KEY columns."); @@ -503,6 +488,11 @@ void ColumnDialog::addNotNull() addConstraint(ConstraintDialog::NOTNULL); } +void ColumnDialog::addGenerated() +{ + addConstraint(ConstraintDialog::GENERATED); +} + void ColumnDialog::addDefault() { addConstraint(ConstraintDialog::DEFAULT); @@ -538,6 +528,11 @@ void ColumnDialog::configureNotNull() configureConstraint(SqliteCreateTable::Column::Constraint::NOT_NULL); } +void ColumnDialog::configureGenerated() +{ + configureConstraint(SqliteCreateTable::Column::Constraint::GENERATED); +} + void ColumnDialog::configureDefault() { configureConstraint(SqliteCreateTable::Column::Constraint::DEFAULT); @@ -569,6 +564,11 @@ void ColumnDialog::collateToggled(bool enabled) constraintToggled(SqliteCreateTable::Column::Constraint::COLLATE, enabled); } +void ColumnDialog::generatedToggled(bool enabled) +{ + constraintToggled(SqliteCreateTable::Column::Constraint::GENERATED, enabled); +} + void ColumnDialog::notNullToggled(bool enabled) { constraintToggled(SqliteCreateTable::Column::Constraint::NOT_NULL, enabled); @@ -596,6 +596,7 @@ void ColumnDialog::updateValidations() ui->notNullCheck, ui->checkCheck, ui->collateCheck, + ui->generatedCheck, ui->defaultCheck }) { @@ -609,6 +610,7 @@ void ColumnDialog::updateValidations() ui->notNullButton, ui->checkButton, ui->collateButton, + ui->generatedButton, ui->defaultButton }) { @@ -663,6 +665,47 @@ QToolBar* ColumnDialog::getToolBar(int toolbar) const return nullptr; } +void ColumnDialog::disableConstraint(ConstraintDialog::Constraint constraint) +{ + disabledConstraints << constraint; + switch (constraint) { + case ConstraintDialog::PK: + ui->pkCheck->setEnabled(false); + actionMap[ADD_PK]->setEnabled(false); + break; + case ConstraintDialog::FK: + ui->fkCheck->setEnabled(false); + actionMap[ADD_FK]->setEnabled(false); + break; + case ConstraintDialog::UNIQUE: + ui->uniqueCheck->setEnabled(false); + actionMap[ADD_UNIQUE]->setEnabled(false); + break; + case ConstraintDialog::NOTNULL: + ui->notNullCheck->setEnabled(false); + actionMap[ADD_NOT_NULL]->setEnabled(false); + break; + case ConstraintDialog::CHECK: + ui->checkCheck->setEnabled(false); + actionMap[ADD_CHECK]->setEnabled(false); + break; + case ConstraintDialog::COLLATE: + ui->collateCheck->setEnabled(false); + actionMap[ADD_COLLATE]->setEnabled(false); + break; + case ConstraintDialog::GENERATED: + ui->generatedCheck->setEnabled(false); + actionMap[ADD_GENERATED]->setEnabled(false); + break; + case ConstraintDialog::DEFAULT: + ui->defaultCheck->setEnabled(false); + actionMap[ADD_DEFAULT]->setEnabled(false); + break; + case ConstraintDialog::UNKNOWN: + break; + } +} + void ColumnDialog::updateDataType() { if (!column) |
