QGraphicsView实现简易地图16『爆炸效果』

2024-05-26 10:04

本文主要是介绍QGraphicsView实现简易地图16『爆炸效果』,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

前文链接:QGraphicsView实现简易地图15『测量面积』
一种简单的爆炸波扩散效果
动态演示效果:
在这里插入图片描述

静态展示图片:
在这里插入图片描述

核心代码:

#pragma once
#include "../AbstractGeoItem.h"
#include "DataStruct/GeoData.h"/** 爆炸扩散效果-静态*/class ExplosiveDiffusionItem : public AbstractGeoItem
{
public:ExplosiveDiffusionItem(const GeoCoord &geoCoord, int radius, QGraphicsItem *parent = nullptr);~ExplosiveDiffusionItem();// 更新地理位置virtual void updateGeoPos();protected:virtual QRectF boundingRect() const override;virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;// 设置半径(单位:米)void setRadius(int radius);// 获取半径(单位:米)int radius();protected:int m_radius;	// 半径(单位:米)double m_rw;	// 基于指定经纬度处的椭圆横轴半径double m_rh;	// 基于指定经纬度处的椭圆竖轴半径
};
#include "ExplosiveDiffusionItem.h"
#include <QRadialGradient>
#include <QPainter>
#include "Utility/MapUtility.h"ExplosiveDiffusionItem::ExplosiveDiffusionItem(const GeoCoord &geoCoord, int radius, QGraphicsItem *parent /*= nullptr*/) : AbstractGeoItem(parent)
{setZValue(300);setGeoPos(geoCoord.lon, geoCoord.lat);m_radius = radius;
}ExplosiveDiffusionItem::~ExplosiveDiffusionItem()
{}void ExplosiveDiffusionItem::updateGeoPos()
{AbstractGeoItem::updateGeoPos();prepareGeometryChange();
}QRectF ExplosiveDiffusionItem::boundingRect() const
{return QRectF(-m_rw, -m_rh, 2 * m_rw, 2 * m_rh);
}void ExplosiveDiffusionItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{QRadialGradient gr(0, 0, m_rw, 0, 0);gr.setColorAt(0.0, QColor(255, 255, 255, 0));gr.setColorAt(0.90, QColor(255, 255, 255, 10));gr.setColorAt(0.94, QColor(255, 255, 255, 40));gr.setColorAt(0.99, QColor(185, 225, 240, 255));gr.setColorAt(1, QColor(185, 225, 240, 128));painter->setRenderHint(QPainter::Antialiasing);painter->setBrush(gr);painter->setPen(Qt::NoPen);painter->drawEllipse(boundingRect());
}void ExplosiveDiffusionItem::setRadius(int radius)
{m_radius = radius;GeoCoord right = MapUtility::geoCoordByDisAndBearing(m_lon, m_lat, 90, m_radius);GeoCoord top = MapUtility::geoCoordByDisAndBearing(m_lon, m_lat, 0, m_radius);QPointF rightPos = sceneCoordFromGeoCoord(right.lon, right.lat);QPointF topPos = sceneCoordFromGeoCoord(top.lon, top.lat);QPointF centerPos = sceneCoordFromGeoCoord(m_lon, m_lat);m_rw = rightPos.x() - centerPos.x();m_rh = centerPos.y() - topPos.y();prepareGeometryChange();
}int ExplosiveDiffusionItem::radius()
{return m_radius;
}

此处提供的动态效果,是利用QPropertyAnimation制作而成,后面文章的动态效果也是采用这种方法,后续将不再展示代码,参考此处即可。

#pragma once
#include "ExplosiveDiffusionItem.h"/** 爆炸扩散效果-动态扩散*/class QPropertyAnimation;class ExplosiveDiffusionAnimateItem : public QObject, public ExplosiveDiffusionItem
{Q_OBJECTQ_PROPERTY(int m_radius WRITE setRadius READ radius)public:ExplosiveDiffusionAnimateItem(const GeoCoord &geoCoord, int radius, QGraphicsItem *parent = nullptr);~ExplosiveDiffusionAnimateItem();void start(int msecs = 1000);private:QPropertyAnimation *m_animation;
};
#include "ExplosiveDiffusionAnimateItem.h"
#include <QPropertyAnimation>ExplosiveDiffusionAnimateItem::ExplosiveDiffusionAnimateItem(const GeoCoord &geoCoord, int radius, QGraphicsItem *parent /*= nullptr*/): ExplosiveDiffusionItem(geoCoord, radius, parent)
{m_animation = new QPropertyAnimation(this, "m_radius", this);m_animation->setEasingCurve(QEasingCurve::InOutQuad);connect(m_animation, &QAbstractAnimation::finished, this, &ExplosiveDiffusionAnimateItem::finished);
}ExplosiveDiffusionAnimateItem::~ExplosiveDiffusionAnimateItem()
{}void ExplosiveDiffusionAnimateItem::start(int msecs/* = 1000*/)
{if (m_animation->state() != QAbstractAnimation::Stopped)m_animation->stop();m_animation->setDuration(msecs);m_animation->setStartValue(0);m_animation->setEndValue(m_radius);m_animation->start();
}

