1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of Qt Creator. 7 ** 8 ** Commercial License Usage 9 ** Licensees holding valid commercial Qt licenses may use this file in 10 ** accordance with the commercial license agreement provided with the 11 ** Software or, alternatively, in accordance with the terms contained in 12 ** a written agreement between you and The Qt Company. For licensing terms 13 ** and conditions see https://www.qt.io/terms-conditions. For further 14 ** information use the contact form at https://www.qt.io/contact-us. 15 ** 16 ** GNU General Public License Usage 17 ** Alternatively, this file may be used under the terms of the GNU 18 ** General Public License version 3 as published by the Free Software 19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 ** included in the packaging of this file. Please review the following 21 ** information to ensure the GNU General Public License requirements will 22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 ** 24 ****************************************************************************/ 25 26 #include "senddocumenttracker.h" 27 28 #include <algorithm> 29 30 namespace CppTools { 31 setLastSentRevision(int revision)32void SendDocumentTracker::setLastSentRevision(int revision) 33 { 34 m_lastSentRevision = revision; 35 m_contentChangeStartPosition = std::numeric_limits<int>::max(); 36 } 37 lastSentRevision() const38int SendDocumentTracker::lastSentRevision() const 39 { 40 return m_lastSentRevision; 41 } 42 setLastCompletionPosition(int lastCompletionPosition)43void SendDocumentTracker::setLastCompletionPosition(int lastCompletionPosition) 44 { 45 m_lastCompletionPosition = lastCompletionPosition; 46 } 47 lastCompletionPosition() const48int SendDocumentTracker::lastCompletionPosition() const 49 { 50 return m_lastCompletionPosition; 51 } 52 applyContentChange(int startPosition)53void SendDocumentTracker::applyContentChange(int startPosition) 54 { 55 if (startPosition < m_lastCompletionPosition) 56 m_lastCompletionPosition = -1; 57 58 m_contentChangeStartPosition = std::min(startPosition, m_contentChangeStartPosition); 59 } 60 shouldSendCompletion(int newCompletionPosition) const61bool SendDocumentTracker::shouldSendCompletion(int newCompletionPosition) const 62 { 63 return m_lastCompletionPosition != newCompletionPosition; 64 } 65 shouldSendRevision(uint newRevision) const66bool SendDocumentTracker::shouldSendRevision(uint newRevision) const 67 { 68 return m_lastSentRevision != int(newRevision); 69 } 70 shouldSendRevisionWithCompletionPosition(int newRevision,int newCompletionPosition) const71bool SendDocumentTracker::shouldSendRevisionWithCompletionPosition(int newRevision, int newCompletionPosition) const 72 { 73 if (shouldSendRevision(newRevision)) 74 return changedBeforeCompletionPosition(newCompletionPosition); 75 76 return false; 77 } 78 changedBeforeCompletionPosition(int newCompletionPosition) const79bool SendDocumentTracker::changedBeforeCompletionPosition(int newCompletionPosition) const 80 { 81 return m_contentChangeStartPosition < newCompletionPosition; 82 } 83 84 } // namespace CppTools 85