Commit 34868ee7 authored by Claudio Cambra's avatar Claudio Cambra
Browse files

Clean up hourlyincidencemodel and multidayincidencemodel, detach from config



Signed-off-by: Claudio Cambra's avatarClaudio Cambra <claudio.cambra@gmail.com>
parent a99cc340
......@@ -280,6 +280,7 @@ Column {
model: Kalendar.MultiDayIncidenceModel {
periodLength: viewColumn.daysToShow
filters: Kalendar.MultiDayIncidenceModel.AllDayOnly | Kalendar.MultiDayIncidenceModel.MultiDayOnly
showSubTodos: Kalendar.Config.showSubtodosInCalendarViews
model: Kalendar.IncidenceOccurrenceModel {
start: viewColumn.startDate
length: viewColumn.daysToShow
......@@ -622,6 +623,7 @@ Column {
model: Kalendar.HourlyIncidenceModel {
periodLength: viewColumn.periodLength
filters: Kalendar.MultiDayIncidenceModel.AllDayOnly | Kalendar.MultiDayIncidenceModel.MultiDayOnly
showSubTodos: Kalendar.Config.showSubtodosInCalendarViews
model: Kalendar.IncidenceOccurrenceModel {
start: viewColumn.startDate
length: viewColumn.daysToShow
......
......@@ -109,6 +109,7 @@ QQC2.ScrollView {
model: Kalendar.MultiDayIncidenceModel {
periodLength: 1
showSubTodos: Kalendar.Config.showSubtodosInCalendarViews
model: Kalendar.IncidenceOccurrenceModel {
start: scrollView.startDate
length: scrollView.daysInMonth
......
......@@ -242,6 +242,7 @@ Item {
Repeater {
model: Kalendar.MultiDayIncidenceModel {
periodLength: 7
showSubTodos: Kalendar.Config.showSubtodosInCalendarViews
model: Kalendar.IncidenceOccurrenceModel {
start: root.startDate
length: root.daysToShow
......
......@@ -7,17 +7,11 @@
#include <cmath>
HourlyIncidenceModel::HourlyIncidenceModel(QObject *parent)
: QAbstractItemModel(parent)
: QAbstractListModel(parent)
{
mRefreshTimer.setSingleShot(true);
mRefreshTimer.setInterval(100);
mRefreshTimer.callOnTimeout(this, &HourlyIncidenceModel::resetLayoutLines);
m_config = KalendarConfig::self();
QObject::connect(m_config, &KalendarConfig::showSubtodosInCalendarViewsChanged, this, [&]() {
beginResetModel();
endResetModel();
});
}
QModelIndex HourlyIncidenceModel::index(int row, int column, const QModelIndex &parent) const
......@@ -32,11 +26,6 @@ QModelIndex HourlyIncidenceModel::index(int row, int column, const QModelIndex &
return {};
}
QModelIndex HourlyIncidenceModel::parent(const QModelIndex &) const
{
return {};
}
int HourlyIncidenceModel::rowCount(const QModelIndex &parent) const
{
// Number of weeks
......@@ -46,11 +35,6 @@ int HourlyIncidenceModel::rowCount(const QModelIndex &parent) const
return 0;
}
int HourlyIncidenceModel::columnCount(const QModelIndex &) const
{
return 1;
}
static double getDuration(const QDateTime &start, const QDateTime &end, int periodLength)
{
return ((start.secsTo(end) * 1.0) / 60.0) / periodLength;
......@@ -84,7 +68,7 @@ QList<QModelIndex> HourlyIncidenceModel::sortedIncidencesFromSourceModel(const Q
continue;
}
if (!m_config->showSubtodosInCalendarViews()
if (!m_showSubTodos
&& !srcIdx.data(IncidenceOccurrenceModel::IncidencePtr).value<KCalendarCore::Incidence::Ptr>()->relatedTo().isEmpty()) {
continue;
}
......@@ -358,7 +342,7 @@ QVariant HourlyIncidenceModel::data(const QModelIndex &idx, int role) const
}
}
IncidenceOccurrenceModel *HourlyIncidenceModel::model()
IncidenceOccurrenceModel *HourlyIncidenceModel::model() const
{
return mSourceModel;
}
......@@ -464,7 +448,7 @@ void HourlyIncidenceModel::updateScheduledLayoutLines()
m_linesToUpdate.clear();
}
int HourlyIncidenceModel::periodLength()
int HourlyIncidenceModel::periodLength() const
{
return mPeriodLength;
}
......@@ -474,7 +458,7 @@ void HourlyIncidenceModel::setPeriodLength(int periodLength)
mPeriodLength = periodLength;
}
HourlyIncidenceModel::Filters HourlyIncidenceModel::filters()
HourlyIncidenceModel::Filters HourlyIncidenceModel::filters() const
{
return m_filters;
}
......@@ -487,6 +471,23 @@ void HourlyIncidenceModel::setFilters(HourlyIncidenceModel::Filters filters)
endResetModel();
}
bool HourlyIncidenceModel::showSubTodos() const
{
return m_showSubTodos;
}
void HourlyIncidenceModel::setShowSubTodos(const bool showSubTodos)
{
if (showSubTodos == m_showSubTodos) {
return;
}
m_showSubTodos = showSubTodos;
Q_EMIT showSubTodosChanged();
resetLayoutLines();
}
QHash<int, QByteArray> HourlyIncidenceModel::roleNames() const
{
return {
......
......@@ -9,7 +9,6 @@
#include <QList>
#include <QSharedPointer>
#include <QTimer>
#include <kalendarconfig.h>
namespace KCalendarCore
{
......@@ -21,12 +20,13 @@ class Incidence;
* The "incidences" roles provides a list of lists, where each list represents a visual line,
* containing a number of events to display.
*/
class HourlyIncidenceModel : public QAbstractItemModel
class HourlyIncidenceModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(int periodLength READ periodLength WRITE setPeriodLength NOTIFY periodLengthChanged)
Q_PROPERTY(HourlyIncidenceModel::Filters filters READ filters WRITE setFilters NOTIFY filtersChanged)
Q_PROPERTY(IncidenceOccurrenceModel *model READ model WRITE setModel NOTIFY modelChanged)
Q_PROPERTY(bool showSubTodos READ showSubTodos WRITE setShowSubTodos NOTIFY showSubTodosChanged)
public:
enum Filter {
......@@ -46,26 +46,26 @@ public:
~HourlyIncidenceModel() override = default;
QModelIndex index(int row, int column, const QModelIndex &parent = {}) const override;
QModelIndex parent(const QModelIndex &index) const override;
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
QHash<int, QByteArray> roleNames() const override;
IncidenceOccurrenceModel *model();
void setModel(IncidenceOccurrenceModel *model);
int periodLength();
void setPeriodLength(int periodLength);
HourlyIncidenceModel::Filters filters();
void setFilters(HourlyIncidenceModel::Filters filters);
IncidenceOccurrenceModel *model() const;
int periodLength() const;
HourlyIncidenceModel::Filters filters() const;
bool showSubTodos() const;
Q_SIGNALS:
void periodLengthChanged();
void filtersChanged();
void modelChanged();
void showSubTodosChanged();
public Q_SLOTS:
void setModel(IncidenceOccurrenceModel *model);
void setPeriodLength(int periodLength);
void setFilters(HourlyIncidenceModel::Filters filters);
void setShowSubTodos(const bool showSubTodos);
private Q_SLOTS:
void resetLayoutLines();
......@@ -84,7 +84,7 @@ private:
QVector<QVariantList> m_laidOutLines;
int mPeriodLength{15}; // In minutes
HourlyIncidenceModel::Filters m_filters;
KalendarConfig *m_config = nullptr;
bool m_showSubTodos = true;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(HourlyIncidenceModel::Filters)
......@@ -119,6 +119,7 @@ void IncidenceOccurrenceModel::scheduleReset()
void IncidenceOccurrenceModel::resetFromSource()
{
if (!m_coreCalendar) {
qCWarning(KALENDAR_LOG) << "Not resetting IOC from source as no core calendar set.";
return;
}
......
......@@ -19,9 +19,6 @@ MultiDayIncidenceModel::MultiDayIncidenceModel(QObject *parent)
m_updateLinesTimer.setSingleShot(true);
m_updateLinesTimer.setInterval(100);
m_updateLinesTimer.callOnTimeout(this, &MultiDayIncidenceModel::updateScheduledLayoutLines);
m_config = KalendarConfig::self();
connect(m_config, &KalendarConfig::showSubtodosInCalendarViewsChanged, this, &MultiDayIncidenceModel::resetLayoutLines);
}
int MultiDayIncidenceModel::rowCount(const QModelIndex &parent) const
......@@ -265,7 +262,7 @@ QVariant MultiDayIncidenceModel::data(const QModelIndex &idx, int role) const
}
}
IncidenceOccurrenceModel *MultiDayIncidenceModel::model()
IncidenceOccurrenceModel *MultiDayIncidenceModel::model() const
{
return mSourceModel;
}
......@@ -285,12 +282,12 @@ void MultiDayIncidenceModel::setModel(IncidenceOccurrenceModel *model)
mRefreshTimer.start(100);
}
};
QObject::connect(model, &QAbstractItemModel::dataChanged, this, &MultiDayIncidenceModel::slotSourceDataChanged);
QObject::connect(model, &QAbstractItemModel::layoutChanged, this, resetModel);
QObject::connect(model, &QAbstractItemModel::modelReset, this, resetModel);
QObject::connect(model, &QAbstractItemModel::rowsInserted, this, &MultiDayIncidenceModel::scheduleLayoutLinesUpdates);
QObject::connect(model, &QAbstractItemModel::rowsMoved, this, resetModel);
QObject::connect(model, &QAbstractItemModel::rowsRemoved, this, &MultiDayIncidenceModel::scheduleLayoutLinesUpdates);
connect(model, &QAbstractItemModel::dataChanged, this, &MultiDayIncidenceModel::slotSourceDataChanged);
connect(model, &QAbstractItemModel::layoutChanged, this, resetModel);
connect(model, &QAbstractItemModel::modelReset, this, resetModel);
connect(model, &QAbstractItemModel::rowsInserted, this, &MultiDayIncidenceModel::scheduleLayoutLinesUpdates);
connect(model, &QAbstractItemModel::rowsMoved, this, resetModel);
connect(model, &QAbstractItemModel::rowsRemoved, this, &MultiDayIncidenceModel::scheduleLayoutLinesUpdates);
mRefreshTimer.start(100);
}
......@@ -383,7 +380,7 @@ void MultiDayIncidenceModel::setPeriodLength(int periodLength)
mPeriodLength = periodLength;
}
MultiDayIncidenceModel::Filters MultiDayIncidenceModel::filters()
MultiDayIncidenceModel::Filters MultiDayIncidenceModel::filters() const
{
return m_filters;
}
......@@ -396,9 +393,26 @@ void MultiDayIncidenceModel::setFilters(MultiDayIncidenceModel::Filters filters)
endResetModel();
}
bool MultiDayIncidenceModel::showSubTodos() const
{
return m_showSubTodos;
}
void MultiDayIncidenceModel::setShowSubTodos(const bool showSubTodos)
{
if (showSubTodos == m_showSubTodos) {
return;
}
m_showSubTodos = showSubTodos;
Q_EMIT showSubTodosChanged();
resetLayoutLines();
}
bool MultiDayIncidenceModel::incidencePassesFilter(const QModelIndex &idx) const
{
if (!m_filters && m_config->showSubtodosInCalendarViews()) {
if (!m_filters && m_showSubTodos) {
return true;
}
bool include = false;
......@@ -418,7 +432,7 @@ bool MultiDayIncidenceModel::incidencePassesFilter(const QModelIndex &idx) const
}
}
if (!m_config->showSubtodosInCalendarViews()
if (!m_showSubTodos
&& idx.data(IncidenceOccurrenceModel::IncidencePtr).value<KCalendarCore::Incidence::Ptr>()->relatedTo().isEmpty()) {
include = true;
}
......@@ -426,7 +440,7 @@ bool MultiDayIncidenceModel::incidencePassesFilter(const QModelIndex &idx) const
return include;
}
int MultiDayIncidenceModel::incidenceCount()
int MultiDayIncidenceModel::incidenceCount() const
{
int count = 0;
......
......@@ -12,7 +12,6 @@
#include <QList>
#include <QSharedPointer>
#include <QTimer>
#include <kalendarconfig.h>
namespace KCalendarCore
{
......@@ -31,6 +30,7 @@ class MultiDayIncidenceModel : public QAbstractListModel
Q_PROPERTY(MultiDayIncidenceModel::Filters filters READ filters WRITE setFilters NOTIFY filtersChanged)
Q_PROPERTY(int incidenceCount READ incidenceCount NOTIFY incidenceCountChanged)
Q_PROPERTY(IncidenceOccurrenceModel *model READ model WRITE setModel NOTIFY modelChanged)
Q_PROPERTY(bool showSubTodos READ showSubTodos WRITE setShowSubTodos NOTIFY showSubTodosChanged)
public:
enum Filter {
......@@ -54,20 +54,24 @@ public:
QVariant data(const QModelIndex &index, int role) const override;
QHash<int, QByteArray> roleNames() const override;
IncidenceOccurrenceModel *model();
void setModel(IncidenceOccurrenceModel *model);
IncidenceOccurrenceModel *model() const;
int periodLength() const;
void setPeriodLength(int periodLength);
MultiDayIncidenceModel::Filters filters();
void setFilters(MultiDayIncidenceModel::Filters filters);
bool incidencePassesFilter(const QModelIndex &idx) const;
Q_INVOKABLE int incidenceCount();
MultiDayIncidenceModel::Filters filters() const;
bool showSubTodos() const;
int incidenceCount() const;
Q_SIGNALS:
void periodLengthChanged();
void filtersChanged();
void incidenceCountChanged();
void modelChanged();
void showSubTodosChanged();
public Q_SLOTS:
void setModel(IncidenceOccurrenceModel *model);
void setPeriodLength(int periodLength);
void setFilters(MultiDayIncidenceModel::Filters filters);
void setShowSubTodos(const bool showSubTodos);
protected:
void setIncidenceCount(int incidenceCount);
......@@ -77,6 +81,7 @@ private Q_SLOTS:
void slotSourceDataChanged(const QModelIndex &upperLeft, const QModelIndex &bottomRight);
void scheduleLayoutLinesUpdates(const QModelIndex &sourceIndexParent, const int sourceFirstRow, const int sourceLastRow);
void updateScheduledLayoutLines();
bool incidencePassesFilter(const QModelIndex &idx) const;
private:
QList<QModelIndex> sortedIncidencesFromSourceModel(const QDate &rowStart) const;
......@@ -89,7 +94,7 @@ private:
QVector<QVariantList> m_laidOutLines;
int mPeriodLength = 7;
MultiDayIncidenceModel::Filters m_filters;
KalendarConfig *m_config = nullptr;
bool m_showSubTodos = true;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(MultiDayIncidenceModel::Filters)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment