#3097 Optionally add plot title to the plot itself

This commit is contained in:
Gaute Lindkvist 2018-06-26 10:24:29 +02:00
parent ad4e0bccc5
commit f0bd7c726a
6 changed files with 98 additions and 29 deletions

View File

@ -65,6 +65,23 @@ void RimViewWindow::removeMdiWindowFromMdiArea()
if ( m_windowController() ) m_windowController->removeWindowFromMDI(); if ( m_windowController() ) m_windowController->removeWindowFromMDI();
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimViewWindow::windowTitle()
{
if (this->userDescriptionField())
{
caf::PdmUiFieldHandle* uiFieldHandle = this->userDescriptionField()->uiCapability();
if (uiFieldHandle)
{
QVariant v = uiFieldHandle->uiValue();
return v.toString();
}
}
return QString("");
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -168,15 +185,7 @@ void RimViewWindow::updateMdiWindowTitle()
{ {
if ( viewWidget() ) if ( viewWidget() )
{ {
if ( this->userDescriptionField() ) viewWidget()->setWindowTitle(windowTitle());
{
caf::PdmUiFieldHandle* uiFieldHandle = this->userDescriptionField()->uiCapability();
if ( uiFieldHandle )
{
QVariant v = uiFieldHandle->uiValue();
viewWidget()->setWindowTitle(v.toString());
}
}
} }
} }

View File

@ -69,6 +69,7 @@ protected:
///////// Interface for the Window controller ///////// Interface for the Window controller
friend class RimMdiWindowController; friend class RimMdiWindowController;
QString windowTitle();
virtual QWidget* createViewWidget(QWidget* mainWindowParent) = 0; virtual QWidget* createViewWidget(QWidget* mainWindowParent) = 0;
virtual void updateViewWidgetAfterCreation() {}; virtual void updateViewWidgetAfterCreation() {};
virtual void updateMdiWindowTitle(); // Has real default implementation virtual void updateMdiWindowTitle(); // Has real default implementation

View File

@ -79,6 +79,7 @@ RimWellLogPlot::RimWellLogPlot()
CAF_PDM_InitField(&m_maxVisibleDepth, "MaximumDepth", 1000.0, "Max", "", "", ""); CAF_PDM_InitField(&m_maxVisibleDepth, "MaximumDepth", 1000.0, "Max", "", "", "");
CAF_PDM_InitField(&m_isAutoScaleDepthEnabled, "AutoScaleDepthEnabled", true, "Auto Scale", "", "", ""); CAF_PDM_InitField(&m_isAutoScaleDepthEnabled, "AutoScaleDepthEnabled", true, "Auto Scale", "", "", "");
m_isAutoScaleDepthEnabled.uiCapability()->setUiHidden(true); m_isAutoScaleDepthEnabled.uiCapability()->setUiHidden(true);
CAF_PDM_InitField(&m_showTitleInPlot, "ShowTitleInPlot", true, "Show Title in Plot", "", "", "");
CAF_PDM_InitField(&m_showTrackLegends, "ShowTrackLegends", true, "Show Legends", "", "", ""); CAF_PDM_InitField(&m_showTrackLegends, "ShowTrackLegends", true, "Show Legends", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_tracks, "Tracks", "", "", "", ""); CAF_PDM_InitFieldNoDefault(&m_tracks, "Tracks", "", "", "", "");
@ -113,6 +114,12 @@ void RimWellLogPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c
m_isAutoScaleDepthEnabled = false; m_isAutoScaleDepthEnabled = false;
} }
else if (changedField == &m_showTitleInPlot ||
changedField == &m_showTrackLegends)
{
updateTracks();
if (m_viewer) m_viewer->updateChildrenLayout();
}
else if (changedField == &m_isAutoScaleDepthEnabled) else if (changedField == &m_isAutoScaleDepthEnabled)
{ {
updateDepthZoom(); updateDepthZoom();
@ -121,8 +128,7 @@ void RimWellLogPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c
{ {
updateMdiWindowTitle(); updateMdiWindowTitle();
} }
else if ( changedField == &m_depthType )
if ( changedField == &m_depthType )
{ {
RimWellAllocationPlot* wellAllocPlot; RimWellAllocationPlot* wellAllocPlot;
firstAncestorOrThisOfType(wellAllocPlot); firstAncestorOrThisOfType(wellAllocPlot);
@ -134,18 +140,12 @@ void RimWellLogPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c
updateDepthZoom(); updateDepthZoom();
} }
} }
if ( changedField == &m_depthUnit) else if ( changedField == &m_depthUnit)
{ {
updateTracks(); updateTracks();
updateDepthZoom(); updateDepthZoom();
} }
if ( changedField == &m_showTrackLegends)
{
updateTracks();
if (m_viewer) m_viewer->updateChildrenLayout();
}
RimWellRftPlot* rftPlot(nullptr); RimWellRftPlot* rftPlot(nullptr);
this->firstAncestorOrThisOfType(rftPlot); this->firstAncestorOrThisOfType(rftPlot);
@ -583,6 +583,7 @@ void RimWellLogPlot::uiOrderingForPlot(caf::PdmUiOrdering& uiOrdering)
uiOrdering.add(&m_depthUnit); uiOrdering.add(&m_depthUnit);
} }
uiOrdering.add(&m_showTitleInPlot);
uiOrdering.add(&m_showTrackLegends); uiOrdering.add(&m_showTrackLegends);
} }
@ -615,7 +616,7 @@ void RimWellLogPlot::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering&
void RimWellLogPlot::onLoadDataAndUpdate() void RimWellLogPlot::onLoadDataAndUpdate()
{ {
updateMdiWindowVisibility(); updateMdiWindowVisibility();
updatePlotTitle();
updateTracks(); updateTracks();
} }
@ -834,6 +835,14 @@ QString RimWellLogPlot::depthPlotTitle() const
return depthTitle; return depthTitle;
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimWellLogPlot::isPlotTitleVisible() const
{
return m_showTitleInPlot();
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -903,3 +912,14 @@ void RimWellLogPlot::updateDisabledDepthTypes()
} }
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellLogPlot::updatePlotTitle()
{
if (m_viewer)
{
m_viewer->setPlotTitle(this->windowTitle());
}
}

