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())); 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() { void DatabaseTabWidget::toggleTabbar() {
if (count() > 1) { if (count() > 1) {
if (!tabBar()->isVisible()) { 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); removeTab(index);
toggleTabbar(); toggleTabbar();
m_dbList.remove(db); m_dbList.remove(db);
delete dbStruct.file; delete dbStruct.file;
delete dbStruct.dbWidget; delete dbStruct.dbWidget;
delete db; delete db;
return true;
} }
bool DatabaseTabWidget::closeAllDatabases() { bool DatabaseTabWidget::closeAllDatabases() {

View File

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