Show tables in foreign key editor in alphabetical order

Make sure to list the tables in the foreign key editor of the Edit Table
dialog in alphabetical order instead sorting them randomly.

See issue #2700.
This commit is contained in:
Martin Kleusberg
2021-05-21 16:52:55 +02:00
parent a55890f7d0
commit d7074bb834
2 changed files with 3 additions and 8 deletions

View File

@@ -84,11 +84,7 @@ ForeignKeyEditorDelegate::ForeignKeyEditorDelegate(const DBBrowserDB& db, sqlb::
for(const auto& it : m_db.schemata)
{
for(const auto& jt : it.second.tables)
{
// Don't insert the current table into the list. The name and fields of the current table are always taken from the m_table reference
if(jt.first != m_table.name())
m_tablesIds.insert({jt.first, jt.second->fieldNames()});
}
m_tablesIds.insert({jt.first, jt.second->fieldNames()});
}
}
@@ -126,7 +122,6 @@ QWidget* ForeignKeyEditorDelegate::createEditor(QWidget* parent, const QStyleOpt
editor->tablesComboBox->clear();
for(const auto& i : m_tablesIds)
editor->tablesComboBox->addItem(QString::fromStdString(i.first));
editor->tablesComboBox->addItem(QString::fromStdString(m_table.name())); // For recursive foreign keys
return editor;
}

View File

@@ -2,7 +2,7 @@
#define FOREIGNKEYDELEGATE_H
#include <QStyledItemDelegate>
#include <unordered_map>
#include <map>
#include <vector>
#include <string>
@@ -28,7 +28,7 @@ public:
private:
const DBBrowserDB& m_db;
sqlb::Table& m_table;
mutable std::unordered_map<std::string, std::vector<std::string>> m_tablesIds;
mutable std::map<std::string, std::vector<std::string>> m_tablesIds;
};
#endif // FOREIGNKEYDELEGATE_H