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

cantor/src/lib

  • sources
  • kde-4.14
  • kdeedu
  • cantor
  • src
  • lib
textresult.cpp
Go to the documentation of this file.
1 /*
2  This program is free software; you can redistribute it and/or
3  modify it under the terms of the GNU General Public License
4  as published by the Free Software Foundation; either version 2
5  of the License, or (at your option) any later version.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin Street, Fifth Floor,
15  Boston, MA 02110-1301, USA.
16 
17  ---
18  Copyright (C) 2009 Alexander Rieder <alexanderrieder@gmail.com>
19  */
20 
21 #include "textresult.h"
22 using namespace Cantor;
23 
24 #include <kdebug.h>
25 
26 #include <QFile>
27 #include <QTextStream>
28 
29 class Cantor::TextResultPrivate
30 {
31 public:
32  TextResultPrivate()
33  {
34  format=TextResult::PlainTextFormat;
35  }
36 
37  QString data;
38  QString plain;
39  TextResult::Format format;
40 };
41 
42 TextResult::TextResult(const QString& data) : d(new TextResultPrivate)
43 {
44  d->data=data.trimmed();
45  d->plain=data.trimmed();
46 }
47 
48 TextResult::TextResult(const QString& data, const QString& plain) : d(new TextResultPrivate)
49 {
50  d->data=data.trimmed();
51  d->plain=plain.trimmed();
52 }
53 
54 
55 TextResult::~TextResult()
56 {
57  delete d;
58 }
59 
60 QString TextResult::toHtml()
61 {
62  QString s=d->data;
63  s.replace('\n', "<br/>\n");
64  return s;
65 }
66 
67 QVariant TextResult::data()
68 {
69  return QVariant(d->data);
70 }
71 
72 QString TextResult::plain()
73 {
74  return d->plain;
75 }
76 
77 int TextResult::type()
78 {
79  return TextResult::Type;
80 }
81 
82 QString TextResult::mimeType()
83 {
84  kDebug()<<"format: "<<format();
85  if(format()==TextResult::PlainTextFormat)
86  return "text/plain";
87  else
88  return "text/x-tex";
89 }
90 
91 TextResult::Format TextResult::format()
92 {
93  return d->format;
94 }
95 
96 void TextResult::setFormat(TextResult::Format f)
97 {
98  d->format=f;
99 }
100 
101 QDomElement TextResult::toXml(QDomDocument& doc)
102 {
103  kDebug()<<"saving textresult "<<toHtml();
104  QDomElement e=doc.createElement("Result");
105  e.setAttribute("type", "text");
106  QDomText txt=doc.createTextNode(data().toString());
107  e.appendChild(txt);
108 
109  return e;
110 }
111 
112 void TextResult::save(const QString& filename)
113 {
114  QFile file(filename);
115 
116  if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
117  return;
118 
119  QTextStream stream(&file);
120 
121  stream<<d->data;
122 
123  file.close();
124 }
125 
126 
127 
Cantor::TextResult::type
int type()
returns an unique number, representing the type of this result.
Definition: textresult.cpp:77
QDomNode::appendChild
QDomNode appendChild(const QDomNode &newChild)
Cantor::TextResult::PlainTextFormat
Definition: textresult.h:36
Cantor::TextResult::data
QVariant data()
returns data associated with this result (text/images/etc)
Definition: textresult.cpp:67
Cantor::TextResult::TextResult
TextResult(const QString &text)
Definition: textresult.cpp:42
QFile
QTextStream
textresult.h
Cantor::TextResult::toHtml
QString toHtml()
returns html code, that represents this result, e.g.
Definition: textresult.cpp:60
Cantor::TextResult::mimeType
QString mimeType()
returns the mimetype, this result is
Definition: textresult.cpp:82
QDomElement::setAttribute
void setAttribute(const QString &name, const QString &value)
Cantor::TextResult::toXml
QDomElement toXml(QDomDocument &doc)
returns a DomElement, containing the information of the result
Definition: textresult.cpp:101
Cantor::TextResult::format
Format format()
Definition: textresult.cpp:91
QString::trimmed
QString trimmed() const
QString
QFile::open
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
QDomDocument::createTextNode
QDomText createTextNode(const QString &value)
Cantor::TextResult::plain
QString plain()
Definition: textresult.cpp:72
QDomDocument
QFile::close
virtual void close()
Cantor::TextResult::Type
Definition: textresult.h:35
QString::replace
QString & replace(int position, int n, QChar after)
Cantor::TextResult::save
void save(const QString &filename)
saves this to a file
Definition: textresult.cpp:112
Cantor::TextResult::setFormat
void setFormat(Format f)
Definition: textresult.cpp:96
QDomDocument::createElement
QDomElement createElement(const QString &tagName)
QDomElement
Cantor::TextResult::Format
Format
Definition: textresult.h:36
QDomText
Cantor::TextResult::~TextResult
~TextResult()
Definition: textresult.cpp:55
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:16:33 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

cantor/src/lib

Skip menu "cantor/src/lib"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

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