• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdeedu
  • Sitemap
  • Contact Us
 

parley

lessonmodel.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002 
00003     Copyright 2008 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
00004 
00005  ***************************************************************************/
00006 
00007 /***************************************************************************
00008  *                                                                         *
00009  *   This program is free software; you can redistribute it and/or modify  *
00010  *   it under the terms of the GNU General Public License as published by  *
00011  *   the Free Software Foundation; either version 2 of the License, or     *
00012  *   (at your option) any later version.                                   *
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     // modulo - fraction lesson if not 0 we need one more
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             // next entry to be assigned to one of the new lessons
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 

parley

Skip menu "parley"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdeedu

Skip menu "kdeedu"
  • kalzium
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  •   docs
  •   src
  • parley
  •   stepcore
Generated for kdeedu by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal