Avoid possible database busy message when using the Browse Table action

Avoid a possible database busy warning when using the Browse Table
context menu action in the Database Structure tab. This happened because
of an unnecessary schema update.

Also do not refresh the view when changing between the main tabs. This
makes tab switching faster, makes sure the scroll position is not lost,
and avoid two queries instead of one when using the Browse Table action.

See issue #2283.
This commit is contained in:
Martin Kleusberg
2020-08-17 16:57:45 +02:00
parent 47aa591dfb
commit 73b2a1c23d
4 changed files with 19 additions and 37 deletions

View File

@@ -2630,12 +2630,7 @@ bool MainWindow::loadProject(QString filename, bool readOnly)
}
if (!currentTable.isEmpty())
{
int tab_index = newTableBrowserTab(true);
TableBrowser* w = qobject_cast<TableBrowser*>(ui->tabBrowsers->widget(tab_index));
if(w)
w->setCurrentTable(currentTable);
}
newTableBrowserTab(true, currentTable);
xml.skipCurrentElement();
} else if(xml.name() == "table") {
@@ -2644,11 +2639,8 @@ bool MainWindow::loadProject(QString filename, bool readOnly)
sqlb::ObjectIdentifier table;
table.fromSerialised(xml.attributes().value("table").toString().toStdString());
int tab_index = newTableBrowserTab(true);
int tab_index = newTableBrowserTab(true, table);
ui->tabBrowsers->setTabText(tab_index, title);
TableBrowser* w = qobject_cast<TableBrowser*>(ui->tabBrowsers->widget(tab_index));
if(w)
w->setCurrentTable(table);
xml.skipCurrentElement();
} else if(xml.name() == "current_tab") {
@@ -3126,14 +3118,15 @@ void MainWindow::switchToBrowseDataTab(sqlb::ObjectIdentifier tableToBrowse)
tableToBrowse.setName(ui->dbTreeWidget->model()->data(ui->dbTreeWidget->currentIndex().sibling(ui->dbTreeWidget->currentIndex().row(), DbStructureModel::ColumnName), Qt::EditRole).toString().toStdString());
}
int tab_index = newTableBrowserTab();
TableBrowser* w = qobject_cast<TableBrowser*>(ui->tabBrowsers->widget(tab_index));
if(w)
w->setCurrentTable(tableToBrowse);
newTableBrowserTab(false, tableToBrowse);
if (ui->mainTab->indexOf(ui->browser) == -1)
ui->mainTab->addTab(ui->browser, ui->browser->accessibleName());
// Don't emit a main tab changed signal here because all it would do is refreshing the just loaded table view
ui->mainTab->blockSignals(true);
ui->mainTab->setCurrentWidget(ui->browser);
ui->mainTab->blockSignals(false);
}
void MainWindow::copyCurrentCreateStatement()
@@ -3571,7 +3564,7 @@ void MainWindow::closeTableBrowserTab(int index, bool force)
newTableBrowserTab(true);
}
int MainWindow::newTableBrowserTab(bool resetCounter)
int MainWindow::newTableBrowserTab(bool resetCounter, const sqlb::ObjectIdentifier& tableToBrowse)
{
static int tabNumber = 0;
@@ -3580,7 +3573,7 @@ int MainWindow::newTableBrowserTab(bool resetCounter)
// Create and initialise widget
TableBrowser* w = new TableBrowser(&db, this);
w->setStructure(dbStructureModel);
w->setStructure(dbStructureModel, tableToBrowse);
w->setEnabled(ui->fileCloseAction->isEnabled());
// Connect signals and slots

View File

@@ -208,7 +208,7 @@ private slots:
void renameSqlTab(int index);
void showContextMenuSqlTabBar(const QPoint& pos);
int newTableBrowserTab(bool resetCounter = false);
int newTableBrowserTab(bool resetCounter = false, const sqlb::ObjectIdentifier& tableToBrowse = {});
void closeTableBrowserTab(int index, bool force = false);
void changeTableBrowserTab(int index);
void renameTableBrowserTab(int index);

View File

@@ -143,6 +143,11 @@ TableBrowser::TableBrowser(DBBrowserDB* _db, QWidget* parent) :
connect(ui->dataTable, &ExtendedTableWidget::openFileFromDropEvent, this, &TableBrowser::requestFileOpen);
connect(ui->dataTable, &ExtendedTableWidget::selectedRowsToBeDeleted, this, &TableBrowser::deleteRecord);
connect(ui->actionRefresh, &QAction::triggered, this, [this]() {
db->updateSchema();
updateTable();
});
connect(ui->fontComboBox, &QFontComboBox::currentFontChanged, this, [this](const QFont &font) {
modifyFormat([font](CondFormat& format) { format.setFontFamily(font.family()); });
});
@@ -378,9 +383,12 @@ void TableBrowser::setSettings(const sqlb::ObjectIdentifier& table, const Browse
void TableBrowser::setStructure(QAbstractItemModel* model, const sqlb::ObjectIdentifier& old_table)
{
dbStructureModel = model;
ui->comboBrowseTable->setModel(model);
ui->comboBrowseTable->blockSignals(true);
ui->comboBrowseTable->setModel(model);
ui->comboBrowseTable->setRootModelIndex(dbStructureModel->index(0, 0)); // Show the 'browsable' section of the db structure tree
ui->comboBrowseTable->blockSignals(false);
int old_table_index = ui->comboBrowseTable->findText(QString::fromStdString(old_table.toDisplayString()));
if(old_table_index == -1 && ui->comboBrowseTable->count()) // If the old table couldn't be found anymore but there is another table, select that
ui->comboBrowseTable->setCurrentIndex(0);
@@ -422,9 +430,6 @@ void TableBrowser::updateTable()
return;
}
// Update the schema first
db->updateSchema();
// Reset the minimum width of the vertical header which could have been modified in updateFilter
// or in headerClicked.
ui->dataTable->verticalHeader()->setMinimumWidth(0);

View File

@@ -1406,22 +1406,6 @@
</hint>
</hints>
</connection>
<connection>
<sender>actionRefresh</sender>
<signal>triggered()</signal>
<receiver>TableBrowser</receiver>
<slot>updateTable()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>518</x>
<y>314</y>
</hint>
</hints>
</connection>
<connection>
<sender>actionPrintTable</sender>
<signal>triggered()</signal>