Commit a25d66a9 authored by Eike Ziller's avatar Eike Ziller Committed by David Schulz

EditorManager: Get rid of weird logic when finding next view

Removes another algorithm that was starting from the root and took the
whole tree into account.
Instead, make findNextView a method of EditorView, and avoid any
explicit usage of a single root splitter.

Change-Id: I343030521472741a8dfd7134ed16d9beeb10d10a
Reviewed-by: default avatarDavid Schulz <david.schulz@digia.com>
parent f4eabcfa
......@@ -1871,7 +1871,7 @@ QList<IEditor*> EditorManager::visibleEditors() const
do {
if (view->currentEditor())
editors.append(view->currentEditor());
view = d->m_splitter->findNextView(view);
view = view->findNextView();
} while (view && view != firstView);
}
} else {
......@@ -2224,9 +2224,7 @@ void EditorManager::gotoOtherSplit()
splitSideBySide();
EditorView *view = currentEditorView();
view = d->m_splitter->findNextView(view);
if (!view)
view = d->m_splitter->findFirstView();
view = view->findNextView();
if (view) {
if (IEditor *editor = view->currentEditor()) {
setCurrentEditor(editor, true);
......
......@@ -124,6 +124,29 @@ SplitterOrView *EditorView::parentSplitterOrView() const
return m_parentSplitterOrView;
}
EditorView *EditorView::findNextView()
{
SplitterOrView *current = parentSplitterOrView();
QTC_ASSERT(current, return this);
SplitterOrView *parent = current->findParentSplitter();
while (parent) {
QSplitter *splitter = parent->splitter();
QTC_ASSERT(splitter, return this);
QTC_ASSERT(splitter->count() == 2, return this);
// is current the first child? then the next view is the first one in current's sibling
if (splitter->widget(0) == current) {
SplitterOrView *second = qobject_cast<SplitterOrView *>(splitter->widget(1));
QTC_ASSERT(second, return this);
return second->findFirstView();
}
// otherwise go up the hierarchy
current = parent;
parent = current->findParentSplitter();
}
// current has no parent, so just take the very first view
return current->findFirstView();
}
void EditorView::closeView()
{
EditorManager *em = ICore::editorManager();
......@@ -527,38 +550,6 @@ SplitterOrView *SplitterOrView::findParentSplitter() const
return 0;
}
EditorView *SplitterOrView::findNextView(EditorView *view)
{
if (!view)
return 0;
bool found = false;
SplitterOrView *splitterOrView = findNextView_helper(view->parentSplitterOrView(), &found);
if (splitterOrView)
return splitterOrView->view();
return 0;
}
SplitterOrView *SplitterOrView::findNextView_helper(SplitterOrView *view, bool *found)
{
if (*found && m_view)
return this;
if (this == view) {
*found = true;
return 0;
}
if (m_splitter) {
for (int i = 0; i < m_splitter->count(); ++i) {
if (SplitterOrView *splitterOrView = qobject_cast<SplitterOrView*>(m_splitter->widget(i))) {
if (SplitterOrView *result = splitterOrView->findNextView_helper(view, found))
return result;
}
}
}
return 0;
}
QSize SplitterOrView::minimumSizeHint() const
{
if (m_splitter)
......
......@@ -80,6 +80,7 @@ public:
virtual ~EditorView();
SplitterOrView *parentSplitterOrView() const;
EditorView *findNextView();
int editorCount() const;
void addEditor(IEditor *editor);
......@@ -184,8 +185,6 @@ public:
EditorView *findFirstView();
SplitterOrView *findParentSplitter() const;
EditorView *findNextView(EditorView *view);
QSize sizeHint() const { return minimumSizeHint(); }
QSize minimumSizeHint() const;
......@@ -193,7 +192,6 @@ public:
private:
void unsplitAll_helper();
SplitterOrView *findNextView_helper(SplitterOrView *view, bool *found);
bool m_isRoot;
QStackedLayout *m_layout;
EditorView *m_view;
......
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