738 lines
29 KiB
C++
738 lines
29 KiB
C++
#pragma once
|
||
#include <QHBoxLayout>
|
||
#include <QLabel>
|
||
#include <QLineEdit>
|
||
#include <QWidgetAction>
|
||
#include <QDebug>
|
||
#include <QMenu>
|
||
#include "../GenerateMockData.h"
|
||
#include "../RenderAble.h"
|
||
#include "../base/Plot.h"
|
||
#include "../GlobalTypes.h"
|
||
#include <QColorDialog>
|
||
#include <QPushButton>
|
||
#include <QFontMetrics>
|
||
#include "../base/MutiSelectRect.h"
|
||
#include "../plottable/Afterglow.h"
|
||
#include "../plottable/AudioFrequent.h"
|
||
#include "../plottable/Planisphere.h"
|
||
#include "../plottable/WaterFall.h"
|
||
#include "../plottable/Spectrum.h"
|
||
#include "../plottable/SweepFrequent.h"
|
||
#include "../Axis/TimeAxis.h"
|
||
#include "../Axis/AbsAxis.h"
|
||
#include "../Axis/FrequentAxis.h"
|
||
#include <QRandomGenerator>
|
||
#include <QScrollArea>
|
||
#include <QMenu>
|
||
#include <QWidgetAction>
|
||
#include <QApplication>
|
||
#include "../base/SelectColorDialog/SelectColorDialog.h"
|
||
|
||
namespace YSG {
|
||
|
||
|
||
static QColor getColor(int lowest, int highest) {
|
||
int r = QRandomGenerator::global()->bounded(lowest, highest);
|
||
int g = QRandomGenerator::global()->bounded(lowest, highest);
|
||
int b = QRandomGenerator::global()->bounded(lowest, highest);
|
||
return {r, g, b};
|
||
}
|
||
|
||
static QString getBackgroundStyleSheet() {
|
||
QString color = QString("background-color: %1;").arg(getColor(176, 256).name());
|
||
return color;
|
||
}
|
||
|
||
static QString getButtonStyleSheet() {
|
||
QString color = QString("background-color: %1; color: #000000;").arg(getColor(200, 256).name());
|
||
return color;
|
||
}
|
||
|
||
template<typename T>
|
||
QString getInitValue(const T& value) {
|
||
return QString::number(value);
|
||
}
|
||
template<>
|
||
inline QString getInitValue<QString>(const QString& value) {
|
||
return value;
|
||
}
|
||
|
||
template<typename T>
|
||
T getValueFromString(const QString& value) {
|
||
return value.toDouble();
|
||
}
|
||
template<>
|
||
inline QString getValueFromString<QString>(const QString& value) {
|
||
return value;
|
||
}
|
||
|
||
|
||
template<typename T>
|
||
static QWidget* createEditWidget_List(const QString& buttonText,
|
||
const std::function<void(const QVector<T>&)>& click, const QVector<T>& initValues) {
|
||
auto container = new QWidget;
|
||
auto layout = new QHBoxLayout(container);
|
||
layout->setAlignment(Qt::AlignLeft);
|
||
layout->setContentsMargins(0 ,0, 0, 0);
|
||
auto confirm = new QPushButton(buttonText);
|
||
// QApplication* app = (QApplication*)QApplication::instance();
|
||
// qDebug() << "Global StyleSheet:" << app->styleSheet();
|
||
confirm->setStyleSheet(getButtonStyleSheet());
|
||
|
||
// 清除 QSS
|
||
|
||
|
||
QFont font;
|
||
font.setFamily("Segoe UI");
|
||
confirm->setFont(font);
|
||
confirm->setMinimumWidth(QFontMetrics(confirm->font()).horizontalAdvance(buttonText) + 8);
|
||
confirm->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||
layout->addWidget(confirm);
|
||
QVector<QLineEdit*> lineEditList;
|
||
for(const T& initValue : initValues) {
|
||
QString initValueStr = getInitValue<T>(initValue);
|
||
auto curEdit = new QLineEdit(initValueStr);
|
||
curEdit->setStyleSheet(getButtonStyleSheet());
|
||
// curEdit->setMaximumWidth(50);
|
||
auto fm = QFontMetrics(QFont());
|
||
int width = fm.horizontalAdvance(initValueStr);
|
||
// curEdit->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
|
||
curEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||
int w = qMax((int)((double)width * 1.4) + 16, 50);
|
||
curEdit->setMinimumWidth(w);
|
||
lineEditList.append(curEdit);
|
||
layout->addWidget(curEdit);
|
||
}
|
||
|
||
|
||
|
||
QObject::connect(confirm, &QPushButton::clicked, [lineEditList, click]() {
|
||
QVector<T> values;
|
||
for(QLineEdit* lineEdit : lineEditList) {
|
||
values.append(getValueFromString<T>(lineEdit->text()));
|
||
}
|
||
click(values);
|
||
});
|
||
return container;
|
||
}
|
||
|
||
|
||
template<typename T>
|
||
static QWidget* createEditWidget(const QString& buttonText,
|
||
const std::function<void(const T&)>& click, const T& initValues) {
|
||
return createEditWidget_List<T>(buttonText, [click](const QVector<T>& data) {
|
||
click(data.first());
|
||
}, QVector<T>{initValues});
|
||
}
|
||
|
||
static QWidget* createRange(Axis* axis, const QString& text = "更改轴范围") {
|
||
return createEditWidget_List<double>(text, [axis](const QVector<double>& values) {
|
||
axis->set_coordRange(Range{values[0], values[1]});
|
||
}, {axis->coordRange().lower, axis->coordRange().upper});
|
||
}
|
||
|
||
static QMenu* findParentMenu(QWidget* widget) {
|
||
// 从当前窗口开始,逐步检查父窗口
|
||
QWidget* parent = widget->parentWidget();
|
||
while (parent) {
|
||
if (QMenu* menu = qobject_cast<QMenu*>(parent)) {
|
||
return menu; // 找到第一个 QMenu 类型的父窗口
|
||
}
|
||
parent = parent->parentWidget();
|
||
}
|
||
return nullptr; // 如果没有找到 QMenu 类型的父窗口
|
||
}
|
||
|
||
static QWidget* createSelectColor(const QString& text, const std::function<void(QColor)>& click, const QColor& color = QColor()) {
|
||
auto ret = new QWidget;
|
||
auto l = new QHBoxLayout(ret);
|
||
l->setContentsMargins(0, 0, 0, 0);
|
||
//l->setSpacing(0);
|
||
QString bs = getButtonStyleSheet();
|
||
auto showColor = new QWidget;
|
||
showColor->setStyleSheet(QString("background-color: %1; border: 2px solid #000000;").arg(color.name(QColor::HexArgb)));
|
||
showColor->setFixedWidth(30);
|
||
static QPushButton *btn = nullptr;
|
||
//static auto dialog = new CustomColorDialog(Qt::white, QApplication::activeWindow());
|
||
static auto dialog = new SelectColorDialog;
|
||
dialog->resize(800, 600);
|
||
// dialog->adjustSize();
|
||
auto label = new QLineEdit(color.isValid() ? color.name(QColor::HexArgb) : "无效");
|
||
label->setAlignment(Qt::AlignCenter);
|
||
label->setStyleSheet("background-color: #ffffff; color: #000000;");
|
||
//label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
||
auto button = new QPushButton(text);
|
||
button->setStyleSheet(bs);
|
||
QObject::connect(button, &QPushButton::clicked, [button, label]() {
|
||
btn = button;
|
||
dialog->setCurrentColor(QColor(label->text()));
|
||
dialog->show();
|
||
});
|
||
QObject::connect(dialog, &QDialog::finished, [ret, button, click, label, showColor](int result) {
|
||
if(btn != button) return;
|
||
if (result == QDialog::Accepted) {
|
||
QColor selectColor = dialog->currentColor();
|
||
click(selectColor);
|
||
label->setText(selectColor.name(QColor::HexArgb));
|
||
showColor->setStyleSheet(QString("background-color: %1; border: 2px solid #000000;")
|
||
.arg(selectColor.name(QColor::HexArgb)));
|
||
} else if (result == -1) {
|
||
click(QColor());
|
||
label->setText("无颜色");
|
||
showColor->setStyleSheet(QString("background-color: rgba(255, 255, 255, 0); border: 2px solid #000000;"));
|
||
}
|
||
QMenu* menu = findParentMenu(ret);
|
||
if(menu) {
|
||
menu->show();
|
||
}
|
||
});
|
||
l->addWidget(button);
|
||
l->addWidget(label);
|
||
l->addWidget(showColor);
|
||
return ret;
|
||
}
|
||
|
||
static QPushButton *createButton(const QString& text, const std::function<void(void)>& click) {
|
||
auto button = new QPushButton(text);
|
||
button->setStyleSheet(getButtonStyleSheet());
|
||
QObject::connect(button, &QPushButton::clicked, [click]() {
|
||
click();
|
||
});
|
||
return button;
|
||
}
|
||
|
||
|
||
|
||
static QPushButton *createToggleButton(const QString& text, const QString& text2, const std::function<void()>& click, bool firstState) {
|
||
auto button = new QPushButton(firstState ? text : text2);
|
||
button->setStyleSheet(getButtonStyleSheet());
|
||
QObject::connect(button, &QPushButton::clicked, [button, click, text, text2]() {
|
||
click();
|
||
if(button->text() == text2) {
|
||
button->setText(text);
|
||
} else {
|
||
button->setText(text2);
|
||
}
|
||
});
|
||
return button;
|
||
}
|
||
|
||
|
||
static QLabel* createLabel(const QString& text, int h = 50, const QColor& color = Qt::black) {
|
||
auto l = new QLabel(text);
|
||
QFont font;
|
||
font.setFamily("Segoe UI");
|
||
font.setBold(true);
|
||
l->setFont(font);
|
||
l->setFixedHeight(h);
|
||
l->setAlignment(Qt::AlignHCenter | Qt::AlignBottom);
|
||
l->setStyleSheet(QString("color: %1;").arg(color.name(QColor::HexArgb)));
|
||
return l;
|
||
}
|
||
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
static QVector<QWidget*> bw(const QVector<QWidget*>& widgets, const QString& name) {
|
||
if(widgets.empty()) return {};
|
||
auto ret = new QWidget;
|
||
ret->setStyleSheet(YSG::getBackgroundStyleSheet());
|
||
auto l = new QVBoxLayout(ret);
|
||
auto label = new QLabel(name);
|
||
label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||
QFontMetrics fm(label->font());
|
||
label->setFixedSize(fm.horizontalAdvance(name) + 16, fm.height() + 8);
|
||
label->setStyleSheet(QString("color: %1; background-color: %2; padding: 0px; margin: 0px;")
|
||
.arg(
|
||
QColor(Qt::white).name(QColor::HexArgb),
|
||
QColor(Qt::black).name(QColor::HexArgb))
|
||
);
|
||
l->addWidget(label, 0, Qt::AlignHCenter | Qt::AlignBottom);
|
||
for(QWidget *w : widgets) {
|
||
l->addWidget(w);
|
||
}
|
||
return {ret};
|
||
}
|
||
|
||
static QWidget* createControl(YSG::Plot* plot, const QVector<QWidget*>& widgets = {}) {
|
||
auto control = new QWidget;
|
||
auto l = new QVBoxLayout(control);
|
||
l->setAlignment(Qt::AlignTop);
|
||
l->setContentsMargins({0, 0, 0, 0});
|
||
l->setSpacing(0);
|
||
QVector<QWidget*> ws = {
|
||
YSG::createToggleButton("暂停渲染", "开始渲染", [plot]() {
|
||
plot->isRendering() ? plot->pauseRender() : plot->startRender();
|
||
}, plot->isRendering()),
|
||
YSG::createToggleButton("停止性能测试", "启动性能测试", [plot]() {
|
||
plot->set_usePerformanceShower(plot->usePerformanceShower() ? false : true);
|
||
}, plot->usePerformanceShower()),
|
||
YSG::createSelectColor("更改背景色", [plot](const QColor& color) {
|
||
plot->setBackgroundColor(color);
|
||
}, plot->backgroundColor()),
|
||
YSG::createEditWidget_List<int>("渲染数据Timer", [plot](QVector<int> data) {
|
||
if(data[0] < 0) {
|
||
plot->pauseRender();
|
||
} else {
|
||
plot->startRender(data[0]);
|
||
}
|
||
}, {30}),
|
||
};
|
||
|
||
|
||
for(QWidget* cur : bw(ws, "plot基础") + widgets) {
|
||
l->addWidget(cur);
|
||
}
|
||
return control;
|
||
}
|
||
|
||
static QVector<QWidget*> cw(YSG::AbsAxis* it) {
|
||
if(it == nullptr) return{};
|
||
auto t = QVector<QWidget*> {
|
||
YSG::createButton("反转轴整体方向", [it](){
|
||
it->set_orientation(it->orientation() == Qt::Horizontal ? Qt::Vertical : Qt::Horizontal);
|
||
}),
|
||
YSG::createEditWidget_List<int>("主刻度值", [it](const QVector<int>& values) {
|
||
it->set_tickLength(values[0]);
|
||
}, {it->tickLength()}),
|
||
YSG::createEditWidget_List<int>("子刻度值", [it](const QVector<int>& values) {
|
||
it->set_subTickLength(values[0]);
|
||
}, {it->subTickLength()}),
|
||
YSG::createSelectColor("更改轴颜色", [it](const QColor& color) {
|
||
it->set_color(color);
|
||
}, it->color()),
|
||
YSG::createEditWidget_List<QString>("设置单位", [it](const QVector<QString>& values) {
|
||
it->set_unitText(values[0]);
|
||
}, {it->unitText()}),
|
||
YSG::createSelectColor("更改UnitText颜色", [it](const QColor& color) {
|
||
it->set_unitTextPen(QPen(color));
|
||
}, it->color()),
|
||
YSG::createSelectColor("更改UnitText背景色", [it](const QColor& color) {
|
||
it->set_unitTextBackgroundBrush(QBrush(color));
|
||
}, it->color()),
|
||
YSG::createEditWidget_List<int>("更改刻度斜度", [it](const QVector<int>& values) {
|
||
it->set_rotate(values[0]);
|
||
}, {it->rotate()}),
|
||
};
|
||
return t;
|
||
}
|
||
|
||
static QVector<QWidget*> cw(YSG::Axis* it) {
|
||
if(it == nullptr) return{};
|
||
auto t = QVector<QWidget*> {
|
||
YSG::createRange(it),
|
||
};
|
||
return cw(dynamic_cast<YSG::AbsAxis*>(it)) + t;
|
||
}
|
||
|
||
static QVector<QWidget*> cw(YSG::FrequentAxis* it) {
|
||
if(it == nullptr) return{};
|
||
auto t = QVector<QWidget*> {
|
||
|
||
};
|
||
return cw(dynamic_cast<YSG::Axis*>(it)) + t;
|
||
}
|
||
|
||
static QVector<QWidget*> cw(YSG::TimeAxis* it, int numPreSecond = -1) {
|
||
if(it == nullptr) return{};
|
||
auto t = QVector<QWidget*> {
|
||
YSG::createEditWidget_List<QString>("时间格式", [it](QVector<QString> data) {
|
||
it->set_timeFormat(data[0]);
|
||
}, {it->timeFormat()}),
|
||
YSG::createEditWidget_List<int>("单位间隔pixel", [it](QVector<int> data) {
|
||
it->set_tickPixelSpace(data[0]);
|
||
}, {it->tickPixelSpace()}),
|
||
};
|
||
|
||
auto timer = new QTimer(it->mPlot);
|
||
if(numPreSecond > 0) timer->start(static_cast<int>(1000.0/static_cast<double>(numPreSecond)));
|
||
QObject::connect(timer, &QTimer::timeout, [it]() {
|
||
it->giveData(QTime::currentTime());
|
||
});
|
||
t.append(YSG::createEditWidget_List<double>("推数据Timer(次/s)", [timer](QVector<double> data) {
|
||
if(data[0] < 0) {
|
||
timer->stop();
|
||
} else {
|
||
timer->start((int)(1000.0/data[0]));
|
||
}
|
||
}, {timer->interval() > 0 ? 1000.0/timer->interval() : -1} ));
|
||
return t + cw(dynamic_cast<YSG::AbsAxis*>(it));
|
||
}
|
||
|
||
|
||
static QVector<QWidget*> cw(YSG::MutiSelectRect* it) {
|
||
if(it == nullptr) return{};
|
||
auto t = QVector<QWidget*>{
|
||
YSG::createSelectColor("更改填充色", [it](const QColor& color) {
|
||
it->setRectBrush(QBrush(color));
|
||
}, it->rectBrush().color()),
|
||
YSG::createSelectColor("更改边框色", [it](const QColor& color) {
|
||
qDebug() << " color.isValid() == " << color.isValid();
|
||
QPen pen(color);
|
||
pen.setStyle(Qt::DashLine);
|
||
it->setBorderPen(pen);
|
||
qDebug() << " color.isValid() == " << pen.color().isValid();
|
||
}, it->borderPen().color()),
|
||
YSG::createSelectColor("更改字色", [it](const QColor& color) {
|
||
it->setFontPen(QPen(color));
|
||
}, it->fontPen().color())
|
||
};
|
||
return t;
|
||
}
|
||
|
||
template <typename T>
|
||
static QVector<QWidget*> cw(YSG::HoverInfoRenderAble<T>* it) {
|
||
if(it == nullptr) return{};
|
||
auto t = QVector<QWidget*>{
|
||
YSG::createLabel("悬浮信息"),
|
||
YSG::createToggleButton("启动悬浮信息", "停止悬浮信息", [it]() {
|
||
it->setUseHoverInfo(!it->useHoverInfo());
|
||
}, !it->useHoverInfo()),
|
||
YSG::createSelectColor("设置文字颜色", [it](const QColor& c) {
|
||
QPen pen = it->hoverInfoPen();
|
||
pen.setColor(c);
|
||
it->setHoverInfoPen(pen);
|
||
}, it->hoverInfoPen().color()),
|
||
YSG::createSelectColor("设置背景颜色", [it](const QColor& c) {
|
||
QBrush brush = it->hoverInfoBackgroundBrush();
|
||
brush.setColor(c);
|
||
it->setHoverInfoBackgroundBrush(brush);
|
||
}, it->hoverInfoBackgroundBrush().color())
|
||
};
|
||
|
||
return t;
|
||
}
|
||
|
||
static QVector<QWidget*> cw(YSG::WaterFall* it, int numPreSecond = -1) {
|
||
if(it == nullptr) return{};
|
||
auto timer = new QTimer(it->mPlot);
|
||
if(numPreSecond > 0) timer->start(static_cast<int>(1000.0/static_cast<double>(numPreSecond)));
|
||
QObject::connect(timer, &QTimer::timeout, [it]() {
|
||
QVector<double> d = YSG::getData(it->powerRange(), it->frequentPointSize());
|
||
int tick = it->timeAxis()->giveData(QTime::currentTime());
|
||
it->giveData(tick, d);
|
||
});
|
||
auto t = QVector<QWidget*> {
|
||
YSG::createEditWidget_List<double>("推数据Timer(次/s)", [timer](QVector<double> data) {
|
||
if(data[0] < 0) {
|
||
timer->stop();
|
||
} else {
|
||
timer->start((int)(1000.0/data[0]));
|
||
}
|
||
}, {timer->interval() > 0 ? 1000.0/timer->interval() : -1}),
|
||
};
|
||
return t + cw(static_cast<YSG::HoverInfoRenderAble<YSG::WaterFall>*>(it));
|
||
}
|
||
|
||
static QVector<QWidget*> cw(YSG::AudioFrequent* it, int numPreSecond = -1) {
|
||
if(it == nullptr) return{};
|
||
auto timer = new QTimer(it->mPlot);
|
||
if(numPreSecond > 0) timer->start(static_cast<int>(1000.0/static_cast<double>(numPreSecond)));
|
||
QObject::connect(timer, &QTimer::timeout, [it]() {
|
||
int tick = it->timeAxis()->giveData(QTime::currentTime());
|
||
it->giveData(tick, YSG::getData({0, 20}));
|
||
});
|
||
auto t = QVector<QWidget*> {
|
||
YSG::createEditWidget_List<double>("推数据Timer(次/s)", [timer](QVector<double> data) {
|
||
if(data[0] < 0) {
|
||
timer->stop();
|
||
} else {
|
||
timer->start((int)(1000.0/data[0]));
|
||
}
|
||
}, {timer->interval() > 0 ? 1000.0/timer->interval() : -1}),
|
||
};
|
||
return t;
|
||
}
|
||
|
||
static QVector<QWidget*> cw(YSG::Planisphere* it, int numPreSecond = -1) {
|
||
if(it == nullptr) return{};
|
||
auto timer = new QTimer(it->mPlot);
|
||
QObject::connect(timer, &QTimer::timeout, [it]() {
|
||
for(int i = 0; i < 10; ++i) {
|
||
double x = YSG::getData(it->IRange());
|
||
double y = YSG::getData(it->QRange());
|
||
it->giveData({x, y});
|
||
}
|
||
});
|
||
if(numPreSecond > 0) timer->start(static_cast<int>(1000.0/static_cast<double>(numPreSecond)));
|
||
|
||
auto t = QVector<QWidget*>{
|
||
YSG::createEditWidget_List<double>("推数据Timer(次/s)", [timer](QVector<double> data) {
|
||
if(data[0] < 0) {
|
||
timer->stop();
|
||
} else {
|
||
timer->start((int)(1000.0/data[0]));
|
||
}
|
||
}, {timer->interval() > 0 ? 1000.0/timer->interval() : -1}),
|
||
YSG::createEditWidget_List<int>("设置持续时间(ms)", [it](QVector<int> data) {
|
||
it->set_continueMillisecond(data[0]);
|
||
}, {it->continueMillisecond()}),
|
||
YSG::createSelectColor("更改IQ点颜色", [it](const QColor& color) {
|
||
it->set_pointColor(color);
|
||
}, it->pointColor()),
|
||
YSG::createSelectColor("更改锚点颜色", [it](const QColor& color) {
|
||
it->set_anchorColor(color);
|
||
}, it->anchorColor()),
|
||
YSG::createEditWidget_List<double>("I范围", [it](QVector<double> data) {
|
||
it->set_IRange({data[0], data[1]});
|
||
}, {it->IRange().lower, it->IRange().upper}),
|
||
YSG::createEditWidget_List<double>("Q范围", [it](QVector<double> data) {
|
||
it->set_QRange({data[0], data[1]});
|
||
}, {it->QRange().lower, it->QRange().upper}),
|
||
YSG::createButton("设置到轴中心", [it]() {
|
||
it->setToAxisCenter();
|
||
}),
|
||
};
|
||
return t;
|
||
}
|
||
|
||
|
||
static QVector<QWidget*> cw(YSG::Afterglow* it, int numPreSecond = -1) {
|
||
if(it == nullptr) return{};
|
||
static auto createBaseData = [it]() {
|
||
YSG::Range r = it->powerRange();
|
||
QVector<double> ret(it->frequentPointSize());
|
||
ret[0] = getData(r);
|
||
for(int i = 1; i < it->frequentPointSize(); ++i) {
|
||
double rate;
|
||
if(i % 20 == 0) {
|
||
double that = qAbs(ret[i - 1] - r.lower)/r.size() - 0.5;
|
||
rate = (1.0 - that) * YSG::getData({0.8, 1.2});
|
||
} else {
|
||
rate = YSG::getData({0.8, 1.2});
|
||
}
|
||
ret[i] = YSG::clamp(ret[i - 1]*rate, r.lower, r.upper);
|
||
}
|
||
return ret;
|
||
};
|
||
static QVector<double> baseData = createBaseData();
|
||
auto timer = new QTimer(it->mPlot);
|
||
QObject::connect(timer, &QTimer::timeout, [it]() {
|
||
YSG::Range r = it->powerRange();
|
||
int n = baseData.size();
|
||
QVector<double> curData(n);
|
||
for (int i = 0; i < n; ++i) {
|
||
double rate = YSG::getData({0.8, 1.2});
|
||
curData[i] = YSG::clamp(baseData[i]*rate, r.lower, r.upper);
|
||
}
|
||
it->giveData(curData);
|
||
});
|
||
if(numPreSecond > 0) timer->start(static_cast<int>(1000.0/static_cast<double>(numPreSecond)));
|
||
auto t = QVector<QWidget*>{
|
||
YSG::createEditWidget_List<double>("推数据Timer(次/s)", [timer](QVector<double> data) {
|
||
if(data[0] < 0) {
|
||
timer->stop();
|
||
} else {
|
||
timer->start((int)(1000.0/data[0]));
|
||
}
|
||
}, {timer->interval() > 0 ? 1000.0/timer->interval() : -1}),
|
||
YSG::createEditWidget_List<double>("频率范围", [it](QVector<double> data) {
|
||
it->set_frequentRange({data[0], data[1]});
|
||
}, {it->frequentRange().lower, it->frequentRange().upper}),
|
||
YSG::createEditWidget_List<double>("功率概率范围", [it](QVector<double> data) {
|
||
it->set_powerRange({data[0], data[1]});
|
||
}, {it->powerRange().lower, it->powerRange().upper}),
|
||
YSG::createButton("更改基础线", []() {
|
||
baseData = createBaseData();
|
||
}),
|
||
|
||
};
|
||
return t;
|
||
}
|
||
|
||
|
||
static QVector<QWidget*> cw(YSG::Spectrum* it, int numPreSecond = -1) {
|
||
if(it == nullptr) return{};
|
||
auto timer = new QTimer(it->mPlot);
|
||
if(numPreSecond > 0) timer->start(static_cast<int>(1000.0/static_cast<double>(numPreSecond)));
|
||
QObject::connect(timer, &QTimer::timeout, [it]() {
|
||
it->giveData(YSG::getData(it->powerAxis()->coordRange(), it->frequentPointSize()));
|
||
});
|
||
auto t = QVector<QWidget*> {
|
||
YSG::createEditWidget_List<double>("推数据Timer(次/s)", [timer](QVector<double> data) {
|
||
if(data[0] < 0) {
|
||
timer->stop();
|
||
} else {
|
||
timer->start((int)(1000.0/data[0]));
|
||
}
|
||
}, {timer->interval() > 0 ? 1000.0/timer->interval() : -1}),
|
||
YSG::createEditWidget_List<double>("频率范围", [it](QVector<double> data) {
|
||
it->set_frequentRange({data[0], data[1]});
|
||
}, {it->frequentRange().lower, it->frequentRange().upper}),
|
||
YSG::createEditWidget_List<int>("设置频率点数", [it](QVector<int> data) {
|
||
it->set_frequentPointSize(data[0]);
|
||
}, {it->frequentPointSize()}),
|
||
YSG::createLabel("sweepRect"),
|
||
YSG::createToggleButton("停止sweepRect", "启动sweepRect", [it]() {
|
||
it->set_useSweepFrequentRect(!it->useSweepFrequentRect());
|
||
}, it->useSweepFrequentRect()),
|
||
YSG::createEditWidget_List<double>("sweepRect 范围", [it](QVector<double> data) {
|
||
if(!it->useSweepFrequentRect()) it->set_useSweepFrequentRect(true);
|
||
it->set_sweepFrequentRange({data[0], data[1]});
|
||
}, {it->sweepFrequentRange().lower, it->sweepFrequentRange().upper}),
|
||
YSG::createEditWidget_List<double>("中频", [it](QVector<double> data) {
|
||
if(!it->useSweepFrequentRect()) it->set_useSweepFrequentRect(true);
|
||
it->set_middleSweepFrequent(data[0]);
|
||
}, {it->middleSweepFrequent()}),
|
||
YSG::createSelectColor("扫频矩形", [it](const QColor& c) {
|
||
it->set_sweepRectBrush(QBrush(c));
|
||
}),
|
||
YSG::createSelectColor("中频", [it](const QColor& c) {
|
||
if(!c.isValid()) {
|
||
it->set_middleFrequentPen(Qt::NoPen);
|
||
}
|
||
it->set_middleFrequentPen(QPen(c));
|
||
}, it->middleFrequentPen().color()),
|
||
YSG::createLabel("marker"),
|
||
YSG::createToggleButton("停止最大值marker", "启动最大值marker", [it]() {
|
||
it->set_useMaxMarker(!it->useMaxMarker());
|
||
}, it->useMaxMarker()),
|
||
YSG::createToggleButton("停止最小值marker", "启动最小值marker", [it]() {
|
||
it->set_useMinMarker(!it->useMinMarker());
|
||
}, it->useMinMarker()),
|
||
YSG::createEditWidget_List<double>("添加自定义marker", [it](QVector<double> data) {
|
||
it->addCustomMarker(data[0]);
|
||
}, {0}),
|
||
YSG::createEditWidget_List<double>("添加自定义Linemarker", [it](QVector<double> data) {
|
||
it->addCustomLineMarker(data[0]);
|
||
}, {0}),
|
||
YSG::createEditWidget_List<double>("删除marker", [it](QVector<double> data) {
|
||
it->removeCustomMarker(data[0]);
|
||
}, {0}),
|
||
YSG::createEditWidget_List<double>("清楚所有marker", [it](QVector<double> data) {
|
||
it->clearAllCustomMarker();
|
||
}, {}),
|
||
YSG::createEditWidget_List<int>("选择当前marker", [it](QVector<int> data) {
|
||
it->setSelectedLineMarker(data[0]);
|
||
}, {0}),
|
||
YSG::createEditWidget_List<double>("选择下一个marker", [it](QVector<double> data) {
|
||
it->selectNext();
|
||
}, {}),
|
||
YSG::createEditWidget_List<double>("选择上一个marker", [it](QVector<double> data) {
|
||
it->selectPrevious();
|
||
}, {}),
|
||
YSG::createLabel("当前线"),
|
||
YSG::createSelectColor("当前线色", [it](const QColor& c) {
|
||
if(!c.isValid()) {
|
||
it->set_curPen(Qt::NoPen);
|
||
return;
|
||
}
|
||
it->set_curPen(c);
|
||
}, it->curPen().color()),
|
||
YSG::createSelectColor("当前线填充色", [it](const QColor& c) {
|
||
it->set_curBrush(c);
|
||
}, it->curBrush().color()),
|
||
YSG::createLabel("最大值线"),
|
||
YSG::createToggleButton("停止最大值线", "启动最大值线",[it]() {
|
||
it->set_useMaxLine(!it->useMaxLine());
|
||
}, it->useMaxLine()),
|
||
YSG::createSelectColor("最大值线色", [it](const QColor& c) {
|
||
if(c.isValid()) {
|
||
it->set_maxPen(Qt::NoPen);
|
||
return;
|
||
}
|
||
it->set_maxPen(c);
|
||
}, it->maxPen().color()),
|
||
YSG::createSelectColor("最大值线填充色", [it](const QColor& c) {
|
||
it->set_maxBrush(c);
|
||
}, it->maxBrush().color()),
|
||
YSG::createLabel("最小值线"),
|
||
YSG::createToggleButton("停止最小值线", "启动最小值线", [it]() {
|
||
it->set_useMinLine(!it->useMinLine());
|
||
}, it->useMinLine()),
|
||
YSG::createSelectColor("最小值线色", [it](const QColor& c) {
|
||
it->set_minPen(c);
|
||
}, it->minPen().color()),
|
||
YSG::createSelectColor("最小值线填充色", [it](const QColor& c) {
|
||
it->set_minBrush(c);
|
||
}, it->minBrush().color()),
|
||
};
|
||
|
||
|
||
return cw(static_cast<YSG::HoverInfoRenderAble<YSG::Spectrum>*>(it)) + t;
|
||
}
|
||
|
||
static QVector<QWidget*> cw(YSG::SweepFrequent* it, int numPreSecond = -1) {
|
||
if(it == nullptr) return{};
|
||
auto timer = new QTimer(it->mPlot);
|
||
if(numPreSecond > 0) timer->start(static_cast<int>(1000.0/static_cast<double>(numPreSecond)));
|
||
QObject::connect(timer, &QTimer::timeout, [it]() {
|
||
it->giveData(YSG::getData(it->powerAxis()->coordRange(), it->blockFrequentPointSize()));
|
||
});
|
||
auto t = QVector<QWidget*> {
|
||
YSG::createEditWidget_List<double>("推数据Timer(次/s)", [timer](QVector<double> data) {
|
||
if(data[0] < 0) {
|
||
timer->stop();
|
||
} else {
|
||
timer->start((int)(1000.0/data[0]));
|
||
}
|
||
}, {timer->interval() > 0 ? 1000.0/timer->interval() : -1}),
|
||
YSG::createSelectColor("线颜色", [it](const QColor& color) {
|
||
it->set_pen(QPen(color));
|
||
}, it->pen().color()),
|
||
YSG::createSelectColor("扫频线颜色", [it](const QColor& color) {
|
||
QPen p = it->curFrequentPen();
|
||
p.setColor(color);
|
||
it->set_curFrequentPen(p);
|
||
}, it->curFrequentPen().color()),
|
||
YSG::createEditWidget_List<double>("频率范围", [it](const QVector<double>& data) {
|
||
it->set_frequentRange({data[0], data[1]});
|
||
}, {it->frequentRange().lower, it->frequentRange().upper})
|
||
};
|
||
return t;
|
||
}
|
||
|
||
static QMenu* createMenu(YSG::Plot* plot, const QVector<QWidget*>& widgets) {
|
||
auto menu = new QMenu(plot);
|
||
menu->setObjectName("memu");
|
||
//menu->setStyle(nullptr);
|
||
menu->hide();
|
||
menu->setContentsMargins(0 ,0, 0, 0);
|
||
auto container = createControl(plot, widgets);
|
||
auto scrollArea = new QScrollArea;
|
||
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||
scrollArea->setContentsMargins(0, 0, 0, 0);
|
||
scrollArea->setWidget(container);
|
||
scrollArea->setWidgetResizable(true);
|
||
scrollArea->setObjectName("scrollArea");
|
||
auto scrollAction = new QWidgetAction(menu);
|
||
scrollAction->setDefaultWidget(scrollArea);
|
||
menu->addAction(scrollAction);
|
||
return menu;
|
||
}
|
||
|
||
static QMenu* createMenu_Normal(QWidget* w, const QVector<QWidget*>& widgets) {
|
||
auto menu = new QMenu(w);
|
||
menu->setObjectName("memu_normal");
|
||
//menu->setStyle(nullptr);
|
||
menu->hide();
|
||
menu->setContentsMargins(0 ,0, 0, 0);
|
||
auto container = new QWidget;
|
||
auto l = new QVBoxLayout(container);
|
||
l->setAlignment(Qt::AlignTop);
|
||
l->setContentsMargins({0, 0, 0, 0});
|
||
l->setSpacing(4);
|
||
for (auto widget : widgets)
|
||
{
|
||
l->addWidget(widget);
|
||
}
|
||
auto scrollArea = new QScrollArea;
|
||
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||
scrollArea->setContentsMargins(0, 0, 0, 0);
|
||
scrollArea->setWidget(container);
|
||
scrollArea->setWidgetResizable(true);
|
||
scrollArea->setObjectName("scrollArea2");
|
||
auto scrollAction = new QWidgetAction(menu);
|
||
scrollAction->setDefaultWidget(scrollArea);
|
||
menu->addAction(scrollAction);
|
||
|
||
|
||
|
||
return menu;
|
||
}
|
||
|