1 /*
2     SPDX-FileCopyrightText: 2010 David Nolden <david.nolden.kdevelop@art-master.de>
3 
4     SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "persistentmovingrange.h"
8 #include "persistentmovingrangeprivate.h"
9 #include <interfaces/icore.h>
10 #include <util/foregroundlock.h>
11 
PersistentMovingRange(const KTextEditor::Range & range,const IndexedString & document,bool shouldExpand)12 KDevelop::PersistentMovingRange::PersistentMovingRange(const KTextEditor::Range& range, const IndexedString& document,
13                                                        bool shouldExpand)
14     : m_p(new PersistentMovingRangePrivate)
15 {
16     VERIFY_FOREGROUND_LOCKED;
17     m_p->m_range = range;
18     m_p->m_document = document;
19     m_p->m_shouldExpand = shouldExpand;
20 
21     m_p->connectTracker();
22 }
23 
document() const24 KDevelop::IndexedString KDevelop::PersistentMovingRange::document() const
25 {
26     return m_p->m_document;
27 }
28 
setZDepth(float depth) const29 void KDevelop::PersistentMovingRange::setZDepth(float depth) const
30 {
31     VERIFY_FOREGROUND_LOCKED;
32     m_p->m_zDepth = depth;
33 
34     if (m_p->m_movingRange)
35         m_p->m_movingRange->setZDepth(depth);
36 }
37 
~PersistentMovingRange()38 KDevelop::PersistentMovingRange::~PersistentMovingRange()
39 {
40     VERIFY_FOREGROUND_LOCKED;
41     if (m_p->m_movingRange)
42         delete m_p->m_movingRange;
43     delete m_p;
44 }
45 
range() const46 KTextEditor::Range KDevelop::PersistentMovingRange::range() const
47 {
48     VERIFY_FOREGROUND_LOCKED;
49 
50     m_p->updateRangeFromMoving();
51     return m_p->m_range;
52 }
53 
text() const54 QString KDevelop::PersistentMovingRange::text() const
55 {
56     VERIFY_FOREGROUND_LOCKED;
57 
58     if (m_p->m_movingRange)
59         return m_p->m_movingRange->document()->text(m_p->m_movingRange->toRange());
60 
61     return QString();
62 }
63 
valid() const64 bool KDevelop::PersistentMovingRange::valid() const
65 {
66     VERIFY_FOREGROUND_LOCKED;
67     return m_p->m_valid;
68 }
69 
setAttribute(const KTextEditor::Attribute::Ptr & attribute)70 void KDevelop::PersistentMovingRange::setAttribute(const KTextEditor::Attribute::Ptr& attribute)
71 {
72     VERIFY_FOREGROUND_LOCKED;
73     if (m_p->m_movingRange)
74         m_p->m_movingRange->setAttribute(attribute);
75 }
76