[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
|
||||
.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()
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>902</width>
|
||||
<height>527</height>
|
||||
<width>777</width>
|
||||
<height>530</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -133,8 +133,8 @@
|
|||
<rect>
|
||||
<x>330</x>
|
||||
<y>20</y>
|
||||
<width>531</width>
|
||||
<height>431</height>
|
||||
<width>430</width>
|
||||
<height>430</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
|
|
133
mycanvas.cpp
133
mycanvas.cpp
|
@ -1,117 +1,96 @@
|
|||
|
||||
#include "mycanvas.h"
|
||||
#include <qpainter.h>
|
||||
#include <qpen.h>
|
||||
#include <qsize.h>
|
||||
#include <qwidget.h>
|
||||
|
||||
MyCanvas::MyCanvas(QWidget *parent) : QChartView(new QChart(), parent) {
|
||||
chart()->setTitle("Фазовое распределение антенных решеток");
|
||||
chart()->legend()->hide();
|
||||
MyCanvas::MyCanvas(QWidget *parent) : QWidget(parent) {
|
||||
// chart()->setTitle("Фазовое распределение антенных решеток");
|
||||
// chart()->legend()->hide();
|
||||
|
||||
QValueAxis *qAxisX = new QValueAxis();
|
||||
QValueAxis *qAxisY = new QValueAxis();
|
||||
qAxisX->setRange(-1, 1);
|
||||
qAxisY->setRange(-1, 1);
|
||||
chart()->addAxis(qAxisX, Qt::AlignLeft);
|
||||
chart()->addAxis(qAxisY, Qt::AlignBottom);
|
||||
// QValueAxis *qAxisX = new QValueAxis();
|
||||
// QValueAxis *qAxisY = new QValueAxis();
|
||||
// qAxisX->setRange(-1, 1);
|
||||
// qAxisY->setRange(-1, 1);
|
||||
// chart()->addAxis(qAxisX, Qt::AlignLeft);
|
||||
// chart()->addAxis(qAxisY, Qt::AlignBottom);
|
||||
}
|
||||
|
||||
void MyCanvas::drawState(ToPaintState state) {
|
||||
this->state = state;
|
||||
chart()->removeAllSeries();
|
||||
chart()->createDefaultAxes();
|
||||
this->update();
|
||||
}
|
||||
|
||||
void MyCanvas::paintEvent(QPaintEvent *event) {
|
||||
QPainter painter(this);
|
||||
|
||||
QScatterSeries *series1 = new QScatterSeries();
|
||||
series1->setMarkerSize(5);
|
||||
|
||||
switch (this->state.type) {
|
||||
case 1: // фазвовое распределение
|
||||
{
|
||||
series1->setMarkerShape(QScatterSeries::MarkerShapeRectangle);
|
||||
case 1:
|
||||
for (int i = 0; i < this->radar.FIzlArray.size(); ++i) {
|
||||
|
||||
for (int i = 0; i < this->radar.FIzlArray.size(); i++) {
|
||||
int c = i % 4;
|
||||
painter.setPen(QPen(QColor(63 * c, 255 - 63 * c, 163 * c)));
|
||||
|
||||
TIzl izls = radar.FIzlArray[i];
|
||||
// double x = izls.IzPos.Z - 0.0085;
|
||||
// double y = izls.IzPos.Y - 0.0115;
|
||||
// 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);
|
||||
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);
|
||||
painter.drawRect(rect);
|
||||
}
|
||||
|
||||
chart()->addSeries(series1);
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
// IAmpIzls
|
||||
{
|
||||
series1->setMarkerShape(QScatterSeries::MarkerShapeRectangle);
|
||||
//series1->setPen(QPen(QColor(izls.Amplitude)));
|
||||
|
||||
|
||||
for (int i = 0; i < this->radar.FIzlArray.size(); ++i) {
|
||||
|
||||
TIzl izls = radar.FIzlArray[i];
|
||||
painter.setPen(QPen(QColor(izls.Amplitude)));
|
||||
|
||||
QPoint point(izls.IzPos.Z, izls.IzPos.Y);
|
||||
series1->append(point);
|
||||
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);
|
||||
}
|
||||
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;
|
||||
case 3:
|
||||
{
|
||||
// FazIzls
|
||||
series1->setMarkerShape(QScatterSeries::MarkerShapeRectangle);
|
||||
|
||||
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;
|
||||
double faz = frac(izls.Fase*0.5/M_PI)*2/M_PI;
|
||||
painter.setPen(QPen(QColor(faz)));
|
||||
|
||||
// double x = izls.IzPos.Z - 0.008;
|
||||
// double y = izls.IzPos.Y - 0.011;
|
||||
// double x2 = izls.IzPos.Z + 0.008;
|
||||
// double y2 = izls.IzPos.Y + 0.011;
|
||||
|
||||
//series1->setPen(QPen(QColor(faz)));
|
||||
series1->append(QPointF(izls.IzPos.Z, izls.IzPos.Y));
|
||||
}
|
||||
|
||||
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;
|
||||
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);
|
||||
}
|
||||
TColPoint mass = FDNMass[i][j];
|
||||
QPen pen = QPen(QColor(255,255,255));
|
||||
pen.setWidth(5);
|
||||
painter.setPen(pen);
|
||||
|
||||
QPointF point = transposePoint(mass.x, mass.y, state.axisX, state.axisY);
|
||||
painter.drawPoint(point);
|
||||
}
|
||||
}
|
||||
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));
|
||||
}
|
||||
|
|
25
mycanvas.h
25
mycanvas.h
|
@ -1,18 +1,18 @@
|
|||
#ifndef MYCANVAS_H
|
||||
#define MYCANVAS_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPainter>
|
||||
#include <QPaintEvent>
|
||||
#include <QScatterSeries>
|
||||
#include <QChart>
|
||||
#include <QChartView>
|
||||
#include <QPaintEvent>
|
||||
#include <QPainter>
|
||||
#include <QScatterSeries>
|
||||
#include <QValueAxis>
|
||||
#include <QWidget>
|
||||
#include <qwidget.h>
|
||||
|
||||
#include "RadarExt.h"
|
||||
|
||||
struct TColPoint
|
||||
{
|
||||
struct TColPoint {
|
||||
double x, y, amp;
|
||||
QColor col;
|
||||
};
|
||||
|
@ -23,10 +23,12 @@ public:
|
|||
ToPaintState(int type) : type(type) {}
|
||||
|
||||
int type = 0;
|
||||
double pointSize = 5;
|
||||
double axisX = 1;
|
||||
double axisY = 1;
|
||||
};
|
||||
|
||||
class MyCanvas : public QChartView
|
||||
{
|
||||
class MyCanvas : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MyCanvas(QWidget *parent = nullptr);
|
||||
|
@ -34,9 +36,14 @@ public:
|
|||
QVector<QVector<TColPoint>> FDNMass;
|
||||
void drawState(ToPaintState);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue