Working click matrix to change correlation plots

This commit is contained in:
Gaute Lindkvist 2020-05-04 19:47:32 +02:00
parent 8be36be06b
commit 27600fa57a
15 changed files with 261 additions and 129 deletions

View File

@ -26,6 +26,8 @@ ${SOURCE_GROUP_SOURCE_FILES}
) )
list(APPEND QT_MOC_HEADERS list(APPEND QT_MOC_HEADERS
${CMAKE_CURRENT_LIST_DIR}/RimCorrelationMatrixPlot.h
${CMAKE_CURRENT_LIST_DIR}/RimCorrelationReportPlot.h
) )
source_group( "ProjectDataModel\\CorrelationPlots" FILES ${SOURCE_GROUP_HEADER_FILES} ${SOURCE_GROUP_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/CMakeLists_files.cmake ) source_group( "ProjectDataModel\\CorrelationPlots" FILES ${SOURCE_GROUP_HEADER_FILES} ${SOURCE_GROUP_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/CMakeLists_files.cmake )

View File

@ -228,7 +228,13 @@ std::set<RifEclipseSummaryAddress> RimAbstractCorrelationPlot::addresses()
for ( RimSummaryCaseCollection* ensemble : analyserOfSelectedCurveDefs->m_ensembles ) for ( RimSummaryCaseCollection* ensemble : analyserOfSelectedCurveDefs->m_ensembles )
{ {
const std::set<RifEclipseSummaryAddress>& caseAddrs = ensemble->ensembleSummaryAddresses(); const std::set<RifEclipseSummaryAddress>& caseAddrs = ensemble->ensembleSummaryAddresses();
addresses.insert( caseAddrs.begin(), caseAddrs.end() ); for ( auto addr : caseAddrs )
{
if ( analyserOfSelectedCurveDefs->m_quantityNames.count( addr.quantityName() ) )
{
addresses.insert( addr );
}
}
} }
return addresses; return addresses;
@ -335,7 +341,7 @@ RiuQwtPlotWidget* RimAbstractCorrelationPlot::doCreatePlotViewWidget( QWidget* m
if ( !m_plotWidget ) if ( !m_plotWidget )
{ {
m_plotWidget = new RiuQwtPlotWidget( this, mainWindowParent ); m_plotWidget = new RiuQwtPlotWidget( this, mainWindowParent );
// updatePlotTitle(); updatePlotTitle();
} }
return m_plotWidget; return m_plotWidget;

View File

@ -46,6 +46,7 @@
#include "cvfScalarMapper.h" #include "cvfScalarMapper.h"
#include "qwt_plot_marker.h" #include "qwt_plot_marker.h"
#include "qwt_plot_shapeitem.h"
#include "qwt_scale_draw.h" #include "qwt_scale_draw.h"
#include "qwt_text.h" #include "qwt_text.h"
@ -56,6 +57,19 @@
CAF_PDM_SOURCE_INIT( RimCorrelationMatrixPlot, "CorrelationMatrixPlot" ); CAF_PDM_SOURCE_INIT( RimCorrelationMatrixPlot, "CorrelationMatrixPlot" );
class CorrelationMatrixShapeItem : public QwtPlotShapeItem
{
public:
CorrelationMatrixShapeItem( const QString& title = QString() )
: QwtPlotShapeItem( title )
{
}
public:
EnsembleParameter parameter;
RiaSummaryCurveDefinition curveDef;
};
class TextScaleDraw : public QwtScaleDraw class TextScaleDraw : public QwtScaleDraw
{ {
public: public:
@ -75,19 +89,20 @@ private:
std::map<size_t, QString> m_tickLabels; std::map<size_t, QString> m_tickLabels;
}; };
template <typename KeyType, typename ValueType>
class CorrelationMatrixRowOrColumn class CorrelationMatrixRowOrColumn
{ {
public: public:
CorrelationMatrixRowOrColumn( const QString& label, CorrelationMatrixRowOrColumn( const KeyType& key,
const std::vector<double>& values, const std::vector<double>& correlations,
const std::vector<QString>& entryLabels ) const std::vector<ValueType>& values )
: m_label( label ) : m_key( key )
, m_correlations( correlations )
, m_values( values ) , m_values( values )
, m_entryLabels( entryLabels )
, m_correlationSum( 0.0 ) , m_correlationSum( 0.0 )
{ {
bool anyValid = false; bool anyValid = false;
for ( auto value : values ) for ( auto value : correlations )
{ {
if ( RiaCurveDataTools::isValidValue( value, false ) ) if ( RiaCurveDataTools::isValidValue( value, false ) )
{ {
@ -103,13 +118,16 @@ public:
} }
} }
QString m_label; KeyType m_key;
std::vector<double> m_values; std::vector<double> m_correlations;
std::vector<QString> m_entryLabels; std::vector<ValueType> m_values;
double m_correlationSum; double m_correlationSum;
double m_correlationMagnitude; double m_correlationMagnitude;
}; };
using CorrelationMatrixColumn = CorrelationMatrixRowOrColumn<EnsembleParameter, RiaSummaryCurveDefinition>;
using CorrelationMatrixRow = CorrelationMatrixRowOrColumn<RiaSummaryCurveDefinition, EnsembleParameter>;
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -315,22 +333,24 @@ void RimCorrelationMatrixPlot::updateAxes()
m_plotWidget->setAxisLabelAlignment( QwtPlot::xBottom, Qt::AlignRight ); m_plotWidget->setAxisLabelAlignment( QwtPlot::xBottom, Qt::AlignRight );
} }
void eraseInvalidEntries( std::vector<CorrelationMatrixRowOrColumn>& matrix ) template <typename KeyType, typename ValueType>
void eraseInvalidEntries( std::vector<CorrelationMatrixRowOrColumn<KeyType, ValueType>>& matrix )
{ {
matrix.erase( std::remove_if( matrix.begin(), matrix.erase( std::remove_if( matrix.begin(),
matrix.end(), matrix.end(),
[]( const CorrelationMatrixRowOrColumn& entry ) { []( const CorrelationMatrixRowOrColumn<KeyType, ValueType>& entry ) {
return !RiaCurveDataTools::isValidValue( entry.m_correlationSum, false ); return !RiaCurveDataTools::isValidValue( entry.m_correlationSum, false );
} ), } ),
matrix.end() ); matrix.end() );
} }
void sortEntries( std::vector<CorrelationMatrixRowOrColumn>& matrix, bool sortByAbsoluteValues ) template <typename KeyType, typename ValueType>
void sortEntries( std::vector<CorrelationMatrixRowOrColumn<KeyType, ValueType>>& matrix, bool sortByAbsoluteValues )
{ {
std::sort( matrix.begin(), std::sort( matrix.begin(),
matrix.end(), matrix.end(),
[&sortByAbsoluteValues]( const CorrelationMatrixRowOrColumn& lhs, [&sortByAbsoluteValues]( const CorrelationMatrixRowOrColumn<KeyType, ValueType>& lhs,
const CorrelationMatrixRowOrColumn& rhs ) -> bool { const CorrelationMatrixRowOrColumn<KeyType, ValueType>& rhs ) -> bool {
if ( sortByAbsoluteValues ) if ( sortByAbsoluteValues )
return lhs.m_correlationMagnitude > rhs.m_correlationMagnitude; return lhs.m_correlationMagnitude > rhs.m_correlationMagnitude;
else else
@ -338,20 +358,22 @@ void sortEntries( std::vector<CorrelationMatrixRowOrColumn>& matrix, bool sortBy
} ); } );
} }
std::vector<CorrelationMatrixRowOrColumn> transpose( const std::vector<CorrelationMatrixRowOrColumn>& matrix ) template <typename KeyType, typename ValueType>
std::vector<CorrelationMatrixRowOrColumn<ValueType, KeyType>>
transpose( const std::vector<CorrelationMatrixRowOrColumn<KeyType, ValueType>>& matrix )
{ {
std::vector<CorrelationMatrixRowOrColumn> transposedMatrix; std::vector<CorrelationMatrixRowOrColumn<ValueType, KeyType>> transposedMatrix;
for ( size_t rowIdx = 0u; rowIdx < matrix[0].m_values.size(); ++rowIdx ) for ( size_t rowIdx = 0u; rowIdx < matrix[0].m_correlations.size(); ++rowIdx )
{ {
QString label = matrix[0].m_entryLabels[rowIdx]; ValueType key = matrix[0].m_values[rowIdx];
std::vector<double> values; std::vector<double> correlations;
std::vector<QString> entryLabels; std::vector<KeyType> values;
for ( size_t colIdx = 0u; colIdx < matrix.size(); ++colIdx ) for ( size_t colIdx = 0u; colIdx < matrix.size(); ++colIdx )
{ {
values.push_back( matrix[colIdx].m_values[rowIdx] ); correlations.push_back( matrix[colIdx].m_correlations[rowIdx] );
entryLabels.push_back( matrix[colIdx].m_label ); values.push_back( matrix[colIdx].m_key );
} }
transposedMatrix.push_back( CorrelationMatrixRowOrColumn( label, values, entryLabels ) ); transposedMatrix.push_back( CorrelationMatrixRowOrColumn<ValueType, KeyType>( key, correlations, values ) );
} }
return transposedMatrix; return transposedMatrix;
} }
@ -369,15 +391,15 @@ void RimCorrelationMatrixPlot::createMatrix()
auto curveDefs = curveDefinitions(); auto curveDefs = curveDefinitions();
if ( curveDefs.empty() ) return; if ( curveDefs.empty() ) return;
std::vector<CorrelationMatrixRowOrColumn> correlationMatrixColumns; std::vector<CorrelationMatrixColumn> correlationMatrixColumns;
for ( EnsembleParameter parameter : ensembleParameters() ) for ( EnsembleParameter parameter : ensembleParameters() )
{ {
if ( parameter.isNumeric() && parameter.isValid() ) if ( parameter.isNumeric() && parameter.isValid() )
{ {
bool anyValidResults = false; bool anyValidResults = false;
std::vector<double> correlations; std::vector<double> correlations;
std::vector<QString> resultLabels; std::vector<RiaSummaryCurveDefinition> selectedCurveDefs;
for ( auto curveDef : curveDefs ) for ( auto curveDef : curveDefs )
{ {
@ -386,8 +408,6 @@ void RimCorrelationMatrixPlot::createMatrix()
auto ensemble = curveDef.ensemble(); auto ensemble = curveDef.ensemble();
auto address = curveDef.summaryAddress(); auto address = curveDef.summaryAddress();
QString resultLabel = curveDef.curveDefinitionText();
if ( ensemble ) if ( ensemble )
{ {
std::vector<double> caseValuesAtTimestep; std::vector<double> caseValuesAtTimestep;
@ -442,12 +462,11 @@ void RimCorrelationMatrixPlot::createMatrix()
} }
} }
correlations.push_back( correlation ); correlations.push_back( correlation );
resultLabels.push_back( resultLabel ); selectedCurveDefs.push_back( curveDef );
} }
if ( anyValidResults ) if ( anyValidResults )
{ {
correlationMatrixColumns.push_back( correlationMatrixColumns.push_back( CorrelationMatrixColumn( parameter, correlations, selectedCurveDefs ) );
CorrelationMatrixRowOrColumn( parameter.name, correlations, resultLabels ) );
} }
} }
} }
@ -462,20 +481,22 @@ void RimCorrelationMatrixPlot::createMatrix()
for ( size_t rowIdx = 0u; rowIdx < correlationMatrixRows.size(); ++rowIdx ) for ( size_t rowIdx = 0u; rowIdx < correlationMatrixRows.size(); ++rowIdx )
{ {
for ( size_t colIdx = 0u; colIdx < correlationMatrixRows[rowIdx].m_values.size(); ++colIdx ) for ( size_t colIdx = 0u; colIdx < correlationMatrixRows[rowIdx].m_correlations.size(); ++colIdx )
{ {
double correlation = correlationMatrixRows[rowIdx].m_values[colIdx]; double correlation = correlationMatrixRows[rowIdx].m_correlations[colIdx];
auto label = QString( "%1" ).arg( correlation, 0, 'f', 2 ); auto label = QString( "%1" ).arg( correlation, 0, 'f', 2 );
cvf::Color3ub color = m_legendConfig->scalarMapper()->mapToColor( correlation ); cvf::Color3ub color = m_legendConfig->scalarMapper()->mapToColor( correlation );
QColor qColor( color.r(), color.g(), color.b() ); QColor qColor( color.r(), color.g(), color.b() );
QwtPlotItem* rectangle = RiuQwtPlotTools::createBoxShape( label, auto rectangle = RiuQwtPlotTools::createBoxShapeT<CorrelationMatrixShapeItem>( label,
(double)colIdx, (double)colIdx,
(double)colIdx + 1.0, (double)colIdx + 1.0,
(double)rowIdx, (double)rowIdx,
(double)rowIdx + 1, (double)rowIdx + 1,
qColor ); qColor );
QwtText textLabel( label ); rectangle->curveDef = correlationMatrixRows[rowIdx].m_key;
cvf::Color3f contrastColor = RiaColorTools::contrastColor( cvf::Color3f( color ) ); rectangle->parameter = correlationMatrixRows[rowIdx].m_values[colIdx];
QwtText textLabel( label );
cvf::Color3f contrastColor = RiaColorTools::contrastColor( cvf::Color3f( color ) );
textLabel.setColor( RiaColorTools::toQColor( contrastColor ) ); textLabel.setColor( RiaColorTools::toQColor( contrastColor ) );
QFont font = textLabel.font(); QFont font = textLabel.font();
font.setPixelSize( RiaFontCache::pointSizeToPixelSize( 7 ) ); font.setPixelSize( RiaFontCache::pointSizeToPixelSize( 7 ) );
@ -486,9 +507,9 @@ void RimCorrelationMatrixPlot::createMatrix()
marker->setYValue( rowIdx + 0.5 ); marker->setYValue( rowIdx + 0.5 );
rectangle->attach( m_plotWidget ); rectangle->attach( m_plotWidget );
marker->attach( m_plotWidget ); marker->attach( m_plotWidget );
m_paramLabels[colIdx] = correlationMatrixRows[rowIdx].m_entryLabels[colIdx]; m_paramLabels[colIdx] = correlationMatrixRows[rowIdx].m_values[colIdx].name;
} }
m_resultLabels[rowIdx] = correlationMatrixRows[rowIdx].m_label; m_resultLabels[rowIdx] = correlationMatrixRows[rowIdx].m_key.curveDefinitionText();
} }
} }
@ -519,3 +540,15 @@ void RimCorrelationMatrixPlot::updateLegend()
m_legendConfig->setAutomaticRanges( 0.0, 1.0, 0.0, 1.0 ); m_legendConfig->setAutomaticRanges( 0.0, 1.0, 0.0, 1.0 );
} }
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCorrelationMatrixPlot::onPlotItemSelected( QwtPlotItem* plotItem, bool toggle )
{
CorrelationMatrixShapeItem* matrixItem = dynamic_cast<CorrelationMatrixShapeItem*>( plotItem );
if ( matrixItem )
{
emit matrixCellSelected( matrixItem->parameter, matrixItem->curveDef );
}
}

