Files
Jungfraujoch/viewer/widgets/SliderPlusBox.cpp
T
leonarski_f 6a21d453ba macOS groundwork: what a static read says will stop an Apple Clang / libc++ build
None of this has been built on a Mac - there is none yet. It is the list a read-only audit of the
viewer/rugnux subtree produced, plus a serial -fsyntax-only pass of every reachable .cpp with
clang 16 + libc++ on Linux, which found exactly one error (the first item).

- JFJochDatasetInfoChartView: std::vector<fftwf_complex> does not compile with libc++, whose
  construct_at refuses an array element type (float[2]). Use std::vector<std::complex<float>> and
  the reinterpret_cast every other FFTW call site already uses.
- libcurl: GSSAPI off on Linux, and neither TLS nor GSSAPI on macOS. The viewer never sets
  CURLOPT_HTTPAUTH, so Negotiate was dead weight that cost a krb5-devel build dependency; on macOS
  curl's FindGSS refuses the system Heimdal outright, and with Secure Transport gone from curl
  (8.15) TLS would mean a Homebrew OpenSSL - the only host library a Mac build would need.
  Linux keeps OpenSSL. CURL_USE_GSSAPI is forced OFF rather than left unset so an existing build
  tree drops its cached ON.
- libjpeg-turbo ExternalProject: CMAKE_SYSTEM_NAME/PROCESSOR were forwarded unconditionally, which
  puts even a native sub-build into cross-compiling mode, and CMAKE_OSX_ARCHITECTURES / SYSROOT /
  DEPLOYMENT_TARGET were not forwarded at all. Now the same rule the zlib-ng sub-build follows.
- ShadowAccumulatorGPU.cu was added on the JFJOCH_USE_CUDA option (default ON) instead of
  JFJOCH_CUDA_AVAILABLE like every other .cu, so a machine without nvcc got a CUDA source in a
  target with no CUDA language.
- CMAKE_OSX_DEPLOYMENT_TARGET defaults to 12.0 (overridable). Left unset, CMake takes the build
  machine's OS version and the .dmg starts nowhere older.
- Standard headers that were only arriving transitively (<chrono>, <cmath>, <limits>, <cstring>,
  <atomic>, <thread>, <string>); newer libc++ releases keep removing such transitive includes.

Checked: the seven changed sources pass clang 16 + libc++ -fsyntax-only. The CMake changes are
not configured or built.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015eAE2K7i5JGDwgwifiCfuA
(cherry picked from commit 5a7282759a)
2026-09-20 18:45:04 +02:00

166 lines
5.9 KiB
C++

// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#include <cmath>
#include "SliderPlusBox.h"
#include "../common/JFJochException.h"
SliderPlusBox::SliderPlusBox(double min, double max, double step, int decimals, QWidget *parent, ScaleType scaleType)
: QWidget(parent), v(min), m_step(step), m_min(min), m_max(max), m_decimals(decimals),
m_pendingSliderValue(0), m_sliderDragging(false), m_scaleType(scaleType) {
if (step <= 0)
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
"Scale factor for SliderPlusBox must be positive");
// A logarithmic scale accepts a minimum of exactly zero: slider position 0 means 0 ("off"),
// and the rest of the track spans [1, max] logarithmically.
if (m_scaleType == Logarithmic && m_min < 0)
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
"Minimum value must not be negative for logarithmic scale");
if (m_max <= m_min)
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
"Maximum value must be greater than minimum");
QHBoxLayout* layout = new QHBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
m_slider = new QSlider(Qt::Horizontal, this);
updateSliderRange();
m_doubleSpinBox = new QDoubleSpinBox(this);
m_doubleSpinBox->setRange(min, max);
m_doubleSpinBox->setDecimals(decimals);
m_doubleSpinBox->setSingleStep(step);
m_doubleSpinBox->setValue(v);
m_doubleSpinBox->setStyleSheet("background-color: rgb(255, 255, 255);");
m_updateTimer = new QTimer(this);
m_updateTimer->setInterval(500); // 500ms throttle
m_updateTimer->setSingleShot(false);
layout->addWidget(m_slider);
layout->addWidget(m_doubleSpinBox);
connect(m_slider, &QSlider::valueChanged, [this](int value) {
const QSignalBlocker blocker(m_doubleSpinBox);
m_pendingSliderValue = value;
double realValue = sliderToValue(value);
m_doubleSpinBox->setValue(realValue);
if (!m_updateTimer->isActive() && m_sliderDragging)
m_updateTimer->start();
}
);
connect(m_updateTimer, &QTimer::timeout, [this]() {
updateFromSlider(m_pendingSliderValue);
});
connect(m_slider, &QSlider::sliderPressed, [this]() {
m_sliderDragging = true;
});
connect(m_slider, &QSlider::sliderReleased, [this]() {
m_sliderDragging = false;
m_updateTimer->stop();
updateFromSlider(m_slider->value());
});
connect(m_doubleSpinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
[this](double value) {
const QSignalBlocker blocker(m_slider);
int sliderValue = valueToSlider(value);
m_slider->setValue(sliderValue);
v = value;
emit valueChanged(v);
});
setLayout(layout);
}
void SliderPlusBox::updateSliderRange() {
if (m_scaleType == Linear) {
m_slider->setRange(static_cast<int>(m_min / m_step), static_cast<int>(m_max / m_step));
m_slider->setValue(valueToSlider(v));
} else { // Logarithmic
// Use a higher resolution for logarithmic scale (1000 steps)
m_slider->setRange(0, 1000);
m_slider->setValue(valueToSlider(v));
}
}
double SliderPlusBox::sliderToValue(int sliderValue) const {
if (m_scaleType == Linear) {
return sliderValue * m_step;
} else { // Logarithmic
const double lo = (m_min > 0.0) ? m_min : 1.0;
if (m_min <= 0.0 && sliderValue <= 0)
return 0.0;
// Map from slider position (0-1000) to logarithmic value range
double logMin = std::log10(lo);
double logMax = std::log10(m_max);
double normalizedPos = static_cast<double>(sliderValue) / 1000.0;
double logValue = logMin + normalizedPos * (logMax - logMin);
return std::pow(10.0, logValue);
}
}
int SliderPlusBox::valueToSlider(double value) const {
if (m_scaleType == Linear) {
return static_cast<int>(value / m_step);
} else { // Logarithmic
const double lo = (m_min > 0.0) ? m_min : 1.0;
if (m_min <= 0.0 && value < lo)
return 0;
// Map from value to slider position (0-1000)
double logMin = std::log10(lo);
double logMax = std::log10(m_max);
double logValue = std::log10(std::max(value, lo)); // Ensure we don't go below min
double normalizedPos = (logValue - logMin) / (logMax - logMin);
return static_cast<int>(normalizedPos * 1000.0);
}
}
void SliderPlusBox::updateFromSlider(int sliderValue) {
// Update our internal value and emit the signal
v = sliderToValue(sliderValue);
emit valueChanged(v);
}
void SliderPlusBox::setValue(double value) {
m_doubleSpinBox->setValue(value);
}
void SliderPlusBox::setMax(double value) {
if (value <= m_min)
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
"Maximum value must be greater than minimum");
if (value >= v) {
// if current value is smaller than new max, don't do anything
m_max = value;
m_doubleSpinBox->setRange(m_min, m_max);
updateSliderRange();
}
}
void SliderPlusBox::setScaleType(ScaleType type) {
if (m_scaleType == type)
return;
if (type == Logarithmic && m_min < 0) {
qWarning() << "Cannot switch to logarithmic scale with min < 0";
return;
}
m_scaleType = type;
// Preserve the current value during scale type change
double currentValue = v;
// Update the slider range for the new scale type
updateSliderRange();
// Reset the value
setValue(currentValue);
}