@@ -78,7 +78,13 @@ ForeignKeyEditorDelegate::ForeignKeyEditorDelegate(const DBBrowserDB& db, sqlb::
7878 , m_db(db)
7979 , m_table(table)
8080{
81-
81+ const auto objects = m_db.getBrowsableObjects ();
82+ for (auto obj : objects) {
83+ if (" table" == obj.gettype ()) {
84+ QString tableName = obj.table .name ();
85+ m_tablesIds.insert (tableName, obj.table .fieldNames ());
86+ }
87+ }
8288}
8389
8490QWidget* ForeignKeyEditorDelegate::createEditor (QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
@@ -99,24 +105,16 @@ QWidget* ForeignKeyEditorDelegate::createEditor(QWidget* parent, const QStyleOpt
99105 box->setCurrentIndex (0 );
100106 });
101107
108+ editor->tablesComboBox ->clear ();
109+ editor->tablesComboBox ->addItems (m_tablesIds.keys ());
110+
102111 return editor;
103112}
104113
105114void ForeignKeyEditorDelegate::setEditorData (QWidget* editor, const QModelIndex& index) const
106115{
107116 ForeignKeyEditor* fkEditor = static_cast <ForeignKeyEditor*>(editor);
108117
109- m_tablesIds.clear ();
110- const auto objects = m_db.getBrowsableObjects ();
111- for (auto obj : objects) {
112- if (" table" == obj.gettype ()) {
113- QString tableName = obj.table .name ();
114- m_tablesIds.insert (tableName, obj.table .fieldNames ());
115- }
116- }
117-
118- fkEditor->tablesComboBox ->addItems (m_tablesIds.keys ());
119-
120118 int column = index.row (); // weird? I know right
121119 sqlb::FieldPtr field = m_table.fields ().at (column);
122120 QSharedPointer<sqlb::ForeignKeyClause> fk = m_table.constraint ({field}, sqlb::Constraint::ForeignKeyConstraintType).dynamicCast <sqlb::ForeignKeyClause>();
@@ -170,4 +168,12 @@ void ForeignKeyEditorDelegate::updateEditorGeometry(QWidget* editor, const QStyl
170168 editor->setGeometry (option.rect );
171169}
172170
171+ void ForeignKeyEditorDelegate::updateTablesList (const QString& oldTableName)
172+ {
173+ // this is used for recursive table constraints when
174+ // table column references column within same table
175+ m_tablesIds.remove (oldTableName);
176+ m_tablesIds.insert (m_table.name (), m_table.fieldNames ());
177+ }
178+
173179#include " ForeignKeyEditorDelegate.moc"
0 commit comments