View File

@ -70,6 +70,7 @@ public:
QString depthPlotTitle() const; QString depthPlotTitle() const;
bool isPlotTitleVisible() const;
bool isTrackLegendsVisible() const; bool isTrackLegendsVisible() const;
void setTrackLegendsVisible(bool doShow); void setTrackLegendsVisible(bool doShow);
@ -131,7 +132,7 @@ private:
void detachAllCurves(); void detachAllCurves();
void updateDisabledDepthTypes(); void updateDisabledDepthTypes();
void updatePlotTitle();
public: // Needed by RiuWellAllocation Plot public: // Needed by RiuWellAllocation Plot
// RimViewWindow overrides // RimViewWindow overrides
@ -150,6 +151,7 @@ private:
caf::PdmField<double> m_minVisibleDepth; caf::PdmField<double> m_minVisibleDepth;
caf::PdmField<double> m_maxVisibleDepth; caf::PdmField<double> m_maxVisibleDepth;
caf::PdmField<bool> m_isAutoScaleDepthEnabled; caf::PdmField<bool> m_isAutoScaleDepthEnabled;
caf::PdmField<bool> m_showTitleInPlot;
caf::PdmField<bool> m_showTrackLegends; caf::PdmField<bool> m_showTrackLegends;
double m_minAvailableDepth; double m_minAvailableDepth;

View File

