Skip to content

Commit 42c5de7

Browse files
committed
Use a separate enum for table constraint types in the Edit Table dialog
This adds a enum of table constraint types to the Edit Table dialog instead of reusing the enum provided by the sqlb::Constraint class. This way changes to the sqlb namespace do not affect the Edit Table dialog as much and in the long term I would like to get rid of the enum in the sqlb::Constraint class anyway.
1 parent a14e6eb commit 42c5de7

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/EditTableDialog.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ EditTableDialog::EditTableDialog(DBBrowserDB& db, const sqlb::ObjectIdentifier&
6060
constraint_menu->addAction(ui->actionAddForeignKey);
6161
constraint_menu->addAction(ui->actionAddUniqueConstraint);
6262
constraint_menu->addAction(ui->actionAddCheckConstraint);
63-
connect(ui->actionAddPrimaryKey, &QAction::triggered, this, [this]() { addConstraint(sqlb::Constraint::PrimaryKeyConstraintType); });
64-
connect(ui->actionAddForeignKey, &QAction::triggered, this, [this]() { addConstraint(sqlb::Constraint::ForeignKeyConstraintType); });
65-
connect(ui->actionAddUniqueConstraint, &QAction::triggered, this, [this]() { addConstraint(sqlb::Constraint::UniqueConstraintType); });
66-
connect(ui->actionAddCheckConstraint, &QAction::triggered, this, [this]() { addConstraint(sqlb::Constraint::CheckConstraintType); });
63+
connect(ui->actionAddPrimaryKey, &QAction::triggered, this, [this]() { addConstraint(TableConstraintType::PrimaryKey); });
64+
connect(ui->actionAddForeignKey, &QAction::triggered, this, [this]() { addConstraint(TableConstraintType::ForeignKey); });
65+
connect(ui->actionAddUniqueConstraint, &QAction::triggered, this, [this]() { addConstraint(TableConstraintType::Unique); });
66+
connect(ui->actionAddCheckConstraint, &QAction::triggered, this, [this]() { addConstraint(TableConstraintType::Check); });
6767
ui->buttonAddConstraint->setMenu(constraint_menu);
6868

6969
// Get list of all collations
@@ -1095,10 +1095,10 @@ void EditTableDialog::removeConstraint()
10951095
populateFields();
10961096
}
10971097

1098-
void EditTableDialog::addConstraint(sqlb::Constraint::ConstraintTypes type)
1098+
void EditTableDialog::addConstraint(TableConstraintType type)
10991099
{
11001100
// There can only be one primary key
1101-
if(type == sqlb::Constraint::PrimaryKeyConstraintType)
1101+
if(type == TableConstraintType::PrimaryKey)
11021102
{
11031103
if(m_table.primaryKey())
11041104
{
@@ -1109,11 +1109,11 @@ void EditTableDialog::addConstraint(sqlb::Constraint::ConstraintTypes type)
11091109

11101110
// Create new constraint
11111111
m_table.addConstraint(sqlb::IndexedColumnVector{}, std::make_shared<sqlb::PrimaryKeyConstraint>());
1112-
} else if(type == sqlb::Constraint::UniqueConstraintType)
1112+
} else if(type == TableConstraintType::Unique)
11131113
m_table.addConstraint(sqlb::IndexedColumnVector{}, std::make_shared<sqlb::UniqueConstraint>());
1114-
else if(type == sqlb::Constraint::ForeignKeyConstraintType)
1114+
else if(type == TableConstraintType::ForeignKey)
11151115
m_table.addConstraint(sqlb::StringVector{}, std::make_shared<sqlb::ForeignKeyClause>());
1116-
else if(type == sqlb::Constraint::CheckConstraintType)
1116+
else if(type == TableConstraintType::Check)
11171117
m_table.addConstraint(std::make_shared<sqlb::CheckConstraint>());
11181118

11191119
// Update SQL and view

src/EditTableDialog.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ class EditTableDialog : public QDialog
5858
MoveBottom
5959
};
6060

61+
enum TableConstraintType
62+
{
63+
PrimaryKey,
64+
Unique,
65+
ForeignKey,
66+
Check
67+
};
68+
6169
void updateColumnWidth();
6270
void updateSqlText();
6371

@@ -85,7 +93,7 @@ private slots:
8593
void setStrict(bool strict);
8694
void changeSchema(const QString& schema);
8795
void removeConstraint();
88-
void addConstraint(sqlb::Constraint::ConstraintTypes type);
96+
void addConstraint(EditTableDialog::TableConstraintType type);
8997
void setOnConflict(const QString& on_conflict);
9098

9199
private:

0 commit comments

Comments
 (0)