• 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
readonlycontainermodel.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 "readonlycontainermodel.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 
36 ReadonlyContainerModel::ReadonlyContainerModel(KEduVocContainer::EnumContainerType type, QObject * parent)
37  : QAbstractItemModel(parent)
38  , m_type(type)
39  , m_doc(0)
40 {
41 }
42 
43 void ReadonlyContainerModel::setDocument(KEduVocDocument * doc)
44 {
45  m_doc = doc;
46  reset();
47 }
48 
49 QModelIndex ReadonlyContainerModel::index(int row, int column, const QModelIndex &parent) const
50 {
51  if (!m_doc || !hasIndex(row, column, parent)) {
52  return QModelIndex();
53  }
54 
55  KEduVocContainer *parentContainer;
56 
57  if (!parent.isValid()) {
58  parentContainer = 0;
59  } else {
60  parentContainer = static_cast<KEduVocContainer*>(parent.internalPointer());
61  }
62 
63  KEduVocContainer *childContainer = 0;
64  if (!parentContainer) {
65  childContainer = rootContainer();
66  if (!childContainer) {
67  return QModelIndex();
68  }
69  } else {
70  childContainer = parentContainer->childContainer(row);
71  }
72  return createIndex(row, column, childContainer);
73 }
74 
75 QModelIndex ReadonlyContainerModel::index(KEduVocContainer * container) const
76 {
77  if (!container) {
78  return QModelIndex();
79  }
80 
81  QModelIndex currentIndex = index(container->row(), 0, index(container->parent()));
82  Q_ASSERT(container == currentIndex.internalPointer());
83 
84  return currentIndex;
85 }
86 
87 QModelIndex ReadonlyContainerModel::parent(const QModelIndex &index) const
88 {
89  if (!index.isValid()) {
90  return QModelIndex();
91  }
92 
93  KEduVocContainer *childItem = static_cast<KEduVocContainer*>(index.internalPointer());
94  if (!childItem) {
95  return QModelIndex();
96  }
97 
98  KEduVocContainer *parentItem = childItem->parent();
99 
100  if (!parentItem) {
101  return QModelIndex();
102  }
103 
104  QModelIndex parentIndex = createIndex(parentItem->row(), 0, parentItem);
105  return parentIndex;
106 }
107 
108 int ReadonlyContainerModel::rowCount(const QModelIndex &parent) const
109 {
110  if (parent.column() > 0) {
111  return 0;
112  }
113 
114  KEduVocContainer *parentItem;
115  if (!parent.isValid()) {
116  // root element
117  if (!m_doc) {
118  return 0;
119  }
120  return 1;
121  } else {
122  parentItem = static_cast<KEduVocContainer*>(parent.internalPointer());
123  return parentItem->childContainerCount();
124  }
125 }
126 
127 QVariant ReadonlyContainerModel::data(const QModelIndex & index, int role) const
128 {
129  if (!index.isValid()) {
130  return QVariant();
131  }
132 
133  KEduVocContainer *container = static_cast<KEduVocContainer*>(index.internalPointer());
134 
135  switch (index.column()) {
136  case 0: // Container name
137  if (role == Qt::DisplayRole || role == Qt::EditRole) {
138  if (index.parent() == QModelIndex()) {
139  return i18n("None");
140  }
141  return container->name();
142  }
143  if (role == Qt::TextAlignmentRole) {
144  return Qt::AlignLeft;
145  }
146  break;
147  }
148 
149  return QVariant();
150 }
151 
152 Qt::ItemFlags ReadonlyContainerModel::flags(const QModelIndex &index) const
153 {
154  if (index.isValid()) {
155  // the root element, not editable for now
156  if (index.parent() == QModelIndex()) {
157  return (Qt::ItemIsEnabled | Qt::ItemIsSelectable);
158  }
159  // the name column
160  if (index.column() == 0) {
161  return (Qt::ItemIsEnabled | Qt::ItemIsSelectable);
162  } else { // every other element
163  return (Qt::ItemIsEnabled | Qt::ItemIsSelectable);
164  }
165  }
166  return 0;
167 }
168 
169 int ReadonlyContainerModel::columnCount(const QModelIndex & parent) const
170 {
171  Q_UNUSED(parent);
172  if (!m_doc) {
173  return 1;
174  }
175 
176  return 1;
177 }
178 
179 KEduVocContainer::EnumContainerType ReadonlyContainerModel::containerType()
180 {
181  return m_type;
182 }
183 
184 
185 #include "readonlycontainermodel.moc"
QAbstractItemModel::hasIndex
bool hasIndex(int row, int column, const QModelIndex &parent) const
QModelIndex
ReadonlyContainerModel::rowCount
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: readonlycontainermodel.cpp:108
ReadonlyContainerModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: readonlycontainermodel.cpp:49
ReadonlyContainerModel::data
virtual QVariant data(const QModelIndex &index, int role) const
Definition: readonlycontainermodel.cpp:127
vocabularymimedata.h
QAbstractItemModel::reset
void reset()
QModelIndex::isValid
bool isValid() const
QObject
ReadonlyContainerModel::m_doc
KEduVocDocument * m_doc
Definition: readonlycontainermodel.h:62
containermimedata.h
QModelIndex::internalPointer
void * internalPointer() const
ReadonlyContainerModel::flags
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Definition: readonlycontainermodel.cpp:152
QModelIndex::parent
QModelIndex parent() const
readonlycontainermodel.h
QAbstractItemModel::createIndex
QModelIndex createIndex(int row, int column, void *ptr) const
ReadonlyContainerModel::columnCount
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition: readonlycontainermodel.cpp:169
ReadonlyContainerModel::setDocument
void setDocument(KEduVocDocument *doc)
Set the new source kvtml file.
Definition: readonlycontainermodel.cpp:43
QModelIndex::column
int column() const
QAbstractItemModel
ReadonlyContainerModel::rootContainer
virtual KEduVocContainer * rootContainer() const =0
QObject::parent
QObject * parent() const
ReadonlyContainerModel::m_type
KEduVocContainer::EnumContainerType m_type
Definition: readonlycontainermodel.h:61
ReadonlyContainerModel::ReadonlyContainerModel
ReadonlyContainerModel(KEduVocContainer::EnumContainerType type, QObject *parent=0)
Definition: readonlycontainermodel.cpp:36
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