KTextEditor
smartrange.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef KDELIBS_KTEXTEDITOR_SMARTRANGE_H
00020 #define KDELIBS_KTEXTEDITOR_SMARTRANGE_H
00021
00022 #include <ktexteditor/ktexteditor_export.h>
00023 #include <ktexteditor/range.h>
00024 #include <ktexteditor/smartcursor.h>
00025 #include <ktexteditor/attribute.h>
00026
00027 #include <QtCore/QList>
00028
00029 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00030 template <class T> class QStack;
00031 #endif
00032
00033 class KAction;
00034
00035 namespace KTextEditor
00036 {
00037 class SmartRangeNotifier;
00038 class SmartRangeWatcher;
00039
00081 class KTEXTEDITOR_EXPORT SmartRange : public Range
00082 {
00083 friend class SmartCursor;
00084
00085 public:
00087 enum InsertBehavior {
00089 DoNotExpand = 0,
00091 ExpandLeft = 0x1,
00093 ExpandRight = 0x2
00094 };
00095 Q_DECLARE_FLAGS(InsertBehaviors, InsertBehavior)
00096
00097 virtual ~SmartRange();
00098
00102 virtual bool isSmartRange() const;
00103
00107 virtual SmartRange* toSmartRange() const;
00108
00121 virtual void setRange(const Range& range);
00122
00130 inline SmartCursor& smartStart()
00131 { return *static_cast<SmartCursor*>(m_start); }
00132
00140 inline const SmartCursor& smartStart() const
00141 { return *static_cast<const SmartCursor*>(m_start); }
00142
00150 inline SmartCursor& smartEnd()
00151 { return *static_cast<SmartCursor*>(m_end); }
00152
00160 inline const SmartCursor& smartEnd() const
00161 { return *static_cast<const SmartCursor*>(m_end); }
00162
00167 virtual bool confineToRange(const Range& range);
00168
00173 virtual bool expandToRange(const Range& range);
00174
00175
00190 Document* document() const;
00191
00198 virtual QStringList text(bool block = false) const;
00199
00207 virtual bool replaceText(const QStringList &text, bool block = false);
00208
00216 virtual bool removeText(bool block = false);
00217
00218
00219
00233 InsertBehaviors insertBehavior() const;
00234
00245 void setInsertBehavior(InsertBehaviors behavior);
00246
00247
00248
00264 inline SmartRange* parentRange() const
00265 { return m_parentRange; }
00266
00281 virtual void setParentRange(SmartRange* r);
00282
00290 bool hasParent(SmartRange* parent) const;
00291
00297 inline int depth() const
00298 { return m_parentRange ? m_parentRange->depth() + 1 : 0; }
00299
00305 inline SmartRange* topParentRange() const
00306 { return parentRange() ? parentRange()->topParentRange() : const_cast<SmartRange*>(this); }
00307
00315 const QList<SmartRange*>& childRanges() const;
00316
00323 void clearChildRanges();
00324
00329 void deleteChildRanges();
00330
00335 void clearAndDeleteChildRanges();
00336
00344 SmartRange* childBefore( const SmartRange * range ) const;
00345
00353 SmartRange* childAfter( const SmartRange * range ) const;
00354
00363 SmartRange* mostSpecificRange(const Range& input) const;
00364
00373 SmartRange* firstRangeContaining(const Cursor& pos) const;
00374
00391 SmartRange* deepestRangeContaining(const Cursor& pos,
00392 QStack<SmartRange*>* rangesEntered = 0L,
00393 QStack<SmartRange*>* rangesExited = 0L) const;
00394
00395
00396
00410 Attribute::Ptr attribute() const;
00411
00418 void setAttribute(Attribute::Ptr attribute);
00419
00420
00421
00440 void associateAction(KAction* action);
00441
00448 void dissociateAction(KAction* action);
00449
00455 const QList<KAction*>& associatedActions() const
00456 { return m_associatedActions; }
00457
00461 void clearAssociatedActions();
00462
00463
00464
00482 SmartRangeNotifier* primaryNotifier();
00483
00488 const QList<SmartRangeNotifier*> notifiers() const;
00489
00495 void addNotifier(SmartRangeNotifier* notifier);
00496
00502 void removeNotifier(SmartRangeNotifier* notifier);
00503
00513 void deletePrimaryNotifier();
00514
00522 const QList<SmartRangeWatcher*>& watchers() const;
00523
00531 void addWatcher(SmartRangeWatcher* watcher);
00532
00538 void removeWatcher(SmartRangeWatcher* watcher);
00540
00541
00555 inline SmartRange& operator=(const SmartRange& rhs)
00556 { setRange(rhs); return *this; }
00557
00567 inline SmartRange& operator=(const Range& rhs)
00568 { setRange(rhs); return *this; }
00569
00570 protected:
00585 SmartRange(SmartCursor* start, SmartCursor* end, SmartRange* parent = 0L, InsertBehaviors insertBehavior = DoNotExpand);
00586
00595 virtual void rangeChanged(Cursor* cursor, const Range& from);
00596
00602 virtual void checkFeedback();
00603
00609 virtual SmartRangeNotifier* createNotifier() = 0;
00610
00611 private:
00616 SmartRange(const SmartRange&);
00617
00622 SmartRange* deepestRangeContainingInternal(const Cursor& pos,
00623 QStack<SmartRange*>* rangesEntered,
00624 QStack<SmartRange*>* rangesExited,
00625 bool first = false) const;
00626
00632 void insertChildRange(SmartRange* newChild);
00633
00639 void removeChildRange(SmartRange* newChild);
00640
00646 Attribute::Ptr m_attribute;
00647
00653 SmartRange* m_parentRange;
00654
00660 QList<SmartRange*> m_childRanges;
00661
00667 QList<KAction*> m_associatedActions;
00668
00674 QList<SmartRangeNotifier*> m_notifiers;
00675
00681 QList<SmartRangeWatcher*> m_watchers;
00682
00688 bool m_ownsAttribute :1;
00689 };
00690
00691 Q_DECLARE_OPERATORS_FOR_FLAGS(SmartRange::InsertBehaviors)
00692
00693 }
00694
00695 #endif
00696
00697