From 9185b34922208527cbb94642633483d43ed775f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabi=C3=A1n=20Inostroza?= Date: Sat, 16 Dec 2017 13:47:37 -0300 Subject: [PATCH] Synchronize PlotDock with 'Execute SQL' table. --- src/MainWindow.cpp | 46 +++++++++++++++++++++++++++++++++++++++------- src/MainWindow.h | 3 ++- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 43cb0ced..8664453f 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -694,6 +694,34 @@ void MainWindow::deleteRecord() } } +void MainWindow::selectCurrentTabTableLines(int firstLine, int lastLine) +{ + if(lastLine >= m_currentTabTableModel->totalRowCount()) + return; + + SqlExecutionArea *qw = (SqlExecutionArea*)ui->tabSqlAreas->currentWidget(); + ExtendedTableWidget *tw = qw->getTableResult(); + + if(firstLine >= m_currentTabTableModel->totalRowCount()) + return; + + QApplication::setOverrideCursor( Qt::WaitCursor ); + // Make sure this line has already been fetched + while(firstLine >= m_currentTabTableModel->rowCount() && m_currentTabTableModel->canFetchMore()) + m_currentTabTableModel->fetchMore(); + + // Select it + tw->clearSelection(); + tw->selectRow(firstLine); + tw->scrollTo(tw->currentIndex(), QAbstractItemView::PositionAtTop); + QApplication::restoreOverrideCursor(); + + QModelIndex topLeft = m_currentTabTableModel->index(firstLine, 0); + QModelIndex bottomRight = m_currentTabTableModel->index(lastLine, m_currentTabTableModel->columnCount()-1); + + tw->selectionModel()->select(QItemSelection(topLeft, bottomRight), QItemSelectionModel::Select | QItemSelectionModel::Rows); +} + void MainWindow::selectTableLine(int lineToSelect) { // Are there even that many lines? @@ -715,16 +743,20 @@ void MainWindow::selectTableLine(int lineToSelect) void MainWindow::selectTableLines(int firstLine, int count) { int lastLine = firstLine+count-1; - // Are there even that many lines? - if(lastLine >= m_browseTableModel->totalRowCount()) - return; + if(ui->mainTab->currentIndex() == 1) { + // Are there even that many lines? + if(lastLine >= m_browseTableModel->totalRowCount()) + return; - selectTableLine(firstLine); + selectTableLine(firstLine); - QModelIndex topLeft = ui->dataTable->model()->index(firstLine, 0); - QModelIndex bottomRight = ui->dataTable->model()->index(lastLine, ui->dataTable->model()->columnCount()-1); + QModelIndex topLeft = ui->dataTable->model()->index(firstLine, 0); + QModelIndex bottomRight = ui->dataTable->model()->index(lastLine, ui->dataTable->model()->columnCount()-1); - ui->dataTable->selectionModel()->select(QItemSelection(topLeft, bottomRight), QItemSelectionModel::Select | QItemSelectionModel::Rows); + ui->dataTable->selectionModel()->select(QItemSelection(topLeft, bottomRight), QItemSelectionModel::Select | QItemSelectionModel::Rows); + }else if(ui->mainTab->currentIndex() == 3) { + selectCurrentTabTableLines(firstLine, lastLine); + } } void MainWindow::navigatePrevious() diff --git a/src/MainWindow.h b/src/MainWindow.h index f3cf28ea..a41c9480 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -222,7 +222,8 @@ private slots: bool fileClose(); void addRecord(); void deleteRecord(); - void selectTableLine( int lineToSelect ); + void selectTableLine(int lineToSelect); + void selectCurrentTabTableLines(int firstLine, int lastLine); void selectTableLines(int firstLine, int count); void navigatePrevious(); void navigateNext();