这篇关于QGraphicsView实现简易地图16『爆炸效果』的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1004148

相关文章

基于C++的UDP网络通信系统设计与实现详解

《基于C++的UDP网络通信系统设计与实现详解》在网络编程领域,UDP作为一种无连接的传输层协议,以其高效、低延迟的特性在实时性要求高的应用场景中占据重要地位,下面我们就来看看如何从零开始构建一个完整... 目录前言一、UDP服务器UdpServer.hpp1.1 基本框架设计1.2 初始化函数Init详解

Java中Map的五种遍历方式实现与对比

《Java中Map的五种遍历方式实现与对比》其实Map遍历藏着多种玩法,有的优雅简洁,有的性能拉满,今天咱们盘一盘这些进阶偏基础的遍历方式,告别重复又臃肿的代码,感兴趣的小伙伴可以了解下... 目录一、先搞懂:Map遍历的核心目标二、几种遍历方式的对比1. 传统EntrySet遍历(最通用)2. Lambd

springboot+redis实现订单过期(超时取消)功能的方法详解

《springboot+redis实现订单过期(超时取消)功能的方法详解》在SpringBoot中使用Redis实现订单过期(超时取消)功能,有多种成熟方案,本文为大家整理了几个详细方法,文中的示例代... 目录一、Redis键过期回调方案(推荐)1. 配置Redis监听器2. 监听键过期事件3. Redi

SpringBoot全局异常拦截与自定义错误页面实现过程解读

《SpringBoot全局异常拦截与自定义错误页面实现过程解读》本文介绍了SpringBoot中全局异常拦截与自定义错误页面的实现方法,包括异常的分类、SpringBoot默认异常处理机制、全局异常拦... 目录一、引言二、Spring Boot异常处理基础2.1 异常的分类2.2 Spring Boot默

基于SpringBoot实现分布式锁的三种方法

《基于SpringBoot实现分布式锁的三种方法》这篇文章主要为大家详细介绍了基于SpringBoot实现分布式锁的三种方法,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录一、基于Redis原生命令实现分布式锁1. 基础版Redis分布式锁2. 可重入锁实现二、使用Redisso

SpringBoo WebFlux+MongoDB实现非阻塞API过程

《SpringBooWebFlux+MongoDB实现非阻塞API过程》本文介绍了如何使用SpringBootWebFlux和MongoDB实现非阻塞API,通过响应式编程提高系统的吞吐量和响应性能... 目录一、引言二、响应式编程基础2.1 响应式编程概念2.2 响应式编程的优势2.3 响应式编程相关技术

C#实现将XML数据自动化地写入Excel文件

《C#实现将XML数据自动化地写入Excel文件》在现代企业级应用中,数据处理与报表生成是核心环节,本文将深入探讨如何利用C#和一款优秀的库,将XML数据自动化地写入Excel文件,有需要的小伙伴可以... 目录理解XML数据结构与Excel的对应关系引入高效工具:使用Spire.XLS for .NETC

Nginx更新SSL证书的实现步骤

《Nginx更新SSL证书的实现步骤》本文主要介绍了Nginx更新SSL证书的实现步骤,包括下载新证书、备份旧证书、配置新证书、验证配置及遇到问题时的解决方法,感兴趣的了解一下... 目录1 下载最新的SSL证书文件2 备份旧的SSL证书文件3 配置新证书4 验证配置5 遇到的http://www.cppc

Nginx之https证书配置实现

《Nginx之https证书配置实现》本文主要介绍了Nginx之https证书配置的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起... 目录背景介绍为什么不能部署在 IIS 或 NAT 设备上?具体实现证书获取nginx配置扩展结果验证

SpringBoot整合 Quartz实现定时推送实战指南

《SpringBoot整合Quartz实现定时推送实战指南》文章介绍了SpringBoot中使用Quartz动态定时任务和任务持久化实现多条不确定结束时间并提前N分钟推送的方案,本文结合实例代码给大... 目录前言一、Quartz 是什么?1、核心定位:解决什么问题?2、Quartz 核心组件二、使用步骤1