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
06b0125e
Commit
06b0125e
authored
Oct 12, 2022
by
Claudio Cambra
Browse files
Port multidayincidencemodel optimisations to hourlyviewincidencemodel
Signed-off-by:
Claudio Cambra
<
claudio.cambra@gmail.com
>
parent
5cce1cf8
Pipeline
#248292
failed with stage
in 1 minute and 59 seconds
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
src/models/hourlyincidencemodel.cpp
View file @
06b0125e
...
...
@@ -386,6 +386,84 @@ void HourlyIncidenceModel::setModel(IncidenceOccurrenceModel *model)
QObject
::
connect
(
model
,
&
QAbstractItemModel
::
rowsRemoved
,
this
,
resetModel
);
}
void
HourlyIncidenceModel
::
slotSourceDataChanged
(
const
QModelIndex
&
upperLeft
,
const
QModelIndex
&
bottomRight
)
{
if
(
!
upperLeft
.
isValid
()
||
!
bottomRight
.
isValid
())
{
return
;
}
const
auto
startRow
=
upperLeft
.
row
();
const
auto
endRow
=
bottomRight
.
row
();
scheduleLayoutLinesUpdates
(
upperLeft
.
parent
(),
startRow
,
endRow
);
}
void
HourlyIncidenceModel
::
scheduleLayoutLinesUpdates
(
const
QModelIndex
&
sourceIndexParent
,
const
int
sourceFirstRow
,
const
int
sourceLastRow
)
{
if
(
!
mSourceModel
)
{
return
;
}
// If we have no existing laid out lines it means we have not done an
// initial setup. Go do that, which will provide incidences anyway
if
(
m_laidOutLines
.
empty
())
{
resetLayoutLines
();
return
;
}
// Don't bother if we are going for a full reset soon
if
(
mRefreshTimer
.
isActive
())
{
return
;
}
for
(
int
i
=
sourceFirstRow
;
i
<=
sourceLastRow
;
++
i
)
{
if
(
m_linesToUpdate
.
count
()
==
m_laidOutLines
.
count
())
{
break
;
}
const
auto
sourceModelIndex
=
mSourceModel
->
index
(
i
,
0
,
sourceIndexParent
);
const
auto
occurrence
=
sourceModelIndex
.
data
(
IncidenceOccurrenceModel
::
IncidenceOccurrence
).
value
<
IncidenceOccurrenceModel
::
Occurrence
>
();
const
auto
sourceModelStartDate
=
mSourceModel
->
start
();
const
auto
startDaysFromSourceStart
=
sourceModelStartDate
.
daysTo
(
occurrence
.
start
.
date
());
const
auto
endDaysFromSourceStart
=
sourceModelStartDate
.
daysTo
(
occurrence
.
end
.
date
());
const
auto
firstPeriodOccurrenceAppears
=
startDaysFromSourceStart
/
mPeriodLength
;
const
auto
lastPeriodOccurrenceAppears
=
endDaysFromSourceStart
/
mPeriodLength
;
if
(
firstPeriodOccurrenceAppears
>
m_laidOutLines
.
count
()
||
lastPeriodOccurrenceAppears
<
0
)
{
continue
;
}
const
auto
lastRow
=
m_laidOutLines
.
count
()
-
1
;
const
auto
minRow
=
qMin
(
qMax
(
static_cast
<
int
>
(
firstPeriodOccurrenceAppears
),
0
),
lastRow
);
const
auto
maxRow
=
qMin
(
static_cast
<
int
>
(
lastPeriodOccurrenceAppears
),
lastRow
);
// We set the layout lines scheduled to redo
m_linesToUpdate
.
insert
(
minRow
);
m_linesToUpdate
.
insert
(
maxRow
);
}
// Throttle how often we are changing the lines or the views will be slow
if
(
!
m_updateLinesTimer
.
isActive
())
{
m_updateLinesTimer
.
start
(
100
);
}
}
void
HourlyIncidenceModel
::
updateScheduledLayoutLines
()
{
for
(
const
auto
lineIndex
:
m_linesToUpdate
)
{
const
auto
periodStart
=
mSourceModel
->
start
().
addDays
(
lineIndex
).
startOfDay
();
const
auto
idx
=
index
(
lineIndex
,
0
);
const
auto
laidOutLine
=
layoutLines
(
periodStart
);
m_laidOutLines
.
replace
(
lineIndex
,
laidOutLine
);
Q_EMIT
dataChanged
(
idx
,
idx
);
}
m_linesToUpdate
.
clear
();
}
int
HourlyIncidenceModel
::
periodLength
()
{
return
mPeriodLength
;
...
...
src/models/hourlyincidencemodel.h
View file @
06b0125e
...
...
@@ -69,12 +69,17 @@ Q_SIGNALS:
private
Q_SLOTS
:
void
resetLayoutLines
();
void
slotSourceDataChanged
(
const
QModelIndex
&
upperLeft
,
const
QModelIndex
&
bottomRight
);
void
scheduleLayoutLinesUpdates
(
const
QModelIndex
&
sourceIndexParent
,
const
int
sourceFirstRow
,
const
int
sourceLastRow
);
void
updateScheduledLayoutLines
();
private:
QList
<
QModelIndex
>
sortedIncidencesFromSourceModel
(
const
QDateTime
&
rowStart
)
const
;
QVariantList
layoutLines
(
const
QDateTime
&
rowStart
)
const
;
QSet
<
int
>
m_linesToUpdate
;
QTimer
mRefreshTimer
;
QTimer
m_updateLinesTimer
;
IncidenceOccurrenceModel
*
mSourceModel
{
nullptr
};
QVector
<
QVariantList
>
m_laidOutLines
;
int
mPeriodLength
{
15
};
// In minutes
...
...
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