mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
Synchronize PlotDock with 'Execute SQL' table. Continuation of PR #1271
Make use of signals to connect the selection in plot to the associated table widget. Every time that the plot is updated from the Main Window the table widget associated to the table or query is connected to the plot and the previous widget is disconnected. This allows the selection of the correct table widget. Line selection methods moved to the Extended Table Widget to be used as slots for this connection. The destroyed signal is also connected for resetting the plot. This fixes a crash that already existed before this PR, when closing a SQL tab while the plot is still associated to the table results model.
This commit is contained in:
@@ -657,3 +657,40 @@ void ExtendedTableWidget::dropEvent(QDropEvent* event)
|
||||
model()->dropMimeData(event->mimeData(), Qt::CopyAction, index.row(), index.column(), QModelIndex());
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
|
||||
void ExtendedTableWidget::selectTableLine(int lineToSelect)
|
||||
{
|
||||
SqliteTableModel* m = qobject_cast<SqliteTableModel*>(model());
|
||||
|
||||
// Are there even that many lines?
|
||||
if(lineToSelect >= m->totalRowCount())
|
||||
return;
|
||||
|
||||
QApplication::setOverrideCursor( Qt::WaitCursor );
|
||||
// Make sure this line has already been fetched
|
||||
while(lineToSelect >= m->rowCount() && m->canFetchMore())
|
||||
m->fetchMore();
|
||||
|
||||
// Select it
|
||||
clearSelection();
|
||||
selectRow(lineToSelect);
|
||||
scrollTo(currentIndex(), QAbstractItemView::PositionAtTop);
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
void ExtendedTableWidget::selectTableLines(int firstLine, int count)
|
||||
{
|
||||
SqliteTableModel* m = qobject_cast<SqliteTableModel*>(model());
|
||||
|
||||
int lastLine = firstLine+count-1;
|
||||
// Are there even that many lines?
|
||||
if(lastLine >= m->totalRowCount())
|
||||
return;
|
||||
|
||||
selectTableLine(firstLine);
|
||||
|
||||
QModelIndex topLeft = m->index(firstLine, 0);
|
||||
QModelIndex bottomRight = m->index(lastLine, m->columnCount()-1);
|
||||
|
||||
selectionModel()->select(QItemSelection(topLeft, bottomRight), QItemSelectionModel::Select | QItemSelectionModel::Rows);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user