diff options
| author | 2015-01-30 17:00:07 -0500 | |
|---|---|---|
| committer | 2015-01-30 17:00:07 -0500 | |
| commit | 016003905ca0e8e459e3dc33e786beda8ec92f45 (patch) | |
| tree | 34aba2d2e0d66fbf2c3821ee8358f56e40c4c95e /SQLiteStudio3/guiSQLiteStudio/dbtree/dbtree.cpp | |
| parent | 724c012ada23ef480c61fe99e3c9784b91aeb1ca (diff) | |
Imported Upstream version 3.0.2upstream/3.0.2
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/dbtree/dbtree.cpp')
| -rw-r--r-- | SQLiteStudio3/guiSQLiteStudio/dbtree/dbtree.cpp | 49 |
1 files changed, 40 insertions, 9 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtree.cpp b/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtree.cpp index 8e137a4..509594d 100644 --- a/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtree.cpp +++ b/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtree.cpp @@ -114,20 +114,21 @@ void DbTree::createActions() createAction(INTEGRITY_CHECK, ICONS.INTEGRITY_CHECK, tr("Integrity check"), this, SLOT(integrityCheck()), this); createAction(ADD_TABLE, ICONS.TABLE_ADD, tr("Create a table"), this, SLOT(addTable()), this); createAction(EDIT_TABLE, ICONS.TABLE_EDIT, tr("Edit the table"), this, SLOT(editTable()), this); - createAction(DEL_TABLE, ICONS.TABLE_DEL, tr("Drop the table"), this, SLOT(delTable()), this); + createAction(DEL_TABLE, ICONS.TABLE_DEL, tr("Delete the table"), this, SLOT(delTable()), this); createAction(EXPORT_TABLE, ICONS.TABLE_EXPORT, tr("Export the table"), this, SLOT(exportTable()), this); createAction(IMPORT_TABLE, ICONS.TABLE_IMPORT, tr("Import into the table"), this, SLOT(importTable()), this); createAction(POPULATE_TABLE, ICONS.TABLE_POPULATE, tr("Populate table"), this, SLOT(populateTable()), this); createAction(CREATE_SIMILAR_TABLE, ICONS.TABLE_CREATE_SIMILAR, tr("Create similar table"), this, SLOT(createSimilarTable()), this); + createAction(RESET_AUTOINCREMENT, ICONS.RESET_AUTOINCREMENT, tr("Reset autoincrement sequence"), this, SLOT(resetAutoincrement()), this); createAction(ADD_INDEX, ICONS.INDEX_ADD, tr("Create an index"), this, SLOT(addIndex()), this); createAction(EDIT_INDEX, ICONS.INDEX_EDIT, tr("Edit the index"), this, SLOT(editIndex()), this); - createAction(DEL_INDEX, ICONS.INDEX_DEL, tr("Drop the index"), this, SLOT(delIndex()), this); + createAction(DEL_INDEX, ICONS.INDEX_DEL, tr("Delete the index"), this, SLOT(delIndex()), this); createAction(ADD_TRIGGER, ICONS.TRIGGER_ADD, tr("Create a trigger"), this, SLOT(addTrigger()), this); createAction(EDIT_TRIGGER, ICONS.TRIGGER_EDIT, tr("Edit the trigger"), this, SLOT(editTrigger()), this); - createAction(DEL_TRIGGER, ICONS.TRIGGER_DEL, tr("Drop the trigger"), this, SLOT(delTrigger()), this); + createAction(DEL_TRIGGER, ICONS.TRIGGER_DEL, tr("Delete the trigger"), this, SLOT(delTrigger()), this); createAction(ADD_VIEW, ICONS.VIEW_ADD, tr("Create a view"), this, SLOT(addView()), this); createAction(EDIT_VIEW, ICONS.VIEW_EDIT, tr("Edit the view"), this, SLOT(editView()), this); - createAction(DEL_VIEW, ICONS.VIEW_DEL, tr("Drop the view"), this, SLOT(delView()), this); + createAction(DEL_VIEW, ICONS.VIEW_DEL, tr("Delete the view"), this, SLOT(delView()), this); createAction(ADD_COLUMN, ICONS.TABLE_COLUMN_ADD, tr("Add a column"), this, SLOT(addColumn()), this); createAction(EDIT_COLUMN, ICONS.TABLE_COLUMN_EDIT, tr("Edit the column"), this, SLOT(editColumn()), this); createAction(DEL_COLUMN, ICONS.TABLE_COLUMN_DELETE, tr("Delete the column"), this, SLOT(delColumn()), this); @@ -188,7 +189,7 @@ void DbTree::updateActionStates(const QStandardItem *item) break; case DbTreeItem::Type::TABLE: enabled << EDIT_TABLE << DEL_TABLE << EXPORT_TABLE << IMPORT_TABLE << POPULATE_TABLE << ADD_COLUMN << CREATE_SIMILAR_TABLE; - enabled << ADD_INDEX << ADD_TRIGGER; + enabled << RESET_AUTOINCREMENT << ADD_INDEX << ADD_TRIGGER; break; case DbTreeItem::Type::VIRTUAL_TABLE: // TODO change below when virtual tables can be edited @@ -304,12 +305,12 @@ void DbTree::setupActionsForMenu(DbTreeItem* currItem, QMenu* contextMenu) { QList<ActionEntry> actions; - ActionEntry dbEntry(ICONS.DATABASE, tr("Datatabase")); + ActionEntry dbEntry(ICONS.DATABASE, tr("Database")); dbEntry += ADD_DB; dbEntry += EDIT_DB; dbEntry += DELETE_DB; - ActionEntry dbEntryExt(ICONS.DATABASE, tr("Datatabase")); + ActionEntry dbEntryExt(ICONS.DATABASE, tr("Database")); dbEntryExt += CONNECT_TO_DB; dbEntryExt += DISCONNECT_FROM_DB; dbEntryExt += _separator; @@ -391,6 +392,7 @@ void DbTree::setupActionsForMenu(DbTreeItem* currItem, QMenu* contextMenu) actions += ActionEntry(EXPORT_TABLE); actions += ActionEntry(POPULATE_TABLE); actions += ActionEntry(CREATE_SIMILAR_TABLE); + actions += ActionEntry(RESET_AUTOINCREMENT); actions += ActionEntry(_separator); actions += dbEntryExt; break; @@ -875,6 +877,7 @@ void DbTree::refreshSchema(Db* db) return; treeModel->refreshSchema(db); + updateActionsForCurrent(); } void DbTree::copy() @@ -929,7 +932,7 @@ void DbTree::createGroup() while (existingItems.contains(name = QInputDialog::getText(this, tr("Create group"), tr("Group name"))) || (name.isEmpty() && !name.isNull())) { - QMessageBox::information(this, tr("Create directory"), tr("Entry with name %1 already exists in directory %2.") + QMessageBox::information(this, tr("Create group"), tr("Entry with name %1 already exists in group %2.") .arg(name).arg(currItem->text()), QMessageBox::Ok); } @@ -1370,6 +1373,32 @@ void DbTree::createSimilarTable() dialog.addTableSimilarTo(QString(), table); } +void DbTree::resetAutoincrement() +{ + Db* db = getSelectedDb(); + if (!db || !db->isValid()) + return; + + DbTreeItem* item = ui->treeView->currentItem(); + QString table = item->getTable(); + if (table.isNull()) + { + qWarning() << "Tried to reset autoincrement, while table wasn't selected in DbTree."; + return; + } + + QMessageBox::StandardButton btn = QMessageBox::question(this, tr("Reset autoincrement"), tr("Are you sure you want to reset autoincrement value for table '%1'?") + .arg(table)); + if (btn != QMessageBox::Yes) + return; + + SqlQueryPtr res = db->exec("DELETE FROM sqlite_sequence WHERE name = ?;", {table}); + if (res->isError()) + notifyError(tr("An error occurred while trying to reset autoincrement value for table '%1': %2").arg(table, res->getErrorText())); + else + notifyInfo(tr("Autoincrement value for table '%1' has been reset successfly.").arg(table)); +} + void DbTree::addColumn(DbTreeItem* item) { Db* db = getSelectedOpenDb(); @@ -1500,7 +1529,7 @@ void DbTree::deleteItems(const QList<DbTreeItem*>& itemsToDelete) if (deletedDatabases.contains(dbToRefresh)) continue; - DBTREE->refreshSchema(dbToRefresh); + refreshSchema(dbToRefresh); } } @@ -1508,6 +1537,8 @@ void DbTree::refreshSchemas() { foreach (Db* db, DBLIST->getDbList()) treeModel->refreshSchema(db); + + updateActionsForCurrent(); } void DbTree::interrupt() |
