Kate::TextFolding

#include <katetextfolding.h>

Inheritance diagram for Kate::TextFolding:

Public Types

enum  FoldingRangeFlag { Persistent = 0x1, Folded = 0x2 }
 
typedef QFlags< FoldingRangeFlagFoldingRangeFlags
 

Signals

void foldingRangesChanged ()
 

Public Slots

void clear ()
 

Public Member Functions

 TextFolding (TextBuffer &buffer)
 
 ~TextFolding ()
 
QString debugDump () const
 
void debugPrint (const QString &title) const
 
void ensureLineIsVisible (int line)
 
QJsonDocument exportFoldingRanges () const
 
KTextEditor::Range foldingRange (qint64 id) const
 
QVector< QPair< qint64, FoldingRangeFlags > > foldingRangesForParentRange (qint64 parentRangeId=-1) const
 
QVector< QPair< qint64, FoldingRangeFlags > > foldingRangesStartingOnLine (int line) const
 
bool foldRange (qint64 id)
 
void importFoldingRanges (const QJsonDocument &folds)
 
bool isLineVisible (int line, qint64 *foldedRangeId=nullptr) const
 
int lineToVisibleLine (int line) const
 
qint64 newFoldingRange (const KTextEditor::Range &range, FoldingRangeFlags flags=FoldingRangeFlags())
 
bool unfoldRange (qint64 id, bool remove=false)
 
int visibleLines () const
 
int visibleLineToLine (int visibleLine) const
 
- 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 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
 
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 (QObject *object)
 
qobject_cast (const 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 *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
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, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &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 the folding information for a TextBuffer.

The interface allows to arbitrary fold given regions of a buffer as long as they are well nested. Multiple instances of this class can exist for the same buffer.

Definition at line 30 of file katetextfolding.h.

Member Enumeration Documentation

Folding state of a range.

Enumerator
Persistent 

Range is persistent, e.g.

it should not auto-delete after unfolding!

Folded 

Range is folded away.

Definition at line 49 of file katetextfolding.h.

Constructor & Destructor Documentation

Kate::TextFolding::TextFolding ( TextBuffer buffer)
explicit

Create folding object for given buffer.

Parameters
buffertext buffer we want to provide folding info for

Definition at line 34 of file katetextfolding.cpp.

Kate::TextFolding::~TextFolding ( )

Cleanup.

Definition at line 43 of file katetextfolding.cpp.

Member Function Documentation

void Kate::TextFolding::clear ( )
slot

Clear the complete folding.

This is automatically triggered if the buffer is cleared.

Definition at line 49 of file katetextfolding.cpp.

QString Kate::TextFolding::debugDump ( ) const

Dump folding state as string, for unit testing and debugging.

Returns
current state as text

Definition at line 422 of file katetextfolding.cpp.

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

Print state to stdout for testing.

Definition at line 428 of file katetextfolding.cpp.

void Kate::TextFolding::ensureLineIsVisible ( int  line)

Ensure that a given line will be visible.

Potentially unfold recursively all folds hiding this line, else just returns.

Parameters
lineline to make visible

Definition at line 236 of file katetextfolding.cpp.

QJsonDocument Kate::TextFolding::exportFoldingRanges ( ) const

Return the current known folding ranges a QJsonDocument to store in configs.

Returns
current folds as variant list

Definition at line 683 of file katetextfolding.cpp.

KTextEditor::Range Kate::TextFolding::foldingRange ( qint64  id) const

Returns the folding range associated with id.

If id is not a valid id, the returned range matches KTextEditor::Range::invalid().

Note
This works for either persistent ranges or folded ranges. Note, that the highlighting does not add folds unless text is folded.
Returns
the folding range for id

Definition at line 115 of file katetextfolding.cpp.

void Kate::TextFolding::foldingRangesChanged ( )
signal

If the folding state of existing ranges changes or ranges are added/removed, this signal is emitted.

QVector< QPair< qint64, TextFolding::FoldingRangeFlags > > Kate::TextFolding::foldingRangesForParentRange ( qint64  parentRangeId = -1) const

Query child folding ranges for given range id.

To query the toplevel ranges pass id -1

Parameters
parentRangeIdid of parent range, pass -1 to query top level ranges
Returns
vector of id's + flags for child ranges

Definition at line 400 of file katetextfolding.cpp.

QVector< QPair< qint64, TextFolding::FoldingRangeFlags > > Kate::TextFolding::foldingRangesStartingOnLine ( int  line) const

Queries which folding ranges start at the given line and returns the id + flags for all of them.

Very fast if nothing is folded, else binary search.

Parameters
lineline to query starting folding ranges
Returns
vector of id's + flags

Definition at line 358 of file katetextfolding.cpp.

bool Kate::TextFolding::foldRange ( qint64  id)

Fold the given range.

Parameters
idid of the range to fold
Returns
success

Definition at line 125 of file katetextfolding.cpp.

void Kate::TextFolding::importFoldingRanges ( const QJsonDocument folds)

Import the folding ranges given as a QJsonDocument like read from configs.

Parameters
foldslist of folds to import

Definition at line 710 of file katetextfolding.cpp.

bool Kate::TextFolding::isLineVisible ( int  line,
qint64 *  foldedRangeId = nullptr 
) const

Query if a given line is visible.

Very fast, if nothing is folded, else does binary search log(n) for n == number of folded ranges

Parameters
linereal line to query
foldedRangeIdif the line is not visible and that pointer is not 0, will be filled with id of range hiding the line or -1
Returns
is that line visible?

Definition at line 211 of file katetextfolding.cpp.

int Kate::TextFolding::lineToVisibleLine ( int  line) const

Convert a text buffer line to a visible line number.

Very fast, if nothing is folded, else walks over all folded regions O(n) for n == number of folded ranges

Parameters
lineline index in the text buffer
Returns
index in visible lines

Definition at line 276 of file katetextfolding.cpp.

qint64 Kate::TextFolding::newFoldingRange ( const KTextEditor::Range range,
FoldingRangeFlags  flags = FoldingRangeFlags() 
)

Create a new folding range.

Parameters
rangefolding range
flagsinitial flags for the new folding range
Returns
on success, id of new range >= 0, else -1, we return no pointer as folding ranges might be auto-deleted internally! the ids are stable for one Kate::TextFolding, e.g. you can rely in unit tests that you get 0,1,.... for successfully created ranges!

Definition at line 72 of file katetextfolding.cpp.

bool Kate::TextFolding::unfoldRange ( qint64  id,
bool  remove = false 
)

Unfold the given range.

In addition it can be forced to remove the region, even if it is persistent.

Parameters
idid of the range to unfold
removeshould the range be removed from the folding after unfolding? ranges that are not persistent auto-remove themself on unfolding
Returns
success

Definition at line 144 of file katetextfolding.cpp.

int Kate::TextFolding::visibleLines ( ) const

Query number of visible lines.

Very fast, if nothing is folded, else walks over all folded regions O(n) for n == number of folded ranges

Definition at line 256 of file katetextfolding.cpp.

int Kate::TextFolding::visibleLineToLine ( int  visibleLine) const

Convert a visible line number to a line number in the text buffer.

Very fast, if nothing is folded, else walks over all folded regions O(n) for n == number of folded ranges

Parameters
visibleLinevisible line index
Returns
index in text buffer lines

Definition at line 317 of file katetextfolding.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Oct 28 2020 23:02:36 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.