Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[libcommhistory] Remove artificial one week limit for date sections. …
…Contributes to JB#17582
  • Loading branch information
Joona Petrell committed May 5, 2020
1 parent 0f8702a commit c6a33b9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 26 deletions.
15 changes: 3 additions & 12 deletions src/contactgroupmodel.cpp
Expand Up @@ -323,7 +323,7 @@ QHash<int,QByteArray> ContactGroupModel::roleNames() const
{
QHash<int,QByteArray> roles;
roles[ContactGroupRole] = "contactGroup";
roles[WeekdaySectionRole] = "weekdaySection";
roles[TimeSectionRole] = "timeSection";
roles[BaseRole + ContactIds] = "contactIds";
roles[BaseRole + ContactNames] = "contactNames"; // TODO: Obsolete, remove
roles[BaseRole + EndTime] = "endTime";
Expand Down Expand Up @@ -393,17 +393,8 @@ QVariant ContactGroupModel::data(const QModelIndex &index, int role) const

if (role == ContactGroupRole) {
return QVariant::fromValue<QObject*>(g);
} else if (role == WeekdaySectionRole) {
QDateTime dateTime = g->endTime().toLocalTime();

// Return the date for the past week, and group all older items together under an
// arbitrary older date
const int daysDiff = QDate::currentDate().toJulianDay() - dateTime.date().toJulianDay();
if (daysDiff < 7)
return dateTime.date();

// Arbitrary static date for older items..
return QDate(2000, 1, 1);
} else if (role == TimeSectionRole) {
return g->endTime().toLocalTime().date();
}

if (role != Qt::DisplayRole)
Expand Down
2 changes: 1 addition & 1 deletion src/contactgroupmodel.h
Expand Up @@ -76,7 +76,7 @@ class LIBCOMMHISTORY_EXPORT ContactGroupModel : public QAbstractTableModel

enum {
ContactGroupRole = Qt::UserRole,
WeekdaySectionRole,
TimeSectionRole,
BaseRole = Qt::UserRole + 2000
};

Expand Down
15 changes: 3 additions & 12 deletions src/groupmodel.cpp
Expand Up @@ -193,7 +193,7 @@ QHash<int, QByteArray> GroupModel::roleNames() const
roles[BaseRole + StartTime] = "startTime";
roles[ContactIdsRole] = "contactIds";
roles[GroupObjectRole] = "group";
roles[WeekdaySectionRole] = "weekdaySection";
roles[TimeSectionRole] = "timeSection";
return roles;
}

Expand Down Expand Up @@ -276,17 +276,8 @@ QVariant GroupModel::data(const QModelIndex &index, int role) const
return QVariant::fromValue<QObject*>(group);
} else if (role == ContactIdsRole) {
return QVariant::fromValue<QList<int> >(group->recipients().contactIds());
} else if (role == WeekdaySectionRole) {
QDateTime dateTime = group->endTime().toLocalTime();

// Return the date for the past week, and group all older items together under an
// arbitrary older date
const int daysDiff = QDate::currentDate().toJulianDay() - dateTime.date().toJulianDay();
if (daysDiff < 7)
return dateTime.date();

// Arbitrary static date for older items..
return QDate(2000, 1, 1);
} else if (role == TimeSectionRole) {
return group->endTime().toLocalTime().date();
}

int column = index.column();
Expand Down
2 changes: 1 addition & 1 deletion src/groupmodel.h
Expand Up @@ -78,7 +78,7 @@ class LIBCOMMHISTORY_EXPORT GroupModel: public QAbstractTableModel
GroupRole = Qt::UserRole,
ContactIdsRole,
GroupObjectRole,
WeekdaySectionRole,
TimeSectionRole,
BaseRole = Qt::UserRole + 1000
};

Expand Down

0 comments on commit c6a33b9

Please sign in to comment.