Skip to content

Commit 7f051f8

Browse files
committed
Some progress towards less usage of SIGNAL and SLOT macros
This is in no way complete but since it is a routine task and I got bored of it I am going to stop here.
1 parent df291aa commit 7f051f8

9 files changed

Lines changed: 56 additions & 60 deletions

src/AddRecordDialog.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ AddRecordDialog::AddRecordDialog(DBBrowserDB& db, const sqlb::ObjectIdentifier&
121121
{
122122
// Create UI
123123
ui->setupUi(this);
124-
connect(ui->treeWidget, SIGNAL(itemChanged(QTreeWidgetItem*,int)),this,SLOT(itemChanged(QTreeWidgetItem*,int)));
124+
connect(ui->treeWidget, &QTreeWidget::itemChanged, this, &AddRecordDialog::itemChanged);
125125

126126
populateFields();
127127

@@ -163,10 +163,8 @@ void AddRecordDialog::setDefaultsStyle(QTreeWidgetItem* item)
163163

164164
void AddRecordDialog::populateFields()
165165
{
166-
// disconnect the itemChanged signal or the SQL text will
167-
// be updated while filling the treewidget.
168-
disconnect(ui->treeWidget, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
169-
this,SLOT(itemChanged(QTreeWidgetItem*,int)));
166+
// Block the itemChanged signal or the SQL text will be updated while filling the treewidget.
167+
ui->treeWidget->blockSignals(true);
170168

171169
ui->treeWidget->clear();
172170

@@ -260,8 +258,8 @@ void AddRecordDialog::populateFields()
260258

261259
updateSqlText();
262260

263-
// and reconnect
264-
connect(ui->treeWidget, SIGNAL(itemChanged(QTreeWidgetItem*,int)),this,SLOT(itemChanged(QTreeWidgetItem*,int)));
261+
// Enable signals from tree widget
262+
ui->treeWidget->blockSignals(false);
265263
}
266264

267265
void AddRecordDialog::accept()

src/Application.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ Application::Application(int& argc, char** argv) :
152152
// Show main window
153153
m_mainWindow = new MainWindow();
154154
m_mainWindow->show();
155-
connect(this, SIGNAL(lastWindowClosed()), this, SLOT(quit()));
155+
connect(this, &Application::lastWindowClosed, this, &Application::quit);
156156

157157
// Open database if one was specified
158158
if(fileToOpen.size())

src/ExtendedTableWidget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ ExtendedTableWidget::ExtendedTableWidget(QWidget* parent) :
227227
// Force ScrollPerItem, so scrolling shows all table rows
228228
setVerticalScrollMode(ExtendedTableWidget::ScrollPerItem);
229229

230-
connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(vscrollbarChanged(int)));
231-
connect(this, SIGNAL(clicked(QModelIndex)), this, SLOT(cellClicked(QModelIndex)));
230+
connect(verticalScrollBar(), &QScrollBar::valueChanged, this, &ExtendedTableWidget::vscrollbarChanged);
231+
connect(this, &ExtendedTableWidget::clicked, this, &ExtendedTableWidget::cellClicked);
232232

233233
// Set up filter row
234234
m_tableHeader = new FilterTableHeader(this);

src/FilterTableHeader.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ FilterTableHeader::FilterTableHeader(QTableView* parent) :
1818
setSectionResizeMode(QHeaderView::Interactive);
1919

2020
// Do some connects: Basically just resize and reposition the input widgets whenever anything changes
21-
connect(this, SIGNAL(sectionResized(int,int,int)), this, SLOT(adjustPositions()));
22-
connect(parent->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(adjustPositions()));
23-
connect(parent->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(adjustPositions()));
21+
connect(this, &FilterTableHeader::sectionResized, this, &FilterTableHeader::adjustPositions);
22+
connect(parent->horizontalScrollBar(), &QScrollBar::valueChanged, this, &FilterTableHeader::adjustPositions);
23+
connect(parent->verticalScrollBar(), &QScrollBar::valueChanged, this, &FilterTableHeader::adjustPositions);
2424

2525
// Set custom context menu handling
2626
setContextMenuPolicy(Qt::CustomContextMenu);
@@ -40,10 +40,10 @@ void FilterTableHeader::generateFilters(size_t number, bool showFirst)
4040
l->setVisible(false);
4141
else
4242
l->setVisible(true);
43-
connect(l, SIGNAL(delayedTextChanged(QString)), this, SLOT(inputChanged(QString)));
44-
connect(l, SIGNAL(addFilterAsCondFormat(QString)), this, SLOT(addFilterAsCondFormat(QString)));
45-
connect(l, SIGNAL(clearAllCondFormats()), this, SLOT(clearAllCondFormats()));
46-
connect(l, SIGNAL(editCondFormats()), this, SLOT(editCondFormats()));
43+
connect(l, &FilterLineEdit::delayedTextChanged, this, &FilterTableHeader::inputChanged);
44+
connect(l, &FilterLineEdit::addFilterAsCondFormat, this, &FilterTableHeader::addFilterAsCondFormat);
45+
connect(l, &FilterLineEdit::clearAllCondFormats, this, &FilterTableHeader::clearAllCondFormats);
46+
connect(l, &FilterLineEdit::editCondFormats, this, &FilterTableHeader::editCondFormats);
4747
filterWidgets.push_back(l);
4848
}
4949

@@ -105,13 +105,13 @@ void FilterTableHeader::addFilterAsCondFormat(const QString& filter)
105105
void FilterTableHeader::clearAllCondFormats()
106106
{
107107
// Just get the column number and send it to anybody responsible or interested in clearing conditional formatting
108-
emit clearAllCondFormats(sender()->property("column").toInt());
108+
emit allCondFormatsCleared(sender()->property("column").toInt());
109109
}
110110

111111
void FilterTableHeader::editCondFormats()
112112
{
113113
// Just get the column number and the new value and send them to anybody interested in editting conditional formatting
114-
emit editCondFormats(sender()->property("column").toInt());
114+
emit condFormatsEdited(sender()->property("column").toInt());
115115
}
116116

117117
void FilterTableHeader::clearFilters()

src/FilterTableHeader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public slots:
2525
signals:
2626
void filterChanged(int column, QString value);
2727
void addCondFormat(int column, QString filter);
28-
void clearAllCondFormats(int column);
29-
void editCondFormats(int column);
28+
void allCondFormatsCleared(int column);
29+
void condFormatsEdited(int column);
3030

3131
protected:
3232
void updateGeometries() override;

src/FindReplaceDialog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ void FindReplaceDialog::setExtendedScintilla(ExtendedScintilla* scintilla)
3434
ui->replaceButton->setEnabled(isWriteable);
3535
ui->replaceAllButton->setEnabled(isWriteable);
3636

37-
connect(m_scintilla, SIGNAL(destroyed()), this, SLOT(hide()));
38-
connect(ui->findText, SIGNAL(editingFinished()), this, SLOT(cancelFind()));
37+
connect(m_scintilla, &ExtendedScintilla::destroyed, this, &FindReplaceDialog::hide);
38+
connect(ui->findText, &QLineEdit::editingFinished, this, &FindReplaceDialog::cancelFind);
3939
connect(ui->regexpCheckBox, &QCheckBox::toggled, this, &FindReplaceDialog::cancelFind);
4040
connect(ui->caseCheckBox, &QCheckBox::toggled, this, &FindReplaceDialog::cancelFind);
4141
connect(ui->wholeWordsCheckBox, &QCheckBox::toggled, this, &FindReplaceDialog::cancelFind);

src/MainWindow.cpp

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,12 @@ void MainWindow::init()
180180
ui->editGoto->setValidator(gotoValidator);
181181

182182
// Set up filters
183-
connect(ui->dataTable->filterHeader(), SIGNAL(filterChanged(int,QString)), this, SLOT(updateFilter(int,QString)));
184-
connect(ui->dataTable->filterHeader(), SIGNAL(addCondFormat(int,QString)), this, SLOT(addCondFormat(int,QString)));
185-
connect(ui->dataTable->filterHeader(), SIGNAL(clearAllCondFormats(int)), this, SLOT(clearAllCondFormats(int)));
186-
connect(ui->dataTable->filterHeader(), SIGNAL(editCondFormats(int)), this, SLOT(editCondFormats(int)));
187-
connect(ui->dataTable, SIGNAL(editCondFormats(int)), this, SLOT(editCondFormats(int)));
188-
connect(m_browseTableModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(dataTableSelectionChanged(QModelIndex)));
183+
connect(ui->dataTable->filterHeader(), &FilterTableHeader::filterChanged, this, &MainWindow::updateFilter);
184+
connect(ui->dataTable->filterHeader(), &FilterTableHeader::addCondFormat, this, &MainWindow::addCondFormat);
185+
connect(ui->dataTable->filterHeader(), &FilterTableHeader::allCondFormatsCleared, this, &MainWindow::clearAllCondFormats);
186+
connect(ui->dataTable->filterHeader(), &FilterTableHeader::condFormatsEdited, this, &MainWindow::editCondFormats);
187+
connect(ui->dataTable, &ExtendedTableWidget::editCondFormats, this, &MainWindow::editCondFormats);
188+
connect(m_browseTableModel, &SqliteTableModel::dataChanged, this, &MainWindow::dataTableSelectionChanged);
189189

190190
// Select in table the rows correspoding to the selected points in plot
191191
connect(plotDock, SIGNAL(pointsSelected(int,int)), ui->dataTable, SLOT(selectTableLines(int,int)));
@@ -235,9 +235,9 @@ void MainWindow::init()
235235
// Add keyboard shortcuts
236236

237237
QShortcut* shortcutBrowseRefreshF5 = new QShortcut(QKeySequence("F5"), this);
238-
connect(shortcutBrowseRefreshF5, SIGNAL(activated()), this, SLOT(refresh()));
238+
connect(shortcutBrowseRefreshF5, &QShortcut::activated, this, &MainWindow::refresh);
239239
QShortcut* shortcutBrowseRefreshCtrlR = new QShortcut(QKeySequence("Ctrl+R"), this);
240-
connect(shortcutBrowseRefreshCtrlR, SIGNAL(activated()), this, SLOT(refresh()));
240+
connect(shortcutBrowseRefreshCtrlR, &QShortcut::activated, this, &MainWindow::refresh);
241241

242242
// Add print shortcut for the DB Structure tab (dbTreeWidget) with context to the widget, so other print shortcuts aren't eclipsed.
243243
QShortcut* shortcutPrint = new QShortcut(QKeySequence(QKeySequence::Print), ui->dbTreeWidget, nullptr, nullptr, Qt::WidgetShortcut);
@@ -439,16 +439,16 @@ void MainWindow::init()
439439
});
440440

