mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 16:18:42 +00:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -129,6 +129,7 @@ public slots:
|
||||
dateToRows.insert(dateTime.date(), arr);
|
||||
}
|
||||
reset();
|
||||
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user