[wip] painter

This commit is contained in:
royalcat 2023-05-18 02:08:48 +03:00
parent 99f4ed4f0c
commit dffc96fd77
7 changed files with 1490 additions and 137 deletions

3
.clangd Normal file
View file

@ -0,0 +1,3 @@
CompileFlags:
Remove:
- -mno-direct-extern-access

3
.gitignore vendored
View file

@ -61,4 +61,5 @@ CMakeFiles
.qtc .qtc
.qt .qt
.cmake .cmake
qtcsettings.cmake qtcsettings.cmake
.cache

1359
CMakeCache.txt Normal file

File diff suppressed because it is too large Load diff

View file

@ -73,7 +73,11 @@ void MainWindow::on_pushButton_5_clicked() {
} }
} }
this->canvas->drawState(ToPaintState(4)); ToPaintState state(4);
state.axisX = maxA;
state.axisY = maxA;
this->canvas->drawState(state);
} }
void MainWindow::on_pushButton_clicked() void MainWindow::on_pushButton_clicked()

View file

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>902</width> <width>777</width>
<height>527</height> <height>530</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -133,8 +133,8 @@
<rect> <rect>
<x>330</x> <x>330</x>
<y>20</y> <y>20</y>
<width>531</width> <width>430</width>
<height>431</height> <height>430</height>
</rect> </rect>
</property> </property>
</widget> </widget>

View file

@ -1,117 +1,96 @@
#include "mycanvas.h" #include "mycanvas.h"
#include <qpainter.h>
#include <qpen.h>
#include <qsize.h>
#include <qwidget.h>
MyCanvas::MyCanvas(QWidget *parent) : QChartView(new QChart(), parent) { MyCanvas::MyCanvas(QWidget *parent) : QWidget(parent) {
chart()->setTitle("Фазовое распределение антенных решеток"); // chart()->setTitle("Фазовое распределение антенных решеток");
chart()->legend()->hide(); // chart()->legend()->hide();
QValueAxis *qAxisX = new QValueAxis(); // QValueAxis *qAxisX = new QValueAxis();
QValueAxis *qAxisY = new QValueAxis(); // QValueAxis *qAxisY = new QValueAxis();
qAxisX->setRange(-1, 1); // qAxisX->setRange(-1, 1);
qAxisY->setRange(-1, 1); // qAxisY->setRange(-1, 1);
chart()->addAxis(qAxisX, Qt::AlignLeft); // chart()->addAxis(qAxisX, Qt::AlignLeft);
chart()->addAxis(qAxisY, Qt::AlignBottom); // chart()->addAxis(qAxisY, Qt::AlignBottom);
} }
void MyCanvas::drawState(ToPaintState state) { void MyCanvas::drawState(ToPaintState state) {
this->state = state; this->state = state;
chart()->removeAllSeries(); this->update();
chart()->createDefaultAxes(); }
QScatterSeries *series1 = new QScatterSeries(); void MyCanvas::paintEvent(QPaintEvent *event) {
series1->setMarkerSize(5); QPainter painter(this);
switch (this->state.type) {
case 1: // фазвовое распределение switch (this->state.type) {
{ case 1:
series1->setMarkerShape(QScatterSeries::MarkerShapeRectangle); for (int i = 0; i < this->radar.FIzlArray.size(); ++i) {
for (int i = 0; i < this->radar.FIzlArray.size(); i++) { int c = i % 4;
int c = i % 4; painter.setPen(QPen(QColor(63 * c, 255 - 63 * c, 163 * c)));
TIzl izls = radar.FIzlArray[i]; TIzl izls = radar.FIzlArray[i];
// double x = izls.IzPos.Z - 0.0085; QRectF rect = this->transposeRect(izls.IzPos.Z - 0.0085, izls.IzPos.Y - 0.0115, izls.IzPos.Z + 0.0085, izls.IzPos.Y + 0.0115, state.axisX, state.axisY);
// double y = izls.IzPos.Y - 0.0115; painter.drawRect(rect);
// double x2 = izls.IzPos.Z + 0.0085; }
// double y2 = izls.IzPos.Y + 0.0115;
case 2:
// IAmpIzls
// series1->setPen(QPen(QColor(63 * c, 255 - 63 * c, 163 * c))); for (int i = 0; i < this->radar.FIzlArray.size(); ++i) {
*series1 << QPointF(izls.IzPos.Z, izls.IzPos.Y);
} TIzl izls = radar.FIzlArray[i];
painter.setPen(QPen(QColor(izls.Amplitude)));
chart()->addSeries(series1);
QRectF rect = this->transposeRect(izls.IzPos.Z - 0.008, izls.IzPos.Y - 0.011, izls.IzPos.Z + 0.008, izls.IzPos.Y + 0.011, state.axisX, state.axisY);
} painter.drawRect(rect);
break; }
break;
case 2: case 3:
// IAmpIzls // FazIzls
{ for (int i = 0; i < this->radar.FIzlArray.size(); ++i) {
series1->setMarkerShape(QScatterSeries::MarkerShapeRectangle);
//series1->setPen(QPen(QColor(izls.Amplitude))); TIzl izls = radar.FIzlArray[i];
double faz = frac(izls.Fase*0.5/M_PI)*2/M_PI;
painter.setPen(QPen(QColor(faz)));
for (int i = 0; i < this->radar.FIzlArray.size(); ++i) {
TIzl izls = radar.FIzlArray[i]; QRectF rect = this->transposeRect(
izls.IzPos.Z - 0.008, izls.IzPos.Y - 0.011, izls.IzPos.Z + 0.008, izls.IzPos.Y + 0.011,
QPoint point(izls.IzPos.Z, izls.IzPos.Y); state.axisX, state.axisY);
series1->append(point); painter.drawRect(rect);
} }
chart()->addSeries(series1); break;
case 4:
// for(int index= 0; index < series1->count(); index++){ // DN
// QPointF p = chart()->mapToPosition(series1->at(index) , series1); for (int i = 0; i < this->FDNMass.size(); ++i) {
// QGraphicsItem *it = this->itemAt(this->mapFromScene(p)); for (int j = 0; j < this->FDNMass[i].size(); ++j) {
// if(QGraphicsRectItem *rect = qgraphicsitem_cast<QGraphicsRectItem*>(it)){ TColPoint mass = FDNMass[i][j];
// QColor color = QColor(radar.FIzlArray[index].Amplitude);; QPen pen = QPen(QColor(255,255,255));
// rect->setBrush(color); pen.setWidth(5);
// } painter.setPen(pen);
// }
} QPointF point = transposePoint(mass.x, mass.y, state.axisX, state.axisY);
painter.drawPoint(point);
break; }
case 3: }
{ break;
// FazIzls }
series1->setMarkerShape(QScatterSeries::MarkerShapeRectangle);
// chart()->addSeries(series1);
for (int i = 0; i < this->radar.FIzlArray.size(); ++i) { }
TIzl izls = radar.FIzlArray[i];
double faz = frac((izls.Fase * 0.5 / M_PI)) * 2 * M_PI; QPointF MyCanvas::transposePoint(double x, double y, double axisX, double axisY) {
double cwidth = static_cast<double>(width())/axisX;
// double x = izls.IzPos.Z - 0.008; double cheight = static_cast<double>(height())/axisY;
// double y = izls.IzPos.Y - 0.011;
// double x2 = izls.IzPos.Z + 0.008; double zeroX = cwidth/2;
// double y2 = izls.IzPos.Y + 0.011; double zeroY = cheight/2;
//series1->setPen(QPen(QColor(faz))); return QPointF(zeroX + (x * cwidth), zeroY + (y * cheight));
series1->append(QPointF(izls.IzPos.Z, izls.IzPos.Y)); }
}
QRectF MyCanvas::transposeRect(double x, double y, double x2, double y2, double axisX, double axisY) {
chart()->addSeries(series1); return QRectF(transposePoint(x, y, axisX, axisY), transposePoint(x2, y2, axisX, axisY));
}
break;
case 4:
{
// DN
series1->setMarkerShape(QScatterSeries::MarkerShapeCircle);
series1->setMarkerSize(20);
for (int i = 0; i < this->FDNMass.size(); ++i) {
for (int j = 0; j < this->FDNMass[i].size(); ++j) {
//series1->setPen(QPen(QColor(this->FDNMass[i][j].col)));
double x =this->FDNMass[i][j].x,
y = this->FDNMass[i][j].y;
*series1 << QPointF(x, y);
}
}
}
break;
}
chart()->addSeries(series1);
} }

View file

@ -1,42 +1,49 @@
#ifndef MYCANVAS_H #ifndef MYCANVAS_H
#define MYCANVAS_H #define MYCANVAS_H
#include <QWidget>
#include <QPainter>
#include <QPaintEvent>
#include <QScatterSeries>
#include <QChart> #include <QChart>
#include <QChartView> #include <QChartView>
#include <QPaintEvent>
#include <QPainter>
#include <QScatterSeries>
#include <QValueAxis> #include <QValueAxis>
#include <QWidget>
#include <qwidget.h>
#include "RadarExt.h" #include "RadarExt.h"
struct TColPoint struct TColPoint {
{ double x, y, amp;
double x, y, amp; QColor col;
QColor col;
}; };
class ToPaintState { class ToPaintState {
public: public:
ToPaintState() {} ToPaintState() {}
ToPaintState(int type) : type (type) {} ToPaintState(int type) : type(type) {}
int type = 0; int type = 0;
double pointSize = 5;
double axisX = 1;
double axisY = 1;
}; };
class MyCanvas : public QChartView class MyCanvas : public QWidget {
{ Q_OBJECT
Q_OBJECT
public: public:
explicit MyCanvas(QWidget *parent = nullptr); explicit MyCanvas(QWidget *parent = nullptr);
TRadar radar = TRadar(); TRadar radar = TRadar();
QVector<QVector<TColPoint>> FDNMass; QVector<QVector<TColPoint>> FDNMass;
void drawState(ToPaintState); void drawState(ToPaintState);
private: private:
ToPaintState state = ToPaintState(); ToPaintState state = ToPaintState();
QRectF transposeRect(double x, double y, double x2, double y2, double axisX, double axisY);
QPointF transposePoint(double x, double y, double axisX, double axisY);
protected:
void paintEvent(QPaintEvent *event);
}; };
#endif // MYCANVAS_H #endif // MYCANVAS_H