mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Implement signal handler
This commit is contained in:
parent
6856597770
commit
beaf4ebd5a
@ -121,6 +121,10 @@ void RimPlotCurve::FillStyle::setUp()
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimPlotCurve::RimPlotCurve()
|
||||
: appearanceChanged( this )
|
||||
, visibilityChanged( this )
|
||||
, dataChanged( this )
|
||||
, nameChanged( this )
|
||||
{
|
||||
CAF_PDM_InitObject( "Curve", ":/WellLogCurve16x16.png", "", "" );
|
||||
|
||||
@ -204,6 +208,7 @@ void RimPlotCurve::fieldChangedByUi( const caf::PdmFieldHandle* changedField, co
|
||||
{
|
||||
this->updateCurveVisibility();
|
||||
if ( m_showCurve() ) loadDataAndUpdate( false );
|
||||
visibilityChanged.send( m_showCurve() );
|
||||
}
|
||||
else if ( changedField == &m_curveName )
|
||||
{
|
||||
@ -232,6 +237,8 @@ void RimPlotCurve::fieldChangedByUi( const caf::PdmFieldHandle* changedField, co
|
||||
m_curveThickness.uiCapability()->setUiReadOnly( m_lineStyle() == RiuQwtPlotCurve::STYLE_NONE );
|
||||
m_curveInterpolation.uiCapability()->setUiReadOnly( m_lineStyle() == RiuQwtPlotCurve::STYLE_NONE );
|
||||
}
|
||||
|
||||
appearanceChanged.send();
|
||||
}
|
||||
else if ( changedField == &m_isUsingAutoName )
|
||||
{
|
||||
@ -241,6 +248,7 @@ void RimPlotCurve::fieldChangedByUi( const caf::PdmFieldHandle* changedField, co
|
||||
}
|
||||
|
||||
updateCurveNameAndUpdatePlotLegendAndTitle();
|
||||
nameChanged.send( curveName() );
|
||||
}
|
||||
else if ( changedField == &m_showLegend )
|
||||
{
|
||||
@ -504,6 +512,7 @@ void RimPlotCurve::updatePlotTitle()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimPlotCurve::updateLegendsInPlot()
|
||||
{
|
||||
nameChanged.send( curveName() );
|
||||
if ( m_parentQwtPlot != nullptr )
|
||||
{
|
||||
m_parentQwtPlot->updateLegend();
|
||||
|
@ -43,6 +43,12 @@ class RimPlotCurve : public caf::PdmObject
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
|
||||
public:
|
||||
caf::Signal<> appearanceChanged;
|
||||
caf::Signal<bool> visibilityChanged;
|
||||
caf::Signal<> dataChanged;
|
||||
caf::Signal<QString> nameChanged;
|
||||
|
||||
public:
|
||||
typedef caf::AppEnum<RiuQwtPlotCurve::CurveInterpolationEnum> CurveInterpolation;
|
||||
typedef caf::AppEnum<RiuQwtPlotCurve::LineStyleEnum> LineStyle;
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "RiaWellLogUnitTools.h"
|
||||
#include "RimPlotCurve.h"
|
||||
|
||||
#include "cafSignal.h"
|
||||
#include "cvfObject.h"
|
||||
|
||||
class RigWellLogCurveData;
|
||||
|
@ -86,6 +86,7 @@
|
||||
#include "cafSelectionManager.h"
|
||||
#include "cvfAssert.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QWheelEvent>
|
||||
|
||||
#include <algorithm>
|
||||
@ -283,6 +284,10 @@ RimWellLogTrack::RimWellLogTrack()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimWellLogTrack::~RimWellLogTrack()
|
||||
{
|
||||
for ( auto curve : m_curves )
|
||||
{
|
||||
disconnectCurveSignals( curve );
|
||||
}
|
||||
m_curves.deleteAllChildObjects();
|
||||
}
|
||||
|
||||
@ -730,14 +735,26 @@ void RimWellLogTrack::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimWellLogTrack::childFieldChangedByUi( const caf::PdmFieldHandle* changedChildField )
|
||||
void RimWellLogTrack::curveVisibilityChanged( const caf::SignalEmitter* emitter, bool visible )
|
||||
{
|
||||
qDebug() << "Curve turned " << ( visible ? "on" : "off" );
|
||||
if ( m_stackCurves )
|
||||
{
|
||||
updateStackedCurveData();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimWellLogTrack::curveAppearanceChanged( const caf::SignalEmitter* emitter )
|
||||
{
|
||||
if ( m_plotWidget )
|
||||
{
|
||||
m_plotWidget->scheduleReplot();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -1040,6 +1057,7 @@ QList<caf::PdmOptionItemInfo> RimWellLogTrack::calculateValueOptions( const caf:
|
||||
void RimWellLogTrack::addCurve( RimWellLogCurve* curve )
|
||||
{
|
||||
m_curves.push_back( curve );
|
||||
connectCurveSignals( curve );
|
||||
|
||||
if ( m_plotWidget )
|
||||
{
|
||||
@ -1053,6 +1071,7 @@ void RimWellLogTrack::addCurve( RimWellLogCurve* curve )
|
||||
void RimWellLogTrack::insertCurve( RimWellLogCurve* curve, size_t index )
|
||||
{
|
||||
m_curves.insert( index, curve );
|
||||
connectCurveSignals( curve );
|
||||
// Todo: Mark curve data to use either TVD or MD
|
||||
|
||||
if ( m_plotWidget )
|
||||
@ -1071,6 +1090,7 @@ void RimWellLogTrack::removeCurve( RimWellLogCurve* curve )
|
||||
{
|
||||
m_curves[index]->detachQwtCurve();
|
||||
m_curves.removeChildObject( curve );
|
||||
disconnectCurveSignals( curve );
|
||||
}
|
||||
}
|
||||
|
||||
@ -1823,6 +1843,11 @@ void RimWellLogTrack::initAfterRead()
|
||||
{
|
||||
m_colorShadingLegend = RimRegularLegendConfig::mapToColorLegend( m_colorShadingPalette_OBSOLETE() );
|
||||
}
|
||||
|
||||
for ( auto curve : m_curves )
|
||||
{
|
||||
connectCurveSignals( curve );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -1987,6 +2012,24 @@ std::vector<std::pair<double, double>> RimWellLogTrack::waterAndRockRegions( Ria
|
||||
return {};
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimWellLogTrack::connectCurveSignals( RimWellLogCurve* curve )
|
||||
{
|
||||
curve->visibilityChanged.connect( this, &RimWellLogTrack::curveVisibilityChanged );
|
||||
curve->appearanceChanged.connect( this, &RimWellLogTrack::curveAppearanceChanged );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimWellLogTrack::disconnectCurveSignals( RimWellLogCurve* curve )
|
||||
{
|
||||
curve->visibilityChanged.disconnect( this );
|
||||
curve->appearanceChanged.disconnect( this );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -250,7 +250,8 @@ private:
|
||||
void doRemoveFromCollection() override;
|
||||
|
||||
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
|
||||
void childFieldChangedByUi( const caf::PdmFieldHandle* changedChildField ) override;
|
||||
void curveVisibilityChanged( const caf::SignalEmitter* emitter, bool visible );
|
||||
void curveAppearanceChanged( const caf::SignalEmitter* emitter );
|
||||
|
||||
QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions,
|
||||
bool* useOptionsOnly ) override;
|
||||
@ -295,6 +296,9 @@ private:
|
||||
std::vector<std::pair<double, double>> waterAndRockRegions( RiaDefines::DepthTypeEnum depthType,
|
||||
const RigWellLogExtractor* extractor ) const;
|
||||
|
||||
void connectCurveSignals( RimWellLogCurve* curve );
|
||||
void disconnectCurveSignals( RimWellLogCurve* curve );
|
||||
|
||||
private:
|
||||
QString m_xAxisTitle;
|
||||
|
||||
|
@ -1392,7 +1392,7 @@ void RimSummaryPlot::updateStackedCurveDataForAxis( RiaDefines::PlotAxis plotAxi
|
||||
{
|
||||
curve->setFillStyle( Qt::SolidPattern );
|
||||
}
|
||||
curve->setOverrideCurveDataY( allTimeSteps, allStackedValues );
|
||||
// curve->setOverrideCurveDataY( allTimeSteps, allStackedValues );
|
||||
curve->setZOrder( zPos );
|
||||
zPos -= 1.0;
|
||||
}
|
||||
|
@ -47,6 +47,8 @@ set( PROJECT_FILES
|
||||
cafNotificationCenter.cpp
|
||||
cafNotificationCenter.h
|
||||
|
||||
cafSignal.h
|
||||
|
||||
cafTristate.cpp
|
||||
cafTristate.h
|
||||
cafFilePath.cpp
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include "cafAssert.h"
|
||||
#include "cafPdmBase.h"
|
||||
#include "cafSignalHandle.h"
|
||||
#include "cafSignal.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
@ -20,7 +20,7 @@ class PdmChildArrayFieldHandle;
|
||||
//==================================================================================================
|
||||
/// The base class of all objects
|
||||
//==================================================================================================
|
||||
class PdmObjectHandle : public SignalObserver
|
||||
class PdmObjectHandle : public SignalObserver, public SignalEmitter
|
||||
{
|
||||
public:
|
||||
PdmObjectHandle();
|
||||
|
106
Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafSignal.h
Normal file
106
Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafSignal.h
Normal file
@ -0,0 +1,106 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2020- Ceetron Solutions AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library 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.
|
||||
//
|
||||
// This library 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.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// This library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
#pragma once
|
||||
|
||||
#include "cafAssert.h"
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
namespace caf
|
||||
{
|
||||
class SignalObserver
|
||||
{
|
||||
public:
|
||||
virtual ~SignalObserver() = default;
|
||||
};
|
||||
|
||||
class SignalEmitter
|
||||
{
|
||||
public:
|
||||
virtual ~SignalEmitter() = default;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
/// General signal class.
|
||||
/// Connect any member function with the signature void(const Signal*, const SignalData* data)
|
||||
/// Connect with .connect(this, &Class::nameOfMethod)
|
||||
/// The method should accept that data may be nullptr
|
||||
//==================================================================================================
|
||||
template <typename... Args>
|
||||
class Signal
|
||||
{
|
||||
public:
|
||||
using MemberCallback = std::function<void( const SignalEmitter*, Args... args )>;
|
||||
|
||||
public:
|
||||
Signal( const SignalEmitter* emitter )
|
||||
: m_emitter( emitter )
|
||||
{
|
||||
}
|
||||
virtual ~Signal() = default;
|
||||
|
||||
template <typename ClassType>
|
||||
void connect( ClassType* observer, void ( ClassType::*method )( const SignalEmitter*, Args... args ) )
|
||||
{
|
||||
static_assert( std::is_convertible<ClassType*, SignalObserver*>::value,
|
||||
"Only classes that inherit SignalObserver can connect as an observer of a Signal." );
|
||||
MemberCallback lambda = [=]( const SignalEmitter* emitter, Args... args ) {
|
||||
// Call method
|
||||
( observer->*method )( emitter, args... );
|
||||
};
|
||||
m_observerCallbacks[observer] = lambda;
|
||||
}
|
||||
|
||||
void disconnect( SignalObserver* observer ) { m_observerCallbacks.erase( observer ); }
|
||||
void send( Args... args )
|
||||
{
|
||||
for ( auto observerCallbackPair : m_observerCallbacks )
|
||||
{
|
||||
observerCallbackPair.second( m_emitter, args... );
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Signal( const Signal& rhs ) = default;
|
||||
Signal& operator=( const Signal& rhs ) = default;
|
||||
|
||||
std::map<SignalObserver*, MemberCallback> m_observerCallbacks;
|
||||
const SignalEmitter* m_emitter;
|
||||
};
|
||||
} // namespace caf
|
Loading…
Reference in New Issue
Block a user