Show units on XY-Plots (optional)
This commit is contained in:
parent
12818d9f7f
commit
85c1c24294
@ -402,7 +402,11 @@ void TraceXYPlot::draw(QPainter &p)
|
||||
auto tickStart = i == 0 ? plotAreaLeft : plotAreaLeft + plotAreaWidth;
|
||||
auto tickLen = i == 0 ? -2 : 2;
|
||||
p.drawLine(tickStart, yCoord, tickStart + tickLen, yCoord);
|
||||
auto tickValue = Unit::ToString(YAxis[i].ticks[j], "", "fpnum kMG", significantDigits);
|
||||
QString unit = "";
|
||||
if(pref.Graphs.showUnits) {
|
||||
unit = AxisUnit(YAxis[i].type);
|
||||
}
|
||||
auto tickValue = Unit::ToString(YAxis[i].ticks[j], unit, "fpnum kMG", significantDigits);
|
||||
if(i == 0) {
|
||||
p.drawText(QRectF(0, yCoord - AxisLabelSize/2 - 2, tickStart + 2 * tickLen, AxisLabelSize), Qt::AlignRight, tickValue);
|
||||
} else {
|
||||
@ -519,12 +523,16 @@ void TraceXYPlot::draw(QPainter &p)
|
||||
bool displayFullFreq = significantDigits <= 5;
|
||||
constexpr int displayLastDigits = 4;
|
||||
QString prefixes = "fpnum kMG";
|
||||
QString unit = "";
|
||||
if(pref.Graphs.showUnits) {
|
||||
unit = AxisUnit(XAxis.type);
|
||||
}
|
||||
QString commonPrefix = QString();
|
||||
if(!displayFullFreq) {
|
||||
auto fullFreq = Unit::ToString(XAxis.ticks.front(), "", prefixes, significantDigits);
|
||||
auto fullFreq = Unit::ToString(XAxis.ticks.front(), unit, prefixes, significantDigits);
|
||||
commonPrefix = fullFreq.at(fullFreq.size() - 1);
|
||||
auto front = fullFreq;
|
||||
front.truncate(fullFreq.size() - displayLastDigits);
|
||||
front.truncate(fullFreq.size() - displayLastDigits - unit.length());
|
||||
auto back = fullFreq;
|
||||
back.remove(0, front.size());
|
||||
back.append("..");
|
||||
@ -537,7 +545,7 @@ void TraceXYPlot::draw(QPainter &p)
|
||||
|
||||
for(auto t : XAxis.ticks) {
|
||||
auto xCoord = Util::Scale<double>(t, XAxis.rangeMin, XAxis.rangeMax, plotAreaLeft, plotAreaLeft + plotAreaWidth);
|
||||
auto tickValue = Unit::ToString(t, "", prefixes, significantDigits);
|
||||
auto tickValue = Unit::ToString(t, unit, prefixes, significantDigits);
|
||||
p.setPen(QPen(pref.Graphs.Color.axis, 1));
|
||||
if(displayFullFreq) {
|
||||
p.drawText(QRect(xCoord - 40, plotAreaBottom + 5, 80, AxisLabelSize), Qt::AlignHCenter, tickValue);
|
||||
@ -548,7 +556,7 @@ void TraceXYPlot::draw(QPainter &p)
|
||||
tickValue = Unit::ToString(t, "", commonPrefix, significantDigits + 1);
|
||||
}
|
||||
|
||||
tickValue.remove(0, tickValue.size() - displayLastDigits);
|
||||
tickValue.remove(0, tickValue.size() - displayLastDigits - unit.length());
|
||||
QRect bounding;
|
||||
p.drawText(QRect(xCoord - 40, plotAreaBottom + 5, 80, AxisLabelSize), Qt::AlignHCenter, tickValue, &bounding);
|
||||
p.setPen(QPen(QColor("orange")));
|
||||
@ -1121,11 +1129,11 @@ QString TraceXYPlot::mouseText(QPoint pos)
|
||||
QString TraceXYPlot::AxisUnit(TraceXYPlot::YAxisType type)
|
||||
{
|
||||
switch(type) {
|
||||
case TraceXYPlot::YAxisType::Magnitude: return "db";
|
||||
case TraceXYPlot::YAxisType::Magnitude: return "dB";
|
||||
case TraceXYPlot::YAxisType::Phase: return "°";
|
||||
case TraceXYPlot::YAxisType::VSWR: return "";
|
||||
case TraceXYPlot::YAxisType::ImpulseReal: return "";
|
||||
case TraceXYPlot::YAxisType::ImpulseMag: return "db";
|
||||
case TraceXYPlot::YAxisType::ImpulseMag: return "dB";
|
||||
case TraceXYPlot::YAxisType::Step: return "";
|
||||
case TraceXYPlot::YAxisType::Impedance: return "Ohm";
|
||||
case TraceXYPlot::YAxisType::GroupDelay: return "s";
|
||||
|
@ -135,6 +135,7 @@ PreferencesDialog::PreferencesDialog(Preferences *pref, QWidget *parent) :
|
||||
p->Acquisition.useDFTinSAmode = ui->AcquisitionUseDFT->isChecked();
|
||||
p->Acquisition.RBWLimitForDFT = ui->AcquisitionDFTlimitRBW->value();
|
||||
p->Acquisition.useMedianAveraging = ui->AcquisitionAveragingMode->currentIndex() == 1;
|
||||
p->Graphs.showUnits = ui->GraphsShowUnit->isChecked();
|
||||
p->Graphs.Color.background = ui->GraphsColorBackground->getColor();
|
||||
p->Graphs.Color.axis = ui->GraphsColorAxis->getColor();
|
||||
p->Graphs.Color.Ticks.Background.enabled = ui->GraphsColorTicksBackgroundEnabled->isChecked();
|
||||
@ -203,6 +204,7 @@ void PreferencesDialog::setInitialGUIState()
|
||||
ui->AcquisitionDFTlimitRBW->setValue(p->Acquisition.RBWLimitForDFT);
|
||||
ui->AcquisitionAveragingMode->setCurrentIndex(p->Acquisition.useMedianAveraging ? 1 : 0);
|
||||
|
||||
ui->GraphsShowUnit->setChecked(p->Graphs.showUnits);
|
||||
ui->GraphsColorBackground->setColor(p->Graphs.Color.background);
|
||||
ui->GraphsColorAxis->setColor(p->Graphs.Color.axis);
|
||||
ui->GraphsColorTicksDivisions->setColor(p->Graphs.Color.Ticks.divisions);
|
||||
|
@ -69,6 +69,7 @@ public:
|
||||
bool useMedianAveraging;
|
||||
} Acquisition;
|
||||
struct {
|
||||
bool showUnits;
|
||||
struct {
|
||||
QColor background;
|
||||
QColor axis;
|
||||
@ -102,7 +103,7 @@ private:
|
||||
QString name;
|
||||
QVariant def;
|
||||
};
|
||||
const std::array<SettingDescription, 39> descr = {{
|
||||
const std::array<SettingDescription, 40> descr = {{
|
||||
{&Startup.ConnectToFirstDevice, "Startup.ConnectToFirstDevice", true},
|
||||
{&Startup.RememberSweepSettings, "Startup.RememberSweepSettings", false},
|
||||
{&Startup.DefaultSweep.type, "Startup.DefaultSweep.type", "Frequency"},
|
||||
@ -131,6 +132,7 @@ private:
|
||||
{&Acquisition.useDFTinSAmode, "Acquisition.useDFTinSAmode", true},
|
||||
{&Acquisition.RBWLimitForDFT, "Acquisition.RBWLimitForDFT", 3000.0},
|
||||
{&Acquisition.useMedianAveraging, "Acquisition.useMedianAveraging", false},
|
||||
{&Graphs.showUnits, "Graphs.showUnits", true},
|
||||
{&Graphs.Color.background, "Graphs.Color.background", QColor(Qt::black)},
|
||||
{&Graphs.Color.axis, "Graphs.Color.axis", QColor(Qt::white)},
|
||||
{&Graphs.Color.Ticks.Background.enabled, "Graphs.Color.Ticks.Background.enabled", true},
|
||||
|
@ -686,6 +686,13 @@
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_11">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="GraphsShowUnit">
|
||||
<property name="text">
|
||||
<string>Show unit on graph axes</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_5">
|
||||
<property name="title">
|
||||
|
Loading…
Reference in New Issue
Block a user