Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Satellite Tracker: Fix sorting of next column #1493

Merged
merged 1 commit into from
Oct 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions plugins/feature/satellitetracker/satellitetrackergui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1080,14 +1080,37 @@ class DateTimeSortedTableWidgetItem : public QTableWidgetItem {
}
};

// 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
{
public:
bool operator<(const QTableWidgetItem &other) const override
{
QCollator coll;
coll.setNumericMode(true);
return coll.compare( text() , other.text() ) < 0;
return coll.compare(text() , other.text()) < 0;
}
};

Expand Down Expand Up @@ -1127,8 +1150,10 @@ void SatelliteTrackerGUI::updateTable(SatelliteState *satState)
{
if ((i == SAT_COL_AOS) || (i == SAT_COL_LOS))
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();
else if (i == SAT_COL_TNE)
items[i] = new NextEventTableWidgetItem();
else
items[i] = new NaturallySortedTableWidgetItem();
items[i]->setToolTip(ui->satTable->horizontalHeaderItem(i)->toolTip());
Expand Down