1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-03 11:24:10 +01:00

GCS GpsDisplay: Display PRN numbers in constellation, and some cleanup.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1721 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
cranphin 2010-09-22 21:36:11 +00:00 committed by cranphin
parent e4d317f40e
commit d9dc37ad33
2 changed files with 48 additions and 17 deletions

View File

@ -30,8 +30,6 @@
#include <QtGui> #include <QtGui>
#include <QDebug> #include <QDebug>
/* /*
* Initialize the widget * Initialize the widget
*/ */
@ -53,30 +51,43 @@ GpsConstellationWidget::GpsConstellationWidget(QWidget *parent) : QGraphicsView(
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
QGraphicsScene *scene = new QGraphicsScene(this);
QSvgRenderer *renderer = new QSvgRenderer(); QSvgRenderer *renderer = new QSvgRenderer();
world = new QGraphicsSvgItem();
renderer->load(QString(":/gpsgadget/images/gpsEarth.svg")); renderer->load(QString(":/gpsgadget/images/gpsEarth.svg"));
world = new QGraphicsSvgItem();
world->setSharedRenderer(renderer); world->setSharedRenderer(renderer);
world->setElementId("map"); world->setElementId("map");
scene = new QGraphicsScene(this);
scene->addItem(world); scene->addItem(world);
scene->setSceneRect(world->boundingRect()); scene->setSceneRect(world->boundingRect());
setScene(scene); setScene(scene);
// Now create 16 satellite icons which we will move around on the map: // Now create 'maxSatellites' satellite icons which we will move around on the map:
for (int i=0; i<16;i++) { for (int i=0; i < MAX_SATTELITES;i++) {
satIcons[i] = new QGraphicsSvgItem(); satellites[i][0] = 0;
satellites[i][1] = 0;
satellites[i][2] = 0;
satellites[i][3] = 0;
satIcons[i] = new QGraphicsSvgItem(world);
satIcons[i]->setSharedRenderer(renderer); satIcons[i]->setSharedRenderer(renderer);
satIcons[i]->setElementId("sat-notSeen"); satIcons[i]->setElementId("sat-notSeen");
satIcons[i]->setParentItem(world);
satIcons[i]->hide(); satIcons[i]->hide();
}
satTexts[i] = new QGraphicsSimpleTextItem("##",satIcons[i]);
satTexts[i]->setBrush(QColor("Black"));
satTexts[i]->setFont(QFont("Courier"));
}
} }
GpsConstellationWidget::~GpsConstellationWidget() GpsConstellationWidget::~GpsConstellationWidget()
{ {
delete scene;
scene = 0;
delete renderer;
renderer = 0;
} }
void GpsConstellationWidget::showEvent(QShowEvent *event) void GpsConstellationWidget::showEvent(QShowEvent *event)
@ -101,8 +112,9 @@ void GpsConstellationWidget::resizeEvent(QResizeEvent* event)
void GpsConstellationWidget::updateSat(int index, int prn, int elevation, int azimuth, int snr) void GpsConstellationWidget::updateSat(int index, int prn, int elevation, int azimuth, int snr)
{ {
if (index >= 16) { if (index >= MAX_SATTELITES) {
return; // A bit of error checking never hurts. // A bit of error checking never hurts.
return;
} }
// TODO: add range checking // TODO: add range checking
@ -116,12 +128,27 @@ void GpsConstellationWidget::updateSat(int index, int prn, int elevation, int az
opd += QPointF(-satIcons[index]->boundingRect().center().x(), opd += QPointF(-satIcons[index]->boundingRect().center().x(),
-satIcons[index]->boundingRect().center().y()); -satIcons[index]->boundingRect().center().y());
satIcons[index]->setTransform(QTransform::fromTranslate(opd.x(),opd.y()), false); satIcons[index]->setTransform(QTransform::fromTranslate(opd.x(),opd.y()), false);
if (snr) if (snr) {
satIcons[index]->setElementId("satellite"); satIcons[index]->setElementId("satellite");
else } else {
satIcons[index]->setElementId("sat-notSeen"); satIcons[index]->setElementId("sat-notSeen");
}
satIcons[index]->show(); satIcons[index]->show();
QRectF iconRect = satIcons[index]->boundingRect();
QString prnString = QString().number(prn);
if(prnString.length() == 1) {
prnString = "0" + prnString;
}
satTexts[index]->setText(prnString);
QRectF textRect = satTexts[index]->boundingRect();
QTransform matrix;
qreal scale = 0.70 * (iconRect.width() / textRect.width());
matrix.translate(iconRect.width()/2, iconRect.height()/2);
matrix.scale(scale,scale);
matrix.translate(-textRect.width()/2,-textRect.height()/2);
satTexts[index]->setTransform(matrix,false);
} else { } else {
satIcons[index]->hide(); satIcons[index]->hide();
} }

View File

@ -48,10 +48,14 @@ public slots:
private slots: private slots:
private: private:
int satellites[16][4]; static const int MAX_SATTELITES = 16;
QGraphicsSvgItem* satIcons[16]; int satellites[MAX_SATTELITES][4];
QGraphicsSvgItem *world; QGraphicsScene *scene;
QGraphicsView *gpsConstellation; QSvgRenderer *renderer;
QGraphicsSvgItem* world;
QGraphicsSvgItem* satIcons[MAX_SATTELITES];
QGraphicsSimpleTextItem* satTexts[MAX_SATTELITES];
QPointF polarToCoord(int elevation, int azimuth); QPointF polarToCoord(int elevation, int azimuth);
protected: protected: