diff --git a/Software/PC_Application/Traces/tracesmithchart.cpp b/Software/PC_Application/Traces/tracesmithchart.cpp index 9ece00c..fdcd3ab 100644 --- a/Software/PC_Application/Traces/tracesmithchart.cpp +++ b/Software/PC_Application/Traces/tracesmithchart.cpp @@ -153,7 +153,7 @@ void TraceSmithChart::draw(QPainter &p) { p.drawArc(rectangle, 0, 5760); constexpr int Circles = 6; - pen = QPen(pref.Graphs.Color.divisions, 0.5, Qt::DashLine); + pen = QPen(pref.Graphs.Color.Ticks.divisions, 0.5, Qt::DashLine); pen.setCosmetic(true); p.setPen(pen); for(int i=1;i= 1) { - // draw X ticks - // this only works for evenly distributed ticks: - auto max = qMax(abs(XAxis.ticks.front()), abs(XAxis.ticks.back())); - auto minLabel = qMin(abs(XAxis.ticks.front()), abs(XAxis.ticks.back())); - double step; - if(XAxis.ticks.size() >= 2) { - step = abs(XAxis.ticks[0] - XAxis.ticks[1]); - } else { - // only one tick, set arbitrary number of digits - step = max / 1000; - } - if(minLabel > 0 && minLabel < step) { - step = minLabel; - } - int significantDigits = floor(log10(max)) - floor(log10(step)) + 1; - bool displayFullFreq = significantDigits <= 5; - constexpr int displayLastDigits = 4; - QString prefixes = "fpnum kMG"; - QString commonPrefix = QString(); - if(!displayFullFreq) { - auto fullFreq = Unit::ToString(XAxis.ticks.front(), "", prefixes, significantDigits); - commonPrefix = fullFreq.at(fullFreq.size() - 1); - auto front = fullFreq; - front.truncate(fullFreq.size() - displayLastDigits); - auto back = fullFreq; - back.remove(0, front.size()); - back.append(".."); - p.setPen(QPen(QColor("orange"))); - QRect bounding; - p.drawText(QRect(2, plotAreaBottom + AxisLabelSize + 5, w.width(), AxisLabelSize), 0, front, &bounding); - p.setPen(pref.Graphs.Color.axis); - p.drawText(QRect(bounding.x() + bounding.width(), plotAreaBottom + AxisLabelSize + 5, w.width(), AxisLabelSize), 0, back); - } - - for(auto t : XAxis.ticks) { - auto xCoord = Util::Scale(t, XAxis.rangeMin, XAxis.rangeMax, plotAreaLeft, plotAreaLeft + plotAreaWidth); - auto tickValue = Unit::ToString(t, "", prefixes, significantDigits); - p.setPen(QPen(pref.Graphs.Color.axis, 1)); - if(displayFullFreq) { - p.drawText(QRect(xCoord - 40, plotAreaBottom + 5, 80, AxisLabelSize), Qt::AlignHCenter, tickValue); - } else { - // check if the same prefix was used as in the fullFreq string - if(tickValue.at(tickValue.size() - 1) != commonPrefix) { - // prefix changed, we reached the next order of magnitude. Force same prefix as in fullFreq and add extra digit - tickValue = Unit::ToString(t, "", commonPrefix, significantDigits + 1); - } - - tickValue.remove(0, tickValue.size() - displayLastDigits); - QRect bounding; - p.drawText(QRect(xCoord - 40, plotAreaBottom + 5, 80, AxisLabelSize), Qt::AlignHCenter, tickValue, &bounding); - p.setPen(QPen(QColor("orange"))); - p.drawText(QRect(0, plotAreaBottom + 5, bounding.x() - 1, AxisLabelSize), Qt::AlignRight, ".."); - p.setPen(QPen(pref.Graphs.Color.axis, 1)); - } - p.drawLine(xCoord, plotAreaBottom, xCoord, plotAreaBottom + 2); - if(xCoord != plotAreaLeft && xCoord != plotAreaLeft + plotAreaWidth) { - p.setPen(QPen(pref.Graphs.Color.divisions, 0.5, Qt::DashLine)); - p.drawLine(xCoord, 0, xCoord, plotAreaBottom); - } - } - } - for(int i=0;i<2;i++) { if(YAxis[i].type == YAxisType::Disabled) { continue; @@ -467,14 +405,17 @@ void TraceXYPlot::draw(QPainter &p) step = max / 1000; } int significantDigits = floor(log10(max)) - floor(log10(step)) + 1; - for(auto t : YAxis[i].ticks) { - auto yCoord = Util::Scale(t, YAxis[i].rangeMax, YAxis[i].rangeMin, 0, w.height() - xAxisSpace); + + auto yCoordWidth = 0; + + for(unsigned int j = 0; j < YAxis[i].ticks.size(); j++) { + auto yCoord = Util::Scale(YAxis[i].ticks[j], YAxis[i].rangeMax, YAxis[i].rangeMin, plotAreaTop, w.height() - xAxisSpace); p.setPen(QPen(pref.Graphs.Color.axis, 1)); // draw tickmark on axis auto tickStart = i == 0 ? plotAreaLeft : plotAreaLeft + plotAreaWidth; auto tickLen = i == 0 ? -2 : 2; p.drawLine(tickStart, yCoord, tickStart + tickLen, yCoord); - auto tickValue = Unit::ToString(t, "", "fpnum kMG", significantDigits); + auto tickValue = Unit::ToString(YAxis[i].ticks[j], "", "fpnum kMG", significantDigits); if(i == 0) { p.drawText(QRectF(0, yCoord - AxisLabelSize/2 - 2, tickStart + 2 * tickLen, AxisLabelSize), Qt::AlignRight, tickValue); } else { @@ -482,13 +423,23 @@ void TraceXYPlot::draw(QPainter &p) } // tick lines - if(yCoord == 0 || yCoord == w.height() - xAxisSpace) { + if(yCoord == plotAreaTop || yCoord == w.height() - xAxisSpace) { // skip tick lines right on the plot borders continue; } if(i == 0) { // only draw tick lines for primary axis - p.setPen(QPen(pref.Graphs.Color.divisions, 0.5, Qt::DashLine)); + if (pref.Graphs.Color.Ticks.Background.enabled) { + yCoordWidth = floor((w.height() - xAxisSpace - plotAreaTop)/(YAxis[i].ticks.size()-1)); + if (j%2) + { + p.setBrush(pref.Graphs.Color.Ticks.Background.background); + p.setPen(pref.Graphs.Color.Ticks.Background.background); + auto rect = QRect(plotAreaLeft+1, yCoord+1, plotAreaWidth-2, yCoordWidth-2); + p.drawRect(rect); + } + } + p.setPen(QPen(pref.Graphs.Color.Ticks.divisions, 0.5, Qt::DashLine)); p.drawLine(plotAreaLeft, yCoord, plotAreaLeft + plotAreaWidth, yCoord); } } @@ -556,6 +507,69 @@ void TraceXYPlot::draw(QPainter &p) p.setClipping(false); } + if(XAxis.ticks.size() >= 1) { + // draw X ticks + // this only works for evenly distributed ticks: + auto max = qMax(abs(XAxis.ticks.front()), abs(XAxis.ticks.back())); + auto minLabel = qMin(abs(XAxis.ticks.front()), abs(XAxis.ticks.back())); + double step; + if(XAxis.ticks.size() >= 2) { + step = abs(XAxis.ticks[0] - XAxis.ticks[1]); + } else { + // only one tick, set arbitrary number of digits + step = max / 1000; + } + if(minLabel > 0 && minLabel < step) { + step = minLabel; + } + int significantDigits = floor(log10(max)) - floor(log10(step)) + 1; + bool displayFullFreq = significantDigits <= 5; + constexpr int displayLastDigits = 4; + QString prefixes = "fpnum kMG"; + QString commonPrefix = QString(); + if(!displayFullFreq) { + auto fullFreq = Unit::ToString(XAxis.ticks.front(), "", prefixes, significantDigits); + commonPrefix = fullFreq.at(fullFreq.size() - 1); + auto front = fullFreq; + front.truncate(fullFreq.size() - displayLastDigits); + auto back = fullFreq; + back.remove(0, front.size()); + back.append(".."); + p.setPen(QPen(QColor("orange"))); + QRect bounding; + p.drawText(QRect(2, plotAreaBottom + AxisLabelSize + 5, w.width(), AxisLabelSize), 0, front, &bounding); + p.setPen(pref.Graphs.Color.axis); + p.drawText(QRect(bounding.x() + bounding.width(), plotAreaBottom + AxisLabelSize + 5, w.width(), AxisLabelSize), 0, back); + } + + for(auto t : XAxis.ticks) { + auto xCoord = Util::Scale(t, XAxis.rangeMin, XAxis.rangeMax, plotAreaLeft, plotAreaLeft + plotAreaWidth); + auto tickValue = Unit::ToString(t, "", prefixes, significantDigits); + p.setPen(QPen(pref.Graphs.Color.axis, 1)); + if(displayFullFreq) { + p.drawText(QRect(xCoord - 40, plotAreaBottom + 5, 80, AxisLabelSize), Qt::AlignHCenter, tickValue); + } else { + // check if the same prefix was used as in the fullFreq string + if(tickValue.at(tickValue.size() - 1) != commonPrefix) { + // prefix changed, we reached the next order of magnitude. Force same prefix as in fullFreq and add extra digit + tickValue = Unit::ToString(t, "", commonPrefix, significantDigits + 1); + } + + tickValue.remove(0, tickValue.size() - displayLastDigits); + QRect bounding; + p.drawText(QRect(xCoord - 40, plotAreaBottom + 5, 80, AxisLabelSize), Qt::AlignHCenter, tickValue, &bounding); + p.setPen(QPen(QColor("orange"))); + p.drawText(QRect(0, plotAreaBottom + 5, bounding.x() - 1, AxisLabelSize), Qt::AlignRight, ".."); + p.setPen(QPen(pref.Graphs.Color.axis, 1)); + } + p.drawLine(xCoord, plotAreaBottom, xCoord, plotAreaBottom + 2); + if(xCoord != plotAreaLeft && xCoord != plotAreaLeft + plotAreaWidth) { + p.setPen(QPen(pref.Graphs.Color.Ticks.divisions, 0.5, Qt::DashLine)); + p.drawLine(xCoord, plotAreaTop, xCoord, plotAreaBottom); + } + } + } + if(dropPending) { p.setOpacity(0.5); p.setBrush(Qt::white); @@ -947,7 +961,7 @@ QPoint TraceXYPlot::plotValueToPixel(QPointF plotValue, int Yaxis) { QPoint p; p.setX(Util::Scale(plotValue.x(), XAxis.rangeMin, XAxis.rangeMax, plotAreaLeft, plotAreaLeft + plotAreaWidth)); - p.setY(Util::Scale(plotValue.y(), YAxis[Yaxis].rangeMin, YAxis[Yaxis].rangeMax, plotAreaBottom, 0)); + p.setY(Util::Scale(plotValue.y(), YAxis[Yaxis].rangeMin, YAxis[Yaxis].rangeMax, plotAreaBottom, plotAreaTop)); return p; } @@ -955,7 +969,7 @@ QPointF TraceXYPlot::pixelToPlotValue(QPoint pixel, int Yaxis) { QPointF p; p.setX(Util::Scale(pixel.x(), plotAreaLeft, plotAreaLeft + plotAreaWidth, XAxis.rangeMin, XAxis.rangeMax)); - p.setY(Util::Scale(pixel.y(), plotAreaBottom, 0, YAxis[Yaxis].rangeMin, YAxis[Yaxis].rangeMax)); + p.setY(Util::Scale(pixel.y(), plotAreaBottom, plotAreaTop, YAxis[Yaxis].rangeMin, YAxis[Yaxis].rangeMax)); return p; } diff --git a/Software/PC_Application/Traces/tracexyplot.h b/Software/PC_Application/Traces/tracexyplot.h index 969bf65..931d663 100644 --- a/Software/PC_Application/Traces/tracexyplot.h +++ b/Software/PC_Application/Traces/tracexyplot.h @@ -119,7 +119,7 @@ private: YAxis YAxis[2]; XAxis XAxis; - int plotAreaLeft, plotAreaWidth, plotAreaBottom; + int plotAreaLeft, plotAreaWidth, plotAreaBottom, plotAreaTop; }; #endif // TRACEXYPLOT_H diff --git a/Software/PC_Application/preferences.cpp b/Software/PC_Application/preferences.cpp index 738d10e..25cc425 100644 --- a/Software/PC_Application/preferences.cpp +++ b/Software/PC_Application/preferences.cpp @@ -134,7 +134,9 @@ PreferencesDialog::PreferencesDialog(Preferences *pref, QWidget *parent) : p->Acquisition.RBWLimitForDFT = ui->AcquisitionDFTlimitRBW->value(); p->Graphs.Color.background = ui->GraphsColorBackground->getColor(); p->Graphs.Color.axis = ui->GraphsColorAxis->getColor(); - p->Graphs.Color.divisions = ui->GraphsColorDivisions->getColor(); + p->Graphs.Color.Ticks.Background.enabled = ui->GraphsColorTicksBackgroundEnabled->isChecked(); + p->Graphs.Color.Ticks.Background.background = ui->GraphsColorTicksBackground->getColor(); + p->Graphs.Color.Ticks.divisions = ui->GraphsColorTicksDivisions->getColor(); p->Graphs.domainChangeBehavior = (GraphDomainChangeBehavior) ui->GraphsDomainChangeBehavior->currentIndex(); p->Graphs.markerBehavior.showDataOnGraphs = ui->GraphsShowMarkerData->isChecked(); p->Graphs.markerBehavior.showAllData = ui->GraphsShowAllMarkerData->isChecked(); @@ -198,7 +200,9 @@ void PreferencesDialog::setInitialGUIState() ui->GraphsColorBackground->setColor(p->Graphs.Color.background); ui->GraphsColorAxis->setColor(p->Graphs.Color.axis); - ui->GraphsColorDivisions->setColor(p->Graphs.Color.divisions); + ui->GraphsColorTicksDivisions->setColor(p->Graphs.Color.Ticks.divisions); + ui->GraphsColorTicksBackgroundEnabled->setChecked(p->Graphs.Color.Ticks.Background.enabled); + ui->GraphsColorTicksBackground->setColor(p->Graphs.Color.Ticks.Background.background); ui->GraphsDomainChangeBehavior->setCurrentIndex((int) p->Graphs.domainChangeBehavior); ui->GraphsShowMarkerData->setChecked(p->Graphs.markerBehavior.showDataOnGraphs); ui->GraphsShowAllMarkerData->setChecked(p->Graphs.markerBehavior.showAllData); diff --git a/Software/PC_Application/preferences.h b/Software/PC_Application/preferences.h index ae00929..9c46615 100644 --- a/Software/PC_Application/preferences.h +++ b/Software/PC_Application/preferences.h @@ -70,7 +70,13 @@ public: struct { QColor background; QColor axis; - QColor divisions; + struct { + QColor divisions; + struct { + bool enabled; + QColor background; + } Background; + } Ticks; } Color; GraphDomainChangeBehavior domainChangeBehavior; struct { @@ -93,7 +99,7 @@ private: QString name; QVariant def; }; - const std::array descr = {{ + const std::array descr = {{ {&Startup.ConnectToFirstDevice, "Startup.ConnectToFirstDevice", true}, {&Startup.RememberSweepSettings, "Startup.RememberSweepSettings", false}, {&Startup.DefaultSweep.type, "Startup.DefaultSweep.type", "Frequency"}, @@ -123,7 +129,9 @@ private: {&Acquisition.RBWLimitForDFT, "Acquisition.RBWLimitForDFT", 3000.0}, {&Graphs.Color.background, "Graphs.Color.background", QColor(Qt::black)}, {&Graphs.Color.axis, "Graphs.Color.axis", QColor(Qt::white)}, - {&Graphs.Color.divisions, "Graphs.Color.divisions", QColor(Qt::gray)}, + {&Graphs.Color.Ticks.Background.enabled, "Graphs.Color.Ticks.Background.enabled", true}, + {&Graphs.Color.Ticks.Background.background, "Graphs.Color.Ticks.Background.background", QColor(20, 20, 20)}, + {&Graphs.Color.Ticks.divisions, "Graphs.Color.Ticks.divisions", QColor(Qt::gray)}, {&Graphs.domainChangeBehavior, "Graphs.domainChangeBehavior", GraphDomainChangeBehavior::AdjustGraphs}, {&Graphs.markerBehavior.showDataOnGraphs, "Graphs.markerBehavior.ShowDataOnGraphs", true}, {&Graphs.markerBehavior.showAllData, "Graphs.markerBehavior.ShowAllData", false}, diff --git a/Software/PC_Application/preferencesdialog.ui b/Software/PC_Application/preferencesdialog.ui index fc477d1..23b3fb5 100644 --- a/Software/PC_Application/preferencesdialog.ui +++ b/Software/PC_Application/preferencesdialog.ui @@ -13,8 +13,8 @@ Preferences - - + + @@ -78,7 +78,7 @@ - 3 + 2 @@ -690,18 +690,53 @@ - - - - Divisions: + + + + Ticks - - - - - - + + false + + + + + + + + false + + + false + + + + + + + Tick lines: + + + + + + + + + + + + + + Different background for every 2nd Y tick + + + true + + + + @@ -873,7 +908,7 @@ - + Qt::Horizontal