forked from qt-creator/qt-creator
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: David Schulz <david.schulz@digia.com>
This commit is contained in:
committed by
David Schulz
parent
f4eabcfa0e
commit
a25d66a944
@@ -1871,7 +1871,7 @@ QList<IEditor*> EditorManager::visibleEditors() const
|
|||||||
do {
|
do {
|
||||||
if (view->currentEditor())
|
if (view->currentEditor())
|
||||||
editors.append(view->currentEditor());
|
editors.append(view->currentEditor());
|
||||||
view = d->m_splitter->findNextView(view);
|
view = view->findNextView();
|
||||||
} while (view && view != firstView);
|
} while (view && view != firstView);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -2224,9 +2224,7 @@ void EditorManager::gotoOtherSplit()
|
|||||||
splitSideBySide();
|
splitSideBySide();
|
||||||
|
|
||||||
EditorView *view = currentEditorView();
|
EditorView *view = currentEditorView();
|
||||||
view = d->m_splitter->findNextView(view);
|
view = view->findNextView();
|
||||||
if (!view)
|
|
||||||
view = d->m_splitter->findFirstView();
|
|
||||||
if (view) {
|
if (view) {
|
||||||
if (IEditor *editor = view->currentEditor()) {
|
if (IEditor *editor = view->currentEditor()) {
|
||||||
setCurrentEditor(editor, true);
|
setCurrentEditor(editor, true);
|
||||||
|
|||||||
@@ -124,6 +124,29 @@ SplitterOrView *EditorView::parentSplitterOrView() const
|
|||||||
return m_parentSplitterOrView;
|
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()
|
void EditorView::closeView()
|
||||||
{
|
{
|
||||||
EditorManager *em = ICore::editorManager();
|
EditorManager *em = ICore::editorManager();
|
||||||
@@ -527,38 +550,6 @@ SplitterOrView *SplitterOrView::findParentSplitter() const
|
|||||||
return 0;
|
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
|
QSize SplitterOrView::minimumSizeHint() const
|
||||||
{
|
{
|
||||||
if (m_splitter)
|
if (m_splitter)
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ public:
|
|||||||
virtual ~EditorView();
|
virtual ~EditorView();
|
||||||
|
|
||||||
SplitterOrView *parentSplitterOrView() const;
|
SplitterOrView *parentSplitterOrView() const;
|
||||||
|
EditorView *findNextView();
|
||||||
|
|
||||||
int editorCount() const;
|
int editorCount() const;
|
||||||
void addEditor(IEditor *editor);
|
void addEditor(IEditor *editor);
|
||||||
@@ -184,8 +185,6 @@ public:
|
|||||||
EditorView *findFirstView();
|
EditorView *findFirstView();
|
||||||
SplitterOrView *findParentSplitter() const;
|
SplitterOrView *findParentSplitter() const;
|
||||||
|
|
||||||
EditorView *findNextView(EditorView *view);
|
|
||||||
|
|
||||||
QSize sizeHint() const { return minimumSizeHint(); }
|
QSize sizeHint() const { return minimumSizeHint(); }
|
||||||
QSize minimumSizeHint() const;
|
QSize minimumSizeHint() const;
|
||||||
|
|
||||||
@@ -193,7 +192,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void unsplitAll_helper();
|
void unsplitAll_helper();
|
||||||
SplitterOrView *findNextView_helper(SplitterOrView *view, bool *found);
|
|
||||||
bool m_isRoot;
|
bool m_isRoot;
|
||||||
QStackedLayout *m_layout;
|
QStackedLayout *m_layout;
|
||||||
EditorView *m_view;
|
EditorView *m_view;
|
||||||
|
|||||||
Reference in New Issue
Block a user