Skip to content

Commit

Permalink
Fix bug which made tables from other schemas inaccessible in Browse Data
Browse files Browse the repository at this point in the history
Fix a bug which made tables from other schemas than the main schema
inaccessible in the Browse Data tab. Most notably this always selects
table "main"."tbl" instead of for example "temp"."tbl".

See issue #2348.

# Conflicts:
#	src/TableBrowser.h
  • Loading branch information
mgrojo committed Aug 22, 2020
1 parent 90d33c6 commit f5a2b10
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void MainWindow::init()
// Set up DB structure tab
dbStructureModel = new DbStructureModel(db, this);
connect(&db, &DBBrowserDB::structureUpdated, this, [this]() {
QString old_table = QString::fromStdString(ui->tableBrowser->currentlyBrowsedTableName().name());
sqlb::ObjectIdentifier old_table = ui->tableBrowser->currentlyBrowsedTableName();
dbStructureModel->reloadData();
populateStructure(old_table);
});
Expand Down Expand Up @@ -572,7 +572,7 @@ void MainWindow::fileNewInMemoryDatabase()
createTable();
}

void MainWindow::populateStructure(const QString& old_table)
void MainWindow::populateStructure(const sqlb::ObjectIdentifier& old_table)
{
// Refresh the structure tab
ui->dbTreeWidget->setRootIndex(dbStructureModel->index(1, 0)); // Show the 'All' part of the db structure
Expand Down
2 changes: 1 addition & 1 deletion src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public slots:
void dbState(bool dirty);
void refresh();
void switchToBrowseDataTab(sqlb::ObjectIdentifier tableToBrowse = sqlb::ObjectIdentifier());
void populateStructure(const QString& old_table = QString());
void populateStructure(const sqlb::ObjectIdentifier& old_table = sqlb::ObjectIdentifier{});
void reloadSettings();

private slots:
Expand Down
10 changes: 5 additions & 5 deletions src/TableBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,9 @@ void TableBrowser::reset()

sqlb::ObjectIdentifier TableBrowser::currentlyBrowsedTableName() const
{
return sqlb::ObjectIdentifier(ui->comboBrowseTable->model()->data(dbStructureModel->index(ui->comboBrowseTable->currentIndex(),
DbStructureModel::ColumnSchema,
ui->comboBrowseTable->rootModelIndex())).toString().toStdString(),
return sqlb::ObjectIdentifier(dbStructureModel->index(ui->comboBrowseTable->currentIndex(),
DbStructureModel::ColumnSchema,
ui->comboBrowseTable->rootModelIndex()).data().toString().toStdString(),
ui->comboBrowseTable->currentData(Qt::EditRole).toString().toStdString()); // Use the edit role here to make sure we actually get the
// table name without the schema bit in front of it.
}
Expand All @@ -376,13 +376,13 @@ void TableBrowser::setSettings(const sqlb::ObjectIdentifier& table, const Browse
m_settings[table] = table_settings;
}

void TableBrowser::setStructure(QAbstractItemModel* model, const QString& old_table)
void TableBrowser::setStructure(QAbstractItemModel* model, const sqlb::ObjectIdentifier& old_table)
{
dbStructureModel = model;
ui->comboBrowseTable->setModel(model);

ui->comboBrowseTable->setRootModelIndex(dbStructureModel->index(0, 0)); // Show the 'browsable' section of the db structure tree
int old_table_index = ui->comboBrowseTable->findText(old_table);
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);
else if(old_table_index == -1) // If there aren't any tables to be selected anymore, clear the table view
Expand Down
3 changes: 1 addition & 2 deletions src/TableBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ class TableBrowser : public QWidget
BrowseDataTableSettings& settings(const sqlb::ObjectIdentifier& object);
void setSettings(const sqlb::ObjectIdentifier& table, const BrowseDataTableSettings& table_settings);

void setStructure(QAbstractItemModel* model, const QString& old_table = QString());
void updateStructure();
void setStructure(QAbstractItemModel* model, const sqlb::ObjectIdentifier& old_table = sqlb::ObjectIdentifier{});

SqliteTableModel* model() { return m_model; }

Expand Down

0 comments on commit f5a2b10

Please sign in to comment.