• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.11.5 API Reference
  • KDE Home
  • Contact Us
 

KTextEditor

  • interfaces
  • ktexteditor
document.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  *
3  * Copyright (C) 2010 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #include "document.h"
22 #include "document.moc"
23 
24 #include "documentadaptor_p.h"
25 #include "documentadaptor_p.moc"
26 
27 using namespace KTextEditor;
28 
29 
30 DocumentAdaptor::DocumentAdaptor(Document *document):
31  QDBusAbstractAdaptor(document),m_document(document) {
32 }
33 
34 DocumentAdaptor::~DocumentAdaptor() {}
35 
36 bool DocumentAdaptor::clear() {
37  return m_document->clear();
38 }
39 
40 bool DocumentAdaptor::reload() {
41  return m_document->documentReload();
42 }
43 
44 bool DocumentAdaptor::save() {
45  return m_document->documentSave();
46 }
47 
48 bool DocumentAdaptor::saveAs() {
49  return m_document->documentSaveAs();
50 }
51 
52 bool DocumentAdaptor::setTextLines(const QStringList &text) {
53  return m_document->setText(text);
54 }
55 
56 bool DocumentAdaptor::isEmpty() const {
57  return m_document->isEmpty();
58 }
59 
60 bool DocumentAdaptor::setEncoding(const QString &encoding) {
61  return m_document->setEncoding(encoding);
62 }
63 
64 const QString &DocumentAdaptor::encoding() const {
65  return m_document->encoding();
66 }
67 
68 bool DocumentAdaptor::setText(const QString &text) {
69  return m_document->setText(text);
70 }
71 
72 QString DocumentAdaptor::text() const {
73  return m_document->text();
74 }
75 
76 int DocumentAdaptor::lines() const {
77  return m_document->lines();
78 }
79 
80 int DocumentAdaptor::totalCharacters() const {
81  return m_document->totalCharacters();
82 }
83 
84 int DocumentAdaptor::lineLength(int line) const {
85  return m_document->lineLength(line);
86 }
87 
88 QPoint DocumentAdaptor::endOfLine(int line) const {
89  Cursor c=m_document->endOfLine(line);
90  return QPoint(c.column(),c.line());
91 }
92 
93 bool DocumentAdaptor::insertText(const QPoint& cursor,const QString& text, bool block) {
94  return m_document->insertText(Cursor(cursor.y(),cursor.x()),text,block);
95 }
96 
97 bool DocumentAdaptor::insertTextLines(const QPoint& cursor,const QStringList& text, bool block) {
98  return m_document->insertText(Cursor(cursor.y(),cursor.x()),text,block);
99 }
100 
101 bool DocumentAdaptor::cursorInText(const QPoint& cursor) {
102  return m_document->cursorInText(Cursor(cursor.y(),cursor.x()));
103 }
104 
105 bool DocumentAdaptor::insertLine(int line, const QString& text) {
106  return m_document->insertLine(line,text);
107 }
108 
109 bool DocumentAdaptor::insertLines(int line, const QStringList& text) {
110  return m_document->insertLines(line,text);
111 }
112 
113 bool DocumentAdaptor::removeLine(int line) {
114  return m_document->removeLine(line);
115 }
116 
117 
118 class KTextEditor::DocumentPrivate {
119  public:
120  DocumentPrivate()
121  : openingError(false), suppressOpeningErrorDialogs(false),isOrphaned(false) { }
122  bool openingError;
123  bool suppressOpeningErrorDialogs;
124  QString openingErrorMessage;
125  bool isOrphaned;
126 };
127 
128 Document::Document( QObject *parent)
129  : KParts::ReadWritePart(parent)
130  , d(new DocumentPrivate())
131 {
132  qRegisterMetaType<KTextEditor::Document*>("KTextEditor::Document*");
133  new DocumentAdaptor(this);
134 }
135 
136 Document::~Document()
137 {
138  delete d;
139 }
140 
141 void Document::setSuppressOpeningErrorDialogs(bool suppress) {
142  d->suppressOpeningErrorDialogs=suppress;
143 }
144 
145 bool Document::suppressOpeningErrorDialogs() const {
146  return d->suppressOpeningErrorDialogs;
147 }
148 
149 bool Document::openingError() const {
150  return d->openingError;
151 }
152 
153 QString Document::openingErrorMessage() const {
154  return d->openingErrorMessage;
155 }
156 
157 void Document::setOpeningError(bool errors) {
158  d->openingError=errors;
159 }
160 
161 void Document::setOpeningErrorMessage(const QString& message) {
162  d->openingErrorMessage=message;
163 }
164 
165 bool Document::isOrphaned() const {
166  return d->isOrphaned;
167 }
168 
169 void Document::setOrphaned(bool value) {
170  d->isOrphaned=value;
171 }
172 
173 bool Document::cursorInText(const Cursor& cursor)
174 {
175  if ( (cursor.line()<0) || (cursor.line()>=lines())) return false;
176  return (cursor.column()>=0) && (cursor.column()<=lineLength(cursor.line())); // = because new line isn't usually contained in line length
177 }
178 
179 bool KTextEditor::Document::replaceText( const Range & range, const QString & text, bool block )
180 {
181  bool success = true;
182  startEditing();
183  success &= removeText(range, block);
184  success &= insertText(range.start(), text, block);
185  endEditing();
186  return success;
187 }
188 
189 bool Document::replaceText( const Range & range, const QStringList & text, bool block )
190 {
191  bool success = true;
192  startEditing();
193  success &= removeText(range, block);
194  success &= insertText(range.start(), text, block);
195  endEditing();
196  return success;
197 }
198 
199 bool Document::isEmpty( ) const
200 {
201  return documentEnd() == Cursor::start();
202 }
203 
204 // kate: space-indent on; indent-width 2; replace-tabs on;
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Mon May 5 2014 18:23:40 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KTextEditor

Skip menu "KTextEditor"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.11.5 API Reference

Skip menu "kdelibs-4.11.5 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
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