mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-04-15 05:32:21 +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) {
|
if (ride != _ride) {
|
||||||
_ride = ride;
|
_ride = ride;
|
||||||
|
|
||||||
|
|
||||||
QDate when;
|
QDate when;
|
||||||
if (_ride && _ride->ride()) when = _ride->dateTime.date();
|
if (_ride && _ride->ride()) when = _ride->dateTime.date();
|
||||||
else when = QDate::currentDate();
|
else when = QDate::currentDate();
|
||||||
@@ -833,6 +834,11 @@ GcMultiCalendar::setFilter(QStringList filter)
|
|||||||
{
|
{
|
||||||
this->filters = filter;
|
this->filters = filter;
|
||||||
|
|
||||||
|
if (!isVisible()) {
|
||||||
|
stale = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i=0; i<calendars.count();i++) {
|
for (int i=0; i<calendars.count();i++) {
|
||||||
calendars.at(i)->setFilter(filter);
|
calendars.at(i)->setFilter(filter);
|
||||||
}
|
}
|
||||||
@@ -848,6 +854,11 @@ GcMultiCalendar::clearFilter()
|
|||||||
{
|
{
|
||||||
this->filters.clear();
|
this->filters.clear();
|
||||||
|
|
||||||
|
if (!isVisible()) {
|
||||||
|
stale = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i=0; i<calendars.count();i++) {
|
for (int i=0; i<calendars.count();i++) {
|
||||||
calendars.at(i)->clearFilter();
|
calendars.at(i)->clearFilter();
|
||||||
}
|
}
|
||||||
@@ -861,6 +872,11 @@ GcMultiCalendar::clearFilter()
|
|||||||
void
|
void
|
||||||
GcMultiCalendar::dateChanged(int month, int year)
|
GcMultiCalendar::dateChanged(int month, int year)
|
||||||
{
|
{
|
||||||
|
if (!isVisible()) {
|
||||||
|
stale = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setUpdatesEnabled(false);
|
setUpdatesEnabled(false);
|
||||||
|
|
||||||
// master changed make all the others change too
|
// master changed make all the others change too
|
||||||
@@ -876,6 +892,11 @@ GcMultiCalendar::dateChanged(int month, int year)
|
|||||||
void
|
void
|
||||||
GcMultiCalendar::resizeEvent(QResizeEvent*)
|
GcMultiCalendar::resizeEvent(QResizeEvent*)
|
||||||
{
|
{
|
||||||
|
if (!isVisible()) {
|
||||||
|
stale = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// we expand x and y
|
// we expand x and y
|
||||||
int oldshowing = showing;
|
int oldshowing = showing;
|
||||||
showing = height() < 180 ? 1 : (int)(height() / 180);
|
showing = height() < 180 ? 1 : (int)(height() / 180);
|
||||||
@@ -899,13 +920,18 @@ GcMultiCalendar::resizeEvent(QResizeEvent*)
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
for (int i=0; i<have; i++) {
|
for (int i=0; i<calendars.count(); i++) {
|
||||||
if (i>=oldshowing && i<showing) {
|
if (i>=oldshowing && i<showing) {
|
||||||
calendars.at(i)->setFilter(this->filters);
|
calendars.at(i)->setFilter(this->filters);
|
||||||
calendars.at(i)->setDate(first.addMonths(i).month(), first.addMonths(i).year());
|
calendars.at(i)->setDate(first.addMonths(i).month(), first.addMonths(i).year());
|
||||||
calendars.at(i)->show();
|
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
|
void
|
||||||
GcMultiCalendar::setRide(RideItem *ride)
|
GcMultiCalendar::setRide(RideItem *ride)
|
||||||
{
|
{
|
||||||
|
_ride = ride;
|
||||||
|
|
||||||
if (active) return;
|
if (active) return;
|
||||||
|
if (!isVisible()) {
|
||||||
|
stale = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setUpdatesEnabled(false);
|
setUpdatesEnabled(false);
|
||||||
active = true; // avoid multiple calls
|
active = true; // avoid multiple calls
|
||||||
@@ -967,3 +999,11 @@ GcMultiCalendar::refresh()
|
|||||||
}
|
}
|
||||||
setUpdatesEnabled(true);
|
setUpdatesEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
GcMultiCalendar::showEvent(QShowEvent*)
|
||||||
|
{
|
||||||
|
setFilter(filters);
|
||||||
|
resizeEvent(NULL);
|
||||||
|
setRide(_ride);
|
||||||
|
}
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ class GcMultiCalendar : public QScrollArea
|
|||||||
void resizeEvent(QResizeEvent*);
|
void resizeEvent(QResizeEvent*);
|
||||||
void setFilter(QStringList filter);
|
void setFilter(QStringList filter);
|
||||||
void clearFilter();
|
void clearFilter();
|
||||||
|
void showEvent(QShowEvent*);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -143,6 +144,8 @@ class GcMultiCalendar : public QScrollArea
|
|||||||
int showing;
|
int showing;
|
||||||
QStringList filters;
|
QStringList filters;
|
||||||
bool active;
|
bool active;
|
||||||
|
bool stale; // we need to redraw when shown
|
||||||
|
RideItem *_ride;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GcCalendar : public QWidget // not a GcWindow - belongs on sidebar
|
class GcCalendar : public QWidget // not a GcWindow - belongs on sidebar
|
||||||
|
|||||||
@@ -129,6 +129,7 @@ public slots:
|
|||||||
dateToRows.insert(dateTime.date(), arr);
|
dateToRows.insert(dateTime.date(), arr);
|
||||||
}
|
}
|
||||||
reset();
|
reset();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
Reference in New Issue
Block a user