[qt] QtEventFinder cleanup
parent
24bce0bb82
commit
edc4d240be
|
@ -38,12 +38,6 @@ using namespace std;
|
||||||
using namespace celmath;
|
using namespace celmath;
|
||||||
|
|
||||||
|
|
||||||
// TODO: share this constant and function with render.cpp
|
|
||||||
static const float MinRelativeOccluderRadius = 0.005f;
|
|
||||||
|
|
||||||
static const int EclipseObjectMask = Body::Planet | Body::Moon | Body::DwarfPlanet | Body::Asteroid;
|
|
||||||
|
|
||||||
|
|
||||||
// Functions to convert between Qt dates and Celestia dates.
|
// Functions to convert between Qt dates and Celestia dates.
|
||||||
// TODO: Qt's date class doesn't support leap seconds
|
// TODO: Qt's date class doesn't support leap seconds
|
||||||
static double QDateToTDB(const QDate& date)
|
static double QDateToTDB(const QDate& date)
|
||||||
|
@ -64,47 +58,6 @@ static QDateTime TDBToQDate(double tdb)
|
||||||
Qt::UTC);
|
Qt::UTC);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct EclipseOcculterSortPredicate
|
|
||||||
{
|
|
||||||
bool operator()(const Eclipse& e0, const Eclipse& e1)
|
|
||||||
{
|
|
||||||
return e0.occulter->getName() < e1.occulter->getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
int dummy;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct EclipseReceiverSortPredicate
|
|
||||||
{
|
|
||||||
bool operator()(const Eclipse& e0, const Eclipse& e1)
|
|
||||||
{
|
|
||||||
return e0.receiver->getName() < e1.receiver->getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
int dummy;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct EclipseStartTimeSortPredicate
|
|
||||||
{
|
|
||||||
bool operator()(const Eclipse& e0, const Eclipse& e1)
|
|
||||||
{
|
|
||||||
return e0.startTime < e1.startTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
int dummy;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct EclipseDurationSortPredicate
|
|
||||||
{
|
|
||||||
bool operator()(const Eclipse& e0, const Eclipse& e1)
|
|
||||||
{
|
|
||||||
return e0.endTime - e0.startTime < e1.endTime - e1.startTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
int dummy;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class EventTableModel : public QAbstractTableModel
|
class EventTableModel : public QAbstractTableModel
|
||||||
{
|
{
|
||||||
|
@ -113,12 +66,12 @@ public:
|
||||||
virtual ~EventTableModel() = default;
|
virtual ~EventTableModel() = default;
|
||||||
|
|
||||||
// Methods from QAbstractTableModel
|
// Methods from QAbstractTableModel
|
||||||
Qt::ItemFlags flags(const QModelIndex& index) const;
|
Qt::ItemFlags flags(const QModelIndex& index) const override;
|
||||||
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||||
int rowCount(const QModelIndex& index) const;
|
int rowCount(const QModelIndex& index) const override;
|
||||||
int columnCount(const QModelIndex& index) const;
|
int columnCount(const QModelIndex& index) const override;
|
||||||
void sort(int column, Qt::SortOrder order);
|
void sort(int column, Qt::SortOrder order) override;
|
||||||
|
|
||||||
void setEclipses(const vector<Eclipse>& _eclipses);
|
void setEclipses(const vector<Eclipse>& _eclipses);
|
||||||
|
|
||||||
|
@ -151,30 +104,27 @@ QVariant EventTableModel::data(const QModelIndex& index, int role) const
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (role != Qt::DisplayRole)
|
||||||
|
{
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
const Eclipse& eclipse = eclipses[index.row()];
|
const Eclipse& eclipse = eclipses[index.row()];
|
||||||
|
|
||||||
if (role == Qt::DisplayRole)
|
switch (index.column())
|
||||||
{
|
{
|
||||||
switch (index.column())
|
case ReceiverColumn:
|
||||||
{
|
return QString(eclipse.receiver->getName(true).c_str());
|
||||||
case ReceiverColumn:
|
case OcculterColumn:
|
||||||
return QString(eclipse.receiver->getName(true).c_str());
|
return QString(eclipse.occulter->getName(true).c_str());
|
||||||
case OcculterColumn:
|
case StartTimeColumn:
|
||||||
return QString(eclipse.occulter->getName(true).c_str());
|
return TDBToQDate(eclipse.startTime).toLocalTime().toString("dd MMM yyyy hh:mm");
|
||||||
case StartTimeColumn:
|
case DurationColumn:
|
||||||
return TDBToQDate(eclipse.startTime).toLocalTime().toString("dd MMM yyyy hh:mm");
|
{
|
||||||
case DurationColumn:
|
int minutes = (int) ((eclipse.endTime - eclipse.startTime) * 24 * 60);
|
||||||
{
|
return QString("%1:%2").arg(minutes / 60).arg(minutes % 60, 2, 10, QLatin1Char('0'));
|
||||||
int minutes = (int) ((eclipse.endTime - eclipse.startTime) * 24 * 60);
|
|
||||||
return QString("%1:%2").arg(minutes / 60).arg(minutes % 60, 2, 10, QLatin1Char('0'));
|
|
||||||
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
default:
|
||||||
{
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -218,16 +168,20 @@ void EventTableModel::sort(int column, Qt::SortOrder order)
|
||||||
switch (column)
|
switch (column)
|
||||||
{
|
{
|
||||||
case ReceiverColumn:
|
case ReceiverColumn:
|
||||||
std::sort(eclipses.begin(), eclipses.end(), EclipseReceiverSortPredicate());
|
std::sort(eclipses.begin(), eclipses.end(),
|
||||||
|
[](const Eclipse& e0, const Eclipse& e1) { return e0.receiver->getName() < e1.receiver->getName(); });
|
||||||
break;
|
break;
|
||||||
case OcculterColumn:
|
case OcculterColumn:
|
||||||
std::sort(eclipses.begin(), eclipses.end(), EclipseOcculterSortPredicate());
|
std::sort(eclipses.begin(), eclipses.end(),
|
||||||
|
[](const Eclipse& e0, const Eclipse& e1) { return e0.occulter->getName() < e1.occulter->getName(); });
|
||||||
break;
|
break;
|
||||||
case StartTimeColumn:
|
case StartTimeColumn:
|
||||||
std::sort(eclipses.begin(), eclipses.end(), EclipseStartTimeSortPredicate());
|
std::sort(eclipses.begin(), eclipses.end(),
|
||||||
|
[](const Eclipse& e0, const Eclipse& e1) { return e0.startTime < e1.startTime; });
|
||||||
break;
|
break;
|
||||||
case DurationColumn:
|
case DurationColumn:
|
||||||
std::sort(eclipses.begin(), eclipses.end(), EclipseDurationSortPredicate());
|
std::sort(eclipses.begin(), eclipses.end(),
|
||||||
|
[](const Eclipse& e0, const Eclipse& e1) { return e0.endTime - e0.startTime < e1.endTime - e1.startTime; });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue