Commit 33c0570c authored by Eike Ziller's avatar Eike Ziller

Make editor views know their SplitterOrView

That gets rid of a whole lot recursive searching for
SplitterOrView *findView(EditorView *)

Change-Id: I4cba09d1e88ba99072a6585b17bce83ef4cad2aa
Reviewed-by: default avatarDavid Schulz <david.schulz@digia.com>
parent 56c873fd
......@@ -641,7 +641,7 @@ void EditorManager::closeView(Core::Internal::EditorView *view)
emptyView(view);
SplitterOrView *splitterOrView = d->m_splitter->findView(view);
SplitterOrView *splitterOrView = view->parentSplitterOrView();
Q_ASSERT(splitterOrView);
Q_ASSERT(splitterOrView->view() == view);
SplitterOrView *splitter = d->m_splitter->findSplitter(splitterOrView);
......
......@@ -58,8 +58,9 @@ using namespace Core::Internal;
// ================EditorView====================
EditorView::EditorView(QWidget *parent) :
EditorView::EditorView(SplitterOrView *parentSplitterOrView, QWidget *parent) :
QWidget(parent),
m_parentSplitterOrView(parentSplitterOrView),
m_toolBar(EditorManager::createToolBar(this)),
m_container(new QStackedWidget(this)),
m_infoBarDisplay(new InfoBarDisplay(this)),
......@@ -118,6 +119,10 @@ EditorView::~EditorView()
{
}
SplitterOrView *EditorView::parentSplitterOrView() const
{
return m_parentSplitterOrView;
}
void EditorView::closeView()
{
......@@ -236,18 +241,16 @@ void EditorView::listSelectionActivated(int index)
void EditorView::splitHorizontally()
{
EditorManager *editorManager = EditorManager::instance();
SplitterOrView *splitterOrView = editorManager->topSplitterOrView()->findView(this);
if (splitterOrView)
splitterOrView->split(Qt::Vertical);
if (m_parentSplitterOrView)
m_parentSplitterOrView->split(Qt::Vertical);
editorManager->updateActions();
}
void EditorView::splitVertically()
{
EditorManager *editorManager = EditorManager::instance();
SplitterOrView *splitterOrView = editorManager->topSplitterOrView()->findView(this);
if (splitterOrView)
splitterOrView->split(Qt::Horizontal);
if (m_parentSplitterOrView)
m_parentSplitterOrView->split(Qt::Horizontal);
editorManager->updateActions();
}
......@@ -258,6 +261,11 @@ void EditorView::closeSplit()
editorManager->updateActions();
}
void EditorView::setParentSplitterOrView(SplitterOrView *splitterOrView)
{
m_parentSplitterOrView = splitterOrView;
}
void EditorView::setCurrentEditor(IEditor *editor)
{
if (!editor || m_container->count() <= 0
......@@ -459,7 +467,7 @@ SplitterOrView::SplitterOrView(OpenEditorsModel *model)
Q_UNUSED(model); // For building in release mode.
m_isRoot = true;
m_layout = new QStackedLayout(this);
m_view = new EditorView();
m_view = new EditorView(this);
m_splitter = 0;
m_layout->addWidget(m_view);
}
......@@ -468,7 +476,7 @@ SplitterOrView::SplitterOrView(Core::IEditor *editor)
{
m_isRoot = false;
m_layout = new QStackedLayout(this);
m_view = new EditorView();
m_view = new EditorView(this);
if (editor)
m_view->addEditor(editor);
m_splitter = 0;
......@@ -535,20 +543,6 @@ SplitterOrView *SplitterOrView::findView(Core::IEditor *editor)
return 0;
}
SplitterOrView *SplitterOrView::findView(EditorView *view)
{
if (view == m_view)
return this;
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->findView(view))
return result;
}
}
return 0;
}
SplitterOrView *SplitterOrView::findSplitter(Core::IEditor *editor)
{
if (m_splitter) {
......@@ -625,8 +619,10 @@ QSplitter *SplitterOrView::takeSplitter()
EditorView *SplitterOrView::takeView()
{
EditorView *oldView = m_view;
if (m_view)
if (m_view) {
m_layout->removeWidget(m_view);
m_view->setParentSplitterOrView(0);
}
m_view = 0;
return oldView;
}
......@@ -736,6 +732,7 @@ void SplitterOrView::unsplit()
em->emptyView(childView);
} else {
m_view = childSplitterOrView->takeView();
m_view->setParentSplitterOrView(this);
m_layout->addWidget(m_view);
QSplitter *parentSplitter = qobject_cast<QSplitter *>(parentWidget());
if (parentSplitter) { // not the toplevel splitterOrView
......
......@@ -69,14 +69,18 @@ struct EditLocation {
QVariant state;
};
class SplitterOrView;
class EditorView : public QWidget
{
Q_OBJECT
public:
explicit EditorView(QWidget *parent = 0);
explicit EditorView(SplitterOrView *parentSplitterOrView, QWidget *parent = 0);
virtual ~EditorView();
SplitterOrView *parentSplitterOrView() const;
int editorCount() const;
void addEditor(IEditor *editor);
void removeEditor(IEditor *editor);
......@@ -106,10 +110,14 @@ private slots:
void closeSplit();
private:
friend class SplitterOrView; // for setParentSplitterOrView
void setParentSplitterOrView(SplitterOrView *splitterOrView);
void updateNavigatorActions();
void updateToolBar(IEditor *editor);
void checkProjectLoaded(IEditor *editor);
SplitterOrView *m_parentSplitterOrView;
EditorToolBar *m_toolBar;
QStackedWidget *m_container;
......@@ -173,7 +181,6 @@ public:
void restoreState(const QByteArray &);
SplitterOrView *findView(Core::IEditor *editor);
SplitterOrView *findView(EditorView *view);
SplitterOrView *findFirstView();
SplitterOrView *findEmptyView();
SplitterOrView *findSplitter(Core::IEditor *editor);
......
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