• 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
basiccontainermodel.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 
3  Copyright 2007-2008 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
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 "containermodel.h"
17 
18 #include <KLocalizedString>
19 #include <KDebug>
20 
21 #include "containermimedata.h"
22 #include "vocabularymimedata.h"
23 
24 #include <keduvocdocument.h>
25 #include <keduvoclesson.h>
26 #include <keduvocwordtype.h>
27 #include <keduvocexpression.h>
28 
29 
35 using namespace Editor;
36 
37 BasicContainerModel::BasicContainerModel(KEduVocContainer::EnumContainerType type, QObject * parent)
38  : QAbstractItemModel(parent)
39  , m_type(type)
40  , m_doc(0)
41 {
42 }
43 
44 void BasicContainerModel::setDocument(KEduVocDocument * doc)
45 {
46  m_doc = doc;
47  if (m_doc) {
48  kDebug() << "Set Document: " << m_doc->url();
49  } else {
50  kDebug() << "Set Invalid Document";
51  }
52  reset();
53 }
54 
55 QModelIndex BasicContainerModel::index(int row, int column, const QModelIndex &parent) const
56 {
57  if (!m_doc || !hasIndex(row, column, parent)) {
58  return QModelIndex();
59  }
60 
61  KEduVocContainer *parentContainer;
62 
63  if (!parent.isValid()) {
64  parentContainer = 0;
65  } else {
66  parentContainer = static_cast<KEduVocContainer*>(parent.internalPointer());
67  }
68 
69  KEduVocContainer *childContainer = 0;
70  if (!parentContainer) {
71  childContainer = rootContainer();
72  if (!childContainer) {
73  return QModelIndex();
74  }
75  } else {
76  childContainer = parentContainer->childContainer(row);
77  }
78  return createIndex(row, column, childContainer);
79 }
80 
81 QModelIndex BasicContainerModel::index(KEduVocContainer * container) const
82 {
83  if(!container) {
84  return QModelIndex();
85  }
86 
87  QModelIndex currentIndex = index(container->row(), 0, index(container->parent()));
88  Q_ASSERT(container == currentIndex.internalPointer());
89 
90  return currentIndex;
91 }
92 
93 QModelIndex BasicContainerModel::parent(const QModelIndex &index) const
94 {
95  if (!index.isValid()) {
96  return QModelIndex();
97  }
98 
99  KEduVocContainer *childItem = static_cast<KEduVocContainer*>(index.internalPointer());
100  if (!childItem) {
101  return QModelIndex();
102  }
103 
104  KEduVocContainer *parentItem = childItem->parent();
105 
106  if (!parentItem) {
107  return QModelIndex();
108  }
109 
110  QModelIndex parentIndex = createIndex(parentItem->row(), 0, parentItem);
111  return parentIndex;
112 }
113 
114 int BasicContainerModel::rowCount(const QModelIndex &parent) const
115 {
116  if (parent.column() > 0) {
117  return 0;
118  }
119 
120  KEduVocContainer *parentItem;
121  if (!parent.isValid()) {
122  // root element
123  if (!m_doc) {
124  return 0;
125  }
126  return 1;
127  } else {
128  parentItem = static_cast<KEduVocContainer*>(parent.internalPointer());
129  return parentItem->childContainerCount();
130  }
131 }
132 
133 QVariant BasicContainerModel::data(const QModelIndex & index, int role) const
134 {
135  if (!index.isValid()) {
136  return QVariant();
137  }
138 
139  KEduVocContainer *container = static_cast<KEduVocContainer*>(index.internalPointer());
140 
141  switch (index.column()){
142  case 0: // Container name
143  if (role == Qt::DisplayRole || role == Qt::EditRole) {
144  if (index.parent() == QModelIndex()) {
145  return i18n("None");
146  }
147  return container->name();
148  }
149  if (role == Qt::TextAlignmentRole) {
150  return Qt::AlignLeft;
151  }
152  break;
153  }
154 
155  return QVariant();
156 }
157 
158 Qt::ItemFlags BasicContainerModel::flags(const QModelIndex &index) const
159 {
160  if (index.isValid()) {
161  // the root element, not editable for now
162  if (index.parent() == QModelIndex()) {
163  return (Qt::ItemIsEnabled | Qt::ItemIsSelectable);
164  }
165  // the name column
166  if ( index.column() == 0 ) {
167  return (Qt::ItemIsEnabled | Qt::ItemIsSelectable);
168  } else { // every other element
169  return (Qt::ItemIsEnabled | Qt::ItemIsSelectable);
170  }
171  }
172  return 0;
173 }
174 
175 int BasicContainerModel::columnCount(const QModelIndex & parent) const
176 {
177  Q_UNUSED(parent);
178  if (!m_doc) {
179  return 1;
180  }
181 
182  return 1;
183 }
184 
185 KEduVocContainer::EnumContainerType BasicContainerModel::containerType()
186 {
187  return m_type;
188 }
189 
190 
191 #include "basiccontainermodel.moc"
Editor::BasicContainerModel::data
virtual QVariant data(const QModelIndex &index, int role) const
Definition: basiccontainermodel.cpp:133
Editor::BasicContainerModel::rootContainer
virtual KEduVocContainer * rootContainer() const =0
QObject
Editor::BasicContainerModel::m_type
KEduVocContainer::EnumContainerType m_type
Definition: basiccontainermodel.h:62
Editor::BasicContainerModel::BasicContainerModel
BasicContainerModel(KEduVocContainer::EnumContainerType type, QObject *parent=0)
Definition: basiccontainermodel.cpp:37
vocabularymimedata.h
Editor::BasicContainerModel::parent
virtual QModelIndex parent(const QModelIndex &index) const
Definition: basiccontainermodel.cpp:93
Editor::BasicContainerModel::containerType
KEduVocContainer::EnumContainerType containerType()
Definition: basiccontainermodel.cpp:185
containermodel.h
containermimedata.h
Editor::BasicContainerModel::columnCount
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition: basiccontainermodel.cpp:175
Editor::BasicContainerModel::m_doc
KEduVocDocument * m_doc
Definition: basiccontainermodel.h:63
QAbstractItemModel
Editor::BasicContainerModel::rowCount
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: basiccontainermodel.cpp:114
Editor::BasicContainerModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: basiccontainermodel.cpp:55
Editor::BasicContainerModel::flags
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Definition: basiccontainermodel.cpp:158
Editor::BasicContainerModel::setDocument
void setDocument(KEduVocDocument *doc)
Set the new source kvtml file.
Definition: basiccontainermodel.cpp:44
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:42:05 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