Skip to content

Commit

Permalink
Convert polling rate slot to lambda
Browse files Browse the repository at this point in the history
Easier to read and also a bit less code.
  • Loading branch information
z3ntu committed May 4, 2024
1 parent aa2058d commit fc7513c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
20 changes: 8 additions & 12 deletions src/devicewidget/performancewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ PerformanceWidget::PerformanceWidget(libopenrazer::Device *device)
pollComboBox->setCurrentText(QString::number(pollRate) + " Hz");
verticalLayout->addWidget(pollComboBox);

connect(pollComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &PerformanceWidget::pollCombo);
connect(pollComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [=](int) {
try {
device->setPollRate(pollComboBox->currentData().value<ushort>());
} catch (const libopenrazer::DBusException &e) {
qWarning("Failed to set polling rate");
util::showError(tr("Failed to set polling rate"));
}
});
}

/* Spacer to bottom */
Expand All @@ -71,14 +78,3 @@ bool PerformanceWidget::isAvailable(libopenrazer::Device *device)
{
return device->hasFeature("dpi") || device->hasFeature("poll_rate");
}

void PerformanceWidget::pollCombo(int /* index */)
{
auto *sender = qobject_cast<QComboBox *>(QObject::sender());
try {
device->setPollRate(sender->currentData().value<ushort>());
} catch (const libopenrazer::DBusException &e) {
qWarning("Failed to set polling rate");
util::showError(tr("Failed to set polling rate"));
}
}
3 changes: 0 additions & 3 deletions src/devicewidget/performancewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ class PerformanceWidget : public QWidget

static bool isAvailable(libopenrazer::Device *device);

public slots:
void pollCombo(int /* index */);

private:
libopenrazer::Device *device;
};
Expand Down

0 comments on commit fc7513c

Please sign in to comment.