mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 19:11:39 -06:00
When creating a new foreign key constraint in the Edit Table dialog, a list of tables to reference is displayed. This list is updated whenever the name of the edited table changes because this is the only table the name of which can change while the Edit Table dialog is opened. However, this meant that when the name of the table changes to some existing table name, the field list of that existing table is replaced by the field list of the current table. If the name of the current table is changed once again, it is deleted entirely from the list. This commit fixes this behaviour by separating the static part of the table and field list from the one table which can change. See issue #1991.
35 lines
1018 B
C++
35 lines
1018 B
C++
#ifndef FOREIGNKEYDELEGATE_H
|
|
#define FOREIGNKEYDELEGATE_H
|
|
|
|
#include <QStyledItemDelegate>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
#include <string>
|
|
|
|
class DBBrowserDB;
|
|
|
|
namespace sqlb
|
|
{
|
|
class Table;
|
|
}
|
|
|
|
class ForeignKeyEditorDelegate : public QStyledItemDelegate
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit ForeignKeyEditorDelegate(const DBBrowserDB& db, sqlb::Table& table, QObject* parent = nullptr);
|
|
|
|
QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
|
void setEditorData(QWidget* editor, const QModelIndex& index) const override;
|
|
void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const override;
|
|
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
|
|
|
private:
|
|
const DBBrowserDB& m_db;
|
|
sqlb::Table& m_table;
|
|
mutable std::unordered_map<std::string, std::vector<std::string>> m_tablesIds;
|
|
};
|
|
|
|
#endif // FOREIGNKEYDELEGATE_H
|