[wip] painter
This commit is contained in:
parent
99f4ed4f0c
commit
dffc96fd77
7 changed files with 1490 additions and 137 deletions
3
.clangd
Normal file
3
.clangd
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
CompileFlags:
|
||||||
|
Remove:
|
||||||
|
- -mno-direct-extern-access
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -62,3 +62,4 @@ CMakeFiles
|
||||||
.qt
|
.qt
|
||||||
.cmake
|
.cmake
|
||||||
qtcsettings.cmake
|
qtcsettings.cmake
|
||||||
|
.cache
|
1359
CMakeCache.txt
Normal file
1359
CMakeCache.txt
Normal file
File diff suppressed because it is too large
Load diff
|
@ -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()
|
||||||
|
|
|
@ -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>
|
||||||
|
|
133
mycanvas.cpp
133
mycanvas.cpp
|
@ -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();
|
}
|
||||||
|
|
||||||
|
void MyCanvas::paintEvent(QPaintEvent *event) {
|
||||||
|
QPainter painter(this);
|
||||||
|
|
||||||
QScatterSeries *series1 = new QScatterSeries();
|
|
||||||
series1->setMarkerSize(5);
|
|
||||||
|
|
||||||
switch (this->state.type) {
|
switch (this->state.type) {
|
||||||
case 1: // фазвовое распределение
|
case 1:
|
||||||
{
|
for (int i = 0; i < this->radar.FIzlArray.size(); ++i) {
|
||||||
series1->setMarkerShape(QScatterSeries::MarkerShapeRectangle);
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
|
|
||||||
// series1->setPen(QPen(QColor(63 * c, 255 - 63 * c, 163 * c)));
|
|
||||||
*series1 << QPointF(izls.IzPos.Z, izls.IzPos.Y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
chart()->addSeries(series1);
|
|
||||||
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
// IAmpIzls
|
// IAmpIzls
|
||||||
{
|
|
||||||
series1->setMarkerShape(QScatterSeries::MarkerShapeRectangle);
|
|
||||||
//series1->setPen(QPen(QColor(izls.Amplitude)));
|
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < this->radar.FIzlArray.size(); ++i) {
|
for (int i = 0; i < this->radar.FIzlArray.size(); ++i) {
|
||||||
|
|
||||||
TIzl izls = radar.FIzlArray[i];
|
TIzl izls = radar.FIzlArray[i];
|
||||||
|
painter.setPen(QPen(QColor(izls.Amplitude)));
|
||||||
|
|
||||||
QPoint point(izls.IzPos.Z, izls.IzPos.Y);
|
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);
|
||||||
series1->append(point);
|
painter.drawRect(rect);
|
||||||
}
|
}
|
||||||
chart()->addSeries(series1);
|
|
||||||
|
|
||||||
// for(int index= 0; index < series1->count(); index++){
|
|
||||||
// QPointF p = chart()->mapToPosition(series1->at(index) , series1);
|
|
||||||
// QGraphicsItem *it = this->itemAt(this->mapFromScene(p));
|
|
||||||
// if(QGraphicsRectItem *rect = qgraphicsitem_cast<QGraphicsRectItem*>(it)){
|
|
||||||
// QColor color = QColor(radar.FIzlArray[index].Amplitude);;
|
|
||||||
// rect->setBrush(color);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
{
|
|
||||||
// FazIzls
|
// FazIzls
|
||||||
series1->setMarkerShape(QScatterSeries::MarkerShapeRectangle);
|
|
||||||
|
|
||||||
for (int i = 0; i < this->radar.FIzlArray.size(); ++i) {
|
for (int i = 0; i < this->radar.FIzlArray.size(); ++i) {
|
||||||
|
|
||||||
TIzl izls = radar.FIzlArray[i];
|
TIzl izls = radar.FIzlArray[i];
|
||||||
double faz = frac((izls.Fase * 0.5 / M_PI)) * 2 * M_PI;
|
double faz = frac(izls.Fase*0.5/M_PI)*2/M_PI;
|
||||||
|
painter.setPen(QPen(QColor(faz)));
|
||||||
|
|
||||||
// double x = izls.IzPos.Z - 0.008;
|
QRectF rect = this->transposeRect(
|
||||||
// double y = izls.IzPos.Y - 0.011;
|
izls.IzPos.Z - 0.008, izls.IzPos.Y - 0.011, izls.IzPos.Z + 0.008, izls.IzPos.Y + 0.011,
|
||||||
// double x2 = izls.IzPos.Z + 0.008;
|
state.axisX, state.axisY);
|
||||||
// double y2 = izls.IzPos.Y + 0.011;
|
painter.drawRect(rect);
|
||||||
|
|
||||||
//series1->setPen(QPen(QColor(faz)));
|
|
||||||
series1->append(QPointF(izls.IzPos.Z, izls.IzPos.Y));
|
|
||||||
}
|
|
||||||
|
|
||||||
chart()->addSeries(series1);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
{
|
|
||||||
// DN
|
// DN
|
||||||
|
|
||||||
series1->setMarkerShape(QScatterSeries::MarkerShapeCircle);
|
|
||||||
series1->setMarkerSize(20);
|
|
||||||
|
|
||||||
for (int i = 0; i < this->FDNMass.size(); ++i) {
|
for (int i = 0; i < this->FDNMass.size(); ++i) {
|
||||||
for (int j = 0; j < this->FDNMass[i].size(); ++j) {
|
for (int j = 0; j < this->FDNMass[i].size(); ++j) {
|
||||||
//series1->setPen(QPen(QColor(this->FDNMass[i][j].col)));
|
TColPoint mass = FDNMass[i][j];
|
||||||
double x =this->FDNMass[i][j].x,
|
QPen pen = QPen(QColor(255,255,255));
|
||||||
y = this->FDNMass[i][j].y;
|
pen.setWidth(5);
|
||||||
*series1 << QPointF(x, y);
|
painter.setPen(pen);
|
||||||
}
|
|
||||||
|
QPointF point = transposePoint(mass.x, mass.y, state.axisX, state.axisY);
|
||||||
|
painter.drawPoint(point);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
chart()->addSeries(series1);
|
// chart()->addSeries(series1);
|
||||||
|
}
|
||||||
|
|
||||||
|
QPointF MyCanvas::transposePoint(double x, double y, double axisX, double axisY) {
|
||||||
|
double cwidth = static_cast<double>(width())/axisX;
|
||||||
|
double cheight = static_cast<double>(height())/axisY;
|
||||||
|
|
||||||
|
double zeroX = cwidth/2;
|
||||||
|
double zeroY = cheight/2;
|
||||||
|
|
||||||
|
return QPointF(zeroX + (x * cwidth), zeroY + (y * cheight));
|
||||||
|
}
|
||||||
|
|
||||||
|
QRectF MyCanvas::transposeRect(double x, double y, double x2, double y2, double axisX, double axisY) {
|
||||||
|
return QRectF(transposePoint(x, y, axisX, axisY), transposePoint(x2, y2, axisX, axisY));
|
||||||
}
|
}
|
||||||
|
|
27
mycanvas.h
27
mycanvas.h
|
@ -1,18 +1,18 @@
|
||||||
#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;
|
||||||
};
|
};
|
||||||
|
@ -20,13 +20,15 @@ struct TColPoint
|
||||||
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);
|
||||||
|
@ -34,9 +36,14 @@ public:
|
||||||
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
|
||||||
|
|
Loading…
Reference in a new issue