#1380 Major refactor of the management of views to fix the active view problem. Expect some trouble following this.

This commit is contained in:
Jacob Støren
2017-03-31 15:13:50 +02:00
parent a914e38d53
commit 442d9d2e41
14 changed files with 123 additions and 297 deletions
@@ -53,6 +53,7 @@ ${CEE_CURRENT_LIST_DIR}RiuCursors.cpp
${CEE_CURRENT_LIST_DIR}RiuDragDrop.cpp
${CEE_CURRENT_LIST_DIR}RiuFemResultTextBuilder.cpp
${CEE_CURRENT_LIST_DIR}RiuGeoQuestNavigation.cpp
${CEE_CURRENT_LIST_DIR}RiuInterfaceToViewWindow.cpp
${CEE_CURRENT_LIST_DIR}RiuLineSegmentQwtPlotCurve.cpp
${CEE_CURRENT_LIST_DIR}RiuMainPlotWindow.cpp
${CEE_CURRENT_LIST_DIR}RiuMainWindow.cpp
@@ -0,0 +1,19 @@
#include "RiuInterfaceToViewWindow.h"
#include <QWidget>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimViewWindow* RiuInterfaceToViewWindow::viewWindowFromWidget(QWidget* possibleViewWindowWidget)
{
auto interfaceToViewWindow = dynamic_cast<RiuInterfaceToViewWindow*>(possibleViewWindowWidget);
if ( interfaceToViewWindow )
{
return (interfaceToViewWindow->ownerViewWindow());
}
else
{
return nullptr;
}
}
@@ -19,6 +19,7 @@
#pragma once
class RimViewWindow;
class QWidget;
//==================================================================================================
//
@@ -29,5 +30,6 @@ class RiuInterfaceToViewWindow
{
public:
virtual RimViewWindow* ownerViewWindow() const = 0;
static RimViewWindow* viewWindowFromWidget( QWidget* possibleViewWindowWidget);
};
@@ -490,58 +490,13 @@ void RiuMainPlotWindow::slotSubWindowActivated(QMdiSubWindow* subWindow)
RimProject * proj = RiaApplication::instance()->project();
if (!proj) return;
// Select in Project Tree
RimViewWindow* viewWindow = RiuInterfaceToViewWindow::viewWindowFromWidget(subWindow->widget());
if (viewWindow)
{
RiuWellLogPlot* wellLogPlotViewer = dynamic_cast<RiuWellLogPlot*>(subWindow->widget());
if (wellLogPlotViewer)
{
RimWellLogPlot* wellLogPlot = wellLogPlotViewer->ownerPlotDefinition();
if (wellLogPlot != RiaApplication::instance()->activeWellLogPlot())
{
RiaApplication::instance()->setActiveWellLogPlot(wellLogPlot);
projectTreeView()->selectAsCurrentItem(wellLogPlot);
}
}
else
{
RiaApplication::instance()->setActiveWellLogPlot(NULL);
}
}
{
RiuSummaryQwtPlot* summaryPlotViewer = dynamic_cast<RiuSummaryQwtPlot*>(subWindow->widget());
if (summaryPlotViewer)
{
RimSummaryPlot* summaryPlot = summaryPlotViewer->ownerPlotDefinition();
if (summaryPlot != RiaApplication::instance()->activeSummaryPlot())
{
RiaApplication::instance()->setActiveSummaryPlot(summaryPlot);
projectTreeView()->selectAsCurrentItem(summaryPlot);
}
}
else
{
RiaApplication::instance()->setActiveSummaryPlot(NULL);
}
}
{
RiuWellAllocationPlot* wellAllocationPlotWidget = dynamic_cast<RiuWellAllocationPlot*>(subWindow->widget());
if (wellAllocationPlotWidget)
{
RimWellAllocationPlot* wellAllocationPlot = wellAllocationPlotWidget->ownerPlotDefinition();
if (wellAllocationPlot != RiaApplication::instance()->activeWellAllocationPlot())
{
RiaApplication::instance()->setActiveWellAllocationPlot(wellAllocationPlot);
projectTreeView()->selectAsCurrentItem(wellAllocationPlot);
}
}
else
{
RiaApplication::instance()->setActiveWellAllocationPlot(nullptr);
}
projectTreeView()->selectAsCurrentItem(viewWindow);
}
}
@@ -618,66 +573,28 @@ void RiuMainPlotWindow::selectedObjectsChanged()
if (!firstSelectedObject) return;
// Well log plot
bool isActiveObjectChanged = false;
RimWellLogPlot* selectedWellLogPlot = dynamic_cast<RimWellLogPlot*>(firstSelectedObject);
if (!selectedWellLogPlot)
RimViewWindow* selectedWindow = dynamic_cast<RimViewWindow*>(firstSelectedObject);
if (!selectedWindow)
{
firstSelectedObject->firstAncestorOrThisOfType(selectedWellLogPlot);
firstSelectedObject->firstAncestorOrThisOfType(selectedWindow);
}
if (selectedWellLogPlot)
// If we cant find the view window as an MDI sub window, we search higher in the
// project tree to find a possible parent view window that has.
if (selectedWindow && !findMdiSubWindow(selectedWindow->viewWidget()))
{
if (selectedWellLogPlot->viewWidget())
if (selectedWindow->parentField() && selectedWindow->parentField()->ownerObject())
{
setActiveViewer(selectedWellLogPlot->viewWidget());
selectedWindow->parentField()->ownerObject()->firstAncestorOrThisOfType(selectedWindow);
}
isActiveObjectChanged = true;
RiaApplication::instance()->setActiveWellLogPlot(selectedWellLogPlot);
}
// Summary plot
RimSummaryPlot* selectedSummaryPlot = dynamic_cast<RimSummaryPlot*>(firstSelectedObject);
if (!selectedSummaryPlot)
if (selectedWindow)
{
firstSelectedObject->firstAncestorOrThisOfType(selectedSummaryPlot);
}
if (selectedSummaryPlot)
{
if (selectedSummaryPlot->viewWidget())
if (selectedWindow->viewWidget())
{
setActiveViewer(selectedSummaryPlot->viewWidget());
setActiveViewer(selectedWindow->viewWidget());
}
isActiveObjectChanged = true;
RiaApplication::instance()->setActiveSummaryPlot(selectedSummaryPlot);
}
// Flow plot
RimWellAllocationPlot* wellAllocationPlot = dynamic_cast<RimWellAllocationPlot*>(firstSelectedObject);
if (!wellAllocationPlot)
{
firstSelectedObject->firstAncestorOrThisOfType(wellAllocationPlot);
}
if (wellAllocationPlot)
{
if (wellAllocationPlot->viewWidget())
{
setActiveViewer(wellAllocationPlot->viewWidget());
}
isActiveObjectChanged = true;
RiaApplication::instance()->setActiveWellAllocationPlot(wellAllocationPlot);
}
if (isActiveObjectChanged)
{
// The only way to get to this code is by selection change initiated from the project tree view
// As we are activating an MDI-window, the focus is given to this MDI-window
// Set focus back to the tree view to be able to continue keyboard tree view navigation
@@ -775,33 +692,12 @@ RimMdiWindowGeometry RiuMainPlotWindow::windowGeometryForViewer(QWidget* viewer)
QMdiSubWindow* mdiWindow = findMdiSubWindow(viewer);
if (mdiWindow)
{
return windowGeometryForWidget(mdiWindow);
return RiuMdiSubWindow::windowGeometryForWidget(mdiWindow);
}
RimMdiWindowGeometry geo;
return geo;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimMdiWindowGeometry RiuMainPlotWindow::windowGeometryForWidget(QWidget* widget)
{
RimMdiWindowGeometry geo;
if (widget)
{
geo.mainWindowID = 1;
geo.x = widget->pos().x();
geo.y = widget->pos().y();
geo.width = widget->size().width();
geo.height = widget->size().height();
geo.isMaximized = widget->isMaximized();
}
return geo;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -72,7 +72,6 @@ public:
void setExpanded(const caf::PdmUiItem* uiItem, bool expanded);
RimMdiWindowGeometry windowGeometryForViewer(QWidget* viewer) override;
RimMdiWindowGeometry windowGeometryForWidget(QWidget* widget);
void tileWindows();
bool isAnyMdiSubWindowVisible();
@@ -1640,33 +1640,13 @@ RimMdiWindowGeometry RiuMainWindow::windowGeometryForViewer(QWidget* viewer)
QMdiSubWindow* mdiWindow = findMdiSubWindow(viewer);
if (mdiWindow)
{
return windowGeometryForWidget(mdiWindow);
return RiuMdiSubWindow::windowGeometryForWidget(mdiWindow);
}
RimMdiWindowGeometry geo;
return geo;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimMdiWindowGeometry RiuMainWindow::windowGeometryForWidget(QWidget* widget)
{
RimMdiWindowGeometry geo;
if (widget)
{
geo.mainWindowID = 0;
geo.x = widget->pos().x();
geo.y = widget->pos().y();
geo.width = widget->size().width();
geo.height = widget->size().height();
geo.isMaximized = widget->isMaximized();
}
return geo;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -105,7 +105,6 @@ public:
void setExpanded(const caf::PdmUiItem* uiItem, bool expanded);
RimMdiWindowGeometry windowGeometryForViewer(QWidget* viewer);
RimMdiWindowGeometry windowGeometryForWidget(QWidget* widget);
void tileWindows();
bool isAnyMdiSubWindowVisible();
@@ -53,30 +53,58 @@ void RiuMdiSubWindow::closeEvent(QCloseEvent* event)
{
QWidget* mainWidget = widget();
RiuWellLogPlot* wellLogPlot = dynamic_cast<RiuWellLogPlot*>(mainWidget);
RiuSummaryQwtPlot* summaryPlot = dynamic_cast<RiuSummaryQwtPlot*>(mainWidget);
if (wellLogPlot)
RimViewWindow* viewWindow = RiuInterfaceToViewWindow::viewWindowFromWidget(mainWidget);
if ( viewWindow )
{
RiuMainPlotWindow* mainPlotWindow = RiaApplication::instance()->mainPlotWindow();
CVF_ASSERT(mainPlotWindow);
wellLogPlot->ownerPlotDefinition()->setMdiWindowGeometry(mainPlotWindow->windowGeometryForWidget(this));
}
else if (summaryPlot)
{
RiuMainPlotWindow* mainPlotWindow = RiaApplication::instance()->mainPlotWindow();
CVF_ASSERT(mainPlotWindow);
summaryPlot->ownerPlotDefinition()->setMdiWindowGeometry(mainPlotWindow->windowGeometryForWidget(this));
viewWindow->setMdiWindowGeometry(windowGeometryForWidget(this));
}
else
{
RiuViewer* viewer = mainWidget->findChild<RiuViewer*>();
if (viewer)
{
viewer->ownerReservoirView()->setMdiWindowGeometry(RiuMainWindow::instance()->windowGeometryForWidget(this));
viewer->ownerReservoirView()->setMdiWindowGeometry(windowGeometryForWidget(this));
}
}
QMdiSubWindow::closeEvent(event);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimMdiWindowGeometry RiuMdiSubWindow::windowGeometryForWidget(QWidget* widget)
{
RimMdiWindowGeometry geo;
// Find topmost parent
QWidget* nextParent = widget->parentWidget();
QWidget* parent = nullptr;
while(nextParent)
{
parent = nextParent;
nextParent = nextParent->parentWidget();
}
int mainWinID = 0;
if (parent)
{
if (parent == RiaApplication::instance()->mainPlotWindow())
{
mainWinID = 1;
}
}
QMdiSubWindow::closeEvent(event);
if (widget)
{
geo.mainWindowID = mainWinID;
geo.x = widget->pos().x();
geo.y = widget->pos().y();
geo.width = widget->size().width();
geo.height = widget->size().height();
geo.isMaximized = widget->isMaximized();
}
return geo;
}
@@ -19,6 +19,7 @@
#pragma once
#include <QMdiSubWindow>
#include "RimViewWindow.h"
class RiuMdiSubWindow : public QMdiSubWindow
@@ -28,6 +29,8 @@ public:
~RiuMdiSubWindow();
static RimMdiWindowGeometry windowGeometryForWidget(QWidget* widget);
protected:
virtual void closeEvent(QCloseEvent* event);
};