1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-22 08:04:49 -05:00

Merge pull request #1493 from srcejon/fix_sat_tracker_next_sort

Satellite Tracker: Fix sorting of next column
This commit is contained in:
Edouard Griffiths 2022-10-29 03:15:52 +02:00 committed by GitHub
commit fcb156b5da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1080,6 +1080,29 @@ public:
} }
}; };
// Handle sorting for next column, which can have times as HH:MM:SS or MM:SS
class NextEventTableWidgetItem : public QTableWidgetItem
{
public:
bool operator<(const QTableWidgetItem &other) const override
{
QString t1 = text();
QString t2 = other.text();
int t1Colons = t1.count(":");
int t2Colons = t2.count(":");
if (t1Colons == t2Colons)
{
QCollator coll;
coll.setNumericMode(true);
return coll.compare(t1, t2) < 0;
}
else
{
return t1Colons < t2Colons;
}
}
};
class NaturallySortedTableWidgetItem : public QTableWidgetItem class NaturallySortedTableWidgetItem : public QTableWidgetItem
{ {
public: public:
@ -1087,7 +1110,7 @@ public:
{ {
QCollator coll; QCollator coll;
coll.setNumericMode(true); coll.setNumericMode(true);
return coll.compare( text() , other.text() ) < 0; return coll.compare(text() , other.text()) < 0;
} }
}; };
@ -1127,8 +1150,10 @@ void SatelliteTrackerGUI::updateTable(SatelliteState *satState)
{ {
if ((i == SAT_COL_AOS) || (i == SAT_COL_LOS)) if ((i == SAT_COL_AOS) || (i == SAT_COL_LOS))
items[i] = new DateTimeSortedTableWidgetItem(); items[i] = new DateTimeSortedTableWidgetItem();
else if((i == SAT_COL_NAME) || (i == SAT_COL_NORAD_ID)) else if ((i == SAT_COL_NAME) || (i == SAT_COL_NORAD_ID))
items[i] = new QTableWidgetItem(); items[i] = new QTableWidgetItem();
else if (i == SAT_COL_TNE)
items[i] = new NextEventTableWidgetItem();
else else
items[i] = new NaturallySortedTableWidgetItem(); items[i] = new NaturallySortedTableWidgetItem();
items[i]->setToolTip(ui->satTable->horizontalHeaderItem(i)->toolTip()); items[i]->setToolTip(ui->satTable->horizontalHeaderItem(i)->toolTip());