From fd17d2f98f9b3dca1122830f3680817a053e37be Mon Sep 17 00:00:00 2001
From: Christian Kamm <christian.d.kamm@nokia.com>
Date: Wed, 18 Nov 2009 11:10:50 +0100
Subject: [PATCH] QuickFixOperation: don't pass the text cursor in constructor
 and apply

Instead, reintroduce setTextCursor and let CPPQuickFixCollector
call it just before invoking apply.

Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
---
 src/plugins/cppeditor/cppquickfix.cpp | 18 ++++++++++--------
 src/plugins/cppeditor/cppquickfix.h   |  6 +++---
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/src/plugins/cppeditor/cppquickfix.cpp b/src/plugins/cppeditor/cppquickfix.cpp
index 11e9c221aef..984c9a265f5 100644
--- a/src/plugins/cppeditor/cppquickfix.cpp
+++ b/src/plugins/cppeditor/cppquickfix.cpp
@@ -96,9 +96,8 @@ protected:
 class HelloQuickFixOp: public QuickFixOperation
 {
 public:
-    HelloQuickFixOp(Document::Ptr doc, const Snapshot &snapshot,
-                    const QTextCursor &textCursor)
-        : QuickFixOperation(doc, snapshot, textCursor)
+    HelloQuickFixOp(Document::Ptr doc, const Snapshot &snapshot)
+        : QuickFixOperation(doc, snapshot)
     {}
 
     virtual QString description() const
@@ -106,7 +105,7 @@ public:
         return QLatin1String("Hello"); // ### tr?
     }
 
-    virtual void apply(QTextCursor)
+    virtual void apply()
     {
         // nothing to do.
     }
@@ -116,9 +115,8 @@ public:
 
 
 QuickFixOperation::QuickFixOperation(CPlusPlus::Document::Ptr doc,
-                                     const CPlusPlus::Snapshot &snapshot,
-                                     const QTextCursor &textCursor)
-    : _doc(doc), _snapshot(snapshot), _textCursor(textCursor)
+                                     const CPlusPlus::Snapshot &snapshot)
+    : _doc(doc), _snapshot(snapshot)
 { }
 
 QuickFixOperation::~QuickFixOperation()
@@ -127,6 +125,9 @@ QuickFixOperation::~QuickFixOperation()
 QTextCursor QuickFixOperation::textCursor() const
 { return _textCursor; }
 
+void QuickFixOperation::setTextCursor(const QTextCursor &cursor)
+{ _textCursor = cursor; }
+
 QTextCursor QuickFixOperation::cursor(AST *ast) const
 {
     TranslationUnit *unit = document()->translationUnit();
@@ -245,7 +246,8 @@ void CPPQuickFixCollector::complete(const TextEditor::CompletionItem &item)
 
     if (index < _quickFixes.size()) {
         QuickFixOperationPtr quickFix = _quickFixes.at(index);
-        quickFix->apply(_editor->textCursor());
+        quickFix->setTextCursor(_editor->textCursor());
+        quickFix->apply();
     }
 }
 
diff --git a/src/plugins/cppeditor/cppquickfix.h b/src/plugins/cppeditor/cppquickfix.h
index 5059a753ccf..eb62dbfc359 100644
--- a/src/plugins/cppeditor/cppquickfix.h
+++ b/src/plugins/cppeditor/cppquickfix.h
@@ -55,18 +55,18 @@ class QuickFixOperation
 
 public:
     QuickFixOperation(CPlusPlus::Document::Ptr doc,
-                      const CPlusPlus::Snapshot &snapshot,
-                      const QTextCursor &textCursor);
+                      const CPlusPlus::Snapshot &snapshot);
 
     virtual ~QuickFixOperation();
 
     virtual QString description() const = 0;
-    virtual void apply(QTextCursor tc) = 0;
+    virtual void apply() = 0;
 
     CPlusPlus::Document::Ptr document() const { return _doc; }
     CPlusPlus::Snapshot snapshot() const { return _snapshot; }
 
     QTextCursor textCursor() const;
+    void setTextCursor(const QTextCursor &cursor);
 
 protected:
     const CPlusPlus::Token &tokenAt(unsigned index) const;
-- 
GitLab