Kate::TextBuffer

Search for usage in LXR

Kate::TextBuffer Class Reference

#include <katetextbuffer.h>

Inheritance diagram for Kate::TextBuffer:

Public Types

enum  EndOfLineMode { eolUnknown = -1, eolUnix = 0, eolDos = 1, eolMac = 2 }
 

Signals

void cleared ()
 
void editingFinished ()
 
void editingStarted ()
 
void lineUnwrapped (int line)
 
void lineWrapped (const KTextEditor::Cursor position)
 
void loaded (const QString &filename, bool encodingErrors)
 
void saved (const QString &filename)
 
void textInserted (const KTextEditor::Cursor position, const QString &text)
 
void textRemoved (KTextEditor::Range range, const QString &text)
 

Public Member Functions

 TextBuffer (KTextEditor::DocumentPrivate *parent, int blockSize=64, bool alwaysUseKAuth=false)
 
 ~TextBuffer () override
 
virtual void clear ()
 
void debugPrint (const QString &title) const
 
const QByteArraydigest () const
 
KTextEditor::DocumentPrivate * document () const
 
bool editingChangedBuffer () const
 
bool editingChangedNumberOfLines () const
 
int editingLastLines () const
 
qint64 editingLastRevision () const
 
int editingMaximalLineChanged () const
 
int editingMinimalLineChanged () const
 
int editingTransactions () const
 
KEncodingProber::ProberType encodingProberType () const
 
EndOfLineMode endOfLineMode () const
 
QTextCodecfallbackTextCodec () const
 
virtual bool finishEditing ()
 
bool generateByteOrderMark () const
 
TextHistoryhistory ()
 
virtual void insertText (const KTextEditor::Cursor position, const QString &text)
 
void invalidateRanges ()
 
TextLine line (int line) const
 
int lineLength (int line) const
 
int lines () const
 
virtual bool load (const QString &filename, bool &encodingErrors, bool &tooLongLinesWrapped, int &longestLineLoaded, bool enforceTextCodec)
 
bool rangePointerValid (TextRange *range) const
 
QVector< TextRange * > rangesForLine (int line, KTextEditor::View *view, bool rangesWithAttributeOnly) const
 
virtual void removeText (KTextEditor::Range range)
 
qint64 revision () const
 
virtual bool save (const QString &filename)
 
void setDigest (const QByteArray &checksum)
 
void setEncodingProberType (KEncodingProber::ProberType proberType)
 
void setEndOfLineMode (EndOfLineMode endOfLineMode)
 
void setFallbackTextCodec (QTextCodec *codec)
 
void setGenerateByteOrderMark (bool generateByteOrderMark)
 
void setLineLengthLimit (int lineLengthLimit)
 
void setTextCodec (QTextCodec *codec)
 
virtual bool startEditing ()
 
QString text () const
 
QTextCodectextCodec () const
 
virtual void unwrapLine (int line)
 
virtual void wrapLine (const KTextEditor::Cursor position)
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
bool blockSignals (bool block)
 
const QObjectListchildren () const const
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectInfo ()
 
void dumpObjectInfo () const const
 
void dumpObjectTree ()
 
void dumpObjectTree () const const
 
QList< QByteArraydynamicPropertyNames () const const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
bool inherits (const char *className) const const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const const
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
QVariant property (const char *name) const const
 
 Q_CLASSINFO (Name, Value)
 
 Q_DISABLE_COPY (Class)
 
 Q_DISABLE_COPY_MOVE (Class)
 
 Q_DISABLE_MOVE (Class)
 
 Q_EMIT Q_EMIT
 
 Q_ENUM (...)
 
 Q_ENUM_NS (...)
 
 Q_ENUMS (...)
 
 Q_FLAG (...)
 
 Q_FLAG_NS (...)
 
 Q_FLAGS (...)
 
 Q_GADGET Q_GADGET
 
 Q_INTERFACES (...)
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 
 Q_OBJECT Q_OBJECT
 
 Q_PROPERTY (...)
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SLOT Q_SLOT
 
 Q_SLOTS Q_SLOTS
 
