Kate
katetextblock.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_TEXTBLOCK_H 00022 #define KATE_TEXTBLOCK_H 00023 00024 #include <QtCore/QVector> 00025 #include <QtCore/QSet> 00026 00027 #include "katepartprivate_export.h" 00028 #include <ktexteditor/cursor.h> 00029 #include "katetextline.h" 00030 00031 namespace Kate { 00032 00033 class TextBuffer; 00034 class TextCursor; 00035 class TextRange; 00036 00041 class KATEPART_TESTS_EXPORT TextBlock { 00042 friend class TextCursor; 00043 friend class TextRange; 00044 friend class TextBuffer; 00045 00046 public: 00052 TextBlock (TextBuffer *buffer, int startLine); 00053 00057 ~TextBlock (); 00058 00063 int startLine () const { return m_startLine; } 00064 00069 void setStartLine (int startLine); 00070 00076 TextLine line (int line) const; 00077 00082 void appendLine (TextLine line) { m_lines.append (line); } 00083 00088 int lines () const { return m_lines.size(); } 00089 00094 void text (QString &text) const; 00095 00101 void wrapLine (const KTextEditor::Cursor &position); 00102 00108 void unwrapLine (int line, TextBlock *previousBlock); 00109 00115 void insertText (const KTextEditor::Cursor &position, const QString &text); 00116 00122 void removeText (const KTextEditor::Range &range, QString &removedText); 00123 00128 void debugPrint (int blockIndex) const; 00129 00136 TextBlock *splitBlock (int fromLine); 00137 00142 void mergeBlock (TextBlock *targetBlock); 00143 00149 void deleteBlockContent (); 00150 00156 void clearBlockContent (TextBlock *targetBlock); 00157 00163 QList<QSet<TextRange*> > rangesForLine (int line) const { 00164 return QList<QSet<TextRange*> >() << m_uncachedRanges << cachedRangesForLine(line); 00165 } 00166 00172 bool containsRange (TextRange* range) const { 00173 return m_cachedLineForRanges.contains(range) || m_uncachedRanges.contains(range); 00174 } 00175 00176 private: 00182 void updateRange(TextRange* range); 00183 00188 void removeRange (TextRange* range); 00189 00196 QSet<TextRange*> cachedRangesForLine (int line) const { 00197 line -= m_startLine; 00198 if(line >= 0 && line < m_cachedRangesForLine.size()) 00199 return m_cachedRangesForLine[line]; 00200 else 00201 return QSet<TextRange*>(); 00202 } 00203 00204 private: 00208 TextBuffer *m_buffer; 00209 00213 QVector<Kate::TextLine> m_lines; 00214 00218 int m_startLine; 00219 00223 QSet<TextCursor *> m_cursors; 00224 00229 QVector<QSet<TextRange *> > m_cachedRangesForLine; 00230 00234 QHash<TextRange *, int> m_cachedLineForRanges; 00235 00239 QSet<TextRange *> m_uncachedRanges; 00240 }; 00241 00242 } 00243 00244 #endif
KDE 4.6 API Reference