View File

@ -33,6 +33,7 @@ class RiuGroupedBarChartBuilder;
//================================================================================================== //==================================================================================================
class RimCorrelationMatrixPlot : public RimAbstractCorrelationPlot class RimCorrelationMatrixPlot : public RimAbstractCorrelationPlot
{ {
Q_OBJECT;
CAF_PDM_HEADER_INIT; CAF_PDM_HEADER_INIT;
public: public:
@ -47,6 +48,9 @@ public:
bool showAbsoluteValues() const; bool showAbsoluteValues() const;
bool sortByAbsoluteValues() const; bool sortByAbsoluteValues() const;
signals:
void matrixCellSelected( const EnsembleParameter&, const RiaSummaryCurveDefinition& );
private: private:
// Overridden PDM methods // Overridden PDM methods
@ -67,6 +71,7 @@ private:
void createMatrix(); void createMatrix();
void updatePlotTitle() override; void updatePlotTitle() override;
void updateLegend() override; void updateLegend() override;
void onPlotItemSelected( QwtPlotItem* plotItem, bool toggle ) override;
private: private:
caf::PdmField<CorrelationFactorEnum> m_correlationFactor; caf::PdmField<CorrelationFactorEnum> m_correlationFactor;

View File

@ -291,7 +291,7 @@ void RimCorrelationPlot::updatePlotTitle()
m_description = QString( "%1 for %2" ).arg( m_correlationFactor().uiText() ).arg( m_selectedVarsUiField ); m_description = QString( "%1 for %2" ).arg( m_correlationFactor().uiText() ).arg( m_selectedVarsUiField );
} }
m_plotWidget->setPlotTitle( m_description ); m_plotWidget->setPlotTitle( m_description );
m_plotWidget->setPlotTitleEnabled( m_showPlotTitle && isMdiWindow() ); m_plotWidget->setPlotTitleEnabled( m_showPlotTitle );
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -315,7 +315,7 @@ void RimCorrelationPlot::setCorrelationFactor( CorrelationFactor factor )
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
bool RimCorrelationPlot::showAbsoluteValues() const bool RimCorrelationPlot::showAbsoluteValues() const
{ {
m_showAbsoluteValues; return m_showAbsoluteValues;
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@ -28,6 +28,7 @@
#include "cafPdmUiOrdering.h" #include "cafPdmUiOrdering.h"
#include "cafPdmUiTreeOrdering.h" #include "cafPdmUiTreeOrdering.h"
#include <QDebug>
#include <QImage> #include <QImage>
#include <QPixmap> #include <QPixmap>
#include <QStringList> #include <QStringList>
@ -61,6 +62,10 @@ RimCorrelationReportPlot::RimCorrelationReportPlot()
m_correlationMatrixPlot->setRowSpan( RimPlot::TWO ); m_correlationMatrixPlot->setRowSpan( RimPlot::TWO );
m_correlationPlot = new RimCorrelationPlot; m_correlationPlot = new RimCorrelationPlot;
m_parameterResultCrossPlot = new RimParameterResultCrossPlot; m_parameterResultCrossPlot = new RimParameterResultCrossPlot;
this->connect( m_correlationMatrixPlot(),
SIGNAL( matrixCellSelected( const EnsembleParameter&, const RiaSummaryCurveDefinition& ) ),
SLOT( onMatrixCellSelected( const EnsembleParameter&, const RiaSummaryCurveDefinition& ) ) );
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -185,6 +190,8 @@ void RimCorrelationReportPlot::recreatePlotWidgets()
m_viewer->addPlot( m_correlationMatrixPlot->viewer() ); m_viewer->addPlot( m_correlationMatrixPlot->viewer() );
m_viewer->addPlot( m_correlationPlot->viewer() ); m_viewer->addPlot( m_correlationPlot->viewer() );
m_viewer->addPlot( m_parameterResultCrossPlot->viewer() ); m_viewer->addPlot( m_parameterResultCrossPlot->viewer() );
m_viewer->scheduleUpdate();
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -222,7 +229,6 @@ QWidget* RimCorrelationReportPlot::createViewWidget( QWidget* mainWindowParent /
{ {
m_viewer = new RiuMultiPlotPage( this, mainWindowParent ); m_viewer = new RiuMultiPlotPage( this, mainWindowParent );
m_viewer->setPlotTitle( m_plotWindowTitle() ); m_viewer->setPlotTitle( m_plotWindowTitle() );
m_viewer->setSubTitlesVisible( true );
recreatePlotWidgets(); recreatePlotWidgets();
return m_viewer; return m_viewer;
@ -294,3 +300,17 @@ void RimCorrelationReportPlot::childFieldChangedByUi( const caf::PdmFieldHandle*
{ {
this->loadDataAndUpdate(); this->loadDataAndUpdate();
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCorrelationReportPlot::onMatrixCellSelected( const EnsembleParameter& param,
const RiaSummaryCurveDefinition& curveDef )
{
m_correlationPlot->setCurveDefinitions( { curveDef } );
m_correlationPlot->loadDataAndUpdate();
m_parameterResultCrossPlot->setCurveDefinitions( { curveDef } );
m_parameterResultCrossPlot->setEnsembleParameter( param.name );
m_parameterResultCrossPlot->loadDataAndUpdate();
// m_viewer->scheduleUpdate();
}

View File

@ -25,6 +25,7 @@
#include "cafPdmPtrField.h" #include "cafPdmPtrField.h"
#include <QDateTime> #include <QDateTime>
#include <QObject>
#include <QPointer> #include <QPointer>
class RimAnalysisPlotDataEntry; class RimAnalysisPlotDataEntry;
@ -34,8 +35,9 @@ class RimSummaryCaseCollection;
class RiuMultiPlotPage; class RiuMultiPlotPage;
class RimCorrelationReportPlot : public RimPlotWindow class RimCorrelationReportPlot : public QObject, public RimPlotWindow
{ {
Q_OBJECT;
CAF_PDM_HEADER_INIT; CAF_PDM_HEADER_INIT;
using CorrelationFactor = RimCorrelationPlot::CorrelationFactor; using CorrelationFactor = RimCorrelationPlot::CorrelationFactor;
using CorrelationFactorEnum = RimCorrelationPlot::CorrelationFactorEnum; using CorrelationFactorEnum = RimCorrelationPlot::CorrelationFactorEnum;
@ -71,6 +73,9 @@ private:
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override; void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
void childFieldChangedByUi( const caf::PdmFieldHandle* changedChildField ) override; void childFieldChangedByUi( const caf::PdmFieldHandle* changedChildField ) override;
private slots:
void onMatrixCellSelected( const EnsembleParameter& param, const RiaSummaryCurveDefinition& curveDef );
private: private:
caf::PdmProxyValueField<QString> m_plotWindowTitle; caf::PdmProxyValueField<QString> m_plotWindowTitle;

View File

@ -187,6 +187,8 @@ void RimParameterResultCrossPlot::updateAxes()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimParameterResultCrossPlot::createPoints() void RimParameterResultCrossPlot::createPoints()
{ {
detachAllCurves();
time_t selectedTimestep = m_timeStep().toTime_t(); time_t selectedTimestep = m_timeStep().toTime_t();
caf::ColorTable colorTable = RiaColorTables::categoryPaletteColors(); caf::ColorTable colorTable = RiaColorTables::categoryPaletteColors();

View File

@ -163,8 +163,8 @@ void RimPlot::attachPlotWidgetSignals( RimPlot* plot, RiuQwtPlotWidget* plotWidg
plot->connect( plotWidget, SIGNAL( plotSelected( bool ) ), SLOT( onPlotSelected( bool ) ) ); plot->connect( plotWidget, SIGNAL( plotSelected( bool ) ), SLOT( onPlotSelected( bool ) ) );
plot->connect( plotWidget, SIGNAL( axisSelected( int, bool ) ), SLOT( onAxisSelected( int, bool ) ) ); plot->connect( plotWidget, SIGNAL( axisSelected( int, bool ) ), SLOT( onAxisSelected( int, bool ) ) );
plot->connect( plotWidget, plot->connect( plotWidget,
SIGNAL( curveSelected( QwtPlotCurve*, bool ) ), SIGNAL( plotItemSelected( QwtPlotItem*, bool ) ),
SLOT( onCurveSelected( QwtPlotCurve*, bool ) ) ); SLOT( onPlotItemSelected( QwtPlotItem*, bool ) ) );
plot->connect( plotWidget, SIGNAL( onKeyPressEvent( QKeyEvent* ) ), SLOT( onKeyPressEvent( QKeyEvent* ) ) ); plot->connect( plotWidget, SIGNAL( onKeyPressEvent( QKeyEvent* ) ), SLOT( onKeyPressEvent( QKeyEvent* ) ) );
plot->connect( plotWidget, SIGNAL( onWheelEvent( QWheelEvent* ) ), SLOT( onWheelEvent( QWheelEvent* ) ) ); plot->connect( plotWidget, SIGNAL( onWheelEvent( QWheelEvent* ) ), SLOT( onWheelEvent( QWheelEvent* ) ) );
plot->connect( plotWidget, SIGNAL( destroyed() ), SLOT( onViewerDestroyed() ) ); plot->connect( plotWidget, SIGNAL( destroyed() ), SLOT( onViewerDestroyed() ) );
@ -199,18 +199,22 @@ void RimPlot::onPlotSelected( bool toggle )
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimPlot::onCurveSelected( QwtPlotCurve* curve, bool toggle ) void RimPlot::onPlotItemSelected( QwtPlotItem* plotItem, bool toggle )
{ {
RimPlotCurve* selectedCurve = dynamic_cast<RimPlotCurve*>( this->findPdmObjectFromQwtCurve( curve ) ); QwtPlotCurve* curve = dynamic_cast<QwtPlotCurve*>( plotItem );
if ( selectedCurve ) if ( curve )
{ {
if ( toggle ) RimPlotCurve* selectedCurve = dynamic_cast<RimPlotCurve*>( this->findPdmObjectFromQwtCurve( curve ) );
if ( selectedCurve )
{ {
RiuPlotMainWindowTools::toggleItemInSelection( selectedCurve ); if ( toggle )
} {
else RiuPlotMainWindowTools::toggleItemInSelection( selectedCurve );
{ }
RiuPlotMainWindowTools::selectAsCurrentItem( selectedCurve ); else
{
RiuPlotMainWindowTools::selectAsCurrentItem( selectedCurve );
}
} }
} }
} }

View File

@ -32,6 +32,7 @@
class RiuQwtPlotWidget; class RiuQwtPlotWidget;
class RimPlotCurve; class RimPlotCurve;
class QwtPlotCurve; class QwtPlotCurve;
class QwtPlotItem;
class QPaintDevice; class QPaintDevice;
class QWheelEvent; class QWheelEvent;
@ -104,7 +105,7 @@ private:
private slots: private slots:
void onPlotSelected( bool toggle ); void onPlotSelected( bool toggle );
virtual void onAxisSelected( int axis, bool toggle ) {} virtual void onAxisSelected( int axis, bool toggle ) {}
void onCurveSelected( QwtPlotCurve* curve, bool toggle ); virtual void onPlotItemSelected( QwtPlotItem* plotItem, bool toggle );
void onViewerDestroyed(); void onViewerDestroyed();
void onKeyPressEvent( QKeyEvent* event ); void onKeyPressEvent( QKeyEvent* event );
void onWheelEvent( QWheelEvent* event ); void onWheelEvent( QWheelEvent* event );

View File

@ -67,7 +67,7 @@ void RiuQwtPlotTools::setCommonPlotBehaviour( QwtPlot* plot )
plot->setAxisFont( QwtPlot::yRight, axisFont ); plot->setAxisFont( QwtPlot::yRight, axisFont );
// Axis title font // Axis title font
std::vector<QwtPlot::Axis> axes = {QwtPlot::xBottom, QwtPlot::xTop, QwtPlot::yLeft, QwtPlot::yRight}; std::vector<QwtPlot::Axis> axes = { QwtPlot::xBottom, QwtPlot::xTop, QwtPlot::yLeft, QwtPlot::yRight };
for ( QwtPlot::Axis axis : axes ) for ( QwtPlot::Axis axis : axes )
{ {
@ -131,14 +131,14 @@ void RiuQwtPlotTools::enableDateBasedBottomXAxis( QwtPlot*
{ {
QwtDateScaleDraw* scaleDraw = new QwtDateScaleDraw( Qt::UTC ); QwtDateScaleDraw* scaleDraw = new QwtDateScaleDraw( Qt::UTC );
std::set<QwtDate::IntervalType> intervals = {QwtDate::Year, std::set<QwtDate::IntervalType> intervals = { QwtDate::Year,
QwtDate::Month, QwtDate::Month,
QwtDate::Week, QwtDate::Week,
QwtDate::Day, QwtDate::Day,
QwtDate::Hour, QwtDate::Hour,
QwtDate::Minute, QwtDate::Minute,
QwtDate::Second, QwtDate::Second,
QwtDate::Millisecond}; QwtDate::Millisecond };
for ( QwtDate::IntervalType interval : intervals ) for ( QwtDate::IntervalType interval : intervals )
{ {
@ -217,26 +217,13 @@ QString RiuQwtPlotTools::dateTimeFormatForInterval( QwtDate::IntervalType
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
QwtPlotItem* RiuQwtPlotTools::createBoxShape( const QString& label, QwtPlotShapeItem* RiuQwtPlotTools::createBoxShape( const QString& label,
double startX, double startX,
double endX, double endX,
double startY, double startY,
double endY, double endY,
QColor color, QColor color,
Qt::BrushStyle brushStyle ) Qt::BrushStyle brushStyle )
{ {
QwtPlotShapeItem* columnShape = new QwtPlotShapeItem( label ); return createBoxShapeT<QwtPlotShapeItem>( label, startX, endX, startY, endY, color, brushStyle );
QPolygonF polygon;
polygon.push_back( QPointF( startX, startY ) );
polygon.push_back( QPointF( endX, startY ) );
polygon.push_back( QPointF( endX, endY ) );
polygon.push_back( QPointF( startX, endY ) );
polygon.push_back( QPointF( startX, startY ) );
columnShape->setPolygon( polygon );
columnShape->setXAxis( QwtPlot::xBottom );
columnShape->setBrush( QBrush( color, brushStyle ) );
columnShape->setLegendMode( QwtPlotShapeItem::LegendShape );
columnShape->setLegendIconSize( QSize( 16, 16 ) );
return columnShape;
} }

View File

@ -21,7 +21,7 @@
#include <qwt_date.h> #include <qwt_date.h>
class QwtPlot; class QwtPlot;
class QwtPlotItem; class QwtPlotShapeItem;
class RiuQwtPlotTools class RiuQwtPlotTools
{ {
@ -41,11 +41,48 @@ public:
RiaQDateTimeTools::DateFormatComponents dateComponents, RiaQDateTimeTools::DateFormatComponents dateComponents,
RiaQDateTimeTools::TimeFormatComponents timeComponents ); RiaQDateTimeTools::TimeFormatComponents timeComponents );
static QwtPlotItem* createBoxShape( const QString& label, static QwtPlotShapeItem* createBoxShape( const QString& label,
double startX, double startX,
double endX, double endX,
double startY, double startY,
double endY, double endY,
QColor color, QColor color,
Qt::BrushStyle brushStyle = Qt::SolidPattern ); Qt::BrushStyle brushStyle = Qt::SolidPattern );
template <typename PlotShapeItemType>
static PlotShapeItemType* createBoxShapeT( const QString& label,
double startX,
double endX,
double startY,
double endY,
QColor color,
Qt::BrushStyle brushStyle = Qt::SolidPattern );
}; };
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template <typename PlotShapeItemType>
PlotShapeItemType* RiuQwtPlotTools::createBoxShapeT( const QString& label,
double startX,
double endX,
double startY,
double endY,
QColor color,
Qt::BrushStyle brushStyle /*= Qt::SolidPattern */ )
{
PlotShapeItemType* columnShape = new PlotShapeItemType( label );
QPolygonF polygon;
polygon.push_back( QPointF( startX, startY ) );
polygon.push_back( QPointF( endX, startY ) );
polygon.push_back( QPointF( endX, endY ) );
polygon.push_back( QPointF( startX, endY ) );
polygon.push_back( QPointF( startX, startY ) );
columnShape->setPolygon( polygon );
columnShape->setXAxis( QwtPlot::xBottom );
columnShape->setBrush( QBrush( color, brushStyle ) );
columnShape->setLegendMode( QwtPlotShapeItem::LegendShape );
columnShape->setLegendIconSize( QSize( 16, 16 ) );
return columnShape;
}

View File

@ -43,6 +43,7 @@
#include "qwt_plot_marker.h" #include "qwt_plot_marker.h"
#include "qwt_plot_picker.h" #include "qwt_plot_picker.h"
#include "qwt_plot_renderer.h" #include "qwt_plot_renderer.h"
#include "qwt_plot_shapeitem.h"
#include "qwt_scale_draw.h" #include "qwt_scale_draw.h"
#include "qwt_scale_widget.h" #include "qwt_scale_widget.h"
#include "qwt_symbol.h" #include "qwt_symbol.h"
@ -632,7 +633,7 @@ bool RiuQwtPlotWidget::eventFilter( QObject* watched, QEvent* event )
!m_clickPosition.isNull() ) !m_clickPosition.isNull() )
{ {
endZoomOperations(); endZoomOperations();
selectClosestCurve( mouseEvent->pos(), toggleItemInSelection ); selectClosestPlotItem( mouseEvent->pos(), toggleItemInSelection );
m_clickPosition = QPoint(); m_clickPosition = QPoint();
return true; return true;
} }
@ -646,7 +647,7 @@ bool RiuQwtPlotWidget::eventFilter( QObject* watched, QEvent* event )
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::hideEvent( QHideEvent* event ) void RiuQwtPlotWidget::hideEvent( QHideEvent* event )
{ {
resetCurveHighlighting(); resetPlotItemHighlighting();
QwtPlot::hideEvent( event ); QwtPlot::hideEvent( event );
} }
@ -946,11 +947,11 @@ void RiuQwtPlotWidget::updateOverlayFrameLayout()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::selectClosestCurve( const QPoint& pos, bool toggleItemInSelection /*= false*/ ) void RiuQwtPlotWidget::selectClosestPlotItem( const QPoint& pos, bool toggleItemInSelection /*= false*/ )
{ {
QwtPlotCurve* closestCurve = nullptr; QwtPlotItem* closestItem = nullptr;
double distMin = DBL_MAX; double distMin = DBL_MAX;
int closestCurvePoint = -1; int closestCurvePoint = -1;
const QwtPlotItemList& itmList = itemList(); const QwtPlotItemList& itmList = itemList();
for ( QwtPlotItemIterator it = itmList.begin(); it != itmList.end(); it++ ) for ( QwtPlotItemIterator it = itmList.begin(); it != itmList.end(); it++ )
@ -962,24 +963,34 @@ void RiuQwtPlotWidget::selectClosestCurve( const QPoint& pos, bool toggleItemInS
int curvePoint = candidateCurve->closestPoint( pos, &dist ); int curvePoint = candidateCurve->closestPoint( pos, &dist );
if ( dist < distMin ) if ( dist < distMin )
{ {
closestCurve = candidateCurve; closestItem = candidateCurve;
distMin = dist; distMin = dist;
closestCurvePoint = curvePoint; closestCurvePoint = curvePoint;
} }
} }
else if ( ( *it )->rtti() == QwtPlotItem::Rtti_PlotShape )
{
QwtPlotShapeItem* shapeItem = static_cast<QwtPlotShapeItem*>( *it );
QPoint scalePos( invTransform( xBottom, pos.x() ), invTransform( yLeft, pos.y() ) );
if ( shapeItem->shape().boundingRect().contains( scalePos ) )
{
closestItem = *it;
distMin = 0.0;
}
}
} }
RiuPlotMainWindowTools::showPlotMainWindow(); RiuPlotMainWindowTools::showPlotMainWindow();
resetCurveHighlighting(); resetPlotItemHighlighting();
if ( closestCurve && distMin < 20 ) if ( closestItem && distMin < 20 )
{ {
// TODO: highlight all selected curves // TODO: highlight all selected curves
highlightCurve( closestCurve ); highlightPlotItem( closestItem );
emit curveSelected( closestCurve, toggleItemInSelection ); emit plotItemSelected( closestItem, toggleItemInSelection );
if ( distMin < 10 ) if ( distMin < 10 && ( closestItem )->rtti() == QwtPlotItem::Rtti_PlotCurve )
{ {
selectPoint( closestCurve, closestCurvePoint ); selectPoint( static_cast<QwtPlotCurve*>( closestItem ), closestCurvePoint );
} }
else else
{ {
@ -1012,14 +1023,15 @@ void RiuQwtPlotWidget::replot()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::highlightCurve( const QwtPlotCurve* closestCurve ) void RiuQwtPlotWidget::highlightPlotItem( const QwtPlotItem* closestItem )
{ {
// NB! Create a copy of the item list before the loop to avoid invalidated iterators when iterating the list // NB! Create a copy of the item list before the loop to avoid invalidated iterators when iterating the list
// plotCurve->setZ() causes the ordering of items in the list to change // plotCurve->setZ() causes the ordering of items in the list to change
auto plotItemList = this->itemList(); auto plotItemList = this->itemList();
for ( QwtPlotItem* plotItem : plotItemList ) for ( QwtPlotItem* plotItem : plotItemList )
{ {
QwtPlotCurve* plotCurve = dynamic_cast<QwtPlotCurve*>( plotItem ); QwtPlotCurve* plotCurve = dynamic_cast<QwtPlotCurve*>( plotItem );
QwtPlotShapeItem* plotShapeItem = dynamic_cast<QwtPlotShapeItem*>( plotItem );
if ( plotCurve ) if ( plotCurve )
{ {
QPen existingPen = plotCurve->pen(); QPen existingPen = plotCurve->pen();
@ -1037,7 +1049,7 @@ void RiuQwtPlotWidget::highlightCurve( const QwtPlotCurve* closestCurve )
} }
double zValue = plotCurve->z(); double zValue = plotCurve->z();
if ( plotCurve == closestCurve ) if ( plotCurve == closestItem )
{ {
plotCurve->setZ( zValue + 100.0 ); plotCurve->setZ( zValue + 100.0 );
} }
@ -1059,20 +1071,29 @@ void RiuQwtPlotWidget::highlightCurve( const QwtPlotCurve* closestCurve )
m_originalCurveColors.insert( std::make_pair( plotCurve, curveColors ) ); m_originalCurveColors.insert( std::make_pair( plotCurve, curveColors ) );
m_originalZValues.insert( std::make_pair( plotCurve, zValue ) ); m_originalZValues.insert( std::make_pair( plotCurve, zValue ) );
} }
else if ( plotShapeItem && plotItem == closestItem )
{
QPen pen = plotShapeItem->pen();
pen.setColor( QColor( Qt::green ) );
pen.setWidth( 3 );
plotShapeItem->setPen( pen );
plotShapeItem->setZ( plotShapeItem->z() + 100.0 );
}
} }
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::resetCurveHighlighting() void RiuQwtPlotWidget::resetPlotItemHighlighting()
{ {
// NB! Create a copy of the item list before the loop to avoid invalidated iterators when iterating the list // NB! Create a copy of the item list before the loop to avoid invalidated iterators when iterating the list
// plotCurve->setZ() causes the ordering of items in the list to change // plotCurve->setZ() causes the ordering of items in the list to change
auto plotItemList = this->itemList(); auto plotItemList = this->itemList();
for ( QwtPlotItem* plotItem : plotItemList ) for ( QwtPlotItem* plotItem : plotItemList )
{ {
QwtPlotCurve* plotCurve = dynamic_cast<QwtPlotCurve*>( plotItem ); QwtPlotCurve* plotCurve = dynamic_cast<QwtPlotCurve*>( plotItem );
QwtPlotShapeItem* plotShapeItem = dynamic_cast<QwtPlotShapeItem*>( plotItem );
if ( plotCurve && m_originalCurveColors.count( plotCurve ) ) if ( plotCurve && m_originalCurveColors.count( plotCurve ) )
{ {
const QPen& existingPen = plotCurve->pen(); const QPen& existingPen = plotCurve->pen();
@ -1088,6 +1109,14 @@ void RiuQwtPlotWidget::resetCurveHighlighting()
symbol->setPen( colors.symbolLineColor, symbol->pen().width(), symbol->pen().style() ); symbol->setPen( colors.symbolLineColor, symbol->pen().width(), symbol->pen().style() );
} }
} }
else if ( plotShapeItem )
{
QPen pen = plotShapeItem->pen();
pen.setColor( QColor( Qt::black ) );
pen.setWidth( 1 );
plotShapeItem->setPen( pen );
plotShapeItem->setZ( plotShapeItem->z() - 100.0 );
}
} }
m_originalCurveColors.clear(); m_originalCurveColors.clear();
m_originalZValues.clear(); m_originalZValues.clear();

View File

@ -39,6 +39,7 @@ class QwtLegend;
class QwtPicker; class QwtPicker;
class QwtPlotCurve; class QwtPlotCurve;
class QwtPlotGrid; class QwtPlotGrid;
class QwtPlotItem;
class QwtPlotMarker; class QwtPlotMarker;
class QwtPlotPicker; class QwtPlotPicker;
@ -134,7 +135,7 @@ public:
signals: signals:
void plotSelected( bool toggleSelection ); void plotSelected( bool toggleSelection );
void axisSelected( int axisId, bool toggleSelection ); void axisSelected( int axisId, bool toggleSelection );
void curveSelected( QwtPlotCurve* curve, bool toggleSelection ); void plotItemSelected( QwtPlotItem* plotItem, bool toggleSelection );
void onKeyPressEvent( QKeyEvent* event ); void onKeyPressEvent( QKeyEvent* event );
void onWheelEvent( QWheelEvent* event ); void onWheelEvent( QWheelEvent* event );
@ -157,12 +158,12 @@ protected:
virtual void endZoomOperations(); virtual void endZoomOperations();
private: private:
void selectClosestCurve( const QPoint& pos, bool toggleItemInSelection = false ); void selectClosestPlotItem( const QPoint& pos, bool toggleItemInSelection = false );
static int defaultMinimumWidth(); static int defaultMinimumWidth();
void replot() override; void replot() override;
void highlightCurve( const QwtPlotCurve* closestCurve ); void highlightPlotItem( const QwtPlotItem* closestItem );
void resetCurveHighlighting(); void resetPlotItemHighlighting();
void onAxisSelected( QwtScaleWidget* scale, bool toggleItemInSelection ); void onAxisSelected( QwtScaleWidget* scale, bool toggleItemInSelection );
void recalculateAxisExtents( QwtPlot::Axis axis ); void recalculateAxisExtents( QwtPlot::Axis axis );

View File

@ -407,11 +407,11 @@ QString PdmPythonGenerator::dataTypeString( const PdmFieldHandle* field, bool us
QString dataType = xmlObj->dataTypeName(); QString dataType = xmlObj->dataTypeName();
std::map<QString, QString> builtins = {{QString::fromStdString( typeid( double ).name() ), "float"}, std::map<QString, QString> builtins = { { QString::fromStdString( typeid( double ).name() ), "float" },
{QString::fromStdString( typeid( float ).name() ), "float"}, { QString::fromStdString( typeid( float ).name() ), "float" },
{QString::fromStdString( typeid( int ).name() ), "int"}, { QString::fromStdString( typeid( int ).name() ), "int" },
{QString::fromStdString( typeid( time_t ).name() ), "time"}, { QString::fromStdString( typeid( time_t ).name() ), "time" },
{QString::fromStdString( typeid( QString ).name() ), "str"}}; { QString::fromStdString( typeid( QString ).name() ), "str" } };
bool foundBuiltin = false; bool foundBuiltin = false;
for ( auto builtin : builtins ) for ( auto builtin : builtins )