• 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
vocabularymimedata.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 
3  Copyright 2007 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 
17 #include "vocabularymimedata.h"
18 
19 #include <keduvoctranslation.h>
20 #include <keduvocwordtype.h>
21 
22 
23 void VocabularyMimeData::setTranslations(QList<KEduVocTranslation *> translations)
24 {
25  // list of pointers for drag and drop - for example to assign word types
26  m_translations = translations;
27 
28  // sort the translations into entries to make deep copies for real copy and paste
29  // to only include each expression once
30  QList<KEduVocExpression *> expressions;
31  foreach(KEduVocTranslation * translation, m_translations) {
32  if (!expressions.contains(translation->entry())) {
33  expressions.append(translation->entry());
34  }
35  }
36 
37  foreach(KEduVocExpression * expression, expressions) {
38  MimeExpression exp;
39  // deep copy
40  exp.expression = KEduVocExpression(*expression);
41 
42  // copy word types
43  // this sucks but there is not really a better was. copying pointers is not a good idea because copy and paste can be done between different documents.
44  foreach(int i, expression->translationIndices()) {
45  // generate text string representation
46  m_text.append(expression->translation(i)->text());
47  m_text.append(" - ");
48 
49  // fill in word types independent of pointers
50  KEduVocWordType *type = expression->translation(i)->wordType();
51 
52  if (type) { // check if it has a type != 0
53  exp.wordTypes[i].grammarType = expression->translation(i)->wordType()->wordType();
54 
55  // this may seem weird, but the root element is "word types" so no need to copy that one.
56  while (type->parent()) {
57  exp.wordTypes[i].wordType.prepend(type->name());
58  type = static_cast<KEduVocWordType*>(type->parent());
59  }
60  }
61  }
62  m_expressions.append(exp);
63  m_text.append('\n');
64  }
65 }
66 
67 QList< KEduVocTranslation * > VocabularyMimeData::translationList() const
68 {
69  return m_translations;
70 }
71 
72 QVariant VocabularyMimeData::retrieveData(const QString & mimeType, QVariant::Type type) const
73 {
74  Q_UNUSED(type)
75  // only use the expression list.expressions
76  // the translation list may be invalid (eg when cut it is no longer valid.
77  // translations can only be used internally for drag and drop!!!
78 
79  if (mimeType == "text/plain") {
80  return m_text;
81  }
82  return QVariant();
83 }
84 
85 QStringList VocabularyMimeData::formats() const
86 {
87  return QStringList() << "text/plain";
88 }
89 
90 QList< VocabularyMimeData::MimeExpression > VocabularyMimeData::expressionList() const
91 {
92  return m_expressions;
93 }
94 
95 
96 #include "vocabularymimedata.moc"
VocabularyMimeData::MimeExpression::expression
KEduVocExpression expression
Definition: vocabularymimedata.h:37
QString::append
QString & append(QChar ch)
VocabularyMimeData::MimeExpression
Definition: vocabularymimedata.h:30
VocabularyMimeData::retrieveData
QVariant retrieveData(const QString &mimeType, QVariant::Type type) const
Definition: vocabularymimedata.cpp:72
vocabularymimedata.h
QList::append
void append(const T &value)
VocabularyMimeData::formats
QStringList formats() const
Definition: vocabularymimedata.cpp:85
QString
QList< KEduVocTranslation * >
QStringList
QList::contains
bool contains(const T &value) const
VocabularyMimeData::MimeExpression::wordTypes
QMap< int, WordTypeStrings > wordTypes
Definition: vocabularymimedata.h:39
VocabularyMimeData::expressionList
QList< VocabularyMimeData::MimeExpression > expressionList() const
Definition: vocabularymimedata.cpp:90
VocabularyMimeData::translationList
QList< KEduVocTranslation * > translationList() const
Definition: vocabularymimedata.cpp:67
VocabularyMimeData::setTranslations
void setTranslations(QList< KEduVocTranslation * > translation)
Definition: vocabularymimedata.cpp:23
QVariant
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