File indexing completed on 2024-05-12 04:38:06

0001 /*
0002     SPDX-FileCopyrightText: 2010 David Nolden <david.nolden.kdevelop@art-master.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef KDEVPLATFORM_PERSISTENTMOVINGRANGE_H
0008 #define KDEVPLATFORM_PERSISTENTMOVINGRANGE_H
0009 
0010 #include <language/languageexport.h>
0011 
0012 #include <KTextEditor/Attribute>
0013 #include <KTextEditor/Range>
0014 
0015 #include <QExplicitlySharedDataPointer>
0016 
0017 namespace KDevelop {
0018 class IndexedString;
0019 class PersistentMovingRangePrivate;
0020 
0021 /**
0022  * A range object that is automatically adapted to all changes a user does to a document. The object
0023  * also survives when the document is opened or closed, as long as the document is only edited from within
0024  * the application.
0025  *
0026  * This object must only be used from within the foreground, or with the foreground lock held.
0027  *
0028  * @todo The implementation of this object is not finished yet, the range is only persistent until the
0029  *            document is closed/reloaded/cleared.
0030  * */
0031 
0032 class KDEVPLATFORMLANGUAGE_EXPORT PersistentMovingRange
0033     : public QSharedData
0034 {
0035 public:
0036     using Ptr = QExplicitlySharedDataPointer<PersistentMovingRange>;
0037 
0038     /**
0039      * Creates a new persistent moving range based on the current revision of the given document
0040      * */
0041     PersistentMovingRange(const KTextEditor::Range& range, const IndexedString& document, bool shouldExpand = false);
0042     ~PersistentMovingRange();
0043 
0044     PersistentMovingRange(const PersistentMovingRange&) = delete;
0045     PersistentMovingRange& operator=(const PersistentMovingRange& rhs) = delete;
0046 
0047     IndexedString document() const;
0048 
0049     /**
0050      * Returns the range in the current revision of the document
0051      */
0052 
0053     KTextEditor::Range range() const;
0054 
0055     /**
0056      * Changes the z-depth for highlighting (see KTextEditor::MovingRange)
0057      * */
0058     void setZDepth(float depth) const;
0059 
0060     /**
0061      * Returns the text contained by the range. Currently only works when the range is open in the editor.
0062      * */
0063     QString text() const;
0064 
0065     /**
0066      * Change the highlighting attribute.
0067      * */
0068     void setAttribute(const KTextEditor::Attribute::Ptr& attribute);
0069 
0070     /**
0071      * Whether this range is still valid. The range is invalidated if the document is changed externally,
0072      * as such a change can not be tracked correctly.
0073      * */
0074     bool valid() const;
0075 
0076 private:
0077     PersistentMovingRangePrivate* m_p;
0078 };
0079 }
0080 
0081 #endif // KDEVPLATFORM_PERSISTENTMOVINGRANGE_H