Clear the tree widget in the Structure tab when after closing a DB

Clear the tree widget in the 'Database Structure' tab of the main window
after closing a database.
See issue #44.
This commit is contained in:
Martin Kleusberg
2014-04-22 22:08:27 +02:00
parent f451beef0d
commit a7110ea0fc
3 changed files with 18 additions and 6 deletions

View File

@@ -125,6 +125,13 @@ void DbStructureModel::reloadData(DBBrowserDB* db)
rootItem->removeChild(rootItem->child(0));
}
// Return here if no DB is opened
if(!db->isOpen())
{
endResetModel();
return;
}
// Create the nodes for tables, indices, views and triggers
QMap<QString, QTreeWidgetItem*> typeToParentItem;
QTreeWidgetItem* itemTables = new QTreeWidgetItem(rootItem);

View File

@@ -220,10 +220,15 @@ void MainWindow::populateStructure()
{
completerModelTables.clear();
clearCompleterModelsFields();
// Refresh the structure tab
db.updateSchema();
dbStructureModel->reloadData(&db);
ui->dbTreeWidget->expandToDepth(0);
if(!db.isOpen())
return;
db.updateSchema();
QStringList tblnames = db.getBrowsableObjectNames();
sqliteHighlighterLogUser->setTableNames(tblnames);
sqliteHighlighterLogApp->setTableNames(tblnames);
@@ -267,10 +272,6 @@ void MainWindow::populateStructure()
sqlarea->getEditor()->setDefaultCompleterModel(&completerModelTables);
sqlarea->getEditor()->insertFieldCompleterModels(completerModelsFields);
}
// Refresh the structure tab
dbStructureModel->reloadData(&db);
ui->dbTreeWidget->expandToDepth(0);
}
void MainWindow::populateTable( const QString & tablename)

View File

@@ -757,10 +757,14 @@ void DBBrowserDB::updateSchema( )
sqlite3_stmt *vm;
const char *tail;
int err=0;
lastErrorMessage = QObject::tr("no error");
objMap.clear();
lastErrorMessage = QObject::tr("no error");
// Exit here is no DB is opened
if(!isOpen())
return;
QString statement = "SELECT type, name, sql, tbl_name FROM sqlite_master;";
QByteArray utf8Statement = statement.toUtf8();