qFindChild (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
 
QList< T > qFindChildren (const QObject *obj, const QString &name)
 
qobject_cast (const QObject *object)
 
qobject_cast (QObject *object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const const
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
 
QThreadthread () const const
 

Additional Inherited Members

- Properties inherited from QObject
 objectName
 
- Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 
- Public Attributes inherited from QObject
typedef QObjectList
 
- Protected Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
int receivers (const char *signal) const const
 
QObjectsender () const const
 
int senderSignalIndex () const const
 
virtual void timerEvent (QTimerEvent *event)
 

Detailed Description

Class representing a text buffer.

The interface is line based, internally the text will be stored in blocks of text lines.

Definition at line 40 of file katetextbuffer.h.

Member Enumeration Documentation

◆ EndOfLineMode

End of line mode.

Definition at line 52 of file katetextbuffer.h.

Constructor & Destructor Documentation

◆ TextBuffer()

Kate::TextBuffer::TextBuffer ( KTextEditor::DocumentPrivate *  parent,
int  blockSize = 64,
bool  alwaysUseKAuth = false 
)
explicit

Construct an empty text buffer.

Empty means one empty line in one block.

Parameters
parentparent qobject
blockSizeblock size in lines the buffer should try to hold, default 64 lines
alwaysUseKAuthonly set this for unit testing purposes

Definition at line 50 of file katetextbuffer.cpp.

◆ ~TextBuffer()

Kate::TextBuffer::~TextBuffer ( )
override

Destruct the text buffer Virtual, we allow inheritance.

Definition at line 78 of file katetextbuffer.cpp.

Member Function Documentation

◆ clear()

void Kate::TextBuffer::clear ( )
virtual

Clears the buffer, reverts to initial empty state.

Empty means one empty line in one block. Virtual, can be overwritten.

Reimplemented in KateBuffer.

Definition at line 116 of file katetextbuffer.cpp.

◆ cleared

void Kate::TextBuffer::cleared ( )
signal

Buffer got cleared.

This is emitted when constructor or load have called clear() internally, or when the user of the buffer has called clear() itself.

◆ debugPrint()

void Kate::TextBuffer::debugPrint ( const QString title) const

Debug output, print whole buffer content with line numbers and line length.

Parameters
titletitle for this output

Definition at line 537 of file katetextbuffer.cpp.

◆ digest()

const QByteArray & Kate::TextBuffer::digest ( ) const

Checksum of the document on disk, set either through file loading in openFile() or in KTextEditor::DocumentPrivate::saveFile()

Returns
git compatible sha1 checksum for this document

Definition at line 704 of file katetextbuffer.cpp.

◆ document()

KTextEditor::DocumentPrivate* Kate::TextBuffer::document ( ) const
inline

Gets the document to which this buffer is bound.

Returns
a pointer to the document

Definition at line 496 of file katetextbuffer.h.

◆ editingChangedBuffer()

bool Kate::TextBuffer::editingChangedBuffer ( ) const
inline

Query information from the last editing transaction: was the content of the buffer changed? This is checked by comparing the editingLastRevision() with the current revision().

Returns
content of buffer was changed in last transaction?

Definition at line 295 of file katetextbuffer.h.

◆ editingChangedNumberOfLines()

bool Kate::TextBuffer::editingChangedNumberOfLines ( ) const
inline

Query information from the last editing transaction: was the number of lines of the buffer changed? This is checked by comparing the editingLastLines() with the current lines().

Returns
content of buffer was changed in last transaction?

Definition at line 305 of file katetextbuffer.h.

◆ editingFinished

void Kate::TextBuffer::editingFinished ( )
signal

Editing transaction has finished.

◆ editingLastLines()

int Kate::TextBuffer::editingLastLines ( ) const
inline

Query the number of lines of this buffer before the ongoing editing transactions.

Returns
number of lines of buffer before current editing transaction altered it

Definition at line 285 of file katetextbuffer.h.

◆ editingLastRevision()

qint64 Kate::TextBuffer::editingLastRevision ( ) const
inline

Query the revision of this buffer before the ongoing editing transactions.

Returns
revision of buffer before current editing transaction altered it

Definition at line 276 of file katetextbuffer.h.

◆ editingMaximalLineChanged()

int Kate::TextBuffer::editingMaximalLineChanged ( ) const
inline

Get maximal line number changed by last editing transaction.

Returns
maximal line number changed by last editing transaction, or -1, if none changed

Definition at line 323 of file katetextbuffer.h.

◆ editingMinimalLineChanged()

int Kate::TextBuffer::editingMinimalLineChanged ( ) const
inline

Get minimal line number changed by last editing transaction.

Returns
maximal line number changed by last editing transaction, or -1, if none changed

Definition at line 314 of file katetextbuffer.h.

◆ editingStarted

void Kate::TextBuffer::editingStarted ( )
signal

Editing transaction has started.

◆ editingTransactions()

int Kate::TextBuffer::editingTransactions ( ) const
inline

Query the number of editing transactions running atm.

Returns
number of running transactions

Definition at line 267 of file katetextbuffer.h.

◆ encodingProberType()

KEncodingProber::ProberType Kate::TextBuffer::encodingProberType ( ) const
inline

Get encoding prober type for this buffer.

Returns
currently in use prober type of this buffer

Definition at line 89 of file katetextbuffer.h.

◆ endOfLineMode()

EndOfLineMode Kate::TextBuffer::endOfLineMode ( ) const
inline

Get end of line mode.

Returns
end of line mode

Definition at line 163 of file katetextbuffer.h.

◆ fallbackTextCodec()

QTextCodec* Kate::TextBuffer::fallbackTextCodec ( ) const
inline

Get fallback codec for this buffer.

Returns
currently in use fallback codec of this buffer

Definition at line 107 of file katetextbuffer.h.

◆ finishEditing()

bool Kate::TextBuffer::finishEditing ( )
virtual

Finish an editing transaction.

Only allowed to be called if editing transaction is started.

Returns
returns true, if this finished last running transaction Virtual, can be overwritten.

Definition at line 207 of file katetextbuffer.cpp.

◆ generateByteOrderMark()

bool Kate::TextBuffer::generateByteOrderMark ( ) const
inline

Generate byte order mark on save?

Returns
should BOM be generated?

Definition at line 143 of file katetextbuffer.h.

◆ history()

TextHistory& Kate::TextBuffer::history ( )
inline

TextHistory of this buffer.

Returns
text history for this buffer

Definition at line 361 of file katetextbuffer.h.

◆ insertText()

void Kate::TextBuffer::insertText ( const KTextEditor::Cursor  position,
const QString text 
)
virtual

Insert text at given cursor position.

Does nothing if text is empty, beside some consistency checks.

Parameters
positionposition where to insert text
texttext to insert Virtual, can be overwritten.

Definition at line 331 of file katetextbuffer.cpp.

◆ invalidateRanges()

void Kate::TextBuffer::invalidateRanges ( )

Invalidate all ranges in this buffer.

Definition at line 107 of file katetextbuffer.cpp.

◆ line()

TextLine Kate::TextBuffer::line ( int  line) const

Retrieve a text line.

Parameters
linewanted line number
Returns
text line

Definition at line 159 of file katetextbuffer.cpp.

◆ lineLength()

int Kate::TextBuffer::lineLength ( int  line) const
inline

Retrieve length for line.

Parameters
linewanted line number
Returns
length of the line

Definition at line 232 of file katetextbuffer.h.

◆ lines()

int Kate::TextBuffer::lines ( ) const
inline

Lines currently stored in this buffer.

This is never 0, even clear will let one empty line remain.

Definition at line 204 of file katetextbuffer.h.

◆ lineUnwrapped

void Kate::TextBuffer::lineUnwrapped ( int  line)
signal

A line got unwrapped.

Parameters
lineline where the unwrap occurred

◆ lineWrapped

void Kate::TextBuffer::lineWrapped ( const KTextEditor::Cursor  position)
signal

A line got wrapped.

Parameters
positionposition where the wrap occurred

◆ load()

bool Kate::TextBuffer::load ( const QString filename,
bool &  encodingErrors,
bool &  tooLongLinesWrapped,
int &  longestLineLoaded,
bool  enforceTextCodec 
)
virtual

Load the given file.

This will first clear the buffer and then load the file. Even on error during loading the buffer will still be cleared. Before calling this, setTextCodec must have been used to set codec!

Parameters
filenamefile to open
encodingErrorswere there problems occurred while decoding the file?
tooLongLinesWrappedwere too long lines found and wrapped?
longestLineLoadedthe longest line in the file (before wrapping)
enforceTextCodecenforce to use only the set text codec
Returns
success, the file got loaded, perhaps with encoding errors Virtual, can be overwritten.

Definition at line 548 of file katetextbuffer.cpp.

◆ loaded

void Kate::TextBuffer::loaded ( const QString filename,
bool  encodingErrors 
)
signal

Buffer loaded successfully a file.

Parameters
filenamefile which was loaded
encodingErrorswere there problems occurred while decoding the file?

◆ rangePointerValid()

bool Kate::TextBuffer::rangePointerValid ( TextRange range) const
inline

Check if the given range pointer is still valid.

Returns
range pointer still belongs to range for this buffer

Definition at line 525 of file katetextbuffer.h.

◆ rangesForLine()

QVector<TextRange *> Kate::TextBuffer::rangesForLine ( int  line,
KTextEditor::View view,
bool  rangesWithAttributeOnly 
) const
inline

Return the ranges which affect the given line.

Parameters
lineline to look at
viewonly return ranges associated with given view
rangesWithAttributeOnlyonly return ranges which have a attribute set
Returns
list of ranges affecting this line

Definition at line 514 of file katetextbuffer.h.

◆ removeText()

void Kate::TextBuffer::removeText ( KTextEditor::Range  range)
virtual

Remove text at given range.

Does nothing if range is empty, beside some consistency checks.

Parameters
rangerange of text to remove, must be on one line only. Virtual, can be overwritten.

Definition at line 369 of file katetextbuffer.cpp.

◆ revision()

qint64 Kate::TextBuffer::revision ( ) const
inline

Revision of this buffer.

Is set to 0 on construction, clear() (load will trigger clear()). Is incremented on each change to the buffer.

Returns
current revision

Definition at line 215 of file katetextbuffer.h.

◆ save()

bool Kate::TextBuffer::save ( const QString filename)
virtual

Save the current buffer content to the given file.

Before calling this, setTextCodec and setFallbackTextCodec must have been used to set codec!

Parameters
filenamefile to save
Returns
success Virtual, can be overwritten.

Definition at line 728 of file katetextbuffer.cpp.

◆ saved

void Kate::TextBuffer::saved ( const QString filename)
signal

Buffer saved successfully a file.

Parameters
filenamefile which was saved

◆ setDigest()

void Kate::TextBuffer::setDigest ( const QByteArray checksum)

Set the checksum of this buffer.

Make sure this checksum is up-to-date when reading digest().

Parameters
checksumgit compatible sha1 digest for the document on disk

Definition at line 709 of file katetextbuffer.cpp.

◆ setEncodingProberType()

void Kate::TextBuffer::setEncodingProberType ( KEncodingProber::ProberType  proberType)
inline

Set encoding prober type for this buffer to use for load.

Parameters
proberTypeprober type to use for encoding

Definition at line 80 of file katetextbuffer.h.

◆ setEndOfLineMode()

void Kate::TextBuffer::setEndOfLineMode ( EndOfLineMode  endOfLineMode)
inline

Set end of line mode for this buffer, not allowed to be set to unknown.

Loading might overwrite this setting, if there is a eol found inside the file.

Parameters
endOfLineModenew eol mode

Definition at line 153 of file katetextbuffer.h.

◆ setFallbackTextCodec()

void Kate::TextBuffer::setFallbackTextCodec ( QTextCodec codec)
inline

Set fallback codec for this buffer to use for load.

Parameters
codecfallback QTextCodec to use for encoding

Definition at line 98 of file katetextbuffer.h.

◆ setGenerateByteOrderMark()

void Kate::TextBuffer::setGenerateByteOrderMark ( bool  generateByteOrderMark)
inline

Generate byte order mark on save.

Loading might overwrite this setting, if there is a BOM found inside the file.

Parameters
generateByteOrderMarkshould BOM be generated?

Definition at line 134 of file katetextbuffer.h.

◆ setLineLengthLimit()

void Kate::TextBuffer::setLineLengthLimit ( int  lineLengthLimit)
inline

Set line length limit.

Parameters
lineLengthLimitnew line length limit

Definition at line 172 of file katetextbuffer.h.

◆ setTextCodec()

void Kate::TextBuffer::setTextCodec ( QTextCodec codec)

Set codec for this buffer to use for load/save.

Loading might overwrite this, if it encounters problems and finds a better codec. Might change BOM setting.

Parameters
codecQTextCodec to use for encoding

Definition at line 714 of file katetextbuffer.cpp.

◆ startEditing()

bool Kate::TextBuffer::startEditing ( )
virtual

Start an editing transaction, the wrapLine/unwrapLine/insertText and removeText functions are only allowed to be called inside a editing transaction.

Editing transactions can stack. The number of startEdit and endEdit calls must match.

Returns
returns true, if no transaction was already running Virtual, can be overwritten.

Definition at line 181 of file katetextbuffer.cpp.

◆ text()

QString Kate::TextBuffer::text ( ) const

Retrieve text of complete buffer.

Returns
text for this buffer, lines separated by '
'

Definition at line 168 of file katetextbuffer.cpp.

◆ textCodec()

QTextCodec* Kate::TextBuffer::textCodec ( ) const
inline

Get codec for this buffer.

Returns
currently in use codec of this buffer

Definition at line 124 of file katetextbuffer.h.

◆ textInserted

void Kate::TextBuffer::textInserted ( const KTextEditor::Cursor  position,
const QString text 
)
signal

Text got inserted.

Parameters
positionposition where the insertion occurred
textinserted text

◆ textRemoved

void Kate::TextBuffer::textRemoved ( KTextEditor::Range  range,
const QString text 
)
signal

Text got removed.

Parameters
rangerange where the removal occurred
textremoved text

◆ unwrapLine()

void Kate::TextBuffer::unwrapLine ( int  line)
virtual

Unwrap given line.

Parameters
lineline to unwrap Virtual, can be overwritten.

Reimplemented in KateBuffer.

Definition at line 278 of file katetextbuffer.cpp.

◆ wrapLine()

void Kate::TextBuffer::wrapLine ( const KTextEditor::Cursor  position)
virtual

Wrap line at given cursor position.

Parameters
positionline/column as cursor where to wrap Virtual, can be overwritten.

Reimplemented in KateBuffer.

Definition at line 236 of file katetextbuffer.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Mar 21 2023 03:54:08 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.