mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
Simplify code
This simplifies some of the super long iterator declarations by using the auto keyword from C++11.
This commit is contained in:
@@ -16,9 +16,9 @@ CreateIndexDialog::CreateIndexDialog(DBBrowserDB* db, QWidget* parent)
|
||||
// Get list of tables, sort it alphabetically and fill the combobox
|
||||
QMultiMap<QString, DBBrowserObject> dbobjs;
|
||||
QList<DBBrowserObject> tables = pdb->objMap.values("table");
|
||||
for(QList<DBBrowserObject>::ConstIterator it=tables.begin();it!=tables.end();++it)
|
||||
for(auto it=tables.constBegin();it!=tables.constEnd();++it)
|
||||
dbobjs.insert((*it).getname(), (*it));
|
||||
for(QMultiMap<QString, DBBrowserObject>::ConstIterator it=dbobjs.begin(); it != dbobjs.end(); ++it)
|
||||
for(auto it=dbobjs.constBegin();it!=dbobjs.constEnd();++it)
|
||||
ui->comboTableName->addItem(QIcon(QString(":icons/table")), (*it).getname());
|
||||
|
||||
QHeaderView *tableHeaderView = ui->tableIndexColumns->horizontalHeader();
|
||||
|
||||
@@ -171,11 +171,11 @@ void DbStructureModel::reloadData()
|
||||
|
||||
// Get all database objects and sort them by their name
|
||||
QMultiMap<QString, DBBrowserObject> dbobjs;
|
||||
for(objectMap::ConstIterator it=m_db.objMap.begin(); it != m_db.objMap.end(); ++it)
|
||||
for(auto it=m_db.objMap.constBegin(); it != m_db.objMap.constEnd(); ++it)
|
||||
dbobjs.insert((*it).getname(), (*it));
|
||||
|
||||
// Add the actual table objects
|
||||
for(QMultiMap<QString, DBBrowserObject>::ConstIterator it=dbobjs.begin(); it != dbobjs.end(); ++it)
|
||||
for(auto it=dbobjs.constBegin();it!=dbobjs.constEnd();++it)
|
||||
{
|
||||
// Object node
|
||||
QTreeWidgetItem* item = addNode(typeToParentItem.value((*it).gettype()), *it);
|
||||
|
||||
@@ -29,8 +29,8 @@ ExportSqlDialog::ExportSqlDialog(DBBrowserDB* db, QWidget* parent, const QString
|
||||
|
||||
// Get list of tables to export
|
||||
objectMap objects = pdb->getBrowsableObjects();
|
||||
for(objectMap::ConstIterator i=objects.begin();i!=objects.end();++i) {
|
||||
ui->listTables->addItem(new QListWidgetItem(QIcon(QString(":icons/%1").arg(i.value().gettype())), i.value().getname()));
|
||||
for(auto it=objects.constBegin();it!=objects.constEnd();++it) {
|
||||
ui->listTables->addItem(new QListWidgetItem(QIcon(QString(":icons/%1").arg(it.value().gettype())), it.value().getname()));
|
||||
}
|
||||
|
||||
// Sort list of tables and select the table specified in the
|
||||
|
||||
@@ -184,11 +184,11 @@ void ImportCsvDialog::accept()
|
||||
// Are we importing into an existing table?
|
||||
bool importToExistingTable = false;
|
||||
objectMap objects = pdb->getBrowsableObjects();
|
||||
for(objectMap::ConstIterator i=objects.begin();i!=objects.end();++i)
|
||||
for(auto it=objects.constBegin();it!=objects.constEnd();++it)
|
||||
{
|
||||
if(i.value().gettype() == "table" && i.value().getname() == ui->editName->text())
|
||||
if(it.value().gettype() == "table" && it.value().getname() == ui->editName->text())
|
||||
{
|
||||
if((size_t)i.value().table.fields().size() != csv.columns())
|
||||
if((size_t)it.value().table.fields().size() != csv.columns())
|
||||
{
|
||||
QMessageBox::warning(this, QApplication::applicationName(),
|
||||
tr("There is already a table of that name and an import into an existing table is only possible if the number of columns match."));
|
||||
|
||||
@@ -365,7 +365,7 @@ void MainWindow::populateStructure()
|
||||
// Update table and column names for syntax highlighting
|
||||
objectMap tab = db.getBrowsableObjects();
|
||||
SqlUiLexer::TablesAndColumnsMap tablesToColumnsMap;
|
||||
for(objectMap::ConstIterator it=tab.begin(); it!=tab.end(); ++it)
|
||||
for(auto it=tab.constBegin();it!=tab.constEnd();++it)
|
||||
{
|
||||
QString objectname = it.value().getname();
|
||||
|
||||
@@ -422,8 +422,7 @@ void MainWindow::populateTable()
|
||||
connect(ui->dataTable->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(dataTableSelectionChanged(QModelIndex)));
|
||||
|
||||
// Search stored table settings for this table
|
||||
QMap<QString, BrowseDataTableSettings>::ConstIterator tableIt;
|
||||
tableIt = browseTableSettings.constFind(tablename);
|
||||
auto tableIt = browseTableSettings.constFind(tablename);
|
||||
bool storedDataFound = tableIt != browseTableSettings.constEnd();
|
||||
|
||||
// Set new table
|
||||
@@ -460,7 +459,7 @@ void MainWindow::populateTable()
|
||||
showRowidColumn(tableIt.value().showRowid);
|
||||
|
||||
// Column widths
|
||||
for(QMap<int, int>::ConstIterator widthIt=tableIt.value().columnWidths.constBegin();widthIt!=tableIt.value().columnWidths.constEnd();++widthIt)
|
||||
for(auto widthIt=tableIt.value().columnWidths.constBegin();widthIt!=tableIt.value().columnWidths.constEnd();++widthIt)
|
||||
ui->dataTable->setColumnWidth(widthIt.key(), widthIt.value());
|
||||
|
||||
// Sorting
|
||||
@@ -469,7 +468,7 @@ void MainWindow::populateTable()
|
||||
|
||||
// Filters
|
||||
FilterTableHeader* filterHeader = qobject_cast<FilterTableHeader*>(ui->dataTable->horizontalHeader());
|
||||
for(QMap<int, QString>::ConstIterator filterIt=tableIt.value().filterValues.constBegin();filterIt!=tableIt.value().filterValues.constEnd();++filterIt)
|
||||
for(auto filterIt=tableIt.value().filterValues.constBegin();filterIt!=tableIt.value().filterValues.constEnd();++filterIt)
|
||||
filterHeader->setFilter(filterIt.key(), filterIt.value());
|
||||
|
||||
// Encoding
|
||||
@@ -1833,7 +1832,7 @@ void MainWindow::updatePlot(SqliteTableModel *model, bool update, bool keepOrRes
|
||||
sItemX = browseTableSettings[ui->comboBrowseTable->currentText()].plotXAxis;
|
||||
|
||||
QMap<QString, PlotSettings> axesY = browseTableSettings[ui->comboBrowseTable->currentText()].plotYAxes;
|
||||
QMap<QString, PlotSettings>::ConstIterator it = axesY.constBegin();
|
||||
auto it = axesY.constBegin();
|
||||
while(it != axesY.constEnd())
|
||||
{
|
||||
mapItemsY.insert(it.key(), it.value().colour);
|
||||
@@ -2508,7 +2507,7 @@ void MainWindow::on_comboLineType_currentIndexChanged(int index)
|
||||
|
||||
// Save settings for this table
|
||||
QMap<QString, PlotSettings>& graphs = browseTableSettings[ui->comboBrowseTable->currentText()].plotYAxes;
|
||||
QMap<QString, PlotSettings>::Iterator it = graphs.begin();
|
||||
auto it = graphs.begin();
|
||||
while(it != graphs.end())
|
||||
{
|
||||
it.value().lineStyle = lineStyle;
|
||||
@@ -2533,7 +2532,7 @@ void MainWindow::on_comboPointShape_currentIndexChanged(int index)
|
||||
|
||||
// Save settings for this table
|
||||
QMap<QString, PlotSettings>& graphs = browseTableSettings[ui->comboBrowseTable->currentText()].plotYAxes;
|
||||
QMap<QString, PlotSettings>::Iterator it = graphs.begin();
|
||||
auto it = graphs.begin();
|
||||
while(it != graphs.end())
|
||||
{
|
||||
it.value().pointShape = shape;
|
||||
@@ -2691,7 +2690,7 @@ void MainWindow::browseDataSetTableEncoding(bool forAllTables)
|
||||
{
|
||||
defaultBrowseTableEncoding = encoding;
|
||||
|
||||
for(QMap<QString, BrowseDataTableSettings>::Iterator it=browseTableSettings.begin();it!=browseTableSettings.end();++it)
|
||||
for(auto it=browseTableSettings.begin();it!=browseTableSettings.end();++it)
|
||||
it.value().encoding = encoding;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ QHash<QString, QVariant> Settings::m_hCache;
|
||||
QVariant Settings::getSettingsValue(const QString& group, const QString& name)
|
||||
{
|
||||
// Have a look in the cache first
|
||||
QHash<QString, QVariant>::iterator cacheIndex = m_hCache.find(group + name);
|
||||
auto cacheIndex = m_hCache.find(group + name);
|
||||
if(cacheIndex != m_hCache.end())
|
||||
{
|
||||
return cacheIndex.value();
|
||||
|
||||
@@ -132,7 +132,7 @@ void SqlUiLexer::setTableNames(const TablesAndColumnsMap& tables)
|
||||
autocompleteApi->clear();
|
||||
listTables.clear();
|
||||
setupAutoCompletion();
|
||||
for(TablesAndColumnsMap::ConstIterator it=tables.constBegin();it!=tables.constEnd();++it)
|
||||
for(auto it=tables.constBegin();it!=tables.constEnd();++it)
|
||||
{
|
||||
foreach(const QString& field, it.value())
|
||||
autocompleteApi->add(it.key() + "?" + QString::number(SqlUiLexer::ApiCompleterIconIdTable) + "." +
|
||||
|
||||
@@ -475,7 +475,7 @@ bool DBBrowserDB::dump(const QString& filename,
|
||||
stream << "BEGIN TRANSACTION;\n";
|
||||
|
||||
// Loop through all tables first as they are required to generate views, indices etc. later
|
||||
for(QList<DBBrowserObject>::ConstIterator it=tables.begin();it!=tables.end();++it)
|
||||
for(auto it=tables.constBegin();it!=tables.constEnd();++it)
|
||||
{
|
||||
if (tablesToDump.indexOf(it->getTableName()) == -1)
|
||||
continue;
|
||||
@@ -577,7 +577,7 @@ bool DBBrowserDB::dump(const QString& filename,
|
||||
// Now dump all the other objects (but only if we are exporting the schema)
|
||||
if(exportSchema)
|
||||
{
|
||||
for(objectMap::ConstIterator it=objMap.begin();it!=objMap.end();++it)
|
||||
for(auto it=objMap.constBegin();it!=objMap.constEnd();++it)
|
||||
{
|
||||
// Make sure it's not a table again
|
||||
if(it.value().gettype() == "table")
|
||||
@@ -1048,7 +1048,7 @@ bool DBBrowserDB::renameColumn(const QString& tablename, const QString& name, sq
|
||||
|
||||
// Save all indices, triggers and views associated with this table because SQLite deletes them when we drop the table in the next step
|
||||
QString otherObjectsSql;
|
||||
for(objectMap::ConstIterator it=objMap.begin();it!=objMap.end();++it)
|
||||
for(auto it=objMap.constBegin();it!=objMap.constEnd();++it)
|
||||
{
|
||||
// If this object references the table and it's not the table itself save it's SQL string
|
||||
if((*it).getTableName() == tablename && (*it).gettype() != "table")
|
||||
@@ -1122,10 +1122,9 @@ bool DBBrowserDB::renameTable(const QString& from_table, const QString& to_table
|
||||
|
||||
objectMap DBBrowserDB::getBrowsableObjects() const
|
||||
{
|
||||
objectMap::ConstIterator it;
|
||||
objectMap res;
|
||||
|
||||
for(it=objMap.begin();it!=objMap.end();++it)
|
||||
for(auto it=objMap.constBegin();it!=objMap.constEnd();++it)
|
||||
{
|
||||
if(it.key() == "table" || it.key() == "view")
|
||||
res.insert(it.key(), it.value());
|
||||
@@ -1136,7 +1135,7 @@ objectMap DBBrowserDB::getBrowsableObjects() const
|
||||
|
||||
DBBrowserObject DBBrowserDB::getObjectByName(const QString& name) const
|
||||
{
|
||||
for (objectMap::ConstIterator it = objMap.begin(); it != objMap.end(); ++it )
|
||||
for(auto it=objMap.constBegin();it!=objMap.constEnd();++it)
|
||||
{
|
||||
if((*it).getname() == name)
|
||||
return *it;
|
||||
|
||||
@@ -355,7 +355,7 @@ FieldVector& Table::primaryKeyRef()
|
||||
|
||||
const FieldVector& Table::primaryKey() const
|
||||
{
|
||||
ConstraintMap::ConstIterator it = m_constraints.constBegin();
|
||||
auto it = m_constraints.constBegin();
|
||||
while(it != m_constraints.constEnd())
|
||||
{
|
||||
if(it.value()->type() == Constraint::PrimaryKeyConstraintType)
|
||||
|
||||
Reference in New Issue
Block a user