Skip to content

Commit 329c07e

Browse files
committed
Fix a ton of warnings from clang, clazy, cppcheck, etc.
1 parent 3e06b2e commit 329c07e

36 files changed

+764
-774
lines changed

src/AboutDialog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class AboutDialog : public QDialog
1313

1414
public:
1515
explicit AboutDialog(QWidget *parent = nullptr);
16-
~AboutDialog();
16+
~AboutDialog() override;
1717

1818
private:
1919
Ui::AboutDialog *ui;

src/AddRecordDialog.cpp

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <QLineEdit>
1212
#include <QMenu>
1313

14+
namespace {
15+
1416
class NullLineEdit: public QLineEdit {
1517
Q_OBJECT
1618
private:
@@ -33,23 +35,24 @@ class NullLineEdit: public QLineEdit {
3335
m_isNull = value;
3436
}
3537
protected:
36-
void contextMenuEvent(QContextMenuEvent *event)
37-
{
38-
QMenu* editContextMenu = createStandardContextMenu();
39-
40-
QAction* nullAction = new QAction(QIcon(":/icons/set_to_null"), tr("Set to NULL"), editContextMenu);
41-
connect(nullAction, &QAction::triggered, [&]() {
42-
setNull(true);
43-
});
44-
nullAction->setShortcut(QKeySequence(tr("Alt+Del")));
45-
editContextMenu->addSeparator();
46-
editContextMenu->addAction(nullAction);
47-
48-
editContextMenu->exec(event->globalPos());
49-
delete editContextMenu;
50-
}
38+
void contextMenuEvent(QContextMenuEvent *event) override
39+
{
40+
QMenu* editContextMenu = createStandardContextMenu();
5141

52-
void keyPressEvent(QKeyEvent *evt) {
42+
QAction* nullAction = new QAction(QIcon(":/icons/set_to_null"), tr("Set to NULL"), editContextMenu);
43+
connect(nullAction, &QAction::triggered, nullAction, [&]() {
44+
setNull(true);
45+
});
46+
nullAction->setShortcut(QKeySequence(tr("Alt+Del")));
47+
editContextMenu->addSeparator();
48+
editContextMenu->addAction(nullAction);
49+
50+
editContextMenu->exec(event->globalPos());
51+
delete editContextMenu;
52+
}
53+
54+
void keyPressEvent(QKeyEvent *evt) override
55+
{
5356
// Alt+Del sets field to NULL
5457
if((evt->modifiers() & Qt::AltModifier) && (evt->key() == Qt::Key_Delete))
5558
setNull(true);
@@ -112,6 +115,9 @@ class EditDelegate: public QStyledItemDelegate {
112115
}
113116
};
114117

118+
}
119+
120+
115121
AddRecordDialog::AddRecordDialog(DBBrowserDB& db, const sqlb::ObjectIdentifier& tableName, QWidget* parent, const std::vector<std::string>& _pseudo_pk)
116122
: QDialog(parent),
117123
ui(new Ui::AddRecordDialog),
@@ -188,8 +194,10 @@ void AddRecordDialog::populateFields()
188194
{
189195
sqlb::TablePtr m_table = pdb.getObjectByName<sqlb::Table>(curTable);
190196
fields = m_table->fields;
191-
for(const sqlb::Field& f : fields)
192-
fks.push_back(m_table->constraint({f.name()}, sqlb::Constraint::ForeignKeyConstraintType));
197+
198+
std::transform(fields.begin(), fields.end(), std::back_inserter(fks), [m_table](const auto& f) {
199+
return m_table->constraint({f.name()}, sqlb::Constraint::ForeignKeyConstraintType);
200+
});
193201

194202
const auto pk_constraint = m_table->primaryKey();
195203
if(pk_constraint)

src/CondFormat.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ std::string CondFormat::filterToSqlCondition(const QString& value, const QString
9999
op = value.left(2);
100100
val = value.mid(2);
101101
}
102-
} else if(value.left(1) == ">" || value.left(1) == "<") {
102+
} else if(value.front() == '>' || value.front() == '<') {
103103
value.midRef(1).toFloat(&numeric);
104104
op = value.at(0);
105105
val = value.mid(1);
106-
} else if(value.left(1) == "=") {
106+
} else if(value.front() == '=') {
107107
val = value.mid(1);
108108

109109
// Check if value to compare with is 'NULL'
@@ -117,7 +117,7 @@ std::string CondFormat::filterToSqlCondition(const QString& value, const QString
117117
op = "IS";
118118
numeric = true;
119119
}
120-
} else if(value.left(1) == "/" && value.right(1) == "/" && value.size() > 2) {
120+
} else if(value.front() == '/' && value.back() == '/' && value.size() > 2) {
121121
val = value.mid(1, value.length() - 2);
122122
op = "REGEXP";
123123
numeric = false;

src/DbStructureModel.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,16 +225,16 @@ QMimeData* DbStructureModel::mimeData(const QModelIndexList& indices) const
225225

226226
// For names, export a (qualified) (escaped) identifier of the item for statement composition in SQL editor.
227227
if(objectType == "field")
228-
namesData.append(getNameForDropping(item->text(ColumnSchema), item->parent()->text(ColumnName), item->text(ColumnName)));
228+
namesData.append(getNameForDropping(item->text(ColumnSchema), item->parent()->text(ColumnName), item->text(ColumnName)).toUtf8());
229229
else if(objectType == "database")
230-
namesData.append(getNameForDropping(item->text(ColumnName), "", ""));
230+
namesData.append(getNameForDropping(item->text(ColumnName), "", "").toUtf8());
231231
else if(!objectType.isEmpty())
232-
namesData.append(getNameForDropping(item->text(ColumnSchema), item->text(ColumnName), ""));
232+
namesData.append(getNameForDropping(item->text(ColumnSchema), item->text(ColumnName), "").toUtf8());
233233

234234
if(objectType != "field" && index.column() == ColumnSQL)
235235
{
236236
// Add the SQL code used to create the object
237-
sqlData.append(data(index, Qt::DisplayRole).toString() + ";\n");
237+
sqlData.append(data(index, Qt::DisplayRole).toByteArray() + ";\n");
238238

239239
// If it is a table also add the content
240240
if(objectType == "table")
@@ -254,7 +254,7 @@ QMimeData* DbStructureModel::mimeData(const QModelIndexList& indices) const
254254
insertStatement += QString("'%1',").arg(tableModel.data(tableModel.index(i, j), Qt::EditRole).toString());
255255
insertStatement.chop(1);
256256
insertStatement += ");\n";
257-
sqlData.append(insertStatement);
257+
sqlData.append(insertStatement.toUtf8());
258258
}
259259
}
260260
}

src/EditDialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ void EditDialog::openPrintDialog()
11661166
QPrinter printer;
11671167
QPrintPreviewDialog *dialog = new QPrintPreviewDialog(&printer);
11681168

1169-
connect(dialog, &QPrintPreviewDialog::paintRequested, [this](QPrinter *previewPrinter) {
1169+
connect(dialog, &QPrintPreviewDialog::paintRequested, this, [this](QPrinter *previewPrinter) {
11701170
QTextDocument document;
11711171
switch (dataSource) {
11721172
case SciBuffer:

src/EditIndexDialog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ EditIndexDialog::EditIndexDialog(DBBrowserDB& db, const sqlb::ObjectIdentifier&
7575
}
7676

7777
// Add event handler for index column name changes. These are only allowed for expression columns, though.
78-
connect(ui->tableIndexColumns, &QTableWidget::itemChanged,
78+
connect(ui->tableIndexColumns, &QTableWidget::itemChanged, this,
7979
[=](QTableWidgetItem* item)
8080
{
8181
index.fields[static_cast<size_t>(item->row())].setName(item->text().toStdString());
@@ -166,7 +166,7 @@ void EditIndexDialog::updateColumnLists()
166166
order->addItem("DESC");
167167
order->setCurrentText(QString::fromStdString(indexFields.at(i).order()).toUpper());
168168
ui->tableIndexColumns->setCellWidget(static_cast<int>(i), 1, order);
169-
connect(order, &QComboBox::currentTextChanged,
169+
connect(order, &QComboBox::currentTextChanged, this,
170170
[=](QString new_order)
171171
{
172172
auto colnum = sqlb::findField(index, indexFields.at(i).name());

src/EditTableDialog.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ EditTableDialog::EditTableDialog(DBBrowserDB& db, const sqlb::ObjectIdentifier&
5858
constraint_menu->addAction(ui->actionAddForeignKey);
5959
constraint_menu->addAction(ui->actionAddUniqueConstraint);
6060
constraint_menu->addAction(ui->actionAddCheckConstraint);
61-
connect(ui->actionAddPrimaryKey, &QAction::triggered, [this]() { addConstraint(sqlb::Constraint::PrimaryKeyConstraintType); });
62-
connect(ui->actionAddForeignKey, &QAction::triggered, [this]() { addConstraint(sqlb::Constraint::ForeignKeyConstraintType); });
63-
connect(ui->actionAddUniqueConstraint, &QAction::triggered, [this]() { addConstraint(sqlb::Constraint::UniqueConstraintType); });
64-
connect(ui->actionAddCheckConstraint, &QAction::triggered, [this]() { addConstraint(sqlb::Constraint::CheckConstraintType); });
61+
connect(ui->actionAddPrimaryKey, &QAction::triggered, this, [this]() { addConstraint(sqlb::Constraint::PrimaryKeyConstraintType); });
62+
connect(ui->actionAddForeignKey, &QAction::triggered, this, [this]() { addConstraint(sqlb::Constraint::ForeignKeyConstraintType); });
63+
connect(ui->actionAddUniqueConstraint, &QAction::triggered, this, [this]() { addConstraint(sqlb::Constraint::UniqueConstraintType); });
64+
connect(ui->actionAddCheckConstraint, &QAction::triggered, this, [this]() { addConstraint(sqlb::Constraint::CheckConstraintType); });
6565
ui->buttonAddConstraint->setMenu(constraint_menu);
6666

6767
// Get list of all collations
@@ -106,7 +106,7 @@ EditTableDialog::EditTableDialog(DBBrowserDB& db, const sqlb::ObjectIdentifier&
106106
}
107107

108108
// Enable/disable remove constraint button depending on whether a constraint is selected
109-
connect(ui->tableConstraints, &QTableWidget::itemSelectionChanged, [this]() {
109+
connect(ui->tableConstraints, &QTableWidget::itemSelectionChanged, this, [this]() {
110110
bool hasSelection = ui->tableConstraints->selectionModel()->hasSelection();
111111
ui->buttonRemoveConstraint->setEnabled(hasSelection);
112112
});
@@ -119,7 +119,7 @@ EditTableDialog::EditTableDialog(DBBrowserDB& db, const sqlb::ObjectIdentifier&
119119
updateColumnWidth();
120120

121121
// Allow editing of constraint columns by double clicking the columns column of the constraints table
122-
connect(ui->tableConstraints, &QTableWidget::itemDoubleClicked, [this](QTableWidgetItem* item) {
122+
connect(ui->tableConstraints, &QTableWidget::itemDoubleClicked, this, [this](QTableWidgetItem* item) {
123123
// Check whether the double clicked item is in the columns column
124124
if(item->column() == kConstraintColumns)
125125
{
@@ -137,7 +137,7 @@ EditTableDialog::EditTableDialog(DBBrowserDB& db, const sqlb::ObjectIdentifier&
137137
dialog->show();
138138

139139
// When clicking the Apply button in the popup dialog, save the new columns list
140-
connect(dialog, &SelectItemsPopup::accepted, [this, dialog, constraint]() {
140+
connect(dialog, &SelectItemsPopup::accepted, this, [this, dialog, constraint]() {
141141
// Check if column selection changed at all
142142
sqlb::StringVector new_columns = dialog->selectedItems();
143143
if(constraint->columnList() != new_columns)
@@ -292,7 +292,7 @@ void EditTableDialog::populateConstraints()
292292
type->addItem(tr("Foreign Key"));
293293
type->addItem(tr("Check"));
294294
type->setCurrentIndex(constraint->type());
295-
connect(type, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [this, type, constraint](int index) {
295+
connect(type, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [this, type, constraint](int index) {
296296
// Handle change of constraint type. Effectively this means removing the old constraint and replacing it by an entirely new one.
297297
// Only the column list and the name can be migrated to the new constraint.
298298

src/ExtendedScintilla.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ void ExtendedScintilla::updateLineNumberAreaWidth()
8989

9090
// Calculate the width of this number if it was all zeros (this is because a 1 might require less space than a 0 and this could
9191
// cause some flickering depending on the font) and set the new margin width.
92+
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
9293
setMarginWidth(0, QFontMetrics(font()).width(QString("0").repeated(digits)) + 5);
94+
#else
95+
setMarginWidth(0, QFontMetrics(font()).horizontalAdvance(QString("0").repeated(digits)) + 5);
96+
#endif
9397
}
9498

9599
void ExtendedScintilla::dropEvent(QDropEvent* e)
@@ -138,8 +142,8 @@ void ExtendedScintilla::reloadCommonSettings()
138142
setMarginsForegroundColor(QPalette().color(QPalette::Active, QPalette::WindowText));
139143
break;
140144
case Settings::DarkStyle :
141-
setMarginsBackgroundColor(QColor("#32414B"));
142-
setMarginsForegroundColor(QColor("#EFF0F1"));
145+
setMarginsBackgroundColor(QColor(0x32, 0x41, 0x4B));
146+
setMarginsForegroundColor(QColor(0xEF, 0xF0, 0xF1));
143147
break;
144148
}
145149
setPaper(Settings::getValue("syntaxhighlighter", "background_colour").toString());
@@ -304,7 +308,7 @@ void ExtendedScintilla::openPrintDialog()
304308
QsciPrinter printer;
305309
QPrintPreviewDialog *dialog = new QPrintPreviewDialog(&printer);
306310

307-
connect(dialog, &QPrintPreviewDialog::paintRequested, [&](QPrinter *previewPrinter) {
311+
connect(dialog, &QPrintPreviewDialog::paintRequested, this, [&](QPrinter *previewPrinter) {
308312
QsciPrinter* sciPrinter = static_cast<QsciPrinter*>(previewPrinter);
309313
sciPrinter->printRange(this);
310314
});

src/ExtendedTableWidget.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ ExtendedTableWidget::ExtendedTableWidget(QWidget* parent) :
310310
printAction->setShortcut(QKeySequence::Print);
311311

312312
// Set up context menu actions
313-
connect(this, &QTableView::customContextMenuRequested,
313+
connect(this, &QTableView::customContextMenuRequested, this,
314314
[=](const QPoint& pos)
315315
{
316316
// Deactivate context menu options if there is no model set
@@ -338,70 +338,70 @@ ExtendedTableWidget::ExtendedTableWidget(QWidget* parent) :
338338
// Show menu
339339
m_contextMenu->popup(viewport()->mapToGlobal(pos));
340340
});
341-
connect(filterAction, &QAction::triggered, [&]() {
341+
connect(filterAction, &QAction::triggered, this, [&]() {
342342
useAsFilter(QString ("="));
343343
});
344-
connect(containingAction, &QAction::triggered, [&]() {
344+
connect(containingAction, &QAction::triggered, this, [&]() {
345345
useAsFilter(QString (""));
346346
});
347347
// Use a regular expression for the not containing filter. Simplify this if we ever support the NOT LIKE filter.
348-
connect(notContainingAction, &QAction::triggered, [&]() {
348+
connect(notContainingAction, &QAction::triggered, this, [&]() {
349349
useAsFilter(QString ("/^((?!"), /* binary */ false, QString (").)*$/"));
350350
});
351-
connect(notEqualToAction, &QAction::triggered, [&]() {
351+
connect(notEqualToAction, &QAction::triggered, this, [&]() {
352352
useAsFilter(QString ("<>"));
353353
});
354-
connect(greaterThanAction, &QAction::triggered, [&]() {
354+
connect(greaterThanAction, &QAction::triggered, this, [&]() {
355355
useAsFilter(QString (">"));
356356
});
357-
connect(lessThanAction, &QAction::triggered, [&]() {
357+
connect(lessThanAction, &QAction::triggered, this, [&]() {
358358
useAsFilter(QString ("<"));
359359
});
360-
connect(greaterEqualAction, &QAction::triggered, [&]() {
360+
connect(greaterEqualAction, &QAction::triggered, this, [&]() {
361361
useAsFilter(QString (">="));
362362
});
363-
connect(lessEqualAction, &QAction::triggered, [&]() {
363+
connect(lessEqualAction, &QAction::triggered, this, [&]() {
364364
useAsFilter(QString ("<="));
365365
});
366-
connect(inRangeAction, &QAction::triggered, [&]() {
366+
connect(inRangeAction, &QAction::triggered, this, [&]() {
367367
useAsFilter(QString ("~"), /* binary */ true);
368368
});
369-
connect(regexpAction, &QAction::triggered, [&]() {
369+
connect(regexpAction, &QAction::triggered, this, [&]() {
370370
useAsFilter(QString ("/"), /* binary */ false, QString ("/"));
371371
});
372-
connect(condFormatAction, &QAction::triggered, [&]() {
372+
connect(condFormatAction, &QAction::triggered, this, [&]() {
373373
emit editCondFormats(currentIndex().column());
374374
});
375375

376-
connect(nullAction, &QAction::triggered, [&]() {
376+
connect(nullAction, &QAction::triggered, this, [&]() {
377377
setToNull(selectedIndexes());
378378
});
379-
connect(copyAction, &QAction::triggered, [&]() {
379+
connect(copyAction, &QAction::triggered, this, [&]() {
380380
copy(false, false);
381381
});
382382
connect(cutAction, &QAction::triggered, this, &ExtendedTableWidget::cut);
383-
connect(copyWithHeadersAction, &QAction::triggered, [&]() {
383+
connect(copyWithHeadersAction, &QAction::triggered, this, [&]() {
384384
copy(true, false);
385385
});
386-
connect(copyAsSQLAction, &QAction::triggered, [&]() {
386+
connect(copyAsSQLAction, &QAction::triggered, this, [&]() {
387387
copy(false, true);
388388
});
389-
connect(pasteAction, &QAction::triggered, [&]() {
389+
connect(pasteAction, &QAction::triggered, this, [&]() {
390390
paste();
391391
});
392-
connect(printAction, &QAction::triggered, [&]() {
392+
connect(printAction, &QAction::triggered, this, [&]() {
393393
openPrintDialog();
394394
});
395395

396396
// Add spreadsheet shortcuts for selecting entire columns or entire rows.
397397
QShortcut* selectColumnShortcut = new QShortcut(QKeySequence("Ctrl+Space"), this);
398-
connect(selectColumnShortcut, &QShortcut::activated, [this]() {
398+
connect(selectColumnShortcut, &QShortcut::activated, this, [this]() {
399399
if(!hasFocus() || selectionModel()->selectedIndexes().isEmpty())
400400
return;
401401
selectionModel()->select(QItemSelection(selectionModel()->selectedIndexes().first(), selectionModel()->selectedIndexes().last()), QItemSelectionModel::Select | QItemSelectionModel::Columns);
402402
});
403403
QShortcut* selectRowShortcut = new QShortcut(QKeySequence("Shift+Space"), this);
404-
connect(selectRowShortcut, &QShortcut::activated, [this]() {
404+
connect(selectRowShortcut, &QShortcut::activated, this, [this]() {
405405
if(!hasFocus() || selectionModel()->selectedIndexes().isEmpty())
406406
return;
407407
selectionModel()->select(QItemSelection(selectionModel()->selectedIndexes().first(), selectionModel()->selectedIndexes().last()), QItemSelectionModel::Select | QItemSelectionModel::Rows);
@@ -1131,7 +1131,7 @@ void ExtendedTableWidget::openPrintDialog()
11311131
QPrinter printer;
11321132
QPrintPreviewDialog *dialog = new QPrintPreviewDialog(&printer);
11331133

1134-
connect(dialog, &QPrintPreviewDialog::paintRequested, [mimeData](QPrinter *previewPrinter) {
1134+
connect(dialog, &QPrintPreviewDialog::paintRequested, this, [mimeData](QPrinter *previewPrinter) {
11351135
QTextDocument document;
11361136
document.setHtml(mimeData->html());
11371137
document.print(previewPrinter);

0 commit comments

Comments
 (0)