Skip to content

Commit 244d811

Browse files
MKleusbergrp-
authored andcommitted
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 sqlitebrowser#44.
1 parent 614504d commit 244d811

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

src/DbStructureModel.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ void DbStructureModel::reloadData(DBBrowserDB* db)
122122
rootItem->removeChild(rootItem->child(0));
123123
}
124124

125+
// Return here if no DB is opened
126+
if(!db->isOpen())
127+
{
128+
endResetModel();
129+
return;
130+
}
131+
125132
// Create the nodes for tables, indices, views and triggers
126133
QMap<QString, QTreeWidgetItem*> typeToParentItem;
127134
QTreeWidgetItem* itemTables = new QTreeWidgetItem(rootItem);

src/MainWindow.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,15 @@ void MainWindow::populateStructure()
224224
{
225225
completerModelTables.clear();
226226
clearCompleterModelsFields();
227+
228+
// Refresh the structure tab
229+
db.updateSchema();
230+
dbStructureModel->reloadData(&db);
231+
ui->dbTreeWidget->expandToDepth(0);
232+
227233
if(!db.isOpen())
228234
return;
229235

230-
db.updateSchema();
231236
QStringList tblnames = db.getBrowsableObjectNames();
232237
sqliteHighlighterLogUser->setTableNames(tblnames);
233238
sqliteHighlighterLogApp->setTableNames(tblnames);
@@ -271,10 +276,6 @@ void MainWindow::populateStructure()
271276
sqlarea->getEditor()->setDefaultCompleterModel(&completerModelTables);
272277
sqlarea->getEditor()->insertFieldCompleterModels(completerModelsFields);
273278
}
274-
275-
// Refresh the structure tab
276-
dbStructureModel->reloadData(&db);
277-
ui->dbTreeWidget->expandToDepth(0);
278279
}
279280

280281
void MainWindow::populateTable( const QString & tablename)

src/sqlitedb.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,10 +756,14 @@ void DBBrowserDB::updateSchema( )
756756
sqlite3_stmt *vm;
757757
const char *tail;
758758
int err=0;
759+
lastErrorMessage = QObject::tr("no error");
759760

760761
objMap.clear();
761762

762-
lastErrorMessage = QObject::tr("no error");
763+
// Exit here is no DB is opened
764+
if(!isOpen())
765+
return;
766+
763767
QString statement = "SELECT type, name, sql, tbl_name FROM sqlite_master;";
764768

765769
QByteArray utf8Statement = statement.toUtf8();

0 commit comments

Comments
 (0)