mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-20 10:54:14 +01:00
LP-536 Fixes (hopefully) for PRN text scaling issue Laurent saw on his PC.
- I resolve the PRN text scaling issue by comparing the scaled text height with the available space. If there is not enough space available, the scaling factor is updated so the final scale factor fills the available space as much as possible. If the height limit has been reached, the corrected scaling is applied to both the PRN and the SNR text to keep both about the same size. - This scaling works fine on my Windows PC. I therefore removed the maximum width limit for the snrwidget. (was 850px) The snr widget will now take up all available width. This does not mean that individual bars will be scaled to fit the width of the widget. However I have implemented a two step scaling for that. If there are less than 16 visible satellites, the width of each bar is calculated based on a total of 16 bars in the view. Just like before my changes. If there are more than 16 satellites visible, the number of bars displayed is incremented from 16 to 24. An aging based hysteresis has been added to prevent continuous flapping between both states. I think this solution is aesthetically more pleasing than scaling the width of the bars to the width of the widget. Especially for low number of satellites. (This solution would show massive bars if only a few satellites are visible) - Since there was no copyright header in gpssnrwidget.cpp and gpssnrwidget.h, I have added one. The OP line is based on the last changes seen in the OP repo.
This commit is contained in:
parent
c0964cfdce
commit
cb8dd90ad7
@ -454,8 +454,8 @@
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>180</width>
|
||||
<height>90</height>
|
||||
<width>90</width>
|
||||
<height>45</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
@ -943,12 +943,12 @@
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>100</height>
|
||||
<height>80</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>850</width>
|
||||
<width>16777215</width>
|
||||
<height>100</height>
|
||||
</size>
|
||||
</property>
|
||||
|
@ -1,4 +1,33 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file gpssnrwidget.cpp
|
||||
* @author The LibrePilot Team, http://www.librepilot.org Copyright (C) 2017.
|
||||
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2014.
|
||||
* @addtogroup GCSPlugins GCS Plugins
|
||||
* @{
|
||||
* @addtogroup GpsSnrWidget GpsSnr Widget Plugin
|
||||
* @{
|
||||
* @brief A widget for visualizing Signal to Noise Ratio information for known SV
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "gpssnrwidget.h"
|
||||
#include <QGraphicsRectItem>
|
||||
#include <QFontMetrics>
|
||||
|
||||
GpsSnrWidget::GpsSnrWidget(QWidget *parent) :
|
||||
QGraphicsView(parent)
|
||||
@ -6,22 +35,31 @@ GpsSnrWidget::GpsSnrWidget(QWidget *parent) :
|
||||
scene = new QGraphicsScene(this);
|
||||
setScene(scene);
|
||||
|
||||
// Now create 'maxSatellites' signal to noise level bars:
|
||||
// Create 'maxSatellites' signal to noise level bars:
|
||||
for (int i = 0; i < MAX_SATELLITES; i++) {
|
||||
satellites[i][0] = 0;
|
||||
satellites[i][1] = 0;
|
||||
satellites[i][2] = 0;
|
||||
satellites[i][3] = 0;
|
||||
|
||||
// draw empty SNR bars and hide them for now
|
||||
boxes[i] = new QGraphicsRectItem();
|
||||
boxes[i]->setBrush(QColor("Green"));
|
||||
scene->addItem(boxes[i]);
|
||||
boxes[i]->hide();
|
||||
|
||||
// draw PRN numbers
|
||||
QFont prnFont("Digital-7", 14); // font size 14 points
|
||||
satTexts[i] = new QGraphicsSimpleTextItem("###", boxes[i]);
|
||||
satTexts[i]->setBrush(QColor("Black"));
|
||||
satTexts[i]->setFont(QFont("Digital-7"));
|
||||
satTexts[i]->setFont(prnFont);
|
||||
|
||||
// Determine the dimensions (in pixels) of a piece of prn reference text.
|
||||
// This is used to make the scaling independent from the width of the actual prn text.
|
||||
QFontMetrics fm(prnFont);
|
||||
prnReferenceTextRect = fm.boundingRect("###");
|
||||
|
||||
// draw SNR levels
|
||||
satSNRs[i] = new QGraphicsSimpleTextItem("##", boxes[i]);
|
||||
satSNRs[i]->setBrush(QColor("Black"));
|
||||
satSNRs[i]->setFont(QFont("Arial"));
|
||||
@ -68,19 +106,51 @@ void GpsSnrWidget::updateSat(int index, int prn, int elevation, int azimuth, int
|
||||
drawSat(index);
|
||||
}
|
||||
|
||||
#define PRN_TEXTAREA_HEIGHT 20
|
||||
#define SIDE_MARGIN 15
|
||||
#define PRN_TEXTAREA_HEIGHT 20
|
||||
#define SIDE_MARGIN 15
|
||||
#define HIGH_SAT_AGING_CYCLES 10
|
||||
|
||||
void GpsSnrWidget::drawSat(int index)
|
||||
{
|
||||
static int satsToShow = MAX_SATELLITES;
|
||||
static int lastNrVisibleSats = 0;
|
||||
static int highSatelliteCountAge = 0;
|
||||
bool heightLimited = false;
|
||||
|
||||
if (index >= MAX_SATELLITES) {
|
||||
// A bit of error checking never hurts.
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
Set the maximum number of satellites in the SNR widget based on the number
|
||||
of satellites previously seen.
|
||||
This code implements an aging timer to prevent flapping between different scales.
|
||||
|
||||
There is a known issue: the current implementation can not differentiate between
|
||||
multiple sources of GPS information. For example a flight controller and a GPS mouse.
|
||||
|
||||
In this case, the scale will always be set to the scale necessary for the
|
||||
source with the highest number of satellites in view.
|
||||
*/
|
||||
if (index == 0) {
|
||||
if (lastNrVisibleSats > 16) {
|
||||
satsToShow = MAX_SATELLITES;
|
||||
highSatelliteCountAge = HIGH_SAT_AGING_CYCLES;
|
||||
} else if (highSatelliteCountAge > 0) {
|
||||
satsToShow = MAX_SATELLITES;
|
||||
--highSatelliteCountAge;
|
||||
} else {
|
||||
satsToShow = 16;
|
||||
}
|
||||
lastNrVisibleSats = 0;
|
||||
}
|
||||
|
||||
const int prn = satellites[index][0];
|
||||
const int snr = satellites[index][3];
|
||||
if (prn && snr) {
|
||||
lastNrVisibleSats++;
|
||||
|
||||
// When using integer values, width and height are the
|
||||
// box width and height, but the left and bottom borders are drawn on the box,
|
||||
// and the top and right borders are drawn just next to the box.
|
||||
@ -89,7 +159,7 @@ void GpsSnrWidget::drawSat(int index)
|
||||
|
||||
// Casting to int rounds down, which is what I want.
|
||||
// Minus 2 to allow a pixel of white left and right.
|
||||
int availableWidth = (int)((scene->width() - 2 - 2 * SIDE_MARGIN) / MAX_SATELLITES);
|
||||
int availableWidth = (int)((scene->width() - 2 - 2 * SIDE_MARGIN) / satsToShow);
|
||||
|
||||
// If there is no space, don't draw anything.
|
||||
if (availableWidth <= 0) {
|
||||
@ -139,27 +209,35 @@ void GpsSnrWidget::drawSat(int index)
|
||||
satTexts[index]->setText(prnString);
|
||||
QRectF textRect = satTexts[index]->boundingRect();
|
||||
|
||||
// Reposition PRN numbers below the bar and rescale
|
||||
// Reposition PRN levels below the bar and rescale to fit the available space
|
||||
QTransform matrix;
|
||||
// rescale based on the textRect height because it depends less on the number of digits:
|
||||
qreal scale = 0.68 * (boxRect.width() / textRect.height());
|
||||
qreal scale = 0.85 * (boxRect.width() / prnReferenceTextRect.width());
|
||||
|
||||
// Limit the maximum PRN text height to PRN_TEXTAREA_HEIGHT
|
||||
if ((prnReferenceTextRect.height() * scale) > (PRN_TEXTAREA_HEIGHT)) {
|
||||
scale = (PRN_TEXTAREA_HEIGHT) / prnReferenceTextRect.height();
|
||||
heightLimited = true;
|
||||
}
|
||||
|
||||
matrix.translate(boxRect.width() / 2, boxRect.height());
|
||||
matrix.scale(scale, scale);
|
||||
matrix.translate(-textRect.width() / 2, 0);
|
||||
satTexts[index]->setTransform(matrix, false);
|
||||
|
||||
|
||||
// Add leading 0 to SNR values
|
||||
QString snrString = QString().number(snr);
|
||||
if (snrString.length() == 1) {
|
||||
snrString = "0" + snrString;
|
||||
}
|
||||
satSNRs[index]->setText(snrString);
|
||||
textRect = satSNRs[index]->boundingRect();
|
||||
|
||||
// Reposition SNR levels above the bar and rescale
|
||||
// Reposition SNR levels above the bar and rescale to fit the available space
|
||||
matrix.reset();
|
||||
// rescale based on the textRect height because it depends less on the number of digits:
|
||||
scale = 0.60 * (boxRect.width() / textRect.height());
|
||||
textRect = satSNRs[index]->boundingRect();
|
||||
if (!heightLimited) {
|
||||
scale = 0.85 * (boxRect.width() / prnReferenceTextRect.width());
|
||||
}
|
||||
matrix.translate(boxRect.width() / 2, 0);
|
||||
matrix.scale(scale, scale);
|
||||
matrix.translate(-textRect.width() / 2, -textRect.height());
|
||||
|
@ -1,8 +1,35 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file gpssnrwidget.h
|
||||
* @author The LibrePilot Team, http://www.librepilot.org Copyright (C) 2017.
|
||||
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2014.
|
||||
* @addtogroup GCSPlugins GCS Plugins
|
||||
* @{
|
||||
* @addtogroup GpsSnrWidget GpsSnr Widget Plugin
|
||||
* @{
|
||||
* @brief A widget for visualizing Signal to Noise Ratio information for known SV
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GPSSNRWIDGET_H
|
||||
#define GPSSNRWIDGET_H
|
||||
|
||||
#include <QGraphicsView>
|
||||
#include <QGraphicsRectItem>
|
||||
class QGraphicsRectItem;
|
||||
|
||||
class GpsSnrWidget : public QGraphicsView {
|
||||
Q_OBJECT
|
||||
@ -22,6 +49,7 @@ private:
|
||||
QGraphicsRectItem *boxes[MAX_SATELLITES];
|
||||
QGraphicsSimpleTextItem *satTexts[MAX_SATELLITES];
|
||||
QGraphicsSimpleTextItem *satSNRs[MAX_SATELLITES];
|
||||
QRectF prnReferenceTextRect;
|
||||
|
||||
void drawSat(int index);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user