#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:10:39 +02:00
parent a914e38d53
commit 442d9d2e41
14 changed files with 123 additions and 297 deletions

View File

@ -1116,6 +1116,25 @@ RimView* RiaApplication::activeReservoirView()
return m_activeReservoirView;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimViewWindow* RiaApplication::activePlotWindow() const
{
RimViewWindow* viewWindow = nullptr;
if ( m_mainPlotWindow )
{
QList<QMdiSubWindow*> subwindows = m_mainPlotWindow->subWindowList(QMdiArea::StackingOrder);
if ( subwindows.size() > 0 )
{
viewWindow = RiuInterfaceToViewWindow::viewWindowFromWidget(subwindows.back()->widget());
}
}
return viewWindow;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -1124,54 +1143,6 @@ void RiaApplication::setActiveReservoirView(RimView* rv)
m_activeReservoirView = rv;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication::setActiveWellLogPlot(RimWellLogPlot* wlp)
{
m_activeWellLogPlot = wlp;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWellLogPlot* RiaApplication::activeWellLogPlot()
{
return m_activeWellLogPlot;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication::setActiveSummaryPlot(RimSummaryPlot* sp)
{
m_activeSummaryPlot = sp;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSummaryPlot* RiaApplication::activeSummaryPlot()
{
return m_activeSummaryPlot;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication::setActiveWellAllocationPlot(RimWellAllocationPlot* wap)
{
m_activeWellAllocationPlot = wap;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWellAllocationPlot* RiaApplication::activeWellAllocationPlot()
{
return m_activeWellAllocationPlot;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -1620,42 +1591,20 @@ RimViewWindow* RiaApplication::activeViewWindow()
{
RimViewWindow* viewWindow = NULL;
QWidget* topLevelWidget = RiaApplication::activeWindow();
QWidget* mainWindowWidget = RiaApplication::activeWindow();
if (dynamic_cast<RiuMainWindow*>(topLevelWidget))
if (dynamic_cast<RiuMainWindow*>(mainWindowWidget))
{
viewWindow = RiaApplication::instance()->activeReservoirView();
}
if (dynamic_cast<RiuMainPlotWindow*>(topLevelWidget))
else if (dynamic_cast<RiuMainPlotWindow*>(mainWindowWidget))
{
RiuMainPlotWindow* mainPlotWindow = dynamic_cast<RiuMainPlotWindow*>(topLevelWidget);
RiuMainPlotWindow* mainPlotWindow = dynamic_cast<RiuMainPlotWindow*>(mainWindowWidget);
QList<QMdiSubWindow*> subwindows = mainPlotWindow->subWindowList(QMdiArea::StackingOrder);
if (subwindows.size() > 0)
{
RiuSummaryQwtPlot* summaryQwtPlot = dynamic_cast<RiuSummaryQwtPlot*>(subwindows.back()->widget());
if (summaryQwtPlot)
{
viewWindow = summaryQwtPlot->ownerPlotDefinition();
}
RiuWellLogPlot* wellLogPlot = dynamic_cast<RiuWellLogPlot*>(subwindows.back()->widget());
if (wellLogPlot)
{
viewWindow = wellLogPlot->ownerPlotDefinition();
}
RiuWellAllocationPlot* wellAllocationPlot = dynamic_cast<RiuWellAllocationPlot*>(subwindows.back()->widget());
if (wellAllocationPlot)
{
viewWindow = wellAllocationPlot->ownerPlotDefinition();
}
RiuFlowCharacteristicsPlot* flowCharacteristicsPlot = dynamic_cast<RiuFlowCharacteristicsPlot*>(subwindows.back()->widget());
if (flowCharacteristicsPlot)
{
viewWindow = flowCharacteristicsPlot->ownerPlotDefinition();
}
viewWindow = RiuInterfaceToViewWindow::viewWindowFromWidget(subwindows.back()->widget());
}
}

View File

@ -96,14 +96,7 @@ public:
RimView* activeReservoirView();
const RimView* activeReservoirView() const;
void setActiveWellLogPlot(RimWellLogPlot*);
RimWellLogPlot* activeWellLogPlot();
void setActiveSummaryPlot(RimSummaryPlot*);
RimSummaryPlot* activeSummaryPlot();
void setActiveWellAllocationPlot(RimWellAllocationPlot*);
RimWellAllocationPlot* activeWellAllocationPlot();
RimViewWindow* activePlotWindow() const;
void scheduleDisplayModelUpdateAndRedraw(RimView* resViewToUpdate);
@ -228,9 +221,6 @@ private slots:
private:
caf::PdmPointer<RimView> m_activeReservoirView;
caf::PdmPointer<RimWellLogPlot> m_activeWellLogPlot;
caf::PdmPointer<RimSummaryPlot> m_activeSummaryPlot;
caf::PdmPointer<RimWellAllocationPlot> m_activeWellAllocationPlot;
caf::PdmPointer<RimProject> m_project;

View File

@ -35,7 +35,8 @@ CAF_CMD_SOURCE_INIT(RicShowContributingWellsFromPlotFeature, "RicShowContributin
//--------------------------------------------------------------------------------------------------
bool RicShowContributingWellsFromPlotFeature::isCommandEnabled()
{
RimWellAllocationPlot* wellAllocationPlot = RiaApplication::instance()->activeWellAllocationPlot();
RimWellAllocationPlot* wellAllocationPlot = dynamic_cast<RimWellAllocationPlot*>(RiaApplication::instance()->activePlotWindow());
if (wellAllocationPlot) return true;
return false;
@ -46,7 +47,8 @@ bool RicShowContributingWellsFromPlotFeature::isCommandEnabled()
//--------------------------------------------------------------------------------------------------
void RicShowContributingWellsFromPlotFeature::onActionTriggered(bool isChecked)
{
RimWellAllocationPlot* wellAllocationPlot = RiaApplication::instance()->activeWellAllocationPlot();
RimWellAllocationPlot* wellAllocationPlot = dynamic_cast<RimWellAllocationPlot*>(RiaApplication::instance()->activePlotWindow());
if (!wellAllocationPlot) return;
int timeStep = wellAllocationPlot->timeStep();

View File

@ -101,7 +101,7 @@ RimSummaryPlot* RicNewGridTimeHistoryCurveFeature::userSelectedSummaryPlot()
if (!defaultSelectedPlot)
{
defaultSelectedPlot = RiaApplication::instance()->activeSummaryPlot();
defaultSelectedPlot = dynamic_cast<RimSummaryPlot*>( RiaApplication::instance()->activePlotWindow() );
}
if (!defaultSelectedPlot && summaryPlotColl->summaryPlots().size() > 0)

View File

@ -66,53 +66,11 @@ void RicViewZoomAllFeature::onActionTriggered(bool isChecked)
QList<QMdiSubWindow*> subwindows = mainPlotWindow->subWindowList(QMdiArea::StackingOrder);
if (subwindows.size() > 0)
{
RimViewWindow* viewWindow = RiuInterfaceToViewWindow::viewWindowFromWidget(subwindows.back()->widget());
if (viewWindow)
{
RiuSummaryQwtPlot* summaryQwtPlot = dynamic_cast<RiuSummaryQwtPlot*>(subwindows.back()->widget());
if (summaryQwtPlot)
{
RimViewWindow* viewWindow = summaryQwtPlot->ownerPlotDefinition();
viewWindow->zoomAll();
summaryQwtPlot->replot();
return;
}
}
{
RiuWellLogPlot* wellLogPlot = dynamic_cast<RiuWellLogPlot*>(subwindows.back()->widget());
if (wellLogPlot)
{
RimViewWindow* viewWindow = wellLogPlot->ownerPlotDefinition();
viewWindow->zoomAll();
wellLogPlot->update();
return;
}
}
{
RiuWellAllocationPlot* wellAllocationPlot = dynamic_cast<RiuWellAllocationPlot*>(subwindows.back()->widget());
if (wellAllocationPlot)
{
RimWellAllocationPlot* viewWindow = wellAllocationPlot->ownerPlotDefinition();
viewWindow->zoomAll();
wellAllocationPlot->update();
return;
}
}
{
RiuFlowCharacteristicsPlot* flowCharPlot = dynamic_cast<RiuFlowCharacteristicsPlot*>(subwindows.back()->widget());
if (flowCharPlot)
{
RimFlowCharacteristicsPlot* viewWindow = flowCharPlot->ownerPlotDefinition();
viewWindow->zoomAll();
flowCharPlot->update();
return;
}
viewWindow->zoomAll();
}
}
}

View File

@ -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

View File

@ -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;
}
}

View File

@ -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);
};

View File

@ -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;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -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();

View File

@ -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;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -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();

View File

@ -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;
}

View File

@ -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);
};