Skip to content

Commit

Permalink
WaveformWidgetFactory: range-based loops, std:as_const
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Oct 28, 2023
1 parent 271ca56 commit a2cf623
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions src/waveform/waveformwidgetfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ void WaveformWidgetFactory::setDefaultZoom(double zoom) {
m_config->set(ConfigKey("[Waveform]","DefaultZoom"), ConfigValue(m_defaultZoom));
}

for (const auto& holder : m_waveformWidgetHolders) {
for (const auto& holder : std::as_const(m_waveformWidgetHolders)) {
holder.m_waveformViewer->setZoom(m_defaultZoom);
}
}
Expand All @@ -657,7 +657,7 @@ void WaveformWidgetFactory::setZoomSync(bool sync) {
}

double refZoom = m_waveformWidgetHolders[0].m_waveformWidget->getZoomFactor();
for (const auto& holder : m_waveformWidgetHolders) {
for (const auto& holder : std::as_const(m_waveformWidgetHolders)) {
holder.m_waveformViewer->setZoom(refZoom);
}
}
Expand All @@ -668,7 +668,7 @@ void WaveformWidgetFactory::setDisplayBeatGridAlpha(int alpha) {
return;
}

for (const auto& holder : m_waveformWidgetHolders) {
for (const auto& holder : std::as_const(m_waveformWidgetHolders)) {
holder.m_waveformWidget->setDisplayBeatGridAlpha(m_beatGridAlpha);
}
}
Expand Down Expand Up @@ -698,22 +698,22 @@ void WaveformWidgetFactory::setPlayMarkerPosition(double position) {
m_config->setValue(ConfigKey("[Waveform]", "PlayMarkerPosition"), m_playMarkerPosition);
}

for (const auto& holder : m_waveformWidgetHolders) {
for (const auto& holder : std::as_const(m_waveformWidgetHolders)) {
holder.m_waveformWidget->setPlayMarkerPosition(m_playMarkerPosition);
}
}

void WaveformWidgetFactory::notifyZoomChange(WWaveformViewer* viewer) {
WaveformWidgetAbstract* pWaveformWidget = viewer->getWaveformWidget();
if (pWaveformWidget != nullptr && isZoomSync()) {
//qDebug() << "WaveformWidgetFactory::notifyZoomChange";
double refZoom = pWaveformWidget->getZoomFactor();

for (std::size_t i = 0; i < m_waveformWidgetHolders.size(); ++i) {
WaveformWidgetHolder& holder = m_waveformWidgetHolders[i];
if (holder.m_waveformViewer != viewer) {
holder.m_waveformViewer->setZoom(refZoom);
}
if (pWaveformWidget == nullptr || !isZoomSync()) {
return;
}
// qDebug() << "WaveformWidgetFactory::notifyZoomChange";
double refZoom = pWaveformWidget->getZoomFactor();

for (const auto& holder : std::as_const(m_waveformWidgetHolders)) {
if (holder.m_waveformViewer != viewer) {
holder.m_waveformViewer->setZoom(refZoom);
}
}
}
Expand Down Expand Up @@ -802,7 +802,7 @@ void WaveformWidgetFactory::swap() {
if (m_type) { // no regular updates for an empty waveform
// Show rendered buffer from last render() run
//qDebug() << "swap() start" << m_vsyncThread->elapsed();
for (const auto& holder : m_waveformWidgetHolders) {
for (const auto& holder : std::as_const(m_waveformWidgetHolders)) {
WaveformWidgetAbstract* pWaveformWidget = holder.m_waveformWidget;

// Don't swap invalid / invisible widgets or widgets with an
Expand Down Expand Up @@ -1164,19 +1164,18 @@ WaveformWidgetType::Type WaveformWidgetFactory::findTypeFromHandleIndex(int inde
}

int WaveformWidgetFactory::findHandleIndexFromType(WaveformWidgetType::Type type) {
int index = -1;
for (int i = 0; i < m_waveformWidgetHandles.size(); i++) {
WaveformWidgetAbstractHandle& handle = m_waveformWidgetHandles[i];
int index = 0;
for (const auto& handle : std::as_const(m_waveformWidgetHandles)) {
if (handle.m_type == type) {
index = i;
return index;
}
index++;
}
return index;
return -1;
}

QString WaveformWidgetFactory::getDisplayNameFromType(WaveformWidgetType::Type type) {
for (int i = 0; i < m_waveformWidgetHandles.size(); i++) {
WaveformWidgetAbstractHandle& handle = m_waveformWidgetHandles[i];
for (const auto& handle : std::as_const(m_waveformWidgetHandles)) {
if (handle.m_type == type) {
return handle.m_displayString;
}
Expand Down

0 comments on commit a2cf623

Please sign in to comment.