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

Kate

  • kde-4.14
  • applications
  • kate
  • part
  • buffer
katetextbuffer.h
Go to the documentation of this file.
1 /* This file is part of the Kate project.
2  *
3  * Copyright (C) 2010 Christoph Cullmann <cullmann@kde.org>
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 #ifndef KATE_TEXTBUFFER_H
22 #define KATE_TEXTBUFFER_H
23 
24 #include <QtCore/QObject>
25 #include <QtCore/QString>
26 #include <QtCore/QVector>
27 #include <QtCore/QSet>
28 #include <QtCore/QTextCodec>
29 
30 #include <ktexteditor/document.h>
31 
32 #include "katedocument.h"
33 #include "katepartprivate_export.h"
34 #include "katetextblock.h"
35 #include "katetextcursor.h"
36 #include "katetextrange.h"
37 #include "katetexthistory.h"
38 
39 // encoding prober
40 #include <kencodingprober.h>
41 
42 namespace Kate {
43 
48 class KATEPART_TESTS_EXPORT TextBuffer : public QObject {
49  friend class TextCursor;
50  friend class TextRange;
51  friend class TextBlock;
52 
53  Q_OBJECT
54 
55  public:
59  enum EndOfLineMode {
60  eolUnknown = -1
61  , eolUnix = 0
62  , eolDos = 1
63  , eolMac = 2
64  };
65 
72  TextBuffer (KateDocument *parent, int blockSize = 64);
73 
78  virtual ~TextBuffer ();
79 
85  virtual void clear ();
86 
91  void setEncodingProberType (KEncodingProber::ProberType proberType) { m_encodingProberType = proberType; }
92 
97  KEncodingProber::ProberType encodingProberType () const { return m_encodingProberType; }
98 
103  void setFallbackTextCodec (QTextCodec *codec) { m_fallbackTextCodec = codec; }
104 
109  QTextCodec *fallbackTextCodec () const { return m_fallbackTextCodec; }
110 
117  void setTextCodec (QTextCodec *codec);
118 
123  QTextCodec *textCodec () const { return m_textCodec; }
124 
130  void setGenerateByteOrderMark (bool generateByteOrderMark) { m_generateByteOrderMark = generateByteOrderMark; }
131 
136  bool generateByteOrderMark () const { return m_generateByteOrderMark; }
137 
143  void setEndOfLineMode (EndOfLineMode endOfLineMode) { Q_ASSERT (endOfLineMode != eolUnknown); m_endOfLineMode = endOfLineMode; }
144 
149  EndOfLineMode endOfLineMode () const { return m_endOfLineMode; }
150 
155  void setNewLineAtEof(bool newlineAtEof) { m_newLineAtEof = newlineAtEof; }
156 
161  void setLineLengthLimit (int lineLengthLimit) { m_lineLengthLimit = lineLengthLimit; }
162 
174  virtual bool load (const QString &filename, bool &encodingErrors, bool &tooLongLinesWrapped, bool enforceTextCodec);
175 
183  virtual bool save (const QString &filename);
184 
189  int lines () const { Q_ASSERT (m_lines > 0); return m_lines; }
190 
196  qint64 revision () const { return m_revision; }
197 
203  TextLine line (int line) const;
204 
209  QString text () const;
210 
218  virtual bool startEditing ();
219 
225  virtual bool finishEditing ();
226 
231  int editingTransactions () const { return m_editingTransactions; }
232 
237  qint64 editingLastRevision () const { return m_editingLastRevision; }
238 
243  int editingLastLines () const { return m_editingLastLines; }
244 
250  bool editingChangedBuffer () const { return editingLastRevision() != revision(); }
251 
257  bool editingChangedNumberOfLines () const { return editingLastLines() != lines(); }
258 
263  int editingMinimalLineChanged () const { return m_editingMinimalLineChanged; }
264 
269  int editingMaximalLineChanged () const { return m_editingMaximalLineChanged; }
270 
276  virtual void wrapLine (const KTextEditor::Cursor &position);
277 
283  virtual void unwrapLine (int line);
284 
291  virtual void insertText (const KTextEditor::Cursor &position, const QString &text);
292 
298  virtual void removeText (const KTextEditor::Range &range);
299 
304  TextHistory &history () { return m_history; }
305 
306  Q_SIGNALS:
311  void cleared ();
312 
318  void loaded (const QString &filename, bool encodingErrors);
319 
324  void saved (const QString &filename);
325 
329  void editingStarted ();
330 
334  void editingFinished ();
335 
340  void lineWrapped (const KTextEditor::Cursor &position);
341 
346  void lineUnwrapped (int line);
347 
353  void textInserted (const KTextEditor::Cursor &position, const QString &text);
354 
360  void textRemoved (const KTextEditor::Range &range, const QString &text);
361 
362  private:
368  int blockForLine (int line) const;
369 
374  void fixStartLines (int startBlock);
375 
380  void balanceBlock (int index);
381 
387  TextBlock *blockForIndex (int index) { return m_blocks[index]; }
388 
396  void notifyAboutRangeChange (KTextEditor::View *view, int startLine, int endLine, bool rangeWithAttribute);
397 
401  void markModifiedLinesAsSaved();
402 
403  public:
408  KateDocument *document () const { return m_document; }
409 
414  void debugPrint (const QString &title) const;
415 
423  QList<TextRange *> rangesForLine (int line, KTextEditor::View *view, bool rangesWithAttributeOnly) const;
424 
429  bool rangePointerValid (TextRange *range) const { return m_ranges.contains (range); }
430 
434  void invalidateRanges();
435 
436  //
437  // md5 checksum handling
438  //
439  public:
445  const QByteArray &digest () const;
446 
452  void setDigest (const QByteArray & md5sum);
453 
454  private:
455  QByteArray m_digest;
456 
457  private:
461  KateDocument *m_document;
462 
466  TextHistory m_history;
467 
471  const int m_blockSize;
472 
476  QVector<TextBlock *> m_blocks;
477 
481  int m_lines;
482 
487  mutable int m_lastUsedBlock;
488 
492  qint64 m_revision;
493 
497  int m_editingTransactions;
498 
502  qint64 m_editingLastRevision;
503 
507  int m_editingLastLines;
508 
512  int m_editingMinimalLineChanged;
513 
517  int m_editingMaximalLineChanged;
518 
523  QSet<TextCursor *> m_invalidCursors;
524 
528  QSet<TextRange *> m_ranges;
529 
533  KEncodingProber::ProberType m_encodingProberType;
534 
538  QTextCodec *m_fallbackTextCodec;
539 
543  QTextCodec *m_textCodec;
544 
549  QString m_mimeTypeForFilterDev;
550 
554  bool m_generateByteOrderMark;
555 
559  EndOfLineMode m_endOfLineMode;
560 
564  bool m_newLineAtEof;
565 
569  int m_lineLengthLimit;
570 };
571 
572 }
573 
574 #endif
Kate::TextBuffer::document
KateDocument * document() const
Gets the document to which this buffer is bound.
Definition: katetextbuffer.h:408
Kate::TextBuffer::setGenerateByteOrderMark
void setGenerateByteOrderMark(bool generateByteOrderMark)
Generate byte order mark on save.
Definition: katetextbuffer.h:130
Kate::TextBuffer::editingChangedBuffer
bool editingChangedBuffer() const
Query information from the last editing transaction: was the content of the buffer changed...
Definition: katetextbuffer.h:250
Kate::TextBuffer::endOfLineMode
EndOfLineMode endOfLineMode() const
Get end of line mode.
Definition: katetextbuffer.h:149
Kate::TextBuffer::textCodec
QTextCodec * textCodec() const
Get codec for this buffer.
Definition: katetextbuffer.h:123
katetextblock.h
Kate::TextBuffer::encodingProberType
KEncodingProber::ProberType encodingProberType() const
Get encoding prober type for this buffer.
Definition: katetextbuffer.h:97
QByteArray
Kate::TextBuffer::rangePointerValid
bool rangePointerValid(TextRange *range) const
Check if the given range pointer is still valid.
Definition: katetextbuffer.h:429
katetexthistory.h
Kate::TextBuffer::setFallbackTextCodec
void setFallbackTextCodec(QTextCodec *codec)
Set fallback codec for this buffer to use for load.
Definition: katetextbuffer.h:103
katedocument.h
KATEPART_TESTS_EXPORT
#define KATEPART_TESTS_EXPORT
Definition: katepartprivate_export.h:36
katetextrange.h
Kate::TextBuffer::EndOfLineMode
EndOfLineMode
End of line mode.
Definition: katetextbuffer.h:59
Kate::TextBuffer::editingMaximalLineChanged
int editingMaximalLineChanged() const
Get maximal line number changed by last editing transaction.
Definition: katetextbuffer.h:269
Kate::TextBuffer::editingChangedNumberOfLines
bool editingChangedNumberOfLines() const
Query information from the last editing transaction: was the number of lines of the buffer changed...
Definition: katetextbuffer.h:257
Kate::TextBuffer::setNewLineAtEof
void setNewLineAtEof(bool newlineAtEof)
Set whether to insert a newline character on save at the end of the file.
Definition: katetextbuffer.h:155
QSharedPointer
QObject
katepartprivate_export.h
Kate::TextBuffer::fallbackTextCodec
QTextCodec * fallbackTextCodec() const
Get fallback codec for this buffer.
Definition: katetextbuffer.h:109
QSet
QString
QList
QTextCodec
KateDocument
Definition: katedocument.h:74
Kate::TextBuffer::setEncodingProberType
void setEncodingProberType(KEncodingProber::ProberType proberType)
Set encoding prober type for this buffer to use for load.
Definition: katetextbuffer.h:91
Kate::TextBuffer::lines
int lines() const
Lines currently stored in this buffer.
Definition: katetextbuffer.h:189
Kate::TextBuffer::setEndOfLineMode
void setEndOfLineMode(EndOfLineMode endOfLineMode)
Set end of line mode for this buffer, not allowed to be set to unknown.
Definition: katetextbuffer.h:143
QVector
Kate::TextCursor
Class representing a 'clever' text cursor.
Definition: katetextcursor.h:43
Kate::TextHistory
Class representing the editing history of a TextBuffer.
Definition: katetexthistory.h:39
Kate::TextBuffer::setLineLengthLimit
void setLineLengthLimit(int lineLengthLimit)
Set line length limit.
Definition: katetextbuffer.h:161
Kate::TextBuffer::generateByteOrderMark
bool generateByteOrderMark() const
Generate byte order mark on save?
Definition: katetextbuffer.h:136
Kate::TextBuffer::revision
qint64 revision() const
Revision of this buffer.
Definition: katetextbuffer.h:196
Kate::TextBuffer::editingMinimalLineChanged
int editingMinimalLineChanged() const
Get minimal line number changed by last editing transaction.
Definition: katetextbuffer.h:263
Kate::TextBuffer::editingTransactions
int editingTransactions() const
Query the number of editing transactions running atm.
Definition: katetextbuffer.h:231
Kate::TextBuffer
Class representing a text buffer.
Definition: katetextbuffer.h:48
Kate::TextBuffer::history
TextHistory & history()
TextHistory of this buffer.
Definition: katetextbuffer.h:304
katetextcursor.h
Kate::TextRange
Class representing a 'clever' text range.
Definition: katetextrange.h:46
Kate::TextBuffer::editingLastRevision
qint64 editingLastRevision() const
Query the revsion of this buffer before the ongoing editing transactions.
Definition: katetextbuffer.h:237
Kate::TextBlock
Class representing a text block.
Definition: katetextblock.h:42
Kate::TextBuffer::editingLastLines
int editingLastLines() const
Query the number of lines of this buffer before the ongoing editing transactions. ...
Definition: katetextbuffer.h:243
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:58 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Kate

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

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

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