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
${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 )

View File

@ -228,7 +228,13 @@ std::set<RifEclipseSummaryAddress> RimAbstractCorrelationPlot::addresses()
for ( RimSummaryCaseCollection* ensemble : analyserOfSelectedCurveDefs->m_ensembles )
{
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;
@ -335,7 +341,7 @@ RiuQwtPlotWidget* RimAbstractCorrelationPlot::doCreatePlotViewWidget( QWidget* m
if ( !m_plotWidget )
{
m_plotWidget = new RiuQwtPlotWidget( this, mainWindowParent );
// updatePlotTitle();
updatePlotTitle();
}
return m_plotWidget;

View File

@ -46,6 +46,7 @@
#include "cvfScalarMapper.h"
#include "qwt_plot_marker.h"
#include "qwt_plot_shapeitem.h"
#include "qwt_scale_draw.h"
#include "qwt_text.h"
@ -56,6 +57,19 @@
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
{
public:
@ -75,19 +89,20 @@ private:
std::map<size_t, QString> m_tickLabels;
};
template <typename KeyType, typename ValueType>
class CorrelationMatrixRowOrColumn
{
public:
CorrelationMatrixRowOrColumn( const QString& label,
const std::vector<double>& values,
const std::vector<QString>& entryLabels )
: m_label( label )
CorrelationMatrixRowOrColumn( const KeyType& key,
const std::vector<double>& correlations,
const std::vector<ValueType>& values )
: m_key( key )
, m_correlations( correlations )
, m_values( values )
, m_entryLabels( entryLabels )
, m_correlationSum( 0.0 )
{
bool anyValid = false;
for ( auto value : values )
for ( auto value : correlations )
{
if ( RiaCurveDataTools::isValidValue( value, false ) )
{
@ -103,13 +118,16 @@ public:
}
}
QString m_label;
std::vector<double> m_values;
std::vector<QString> m_entryLabels;
double m_correlationSum;
double m_correlationMagnitude;
KeyType m_key;
std::vector<double> m_correlations;
std::vector<ValueType> m_values;
double m_correlationSum;
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 );
}
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.end(),
[]( const CorrelationMatrixRowOrColumn& entry ) {
[]( const CorrelationMatrixRowOrColumn<KeyType, ValueType>& entry ) {
return !RiaCurveDataTools::isValidValue( entry.m_correlationSum, false );
} ),
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(),
matrix.end(),
[&sortByAbsoluteValues]( const CorrelationMatrixRowOrColumn& lhs,
const CorrelationMatrixRowOrColumn& rhs ) -> bool {
[&sortByAbsoluteValues]( const CorrelationMatrixRowOrColumn<KeyType, ValueType>& lhs,
const CorrelationMatrixRowOrColumn<KeyType, ValueType>& rhs ) -> bool {
if ( sortByAbsoluteValues )
return lhs.m_correlationMagnitude > rhs.m_correlationMagnitude;
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;
for ( size_t rowIdx = 0u; rowIdx < matrix[0].m_values.size(); ++rowIdx )
std::vector<CorrelationMatrixRowOrColumn<ValueType, KeyType>> transposedMatrix;
for ( size_t rowIdx = 0u; rowIdx < matrix[0].m_correlations.size(); ++rowIdx )
{
QString label = matrix[0].m_entryLabels[rowIdx];
std::vector<double> values;
std::vector<QString> entryLabels;
ValueType key = matrix[0].m_values[rowIdx];
std::vector<double> correlations;
std::vector<KeyType> values;
for ( size_t colIdx = 0u; colIdx < matrix.size(); ++colIdx )
{
values.push_back( matrix[colIdx].m_values[rowIdx] );
entryLabels.push_back( matrix[colIdx].m_label );
correlations.push_back( matrix[colIdx].m_correlations[rowIdx] );
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;
}
@ -369,15 +391,15 @@ void RimCorrelationMatrixPlot::createMatrix()
auto curveDefs = curveDefinitions();
if ( curveDefs.empty() ) return;
std::vector<CorrelationMatrixRowOrColumn> correlationMatrixColumns;
std::vector<CorrelationMatrixColumn> correlationMatrixColumns;
for ( EnsembleParameter parameter : ensembleParameters() )
{
if ( parameter.isNumeric() && parameter.isValid() )
{
bool anyValidResults = false;
std::vector<double> correlations;
std::vector<QString> resultLabels;
bool anyValidResults = false;
std::vector<double> correlations;
std::vector<RiaSummaryCurveDefinition> selectedCurveDefs;
for ( auto curveDef : curveDefs )
{
@ -386,8 +408,6 @@ void RimCorrelationMatrixPlot::createMatrix()
auto ensemble = curveDef.ensemble();
auto address = curveDef.summaryAddress();
QString resultLabel = curveDef.curveDefinitionText();
if ( ensemble )
{
std::vector<double> caseValuesAtTimestep;
@ -442,12 +462,11 @@ void RimCorrelationMatrixPlot::createMatrix()
}
}
correlations.push_back( correlation );
resultLabels.push_back( resultLabel );
selectedCurveDefs.push_back( curveDef );
}
if ( anyValidResults )
{
correlationMatrixColumns.push_back(
CorrelationMatrixRowOrColumn( parameter.name, correlations, resultLabels ) );
correlationMatrixColumns.push_back( CorrelationMatrixColumn( parameter, correlations, selectedCurveDefs ) );
}
}
}
@ -462,20 +481,22 @@ void RimCorrelationMatrixPlot::createMatrix()
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 );
cvf::Color3ub color = m_legendConfig->scalarMapper()->mapToColor( correlation );
QColor qColor( color.r(), color.g(), color.b() );
QwtPlotItem* rectangle = RiuQwtPlotTools::createBoxShape( label,
(double)colIdx,
(double)colIdx + 1.0,
(double)rowIdx,
(double)rowIdx + 1,
qColor );
QwtText textLabel( label );
cvf::Color3f contrastColor = RiaColorTools::contrastColor( cvf::Color3f( color ) );
auto rectangle = RiuQwtPlotTools::createBoxShapeT<CorrelationMatrixShapeItem>( label,
(double)colIdx,
(double)colIdx + 1.0,
(double)rowIdx,
(double)rowIdx + 1,
qColor );
rectangle->curveDef = correlationMatrixRows[rowIdx].m_key;
rectangle->parameter = correlationMatrixRows[rowIdx].m_values[colIdx];
QwtText textLabel( label );
cvf::Color3f contrastColor = RiaColorTools::contrastColor( cvf::Color3f( color ) );
textLabel.setColor( RiaColorTools::toQColor( contrastColor ) );
QFont font = textLabel.font();
font.setPixelSize( RiaFontCache::pointSizeToPixelSize( 7 ) );
@ -486,9 +507,9 @@ void RimCorrelationMatrixPlot::createMatrix()
marker->setYValue( rowIdx + 0.5 );
rectangle->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 );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
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
{
Q_OBJECT;
CAF_PDM_HEADER_INIT;
public:
@ -47,6 +48,9 @@ public:
bool showAbsoluteValues() const;
bool sortByAbsoluteValues() const;
signals:
void matrixCellSelected( const EnsembleParameter&, const RiaSummaryCurveDefinition& );
private:
// Overridden PDM methods
@ -67,6 +71,7 @@ private:
void createMatrix();
void updatePlotTitle() override;
void updateLegend() override;
void onPlotItemSelected( QwtPlotItem* plotItem, bool toggle ) override;
private:
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_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
{
m_showAbsoluteValues;
return m_showAbsoluteValues;
}
//--------------------------------------------------------------------------------------------------

View File

@ -28,6 +28,7 @@
#include "cafPdmUiOrdering.h"
#include "cafPdmUiTreeOrdering.h"
#include <QDebug>
#include <QImage>
#include <QPixmap>
#include <QStringList>
@ -61,6 +62,10 @@ RimCorrelationReportPlot::RimCorrelationReportPlot()
m_correlationMatrixPlot->setRowSpan( RimPlot::TWO );
m_correlationPlot = new RimCorrelationPlot;
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_correlationPlot->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->setPlotTitle( m_plotWindowTitle() );
m_viewer->setSubTitlesVisible( true );
recreatePlotWidgets();
return m_viewer;
@ -294,3 +300,17 @@ void RimCorrelationReportPlot::childFieldChangedByUi( const caf::PdmFieldHandle*
{
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 <QDateTime>
#include <QObject>
#include <QPointer>
class RimAnalysisPlotDataEntry;
@ -34,8 +35,9 @@ class RimSummaryCaseCollection;
class RiuMultiPlotPage;
class RimCorrelationReportPlot : public RimPlotWindow
class RimCorrelationReportPlot : public QObject, public RimPlotWindow
{
Q_OBJECT;
CAF_PDM_HEADER_INIT;
using CorrelationFactor = RimCorrelationPlot::CorrelationFactor;
using CorrelationFactorEnum = RimCorrelationPlot::CorrelationFactorEnum;
@ -71,6 +73,9 @@ private:
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
void childFieldChangedByUi( const caf::PdmFieldHandle* changedChildField ) override;
private slots:
void onMatrixCellSelected( const EnsembleParameter& param, const RiaSummaryCurveDefinition& curveDef );
private:
caf::PdmProxyValueField<QString> m_plotWindowTitle;

View File

@ -187,6 +187,8 @@ void RimParameterResultCrossPlot::updateAxes()
//--------------------------------------------------------------------------------------------------
void RimParameterResultCrossPlot::createPoints()
{
detachAllCurves();
time_t selectedTimestep = m_timeStep().toTime_t();
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( axisSelected( int, bool ) ), SLOT( onAxisSelected( int, bool ) ) );
plot->connect( plotWidget,
SIGNAL( curveSelected( QwtPlotCurve*, bool ) ),
SLOT( onCurveSelected( QwtPlotCurve*, bool ) ) );
SIGNAL( plotItemSelected( QwtPlotItem*, bool ) ),
SLOT( onPlotItemSelected( QwtPlotItem*, bool ) ) );
plot->connect( plotWidget, SIGNAL( onKeyPressEvent( QKeyEvent* ) ), SLOT( onKeyPressEvent( QKeyEvent* ) ) );
plot->connect( plotWidget, SIGNAL( onWheelEvent( QWheelEvent* ) ), SLOT( onWheelEvent( QWheelEvent* ) ) );
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 ) );
if ( selectedCurve )
QwtPlotCurve* curve = dynamic_cast<QwtPlotCurve*>( plotItem );
if ( curve )
{
if ( toggle )
RimPlotCurve* selectedCurve = dynamic_cast<RimPlotCurve*>( this->findPdmObjectFromQwtCurve( curve ) );
if ( selectedCurve )
{
RiuPlotMainWindowTools::toggleItemInSelection( selectedCurve );
}
else
{
RiuPlotMainWindowTools::selectAsCurrentItem( selectedCurve );
if ( toggle )
{
RiuPlotMainWindowTools::toggleItemInSelection( selectedCurve );
}
else
{
RiuPlotMainWindowTools::selectAsCurrentItem( selectedCurve );
}
}
}
}

View File

@ -32,6 +32,7 @@
class RiuQwtPlotWidget;
class RimPlotCurve;
class QwtPlotCurve;
class QwtPlotItem;
class QPaintDevice;
class QWheelEvent;
@ -104,7 +105,7 @@ private:
private slots:
void onPlotSelected( 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 onKeyPressEvent( QKeyEvent* event );
void onWheelEvent( QWheelEvent* event );

View File

@ -67,7 +67,7 @@ void RiuQwtPlotTools::setCommonPlotBehaviour( QwtPlot* plot )
plot->setAxisFont( QwtPlot::yRight, axisFont );
// 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 )
{
@ -131,14 +131,14 @@ void RiuQwtPlotTools::enableDateBasedBottomXAxis( QwtPlot*
{
QwtDateScaleDraw* scaleDraw = new QwtDateScaleDraw( Qt::UTC );
std::set<QwtDate::IntervalType> intervals = {QwtDate::Year,
QwtDate::Month,
QwtDate::Week,
QwtDate::Day,
QwtDate::Hour,
QwtDate::Minute,
QwtDate::Second,
QwtDate::Millisecond};
std::set<QwtDate::IntervalType> intervals = { QwtDate::Year,
QwtDate::Month,
QwtDate::Week,
QwtDate::Day,
QwtDate::Hour,
QwtDate::Minute,
QwtDate::Second,
QwtDate::Millisecond };
for ( QwtDate::IntervalType interval : intervals )
{
@ -217,26 +217,13 @@ QString RiuQwtPlotTools::dateTimeFormatForInterval( QwtDate::IntervalType
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QwtPlotItem* RiuQwtPlotTools::createBoxShape( const QString& label,
double startX,
double endX,
double startY,
double endY,
QColor color,
Qt::BrushStyle brushStyle )
QwtPlotShapeItem* RiuQwtPlotTools::createBoxShape( const QString& label,
double startX,
double endX,
double startY,
double endY,
QColor color,
Qt::BrushStyle brushStyle )
{
QwtPlotShapeItem* columnShape = new QwtPlotShapeItem( 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;
return createBoxShapeT<QwtPlotShapeItem>( label, startX, endX, startY, endY, color, brushStyle );
}

View File

@ -21,7 +21,7 @@
#include <qwt_date.h>
class QwtPlot;
class QwtPlotItem;
class QwtPlotShapeItem;
class RiuQwtPlotTools
{
@ -41,11 +41,48 @@ public:
RiaQDateTimeTools::DateFormatComponents dateComponents,
RiaQDateTimeTools::TimeFormatComponents timeComponents );
static QwtPlotItem* createBoxShape( const QString& label,
double startX,
double endX,
double startY,
double endY,
QColor color,
Qt::BrushStyle brushStyle = Qt::SolidPattern );
static QwtPlotShapeItem* createBoxShape( const QString& label,
double startX,
double endX,
double startY,
double endY,
QColor color,
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_picker.h"
#include "qwt_plot_renderer.h"
#include "qwt_plot_shapeitem.h"
#include "qwt_scale_draw.h"
#include "qwt_scale_widget.h"
#include "qwt_symbol.h"
@ -632,7 +633,7 @@ bool RiuQwtPlotWidget::eventFilter( QObject* watched, QEvent* event )
!m_clickPosition.isNull() )
{
endZoomOperations();
selectClosestCurve( mouseEvent->pos(), toggleItemInSelection );
selectClosestPlotItem( mouseEvent->pos(), toggleItemInSelection );
m_clickPosition = QPoint();
return true;
}
@ -646,7 +647,7 @@ bool RiuQwtPlotWidget::eventFilter( QObject* watched, QEvent* event )
//--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::hideEvent( QHideEvent* event )
{
resetCurveHighlighting();
resetPlotItemHighlighting();
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;
double distMin = DBL_MAX;
int closestCurvePoint = -1;
QwtPlotItem* closestItem = nullptr;
double distMin = DBL_MAX;
int closestCurvePoint = -1;
const QwtPlotItemList& itmList = itemList();
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 );
if ( dist < distMin )
{
closestCurve = candidateCurve;
closestItem = candidateCurve;
distMin = dist;
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();
resetCurveHighlighting();
if ( closestCurve && distMin < 20 )
resetPlotItemHighlighting();
if ( closestItem && distMin < 20 )
{
// TODO: highlight all selected curves
highlightCurve( closestCurve );
emit curveSelected( closestCurve, toggleItemInSelection );
highlightPlotItem( closestItem );
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
{
@ -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
// plotCurve->setZ() causes the ordering of items in the list to change
auto plotItemList = this->itemList();
for ( QwtPlotItem* plotItem : plotItemList )
{
QwtPlotCurve* plotCurve = dynamic_cast<QwtPlotCurve*>( plotItem );
QwtPlotCurve* plotCurve = dynamic_cast<QwtPlotCurve*>( plotItem );
QwtPlotShapeItem* plotShapeItem = dynamic_cast<QwtPlotShapeItem*>( plotItem );
if ( plotCurve )
{
QPen existingPen = plotCurve->pen();
@ -1037,7 +1049,7 @@ void RiuQwtPlotWidget::highlightCurve( const QwtPlotCurve* closestCurve )
}
double zValue = plotCurve->z();
if ( plotCurve == closestCurve )
if ( plotCurve == closestItem )
{
plotCurve->setZ( zValue + 100.0 );
}
@ -1059,20 +1071,29 @@ void RiuQwtPlotWidget::highlightCurve( const QwtPlotCurve* closestCurve )
m_originalCurveColors.insert( std::make_pair( plotCurve, curveColors ) );
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
// plotCurve->setZ() causes the ordering of items in the list to change
auto plotItemList = this->itemList();
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 ) )
{
const QPen& existingPen = plotCurve->pen();
@ -1088,6 +1109,14 @@ void RiuQwtPlotWidget::resetCurveHighlighting()
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_originalZValues.clear();

View File

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

View File

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