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

parley

  • sources
  • kde-4.14
  • kdeedu
  • parley
  • src
  • collection
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 
29 LessonModel::LessonModel(QObject * parent)
30  : ContainerModel(KEduVocContainer::Lesson, parent)
31 {
32 }
33 
34 KEduVocContainer * LessonModel::rootContainer() const
35 {
36  if (!m_doc) {
37  return 0;
38  }
39  return m_doc->lesson();
40 }
41 
42 Qt::ItemFlags LessonModel::flags(const QModelIndex &index) const
43 {
44  if (index.isValid() && index.parent() == QModelIndex()) {
45  return (Qt::ItemIsEnabled
46  | Qt::ItemIsEditable
47  | Qt::ItemIsSelectable);
48  }
49 
50  // the name column should be checkable to select lessons for practice
51  return ContainerModel::flags(index);
52 }
53 
54 QVariant LessonModel::data(const QModelIndex & index, int role) const
55 {
56  if (index.isValid() && !index.parent().isValid()) {
57  if (index.column() == 0) {
58  switch (role) {
59  case Qt::DisplayRole:
60  return i18nc("display of the name of the vocabulary collection", "Collection: %1", ContainerModel::data(index, role).toString());
61  case Qt::FontRole:
62  QFont f;
63  f.setBold(true);
64  return f;
65  }
66  }
67  }
68  return ContainerModel::data(index, role);
69 }
70 
71 
72 bool LessonModel::setData(const QModelIndex &index, const QVariant &value, int role)
73 {
74  if (index.isValid() && !index.parent().isValid()) {
75  if (index.column() == ContainerNameColumn && role == Qt::EditRole) {
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"
QObject::child
QObject * child(const char *objName, const char *inheritsClass, bool recursiveSearch) const
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:72
QModelIndex
QFont
LessonModel::SplitLessonOrder
SplitLessonOrder
When splitting a lesson into smaller ones - how to sort the entries into lessons. ...
Definition: lessonmodel.h:30
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
LessonModel::rootContainer
KEduVocContainer * rootContainer() const
Definition: lessonmodel.cpp:34
QFont::setBold
void setBold(bool enable)
parleydocument.h
QModelIndex::isValid
bool isValid() const
QAbstractItemModel::endInsertRows
void endInsertRows()
ContainerModel
Model for the tree of containers (lessons, word types).
Definition: containermodel.h:33
QObject
LessonModel::flags
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Definition: lessonmodel.cpp:42
ReadonlyContainerModel::m_doc
KEduVocDocument * m_doc
Definition: readonlycontainermodel.h:62
LessonModel::splitLesson
void splitLesson(const QModelIndex &containerIndex, int entriesPerLesson, SplitLessonOrder order)
Divide a lesson into smaller ones.
Definition: lessonmodel.cpp:83
QModelIndex::internalPointer
void * internalPointer() const
QString
ContainerModel::data
virtual QVariant data(const QModelIndex &index, int role) const
Definition: containermodel.cpp:74
QModelIndex::parent
QModelIndex parent() const
LessonModel::Random
Randomized.
Definition: lessonmodel.h:32
lessonmodel.h
QAbstractItemModel::beginInsertRows
void beginInsertRows(const QModelIndex &parent, int first, int last)
QModelIndex::column
int column() const
LessonModel::data
virtual QVariant data(const QModelIndex &index, int role) const
Definition: lessonmodel.cpp:54
LessonModel::LessonModel
LessonModel(QObject *parent=0)
Definition: lessonmodel.cpp:29
ContainerModel::flags
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Definition: containermodel.cpp:144
ContainerModel::ContainerNameColumn
Definition: containermodel.h:39
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QVariant::toString
QString toString() const
ReadonlyContainerModel::containerType
KEduVocContainer::EnumContainerType containerType()
Definition: readonlycontainermodel.cpp:179
QVariant
Qt::ItemFlags
typedef ItemFlags
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:15:56 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
  • 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