mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Merge pull request #8387 from OPM/qtcharts-summary-plots
Closes #8228 Major refactoring of summary plotting. Now possible to create plots both with Qwt and QtChart as plotting tool.
This commit is contained in:
committed by
GitHub
parent
d9bb82de91
commit
258fbddc10
105
ApplicationLibCode/UserInterface/RiuQtChartsPlotTools.cpp
Normal file
105
ApplicationLibCode/UserInterface/RiuQtChartsPlotTools.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2021- 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 "RiuQtChartsPlotTools.h"
|
||||
|
||||
#include "RiaPlotDefines.h"
|
||||
#include "RiuGuiTheme.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaPreferences.h"
|
||||
#include "RiuQtChartsPlotWidget.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQtChartsPlotTools::setCommonPlotBehaviour( RiuQtChartsPlotWidget* plot )
|
||||
{
|
||||
// Plot background and frame look
|
||||
QPalette newPalette( plot->palette() );
|
||||
newPalette.setColor( QPalette::Window, Qt::white );
|
||||
plot->setPalette( newPalette );
|
||||
|
||||
plot->setAutoFillBackground( true );
|
||||
|
||||
// Axis number font
|
||||
int axisFontSize = caf::FontTools::absolutePointSize( RiaPreferences::current()->defaultPlotFontSize(),
|
||||
caf::FontTools::RelativeSize::Medium );
|
||||
|
||||
// Axis title font
|
||||
int titleFontSize = caf::FontTools::absolutePointSize( RiaPreferences::current()->defaultPlotFontSize(),
|
||||
caf::FontTools::RelativeSize::Medium );
|
||||
bool titleBold = false;
|
||||
plot->setAxesFontsAndAlignment( titleFontSize, axisFontSize, titleBold, Qt::AlignRight );
|
||||
|
||||
// Store the pointer address as an object name. This way
|
||||
// each plot can be identified uniquely for CSS-stylesheets
|
||||
QString objectName = QString( "%1" ).arg( reinterpret_cast<uint64_t>( plot ) );
|
||||
plot->setObjectName( objectName );
|
||||
|
||||
QString canvasName = QString( "%1" ).arg( reinterpret_cast<uint64_t>( plot->getParentForOverlay() ) );
|
||||
plot->getParentForOverlay()->setObjectName( canvasName );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQtChartsPlotTools::setDefaultAxes( RiuQtChartsPlotWidget* plot )
|
||||
{
|
||||
plot->enableAxis( RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM, true );
|
||||
plot->enableAxis( RiaDefines::PlotAxis::PLOT_AXIS_LEFT, true );
|
||||
plot->enableAxis( RiaDefines::PlotAxis::PLOT_AXIS_TOP, false );
|
||||
plot->enableAxis( RiaDefines::PlotAxis::PLOT_AXIS_RIGHT, false );
|
||||
|
||||
plot->setAxisMaxMinor( RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM, 2 );
|
||||
plot->setAxisMaxMinor( RiaDefines::PlotAxis::PLOT_AXIS_LEFT, 3 );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQtChartsPlotTools::enableDateBasedBottomXAxis( RiuQtChartsPlotWidget* plot,
|
||||
const QString& dateFormat,
|
||||
const QString& timeFormat,
|
||||
RiaQDateTimeTools::DateFormatComponents dateComponents,
|
||||
RiaQDateTimeTools::TimeFormatComponents timeComponents )
|
||||
{
|
||||
QString format = dateTimeFormatForInterval( dateFormat, timeFormat, dateComponents, timeComponents );
|
||||
plot->setAxisFormat( RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM, format );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiuQtChartsPlotTools::dateTimeFormatForInterval( const QString& dateFormat,
|
||||
const QString& timeFormat,
|
||||
RiaQDateTimeTools::DateFormatComponents dateComponents,
|
||||
RiaQDateTimeTools::TimeFormatComponents timeComponents )
|
||||
{
|
||||
if ( dateComponents != RiaQDateTimeTools::DATE_FORMAT_UNSPECIFIED &&
|
||||
timeComponents != RiaQDateTimeTools::TimeFormatComponents::TIME_FORMAT_UNSPECIFIED )
|
||||
{
|
||||
return RiaQDateTimeTools::timeFormatString( timeFormat, timeComponents ) + "\n" +
|
||||
RiaQDateTimeTools::dateFormatString( dateFormat, dateComponents );
|
||||
}
|
||||
|
||||
// Default:
|
||||
return RiaQDateTimeTools::timeFormatString( timeFormat, RiaQDateTimeTools::TimeFormatComponents::TIME_FORMAT_NONE ) +
|
||||
"\n" +
|
||||
RiaQDateTimeTools::dateFormatString( dateFormat,
|
||||
RiaQDateTimeTools::DateFormatComponents::DATE_FORMAT_YEAR_MONTH_DAY );
|
||||
}
|
||||
Reference in New Issue
Block a user