mirror of
https://github.com/OPM/ResInsight.git
synced 2026-07-30 16:28:16 -05:00
#9202 Well Log Plot: add option for having the legend inside the plot
This commit is contained in:
@@ -96,6 +96,7 @@ set(SOURCE_GROUP_HEADER_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuMainWindowTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuComparisonViewMover.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuAbstractOverlayContentFrame.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuQwtLegendOverlayContentFrame.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuAbstractLegendFrame.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuCategoryLegendFrame.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuScalarMapperLegendFrame.h
|
||||
@@ -206,6 +207,7 @@ set(SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuQssSyntaxHighlighter.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuTextEditWithCompletion.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuTextContentFrame.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuQwtLegendOverlayContentFrame.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuQwtDateScaleWrapper.cpp
|
||||
)
|
||||
|
||||
@@ -295,6 +297,7 @@ list(
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuScalarMapperLegendFrame.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuTextEditWithCompletion.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuTextContentFrame.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuQwtLegendOverlayContentFrame.h
|
||||
)
|
||||
|
||||
list(APPEND QT_UI_FILES)
|
||||
|
||||
@@ -20,27 +20,28 @@
|
||||
#include "RiuMultiPlotPage.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaGuiApplication.h"
|
||||
#include "RiaPlotDefines.h"
|
||||
#include "RiaPlotWindowRedrawScheduler.h"
|
||||
#include "RiaPreferences.h"
|
||||
|
||||
#include "WellLogCommands/RicWellLogPlotTrackFeatureImpl.h"
|
||||
|
||||
#include "RiaGuiApplication.h"
|
||||
#include "RiaPlotDefines.h"
|
||||
|
||||
#include "RimContextCommandBuilder.h"
|
||||
#include "RimMultiPlot.h"
|
||||
#include "RimPlotCurve.h"
|
||||
#include "RimPlotWindow.h"
|
||||
#include "RimWellLogTrack.h"
|
||||
|
||||
#include "RiuDraggableOverlayFrame.h"
|
||||
#include "RiuMainWindow.h"
|
||||
#include "RiuPlotMainWindow.h"
|
||||
#include "RiuPlotObjectPicker.h"
|
||||
#include "RiuPlotWidget.h"
|
||||
#include "RiuQwtLegendOverlayContentFrame.h"
|
||||
#include "RiuQwtPlotLegend.h"
|
||||
#include "RiuQwtPlotTools.h"
|
||||
#include "RiuQwtPlotWidget.h"
|
||||
#include "qwt_legend_label.h"
|
||||
#ifdef USE_QTCHARTS
|
||||
#include "RiuQtChartsPlotWidget.h"
|
||||
#endif
|
||||
@@ -52,6 +53,7 @@
|
||||
|
||||
#include "qwt_axis.h"
|
||||
#include "qwt_legend.h"
|
||||
#include "qwt_legend_label.h"
|
||||
#include "qwt_plot_layout.h"
|
||||
#include "qwt_plot_renderer.h"
|
||||
#include "qwt_scale_draw.h"
|
||||
@@ -167,10 +169,17 @@ void RiuMultiPlotPage::insertPlot( RiuPlotWidget* plotWidget, size_t index )
|
||||
subTitle->setVisible( false );
|
||||
m_subTitles.insert( static_cast<int>( index ), subTitle );
|
||||
|
||||
RiuQwtPlotLegend* legend = nullptr;
|
||||
RiuQwtPlotWidget* qwtPlotWidget = dynamic_cast<RiuQwtPlotWidget*>( plotWidget );
|
||||
|
||||
RiuQwtPlotLegend* legend = new RiuQwtPlotLegend( this );
|
||||
RiuDraggableOverlayFrame* legendFrame = nullptr;
|
||||
if ( qwtPlotWidget )
|
||||
{
|
||||
legendFrame = new RiuDraggableOverlayFrame( qwtPlotWidget->qwtPlot()->canvas(), plotWidget->overlayMargins() );
|
||||
}
|
||||
|
||||
if ( m_plotDefinition->legendsVisible() && plotWidget->plotDefinition()->legendsVisible() )
|
||||
{
|
||||
legend = new RiuQwtPlotLegend( this );
|
||||
int legendColumns = 1;
|
||||
if ( m_plotDefinition->legendsHorizontal() )
|
||||
{
|
||||
@@ -179,7 +188,6 @@ void RiuMultiPlotPage::insertPlot( RiuPlotWidget* plotWidget, size_t index )
|
||||
legend->setMaxColumns( legendColumns );
|
||||
legend->horizontalScrollBar()->setVisible( false );
|
||||
legend->verticalScrollBar()->setVisible( false );
|
||||
RiuQwtPlotWidget* qwtPlotWidget = dynamic_cast<RiuQwtPlotWidget*>( plotWidget );
|
||||
if ( qwtPlotWidget )
|
||||
{
|
||||
legend->connect( qwtPlotWidget->qwtPlot(),
|
||||
@@ -200,9 +208,11 @@ void RiuMultiPlotPage::insertPlot( RiuPlotWidget* plotWidget, size_t index )
|
||||
|
||||
legend->contentsWidget()->layout()->setAlignment( Qt::AlignBottom | Qt::AlignHCenter );
|
||||
legend->setVisible( false );
|
||||
|
||||
plotWidget->updateLegend();
|
||||
}
|
||||
m_legends.insert( static_cast<int>( index ), legend );
|
||||
m_legendFrames.insert( static_cast<int>( index ), legendFrame );
|
||||
|
||||
scheduleUpdate();
|
||||
}
|
||||
@@ -628,9 +638,10 @@ void RiuMultiPlotPage::reinsertPlotWidgets()
|
||||
{
|
||||
clearGridLayout();
|
||||
|
||||
QList<QPointer<QLabel>> subTitles = this->subTitlesForVisiblePlots();
|
||||
QList<QPointer<RiuQwtPlotLegend>> legends = this->legendsForVisiblePlots();
|
||||
QList<QPointer<RiuPlotWidget>> plotWidgets = this->visiblePlotWidgets();
|
||||
QList<QPointer<QLabel>> subTitles = this->subTitlesForVisiblePlots();
|
||||
QList<QPointer<RiuQwtPlotLegend>> legends = this->legendsForVisiblePlots();
|
||||
QList<QPointer<RiuDraggableOverlayFrame>> legendFrames = this->legendFramesForVisiblePlots();
|
||||
QList<QPointer<RiuPlotWidget>> plotWidgets = this->visiblePlotWidgets();
|
||||
|
||||
m_visibleIndexToPositionMapping.clear();
|
||||
|
||||
@@ -654,7 +665,25 @@ void RiuMultiPlotPage::reinsertPlotWidgets()
|
||||
m_gridLayout->addWidget( subTitles[visibleIndex], 3 * row, column, 1, colSpan );
|
||||
if ( legends[visibleIndex] )
|
||||
{
|
||||
m_gridLayout->addWidget( legends[visibleIndex], 3 * row + 1, column, 1, colSpan, Qt::AlignHCenter | Qt::AlignBottom );
|
||||
if ( m_plotDefinition->legendPosition() == RimPlotWindow::LegendPosition::ABOVE )
|
||||
{
|
||||
m_gridLayout->addWidget( legends[visibleIndex],
|
||||
3 * row + 1,
|
||||
column,
|
||||
1,
|
||||
colSpan,
|
||||
Qt::AlignHCenter | Qt::AlignBottom );
|
||||
}
|
||||
else
|
||||
{
|
||||
CAF_ASSERT( m_plotDefinition->legendPosition() == RimPlotWindow::LegendPosition::INSIDE );
|
||||
|
||||
auto overlayFrame = new RiuQwtLegendOverlayContentFrame;
|
||||
overlayFrame->setLegend( legends[visibleIndex] );
|
||||
legendFrames[visibleIndex]->setContentFrame( overlayFrame );
|
||||
legendFrames[visibleIndex]->setAnchorCorner( RiuDraggableOverlayFrame::AnchorCorner::TopRight );
|
||||
plotWidgets[visibleIndex]->addOverlayFrame( legendFrames[visibleIndex] );
|
||||
}
|
||||
}
|
||||
m_gridLayout->addWidget( plotWidgets[visibleIndex], 3 * row + 2, column, 1 + ( rowSpan - 1 ) * 3, colSpan );
|
||||
|
||||
@@ -830,6 +859,7 @@ void RiuMultiPlotPage::clearGridLayout()
|
||||
{
|
||||
if ( m_plotWidgets[tIdx] )
|
||||
{
|
||||
m_plotWidgets[tIdx]->removeOverlayFrame( m_legendFrames[tIdx] );
|
||||
m_plotWidgets[tIdx]->hide();
|
||||
}
|
||||
if ( m_legends[tIdx] )
|
||||
@@ -875,6 +905,22 @@ QList<QPointer<RiuQwtPlotLegend>> RiuMultiPlotPage::legendsForVisiblePlots() con
|
||||
return legends;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QList<QPointer<RiuDraggableOverlayFrame>> RiuMultiPlotPage::legendFramesForVisiblePlots() const
|
||||
{
|
||||
QList<QPointer<RiuDraggableOverlayFrame>> legendFrames;
|
||||
for ( int i = 0; i < m_plotWidgets.size(); ++i )
|
||||
{
|
||||
if ( m_plotWidgets[i]->isChecked() )
|
||||
{
|
||||
legendFrames.push_back( m_legendFrames[i] );
|
||||
}
|
||||
}
|
||||
return legendFrames;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
#pragma once
|
||||
|
||||
#include "RiuDraggableOverlayFrame.h"
|
||||
#include "RiuInterfaceToViewWindow.h"
|
||||
|
||||
#include "RiaDefines.h"
|
||||
@@ -127,9 +128,10 @@ protected:
|
||||
|
||||
void clearGridLayout();
|
||||
|
||||
QList<QPointer<RiuPlotWidget>> visiblePlotWidgets() const;
|
||||
QList<QPointer<RiuQwtPlotLegend>> legendsForVisiblePlots() const;
|
||||
QList<QPointer<QLabel>> subTitlesForVisiblePlots() const;
|
||||
QList<QPointer<RiuPlotWidget>> visiblePlotWidgets() const;
|
||||
QList<QPointer<RiuQwtPlotLegend>> legendsForVisiblePlots() const;
|
||||
QList<QPointer<QLabel>> subTitlesForVisiblePlots() const;
|
||||
QList<QPointer<RiuDraggableOverlayFrame>> legendFramesForVisiblePlots() const;
|
||||
|
||||
void applyLook();
|
||||
|
||||
@@ -137,16 +139,17 @@ private slots:
|
||||
void onLegendUpdated();
|
||||
|
||||
protected:
|
||||
QPointer<QVBoxLayout> m_layout;
|
||||
QPointer<QHBoxLayout> m_plotLayout;
|
||||
QPointer<QFrame> m_plotWidgetFrame;
|
||||
QPointer<QGridLayout> m_gridLayout;
|
||||
QPointer<QLabel> m_plotTitle;
|
||||
QList<QPointer<QLabel>> m_subTitles;
|
||||
QList<QPointer<RiuQwtPlotLegend>> m_legends;
|
||||
QList<QPointer<RiuPlotWidget>> m_plotWidgets;
|
||||
std::map<int, std::pair<int, int>> m_visibleIndexToPositionMapping;
|
||||
caf::PdmPointer<RimPlotWindow> m_plotDefinition;
|
||||
QPointer<QVBoxLayout> m_layout;
|
||||
QPointer<QHBoxLayout> m_plotLayout;
|
||||
QPointer<QFrame> m_plotWidgetFrame;
|
||||
QPointer<QGridLayout> m_gridLayout;
|
||||
QPointer<QLabel> m_plotTitle;
|
||||
QList<QPointer<QLabel>> m_subTitles;
|
||||
QList<QPointer<RiuQwtPlotLegend>> m_legends;
|
||||
QList<QPointer<RiuDraggableOverlayFrame>> m_legendFrames;
|
||||
QList<QPointer<RiuPlotWidget>> m_plotWidgets;
|
||||
std::map<int, std::pair<int, int>> m_visibleIndexToPositionMapping;
|
||||
caf::PdmPointer<RimPlotWindow> m_plotDefinition;
|
||||
|
||||
int m_titleFontPixelSize;
|
||||
int m_subTitleFontPixelSize;
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2022- 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
#include "RiuQwtLegendOverlayContentFrame.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QTextDocument>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiuQwtLegendOverlayContentFrame::RiuQwtLegendOverlayContentFrame( QWidget* parent )
|
||||
: RiuAbstractOverlayContentFrame( parent )
|
||||
{
|
||||
QVBoxLayout* layout = new QVBoxLayout( this );
|
||||
layout->setContentsMargins( 4, 4, 4, 4 );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQwtLegendOverlayContentFrame::setLegend( QwtLegend* legend )
|
||||
{
|
||||
m_legend = legend;
|
||||
layout()->addWidget( legend );
|
||||
legend->adjustSize();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQwtLegendOverlayContentFrame::renderTo( QPainter* painter, const QRect& targetRect )
|
||||
{
|
||||
painter->save();
|
||||
painter->translate( targetRect.topLeft() + QPoint( this->contentsMargins().left(), this->contentsMargins().top() ) );
|
||||
|
||||
QRegion sourceRegion = visibleRegion();
|
||||
render( painter, QPoint(), sourceRegion );
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2022- 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 "RiuAbstractOverlayContentFrame.h"
|
||||
|
||||
#include <QPointer>
|
||||
#include <QString>
|
||||
|
||||
#include "qwt_legend.h"
|
||||
|
||||
class QLabel;
|
||||
|
||||
class RiuQwtLegendOverlayContentFrame : public RiuAbstractOverlayContentFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
RiuQwtLegendOverlayContentFrame( QWidget* parent = nullptr );
|
||||
|
||||
void setLegend( QwtLegend* legend );
|
||||
void renderTo( QPainter* painter, const QRect& targetRect ) override;
|
||||
|
||||
private:
|
||||
QPointer<QwtLegend> m_legend;
|
||||
};
|
||||
Reference in New Issue
Block a user