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

Kate

katetextbuffer.h

Go to the documentation of this file.
00001 /*  This file is part of the Kate project.
00002  *
00003  *  Copyright (C) 2010 Christoph Cullmann <cullmann@kde.org>
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Library General Public
00007  *  License as published by the Free Software Foundation; either
00008  *  version 2 of the License, or (at your option) any later version.
00009  *
00010  *  This library is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  Library General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU Library General Public License
00016  *  along with this library; see the file COPYING.LIB.  If not, write to
00017  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  *  Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #ifndef KATE_TEXTBUFFER_H
00022 #define KATE_TEXTBUFFER_H
00023 
00024 #include <QtCore/QObject>
00025 #include <QtCore/QString>
00026 #include <QtCore/QVector>
00027 #include <QtCore/QSet>
00028 #include <QtCore/QTextCodec>
00029 
00030 #include <ktexteditor/document.h>
00031 
00032 #include "katepartprivate_export.h"
00033 #include "katetextblock.h"
00034 #include "katetextcursor.h"
00035 #include "katetextrange.h"
00036 #include "katetexthistory.h"
00037 
00038 // encoding prober
00039 #include <kencodingprober.h>
00040 
00041 namespace Kate {
00042 
00047 class KATEPART_TESTS_EXPORT TextBuffer : public QObject {
00048   friend class TextCursor;
00049   friend class TextRange;
00050 
00051   Q_OBJECT
00052 
00053   public:
00057     enum EndOfLineMode {
00058         eolUnknown = -1
00059       , eolUnix = 0
00060       , eolDos = 1
00061       , eolMac = 2
00062     };
00063 
00070     TextBuffer (KTextEditor::Document *parent = 0, int blockSize = 64);
00071 
00076     virtual ~TextBuffer ();
00077 
00083     virtual void clear ();
00084 
00089     void setEncodingProberType (KEncodingProber::ProberType proberType) { m_encodingProberType = proberType; }
00090 
00095     KEncodingProber::ProberType encodingProberType () const { return m_encodingProberType; }
00096 
00101     void setFallbackTextCodec (QTextCodec *codec) { m_fallbackTextCodec = codec; }
00102 
00107     QTextCodec *fallbackTextCodec () const { return m_fallbackTextCodec; }
00108 
00114     void setTextCodec (QTextCodec *codec) { m_textCodec = codec; }
00115 
00120     QTextCodec *textCodec () const { return m_textCodec; }
00121 
00127     void setGenerateByteOrderMark (bool generateByteOrderMark) { m_generateByteOrderMark = generateByteOrderMark; }
00128 
00133     bool generateByteOrderMark () const { return m_generateByteOrderMark; }
00134 
00140     void setEndOfLineMode (EndOfLineMode endOfLineMode) { Q_ASSERT (endOfLineMode != eolUnknown); m_endOfLineMode = endOfLineMode; }
00141 
00146     EndOfLineMode endOfLineMode () const { return m_endOfLineMode; }
00147 
00152     void setRemoveTrailingSpaces (bool removeTrailingSpaces) { m_removeTrailingSpaces = removeTrailingSpaces; }
00153 
00158     bool removeTrailingSpaces () const { return m_removeTrailingSpaces; }
00159 
00169     virtual bool load (const QString &filename, bool &encodingErrors);
00170 
00178     virtual bool save (const QString &filename);
00179 
00184     int lines () const { Q_ASSERT (m_lines > 0); return m_lines; }
00185 
00191     qint64 revision () const { return m_revision; }
00192 
00198     TextLine line (int line) const;
00199 
00204     QString text () const;
00205 
00213     virtual bool startEditing ();
00214 
00220     virtual bool finishEditing ();
00221 
00226     int editingTransactions () const { return m_editingTransactions; }
00227 
00232     qint64 editingLastRevision () const { return m_editingLastRevision; }
00233 
00238     int editingLastLines () const { return m_editingLastLines; }
00239 
00245     bool editingChangedBuffer () const { return editingLastRevision() != revision(); }
00246 
00252     bool editingChangedNumberOfLines () const { return editingLastLines() != lines(); }
00253 
00258     int editingMinimalLineChanged () const { return m_editingMinimalLineChanged; }
00259 
00264     int editingMaximalLineChanged () const { return m_editingMaximalLineChanged; }
00265 
00271     virtual void wrapLine (const KTextEditor::Cursor &position);
00272 
00278     virtual void unwrapLine (int line);
00279 
00286     virtual void insertText (const KTextEditor::Cursor &position, const QString &text);
00287 
00293     virtual void removeText (const KTextEditor::Range &range);
00294 
00299     TextHistory &history () { return m_history; }
00300 
00301   Q_SIGNALS:
00306     void cleared ();
00307 
00313     void loaded (const QString &filename, bool encodingErrors);
00314 
00319     void saved (const QString &filename);
00320 
00324     void editingStarted ();
00325 
00329     void editingFinished ();
00330 
00335     void lineWrapped (const KTextEditor::Cursor &position);
00336 
00341     void lineUnwrapped (int line);
00342 
00348     void textInserted (const KTextEditor::Cursor &position, const QString &text);
00349 
00355     void textRemoved (const KTextEditor::Range &range, const QString &text);
00356 
00357   private:
00363     int blockForLine (int line) const;
00364 
00369     void fixStartLines (int startBlock);
00370 
00375     void balanceBlock (int index);
00376 
00382     TextBlock *blockForIndex (int index) { return m_blocks[index]; }
00383 
00391     void notifyAboutRangeChange (KTextEditor::View *view, int startLine, int endLine, bool rangeWithAttribute);
00392 
00393   public:
00398     KTextEditor::Document *document () const { return m_document; }
00399 
00404     void debugPrint (const QString &title) const;
00405 
00413     QList<TextRange *> rangesForLine (int line, KTextEditor::View *view, bool rangesWithAttributeOnly) const;
00414 
00419     bool rangePointerValid (TextRange *range) const { return m_ranges.contains (range); }
00420 
00424     void invalidateRanges();
00425 
00426   private:
00430     KTextEditor::Document *m_document;
00431 
00435     TextHistory m_history;
00436 
00440     const int m_blockSize;
00441 
00445     QVector<TextBlock *> m_blocks;
00446 
00450     int m_lines;
00451 
00456     mutable int m_lastUsedBlock;
00457 
00461     qint64 m_revision;
00462 
00466     int m_editingTransactions;
00467 
00471     qint64 m_editingLastRevision;
00472 
00476     int m_editingLastLines;
00477 
00481     int m_editingMinimalLineChanged;
00482 
00486     int m_editingMaximalLineChanged;
00487 
00492     QSet<TextCursor *> m_invalidCursors;
00493 
00497     QSet<TextRange *> m_ranges;
00498 
00502     KEncodingProber::ProberType m_encodingProberType;
00503 
00507     QTextCodec *m_fallbackTextCodec;
00508 
00512     QTextCodec *m_textCodec;
00513 
00518     QString m_mimeTypeForFilterDev;
00519 
00523     bool m_generateByteOrderMark;
00524 
00528     EndOfLineMode m_endOfLineMode;
00529 
00533     bool m_removeTrailingSpaces;
00534 };
00535 
00536 }
00537 
00538 #endif

Kate

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • 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
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal