Clean up and express GetGoodDay() in terms of GetDay().

Signed-off-by: Mark Watkins <jedimark@users.sourceforge.net>
This commit is contained in:
Sean Stangl 2014-04-11 15:22:23 -07:00 committed by Mark Watkins
parent c29313ab88
commit be71894ad0
4 changed files with 28 additions and 51 deletions

View File

@ -29,7 +29,7 @@ Day::~Day()
} }
} }
MachineType Day::machine_type() MachineType Day::machine_type() const
{ {
return machine->GetType(); return machine->GetType();
} }

View File

@ -41,7 +41,7 @@ class Day
void AddSession(Session *s); void AddSession(Session *s);
//! \brief Returns this machines type //! \brief Returns this machines type
MachineType machine_type(); MachineType machine_type() const;
//! \brief Returns the count of all this days sessions' events for this day //! \brief Returns the count of all this days sessions' events for this day
int count(ChannelID code); int count(ChannelID code);

View File

@ -114,7 +114,7 @@ class Machine
const QString &GetClass() { return m_class; } const QString &GetClass() { return m_class; }
//! \brief Returns the type of machine, according to MachineType enum //! \brief Returns the type of machine, according to MachineType enum
const MachineType &GetType() { return m_type; } const MachineType &GetType() const { return m_type; }
//! \brief Returns the machineID as a lower case hexadecimal string //! \brief Returns the machineID as a lower case hexadecimal string
QString hexid() { return QString().sprintf("%08lx", m_id); } QString hexid() { return QString().sprintf("%08lx", m_id); }

View File

@ -325,69 +325,46 @@ void Profile::AddDay(QDate date, Day *day, MachineType mt)
daylist[date].push_back(day); daylist[date].push_back(day);
} }
// Get Day record if data available for date and machine type, and has enabled session data, else return NULL // Get Day record if data available for date and machine type,
// and has enabled session data, else return NULL
Day *Profile::GetGoodDay(QDate date, MachineType type) Day *Profile::GetGoodDay(QDate date, MachineType type)
{ {
Day *day = NULL; Day *day = GetDay(date, type);
if (!day)
return NULL;
QMap<QDate, QList<Day *> >::iterator dli = daylist.find(date); // Just return the day if not matching for a machine.
if (type == MT_UNKNOWN)
return day;
if (dli != daylist.end()) { // For a machine match, find at least one enabled Session.
Q_ASSERT(day->machine_type() == type);
for (QList<Day *>::iterator di = (*dli).begin(); di != (*dli).end(); di++) { for (int i = 0; i < day->size(); ++i) {
if ((*day)[i]->enabled())
if (type == MT_UNKNOWN) { // Who cares.. We just want to know there is data available. return day;
day = (*di);
break;
}
if ((*di)->machine_type() == type) {
bool b = false;
for (int i = 0; i < (*di)->size(); i++) {
if ((*(*di))[i]->enabled()) {
b = true;
break;
}
}
if (b) {
day = (*di);
break;
}
}
}
} }
return day; // No enabled Sessions were found.
return NULL;
} }
Day *Profile::GetDay(QDate date, MachineType type) Day *Profile::GetDay(QDate date, MachineType type)
{ {
Day *tmp, *day = NULL; if (!daylist.contains(date))
return NULL;
if (daylist.find(date) != daylist.end()) { QList<Day *> list(daylist.value(date));
for (QList<Day *>::iterator di = daylist[date].begin(); di != daylist[date].end(); di++) { for (int i = 0; i < list.size(); ++i) {
tmp = *di; Day *day = list.at(i);
Q_ASSERT(day != NULL);
if (!tmp) { // Just return the day if not matching for a machine.
qDebug() << "This should never happen in Profile::GetDay()"; if (day->machine_type() == type || type == MT_UNKNOWN) {
break; return day;
}
if (type == MT_UNKNOWN) { // Who cares.. We just want to know there is data available.
day = tmp;
break;
}
if (tmp->machine_type() == type) {
day = tmp;
break;
}
} }
} }
return day; return NULL;
} }