File indexing completed on 2025-03-09 04:10:08
0001 /* 0002 * SPDX-FileCopyrightText: 2022 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "KisCurveRangeModel.h" 0008 0009 #include <KisDynamicSensorFactoryRegistry.h> 0010 0011 using LabelsState = std::tuple<QString, int>; 0012 0013 namespace { 0014 QString calcMinLabelWithFactory(const QString &sensorId) 0015 { 0016 KisDynamicSensorFactory *factory = 0017 KisDynamicSensorFactoryRegistry::instance()->get(sensorId); 0018 0019 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(factory, ""); 0020 0021 return factory->minimumLabel(); 0022 } 0023 0024 QString calcMaxLabelWithFactory(const QString &activeSensorId, const int length) 0025 { 0026 KisDynamicSensorFactory *factory = 0027 KisDynamicSensorFactoryRegistry::instance()->get(activeSensorId); 0028 0029 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(factory, ""); 0030 0031 return factory->maximumLabel(length); 0032 } 0033 0034 QString calcValueSuffixWithFactory(const QString &activeSensorId) 0035 { 0036 KisDynamicSensorFactory *factory = 0037 KisDynamicSensorFactoryRegistry::instance()->get(activeSensorId); 0038 0039 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(factory, ""); 0040 0041 return factory->valueSuffix(); 0042 } 0043 0044 0045 } 0046 0047 KisCurveRangeModel::KisCurveRangeModel(lager::cursor<QString> curve, 0048 lager::reader<QString> activeSensorId, 0049 lager::reader<int> activeSensorLength, 0050 const QString &yMinLabel, 0051 const QString &yMaxLabel, 0052 int yMinValue, 0053 int yMaxValue, 0054 const QString &yValueSuffix) 0055 : m_curve(std::move(curve)) 0056 , m_activeSensorId(std::move(activeSensorId)) 0057 , m_activeSensorLength(std::move(activeSensorLength)) 0058 , m_yMinLabel(yMinLabel) 0059 , m_yMaxLabel(yMaxLabel) 0060 , m_yMinValue(yMinValue) 0061 , m_yMaxValue(yMaxValue) 0062 , m_yValueSuffix(yValueSuffix) 0063 { 0064 } 0065 0066 KisCurveRangeModelFactory KisCurveRangeModel::factory(const QString &yMinLabel, 0067 const QString &yMaxLabel, 0068 int curveMinValue, 0069 int curveMaxValue, 0070 const QString &curveValueSuffix) 0071 { 0072 return [yMinLabel, yMaxLabel, 0073 curveMinValue, curveMaxValue, 0074 curveValueSuffix](lager::cursor<QString> curve, 0075 lager::cursor<QRectF> curveRange, 0076 lager::reader<QString> activeSensorId, 0077 lager::reader<int> activeSensorLength) { 0078 0079 Q_UNUSED(curveRange); 0080 return new KisCurveRangeModel(curve, activeSensorId, activeSensorLength, yMinLabel, yMaxLabel, curveMinValue, curveMaxValue, curveValueSuffix); 0081 }; 0082 } 0083 0084 qreal KisCurveRangeModel::calcXMinValueWithFactory(const QString &sensorId) 0085 { 0086 KisDynamicSensorFactory *factory = 0087 KisDynamicSensorFactoryRegistry::instance()->get(sensorId); 0088 0089 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(factory, 0.0); 0090 0091 return qreal(factory->minimumValue()); 0092 } 0093 0094 qreal KisCurveRangeModel::calcXMaxValueWithFactory(const QString &activeSensorId, const int length) 0095 { 0096 KisDynamicSensorFactory *factory = 0097 KisDynamicSensorFactoryRegistry::instance()->get(activeSensorId); 0098 0099 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(factory, 1.0); 0100 0101 return factory->maximumValue(length); 0102 } 0103 0104 KisCurveRangeModel::~KisCurveRangeModel() 0105 { 0106 } 0107 0108 lager::cursor<QString> KisCurveRangeModel::curve() 0109 { 0110 return m_curve; 0111 } 0112 0113 lager::reader<QString> KisCurveRangeModel::xMinLabel() 0114 { 0115 return m_activeSensorId.map(&calcMinLabelWithFactory); 0116 } 0117 0118 lager::reader<QString> KisCurveRangeModel::xMaxLabel() 0119 { 0120 return lager::with(m_activeSensorId, m_activeSensorLength).map(&calcMaxLabelWithFactory); 0121 } 0122 0123 lager::reader<QString> KisCurveRangeModel::yMinLabel() 0124 { 0125 return m_yMinLabel; 0126 } 0127 0128 lager::reader<QString> KisCurveRangeModel::yMaxLabel() 0129 { 0130 return m_yMaxLabel; 0131 } 0132 0133 lager::reader<qreal> KisCurveRangeModel::yMinValue() 0134 { 0135 return m_yMinValue; 0136 } 0137 0138 lager::reader<qreal> KisCurveRangeModel::yMaxValue() 0139 { 0140 return m_yMaxValue; 0141 } 0142 0143 lager::reader<QString> KisCurveRangeModel::yValueSuffix() 0144 { 0145 return m_yValueSuffix; 0146 } 0147 0148 lager::reader<qreal> KisCurveRangeModel::xMinValue() 0149 { 0150 return m_activeSensorId.map(&calcXMinValueWithFactory); 0151 } 0152 0153 lager::reader<qreal> KisCurveRangeModel::xMaxValue() 0154 { 0155 return lager::with(m_activeSensorId, m_activeSensorLength).map(&calcXMaxValueWithFactory); 0156 } 0157 0158 lager::reader<QString> KisCurveRangeModel::xValueSuffix() 0159 { 0160 return m_activeSensorId.map(&calcValueSuffixWithFactory); 0161 }