FYI: New calendar project (uses C++14 and C++17).

Mark Gaiser markg85 at gmail.com
Wed Dec 28 20:14:38 UTC 2016


Hi,

I saw some commits from Kai to enhance the calendar code (both C++ and
QML), apparently for performance reasons. It's great to see people
interested in performance optimizations ;)

Some weeks ago i was watching cppcon videos. One video [1] got me
interested in playing with constructing a calendar in code and trying to
use as little code as possible. Just as an exercise to play with C++14 and
C++17 features. I was considering the ranges library, but that seemed
overkill to me so i kept myself to C++ 14, 17 and some custom iterators
from cppitertools [2].

Now i have a small* application [3] that calculates which days are in a
given month along with an offset at the beginning of the month (empty
cells). There are no empty cells to fill to 42 days (a common number of
days to display in a calendar).

The code itself (as it is now) is useless for you folks. It just prints a
whole year in months on the console and that's about it. But it is highly
performant! You can make it very useful by building a new
(QAbstractItemModel derived) model around it. That would basically be a
replacement for DaysModel and a cleanup for the Calendar class (updateData
specifically).

Looking back at the DaysModel that is still being used in the current
calendar. hehe, ohh boy.. I would certainly handle things differently if i
were to make it again. For instance, the concept of DaysModel seemed sound
when i made it, now it seems flawed. Why would anyone make a DaysModel with
"DayData" objects and in there have the day, month and year stored as ints.
Yeah... Go figure why i did that, i even don't know it anymore. If i were
to do that again i would make a "MonthModel" with a fixed rowcount of 42
and deduce every day in there by the column value in the QModelIndex. The
model itself only needs to know the month and year upon model construction
(and when changing months), it doesn't even need to remember
it. Calendar::updateData would be heavily simplified as well ;)

Have a look at [3] and feel free to use it however you like it.
You can make it work under C++14 if you replace the structured binding
usage.

Cheers,
Mark

[1] https://www.youtube.com/watch?v=mFUXNMfaciE
[2] https://github.com/ryanhaining/cppitertools
[3] https://github.com/markg85/cansole_calendar
* = small if you don't count the added files from cppitertools.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/plasma-devel/attachments/20161228/54b7f08e/attachment.html>


More information about the Plasma-devel mailing list