Merge pull request #1488 from srcejon/fix_1483

Sat Tracker: Format time to next event as [HH:]MM:SS, rather than MMMM:SS
This commit is contained in:
Edouard Griffiths 2022-10-27 23:10:59 +02:00 committed by GitHub
commit 36d8024717
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 13 deletions

View File

@ -1008,8 +1008,8 @@ void SatelliteTrackerGUI::resizeTable()
ui->satTable->setItem(row, SAT_COL_NAME, new QTableWidgetItem("Satellite123")); ui->satTable->setItem(row, SAT_COL_NAME, new QTableWidgetItem("Satellite123"));
ui->satTable->setItem(row, SAT_COL_AZ, new QTableWidgetItem("360")); ui->satTable->setItem(row, SAT_COL_AZ, new QTableWidgetItem("360"));
ui->satTable->setItem(row, SAT_COL_EL, new QTableWidgetItem("-90")); ui->satTable->setItem(row, SAT_COL_EL, new QTableWidgetItem("-90"));
ui->satTable->setItem(row, SAT_COL_TNE, new QTableWidgetItem("9999:99 AOS")); ui->satTable->setItem(row, SAT_COL_TNE, new QTableWidgetItem("99:99:99 AOS"));
ui->satTable->setItem(row, SAT_COL_DUR, new QTableWidgetItem("999:99")); ui->satTable->setItem(row, SAT_COL_DUR, new QTableWidgetItem("9:99:99"));
ui->satTable->setItem(row, SAT_COL_AOS, new QTableWidgetItem("+1 10:17")); ui->satTable->setItem(row, SAT_COL_AOS, new QTableWidgetItem("+1 10:17"));
ui->satTable->setItem(row, SAT_COL_LOS, new QTableWidgetItem("+1 10:17")); ui->satTable->setItem(row, SAT_COL_LOS, new QTableWidgetItem("+1 10:17"));
ui->satTable->setItem(row, SAT_COL_MAX_EL, new QTableWidgetItem("90")); ui->satTable->setItem(row, SAT_COL_MAX_EL, new QTableWidgetItem("90"));
@ -1045,8 +1045,7 @@ QString SatelliteTrackerGUI::formatDaysTime(qint64 days, QDateTime dateTime)
return dt.time().toString(QString("hh:mm %1").arg(days)); return dt.time().toString(QString("hh:mm %1").arg(days));
} }
QString SatelliteTrackerGUI::formatSecondsAsHHMMSS(qint64 seconds)
QString SatelliteTrackerGUI::formatSecondsHHMM(qint64 seconds)
{ {
char const* sign = ""; char const* sign = "";
if(seconds < 0) if(seconds < 0)
@ -1054,10 +1053,17 @@ QString SatelliteTrackerGUI::formatSecondsHHMM(qint64 seconds)
sign = "-"; sign = "-";
seconds = -seconds; seconds = -seconds;
} }
return QString("%1%2:%3").arg(sign).arg(seconds/60).arg(seconds%60,2,10,QChar('0')); int minutes = seconds / 60;
seconds = seconds % 60;
int hours = minutes / 60;
minutes = minutes % 60;
if (hours > 0) {
return QString("%1%2:%3:%4").arg(sign).arg(hours).arg(minutes, 2, 10, QChar('0')).arg(seconds, 2, 10, QChar('0'));
} else {
return QString("%1%2:%3").arg(sign).arg(minutes).arg(seconds, 2, 10, QChar('0'));
}
} }
// Table item showing some text, but sorted by datetime set as user data // Table item showing some text, but sorted by datetime set as user data
class DateTimeSortedTableWidgetItem : public QTableWidgetItem { class DateTimeSortedTableWidgetItem : public QTableWidgetItem {
public: public:
@ -1072,7 +1078,6 @@ public:
} }
}; };
class NaturallySortedTableWidgetItem : public QTableWidgetItem class NaturallySortedTableWidgetItem : public QTableWidgetItem
{ {
public: public:
@ -1084,8 +1089,6 @@ public:
} }
}; };
#define SPEED_OF_LIGHT 299792458.0 #define SPEED_OF_LIGHT 299792458.0
// Frequency in Hz, speed in m/s // Frequency in Hz, speed in m/s
@ -1162,10 +1165,10 @@ void SatelliteTrackerGUI::updateTable(SatelliteState *satState)
int daysToAOS = currentDateTime.daysTo(satState->m_passes[0].m_aos); int daysToAOS = currentDateTime.daysTo(satState->m_passes[0].m_aos);
int daysToLOS = currentDateTime.daysTo(satState->m_passes[0].m_los); int daysToLOS = currentDateTime.daysTo(satState->m_passes[0].m_los);
if (satState->m_passes[0].m_aos > currentDateTime) if (satState->m_passes[0].m_aos > currentDateTime)
items[SAT_COL_TNE]->setText(formatSecondsHHMM(currentDateTime.secsTo(satState->m_passes[0].m_aos))+" AOS"); items[SAT_COL_TNE]->setText(formatSecondsAsHHMMSS(currentDateTime.secsTo(satState->m_passes[0].m_aos))+" AOS");
else else
items[SAT_COL_TNE]->setText(formatSecondsHHMM(currentDateTime.secsTo(satState->m_passes[0].m_los))+" LOS"); items[SAT_COL_TNE]->setText(formatSecondsAsHHMMSS(currentDateTime.secsTo(satState->m_passes[0].m_los))+" LOS");
items[SAT_COL_DUR]->setText(formatSecondsHHMM(satState->m_passes[0].m_aos.secsTo(satState->m_passes[0].m_los))); items[SAT_COL_DUR]->setText(formatSecondsAsHHMMSS(satState->m_passes[0].m_aos.secsTo(satState->m_passes[0].m_los)));
items[SAT_COL_AOS]->setText(formatDaysTime(daysToAOS, satState->m_passes[0].m_aos)); items[SAT_COL_AOS]->setText(formatDaysTime(daysToAOS, satState->m_passes[0].m_aos));
items[SAT_COL_AOS]->setData(Qt::UserRole, satState->m_passes[0].m_aos); items[SAT_COL_AOS]->setData(Qt::UserRole, satState->m_passes[0].m_aos);
items[SAT_COL_LOS]->setText(formatDaysTime(daysToLOS, satState->m_passes[0].m_los)); items[SAT_COL_LOS]->setText(formatDaysTime(daysToLOS, satState->m_passes[0].m_los));

View File

@ -129,7 +129,7 @@ private:
QAction *createCheckableItem(QString& text, int idx, bool checked); QAction *createCheckableItem(QString& text, int idx, bool checked);
void updateTimeToAOS(); void updateTimeToAOS();
QString formatDaysTime(qint64 days, QDateTime dateTime); QString formatDaysTime(qint64 days, QDateTime dateTime);
QString formatSecondsHHMM(qint64 seconds); QString formatSecondsAsHHMMSS(qint64 seconds);
void updateDeviceFeatureCombo(); void updateDeviceFeatureCombo();
void updateDeviceFeatureCombo(const QStringList &items, const QString &selected); void updateDeviceFeatureCombo(const QStringList &items, const QString &selected);
void updateFileInputList(); void updateFileInputList();