• 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
katetextline.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_TEXTLINE_H
22 #define KATE_TEXTLINE_H
23 
24 #include <QtCore/QVector>
25 #include <QtCore/QString>
26 #include <QtCore/QSharedPointer>
27 
28 #include "katepartprivate_export.h"
29 
30 namespace Kate {
31 
37 class KATEPART_TESTS_EXPORT TextLineData {
41  friend class TextBlock;
42 
43  public:
47  typedef QVector<short> ContextStack;
48 
52  class Attribute {
53  public:
61  Attribute (int _offset = 0, int _length = 0, short _attributeValue = 0, short _foldingValue = 0)
62  : offset (_offset)
63  , length (_length)
64  , attributeValue (_attributeValue)
65  , foldingValue (_foldingValue)
66  {
67  }
68 
72  int offset;
73 
77  int length;
78 
82  short attributeValue;
83 
87  short foldingValue;
88  };
89 
93  enum Flags
94  {
95  flagHlContinue = 1,
96  flagAutoWrapped = 2,
97  flagFoldingStartAttribute = 4,
98  flagFoldingStartIndentation = 8,
99  flagLineModified = 16,
100  flagLineSavedOnDisk = 32
101  };
102 
106  TextLineData ();
107 
112  TextLineData (const QString &text);
113 
117  ~TextLineData ();
118 
123  const QString &text () const { return m_text; }
124 
129  int firstChar() const;
130 
135  int lastChar() const;
136 
143  int nextNonSpaceChar(int pos) const;
144 
151  int previousNonSpaceChar(int pos) const;
152 
159  inline QChar at (int column) const
160  {
161  if (column >= 0 && column < m_text.length())
162  return m_text[column];
163 
164  return QChar();
165  }
166 
172  inline QChar operator[](int column) const
173  {
174  if (column >= 0 && column < m_text.length())
175  return m_text[column];
176 
177  return QChar();
178  }
179 
180  inline void markAsModified(bool modified)
181  {
182  if (modified) {
183  m_flags |= flagLineModified;
184  m_flags &= (~flagLineSavedOnDisk);
185  } else {
186  m_flags &= (~flagLineModified);
187  }
188  }
189 
190  inline bool markedAsModified() const
191  {
192  return m_flags & flagLineModified;
193  }
194 
195  inline void markAsSavedOnDisk(bool savedOnDisk)
196  {
197  if (savedOnDisk) {
198  m_flags |= flagLineSavedOnDisk;
199  m_flags &= (~flagLineModified);
200  } else {
201  m_flags &= (~flagLineSavedOnDisk);
202  }
203  }
204 
205  inline bool markedAsSavedOnDisk() const
206  {
207  return m_flags & flagLineSavedOnDisk;
208  }
209 
214  bool markedAsFoldingStart() const
215  {
216  return m_flags & (flagFoldingStartAttribute | flagFoldingStartIndentation);
217  }
218 
222  void clearMarkedAsFoldingStart ()
223  {
224  m_flags &= ~(flagFoldingStartAttribute | flagFoldingStartIndentation);
225  }
226 
231  bool markedAsFoldingStartAttribute() const
232  {
233  return m_flags & flagFoldingStartAttribute;
234  }
235 
240  bool markedAsFoldingStartIndentation() const
241  {
242  return m_flags & flagFoldingStartIndentation;
243  }
244 
248  void markAsFoldingStartAttribute ()
249  {
250  clearMarkedAsFoldingStart ();
251  m_flags |= flagFoldingStartAttribute;
252  }
253 
257  void markAsFoldingStartIndentation ()
258  {
259  clearMarkedAsFoldingStart ();
260  m_flags |= flagFoldingStartIndentation;
261  }
262 
266  int length() const { return m_text.length(); }
267 
273  bool hlLineContinue () const { return m_flags & flagHlContinue; }
274 
280  bool isAutoWrapped () const { return m_flags & flagAutoWrapped; }
281 
286  const QString& string() const { return m_text; }
287 
294  QString string (int column, int length) const
295  { return m_text.mid(column, length); }
296 
301  QString leadingWhitespace() const;
302 
306  int indentDepth (int tabWidth) const;
307 
311  int toVirtualColumn (int column, int tabWidth) const;
312 
317  int fromVirtualColumn (int column, int tabWidth) const;
318 
322  int virtualLength (int tabWidth) const;
323 
328  bool matchesAt(int column, const QString& match) const;
329 
333  bool startsWith(const QString& match) const { return m_text.startsWith (match); }
334 
338  bool endsWith(const QString& match) const { return m_text.endsWith (match); }
339 
344  const ContextStack &contextStack () const { return m_contextStack; }
345 
350  void setContextStack (const ContextStack &val) { m_contextStack = val; }
351 
356  void addAttribute (const Attribute &attribute);
357 
361  void clearAttributes () { m_attributesList.clear (); }
362 
367  const QVector<Attribute> &attributesList () const { return m_attributesList; }
368 
376  short attribute (int pos) const
377  {
378  for (int i=0; i < m_attributesList.size(); ++i)
379  {
380  if (pos >= m_attributesList[i].offset && pos < (m_attributesList[i].offset + m_attributesList[i].length))
381  return m_attributesList[i].attributeValue;
382 
383  if (pos < m_attributesList[i].offset)
384  break;
385  }
386 
387  return 0;
388  }
389 
394  void setHlLineContinue (bool cont)
395  {
396  if (cont) m_flags = m_flags | flagHlContinue;
397  else m_flags = m_flags & ~ flagHlContinue;
398  }
399 
404  void setAutoWrapped (bool wrapped)
405  {
406  if (wrapped) m_flags = m_flags | flagAutoWrapped;
407  else m_flags = m_flags & ~ flagAutoWrapped;
408  }
409 
410  private:
416  QString &textReadWrite () { return m_text; }
417 
418  private:
422  QString m_text;
423 
427  QVector<Attribute> m_attributesList;
428 
432  ContextStack m_contextStack;
433 
437  unsigned int m_flags;
438 };
439 
443 typedef QSharedPointer<TextLineData> TextLine;
444 
445 }
446 
447 #endif
Kate::TextLineData::operator[]
QChar operator[](int column) const
Same as at().
Definition: katetextline.h:172
Kate::TextLineData::attribute
short attribute(int pos) const
Gets the attribute at the given position use KRenderer::attributes to get the KTextAttribute for this...
Definition: katetextline.h:376
Kate::TextLineData::isAutoWrapped
bool isAutoWrapped() const
Returns true, if the line was automagically wrapped, otherwise returns false.
Definition: katetextline.h:280
Kate::TextLineData::Attribute::Attribute
Attribute(int _offset=0, int _length=0, short _attributeValue=0, short _foldingValue=0)
Attribute constructor.
Definition: katetextline.h:61
Kate::TextLineData::Attribute
Attribute storage.
Definition: katetextline.h:52
Kate::TextLineData::ContextStack
QVector< short > ContextStack
Context stack.
Definition: katetextline.h:47
Kate::TextLineData::Attribute::foldingValue
short foldingValue
folding value (begin/end type)
Definition: katetextline.h:87
QChar
Kate::TextLineData::Attribute::length
int length
length
Definition: katetextline.h:77
KATEPART_TESTS_EXPORT
#define KATEPART_TESTS_EXPORT
Definition: katepartprivate_export.h:36
Kate::TextLineData::length
int length() const
Returns the line's length.
Definition: katetextline.h:266
Kate::TextLineData
Class representing a single text line.
Definition: katetextline.h:37
Kate::TextLineData::setHlLineContinue
void setHlLineContinue(bool cont)
set hl continue flag
Definition: katetextline.h:394
Kate::TextLineData::contextStack
const ContextStack & contextStack() const
context stack
Definition: katetextline.h:344
Kate::TextLineData::markedAsFoldingStart
bool markedAsFoldingStart() const
Is on this line a folding start?
Definition: katetextline.h:214
QSharedPointer< TextLineData >
Kate::TextLineData::markAsFoldingStartIndentation
void markAsFoldingStartIndentation()
Mark as folding start line of an indentation based folding.
Definition: katetextline.h:257
Kate::TextLineData::at
QChar at(int column) const
Returns the character at the given column.
Definition: katetextline.h:159
katepartprivate_export.h
Kate::TextLineData::attributesList
const QVector< Attribute > & attributesList() const
Accessor to attributes.
Definition: katetextline.h:367
Kate::TextLineData::markAsFoldingStartAttribute
void markAsFoldingStartAttribute()
Mark as folding start line of an attribute based folding.
Definition: katetextline.h:248
Kate::TextLineData::setContextStack
void setContextStack(const ContextStack &val)
Sets the syntax highlight context number.
Definition: katetextline.h:350
Kate::TextLineData::startsWith
bool startsWith(const QString &match) const
Returns true, if the line starts with match, otherwise returns false.
Definition: katetextline.h:333
QString
Kate::TextLineData::hlLineContinue
bool hlLineContinue() const
Returns true, if the line's hl-continue flag is set, otherwise returns false.
Definition: katetextline.h:273
Kate::TextLineData::Attribute::attributeValue
short attributeValue
attribute value (to encode type of this range)
Definition: katetextline.h:82
Kate::TextLineData::markAsModified
void markAsModified(bool modified)
Definition: katetextline.h:180
Kate::TextLineData::markedAsFoldingStartAttribute
bool markedAsFoldingStartAttribute() const
Is on this line a folding start per attribute?
Definition: katetextline.h:231
Kate::TextLineData::endsWith
bool endsWith(const QString &match) const
Returns true, if the line ends with match, otherwise returns false.
Definition: katetextline.h:338
QString::mid
QString mid(int position, int n) const
QVector< short >
Kate::TextLineData::clearMarkedAsFoldingStart
void clearMarkedAsFoldingStart()
Clear folding start status.
Definition: katetextline.h:222
Kate::TextLineData::markedAsFoldingStartIndentation
bool markedAsFoldingStartIndentation() const
Is on this line a folding start per indentation?
Definition: katetextline.h:240
Kate::TextLineData::markedAsSavedOnDisk
bool markedAsSavedOnDisk() const
Definition: katetextline.h:205
Kate::TextLine
QSharedPointer< TextLineData > TextLine
The normal world only accesses the text lines with shared pointers.
Definition: katetextline.h:443
Kate::TextLineData::Flags
Flags
Flags of TextLineData.
Definition: katetextline.h:93
Kate::TextLineData::Attribute::offset
int offset
offset
Definition: katetextline.h:72
Kate::TextLineData::string
const QString & string() const
Returns the complete text line (as a QString reference).
Definition: katetextline.h:286
Kate::TextLineData::setAutoWrapped
void setAutoWrapped(bool wrapped)
set auto-wrapped property
Definition: katetextline.h:404
Kate::TextLineData::text
const QString & text() const
Accessor to the text contained in this line.
Definition: katetextline.h:123
Kate::TextLineData::markAsSavedOnDisk
void markAsSavedOnDisk(bool savedOnDisk)
Definition: katetextline.h:195
Kate::TextLineData::string
QString string(int column, int length) const
Returns the substring with length beginning at the given column.
Definition: katetextline.h:294
Kate::TextLineData::clearAttributes
void clearAttributes()
Clear attributes of this line.
Definition: katetextline.h:361
Kate::TextLineData::markedAsModified
bool markedAsModified() const
Definition: katetextline.h:190
Kate::TextBlock
Class representing a text block.
Definition: katetextblock.h:42
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