From c616b3947806411cd1e7d20ca936b5f1dfae35bd Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Sun, 3 Sep 2017 21:25:29 +0200 Subject: [PATCH] Don't allow selection of tables/indices in VACUUM dialog Remove the feature to select individual tables and indices to vacuum in the vacuum dialog. Turns out SQLite doesn't support this (and apparently never has). If you didn't select all tables at once, it would just print errors to the console output. I have no idea why we ever implemented it this way. However, the dialog could be reused to allow selection of database schemata to compact - and this actually does work. --- src/VacuumDialog.cpp | 34 ++++++++++++---------------------- src/VacuumDialog.ui | 8 ++++---- 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/src/VacuumDialog.cpp b/src/VacuumDialog.cpp index b6512fe6c..b64a76461 100644 --- a/src/VacuumDialog.cpp +++ b/src/VacuumDialog.cpp @@ -16,19 +16,16 @@ VacuumDialog::VacuumDialog(DBBrowserDB* _db, QWidget* parent) : ui->labelSavepointWarning->setVisible(db->getDirty()); // Populate list of objects to compact. We just support vacuuming the main schema here. - QList objects = db->schemata["main"].values("table"); - objects.append(db->schemata["main"].values("index")); - for(QList::const_iterator i=objects.constBegin();i!=objects.constEnd();++i) + for(auto it=db->schemata.constBegin();it!=db->schemata.constEnd();++it) { - QTreeWidgetItem* item = new QTreeWidgetItem(ui->treeSelectedObjects); - item->setText(0, (*i)->name()); - item->setIcon(0, QIcon(QString(":icons/%1").arg(sqlb::Object::typeToString((*i)->type())))); - ui->treeSelectedObjects->addTopLevelItem(item); + QTreeWidgetItem* item = new QTreeWidgetItem(ui->treeDatabases); + item->setText(0, it.key()); + item->setIcon(0, QIcon(QString(":icons/database"))); + ui->treeDatabases->addTopLevelItem(item); } - // Sort objects and select them all - ui->treeSelectedObjects->sortByColumn(0, Qt::AscendingOrder); - ui->treeSelectedObjects->selectAll(); + // Select the first item which should always be the main schema + ui->treeDatabases->setCurrentItem(ui->treeDatabases->topLevelItem(0)); } VacuumDialog::~VacuumDialog() @@ -38,7 +35,7 @@ VacuumDialog::~VacuumDialog() void VacuumDialog::accept() { - if(ui->treeSelectedObjects->selectedItems().count() == 0) + if(ui->treeDatabases->selectedItems().count() == 0) return QDialog::reject(); QApplication::setOverrideCursor(Qt::WaitCursor); @@ -46,17 +43,10 @@ void VacuumDialog::accept() // Commit all changes first db->releaseAllSavepoints(); - // All items selected? - if(ui->treeSelectedObjects->selectedItems().count() == ui->treeSelectedObjects->topLevelItemCount()) - { - // Yes, so just execute a simple vacuum command for all objects - db->executeSQL("VACUUM;", false); - } else { - // No, so execute a vacuum command for each selected object individually - QList selection = ui->treeSelectedObjects->selectedItems(); - foreach(QTreeWidgetItem* item, selection) - db->executeSQL(QString("VACUUM %1;").arg(sqlb::escapeIdentifier(item->text(0))), false); - } + // Loop through all selected databases and vacuum them individually + QList selection = ui->treeDatabases->selectedItems(); + foreach(QTreeWidgetItem* item, selection) + db->executeSQL(QString("VACUUM %1;").arg(sqlb::escapeIdentifier(item->text(0))), false); QApplication::restoreOverrideCursor(); QDialog::accept(); diff --git a/src/VacuumDialog.ui b/src/VacuumDialog.ui index 7d9de99ca..e1bf21546 100644 --- a/src/VacuumDialog.ui +++ b/src/VacuumDialog.ui @@ -36,15 +36,15 @@ - Please select the objects to compact: + Please select the databases to co&mpact: - treeSelectedObjects + treeDatabases - + QAbstractItemView::NoEditTriggers @@ -86,7 +86,7 @@ - treeSelectedObjects + treeDatabases buttonBox