#4166 Add feature for swapping cross plot axes + tweaks to legend

* Also put x and y property side by side in property editor
This commit is contained in:
Gaute Lindkvist 2019-03-08 09:59:29 +01:00
parent 1e777eaea0
commit e00f983360
16 changed files with 210 additions and 35 deletions

View File

@ -2,11 +2,13 @@
set (SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RicCreateGridCrossPlotFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicCreateGridCrossPlotCurveSetFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicSwapGridCrossPlotCurveSetAxesFeature.h
)
set (SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RicCreateGridCrossPlotFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicCreateGridCrossPlotCurveSetFeature.cpp)
${CMAKE_CURRENT_LIST_DIR}/RicCreateGridCrossPlotCurveSetFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicSwapGridCrossPlotCurveSetAxesFeature.cpp)
list(APPEND CODE_HEADER_FILES
${SOURCE_GROUP_HEADER_FILES}

View File

@ -19,8 +19,6 @@
#include "cafCmdFeature.h"
#include <vector>
//==================================================================================================
///
//==================================================================================================

View File

@ -0,0 +1,61 @@
#include "RicSwapGridCrossPlotCurveSetAxesFeature.h"
#include "RimGridCrossPlot.h"
#include "RimGridCrossPlotCurveSet.h"
#include <cafSelectionManager.h>
#include <QAction>
CAF_CMD_SOURCE_INIT(RicSwapGridCrossPlotCurveSetAxesFeature, "RicSwapGridCrossPlotCurveSetAxesFeature");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicSwapGridCrossPlotCurveSetAxesFeature::isCommandEnabled()
{
if (caf::SelectionManager::instance()->selectedItemOfType<RimGridCrossPlotCurveSet>())
{
return true;
}
else if (caf::SelectionManager::instance()->selectedItemOfType<RimGridCrossPlot>())
{
auto plot = caf::SelectionManager::instance()->selectedItemOfType<RimGridCrossPlot>();
if (!plot->curveSets().empty())
return true;
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSwapGridCrossPlotCurveSetAxesFeature::onActionTriggered(bool isChecked)
{
if (caf::SelectionManager::instance()->selectedItemOfType<RimGridCrossPlotCurveSet>())
{
auto curveSet = caf::SelectionManager::instance()->selectedItemOfType<RimGridCrossPlotCurveSet>();
curveSet->swapAxisProperties(true);
}
else if (caf::SelectionManager::instance()->selectedItemOfType<RimGridCrossPlot>())
{
auto plot = caf::SelectionManager::instance()->selectedItemOfType<RimGridCrossPlot>();
plot->swapAllAxisProperties();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSwapGridCrossPlotCurveSetAxesFeature::setupActionLook(QAction* actionToSetup)
{
if (caf::SelectionManager::instance()->selectedItemOfType<RimGridCrossPlotCurveSet>())
{
actionToSetup->setText("Swap Axis Properties");
}
else
{
actionToSetup->setText("Swap Axis Properties for all Data Sets in Plot");
}
actionToSetup->setIcon(QIcon(":/Swap.png"));
}

View File

@ -0,0 +1,38 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2019- Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafCmdFeature.h"
//==================================================================================================
///
//==================================================================================================
class RicSwapGridCrossPlotCurveSetAxesFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
bool isCommandEnabled() override;
void onActionTriggered(bool isChecked) override;
void setupActionLook(QAction* actionToSetup) override;
};

View File

@ -487,6 +487,7 @@ void RimGridCrossPlot::updatePlot()
{
m_qwtPlot->insertLegend(nullptr);
}
m_qwtPlot->updateLegendSizesToMatchPlot();
m_qwtPlot->replot();
}
}
@ -507,6 +508,18 @@ void RimGridCrossPlot::updateCurveNamesAndPlotTitle()
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGridCrossPlot::swapAllAxisProperties()
{
for (auto curveSet : m_crossPlotCurveSets)
{
curveSet->swapAxisProperties(false);
}
loadDataAndUpdate();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -69,6 +69,7 @@ public:
void detachAllCurves();
void performAutoNameUpdate() override;
void updateCurveNamesAndPlotTitle();
void swapAllAxisProperties();
RiuGridCrossQwtPlot* qwtPlot() const;
public:

View File

@ -79,7 +79,7 @@ RimGridCrossPlotCurveSet::RimGridCrossPlotCurveSet()
CAF_PDM_InitField(&m_timeStep, "TimeStep", -1, "Time Step", "", "", "");
m_timeStep.uiCapability()->setUiEditorTypeName(caf::PdmUiComboBoxEditor::uiEditorTypeName());
CAF_PDM_InitFieldNoDefault(&m_cellFilterView, "VisibleCellView", "Filter by Cells Visible in 3d View", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_cellFilterView, "VisibleCellView", "Filter by 3d View Visibility", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_grouping, "Grouping", "Group Data by", "", "", "");
@ -87,11 +87,13 @@ RimGridCrossPlotCurveSet::RimGridCrossPlotCurveSet()
m_xAxisProperty = new RimEclipseResultDefinition;
m_xAxisProperty.uiCapability()->setUiHidden(true);
m_xAxisProperty.uiCapability()->setUiTreeChildrenHidden(true);
m_xAxisProperty->setLabelsOnTop(true);
CAF_PDM_InitFieldNoDefault(&m_yAxisProperty, "YAxisProperty", "Y-Axis Property", "", "", "");
m_yAxisProperty = new RimEclipseResultDefinition;
m_yAxisProperty.uiCapability()->setUiHidden(true);
m_yAxisProperty.uiCapability()->setUiTreeChildrenHidden(true);
m_yAxisProperty->setLabelsOnTop(true);
CAF_PDM_InitFieldNoDefault(&m_groupingProperty, "GroupingProperty", "Data Grouping Property", "", "", "");
m_groupingProperty = new RimEclipseCellColors;
@ -115,6 +117,7 @@ RimGridCrossPlotCurveSet::RimGridCrossPlotCurveSet()
void RimGridCrossPlotCurveSet::setCellFilterView(RimGridView* cellFilterView)
{
m_cellFilterView = cellFilterView;
m_groupingProperty->setReservoirView(dynamic_cast<RimEclipseView*>(m_cellFilterView()));
}
//--------------------------------------------------------------------------------------------------
@ -534,7 +537,7 @@ void RimGridCrossPlotCurveSet::defineUiOrdering(QString uiConfigName, caf::PdmUi
caf::PdmUiGroup* xAxisGroup = uiOrdering.addNewGroup("X-Axis Property");
m_xAxisProperty->uiOrdering(uiConfigName, *xAxisGroup);
caf::PdmUiGroup* yAxisGroup = uiOrdering.addNewGroup("Y-Axis Property");
caf::PdmUiGroup* yAxisGroup = uiOrdering.addNewGroup("Y-Axis Property", false);
m_yAxisProperty->uiOrdering(uiConfigName, *yAxisGroup);
}
@ -599,6 +602,7 @@ void RimGridCrossPlotCurveSet::fieldChangedByUi(const caf::PdmFieldHandle* chang
}
else if (changedField == &m_cellFilterView)
{
m_groupingProperty->setReservoirView(dynamic_cast<RimEclipseView*>(m_cellFilterView()));
loadDataAndUpdate(true);
}
else if (changedField == &m_isChecked)
@ -767,6 +771,21 @@ bool RimGridCrossPlotCurveSet::groupingEnabled() const
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGridCrossPlotCurveSet::swapAxisProperties(bool updatePlot)
{
RimEclipseResultDefinition* xAxisProperties = m_xAxisProperty();
RimEclipseResultDefinition* yAxisProperties = m_yAxisProperty();
m_xAxisProperty.removeChildObject(xAxisProperties);
m_yAxisProperty.removeChildObject(yAxisProperties);
m_yAxisProperty = xAxisProperties;
m_xAxisProperty = yAxisProperties;
loadDataAndUpdate(updatePlot);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -113,6 +113,7 @@ public:
void updateLegend();
bool groupingByCategoryResult() const;
bool groupingEnabled() const;
void swapAxisProperties(bool updatePlot);
protected:
void initAfterRead() override;

View File

@ -60,6 +60,7 @@
#include "RimGridCollection.h"
#include "RimGridCrossPlot.h"
#include "RimGridCrossPlotCollection.h"
#include "RimGridCrossPlotCurveSet.h"
#include "RimIdenticalGridCaseGroup.h"
#include "RimIntersection.h"
#include "RimIntersectionBox.h"
@ -472,6 +473,11 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
else if (dynamic_cast<RimGridCrossPlot*>(uiItem))
{
menuBuilder << "RicCreateGridCrossPlotCurveSetFeature";
menuBuilder << "RicSwapGridCrossPlotCurveSetAxesFeature";
}
else if (dynamic_cast<RimGridCrossPlotCurveSet*>(uiItem))
{
menuBuilder << "RicSwapGridCrossPlotCurveSetAxesFeature";
}
else if (dynamic_cast<RimSummaryPlot*>(uiItem)) // This is also the definition for RimSummaryCrossPlot
{

View File

@ -76,6 +76,7 @@ CAF_PDM_SOURCE_INIT(RimEclipseResultDefinition, "ResultDefinition");
//--------------------------------------------------------------------------------------------------
RimEclipseResultDefinition::RimEclipseResultDefinition()
: m_diffResultOptionsEnabled(false)
, m_labelsOnTop(false)
{
CAF_PDM_InitObject("Result Definition", "", "", "");
@ -1172,6 +1173,14 @@ void RimEclipseResultDefinition::setDiffResultOptionsEnabled(bool enabled)
m_diffResultOptionsEnabled = true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimEclipseResultDefinition::setLabelsOnTop(bool labelsOnTop)
{
m_labelsOnTop = labelsOnTop;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -1302,6 +1311,19 @@ void RimEclipseResultDefinition::defineUiOrdering(QString uiConfigName, caf::Pdm
m_resultVariableUiField.uiCapability()->setUiName(resultPropertyLabel);
}
if (m_labelsOnTop)
{
std::vector<caf::PdmFieldHandle*> fields;
this->fields(fields);
for (auto field : fields)
{
if (field->uiCapability())
{
field->uiCapability()->setUiLabelPosition(caf::PdmUiItemInfo::TOP);
}
}
}
uiOrdering.skipRemainingFields(true);
}

View File

@ -121,6 +121,7 @@ public:
void updateUiFieldsFromActiveResult();
void setDiffResultOptionsEnabled(bool enabled);
void setLabelsOnTop(bool labelsOnTop);
protected:
virtual void updateLegendCategorySettings() {};
@ -214,5 +215,6 @@ private:
private:
bool m_diffResultOptionsEnabled;
bool m_labelsOnTop;
};

View File

@ -148,6 +148,7 @@
<file>ReachCircle16x16.png</file>
<file>2DMapProjection16x16.png</file>
<file>Ruler24x24.png</file>
<file>Swap.png</file>
</qresource>
<qresource prefix="/Shader/">
<file>fs_CellFace.glsl</file>

Binary file not shown.

After

Width:  |  Height:  |  Size: 466 B

View File

@ -83,6 +83,41 @@ void RiuGridCrossQwtPlot::removeCurveSetLegend(RimGridCrossPlotCurveSet* curveSe
this->updateLegendLayout();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuGridCrossQwtPlot::updateLegendSizesToMatchPlot()
{
RimGridCrossPlot* crossPlot = dynamic_cast<RimGridCrossPlot*>(ownerPlotDefinition());
if (!crossPlot) return;
bool anyLegendResized = false;
for (RimGridCrossPlotCurveSet* curveSet : crossPlot->curveSets())
{
if (!curveSet->isChecked() || !curveSet->legendConfig()->showLegend()) continue;
auto pairIt = m_legendWidgets.find(curveSet);
if (pairIt != m_legendWidgets.end())
{
RiuCvfOverlayItemWidget* overlayWidget = pairIt->second;
if (overlayWidget->isVisible())
{
caf::TitledOverlayFrame* overlayItem = curveSet->legendConfig()->titledOverlayFrame();
if (resizeOverlayItemToFitPlot(overlayItem))
{
anyLegendResized = true;
overlayWidget->updateFromOverlayItem(overlayItem);
}
}
}
}
if (anyLegendResized)
{
updateLegendLayout();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -146,35 +181,7 @@ void RiuGridCrossQwtPlot::updateLegendLayout()
void RiuGridCrossQwtPlot::resizeEvent(QResizeEvent* e)
{
QwtPlot::resizeEvent(e);
RimGridCrossPlot* crossPlot = dynamic_cast<RimGridCrossPlot*>(ownerPlotDefinition());
if (!crossPlot) return;
bool anyLegendResized = false;
for (RimGridCrossPlotCurveSet* curveSet : crossPlot->curveSets())
{
if (!curveSet->isChecked() || !curveSet->legendConfig()->showLegend()) continue;
auto pairIt = m_legendWidgets.find(curveSet);
if (pairIt != m_legendWidgets.end())
{
RiuCvfOverlayItemWidget* overlayWidget = pairIt->second;
if (overlayWidget->isVisible())
{
caf::TitledOverlayFrame* overlayItem = curveSet->legendConfig()->titledOverlayFrame();
if (resizeOverlayItemToFitPlot(overlayItem))
{
anyLegendResized = true;
overlayWidget->updateFromOverlayItem(overlayItem);
}
}
}
}
if (anyLegendResized)
{
updateLegendLayout();
}
updateLegendSizesToMatchPlot();
}
//--------------------------------------------------------------------------------------------------

View File

@ -46,7 +46,7 @@ public:
void addOrUpdateCurveSetLegend(RimGridCrossPlotCurveSet* curveSetToShowLegendFor);
void removeCurveSetLegend(RimGridCrossPlotCurveSet* curveSetToShowLegendFor);
void updateLegendSizesToMatchPlot();
protected:
void updateLayout() override;
void updateLegendLayout();

View File

@ -320,6 +320,10 @@ QMinimizePanel*
groupBoxLayout->setContentsMargins(0, 0, 0, 0);
groupBoxLayout->setHorizontalSpacing(0);
}
else
{
groupBoxLayout->setContentsMargins(6, 6, 6, 6);
}
groupBox->contentFrame()->setLayout(groupBoxLayout);
connect(groupBox, SIGNAL(expandedChanged(bool)), this, SLOT(groupBoxExpandedStateToggled(bool)));