KTextEditor
smartrange.h
Go to the documentation of this file.
00001 /* This file is part of the KDE project 00002 Copyright (C) 2003-2005 Hamish Rodda <rodda@kde.org> 00003 Copyright (C) 2008 David Nolden <david.nolden.kdevelop@art-master.de> 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 version 2 as published by the Free Software Foundation. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #ifndef KDELIBS_KTEXTEDITOR_SMARTRANGE_H 00021 #define KDELIBS_KTEXTEDITOR_SMARTRANGE_H 00022 00023 #include <ktexteditor/ktexteditor_export.h> 00024 #include <ktexteditor/range.h> 00025 #include <ktexteditor/smartcursor.h> 00026 #include <ktexteditor/attribute.h> 00027 00028 #include <QtCore/QList> 00029 00030 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00031 template <class T> class QStack; 00032 #endif 00033 00034 class KAction; 00035 00036 namespace KTextEditor 00037 { 00038 class SmartRangeNotifier; 00039 class SmartRangeWatcher; 00040 00094 class KTEXTEDITOR_EXPORT SmartRange : public Range 00095 { 00096 friend class SmartCursor; 00097 00098 public: 00100 enum InsertBehavior { 00102 DoNotExpand = 0, 00104 ExpandLeft = 0x1, 00106 ExpandRight = 0x2 00107 }; 00108 Q_DECLARE_FLAGS(InsertBehaviors, InsertBehavior) 00109 00110 virtual ~SmartRange(); 00111 00115 virtual bool isSmartRange() const; 00116 00120 virtual SmartRange* toSmartRange() const; 00121 00134 virtual void setRange(const Range& range); 00135 00143 inline SmartCursor& smartStart() 00144 { return *static_cast<SmartCursor*>(m_start); } 00145 00153 inline const SmartCursor& smartStart() const 00154 { return *static_cast<const SmartCursor*>(m_start); } 00155 00163 inline SmartCursor& smartEnd() 00164 { return *static_cast<SmartCursor*>(m_end); } 00165 00173 inline const SmartCursor& smartEnd() const 00174 { return *static_cast<const SmartCursor*>(m_end); } 00175 00180 virtual bool confineToRange(const Range& range); 00181 00186 virtual bool expandToRange(const Range& range); 00187 00188 //BEGIN Functionality present from having this range associated with a Document 00203 Document* document() const; 00204 00211 virtual QStringList text(bool block = false) const; 00212 00220 virtual bool replaceText(const QStringList &text, bool block = false); 00221 00229 virtual bool removeText(bool block = false); 00230 //END 00231 00232 //BEGIN Behavior 00246 InsertBehaviors insertBehavior() const; 00247 00258 void setInsertBehavior(InsertBehaviors behavior); 00259 //END 00260 00261 //BEGIN Relationships to other ranges 00277 inline SmartRange* parentRange() const 00278 { return m_parentRange; } 00279 00294 virtual void setParentRange(SmartRange* r); 00295 00303 bool hasParent(SmartRange* parent) const; 00304 00310 inline int depth() const 00311 { return m_parentRange ? m_parentRange->depth() + 1 : 0; } 00312 00318 inline SmartRange* topParentRange() const 00319 { return parentRange() ? parentRange()->topParentRange() : const_cast<SmartRange*>(this); } 00320 00328 const QList<SmartRange*>& childRanges() const; 00329 00336 void clearChildRanges(); 00337 00342 void deleteChildRanges(); 00343 00348 void clearAndDeleteChildRanges(); 00349 00358 SmartRange* childBefore( const SmartRange * range ) const; 00359 00368 SmartRange* childAfter( const SmartRange * range ) const; 00369 00381 SmartRange* mostSpecificRange(const Range& input) const; 00382 00391 SmartRange* firstRangeContaining(const Cursor& pos) const; 00392 00412 SmartRange* deepestRangeContaining(const Cursor& pos, 00413 QStack<SmartRange*>* rangesEntered = 0L, 00414 QStack<SmartRange*>* rangesExited = 0L) const; 00415 00416 QList<SmartRange*> deepestRangesContaining(const Cursor& pos) const; 00417 00422 int overlapCount() const; 00423 //END 00424 00425 //BEGIN Arbitrary highlighting 00439 Attribute::Ptr attribute() const; 00440 00450 void setAttribute(Attribute::Ptr attribute); 00451 //END 00452 00453 //BEGIN Action binding 00472 void associateAction(KAction* action); 00473 00480 void dissociateAction(KAction* action); 00481 00487 const QList<KAction*>& associatedActions() const 00488 { return m_associatedActions; } 00489 00493 void clearAssociatedActions(); 00494 //END 00495 00496 //BEGIN Notification methods 00514 SmartRangeNotifier* primaryNotifier(); 00515 00520 const QList<SmartRangeNotifier*> notifiers() const; 00521 00529 void addNotifier(SmartRangeNotifier* notifier); 00530 00536 void removeNotifier(SmartRangeNotifier* notifier); 00537 00547 void deletePrimaryNotifier(); 00548 00556 const QList<SmartRangeWatcher*>& watchers() const; 00557 00567 void addWatcher(SmartRangeWatcher* watcher); 00568 00574 void removeWatcher(SmartRangeWatcher* watcher); 00576 //END 00577 00591 inline SmartRange& operator=(const SmartRange& rhs) 00592 { setRange(rhs); return *this; } 00593 00603 inline SmartRange& operator=(const Range& rhs) 00604 { setRange(rhs); return *this; } 00605 00606 protected: 00622 SmartRange(SmartCursor* start, SmartCursor* end, SmartRange* parent = 0L, InsertBehaviors insertBehavior = DoNotExpand); 00623 00632 virtual void rangeChanged(Cursor* cursor, const Range& from); 00633 00639 virtual void checkFeedback(); 00640 00646 virtual SmartRangeNotifier* createNotifier() = 0; 00647 00652 void rebuildChildStructure(); 00653 00654 private: 00659 SmartRange(const SmartRange&); 00660 00665 SmartRange* deepestRangeContainingInternal(const Cursor& pos, 00666 QStack<SmartRange*>* rangesEntered, 00667 QStack<SmartRange*>* rangesExited, 00668 bool first = false) const; 00669 00675 void insertChildRange(SmartRange* newChild); 00676 00682 void removeChildRange(SmartRange* newChild); 00683 00689 Attribute::Ptr m_attribute; 00690 00691 SmartRange* m_parentRange; 00692 00698 QList<SmartRange*> m_childRanges; 00699 00705 QList<KAction*> m_associatedActions; 00706 00712 QList<SmartRangeNotifier*> m_notifiers; 00713 00719 QList<SmartRangeWatcher*> m_watchers; 00720 00726 bool m_ownsAttribute :1; 00733 uchar m_overlapCount:6; 00734 }; 00735 00736 Q_DECLARE_OPERATORS_FOR_FLAGS(SmartRange::InsertBehaviors) 00737 00738 } 00739 00740 #endif 00741 00742 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE 4.6 API Reference