aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/classview/classviewmanager.cpp
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@theqtcompany.com>2014-10-17 09:32:17 +0200
committerEike Ziller <eike.ziller@theqtcompany.com>2014-10-22 13:14:18 +0200
commit1d414e8dbdd407db27e44fc49a7739662636fe9c (patch)
tree20182e9d3d64e18f440f23769e4048f4b13a4b2b /src/plugins/classview/classviewmanager.cpp
parentce0fe84208b9eb402fecc9a7a58480357dc0a44b (diff)
ClassView: Simplify code
Change-Id: I7b69ff062222c44ac11c4961c3a221917df73df2 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
Diffstat (limited to 'src/plugins/classview/classviewmanager.cpp')
-rw-r--r--src/plugins/classview/classviewmanager.cpp61
1 files changed, 22 insertions, 39 deletions
diff --git a/src/plugins/classview/classviewmanager.cpp b/src/plugins/classview/classviewmanager.cpp
index f18202605a..56f6350b5e 100644
--- a/src/plugins/classview/classviewmanager.cpp
+++ b/src/plugins/classview/classviewmanager.cpp
@@ -443,51 +443,34 @@ void Manager::gotoLocation(const QString &fileName, int line, int column)
void Manager::gotoLocations(const QList<QVariant> &list)
{
QSet<SymbolLocation> locations = Utils::roleToLocations(list);
-
- if (locations.count() == 0)
+ if (locations.size() == 0)
return;
- QString fileName;
- int line = 0;
- int column = 0;
- bool currentPositionAvailable = false;
-
- // what is open now?
- if (IEditor *editor = EditorManager::currentEditor()) {
- // get current file name
- if (IDocument *document = editor->document())
- fileName = document->filePath();
+ // Default to first known location
+ SymbolLocation loc = *locations.constBegin();
- // if text file - what is current position?
- TextEditor::BaseTextEditor *textEditor = qobject_cast<TextEditor::BaseTextEditor *>(editor);
+ if (locations.size() > 1) {
+ // The symbol has multiple locations. Check if we are already at one location,
+ // and if so, cycle to the "next" one
+ auto textEditor = qobject_cast<TextEditor::BaseTextEditor *>(EditorManager::currentEditor());
if (textEditor) {
- // there is open currently text editor
- int position = textEditor->position();
- textEditor->convertPosition(position, &line, &column);
- currentPositionAvailable = true;
+ // check if current cursor position is a known location of the symbol
+ const QString fileName = textEditor->document()->filePath();
+ int line;
+ int column;
+ textEditor->convertPosition(textEditor->position(), &line, &column);
+ SymbolLocation current(fileName, line, column);
+ QSet<SymbolLocation>::const_iterator it = locations.find(current);
+ QSet<SymbolLocation>::const_iterator end = locations.constEnd();
+ if (it != end) {
+ // we already are at the symbol, cycle to next location
+ ++it;
+ if (it == end)
+ it = locations.begin();
+ loc = *it;
+ }
}
}
-
- // if there is something open - try to check, is it currently activated symbol?
- if (currentPositionAvailable) {
- SymbolLocation current(fileName, line, column);
- QSet<SymbolLocation>::const_iterator it = locations.find(current);
- QSet<SymbolLocation>::const_iterator end = locations.constEnd();
- // is it known location?
- if (it != end) {
- // found - do one additional step
- ++it;
- if (it == end)
- it = locations.begin();
- const SymbolLocation &found = *it;
- gotoLocation(found.fileName(), found.line(), found.column());
- return;
- }
- }
-
- // no success - open first item in the list
- const SymbolLocation loc = *locations.constBegin();
-
gotoLocation(loc.fileName(), loc.line(), loc.column());
}