Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace qMin,qMax,qBound,qRound,qAbs with standard funcs #2236

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

isf63
Copy link
Contributor

@isf63 isf63 commented Feb 8, 2025

No description provided.

@@ -77,7 +79,7 @@ CustomButton::~CustomButton() = default;
void CustomButton::wheelEvent(QWheelEvent *event)
{
QPoint anglePoint = event->angleDelta();
bool horizontal(qAbs(event->angleDelta().x()) > qAbs(anglePoint.y()));
bool horizontal(std::abs(event->angleDelta().x()) > std::abs(anglePoint.y()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs cmath.

@@ -86,7 +88,7 @@ void LXQtNetworkMonitorConfiguration::loadSettings()
ui->interfaceCB->addItem(QLatin1String(stats[ix].interface_name));

QString interface = settings().value(QStringLiteral("interface")).toString();
ui->interfaceCB->setCurrentIndex(qMax(qMin(0, count - 1), ui->interfaceCB->findText(interface)));
ui->interfaceCB->setCurrentIndex(std::clamp(count - 1, ui->interfaceCB->findText(interface), 0));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QComboBox::findText can be > 0, in which case, clamp will be undefined. So, min and max should be used.

@@ -47,8 +49,8 @@ int AudioEngine::volumeBounded(int volume, AudioDevice* device) const
{
int maximum = volumeMax(device);
double v = ((double) volume / 100.0) * maximum;
double bounded = qBound<double>(0, v, maximum);
return qRound((bounded / maximum) * 100);
double bounded = std::clamp<double>(v, 0.0, maximum);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope maximum >= 0; it seems to be the case; doesn't it?

@@ -215,7 +215,7 @@ void LXQtVolume::handleSinkListChanged()
{
if (m_engine->sinks().count() > 0)
{
m_defaultSink = m_engine->sinks().at(qBound(0, m_defaultSinkIndex, m_engine->sinks().count()-1));
m_defaultSink = m_engine->sinks().at(std::clamp<qsizetype>(m_defaultSinkIndex, 0, m_engine->sinks().count()-1));
Copy link
Member

@tsujan tsujan Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if m_engine->sinks().count() is 0? Is it possible here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants