Skip to content

Commit a5d3669

Browse files
committed
Simplify code
1 parent b6c0560 commit a5d3669

4 files changed

Lines changed: 22 additions & 22 deletions

File tree

src/DbStructureModel.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -303,27 +303,27 @@ void DbStructureModel::buildTree(QTreeWidgetItem* parent, const QString& schema)
303303

304304
// Get all database objects and sort them by their name
305305
QMultiMap<QString, sqlb::ObjectPtr> dbobjs;
306-
for(auto it=objmap.constBegin(); it != objmap.constEnd(); ++it)
307-
dbobjs.insert((*it)->name(), (*it));
306+
for(auto it : objmap)
307+
dbobjs.insert(it->name(), it);
308308

309309
// Add the database objects to the tree nodes
310-
for(auto it=dbobjs.constBegin();it!=dbobjs.constEnd();++it)
310+
for(auto it : dbobjs)
311311
{
312312
// Object node
313-
QTreeWidgetItem* item = addNode(typeToParentItem.value(sqlb::Object::typeToString((*it)->type())), *it, schema);
313+
QTreeWidgetItem* item = addNode(typeToParentItem.value(sqlb::Object::typeToString(it->type())), it, schema);
314314

315315
// If it is a table or view add the field nodes, add an extra node for the browsable section
316-
if((*it)->type() == sqlb::Object::Types::Table || (*it)->type() == sqlb::Object::Types::View)
317-
addNode(browsablesRootItem, *it, schema);
316+
if(it->type() == sqlb::Object::Types::Table || it->type() == sqlb::Object::Types::View)
317+
addNode(browsablesRootItem, it, schema);
318318

319319
// Add field nodes if there are any
320-
sqlb::FieldInfoList fieldList = (*it)->fieldInformation();
320+
sqlb::FieldInfoList fieldList = it->fieldInformation();
321321
if(!fieldList.empty())
322322
{
323323
QStringList pk_columns;
324-
if((*it)->type() == sqlb::Object::Types::Table)
324+
if(it->type() == sqlb::Object::Types::Table)
325325
{
326-
sqlb::FieldVector pk = (*it).dynamicCast<sqlb::Table>()->primaryKey();
326+
sqlb::FieldVector pk = it.dynamicCast<sqlb::Table>()->primaryKey();
327327
for(const sqlb::FieldPtr& pk_col : pk)
328328
pk_columns.push_back(pk_col->name());
329329

src/EditIndexDialog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ EditIndexDialog::EditIndexDialog(DBBrowserDB& db, const sqlb::ObjectIdentifier&
3333
}
3434
} else { // If this is an existing index, only offer tables of the current database schema
3535
QList<sqlb::ObjectPtr> tables = pdb.schemata[curIndex.schema()].values("table");
36-
for(auto it=tables.constBegin();it!=tables.constEnd();++it)
36+
for(auto it : tables)
3737
{
3838
// Only show the schema name for non-main schemata
39-
sqlb::ObjectIdentifier obj(curIndex.schema(), (*it)->name());
39+
sqlb::ObjectIdentifier obj(curIndex.schema(), it->name());
4040
dbobjs.insert(obj.toDisplayString(), obj);
4141
}
4242
}

src/MainWindow.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,11 +427,11 @@ void MainWindow::populateStructure(const QString& old_table)
427427
for(auto it=db.schemata.constBegin();it!=db.schemata.constEnd();++it)
428428
{
429429
objectMap tab = db.getBrowsableObjects(it.key());
430-
for(auto it=tab.constBegin();it!=tab.constEnd();++it)
430+
for(auto it : tab)
431431
{
432-
QString objectname = (*it)->name();
432+
QString objectname = it->name();
433433

434-
sqlb::FieldInfoList fi = (*it)->fieldInformation();
434+
sqlb::FieldInfoList fi = it->fieldInformation();
435435
for(const sqlb::FieldInfo& f : fi)
436436
tablesToColumnsMap[objectname].append(f.name);
437437
}

src/sqlitedb.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,16 +1205,16 @@ bool DBBrowserDB::alterTable(const sqlb::ObjectIdentifier& tablename, const sqlb
12051205

12061206
// Save all indices, triggers and views associated with this table because SQLite deletes them when we drop the table in the next step
12071207
QStringList otherObjectsSql;
1208-
for(auto it=schemata[tablename.schema()].constBegin();it!=schemata[tablename.schema()].constEnd();++it)
1208+
for(auto it : schemata[tablename.schema()])
12091209
{
12101210
// If this object references the table and it's not the table itself save it's SQL string
1211-
if((*it)->baseTable() == tablename.name() && (*it)->type() != sqlb::Object::Types::Table)
1211+
if(it->baseTable() == tablename.name() && it->type() != sqlb::Object::Types::Table)
12121212
{
12131213
// If this is an index, update the fields first. This highly increases the chance that the SQL statement won't throw an
12141214
// error later on when we try to recreate it.
1215-
if((*it)->type() == sqlb::Object::Types::Index)
1215+
if(it->type() == sqlb::Object::Types::Index)
12161216
{
1217-
sqlb::IndexPtr idx = (*it).dynamicCast<sqlb::Index>();
1217+
sqlb::IndexPtr idx = it.dynamicCast<sqlb::Index>();
12181218

12191219
// Are we updating a field name or are we removing a field entirely?
12201220
if(to)
@@ -1238,7 +1238,7 @@ bool DBBrowserDB::alterTable(const sqlb::ObjectIdentifier& tablename, const sqlb
12381238
} else {
12391239
// If it's a view or a trigger we don't have any chance to corrections yet. Just store the statement as is and
12401240
// hope for the best.
1241-
otherObjectsSql << (*it)->originalSql().trimmed() + ";";
1241+
otherObjectsSql << it->originalSql().trimmed() + ";";
12421242
}
12431243
}
12441244
}
@@ -1352,10 +1352,10 @@ objectMap DBBrowserDB::getBrowsableObjects(const QString& schema) const
13521352

13531353
const sqlb::ObjectPtr DBBrowserDB::getObjectByName(const sqlb::ObjectIdentifier& name) const
13541354
{
1355-
for(auto it=schemata[name.schema()].constBegin();it!=schemata[name.schema()].constEnd();++it)
1355+
for(auto it : schemata[name.schema()])
13561356
{
1357-
if((*it)->name() == name.name())
1358-
return *it;
1357+
if(it->name() == name.name())
1358+
return it;
13591359
}
13601360
return sqlb::ObjectPtr(nullptr);
13611361
}

0 commit comments

Comments
 (0)