Invalidate hour cache when enabling/disabling sessions

This commit is contained in:
Mark Watkins 2014-10-11 13:07:29 +10:00
parent dac961d981
commit 5e8047f528
5 changed files with 47 additions and 2 deletions

View File

@ -791,7 +791,7 @@ qint64 Day::total_time(MachineType type)
Session &sess = *(*it);
int slicesize = sess.m_slices.size();
if ((sess.type() == type) && sess.enabled()) {
if (sess.enabled() && (sess.type() == type)) {
first = sess.first();
last = sess.last();

View File

@ -1260,6 +1260,39 @@ EventDataType Profile::calcBelowThreshold(ChannelID code, EventDataType threshol
return val;
}
Day * Profile::findSessionDay(Session * session)
{
MachineType mt = session->type();
QDate start = LastGoodDay(mt);
QDate end = LastGoodDay(mt);
QDate date = start;
if (date.isNull()) {
return 0;
}
double val = 0;
int cnt = 0;
do {
Day *day = FindGoodDay(date, mt);
if (day) {
for (int i=0; i<day->size(); i++) {
Session * s = day->sessions.at(i);
if (s == session) {
return day;
}
}
}
date = date.addDays(1);
} while (date <= end);
return nullptr;
}
EventDataType Profile::calcAvg(ChannelID code, MachineType mt, QDate start, QDate end)
{

View File

@ -181,6 +181,7 @@ class Profile : public Preferences
QDate start = QDate(), QDate end = QDate());
Day * findSessionDay(Session * session);
// XML load components
virtual void ExtraLoad(QDomElement &root);

View File

@ -86,6 +86,17 @@ void Session::TrashEvents()
eventlist.squeeze();
}
void Session::setEnabled(bool b)
{
s_enabled = b;
// not so simple.. we have to invalidate the hours cache in the day record..
Day * day = p_profile->findSessionDay(this);
if (day) {
day->invalidate();
}
}
QString Session::eventFile() const
{
return s_machine->getEventsPath()+QString().sprintf("%08lx.001", s_session);

View File

@ -111,7 +111,7 @@ class Session
inline bool enabled() const { return s_enabled; }
//! \brief Sets whether or not session is being used.
void setEnabled(bool b) { s_enabled = b; }
void setEnabled(bool b);
inline qint64 realFirst() const { return s_first; }
inline qint64 realLast() const { return s_last; }