Commit fd17d2f9 authored by Christian Kamm's avatar Christian Kamm
Browse files

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: default avatarRoberto Raggi <roberto.raggi@nokia.com>
parent dd1eaec0
......@@ -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();
}
}
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment