mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
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:
@@ -1,6 +1,7 @@
|
||||
#include "ExtendedTableWidget.h"
|
||||
#include "sqlitetablemodel.h"
|
||||
#include "FilterTableHeader.h"
|
||||
#include "sqlitetypes.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
@@ -15,6 +16,7 @@ ExtendedTableWidget::ExtendedTableWidget(QWidget* parent) :
|
||||
setHorizontalScrollMode(ExtendedTableWidget::ScrollPerPixel);
|
||||
|
||||
connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(vscrollbarChanged(int)));
|
||||
connect(this, SIGNAL(clicked(QModelIndex)), this, SLOT(cellClicked(QModelIndex)));
|
||||
|
||||
// Set up filter row
|
||||
m_tableHeader = new FilterTableHeader(this);
|
||||
@@ -125,3 +127,16 @@ QSet<int> ExtendedTableWidget::selectedCols()
|
||||
selectedCols.insert(idx.column());
|
||||
return selectedCols;
|
||||
}
|
||||
|
||||
void ExtendedTableWidget::cellClicked(const QModelIndex& index)
|
||||
{
|
||||
// If Alt key is pressed try to jump to the row referenced by the foreign key of the clicked cell
|
||||
if(qApp->keyboardModifiers().testFlag(Qt::ControlModifier) && qApp->keyboardModifiers().testFlag(Qt::ShiftModifier) && model())
|
||||
{
|
||||
SqliteTableModel* m = qobject_cast<SqliteTableModel*>(model());
|
||||
sqlb::ForeignKeyClause fk = m->getForeignKeyClause(index.column()-1);
|
||||
|
||||
if(fk.isSet())
|
||||
emit foreignKeyClicked(fk.table(), fk.columns().size() ? fk.columns().at(0) : "", m->data(index, Qt::EditRole).toByteArray());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user