diff options
author | Roberto Raggi <roberto.raggi@nokia.com> | 2010-06-03 15:15:11 +0200 |
---|---|---|
committer | Roberto Raggi <roberto.raggi@nokia.com> | 2010-06-03 15:15:11 +0200 |
commit | bcf50a0a49371e3e3eb791b66d4d63bc217d110b (patch) | |
tree | b114eeaf52027ab957b9b103429af6e87d84ee50 /src/plugins/texteditor/quickfix.cpp | |
parent | 3d81ae8574b03301099428823627683f31811bfc (diff) | |
download | qt-creator-bcf50a0a49371e3e3eb791b66d4d63bc217d110b.tar.gz |
Generalized the quickfix collector.
Diffstat (limited to 'src/plugins/texteditor/quickfix.cpp')
-rw-r--r-- | src/plugins/texteditor/quickfix.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/plugins/texteditor/quickfix.cpp b/src/plugins/texteditor/quickfix.cpp index 48adec102a..2259a03a7d 100644 --- a/src/plugins/texteditor/quickfix.cpp +++ b/src/plugins/texteditor/quickfix.cpp @@ -36,6 +36,7 @@ #include <QtCore/QDebug> using TextEditor::QuickFixOperation; +using TextEditor::QuickFixCollector; QuickFixOperation::QuickFixOperation(TextEditor::BaseTextEditor *editor) : _editor(editor) @@ -166,3 +167,85 @@ void QuickFixOperation::perform() createChangeSet(); apply(); } + +QuickFixCollector::QuickFixCollector() + : _editable(0) +{ } + +QuickFixCollector::~QuickFixCollector() +{ } + +TextEditor::ITextEditable *QuickFixCollector::editor() const +{ return _editable; } + +int QuickFixCollector::startPosition() const +{ return _editable->position(); } + +bool QuickFixCollector::supportsEditor(TextEditor::ITextEditable *) +{ return true; } + +bool QuickFixCollector::triggersCompletion(TextEditor::ITextEditable *) +{ return false; } + +int QuickFixCollector::startCompletion(TextEditor::ITextEditable *editable) +{ + Q_ASSERT(editable != 0); + + _editable = editable; + + if (TextEditor::QuickFixState *state = initializeCompletion(editable)) { + TextEditor::BaseTextEditor *editor = qobject_cast<TextEditor::BaseTextEditor *>(editable->widget()); + Q_ASSERT(editor != 0); + + const QList<TextEditor::QuickFixOperation::Ptr> quickFixOperations = this->quickFixOperations(editor); + QMap<int, QList<TextEditor::QuickFixOperation::Ptr> > matchedOps; + + foreach (TextEditor::QuickFixOperation::Ptr op, quickFixOperations) { + op->setTextCursor(editor->textCursor()); + int priority = op->match(state); + if (priority != -1) + matchedOps[priority].append(op); + } + + QMapIterator<int, QList<TextEditor::QuickFixOperation::Ptr> > it(matchedOps); + it.toBack(); + if (it.hasPrevious()) { + it.previous(); + _quickFixes = it.value(); + } + + delete state; + + if (! _quickFixes.isEmpty()) + return editable->position(); + } + + return -1; +} + +void QuickFixCollector::completions(QList<TextEditor::CompletionItem> *quickFixItems) +{ + for (int i = 0; i < _quickFixes.size(); ++i) { + TextEditor::QuickFixOperation::Ptr op = _quickFixes.at(i); + + TextEditor::CompletionItem item(this); + item.text = op->description(); + item.data = QVariant::fromValue(i); + quickFixItems->append(item); + } +} + +void QuickFixCollector::complete(const TextEditor::CompletionItem &item) +{ + const int index = item.data.toInt(); + + if (index < _quickFixes.size()) { + TextEditor::QuickFixOperation::Ptr quickFix = _quickFixes.at(index); + quickFix->perform(); + } +} + +void QuickFixCollector::cleanup() +{ + _quickFixes.clear(); +} |