gui/plotxy: implement background ticks
Improve trace readability when is displayed on xy plot. The user is able to enable this option throughout preferences dialog.
This commit is contained in:
parent
ea8693566f
commit
6ef0d9e87a
@ -153,7 +153,7 @@ void TraceSmithChart::draw(QPainter &p) {
|
|||||||
p.drawArc(rectangle, 0, 5760);
|
p.drawArc(rectangle, 0, 5760);
|
||||||
|
|
||||||
constexpr int Circles = 6;
|
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);
|
pen.setCosmetic(true);
|
||||||
p.setPen(pen);
|
p.setPen(pen);
|
||||||
for(int i=1;i<Circles;i++) {
|
for(int i=1;i<Circles;i++) {
|
||||||
|
@ -360,6 +360,7 @@ void TraceXYPlot::draw(QPainter &p)
|
|||||||
p.setPen(pen);
|
p.setPen(pen);
|
||||||
plotAreaLeft = YAxis[0].type == YAxisType::Disabled ? yAxisDisabledSpace : yAxisSpace;
|
plotAreaLeft = YAxis[0].type == YAxisType::Disabled ? yAxisDisabledSpace : yAxisSpace;
|
||||||
plotAreaWidth = w.width();
|
plotAreaWidth = w.width();
|
||||||
|
plotAreaTop = 10;
|
||||||
plotAreaBottom = w.height() - xAxisSpace;
|
plotAreaBottom = w.height() - xAxisSpace;
|
||||||
if(YAxis[0].type != YAxisType::Disabled) {
|
if(YAxis[0].type != YAxisType::Disabled) {
|
||||||
plotAreaWidth -= yAxisSpace;
|
plotAreaWidth -= yAxisSpace;
|
||||||
@ -372,7 +373,7 @@ void TraceXYPlot::draw(QPainter &p)
|
|||||||
plotAreaWidth -= yAxisDisabledSpace;
|
plotAreaWidth -= yAxisDisabledSpace;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto plotRect = QRect(plotAreaLeft, 0, plotAreaWidth + 1, plotAreaBottom);
|
auto plotRect = QRect(plotAreaLeft, plotAreaTop, plotAreaWidth + 1, plotAreaBottom-plotAreaTop);
|
||||||
p.drawRect(plotRect);
|
p.drawRect(plotRect);
|
||||||
|
|
||||||
// draw axis types
|
// draw axis types
|
||||||
@ -437,8 +438,8 @@ void TraceXYPlot::draw(QPainter &p)
|
|||||||
}
|
}
|
||||||
p.drawLine(xCoord, plotAreaBottom, xCoord, plotAreaBottom + 2);
|
p.drawLine(xCoord, plotAreaBottom, xCoord, plotAreaBottom + 2);
|
||||||
if(xCoord != plotAreaLeft && xCoord != plotAreaLeft + plotAreaWidth) {
|
if(xCoord != plotAreaLeft && xCoord != plotAreaLeft + plotAreaWidth) {
|
||||||
p.setPen(QPen(pref.Graphs.Color.divisions, 0.5, Qt::DashLine));
|
p.setPen(QPen(pref.Graphs.Color.Ticks.divisions, 0.5, Qt::DashLine));
|
||||||
p.drawLine(xCoord, 0, xCoord, plotAreaBottom);
|
p.drawLine(xCoord, plotAreaTop, xCoord, plotAreaBottom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -467,14 +468,18 @@ void TraceXYPlot::draw(QPainter &p)
|
|||||||
step = max / 1000;
|
step = max / 1000;
|
||||||
}
|
}
|
||||||
int significantDigits = floor(log10(max)) - floor(log10(step)) + 1;
|
int significantDigits = floor(log10(max)) - floor(log10(step)) + 1;
|
||||||
for(auto t : YAxis[i].ticks) {
|
|
||||||
auto yCoord = Util::Scale<double>(t, YAxis[i].rangeMax, YAxis[i].rangeMin, 0, w.height() - xAxisSpace);
|
auto yCoordWidth = 0;
|
||||||
|
auto yCoordLast = 0;
|
||||||
|
|
||||||
|
for(unsigned int j = 0; j < YAxis[i].ticks.size(); j++) {
|
||||||
|
auto yCoord = Util::Scale<double>(YAxis[i].ticks[j], YAxis[i].rangeMax, YAxis[i].rangeMin, plotAreaTop, w.height() - xAxisSpace);
|
||||||
p.setPen(QPen(pref.Graphs.Color.axis, 1));
|
p.setPen(QPen(pref.Graphs.Color.axis, 1));
|
||||||
// draw tickmark on axis
|
// draw tickmark on axis
|
||||||
auto tickStart = i == 0 ? plotAreaLeft : plotAreaLeft + plotAreaWidth;
|
auto tickStart = i == 0 ? plotAreaLeft : plotAreaLeft + plotAreaWidth;
|
||||||
auto tickLen = i == 0 ? -2 : 2;
|
auto tickLen = i == 0 ? -2 : 2;
|
||||||
p.drawLine(tickStart, yCoord, tickStart + tickLen, yCoord);
|
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) {
|
if(i == 0) {
|
||||||
p.drawText(QRectF(0, yCoord - AxisLabelSize/2 - 2, tickStart + 2 * tickLen, AxisLabelSize), Qt::AlignRight, tickValue);
|
p.drawText(QRectF(0, yCoord - AxisLabelSize/2 - 2, tickStart + 2 * tickLen, AxisLabelSize), Qt::AlignRight, tickValue);
|
||||||
} else {
|
} else {
|
||||||
@ -482,14 +487,25 @@ void TraceXYPlot::draw(QPainter &p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// tick lines
|
// tick lines
|
||||||
if(yCoord == 0 || yCoord == w.height() - xAxisSpace) {
|
if(yCoord == plotAreaTop || yCoord == w.height() - xAxisSpace) {
|
||||||
// skip tick lines right on the plot borders
|
// skip tick lines right on the plot borders
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(i == 0) {
|
if(i == 0) {
|
||||||
// only draw tick lines for primary axis
|
// only draw tick lines for primary axis
|
||||||
p.setPen(QPen(pref.Graphs.Color.divisions, 0.5, Qt::DashLine));
|
p.setPen(QPen(pref.Graphs.Color.Ticks.divisions, 0.5, Qt::DashLine));
|
||||||
p.drawLine(plotAreaLeft, yCoord, plotAreaLeft + plotAreaWidth, yCoord);
|
p.drawLine(plotAreaLeft, yCoord, plotAreaLeft + plotAreaWidth, yCoord);
|
||||||
|
|
||||||
|
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);
|
||||||
|
auto rect = QRect(plotAreaLeft, yCoord, plotAreaWidth, yCoordWidth);
|
||||||
|
p.drawRect(rect);
|
||||||
|
}
|
||||||
|
yCoordLast = yCoord;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -947,7 +963,7 @@ QPoint TraceXYPlot::plotValueToPixel(QPointF plotValue, int Yaxis)
|
|||||||
{
|
{
|
||||||
QPoint p;
|
QPoint p;
|
||||||
p.setX(Util::Scale<double>(plotValue.x(), XAxis.rangeMin, XAxis.rangeMax, plotAreaLeft, plotAreaLeft + plotAreaWidth));
|
p.setX(Util::Scale<double>(plotValue.x(), XAxis.rangeMin, XAxis.rangeMax, plotAreaLeft, plotAreaLeft + plotAreaWidth));
|
||||||
p.setY(Util::Scale<double>(plotValue.y(), YAxis[Yaxis].rangeMin, YAxis[Yaxis].rangeMax, plotAreaBottom, 0));
|
p.setY(Util::Scale<double>(plotValue.y(), YAxis[Yaxis].rangeMin, YAxis[Yaxis].rangeMax, plotAreaBottom, plotAreaTop));
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -955,7 +971,7 @@ QPointF TraceXYPlot::pixelToPlotValue(QPoint pixel, int Yaxis)
|
|||||||
{
|
{
|
||||||
QPointF p;
|
QPointF p;
|
||||||
p.setX(Util::Scale<double>(pixel.x(), plotAreaLeft, plotAreaLeft + plotAreaWidth, XAxis.rangeMin, XAxis.rangeMax));
|
p.setX(Util::Scale<double>(pixel.x(), plotAreaLeft, plotAreaLeft + plotAreaWidth, XAxis.rangeMin, XAxis.rangeMax));
|
||||||
p.setY(Util::Scale<double>(pixel.y(), plotAreaBottom, 0, YAxis[Yaxis].rangeMin, YAxis[Yaxis].rangeMax));
|
p.setY(Util::Scale<double>(pixel.y(), plotAreaBottom, plotAreaTop, YAxis[Yaxis].rangeMin, YAxis[Yaxis].rangeMax));
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ private:
|
|||||||
YAxis YAxis[2];
|
YAxis YAxis[2];
|
||||||
XAxis XAxis;
|
XAxis XAxis;
|
||||||
|
|
||||||
int plotAreaLeft, plotAreaWidth, plotAreaBottom;
|
int plotAreaLeft, plotAreaWidth, plotAreaBottom, plotAreaTop;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TRACEXYPLOT_H
|
#endif // TRACEXYPLOT_H
|
||||||
|
@ -134,7 +134,9 @@ PreferencesDialog::PreferencesDialog(Preferences *pref, QWidget *parent) :
|
|||||||
p->Acquisition.RBWLimitForDFT = ui->AcquisitionDFTlimitRBW->value();
|
p->Acquisition.RBWLimitForDFT = ui->AcquisitionDFTlimitRBW->value();
|
||||||
p->Graphs.Color.background = ui->GraphsColorBackground->getColor();
|
p->Graphs.Color.background = ui->GraphsColorBackground->getColor();
|
||||||
p->Graphs.Color.axis = ui->GraphsColorAxis->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.domainChangeBehavior = (GraphDomainChangeBehavior) ui->GraphsDomainChangeBehavior->currentIndex();
|
||||||
p->Graphs.markerBehavior.showDataOnGraphs = ui->GraphsShowMarkerData->isChecked();
|
p->Graphs.markerBehavior.showDataOnGraphs = ui->GraphsShowMarkerData->isChecked();
|
||||||
p->Graphs.markerBehavior.showAllData = ui->GraphsShowAllMarkerData->isChecked();
|
p->Graphs.markerBehavior.showAllData = ui->GraphsShowAllMarkerData->isChecked();
|
||||||
@ -198,7 +200,9 @@ void PreferencesDialog::setInitialGUIState()
|
|||||||
|
|
||||||
ui->GraphsColorBackground->setColor(p->Graphs.Color.background);
|
ui->GraphsColorBackground->setColor(p->Graphs.Color.background);
|
||||||
ui->GraphsColorAxis->setColor(p->Graphs.Color.axis);
|
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->GraphsDomainChangeBehavior->setCurrentIndex((int) p->Graphs.domainChangeBehavior);
|
||||||
ui->GraphsShowMarkerData->setChecked(p->Graphs.markerBehavior.showDataOnGraphs);
|
ui->GraphsShowMarkerData->setChecked(p->Graphs.markerBehavior.showDataOnGraphs);
|
||||||
ui->GraphsShowAllMarkerData->setChecked(p->Graphs.markerBehavior.showAllData);
|
ui->GraphsShowAllMarkerData->setChecked(p->Graphs.markerBehavior.showAllData);
|
||||||
|
@ -70,7 +70,13 @@ public:
|
|||||||
struct {
|
struct {
|
||||||
QColor background;
|
QColor background;
|
||||||
QColor axis;
|
QColor axis;
|
||||||
|
struct {
|
||||||
QColor divisions;
|
QColor divisions;
|
||||||
|
struct {
|
||||||
|
bool enabled;
|
||||||
|
QColor background;
|
||||||
|
} Background;
|
||||||
|
} Ticks;
|
||||||
} Color;
|
} Color;
|
||||||
GraphDomainChangeBehavior domainChangeBehavior;
|
GraphDomainChangeBehavior domainChangeBehavior;
|
||||||
struct {
|
struct {
|
||||||
@ -93,7 +99,7 @@ private:
|
|||||||
QString name;
|
QString name;
|
||||||
QVariant def;
|
QVariant def;
|
||||||
};
|
};
|
||||||
const std::array<SettingDescription, 35> descr = {{
|
const std::array<SettingDescription, 37> descr = {{
|
||||||
{&Startup.ConnectToFirstDevice, "Startup.ConnectToFirstDevice", true},
|
{&Startup.ConnectToFirstDevice, "Startup.ConnectToFirstDevice", true},
|
||||||
{&Startup.RememberSweepSettings, "Startup.RememberSweepSettings", false},
|
{&Startup.RememberSweepSettings, "Startup.RememberSweepSettings", false},
|
||||||
{&Startup.DefaultSweep.type, "Startup.DefaultSweep.type", "Frequency"},
|
{&Startup.DefaultSweep.type, "Startup.DefaultSweep.type", "Frequency"},
|
||||||
@ -123,7 +129,9 @@ private:
|
|||||||
{&Acquisition.RBWLimitForDFT, "Acquisition.RBWLimitForDFT", 3000.0},
|
{&Acquisition.RBWLimitForDFT, "Acquisition.RBWLimitForDFT", 3000.0},
|
||||||
{&Graphs.Color.background, "Graphs.Color.background", QColor(Qt::black)},
|
{&Graphs.Color.background, "Graphs.Color.background", QColor(Qt::black)},
|
||||||
{&Graphs.Color.axis, "Graphs.Color.axis", QColor(Qt::white)},
|
{&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(Qt::white)},
|
||||||
|
{&Graphs.Color.Ticks.divisions, "Graphs.Color.Ticks.divisions", QColor(Qt::gray)},
|
||||||
{&Graphs.domainChangeBehavior, "Graphs.domainChangeBehavior", GraphDomainChangeBehavior::AdjustGraphs},
|
{&Graphs.domainChangeBehavior, "Graphs.domainChangeBehavior", GraphDomainChangeBehavior::AdjustGraphs},
|
||||||
{&Graphs.markerBehavior.showDataOnGraphs, "Graphs.markerBehavior.ShowDataOnGraphs", true},
|
{&Graphs.markerBehavior.showDataOnGraphs, "Graphs.markerBehavior.ShowDataOnGraphs", true},
|
||||||
{&Graphs.markerBehavior.showAllData, "Graphs.markerBehavior.ShowAllData", false},
|
{&Graphs.markerBehavior.showAllData, "Graphs.markerBehavior.ShowAllData", false},
|
||||||
|
@ -13,8 +13,8 @@
|
|||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Preferences</string>
|
<string>Preferences</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QFormLayout" name="formLayout">
|
<layout class="QVBoxLayout" name="verticalLayout_13">
|
||||||
<item row="0" column="0">
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0">
|
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTreeWidget" name="treeWidget">
|
<widget class="QTreeWidget" name="treeWidget">
|
||||||
@ -78,7 +78,7 @@
|
|||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>3</number>
|
<number>2</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="Startup">
|
<widget class="QWidget" name="Startup">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||||
@ -690,6 +690,28 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="3" column="0" colspan="2">
|
||||||
|
<widget class="QGroupBox" name="groupBox_13">
|
||||||
|
<property name="title">
|
||||||
|
<string>Ticks</string>
|
||||||
|
</property>
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="ColorPickerButton" name="GraphsColorTicksBackground">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QLabel" name="label_17">
|
<widget class="QLabel" name="label_17">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -698,12 +720,25 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="2" column="1">
|
||||||
<widget class="ColorPickerButton" name="GraphsColorDivisions">
|
<widget class="ColorPickerButton" name="GraphsColorTicksDivisions">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QCheckBox" name="GraphsColorTicksBackgroundEnabled">
|
||||||
|
<property name="text">
|
||||||
|
<string>Enable background</string>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -873,7 +908,7 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item>
|
||||||
<widget class="QDialogButtonBox" name="buttonBox">
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
|
Loading…
Reference in New Issue
Block a user