1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2026-03-31 12:15:36 -04:00
sdrangel/sdrgui/gui/scaleengine.h
Jon Beniston 9171a205d4 Spectrum Changes:
Added optional scrollbar to be able to scroll back through waterfall.
When scrolling is enabled:
        Can adjust power scale for complete waterfall, not just future spectra.
        Waterfall time axis can use local time or UTC.
        Waterfall not lost when resizing window.
Can now zoom when device is stopped.
Added Min averaging type.
Added button to load spectrum from .csv file.
Add button to save spectrum/waterfall to .png or jpg.
Changed show all controls button to a combobox with choices of Min/Std/All (Minimum/Standard/All).
Changed some buttons in spectrum GUI from QPushButton to QToolButton so their size matches the others.
Fix spectrum from displaying a mixture of old and new spectrums (m_currentSpectrum was a pointer to SpectrumVis buffer).
Added M1 and M2 memories to allow display of reference spectra.
Added math operations to allow spectrum to be difference of current spectrum and either memory or a moving average.
Fixed measurement counts, so they are performed once per spectrum, not on displayed spectra.
Added spectrum mask measurement, to check when a spectrum exceeds mask held in M1 or M2.
Optionally display power/frequency under cursor in status line.
Optionally display peak power/frequency in status line.
Fix incorrect nyquist sample replication, when zoom used.
Fix cursor not changing from resize to pointer when moving over spectrum measurements window.
Add spectrum colour setting.
2026-03-25 16:30:13 +00:00

129 lines
4.3 KiB
C++

///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
// written by Christian Daniel //
// Copyright (C) 2015-2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDE_SCALEENGINE_H
#define INCLUDE_SCALEENGINE_H
#include <math.h>
#include <QFont>
#include <QString>
#include <QList>
#include "dsp/physicalunit.h"
#include "export.h"
class SDRGUI_API ScaleEngine {
public:
struct Tick {
float pos;
bool major;
float textPos;
float textSize;
QString text;
};
typedef QList<Tick> TickList;
class TickFormatter {
public:
virtual QString formatTick(double value) const = 0;
};
ScaleEngine();
void setOrientation(Qt::Orientation orientation);
void setFont(const QFont& font);
void setSize(float size);
float getSize() { return m_size; }
void setRange(Unit::Physical physicalUnit, float rangeMin, float rangeMax);
float getRange() const { return m_rangeMax - m_rangeMin; }
float getRangeMin() const { return m_rangeMin; }
float getRangeMax() const { return m_rangeMax; }
void setMakeOpposite(bool makeOpposite) { m_makeOpposite = makeOpposite; }
void setFixedDecimalPlaces(int decimalPlaces) { m_fixedDecimalPlaces =decimalPlaces; }
void setTruncateMode(bool mode);
float getPosFromValue(double value);
float getValueFromPos(double pos);
const TickList& getTickList();
float getScaleWidth();
void setTickFormatter(TickFormatter *tickFormatter) { m_tickFormatter = tickFormatter; }
void requestReCalc() { m_recalc = true; }
private:
// base configuration
Qt::Orientation m_orientation;
QFont m_font;
float m_charSize;
// graph configuration
double m_size;
Unit::Physical m_physicalUnit;
double m_rangeMin;
double m_rangeMax;
// calculated values
bool m_recalc;
double m_scale;
QString m_unitStr;
QString m_multiplierStr;
TickList m_tickList;
double m_majorTickValueDistance;
double m_firstMajorTickValue;
int m_numMinorTicks;
int m_decimalPlaces;
int m_fixedDecimalPlaces;
bool m_makeOpposite; // will show -value instead of value
bool m_truncateMode; //!< truncate upper digits mode
bool m_truncated; //!< true if upper digits are truncated
double m_truncationValue; //!< value to subreact from tick display values
TickFormatter *m_tickFormatter;
QString formatTick(double value, int decimalPlaces);
void calcCharSize();
void calcScaleFactor();
double calcMajorTickUnits(double distance, int* retDecimalPlaces);
int calcTickTextSize(double distance);
void forceTwoTicks();
void reCalc();
void reCalcStd();
void reCalcS();
void truncS(int nbMaxTicks, std::vector<double>& sVals, std::vector<double>& dbVals);
void adjustText(const QFontMetricsF& fontMetrics, Tick& tick);
void updateTruncation();
inline int order(double value) {
return floor(log10(value));
}
double majorTickValue(int tick);
double minorTickValue(int tick);
QString getRangeMinStr();
QString getRangeMaxStr();
float getPosFromValueTrunc(double value);
float getValueFromPosTrunc(double pos);
};
#endif // INCLUDE_SCALEENGINE_H