Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
Kalendar
Commits
5cce1cf8
Commit
5cce1cf8
authored
Oct 12, 2022
by
Claudio Cambra
Browse files
Cache layout lines in hourlyincidencemodel
Signed-off-by:
Claudio Cambra
<
claudio.cambra@gmail.com
>
parent
64e9af22
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/models/hourlyincidencemodel.cpp
View file @
5cce1cf8
...
...
@@ -10,6 +10,8 @@ HourlyIncidenceModel::HourlyIncidenceModel(QObject *parent)
:
QAbstractItemModel
(
parent
)
{
mRefreshTimer
.
setSingleShot
(
true
);
mRefreshTimer
.
setInterval
(
100
);
mRefreshTimer
.
callOnTimeout
(
this
,
&
HourlyIncidenceModel
::
resetLayoutLines
);
m_config
=
KalendarConfig
::
self
();
QObject
::
connect
(
m_config
,
&
KalendarConfig
::
showSubtodosInCalendarViewsChanged
,
this
,
[
&
]()
{
...
...
@@ -311,9 +313,34 @@ QVariantList HourlyIncidenceModel::layoutLines(const QDateTime &rowStart) const
return
result
;
}
void
HourlyIncidenceModel
::
resetLayoutLines
()
{
if
(
mSourceModel
->
calendar
()
->
isLoading
())
{
if
(
!
mRefreshTimer
.
isActive
())
{
mRefreshTimer
.
start
(
100
);
}
return
;
}
beginResetModel
();
m_laidOutLines
.
clear
();
const
auto
numPeriods
=
rowCount
({});
m_laidOutLines
.
reserve
(
numPeriods
);
for
(
int
i
=
0
;
i
<
numPeriods
;
++
i
)
{
const
auto
periodStart
=
mSourceModel
->
start
().
addDays
(
i
).
startOfDay
();
const
auto
periodIncidenceLayout
=
layoutLines
(
periodStart
);
m_laidOutLines
.
append
(
periodIncidenceLayout
);
}
endResetModel
();
}
QVariant
HourlyIncidenceModel
::
data
(
const
QModelIndex
&
idx
,
int
role
)
const
{
if
(
!
hasIndex
(
idx
.
row
(),
idx
.
column
()))
{
if
(
!
hasIndex
(
idx
.
row
(),
idx
.
column
())
||
!
mSourceModel
||
m_laidOutLines
.
empty
()
)
{
return
{};
}
if
(
!
mSourceModel
)
{
...
...
@@ -324,7 +351,7 @@ QVariant HourlyIncidenceModel::data(const QModelIndex &idx, int role) const
case
PeriodStartDateTime
:
return
rowStart
;
case
Incidences
:
return
layoutLines
(
rowStart
);
return
m_laidOutLines
.
at
(
idx
.
row
()
);
default:
Q_ASSERT
(
false
);
return
{};
...
...
@@ -339,12 +366,16 @@ IncidenceOccurrenceModel *HourlyIncidenceModel::model()
void
HourlyIncidenceModel
::
setModel
(
IncidenceOccurrenceModel
*
model
)
{
beginResetModel
();
m_laidOutLines
.
clear
();
mSourceModel
=
model
;
Q_EMIT
modelChanged
();
endResetModel
();
auto
resetModel
=
[
this
]
{
if
(
!
mRefreshTimer
.
isActive
())
{
beginResetModel
();
endResetModel
();
mRefreshTimer
.
start
(
50
);
mRefreshTimer
.
start
(
100
);
}
};
QObject
::
connect
(
model
,
&
QAbstractItemModel
::
dataChanged
,
this
,
resetModel
);
...
...
@@ -353,7 +384,6 @@ void HourlyIncidenceModel::setModel(IncidenceOccurrenceModel *model)
QObject
::
connect
(
model
,
&
QAbstractItemModel
::
rowsInserted
,
this
,
resetModel
);
QObject
::
connect
(
model
,
&
QAbstractItemModel
::
rowsMoved
,
this
,
resetModel
);
QObject
::
connect
(
model
,
&
QAbstractItemModel
::
rowsRemoved
,
this
,
resetModel
);
endResetModel
();
}
int
HourlyIncidenceModel
::
periodLength
()
...
...
src/models/hourlyincidencemodel.h
View file @
5cce1cf8
...
...
@@ -67,11 +67,16 @@ Q_SIGNALS:
void
filtersChanged
();
void
modelChanged
();
private
Q_SLOTS
:
void
resetLayoutLines
();
private:
QTimer
mRefreshTimer
;
QList
<
QModelIndex
>
sortedIncidencesFromSourceModel
(
const
QDateTime
&
rowStart
)
const
;
QVariantList
layoutLines
(
const
QDateTime
&
rowStart
)
const
;
QTimer
mRefreshTimer
;
IncidenceOccurrenceModel
*
mSourceModel
{
nullptr
};
QVector
<
QVariantList
>
m_laidOutLines
;
int
mPeriodLength
{
15
};
// In minutes
HourlyIncidenceModel
::
Filters
m_filters
;
KalendarConfig
*
m_config
=
nullptr
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment