parley
lessonmodel.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "lessonmodel.h"
00017
00018 #include <KRandom>
00019
00025 LessonModel::LessonModel(QObject * parent)
00026 :ContainerModel(KEduVocContainer::Lesson, parent)
00027 {
00028 }
00029
00030 KEduVocContainer * LessonModel::rootContainer() const
00031 {
00032 if (!m_doc) {
00033 return 0;
00034 }
00035 return m_doc->lesson();
00036 }
00037
00038 void LessonModel::splitLesson(const QModelIndex& containerIndex, int entriesPerLesson, SplitLessonOrder order)
00039 {
00040 if (!containerIndex.isValid()) {
00041 return;
00042 }
00043
00044 if (!static_cast<KEduVocContainer*>(containerIndex.internalPointer())->containerType() == KEduVocContainer::Lesson) {
00045 return;
00046 }
00047
00048 KEduVocLesson* parentLesson = static_cast<KEduVocLesson*>(containerIndex.internalPointer());
00049
00050 int numNewLessons = parentLesson->entryCount() / entriesPerLesson;
00051
00052 if (parentLesson->entryCount()%entriesPerLesson) {
00053 numNewLessons++;
00054 }
00055
00056 while (parentLesson->entryCount() > 0) {
00057 beginInsertRows(containerIndex, parentLesson->entryCount(), parentLesson->entryCount() );
00058 KEduVocLesson* child = new KEduVocLesson(parentLesson->name()
00059 + QString(" %1").arg(parentLesson->childContainerCount() + 1), parentLesson);
00060 parentLesson->appendChildContainer(child);
00061 endInsertRows();
00062
00063 while (parentLesson->entryCount() > 0 && child->entryCount() < entriesPerLesson) {
00064
00065 int nextEntry=0;
00066 if (order == Random) {
00067 nextEntry = KRandom::random() % parentLesson->entryCount();
00068 child->appendEntry(parentLesson->entry(nextEntry));
00069 }
00070 }
00071 }
00072 }
00073
00074
00075 #include "lessonmodel.moc"
00076
00077