Allow clicking cells with foreign key in order to jump to referenced cell

Add a tooltip to the database browser when you hover a cell with a
foreign key set in order to show the referenced table and column.

When clicking on such a cell while holding the Ctrl and Shift key (only
one of them won't work because they are for multiselection and Alt
doesn't do the trick on my system because it's just for grabbing and
moving the window) try to jump to the table and row which is referenced
in the clicked cell.

See issue #192.
This commit is contained in:
Martin Kleusberg
2015-06-21 23:55:55 +02:00
parent 9dc59086a6
commit 39a49e33c2
9 changed files with 92 additions and 3 deletions

View File

@@ -265,11 +265,26 @@ QVariant SqliteTableModel::data(const QModelIndex &index, int role) const
if(m_data.at(index.row()).at(index.column()).isNull())
return QColor(PreferencesDialog::getSettingsValue("databrowser", "null_bg_colour").toString());
return QVariant();
} else if(role == Qt::ToolTipRole) {
sqlb::ForeignKeyClause fk = getForeignKeyClause(index.column()-1);
if(fk.isSet())
return tr("References %1(%2)\nHold Ctrl+Shift and click to jump there").arg(fk.table()).arg(fk.columns().join(','));
else
return QString();
} else {
return QVariant();
}
}
sqlb::ForeignKeyClause SqliteTableModel::getForeignKeyClause(int column) const
{
DBBrowserObject obj = m_db->getObjectByName(m_sTable);
if(obj.getname().size())
return obj.table.fields().at(column)->foreignKey();
else
return sqlb::ForeignKeyClause();
}
bool SqliteTableModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
if(index.isValid() && role == Qt::EditRole)