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