Delete open databases when DatabaseTabWidget is destructed.

This commit is contained in:
Felix Geyer 2012-06-29 23:40:51 +02:00
parent 9ae6d2cd05
commit ca13ad8d25
2 changed files with 21 additions and 1 deletions

View File

@ -53,6 +53,15 @@ DatabaseTabWidget::DatabaseTabWidget(QWidget* parent)
connect(this, SIGNAL(currentChanged(int)), SLOT(emitEntrySelectionChanged()));
}
DatabaseTabWidget::~DatabaseTabWidget()
{
QHashIterator<Database*, DatabaseManagerStruct> i(m_dbList);
while (i.hasNext()) {
i.next();
deleteDatabase(i.key());
}
}
void DatabaseTabWidget::toggleTabbar() {
if (count() > 1) {
if (!tabBar()->isVisible()) {
@ -201,13 +210,22 @@ bool DatabaseTabWidget::closeDatabase(Database* db)
}
}
deleteDatabase(db);
return true;
}
void DatabaseTabWidget::deleteDatabase(Database* db)
{
const DatabaseManagerStruct dbStruct = m_dbList.value(db);
int index = databaseIndex(db);
removeTab(index);
toggleTabbar();
m_dbList.remove(db);
delete dbStruct.file;
delete dbStruct.dbWidget;
delete db;
return true;
}
bool DatabaseTabWidget::closeAllDatabases() {

View File

@ -47,6 +47,7 @@ class DatabaseTabWidget : public QTabWidget
public:
explicit DatabaseTabWidget(QWidget* parent);
~DatabaseTabWidget();
void openDatabase(const QString& fileName, const QString& pw = QString(),
const QString& keyFile = QString());
DatabaseWidget* currentDatabaseWidget();
@ -93,6 +94,7 @@ private:
void saveDatabase(Database* db);
void saveDatabaseAs(Database* db);
bool closeDatabase(Database* db);
void deleteDatabase(Database* db);
int databaseIndex(Database* db);
Database* indexDatabase(int index);
DatabaseManagerStruct indexDatabaseManagerStruct(int index);