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

parley

  • sources
  • kde-4.12
  • kdeedu
  • parley
  • src
  • vocabulary
lessonmodel.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 
3  Copyright 2008-2009 Frederik Gladhorn <gladhorn@kde.org>
4 
5  ***************************************************************************/
6 
7 /***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "lessonmodel.h"
17 
18 #include "parleydocument.h"
19 #include <KRandom>
20 #include <KLocalizedString>
21 #include <QFont>
22 
28 using namespace Editor;
29 
30 LessonModel::LessonModel(QObject * parent)
31  :ContainerModel(KEduVocContainer::Lesson, parent)
32 {
33 }
34 
35 KEduVocContainer * LessonModel::rootContainer() const
36 {
37  if (!m_doc) {
38  return 0;
39  }
40  return m_doc->lesson();
41 }
42 
43 Qt::ItemFlags LessonModel::flags(const QModelIndex &index) const
44 {
45  if (index.isValid() && index.parent() == QModelIndex()) {
46  return (Qt::ItemIsEnabled
47  | Qt::ItemIsEditable
48  | Qt::ItemIsSelectable);
49  }
50 
51  // the name column should be checkable to select lessons for practice
52  return ContainerModel::flags(index);
53 }
54 
55 QVariant LessonModel::data(const QModelIndex & index, int role) const
56 {
57  if (index.isValid() && !index.parent().isValid()) {
58  if (index.column() == 0) {
59  switch (role) {
60  case Qt::DisplayRole:
61  return i18nc("display of the name of the vocabulary collection", "Collection: %1", ContainerModel::data(index, role).toString());
62  case Qt::FontRole:
63  QFont f;
64  f.setBold(true);
65  return f;
66  }
67  }
68  }
69  return ContainerModel::data(index, role);
70 }
71 
72 
73 bool LessonModel::setData(const QModelIndex &index, const QVariant &value, int role)
74 {
75  if (index.isValid() && !index.parent().isValid()) {
76  if (index.column() == 0 && role == Qt::DisplayRole) {
77  m_doc->setTitle(value.toString());
78  }
79  }
80  return ContainerModel::setData(index, value, role);
81 }
82 
83 void LessonModel::splitLesson(const QModelIndex& containerIndex, int entriesPerLesson, SplitLessonOrder order)
84 {
85  if (!containerIndex.isValid()) {
86  return;
87  }
88 
89  if (!static_cast<KEduVocContainer*>(containerIndex.internalPointer())->containerType() == KEduVocContainer::Lesson) {
90  return;
91  }
92 
93  KEduVocLesson* parentLesson = static_cast<KEduVocLesson*>(containerIndex.internalPointer());
94 
95  int numNewLessons = parentLesson->entryCount() / entriesPerLesson;
96  // modulo - fraction lesson if not 0 we need one more
97  if (parentLesson->entryCount()%entriesPerLesson) {
98  numNewLessons++;
99  }
100 
101  while (parentLesson->entryCount() > 0) {
102  beginInsertRows(containerIndex, parentLesson->entryCount(), parentLesson->entryCount() );
103  KEduVocLesson* child = new KEduVocLesson(parentLesson->name()
104  + QString(" %1").arg(parentLesson->childContainerCount() + 1), parentLesson);
105  parentLesson->appendChildContainer(child);
106  endInsertRows();
107 
108  while (parentLesson->entryCount() > 0 && child->entryCount() < entriesPerLesson) {
109  // next entry to be assigned to one of the new lessons
110  int nextEntry=0;
111  if (order == Random) {
112  nextEntry = KRandom::random() % parentLesson->entryCount();
113  child->appendEntry(parentLesson->entry(nextEntry));
114  }
115  }
116  }
117 }
118 
119 
120 #include "lessonmodel.moc"
121 
122 
Editor::ContainerModel::setData
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Change the name or checkbox of a lesson.
Definition: containermodel.cpp:112
Editor::ContainerModel::data
virtual QVariant data(const QModelIndex &index, int role) const
Definition: containermodel.cpp:74
QObject
Editor::LessonModel::data
virtual QVariant data(const QModelIndex &index, int role) const
Definition: lessonmodel.cpp:55
Editor::ContainerModel::flags
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Definition: containermodel.cpp:144
parleydocument.h
Editor::BasicContainerModel::containerType
KEduVocContainer::EnumContainerType containerType()
Definition: basiccontainermodel.cpp:185
Editor::LessonModel::rootContainer
KEduVocContainer * rootContainer() const
Definition: lessonmodel.cpp:35
Editor::ContainerModel
Model for the tree of containers (lessons, word types).
Definition: containermodel.h:33
Editor::LessonModel::flags
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Definition: lessonmodel.cpp:43
Editor::LessonModel::SplitLessonOrder
SplitLessonOrder
When splitting a lesson into smaller ones - how to sort the entries into lessons. ...
Definition: lessonmodel.h:31
Editor::BasicContainerModel::m_doc
KEduVocDocument * m_doc
Definition: basiccontainermodel.h:63
lessonmodel.h
Editor::LessonModel::splitLesson
void splitLesson(const QModelIndex &containerIndex, int entriesPerLesson, SplitLessonOrder order)
Divide a lesson into smaller ones.
Definition: lessonmodel.cpp:83
Editor::LessonModel::Random
Randomized.
Definition: lessonmodel.h:33
Editor::LessonModel::LessonModel
LessonModel(QObject *parent=0)
Definition: lessonmodel.cpp:30
Editor::LessonModel::setData
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Change the name or checkbox of a lesson.
Definition: lessonmodel.cpp:73
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:42:06 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

parley

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

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal