Skip to content

Commit b803e3c

Browse files
committed
Use more STL containers instead of Qt containers
1 parent a0624b0 commit b803e3c

17 files changed

+87
-80
lines changed

src/Application.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Application::Application(int& argc, char** argv) :
136136
value = option.at(1).split(",");
137137
else
138138
value = option.at(1);
139-
Settings::setValue(setting.at(0), setting.at(1), value, !saveToDisk);
139+
Settings::setValue(setting.at(0).toStdString(), setting.at(1).toStdString(), value, !saveToDisk);
140140
}
141141
}
142142
}

src/ColumnDisplayFormatDialog.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,11 @@ ColumnDisplayFormatDialog::ColumnDisplayFormatDialog(DBBrowserDB& db, const sqlb
6363
} else {
6464
// When it doesn't match any predefined format, it is considered custom
6565
QString formatName = "custom";
66-
for(auto& formatKey : formatFunctions.keys()) {
67-
if(current_format == formatFunctions.value(formatKey)) {
68-
formatName = formatKey;
69-
break;
70-
}
71-
}
66+
auto it = std::find_if(formatFunctions.begin(), formatFunctions.end(), [current_format](const std::pair<std::string, QString>& s) {
67+
return s.second == current_format;
68+
});
69+
if(it != formatFunctions.end())
70+
formatName = QString::fromStdString(it->first);
7271
ui->comboDisplayFormat->setCurrentIndex(ui->comboDisplayFormat->findData(formatName));
7372
ui->editDisplayFormat->setText(current_format);
7473
}
@@ -89,12 +88,12 @@ QString ColumnDisplayFormatDialog::selectedDisplayFormat() const
8988

9089
void ColumnDisplayFormatDialog::updateSqlCode()
9190
{
92-
QString format = ui->comboDisplayFormat->currentData().toString();
91+
std::string format = ui->comboDisplayFormat->currentData().toString().toStdString();
9392

9493
if(format == "default")
9594
ui->editDisplayFormat->setText(sqlb::escapeIdentifier(column_name));
9695
else if(format != "custom")
97-
ui->editDisplayFormat->setText(formatFunctions.value(format));
96+
ui->editDisplayFormat->setText(formatFunctions.at(format));
9897
}
9998

10099
void ColumnDisplayFormatDialog::accept()

src/ColumnDisplayFormatDialog.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
#define COLUMNDISPLAYFORMATDIALOG_H
33

44
#include <QDialog>
5-
#include <QMap>
5+
6+
#include <unordered_map>
67

78
#include "sql/ObjectIdentifier.h"
89

@@ -32,7 +33,7 @@ private slots:
3233
private:
3334
Ui::ColumnDisplayFormatDialog* ui;
3435
QString column_name;
35-
QMap<QString, QString> formatFunctions;
36+
std::unordered_map<std::string, QString> formatFunctions;
3637
DBBrowserDB& pdb;
3738
sqlb::ObjectIdentifier curTable;
3839
};

src/DbStructureModel.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <QMimeData>
88
#include <QMessageBox>
99
#include <QApplication>
10+
#include <unordered_map>
1011

1112
DbStructureModel::DbStructureModel(DBBrowserDB& db, QObject* parent)
1213
: QAbstractItemModel(parent),
@@ -303,7 +304,7 @@ bool DbStructureModel::dropMimeData(const QMimeData* data, Qt::DropAction action
303304
void DbStructureModel::buildTree(QTreeWidgetItem* parent, const std::string& schema)
304305
{
305306
// Build a map from object type to tree node to simplify finding the correct tree node later
306-
QMap<std::string, QTreeWidgetItem*> typeToParentItem;
307+
std::unordered_map<std::string, QTreeWidgetItem*> typeToParentItem;
307308

308309
// Get object map for the given schema
309310
objectMap objmap = m_db.schemata[schema];
@@ -312,22 +313,22 @@ void DbStructureModel::buildTree(QTreeWidgetItem* parent, const std::string& sch
312313
QTreeWidgetItem* itemTables = new QTreeWidgetItem(parent);
313314
itemTables->setIcon(ColumnName, QIcon(QString(":/icons/table")));
314315
itemTables->setText(ColumnName, tr("Tables (%1)").arg(objmap.values("table").count()));
315-
typeToParentItem.insert("table", itemTables);
316+
typeToParentItem.insert({"table", itemTables});
316317

317318
QTreeWidgetItem* itemIndices = new QTreeWidgetItem(parent);
318319
itemIndices->setIcon(ColumnName, QIcon(QString(":/icons/index")));
319320
itemIndices->setText(ColumnName, tr("Indices (%1)").arg(objmap.values("index").count()));
320-
typeToParentItem.insert("index", itemIndices);
321+
typeToParentItem.insert({"index", itemIndices});
321322

322323
QTreeWidgetItem* itemViews = new QTreeWidgetItem(parent);
323324
itemViews->setIcon(ColumnName, QIcon(QString(":/icons/view")));
324325
itemViews->setText(ColumnName, tr("Views (%1)").arg(objmap.values("view").count()));
325-
typeToParentItem.insert("view", itemViews);
326+
typeToParentItem.insert({"view", itemViews});
326327

327328
QTreeWidgetItem* itemTriggers = new QTreeWidgetItem(parent);
328329
itemTriggers->setIcon(ColumnName, QIcon(QString(":/icons/trigger")));
329330
itemTriggers->setText(ColumnName, tr("Triggers (%1)").arg(objmap.values("trigger").count()));
330-
typeToParentItem.insert("trigger", itemTriggers);
331+
typeToParentItem.insert({"trigger", itemTriggers});
331332

332333
// Get all database objects and sort them by their name
333334
QMultiMap<std::string, sqlb::ObjectPtr> dbobjs;
@@ -338,7 +339,7 @@ void DbStructureModel::buildTree(QTreeWidgetItem* parent, const std::string& sch
338339
for(auto it : dbobjs)
339340
{
340341
// Object node
341-
QTreeWidgetItem* item = addNode(typeToParentItem.value(sqlb::Object::typeToString(it->type())), it, schema);
342+
QTreeWidgetItem* item = addNode(typeToParentItem.at(sqlb::Object::typeToString(it->type())), it, schema);
342343

343344
// If it is a table or view add the field nodes, add an extra node for the browsable section
344345
if(it->type() == sqlb::Object::Types::Table || it->type() == sqlb::Object::Types::View)

src/EditIndexDialog.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ EditIndexDialog::EditIndexDialog(DBBrowserDB& db, const sqlb::ObjectIdentifier&
1919
ui->sqlTextEdit->setReadOnly(true);
2020

2121
// Get list of tables, sort it alphabetically and fill the combobox
22-
QMap<std::string, sqlb::ObjectIdentifier> dbobjs; // Map from display name to full object identifier
22+
std::map<std::string, sqlb::ObjectIdentifier> dbobjs; // Map from display name to full object identifier
2323
if(newIndex) // If this is a new index, offer all tables of all database schemata
2424
{
2525
for(auto it=pdb.schemata.constBegin();it!=pdb.schemata.constEnd();++it)
@@ -29,7 +29,7 @@ EditIndexDialog::EditIndexDialog(DBBrowserDB& db, const sqlb::ObjectIdentifier&
2929
{
3030
// Only show the schema name for non-main schemata
3131
sqlb::ObjectIdentifier obj(it.key(), (*jt)->name());
32-
dbobjs.insert(obj.toDisplayString(), obj);
32+
dbobjs.insert({obj.toDisplayString(), obj});
3333
}
3434
}
3535
} else { // If this is an existing index, only offer tables of the current database schema
@@ -38,12 +38,12 @@ EditIndexDialog::EditIndexDialog(DBBrowserDB& db, const sqlb::ObjectIdentifier&
3838
{
3939
// Only show the schema name for non-main schemata
4040
sqlb::ObjectIdentifier obj(curIndex.schema(), it->name());
41-
dbobjs.insert(obj.toDisplayString(), obj);
41+
dbobjs.insert({obj.toDisplayString(), obj});
4242
}
4343
}
4444
ui->comboTableName->blockSignals(true);
45-
for(auto it=dbobjs.constBegin();it!=dbobjs.constEnd();++it)
46-
ui->comboTableName->addItem(QIcon(QString(":icons/table")), QString::fromStdString(it.key()), QString::fromStdString(it.value().toSerialised()));
45+
for(auto it=dbobjs.cbegin();it!=dbobjs.cend();++it)
46+
ui->comboTableName->addItem(QIcon(QString(":icons/table")), QString::fromStdString(it->first), QString::fromStdString(it->second.toSerialised()));
4747
ui->comboTableName->blockSignals(false);
4848

4949
QHeaderView *tableHeaderView = ui->tableIndexColumns->horizontalHeader();

src/EditTableDialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ void EditTableDialog::checkInput()
277277
if (normTableName != m_table.name()) {
278278
const std::string oldTableName = m_table.name();
279279
m_table.setName(normTableName);
280-
m_fkEditorDelegate->updateTablesList(QString::fromStdString(oldTableName));
280+
m_fkEditorDelegate->updateTablesList(oldTableName);
281281

282282
// update fk's that refer to table itself recursively
283283
const auto& fields = m_table.fields;

src/ExtendedScintilla.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void ExtendedScintilla::dropEvent(QDropEvent* e)
111111
f.close();
112112
}
113113

114-
void ExtendedScintilla::setupSyntaxHighlightingFormat(QsciLexer *lexer, const QString& settings_name, int style)
114+
void ExtendedScintilla::setupSyntaxHighlightingFormat(QsciLexer* lexer, const std::string& settings_name, int style)
115115
{
116116
lexer->setColor(QColor(Settings::getValue("syntaxhighlighter", settings_name + "_colour").toString()), style);
117117

src/ExtendedScintilla.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public slots:
4242
protected:
4343
void dropEvent(QDropEvent* e) override;
4444

45-
void setupSyntaxHighlightingFormat(QsciLexer *lexer, const QString& settings_name, int style);
45+
void setupSyntaxHighlightingFormat(QsciLexer* lexer, const std::string& settings_name, int style);
4646
void reloadLexerSettings(QsciLexer *lexer);
4747
void reloadCommonSettings();
4848

src/ExtendedTableWidget.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ UniqueFilterModel::UniqueFilterModel(QObject* parent)
110110
bool UniqueFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
111111
{
112112
QModelIndex index = sourceModel()->index(sourceRow, filterKeyColumn(), sourceParent);
113-
const QString& value = index.data(Qt::EditRole).toString();
113+
const std::string value = index.data(Qt::EditRole).toString().toStdString();
114114

115-
if (!value.isEmpty() && !m_uniqueValues.contains(value)) {
115+
if (!value.empty() && m_uniqueValues.find(value) == m_uniqueValues.end()) {
116116
const_cast<UniqueFilterModel*>(this)->m_uniqueValues.insert(value);
117117
return true;
118118
}
@@ -834,7 +834,7 @@ void ExtendedTableWidget::vscrollbarChanged(int value)
834834
}
835835
}
836836

837-
int ExtendedTableWidget::numVisibleRows()
837+
int ExtendedTableWidget::numVisibleRows() const
838838
{
839839
// Get the row numbers of the rows currently visible at the top and the bottom of the widget
840840
int row_top = rowAt(0) == -1 ? 0 : rowAt(0);
@@ -844,9 +844,9 @@ int ExtendedTableWidget::numVisibleRows()
844844
return row_bottom - row_top;
845845
}
846846

847-
QSet<int> ExtendedTableWidget::selectedCols()
847+
std::unordered_set<int> ExtendedTableWidget::selectedCols() const
848848
{
849-
QSet<int> selectedCols;
849+
std::unordered_set<int> selectedCols;
850850
for(const QModelIndex & idx : selectedIndexes())
851851
selectedCols.insert(idx.column());
852852
return selectedCols;

src/ExtendedTableWidget.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
#define EXTENDEDTABLEWIDGET_H
33

44
#include <QTableView>
5-
#include <QSet>
65
#include <QStyledItemDelegate>
76
#include <QSortFilterProxyModel>
7+
#include <unordered_set>
88

99
#include "sql/Query.h"
1010

@@ -25,7 +25,7 @@ class UniqueFilterModel : public QSortFilterProxyModel
2525
explicit UniqueFilterModel(QObject* parent = nullptr);
2626
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
2727
private:
28-
QSet<QString> m_uniqueValues;
28+
std::unordered_set<std::string> m_uniqueValues;
2929
};
3030

3131
// We use this class to provide editor widgets for the ExtendedTableWidget. It's used for every cell in the table view.
@@ -52,8 +52,8 @@ class ExtendedTableWidget : public QTableView
5252
FilterTableHeader* filterHeader() { return m_tableHeader; }
5353

5454
public:
55-
QSet<int> selectedCols();
56-
int numVisibleRows();
55+
std::unordered_set<int> selectedCols() const;
56+
int numVisibleRows() const;
5757

5858
void sortByColumns(const std::vector<sqlb::SortedColumn>& columns);
5959

0 commit comments

Comments
 (0)