64 lines
2.1 KiB
C++
64 lines
2.1 KiB
C++
#pragma once
|
|
#include "Tool.h"
|
|
|
|
static QWidget* createSpectrunPlot() {
|
|
class SpectrumPlot : public YSG::Plot {
|
|
public:
|
|
YSG::FrequentAxis *xAxis{};
|
|
YSG::Axis *yAxis{};
|
|
YSG::MutiSelectRect* msr{};
|
|
YSG::Spectrum *sp{};
|
|
QMenu *mMenu{};
|
|
void init() override {
|
|
Plot::init();
|
|
mObjectName = "SpectrumPlot";
|
|
xAxis = YSG::FrequentAxis::Builder(this, Qt::Horizontal)
|
|
.set_coordRange({0, 100})
|
|
.set_tickLength(-10)
|
|
.set_subTickLength(-5)
|
|
.set_use_wheel(true)
|
|
.set_use_drag(true)
|
|
.build();
|
|
|
|
yAxis = YSG::Axis::Builder(this, Qt::Vertical)
|
|
.set_coordRange({100, 0})
|
|
.set_unitText("功率")
|
|
.set_use_drag(true)
|
|
.build();
|
|
|
|
sp = YSG::Spectrum::Builder(xAxis, yAxis)
|
|
.set_frequentRange({0, 100})
|
|
.build();
|
|
|
|
msr = YSG::MutiSelectRect::Builder(xAxis, yAxis).build();
|
|
}
|
|
protected:
|
|
void resizeEvent(QResizeEvent* event) override {
|
|
int leftMargin = 20, rightMargin = 20, topMargin = 20, bottomMargin = 20;
|
|
int w = width() - leftMargin - rightMargin;
|
|
int h = height() - topMargin - bottomMargin;
|
|
xAxis->set_x(leftMargin);
|
|
xAxis->set_y(height() - bottomMargin);
|
|
xAxis->set_pixelSize(w);
|
|
yAxis->set_x(leftMargin);
|
|
yAxis->set_y(topMargin);
|
|
yAxis->set_pixelSize(h);
|
|
sp->set_frequentPointSize(sp->frequentAxis()->getPixelPointSize());
|
|
}
|
|
void contextMenuEvent(QContextMenuEvent* event) override {
|
|
if(!mMenu) {
|
|
auto ws =
|
|
bw(cw(sp, -1), "频谱图") +
|
|
bw(cw(xAxis), "频率x轴") +
|
|
bw(cw(yAxis), "功率y轴") +
|
|
bw(cw(msr), "多选框");
|
|
mMenu = createMenu(this, ws);
|
|
}
|
|
mMenu->exec(event->globalPos());
|
|
}
|
|
};
|
|
auto w = new SpectrumPlot;
|
|
w->init();
|
|
return w;
|
|
}
|