From 7167ce41b61d2ba2cdb526777a4233eb84a3b66a Mon Sep 17 00:00:00 2001 From: Unit 193 Date: Sat, 6 Dec 2014 17:33:25 -0500 Subject: Imported Upstream version 2.99.6 --- .../constraints/columnuniqueandnotnullpanel.cpp | 99 ++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 SQLiteStudio3/guiSQLiteStudio/constraints/columnuniqueandnotnullpanel.cpp (limited to 'SQLiteStudio3/guiSQLiteStudio/constraints/columnuniqueandnotnullpanel.cpp') diff --git a/SQLiteStudio3/guiSQLiteStudio/constraints/columnuniqueandnotnullpanel.cpp b/SQLiteStudio3/guiSQLiteStudio/constraints/columnuniqueandnotnullpanel.cpp new file mode 100644 index 0000000..7c0f5a8 --- /dev/null +++ b/SQLiteStudio3/guiSQLiteStudio/constraints/columnuniqueandnotnullpanel.cpp @@ -0,0 +1,99 @@ +#include "columnuniqueandnotnullpanel.h" +#include "ui_columnuniqueandnotnullpanel.h" +#include "parser/ast/sqlitecreatetable.h" +#include "parser/keywords.h" +#include "uiutils.h" + +ColumnUniqueAndNotNullPanel::ColumnUniqueAndNotNullPanel(QWidget *parent) : + ConstraintPanel(parent), + ui(new Ui::ColumnUniqueAndNotNullPanel) +{ + ui->setupUi(this); + init(); +} + +ColumnUniqueAndNotNullPanel::~ColumnUniqueAndNotNullPanel() +{ + delete ui; +} + +void ColumnUniqueAndNotNullPanel::changeEvent(QEvent *e) +{ + QWidget::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + ui->retranslateUi(this); + break; + default: + break; + } +} + +void ColumnUniqueAndNotNullPanel::init() +{ + ui->conflictCombo->addItems(getConflictAlgorithms()); + + connect(ui->namedCheck, SIGNAL(toggled(bool)), this, SIGNAL(updateValidation())); + connect(ui->namedEdit, SIGNAL(textChanged(QString)), this, SIGNAL(updateValidation())); + connect(ui->namedCheck, SIGNAL(toggled(bool)), this, SLOT(updateState())); + connect(ui->conflictCheck, SIGNAL(toggled(bool)), this, SLOT(updateState())); + updateState(); +} + +void ColumnUniqueAndNotNullPanel::readConstraint() +{ + SqliteCreateTable::Column::Constraint* constr = dynamic_cast(constraint.data()); + + if (!constr->name.isNull()) + { + ui->namedCheck->setChecked(true); + ui->namedEdit->setText(constr->name); + } + + if (constr->onConflict != SqliteConflictAlgo::null) + { + ui->conflictCheck->setChecked(true); + ui->conflictCombo->setCurrentText(sqliteConflictAlgo(constr->onConflict)); + } +} + +void ColumnUniqueAndNotNullPanel::updateState() +{ + ui->namedEdit->setEnabled(ui->namedCheck->isChecked()); + ui->conflictCombo->setEnabled(ui->conflictCheck->isChecked()); +} + + +bool ColumnUniqueAndNotNullPanel::validate() +{ + bool nameOk = true; + if (ui->namedCheck->isChecked() && ui->namedEdit->text().isEmpty()) + nameOk = false; + + setValidState(ui->namedEdit, nameOk, tr("Enter a name of the constraint.")); + + return nameOk; +} + +void ColumnUniqueAndNotNullPanel::constraintAvailable() +{ + if (constraint.isNull()) + return; + + readConstraint(); +} + +void ColumnUniqueAndNotNullPanel::storeConfiguration() +{ + if (constraint.isNull()) + return; + + storeType(); + + SqliteCreateTable::Column::Constraint* constr = dynamic_cast(constraint.data()); + if (ui->namedCheck->isChecked()) + constr->name = ui->namedEdit->text(); + + if (ui->conflictCheck->isChecked() && ui->conflictCombo->currentIndex() > -1) + constr->onConflict = sqliteConflictAlgo(ui->conflictCombo->currentText()); +} -- cgit v1.2.3