188 lines
5.9 KiB
C++
188 lines
5.9 KiB
C++
#include "Spectrum_p.h"
|
|
|
|
|
|
|
|
namespace YSG {
|
|
Q_Ptr_cpp(Spectrum)
|
|
PROP_P(Spectrum, FrequentAxis*, frequentAxis)
|
|
PROP_P(Spectrum, Axis*, powerAxis);
|
|
PROP_G(Spectrum, int, frequentPointSize);
|
|
PROP_G(Spectrum, Range, frequentRange);
|
|
PROP_P(Spectrum, double, middleSweepFrequent);
|
|
PROP_P(Spectrum, Range, sweepFrequentRange);
|
|
PROP_P(Spectrum, bool, useMaxLine);
|
|
PROP_P(Spectrum, bool, useMinLine);
|
|
PROP_P(Spectrum, bool, useMaxMarker);
|
|
PROP_P(Spectrum, bool, useMinMarker);
|
|
PROP_P(Spectrum, bool, useSweepFrequentRect);
|
|
PROP_P(Spectrum, QBrush, maxBrush);
|
|
PROP_P(Spectrum, QBrush, curBrush);
|
|
PROP_P(Spectrum, QBrush, minBrush);
|
|
PROP_P(Spectrum, QPen, maxPen);
|
|
PROP_P(Spectrum, QPen, curPen);
|
|
PROP_P(Spectrum, QPen, minPen);
|
|
PROP_P(Spectrum, QPen, selectMarkerPen);
|
|
PROP_P(Spectrum, QPen, markerPen);
|
|
PROP_P(Spectrum, QPen, middleFrequentPen);
|
|
PROP_P(Spectrum, QBrush, sweepRectBrush);
|
|
|
|
void Spectrum::set_frequentPointSize(int frequentPointSize) {
|
|
INIT_SET(Spectrum)
|
|
sc->frequentPointSize = frequentPointSize;
|
|
sc->updateFrequentPointSize(sc->frequentPointSize, sc->frequentRange);
|
|
}
|
|
|
|
void Spectrum::set_frequentRange(Range frequentRange){
|
|
INIT_SET(Spectrum)
|
|
sc->frequentRange = frequentRange;
|
|
sc->updateFrequentPointSize(sc->frequentPointSize, sc->frequentRange);
|
|
}
|
|
|
|
|
|
Spectrum::Builder::Builder(FrequentAxis* frequentAxis, Axis* powerAxis) {
|
|
ASSERT(frequentAxis->mPlot != nullptr, "Afterglow build error! frequentAxis->mPlot == nullptr");
|
|
ASSERT(frequentAxis->mPlot == powerAxis->mPlot, "Afterglow build error! frequentAxis->mPlot != powerAxis->mPlot");
|
|
plot = frequentAxis->mPlot;
|
|
this->frequentAxis = frequentAxis;
|
|
this->powerAxis = powerAxis;
|
|
}
|
|
Spectrum* Spectrum::Builder::build() {
|
|
auto ret = new Spectrum;
|
|
ret->init(plot, layerName);
|
|
SpectrumPrivate* pd = ret->d();
|
|
SpectrumRenderState* sc = reinterpret_cast<SpectrumRenderState*>(pd->state(State_Edit));
|
|
PROP_R(FrequentAxis*, frequentAxis)
|
|
PROP_R(Axis*, powerAxis);
|
|
PROP_R(int, frequentPointSize);
|
|
PROP_R(Range, frequentRange);
|
|
PROP_R(double, middleSweepFrequent);
|
|
PROP_R(Range, sweepFrequentRange);
|
|
PROP_R(bool, useMaxLine);
|
|
PROP_R(bool, useMinLine);
|
|
PROP_R(bool, useMaxMarker);
|
|
PROP_R(bool, useMinMarker);
|
|
PROP_R(bool, useSweepFrequentRect);
|
|
PROP_R(QBrush, maxBrush);
|
|
PROP_R(QBrush, curBrush);
|
|
PROP_R(QBrush, minBrush);
|
|
PROP_R(QPen, maxPen);
|
|
PROP_R(QPen, curPen);
|
|
PROP_R(QPen, minPen);
|
|
PROP_R(QPen, selectMarkerPen);
|
|
PROP_R(QPen, markerPen);
|
|
PROP_R(QPen, middleFrequentPen);
|
|
PROP_R(QBrush, sweepRectBrush);
|
|
sc->updateFrequentPointSize(sc->frequentPointSize, sc->frequentRange);
|
|
return ret;
|
|
}
|
|
|
|
Spectrum* SpectrumPrivate::q() {
|
|
return reinterpret_cast<Spectrum*>(qPtr);
|
|
}
|
|
void SpectrumPrivate::draw(QPainter* painter) {
|
|
auto s = renderState();
|
|
PerformanceShower *shower = q()->mPlot->d->mShower;
|
|
if(shower) {
|
|
shower->mInfoMap["mFrequentPointSize"] = PerformanceLine(QString("mFrequentPointSize:%1")
|
|
.arg(s->frequentPointSize));
|
|
}
|
|
s->draw(painter);
|
|
if(q()->hoverOK(q())) {
|
|
q()->drawHover(painter, s->frequentAxis, s->powerAxis);
|
|
}
|
|
}
|
|
|
|
|
|
void Spectrum::giveData(const QVector<double> &lineData){
|
|
if(!ok()) return;
|
|
INIT_SET(Spectrum)
|
|
sc->setFrenquentData(lineData);
|
|
}
|
|
|
|
void Spectrum::addCustomMarker(double frequent){
|
|
INIT_SET(Spectrum)
|
|
sc->markerList.append(Marker{frequent, false});
|
|
}
|
|
|
|
void Spectrum::addCustomLineMarker(double frequent){
|
|
INIT_SET(Spectrum)
|
|
sc->markerList.append(Marker{frequent, true});
|
|
}
|
|
|
|
void Spectrum::removeCustomMarker(double frequent){
|
|
INIT_SET(Spectrum)
|
|
for (Marker &marker: sc->markerList) {
|
|
if (qFuzzyCompare(marker.frequent, frequent)) {
|
|
sc->markerList.removeOne(marker);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void Spectrum::removeCurrentMarker(SRC src) {
|
|
INIT_SET(Spectrum)
|
|
sc->markerList.removeAt(sc->curSelectIndex);
|
|
}
|
|
|
|
void Spectrum::clearAllCustomMarker(SRC src) {
|
|
INIT_SET(Spectrum)
|
|
sc->markerList.clear();
|
|
}
|
|
|
|
double Spectrum::getMarkFrequent(int markIndex, SRC src) {
|
|
INIT_GET(Spectrum)
|
|
if (markIndex < 0 || markIndex >= renderState->markerList.size())
|
|
return -1;
|
|
return renderState->markerList[markIndex].frequent;
|
|
}
|
|
|
|
void Spectrum::setMarkerFrequent(int markerIndex, double frequent) {
|
|
INIT_SET(Spectrum)
|
|
QVector<Marker> &markers = sc->markerList;
|
|
if (markerIndex < 0 || markerIndex >= markers.size())
|
|
return;
|
|
markers[markerIndex].frequent = frequent;
|
|
}
|
|
|
|
void Spectrum::setCurrentMarkerFrequent(double frequent) {
|
|
INIT_SET(Spectrum)
|
|
sc->setCurFrequent(frequent);
|
|
}
|
|
|
|
int Spectrum::selectLineMarkerSize(SRC src) {
|
|
INIT_GET(Spectrum)
|
|
return renderState->markerList.size();
|
|
}
|
|
|
|
int Spectrum::curSelectMarkerIndex(SRC src) {
|
|
INIT_GET(Spectrum)
|
|
return renderState->curSelectIndex;
|
|
}
|
|
|
|
void Spectrum::setSelectedLineMarker(int markerIndex){
|
|
INIT_SET(Spectrum)
|
|
sc->setSelectIndex(markerIndex);
|
|
}
|
|
|
|
void Spectrum::selectNext(SRC src) {
|
|
INIT_SET(Spectrum)
|
|
sc->selectNextMarker();
|
|
}
|
|
|
|
void Spectrum::selectPrevious(SRC src) {
|
|
INIT_SET(Spectrum)
|
|
sc->selectPrevMarker();
|
|
}
|
|
|
|
void Spectrum::unSelectMarker(SRC src) {
|
|
INIT_SET(Spectrum)
|
|
sc->unSelect();
|
|
}
|
|
|
|
double Spectrum::getPower(double frequent, bool& ok, SRC src) {
|
|
INIT_GET(Spectrum)
|
|
return renderState->getY(frequent, ok);
|
|
}
|
|
|
|
}
|