4 : QGraphicsView(parent)
7 scene =
new QGraphicsScene(
this);
11 for (
int i = 0;
i < MAX_SATELLITES;
i++) {
18 for (
int i = 0;
i < MAX_SHOWN_SATELLITES;
i++) {
19 boxes[
i] =
new QGraphicsRectItem();
20 boxes[
i]->setBrush(QColor(
"Green"));
21 scene->addItem(boxes[
i]);
24 satTexts[
i] =
new QGraphicsSimpleTextItem(
"##", boxes[i]);
25 satTexts[
i]->setBrush(QColor(
"White"));
26 satTexts[
i]->setFont(QFont(
"Courier", -1, QFont::ExtraBold));
28 satSNRs[
i] =
new QGraphicsSimpleTextItem(
"##", boxes[i]);
29 satSNRs[
i]->setBrush(QColor(
"Black"));
30 satSNRs[
i]->setFont(QFont(
"Courier", -1, QFont::ExtraBold));
56 scene->setSceneRect(0, 0, this->viewport()->width(), this->viewport()->height());
63 for (
int index = 0; index < MAX_SATELLITES; index++) {
64 if (satellites[index][3] > 0) {
65 drawSat(drawIndex++, index);
69 for (
int index = 0; index < MAX_SATELLITES; index++) {
70 if (satellites[index][3] <= 0) {
71 drawSat(drawIndex++, index);
78 if (index >= MAX_SATELLITES) {
84 satellites[index][0] = prn;
85 satellites[index][1] = elevation;
86 satellites[index][2] = azimuth;
87 satellites[index][3] = snr;
90 void GpsSnrWidget::drawSat(
int drawIndex,
int index)
92 if (index >= MAX_SATELLITES) {
97 if (drawIndex >= MAX_SHOWN_SATELLITES) {
101 const int prn = satellites[index][0];
102 const int snr = satellites[index][3];
104 boxes[drawIndex]->show();
114 int availableWidth = (int)((scene->width() - 2) / MAX_SHOWN_SATELLITES);
117 qreal width = availableWidth - 2;
119 qreal height = int((scene->height() / 99) * snr + 0.5);
121 qreal
x = availableWidth * drawIndex + 1;
123 qreal
y = scene->height() - height;
125 boxes[drawIndex]->setRect(0, 0, width - 1, height - 1);
126 boxes[drawIndex]->setPos(x, y);
128 QRectF boxRect = boxes[drawIndex]->boundingRect();
129 QString prnString = QString().number(prn);
130 if (prnString.length() == 1) {
131 prnString =
"0" + prnString;
133 satTexts[drawIndex]->setText(prnString);
134 QRectF textRect = satTexts[drawIndex]->boundingRect();
137 qreal scale = 0.85 * (boxRect.width() / textRect.width());
138 matrix.translate(boxRect.width() / 2, boxRect.height());
139 matrix.scale(scale, scale);
140 matrix.translate(-textRect.width() / 2, -textRect.height());
141 satTexts[drawIndex]->setTransform(matrix,
false);
143 QString snrString = QString().number(snr);
144 if (snrString.length() == 1) {
145 snrString =
"0" + snrString;
147 satSNRs[drawIndex]->setText(snrString);
148 textRect = satSNRs[drawIndex]->boundingRect();
151 scale = 0.85 * (boxRect.width() / textRect.width());
152 matrix.translate(boxRect.width() / 2, 0);
153 matrix.scale(scale, scale);
154 matrix.translate(-textRect.width() / 2, -textRect.height());
155 satSNRs[drawIndex]->setTransform(matrix,
false);
158 boxes[drawIndex]->hide();