#3104 Well Log Plots: Implement variable width for tracks

This commit is contained in:
Gaute Lindkvist 2018-06-26 11:18:24 +02:00
parent ad17ee1050
commit e4288972de
6 changed files with 136 additions and 42 deletions

View File

@ -155,6 +155,8 @@ RimWellLogTrack::RimWellLogTrack()
CAF_PDM_InitField(&m_showformationFluids, "ShowFormationFluids", false, "Show Fluids", "", "", "");
CAF_PDM_InitField(&m_widthScaleFactor, "WidthScaleFactor", 1, "Width", "", "Set width of track. ", "");
m_formationsForCaseWithSimWellOnly = false;
}
@ -221,19 +223,17 @@ void RimWellLogTrack::fieldChangedByUi(const caf::PdmFieldHandle* changedField,
m_wellLogTrackPlotWidget->setVisible(m_show());
}
RimWellLogPlot* wellLogPlot;
this->firstAncestorOrThisOfType(wellLogPlot);
if (wellLogPlot)
updateParentPlotLayout();
}
else if (changedField == &m_widthScaleFactor)
{
if (m_widthScaleFactor < 1 && m_widthScaleFactor > 10)
{
wellLogPlot->calculateAvailableDepthRange();
wellLogPlot->updateDepthZoom();
RiuWellLogPlot* wellLogPlotViewer = dynamic_cast<RiuWellLogPlot*>(wellLogPlot->viewWidget());
if (wellLogPlotViewer)
{
wellLogPlotViewer->updateChildrenLayout();
}
m_widthScaleFactor = cvf::Math::clamp(m_widthScaleFactor(), 1, 10);
updateEditors();
}
updateParentPlotLayout();
}
else if (changedField == &m_visibleXRangeMin || changedField == &m_visibleXRangeMax)
{
@ -241,6 +241,7 @@ void RimWellLogTrack::fieldChangedByUi(const caf::PdmFieldHandle* changedField,
m_wellLogTrackPlotWidget->replot();
m_isAutoScaleXEnabled = false;
updateEditors();
updateParentPlotLayout();
}
else if (changedField == &m_isAutoScaleXEnabled)
{
@ -357,6 +358,23 @@ void RimWellLogTrack::fieldChangedByUi(const caf::PdmFieldHandle* changedField,
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellLogTrack::updateParentPlotLayout()
{
RimWellLogPlot* wellLogPlot;
this->firstAncestorOrThisOfType(wellLogPlot);
if (wellLogPlot)
{
RiuWellLogPlot* wellLogPlotViewer = dynamic_cast<RiuWellLogPlot*>(wellLogPlot->viewWidget());
if (wellLogPlotViewer)
{
wellLogPlotViewer->updateChildrenLayout();
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -638,6 +656,23 @@ QString RimWellLogTrack::depthPlotTitle() const
return parent->depthPlotTitle();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RimWellLogTrack::widthScaleFactor() const
{
return m_widthScaleFactor();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellLogTrack::setWidthScaleFactor(int scaleFactor)
{
m_widthScaleFactor = scaleFactor;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellLogTrack::setFormationWellPath(RimWellPath* wellPath)
@ -863,7 +898,10 @@ RimWellLogCurve* RimWellLogTrack::curveDefinitionFromCurve(const QwtPlotCurve* c
void RimWellLogTrack::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering)
{
uiOrdering.add(&m_userName);
// Hidden option that may still be useful for testing: enables you to control the width of tracks.
#ifdef ENABLE_WIDTHWEIGHT_GUI
uiOrdering.add(&m_widthScaleFactor);
#endif
caf::PdmUiGroup* formationGroup = uiOrdering.addNewGroup("Zonation/Formation Names");
formationGroup->add(&m_showFormations);

View File

@ -78,10 +78,12 @@ public:
void takeOutCurve(RimWellLogCurve* curve);
void deleteAllCurves();
size_t curveIndex(RimWellLogCurve* curve);
size_t curveCount() { return curves.size(); }
void setXAxisTitle(const QString& text);
size_t curveIndex(RimWellLogCurve* curve);
size_t curveCount() { return curves.size(); }
void setXAxisTitle(const QString& text);
QString depthPlotTitle() const;
int widthScaleFactor() const;
void setWidthScaleFactor(int scaleFactor);
void setFormationWellPath(RimWellPath* wellPath);
void setFormationSimWellName(const QString& simWellName);
@ -128,6 +130,7 @@ public:
private:
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override;
void updateParentPlotLayout();
virtual QList<caf::PdmOptionItemInfo> calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly) override;
virtual caf::PdmFieldHandle* objectToggleField() override;
@ -180,7 +183,7 @@ private:
caf::PdmField<int> m_formationBranchIndex;
caf::PdmField<caf::AppEnum<RigWellPathFormations::FormationLevel>> m_formationLevel;
caf::PdmField<bool> m_showformationFluids;
caf::PdmField<int> m_widthScaleFactor;
caf::PdmField<bool> m_formationBranchDetection;
bool m_formationsForCaseWithSimWellOnly;

View File

@ -313,15 +313,12 @@ void RiuWellLogPlot::resizeEvent(QResizeEvent *event)
}
//--------------------------------------------------------------------------------------------------
///
///
//--------------------------------------------------------------------------------------------------
void RiuWellLogPlot::placeChildWidgets(int height, int width)
std::map<int, int> RiuWellLogPlot::calculateTrackWidths(int frameWidth)
{
int trackCount = m_trackPlots.size();
CVF_ASSERT(m_legends.size() == trackCount);
const int trackPadding = 4;
int visibleTrackCount = 0;
for (int tIdx = 0; tIdx < trackCount; ++tIdx)
{
@ -330,12 +327,59 @@ void RiuWellLogPlot::placeChildWidgets(int height, int width)
int scrollBarWidth = 0;
if (m_scrollBar->isVisible()) scrollBarWidth = m_scrollBar->sizeHint().width();
std::map<int, int> trackWidths;
if (visibleTrackCount)
{
int totalTrackWidth = (frameWidth - scrollBarWidth);
int trackWidthExtra = (frameWidth - scrollBarWidth) % visibleTrackCount;
int totalWidthWeights = 0;
for (int tIdx = 0; tIdx < trackCount; ++tIdx)
{
if (m_trackPlots[tIdx]->isVisible())
{
totalWidthWeights += m_trackPlots[tIdx]->widthScaleFactor();
}
}
for (int tIdx = 0; tIdx < trackCount; ++tIdx)
{
if (m_trackPlots[tIdx]->isVisible())
{
int realTrackWidth = (totalTrackWidth * m_trackPlots[tIdx]->widthScaleFactor()) / totalWidthWeights;
if (trackWidthExtra > 0)
{
realTrackWidth += 1;
--trackWidthExtra;
}
trackWidths[tIdx] = realTrackWidth;
}
}
}
return trackWidths;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellLogPlot::placeChildWidgets(int height, int width)
{
CVF_ASSERT(m_legends.size() == m_trackPlots.size());
const int trackPadding = 4;
std::map<int, int> trackWidths = calculateTrackWidths(width);
size_t visibleTrackCount = trackWidths.size();
int maxLegendHeight = 0;
if (m_plotDefinition && m_plotDefinition->isTrackLegendsVisible())
{
for ( int tIdx = 0; tIdx < trackCount; ++tIdx )
for ( int tIdx = 0; tIdx < m_trackPlots.size(); ++tIdx )
{
if ( m_trackPlots[tIdx]->isVisible() )
{
@ -358,7 +402,7 @@ void RiuWellLogPlot::placeChildWidgets(int height, int width)
{
int maxCanvasOffset = 0;
for (int tIdx = 0; tIdx < trackCount; ++tIdx)
for (int tIdx = 0; tIdx < m_trackPlots.size(); ++tIdx)
{
if (m_trackPlots[tIdx]->isVisible())
{
@ -368,20 +412,11 @@ void RiuWellLogPlot::placeChildWidgets(int height, int width)
}
}
int trackWidth = (width - scrollBarWidth)/visibleTrackCount;
int trackWidthExtra = (width-scrollBarWidth)%visibleTrackCount;
for (int tIdx = 0; tIdx < trackCount; ++tIdx)
for (int tIdx = 0; tIdx < m_trackPlots.size(); ++tIdx)
{
if (m_trackPlots[tIdx]->isVisible())
{
int realTrackWidth = trackWidth;
if (trackWidthExtra > 0)
{
realTrackWidth += 1;
--trackWidthExtra;
}
int adjustedVerticalPosition = titleHeight + maxLegendHeight + 10;
int adjustedTrackHeight = trackHeight;
{
@ -396,7 +431,8 @@ void RiuWellLogPlot::placeChildWidgets(int height, int width)
adjustedVerticalPosition += canvasShift - myMargins;
adjustedTrackHeight -= canvasShift;
}
int realTrackWidth = trackWidths[tIdx];
m_legends[tIdx]->setGeometry(trackX + trackPadding, titleHeight, realTrackWidth - 2 * trackPadding, maxLegendHeight);
m_trackPlots[tIdx]->setGeometry(trackX + trackPadding, adjustedVerticalPosition, realTrackWidth - 2 * trackPadding, adjustedTrackHeight);
@ -440,7 +476,7 @@ void RiuWellLogPlot::updateChildrenLayout()
else
{
m_legends[tIdx]->hide();
}
}
}
placeChildWidgets(this->height(), this->width());

View File

@ -19,13 +19,15 @@
#pragma once
#include "RiuInterfaceToViewWindow.h"
#include "cafPdmPointer.h"
#include <QList>
#include <QPointer>
#include <QWidget>
#include "RiuInterfaceToViewWindow.h"
#include <map>
class RimWellLogPlot;
class RiuWellLogTrack;
@ -71,6 +73,7 @@ protected:
private:
void updateScrollBar(double minDepth, double maxDepth);
void modifyWidthOfContainingMdiWindow(int widthChange);
std::map<int, int> calculateTrackWidths(int frameWidth);
void placeChildWidgets(int height, int width);
private slots:
@ -78,11 +81,11 @@ private slots:
void scheduleUpdateChildrenLayout();
private:
QLabel* m_plotTitle;
QScrollBar* m_scrollBar;
QList<QPointer<QwtLegend> > m_legends;
QLabel* m_plotTitle;
QScrollBar* m_scrollBar;
QList<QPointer<QwtLegend> > m_legends;
QList<QPointer<RiuWellLogTrack> > m_trackPlots;
caf::PdmPointer<RimWellLogPlot> m_plotDefinition;
QTimer* m_scheduleUpdateChildrenLayoutTimer;
caf::PdmPointer<RimWellLogPlot> m_plotDefinition;
QTimer* m_scheduleUpdateChildrenLayoutTimer;
};

View File

@ -275,3 +275,16 @@ void RiuWellLogTrack::enableVerticalAxisLabelsAndTitle(bool enable)
this->axisScaleDraw(QwtPlot::yLeft)->enableComponent(
QwtAbstractScaleDraw::Labels, enable);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RiuWellLogTrack::widthScaleFactor() const
{
if (m_plotTrackDefinition)
{
return m_plotTrackDefinition->widthScaleFactor();
}
return 1;
}

View File

@ -53,6 +53,7 @@ public:
bool isRimTrackVisible();
void enableVerticalAxisLabelsAndTitle(bool enable);
int widthScaleFactor() const;
protected:
virtual bool eventFilter(QObject* watched, QEvent* event);