@ -36,9 +36,9 @@
#include <QFocusEvent> #include <QFocusEvent>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QMdiSubWindow> #include <QMdiSubWindow>
#include <QMenu>
#include <QScrollBar> #include <QScrollBar>
#include <QTimer> #include <QTimer>
#include <QMenu>
#include <math.h> #include <math.h>
@ -57,6 +57,12 @@ RiuWellLogPlot::RiuWellLogPlot(RimWellLogPlot* plotDefinition, QWidget* parent)
setAutoFillBackground(true); setAutoFillBackground(true);
m_plotTitle = new QLabel("PLOT TITLE HERE", this);
QFont font = m_plotTitle->font();
font.setPointSize(12);
font.setBold(true);
m_plotTitle->setFont(font);
m_plotTitle->hide();
m_scrollBar = new QScrollBar(this); m_scrollBar = new QScrollBar(this);
m_scrollBar->setOrientation(Qt::Vertical); m_scrollBar->setOrientation(Qt::Vertical);
m_scrollBar->setVisible(true); m_scrollBar->setVisible(true);
@ -201,6 +207,16 @@ void RiuWellLogPlot::setDepthZoomAndReplot(double minDepth, double maxDepth)
updateScrollBar(minDepth, maxDepth); updateScrollBar(minDepth, maxDepth);
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellLogPlot::setPlotTitle(const QString& plotTitle)
{
m_plotTitle->setText(plotTitle);
m_plotTitle->setGeometry(0, 0, m_plotTitle->sizeHint().width(), m_plotTitle->sizeHint().height());
this->updateChildrenLayout();
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -326,6 +342,12 @@ void RiuWellLogPlot::placeChildWidgets(int height, int width)
} }
} }
int titleHeight = 0;
if (m_plotTitle && m_plotTitle->isVisible())
{
titleHeight = m_plotTitle->height() + 10;
}
int trackHeight = height - maxLegendHeight; int trackHeight = height - maxLegendHeight;
int trackX = 0; int trackX = 0;
@ -345,15 +367,18 @@ void RiuWellLogPlot::placeChildWidgets(int height, int width)
--trackWidthExtra; --trackWidthExtra;
} }
int realLegendWidth = std::max(realTrackWidth, m_legends[tIdx]->sizeHint().width()); int realLegendWidth = std::max(realTrackWidth, m_legends[tIdx]->sizeHint().width());
m_legends[tIdx]->setGeometry(trackX, 0, realLegendWidth, maxLegendHeight); m_legends[tIdx]->setGeometry(trackX, titleHeight, realLegendWidth, maxLegendHeight);
m_trackPlots[tIdx]->setGeometry(trackX, maxLegendHeight, realTrackWidth, trackHeight); m_trackPlots[tIdx]->setGeometry(trackX, titleHeight + maxLegendHeight, realTrackWidth, trackHeight);
trackX += realTrackWidth; trackX += realTrackWidth;
} }
} }
} }
if (m_scrollBar->isVisible()) m_scrollBar->setGeometry(trackX, maxLegendHeight, scrollBarWidth, trackHeight); if (m_scrollBar->isVisible())
{
m_scrollBar->setGeometry(trackX, titleHeight + maxLegendHeight, m_scrollBar->sizeHint().width(), trackHeight);
}
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -361,6 +386,17 @@ void RiuWellLogPlot::placeChildWidgets(int height, int width)
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuWellLogPlot::updateChildrenLayout() void RiuWellLogPlot::updateChildrenLayout()
{ {
if (m_plotDefinition && m_plotDefinition->isPlotTitleVisible())
{
m_plotTitle->setGeometry(0, 0, m_plotTitle->sizeHint().width(), m_plotTitle->sizeHint().height());
m_plotTitle->show();
}
else
{
m_plotTitle->hide();
}
int trackCount = m_trackPlots.size(); int trackCount = m_trackPlots.size();
for (int tIdx = 0; tIdx < trackCount; ++tIdx) for (int tIdx = 0; tIdx < trackCount; ++tIdx)
{ {

View File

@ -30,9 +30,9 @@
class RimWellLogPlot; class RimWellLogPlot;
class RiuWellLogTrack; class RiuWellLogTrack;
class QHBoxLayout;
class QScrollBar;
class QFocusEvent; class QFocusEvent;
class QLabel;
class QScrollBar;
class QwtLegend; class QwtLegend;
//================================================================================================== //==================================================================================================
@ -56,8 +56,9 @@ public:
void removeTrackPlot(RiuWellLogTrack* trackPlot); void removeTrackPlot(RiuWellLogTrack* trackPlot);
void setDepthZoomAndReplot(double minDepth, double maxDepth); void setDepthZoomAndReplot(double minDepth, double maxDepth);
void setPlotTitle(const QString& plotTitle);
public slots: public slots:
void updateChildrenLayout(); void updateChildrenLayout();
protected: protected:
@ -77,7 +78,7 @@ private slots:
void scheduleUpdateChildrenLayout(); void scheduleUpdateChildrenLayout();
private: private:
QHBoxLayout* m_layout; QLabel* m_plotTitle;
QScrollBar* m_scrollBar; QScrollBar* m_scrollBar;
QList<QPointer<QwtLegend> > m_legends; QList<QPointer<QwtLegend> > m_legends;
QList<QPointer<RiuWellLogTrack> > m_trackPlots; QList<QPointer<RiuWellLogTrack> > m_trackPlots;