Skip to content

Commit

Permalink
(#539) When view is unlinked, ask user to keep either override or ori…
Browse files Browse the repository at this point in the history
…ginal range filter collection
  • Loading branch information
magnesj committed Oct 21, 2015
1 parent 065a688 commit 8de8100
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,17 @@ bool RicDeleteAllLinkedViewsFeature::isCommandEnabled()
void RicDeleteAllLinkedViewsFeature::onActionTriggered(bool isChecked)
{
RimProject* proj = RiaApplication::instance()->project();
if (proj->viewLinkerCollection()->viewLinker())

RimViewLinker* viewLinker = proj->viewLinkerCollection()->viewLinker();
if (viewLinker)
{
delete proj->viewLinkerCollection()->viewLinker();
// Remove the view linker object from the view linker collection
// viewLinkerCollection->viewLinker is a PdmChildField containing one RimViewLinker child object
proj->viewLinkerCollection->viewLinker.removeChildObject(viewLinker);

viewLinker->applyRangeFilterCollectionByUserChoice();

proj->viewLinkerCollection()->viewLinker = NULL;
delete viewLinker;

proj->uiCapability()->updateConnectedEditors();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,14 @@ void RicSetMasterViewFeature::onActionTriggered(bool isChecked)
RimProject* proj = RiaApplication::instance()->project();
RimViewLinker* viewLinker = proj->viewLinkerCollection()->viewLinker();

viewLinker->applyRangeFilterCollectionByUserChoice();

RimView* previousMasterView = viewLinker->masterView();

viewLinker->setMasterView(activeView);
viewLinker->updateDependentViews();

viewLinker->addDependentView(previousMasterView);


proj->viewLinkerCollection.uiCapability()->updateConnectedEditors();
proj->updateConnectedEditors();
Expand Down
3 changes: 2 additions & 1 deletion ApplicationCode/Commands/ViewLink/RicUnLinkViewFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ void RicUnLinkViewFeature::onActionTriggered(bool isChecked)
if (!activeView) return;

RimViewController* viewController = activeView->viewController();
caf::SelectionManager::instance()->setSelectedItem(viewController);
viewController->applyRangeFilterCollectionByUserChoice();

caf::SelectionManager::instance()->setSelectedItem(viewController);
caf::CmdFeature* feature = caf::CmdFeatureManager::instance()->getCommandFeature("RicDeleteItemFeature");
if (feature)
{
Expand Down
23 changes: 23 additions & 0 deletions ApplicationCode/ProjectDataModel/RimView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,3 +705,26 @@ RimCellRangeFilterCollection* RimView::overrideRangeFilterCollection()
return m_overrideRangeFilterCollection();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimView::replaceRangeFilterCollectionWithOverride()
{
RimCellRangeFilterCollection* overrideRfc = m_overrideRangeFilterCollection;
CVF_ASSERT(overrideRfc);

RimCellRangeFilterCollection* currentRfc = m_rangeFilterCollection;
if (currentRfc)
{
delete currentRfc;
}

// Must call removeChildObject() to make sure the object has no parent
// No parent is required when assigning a object into a field
m_overrideRangeFilterCollection.removeChildObject(overrideRfc);

m_rangeFilterCollection = overrideRfc;

this->uiCapability()->updateConnectedEditors();
}

1 change: 1 addition & 0 deletions ApplicationCode/ProjectDataModel/RimView.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class RimView : public caf::PdmObject

RimCellRangeFilterCollection* overrideRangeFilterCollection();
void setOverrideRangeFilterCollection(RimCellRangeFilterCollection* rfc);
void replaceRangeFilterCollectionWithOverride();

caf::PdmField< std::vector<int> > windowGeometry;

Expand Down
61 changes: 60 additions & 1 deletion ApplicationCode/ProjectDataModel/RimViewController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
#include "cafPdmUiTreeOrdering.h"
#include "RigCaseToCaseRangeFilterMapper.h"

#include <QMessageBox>

CAF_PDM_SOURCE_INIT(RimViewController, "ViewController");
//--------------------------------------------------------------------------------------------------
///
Expand Down Expand Up @@ -148,6 +150,11 @@ void RimViewController::fieldChangedByUi(const caf::PdmFieldHandle* changedField
{
if (changedField == &m_isActive)
{
if (!m_isActive)
{
applyRangeFilterCollectionByUserChoice();
}

updateOverrides();
updateResultColorsControl();
updateCameraLink();
Expand Down Expand Up @@ -176,6 +183,10 @@ void RimViewController::fieldChangedByUi(const caf::PdmFieldHandle* changedField
}
else if (changedField == &m_syncRangeFilters)
{
if (!m_syncRangeFilters)
{
applyRangeFilterCollectionByUserChoice();
}
updateOverrides();
}
else if (changedField == &m_syncPropertyFilters)
Expand Down Expand Up @@ -478,7 +489,6 @@ RimViewLinker* RimViewController::ownerViewLinker()
{
RimViewLinker* viewLinker = NULL;
this->firstAnchestorOrThisOfType(viewLinker);
CVF_ASSERT(viewLinker);

return viewLinker;
}
Expand Down Expand Up @@ -812,3 +822,52 @@ void RimViewController::updateRangeFilterOverrides(RimCellRangeFilter* changedRa

}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimViewController::applyRangeFilterCollectionByUserChoice()
{
if (!m_managedView->overrideRangeFilterCollection())
{
return;
}

bool restoreOriginal = askUserToRestoreOriginalRangeFilterCollection(m_managedView->name);
if (restoreOriginal)
{
m_managedView->setOverrideRangeFilterCollection(NULL);
}
else
{
m_managedView->replaceRangeFilterCollectionWithOverride();
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimViewController::askUserToRestoreOriginalRangeFilterCollection(const QString& viewName)
{
RimView* activeView = RiaApplication::instance()->activeReservoirView();

QMessageBox msgBox(activeView->viewer()->layoutWidget());
msgBox.setIcon(QMessageBox::Question);

QString questionText;
questionText = QString("The linked view named \"%1\" is about to be unlinked. The range filters can either restore the original or keep the current range filters based on the master view.").arg(viewName);

msgBox.setText(questionText);
msgBox.setInformativeText("Do you want to restore the original range filters?");
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);

int ret = msgBox.exec();
if (ret == QMessageBox::Yes)
{
return true;
}
else
{
return false;
}
}

4 changes: 4 additions & 0 deletions ApplicationCode/ProjectDataModel/RimViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class RimViewController : public caf::PdmObject
void updateDisplayNameAndIcon();

void updateRangeFilterOverrides(RimCellRangeFilter* changedRangeFilter);
void applyRangeFilterCollectionByUserChoice();


protected: // Pdm overridden methods
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
Expand All @@ -98,6 +100,8 @@ class RimViewController : public caf::PdmObject
RimGeoMechView* managedGeoView();
static void removeOverrides(RimView* view);

static bool askUserToRestoreOriginalRangeFilterCollection(const QString& viewName);

private:
caf::PdmField<QString> m_name;
caf::PdmPtrField<RimView*> m_managedView;
Expand Down
27 changes: 27 additions & 0 deletions ApplicationCode/ProjectDataModel/RimViewLinker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,14 @@ bool RimViewLinker::isActive()
RimViewLinkerCollection* viewLinkerCollection = NULL;
this->firstAnchestorOrThisOfType(viewLinkerCollection);

if (!viewLinkerCollection)
{
// This will happen when the all linked views are about to be deleted
// The viewLinker is taken out of the viewLinkerCollection, and no parent can be found
// See RicDeleteAllLinkedViewsFeature
return false;
}

return viewLinkerCollection->isActive();
}

Expand Down Expand Up @@ -614,3 +622,22 @@ void RimViewLinker::addViewControllers(caf::PdmUiTreeOrdering& uiTreeOrdering)
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimViewLinker::applyRangeFilterCollectionByUserChoice()
{
for (size_t j = 0; j < m_viewControllers.size(); j++)
{
m_viewControllers[j]->applyRangeFilterCollectionByUserChoice();
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimViewLinker::removeViewController(RimViewController* viewController)
{
m_viewControllers.removeChildObject(viewController);
}

2 changes: 2 additions & 0 deletions ApplicationCode/ProjectDataModel/RimViewLinker.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ class RimViewLinker : public caf::PdmObject

void addDependentView(RimView* view);
void updateDependentViews();
void removeViewController(RimViewController* viewController);

void updateCamera(RimView* sourceView);
void updateTimeStep(RimView* sourceView, int timeStep);
void updateScaleZ(RimView* sourceView, double scaleZ);

void updateCellResult();
void updateRangeFilters(RimCellRangeFilter* changedRangeFilter);
void applyRangeFilterCollectionByUserChoice();

void scheduleGeometryRegenForDepViews(RivCellSetEnum geometryType);
void scheduleCreateDisplayModelAndRedrawForDependentViews();
Expand Down
5 changes: 5 additions & 0 deletions ApplicationCode/ProjectDataModel/RimViewLinkerCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ void RimViewLinkerCollection::fieldChangedByUi(const caf::PdmFieldHandle* change
{
if (viewLinker())
{
if (!isActive)
{
viewLinker()->applyRangeFilterCollectionByUserChoice();
}

viewLinker()->updateDependentViews();
}
}
Expand Down
1 change: 1 addition & 0 deletions ApplicationCode/UserInterface/RiuViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ void RiuViewer::mouseReleaseEvent(QMouseEvent* event)
return;
}

event->accept();
m_viewerCommands->displayContextMenu(event);
return;
}
Expand Down
12 changes: 11 additions & 1 deletion ApplicationCode/UserInterface/RiuViewerCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,17 @@ void RiuViewerCommands::displayContextMenu(QMouseEvent* event)
}
}

menu.exec(event->globalPos());
if (menu.actions().size() > 0)
{
// event->accept();
QAction* act = menu.exec(event->globalPos());
/*
if (act)
{
cvf::Trace::show("Jadda");
}
*/
}
}

//--------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 8de8100

Please sign in to comment.