ResInsight/ApplicationLibCode/UserInterface/RiuMultiPlotPage.h

193 lines
6.8 KiB
C
Raw Normal View History

2019-12-19 04:37:40 -06:00
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RiuDraggableOverlayFrame.h"
#include "RiuInterfaceToViewWindow.h"
2019-12-19 04:37:40 -06:00
#include "RiaDefines.h"
2019-12-19 04:37:40 -06:00
#include "cafPdmPointer.h"
#include "cafSelectionChangedReceiver.h"
#include "qwt_axis_id.h"
2019-12-19 04:37:40 -06:00
#include <QFrame>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QList>
#include <QPointer>
#include <QWidget>
#include <functional>
2019-12-19 04:37:40 -06:00
#include <map>
class RiaPlotWindowRedrawScheduler;
class RimPlotWindow;
2019-12-19 04:37:40 -06:00
class RiuQwtPlotLegend;
class RiuPlotWidget;
2019-12-19 04:37:40 -06:00
class QFocusEvent;
class QLabel;
class QPaintDevice;
class QScrollBar;
class QwtLegend;
class QwtLegendData;
class QwtPlot;
//==================================================================================================
//
// RiuMultiPlotPage
//
//==================================================================================================
class RiuMultiPlotPage : public QWidget, public caf::SelectionChangedReceiver, public RiuInterfaceToViewWindow
2019-12-19 04:37:40 -06:00
{
Q_OBJECT
public:
RiuMultiPlotPage( RimPlotWindow* plotDefinition, QWidget* parent = nullptr );
2019-12-19 04:37:40 -06:00
~RiuMultiPlotPage() override;
RimViewWindow* ownerViewWindow() const override;
RimPlotWindow* ownerPlotDefinition();
2019-12-19 04:37:40 -06:00
void addPlot( RiuPlotWidget* plotWidget );
void insertPlot( RiuPlotWidget* plotWidget, size_t index );
void removePlot( RiuPlotWidget* plotWidget );
2019-12-19 04:37:40 -06:00
void removeAllPlots();
int indexOfPlotWidget( RiuPlotWidget* plotWidget );
2019-12-19 04:37:40 -06:00
void setPlotTitle( const QString& plotTitle );
void setTitleVisible( bool visible );
2020-05-09 04:23:58 -05:00
void setTitleFontSizes( int titleFontSize, int subTitleFontSize );
void setLegendFontSize( int legendFontSize );
void setAxisFontSizes( int axisTitleFontSize, int axisValueFontSize );
void setSubTitlesVisible( bool visible );
2019-12-19 04:37:40 -06:00
bool previewModeEnabled() const;
void setPagePreviewModeEnabled( bool previewMode );
2019-12-19 04:37:40 -06:00
void setAutoAlignAxes( bool autoAlignAxes );
void scheduleUpdate( RiaDefines::MultiPlotPageUpdateType whatToUpdate = RiaDefines::MultiPlotPageUpdateType::ALL );
void scheduleReplotOfAllPlots();
virtual void updateVerticalScrollBar( double visibleMin, double visibleMax, double totalMin, double totalMax ) {}
2020-06-08 03:49:45 -05:00
void updateSubTitles();
virtual void renderTo( QPaintDevice* paintDevice );
void renderTo( QPainter* painter, double scalingFactor );
2019-12-19 04:37:40 -06:00
QSize sizeHint() const override;
QSize minimumSizeHint() const override;
int heightForWidth( int width ) const override;
std::pair<int, int> findAvailableRowAndColumn( int startRow, int startColumn, int columnSpan, int columnCount ) const;
public slots:
virtual void performUpdate( RiaDefines::MultiPlotPageUpdateType whatToUpdate );
2019-12-19 04:37:40 -06:00
protected:
void contextMenuEvent( QContextMenuEvent* ) override;
QLabel* createTitleLabel() const;
void showEvent( QShowEvent* event ) override;
bool hasHeightForWidth() const override;
void updateMarginsFromPageLayout();
void updateLegendColumns( RiuQwtPlotLegend* legend );
void updateLegendFont( RiuQwtPlotLegend* legend );
2019-12-19 04:37:40 -06:00
std::pair<int, int> rowAndColumnCount( int plotWidgetCount ) const;
void alignAxes();
void alignAxis( QwtAxisId axis, int row, std::function<bool( int, int, int )> positionMatcher );
2021-04-14 21:14:51 -05:00
void onSelectionManagerSelectionChanged( const std::set<int>& changedSelectionLevels ) override;
2019-12-19 04:37:40 -06:00
virtual bool showYAxis( int row, int column ) const;
virtual void reinsertPlotWidgets();
virtual void refreshLegends();
void updatePlotLayouts();
void addLegendWidget( RiuPlotWidget* plotWidget, RiuQwtPlotLegend* legend, RiuDraggableOverlayFrame* legendFrame, int row, int column, int colSpan );
void reinsertPlotWidget( RiuPlotWidget* plotWidget,
RiuQwtPlotLegend* legend,
RiuDraggableOverlayFrame* legendFrame,
QLabel* subTitle,
int row,
int column,
int rowSpan,
int colSpan );
void updateSubTitleVisibility( QLabel* subTitle );
void setDefaultAxisProperties( RiuPlotWidget* plotWidget, int row, int column );
void adjustHeadingSpacing( RiuPlotWidget* plotWidget );
void setRowAndColumnStretches( int row, int column, int rowSpan, int colSpan );
void updateLegendVisibility( RiuPlotWidget* plotWidget, RiuQwtPlotLegend* legend, RiuDraggableOverlayFrame* legendFrame );
void updateTitleFont();
int alignCanvasTops();
2019-12-19 04:37:40 -06:00
void clearGridLayout();
2019-12-19 04:37:40 -06:00
QList<QPointer<RiuPlotWidget>> visiblePlotWidgets() const;
QList<QPointer<RiuQwtPlotLegend>> legendsForVisiblePlots() const;
QList<QPointer<QLabel>> subTitlesForVisiblePlots() const;
QList<QPointer<RiuDraggableOverlayFrame>> legendFramesForVisiblePlots() const;
2019-12-19 04:37:40 -06:00
void applyLook();
2019-12-19 04:37:40 -06:00
private slots:
void onLegendUpdated();
2019-12-19 04:37:40 -06:00
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<RiuDraggableOverlayFrame>> m_legendFrames;
QList<QPointer<RiuPlotWidget>> m_plotWidgets;
std::map<int, std::pair<int, int>> m_visibleIndexToPositionMapping;
caf::PdmPointer<RimPlotWindow> m_plotDefinition;
2020-05-09 04:23:58 -05:00
int m_titleFontPixelSize;
int m_subTitleFontPixelSize;
int m_legendFontPixelSize;
2020-05-27 05:58:21 -05:00
int m_axisTitleFontSize;
int m_axisValueFontSize;
2020-05-09 04:23:58 -05:00
bool m_previewMode;
bool m_showSubTitles;
bool m_autoAlignAxes;
2019-12-19 04:37:40 -06:00
std::map<RiuQwtPlotLegend*, int> m_childCountForAdjustSizeOperation;
2019-12-19 04:37:40 -06:00
private:
friend class RiaPlotWindowRedrawScheduler;
};