GcCalendar optimizations

Updated GcCalendar and GcCalendarModel to reduce model
refreshe and redraws when not visible or the month/year
hasn't changed.

Fixes #538.
This commit is contained in:
Mark Liversedge
2013-03-31 13:10:54 +01:00
parent 62304c5a4c
commit 784275256b
3 changed files with 46 additions and 2 deletions

View File

@@ -709,6 +709,7 @@ GcMiniCalendar::setRide(RideItem *ride)
if (ride != _ride) {
_ride = ride;
QDate when;
if (_ride && _ride->ride()) when = _ride->dateTime.date();
else when = QDate::currentDate();
@@ -833,6 +834,11 @@ GcMultiCalendar::setFilter(QStringList filter)
{
this->filters = filter;
if (!isVisible()) {
stale = true;
return;
}
for (int i=0; i<calendars.count();i++) {
calendars.at(i)->setFilter(filter);
}
@@ -848,6 +854,11 @@ GcMultiCalendar::clearFilter()
{
this->filters.clear();
if (!isVisible()) {
stale = true;
return;
}
for (int i=0; i<calendars.count();i++) {
calendars.at(i)->clearFilter();
}
@@ -861,6 +872,11 @@ GcMultiCalendar::clearFilter()
void
GcMultiCalendar::dateChanged(int month, int year)
{
if (!isVisible()) {
stale = true;
return;
}
setUpdatesEnabled(false);
// master changed make all the others change too
@@ -876,6 +892,11 @@ GcMultiCalendar::dateChanged(int month, int year)
void
GcMultiCalendar::resizeEvent(QResizeEvent*)
{
if (!isVisible()) {
stale = true;
return;
}
// we expand x and y
int oldshowing = showing;
showing = height() < 180 ? 1 : (int)(height() / 180);
@@ -899,13 +920,18 @@ GcMultiCalendar::resizeEvent(QResizeEvent*)
} else {
for (int i=0; i<have; i++) {
for (int i=0; i<calendars.count(); i++) {
if (i>=oldshowing && i<showing) {
calendars.at(i)->setFilter(this->filters);
calendars.at(i)->setDate(first.addMonths(i).month(), first.addMonths(i).year());
calendars.at(i)->show();
}
else if (i>=showing) calendars.at(i)->hide();
else if (i>=showing) {
GcMiniCalendar *p = calendars.at(i);
delete p;
calendars.remove(i);
i--; // i is incremented in loop, but we just deleted
}
}
}
}
@@ -913,7 +939,13 @@ GcMultiCalendar::resizeEvent(QResizeEvent*)
void
GcMultiCalendar::setRide(RideItem *ride)
{
_ride = ride;
if (active) return;
if (!isVisible()) {
stale = true;
return;
}
setUpdatesEnabled(false);
active = true; // avoid multiple calls
@@ -967,3 +999,11 @@ GcMultiCalendar::refresh()
}
setUpdatesEnabled(true);
}
void
GcMultiCalendar::showEvent(QShowEvent*)
{
setFilter(filters);
resizeEvent(NULL);
setRide(_ride);
}

View File

@@ -134,6 +134,7 @@ class GcMultiCalendar : public QScrollArea
void resizeEvent(QResizeEvent*);
void setFilter(QStringList filter);
void clearFilter();
void showEvent(QShowEvent*);
private:
@@ -143,6 +144,8 @@ class GcMultiCalendar : public QScrollArea
int showing;
QStringList filters;
bool active;
bool stale; // we need to redraw when shown
RideItem *_ride;
};
class GcCalendar : public QWidget // not a GcWindow - belongs on sidebar

View File

@@ -129,6 +129,7 @@ public slots:
dateToRows.insert(dateTime.date(), arr);
}
reset();
}
public: