Files
sqlitebrowser/src/ForeignKeyEditorDelegate.h
Martin Kleusberg a69c62790f Fix foreign key editor not working correctly in Edit Table dialog
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.
2019-09-22 22:06:04 +02:00

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