441441
// Connect some more signals and slots
442-
connect(ui->dataTable->filterHeader(), SIGNAL(sectionClicked(int)), this, SLOT(browseTableHeaderClicked(int)));
442+
connect(ui->dataTable->filterHeader(), &FilterTableHeader::sectionClicked, this, &MainWindow::browseTableHeaderClicked);
443443
connect(ui->dataTable->filterHeader(), &QHeaderView::sectionDoubleClicked, ui->dataTable, &QTableView::selectColumn);
444-
connect(ui->dataTable->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(setRecordsetLabel()));
445-
connect(ui->dataTable->horizontalHeader(), SIGNAL(sectionResized(int,int,int)), this, SLOT(updateBrowseDataColumnWidth(int,int,int)));
446-
connect(editDock, SIGNAL(recordTextUpdated(QPersistentModelIndex, QByteArray, bool)), this, SLOT(updateRecordText(QPersistentModelIndex, QByteArray, bool)));
447-
connect(ui->dbTreeWidget->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(changeTreeSelection()));
448-
connect(ui->dataTable->horizontalHeader(), SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showDataColumnPopupMenu(QPoint)));
449-
connect(ui->dataTable->verticalHeader(), SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showRecordPopupMenu(QPoint)));
444+
connect(ui->dataTable->verticalScrollBar(), &QScrollBar::valueChanged, this, &MainWindow::setRecordsetLabel);
445+
connect(ui->dataTable->horizontalHeader(), &QHeaderView::sectionResized, this, &MainWindow::updateBrowseDataColumnWidth);
446+
connect(editDock, &EditDialog::recordTextUpdated, this, &MainWindow::updateRecordText);
447+
connect(ui->dbTreeWidget->selectionModel(), &QItemSelectionModel::currentChanged, this, &MainWindow::changeTreeSelection);
448+
connect(ui->dataTable->horizontalHeader(), &QHeaderView::customContextMenuRequested, this, &MainWindow::showDataColumnPopupMenu);
449+
connect(ui->dataTable->verticalHeader(), &QHeaderView::customContextMenuRequested, this, &MainWindow::showRecordPopupMenu);
450450
connect(ui->dataTable, SIGNAL(openFileFromDropEvent(QString)), this, SLOT(fileOpen(QString)));
451-
connect(ui->dockEdit, SIGNAL(visibilityChanged(bool)), this, SLOT(toggleEditDock(bool)));
451+
connect(ui->dockEdit, &QDockWidget::visibilityChanged, this, &MainWindow::toggleEditDock);
452452
connect(m_remoteDb, SIGNAL(openFile(QString)), this, SLOT(fileOpen(QString)));
453453
connect(m_remoteDb, &RemoteDatabase::gotCurrentVersion, this, &MainWindow::checkNewVersion);
454454
connect(m_browseTableModel, &SqliteTableModel::finishedFetch, this, &MainWindow::setRecordsetLabel);
@@ -739,7 +739,7 @@ void MainWindow::populateTable()
739739
ui->dataTable->setModel(m_browseTableModel);
740740
if(reconnectSelectionSignals)
741741
{
742-
connect(ui->dataTable->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(dataTableSelectionChanged(QModelIndex)));
742+
connect(ui->dataTable->selectionModel(), &QItemSelectionModel::currentChanged, this, &MainWindow::dataTableSelectionChanged);
743743
connect(ui->dataTable->selectionModel(), &QItemSelectionModel::selectionChanged, [this](const QItemSelection&, const QItemSelection&) {
744744
updateInsertDeleteRecordButton();
745745

@@ -1077,9 +1077,8 @@ void MainWindow::attachPlot(ExtendedTableWidget* tableWidget, SqliteTableModel*
10771077
disconnect(plotDock, SIGNAL(pointsSelected(int,int)), nullptr, nullptr);
10781078
if(tableWidget) {
10791079
// Connect plot selection to the current table results widget.
1080-
connect(plotDock, SIGNAL(pointsSelected(int,int)), tableWidget, SLOT(selectTableLines(int,int)));
1081-
connect(tableWidget, SIGNAL(destroyed()), plotDock, SLOT(resetPlot()));
1082-
1080+
connect(plotDock, &PlotDock::pointsSelected, tableWidget, &ExtendedTableWidget::selectTableLines);
1081+
connect(tableWidget, &ExtendedTableWidget::destroyed, plotDock, &PlotDock::resetPlot);
10831082
}
10841083
}
10851084

@@ -1578,7 +1577,7 @@ void MainWindow::executeQuery()
15781577
disconnect(*conn);
15791578

15801579
attachPlot(sqlWidget->getTableResult(), sqlWidget->getModel());
1581-
connect(sqlWidget->getTableResult()->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(dataTableSelectionChanged(QModelIndex)));
1580+
connect(sqlWidget->getTableResult()->selectionModel(), &QItemSelectionModel::currentChanged, this, &MainWindow::dataTableSelectionChanged);
15821581
connect(sqlWidget->getTableResult(), &QTableView::doubleClicked, this, &MainWindow::doubleClickTable);
15831582

15841583
auto time_end = std::chrono::high_resolution_clock::now();
@@ -2404,11 +2403,11 @@ int MainWindow::openSqlTab(bool resetCounter)
24042403
// would interfere with the search bar and it'd be anyway redundant.
24052404
w->getEditor()->setEnabledFindDialog(false);
24062405
w->getEditor()->setFocus();
2407-
connect(w, SIGNAL(findFrameVisibilityChanged(bool)), ui->actionSqlFind, SLOT(setChecked(bool)));
2406+
connect(w, &SqlExecutionArea::findFrameVisibilityChanged, ui->actionSqlFind, &QAction::setChecked);
24082407

24092408
// Connect now the find shortcut to the editor with widget context, so it isn't ambiguous with other Scintilla Widgets.
24102409
QShortcut* shortcutFind = new QShortcut(ui->actionSqlFind->shortcut(), w->getEditor(), nullptr, nullptr, Qt::WidgetShortcut);
2411-
connect(shortcutFind, SIGNAL(activated()), ui->actionSqlFind, SLOT(toggle()));
2410+
connect(shortcutFind, &QShortcut::activated, ui->actionSqlFind, &QAction::toggle);
24122411

24132412
return index;
24142413
}

src/PlotDock.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ PlotDock::PlotDock(QWidget* parent)
4848

4949
// Connect signals
5050
connect(ui->treePlotColumns, &QTreeWidget::itemChanged, this, &PlotDock::on_treePlotColumns_itemChanged);
51-
connect(ui->plotWidget, SIGNAL(selectionChangedByUser()), this, SLOT(selectionChanged()));
51+
connect(ui->plotWidget, &QCustomPlot::selectionChangedByUser, this, &PlotDock::selectionChanged);
5252

5353
// connect slots that takes care that when an axis is selected, only that direction can be dragged and zoomed:
54-
connect(ui->plotWidget, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(mousePress()));
55-
connect(ui->plotWidget, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel()));
54+
connect(ui->plotWidget, &QCustomPlot::mousePress, this, &PlotDock::mousePress);
55+
connect(ui->plotWidget, &QCustomPlot::mouseWheel, this, &PlotDock::mouseWheel);
5656

5757
// Enable: click on items to select them, Ctrl+Click for multi-selection, mouse-wheel for zooming and mouse drag for
5858
// changing the visible range.
@@ -61,7 +61,7 @@ PlotDock::PlotDock(QWidget* parent)
6161
ui->plotWidget->setSelectionRectMode(QCP::srmNone);
6262

6363
QShortcut* shortcutCopy = new QShortcut(QKeySequence::Copy, ui->plotWidget, nullptr, nullptr, Qt::WidgetShortcut);
64-
connect(shortcutCopy, SIGNAL(activated()), this, SLOT(copy()));
64+
connect(shortcutCopy, &QShortcut::activated, this, &PlotDock::copy);
6565

6666
QShortcut* shortcutPrint = new QShortcut(QKeySequence::Print, ui->plotWidget, nullptr, nullptr, Qt::WidgetShortcut);
6767
connect(shortcutPrint, &QShortcut::activated, this, &PlotDock::openPrintDialog);
@@ -89,13 +89,13 @@ PlotDock::PlotDock(QWidget* parent)
8989
showLegendAction->setCheckable(true);
9090
m_contextMenu->addAction(showLegendAction);
9191

92-
connect(showLegendAction, SIGNAL(toggled(bool)), this, SLOT(toggleLegendVisible(bool)));
92+
connect(showLegendAction, &QAction::toggled, this, &PlotDock::toggleLegendVisible);
9393

9494
QAction* stackedBarsAction = new QAction(tr("Stacked bars"), m_contextMenu);
9595
stackedBarsAction->setCheckable(true);
9696
m_contextMenu->addAction(stackedBarsAction);
9797

98-
connect(stackedBarsAction, SIGNAL(toggled(bool)), this, SLOT(toggleStackedBars(bool)));
98+
connect(stackedBarsAction, &QAction::toggled, this, &PlotDock::toggleStackedBars);
9999

100100
connect(ui->plotWidget, &QTableView::customContextMenuRequested,
101101
[=](const QPoint& pos) {

src/SqlExecutionArea.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,13 @@ SqlExecutionArea::SqlExecutionArea(DBBrowserDB& _db, QWidget* parent) :
2929
ui->findFrame->hide();
3030

3131
QShortcut* shortcutHideFind = new QShortcut(QKeySequence("ESC"), ui->findLineEdit);
32-
connect(shortcutHideFind, SIGNAL(activated()), this, SLOT(hideFindFrame()));
33-
34-
connect(ui->findLineEdit, SIGNAL(textChanged(const QString &)),
35-
this, SLOT(findLineEdit_textChanged(const QString &)));
36-
connect(ui->previousToolButton, SIGNAL(clicked()), this, SLOT(findPrevious()));
37-
connect(ui->nextToolButton, SIGNAL(clicked()), this, SLOT(findNext()));
38-
connect(ui->findLineEdit, SIGNAL(returnPressed()), this, SLOT(findNext()));
39-
connect(ui->hideFindButton, SIGNAL(clicked()), this, SLOT(hideFindFrame()));
32+
connect(shortcutHideFind, &QShortcut::activated, this, &SqlExecutionArea::hideFindFrame);
33+
34+
connect(ui->findLineEdit, &QLineEdit::textChanged, this, &SqlExecutionArea::findLineEdit_textChanged);
35+
connect(ui->previousToolButton, &QToolButton::clicked, this, &SqlExecutionArea::findPrevious);
36+
connect(ui->nextToolButton, &QToolButton::clicked, this, &SqlExecutionArea::findNext);
37+
connect(ui->findLineEdit, &QLineEdit::returnPressed, this, &SqlExecutionArea::findNext);
38+
connect(ui->hideFindButton, &QToolButton::clicked, this, &SqlExecutionArea::hideFindFrame);
4039

4140
connect(&fileSystemWatch, &QFileSystemWatcher::fileChanged, this, &SqlExecutionArea::fileChanged);
4241

0 commit comments

Comments
 (0)