优化曲线
This commit is contained in:
@@ -51,10 +51,17 @@ void AltitudeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
|
||||
Q_UNUSED(option);
|
||||
Q_UNUSED(widget);
|
||||
|
||||
painter->setRenderHint(QPainter::Antialiasing, true);
|
||||
|
||||
QPen ePen;
|
||||
ePen.setWidth(1);
|
||||
|
||||
|
||||
QFont font;
|
||||
font.setPixelSize(15);//不随着屏幕分辨率改变而改变
|
||||
font.setFamily("Arial");//非衬线
|
||||
painter->setFont(font);
|
||||
|
||||
//画底部
|
||||
painter->save();
|
||||
ePen.setColor(QColor("#a39d9c"));
|
||||
@@ -117,27 +124,26 @@ void AltitudeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
|
||||
if(max != min)
|
||||
{
|
||||
V_scale = (float)160.0 / (max - min);
|
||||
qDebug() << V_scale << max << min;
|
||||
}
|
||||
|
||||
|
||||
//画坐标数据
|
||||
if((max != -999999)&&(min != 999999))
|
||||
{
|
||||
painter->save();
|
||||
ePen.setColor(QColor("#ffcc00"));
|
||||
ePen.setColor(QColor("#FFFFFF"));
|
||||
painter->setPen(ePen);
|
||||
painter->translate(20,180);
|
||||
|
||||
painter->drawText(QRectF(-20,-180,100,20),Qt::AlignVCenter|Qt::AlignLeft, QString::number(max));
|
||||
|
||||
painter->drawText(QRectF(-20, 0,100,20),Qt::AlignVCenter|Qt::AlignLeft, QString::number(min));
|
||||
|
||||
painter->restore();
|
||||
|
||||
|
||||
}
|
||||
|
||||
float size = Elevation.size();
|
||||
float step = 360/(size - 1);
|
||||
|
||||
QPainterPath Elepath;
|
||||
QPainterPath Altpath;
|
||||
|
||||
|
||||
//画地形
|
||||
@@ -149,23 +155,28 @@ void AltitudeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
|
||||
if(!Elevation.isEmpty())
|
||||
{
|
||||
int stepcount = 0;
|
||||
QPainterPath path;
|
||||
//QPainterPath path;
|
||||
|
||||
Elepath.moveTo(0,0);
|
||||
|
||||
QPointF sp;
|
||||
for (QMap<int, float>::iterator i = Elevation.begin();i != Elevation.end(); ++i)
|
||||
{
|
||||
if(i.key() == 0)
|
||||
{
|
||||
path.moveTo(stepcount * step, (-i.value() + min) * V_scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
path.lineTo(stepcount * step, (-i.value() + min) * V_scale);
|
||||
}
|
||||
QPointF ep = QPointF(stepcount * step, (-i.value() + min) * V_scale);
|
||||
QPointF c1 = QPointF((sp.x() + ep.x()) / 2, sp.y());
|
||||
QPointF c2 = QPointF((sp.x() + ep.x()) / 2, ep.y());
|
||||
|
||||
sp = QPointF(stepcount * step, (-i.value() + min) * V_scale);
|
||||
|
||||
Elepath.cubicTo(c1, c2, ep);
|
||||
|
||||
stepcount++;
|
||||
}
|
||||
Elepath.lineTo(360,0);
|
||||
Elepath.closeSubpath();
|
||||
|
||||
|
||||
painter->drawPath(path);
|
||||
painter->fillPath(Elepath,QColor("#ffcc00"));
|
||||
painter->drawPath(Elepath);
|
||||
}
|
||||
painter->restore();
|
||||
|
||||
@@ -178,28 +189,105 @@ void AltitudeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
|
||||
if(!Altitude.isEmpty())
|
||||
{
|
||||
int stepcount = 0;
|
||||
QPainterPath path;
|
||||
//QPainterPath path;
|
||||
|
||||
QPointF sp;
|
||||
for (QMap<int, float>::iterator i = Altitude.begin();i != Altitude.end(); ++i)
|
||||
{
|
||||
|
||||
if(i.key() == 0)
|
||||
{
|
||||
path.moveTo(stepcount * step, (-i.value() + min) * V_scale);
|
||||
Altpath.moveTo(stepcount * step, (-i.value() + min) * V_scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
path.lineTo(stepcount * step, (-i.value() + min) * V_scale);
|
||||
//path.lineTo(stepcount * step, (-i.value() + min) * V_scale);
|
||||
|
||||
// 控制点的 x 坐标为 sp 与 ep 的 x 坐标和的一半
|
||||
// 第一个控制点 c1 的 y 坐标为起始点 sp 的 y 坐标
|
||||
// 第二个控制点 c2 的 y 坐标为结束点 ep 的 y 坐标
|
||||
|
||||
|
||||
QPointF ep = QPointF(stepcount * step, (-i.value() + min) * V_scale);
|
||||
QPointF c1 = QPointF((sp.x() + ep.x()) / 2, sp.y());
|
||||
QPointF c2 = QPointF((sp.x() + ep.x()) / 2, ep.y());
|
||||
|
||||
qDebug() << c1 << c2 << sp << ep;
|
||||
|
||||
sp = QPointF(stepcount * step, (-i.value() + min) * V_scale);
|
||||
|
||||
Altpath.cubicTo(c1, c2, ep);
|
||||
|
||||
|
||||
}
|
||||
|
||||
stepcount++;
|
||||
}
|
||||
|
||||
|
||||
painter->drawPath(Altpath);
|
||||
}
|
||||
painter->restore();
|
||||
|
||||
|
||||
//画填充
|
||||
|
||||
painter->save();
|
||||
ePen.setColor(QColor("#ffcc00"));
|
||||
painter->setPen(ePen);
|
||||
painter->translate(20,180);
|
||||
|
||||
//Altpath.moveTo(Elepath);
|
||||
//Altpath.addPath(Elepath);
|
||||
//Altpath.moveTo(0,0);
|
||||
|
||||
|
||||
|
||||
|
||||
painter->restore();
|
||||
|
||||
|
||||
//test
|
||||
//Bezier(painter);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void AltitudeItem::Bezier(QPainter *painter)
|
||||
{
|
||||
// 曲线上的点
|
||||
static QList<QPointF> points = QList<QPointF>() << QPointF(0, 0) << QPointF(100,-100) << QPointF(200,-120)
|
||||
<< QPointF(300,-100) << QPointF(330,-90) << QPointF(350, -70);
|
||||
QPainterPath path(points[0]);
|
||||
|
||||
for (int i = 0; i < points.size() - 1; ++i) {
|
||||
// 控制点的 x 坐标为 sp 与 ep 的 x 坐标和的一半
|
||||
// 第一个控制点 c1 的 y 坐标为起始点 sp 的 y 坐标
|
||||
// 第二个控制点 c2 的 y 坐标为结束点 ep 的 y 坐标
|
||||
QPointF sp = points[i];
|
||||
QPointF ep = points[i+1];
|
||||
QPointF c1 = QPointF((sp.x() + ep.x()) / 2, sp.y());
|
||||
QPointF c2 = QPointF((sp.x() + ep.x()) / 2, ep.y());
|
||||
|
||||
path.cubicTo(c1, c2, ep);
|
||||
}
|
||||
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing, true);
|
||||
painter->setPen(QPen(Qt::black, 2));
|
||||
|
||||
// 绘制 path
|
||||
painter->translate(40, 130);
|
||||
painter->drawPath(path);
|
||||
|
||||
// 绘制曲线上的点
|
||||
painter->setBrush(Qt::gray);
|
||||
for (int i = 0; i < points.size(); ++i) {
|
||||
painter->drawEllipse(points[i], 4, 4);
|
||||
}
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
||||
void AltitudeItem::RefreshPos()
|
||||
{
|
||||
this->setPos(this->x(),
|
||||
|
||||
@@ -62,6 +62,8 @@ private:
|
||||
QPointF pos_old;
|
||||
|
||||
|
||||
void Bezier(QPainter *painter);
|
||||
|
||||
protected:
|
||||
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||
|
||||
@@ -81,7 +81,7 @@ OPMapWidget::OPMapWidget(QWidget *parent, Configuration *config) : QGraphicsView
|
||||
altitudeitem = new AltitudeItem(map,Qt::red);
|
||||
altitudeitem->setParentItem(map);
|
||||
|
||||
altitudeitem->setPos(0,this->height() - altitudeitem->boundingRect().height());
|
||||
altitudeitem->setPos(0,(this->height() - altitudeitem->boundingRect().height())/2);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -672,7 +672,7 @@ void WayPointItem::setWPProperty(float param1,float param2,float param3,float pa
|
||||
|
||||
ElevationTrig();
|
||||
|
||||
emit AltitudeChanged(this->Number(),property.z);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -736,7 +736,7 @@ void WayPointItem::SetDefault(double lat,double lng,float alt,uint16_t seq)
|
||||
|
||||
ElevationTrig();
|
||||
|
||||
emit AltitudeChanged(this->Number(),property.z);
|
||||
//emit AltitudeChanged(this->Number(),property.z);
|
||||
|
||||
//...
|
||||
}
|
||||
@@ -775,7 +775,7 @@ void WayPointItem::SetAlt(float value)
|
||||
{
|
||||
property.z = value;
|
||||
|
||||
emit AltitudeChanged(this->Number(),property.z);
|
||||
//emit AltitudeChanged(this->Number(),property.z);
|
||||
|
||||
}
|
||||
|
||||
@@ -867,7 +867,7 @@ void WayPointItem::ElevationUpdate(QNetworkReply *reply)
|
||||
qDebug() << "Seq:" << this->Number() << "Elevation" << Elevation;
|
||||
|
||||
emit ElevationChanged(this->Number(),Elevation);
|
||||
|
||||
emit AltitudeChanged(this->Number(),property.z);
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user