mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Move setValueWithFieldChanged to a separate file
Make datavaluefield suitable for refactoring
This commit is contained in:
parent
ae054c3578
commit
a985ec005c
@ -38,6 +38,7 @@
|
|||||||
|
|
||||||
#include "cafCmdFeatureManager.h"
|
#include "cafCmdFeatureManager.h"
|
||||||
#include "cafPdmField.h"
|
#include "cafPdmField.h"
|
||||||
|
#include "cafPdmSetFieldValue.h"
|
||||||
#include "cafPdmUiFieldHandle.h"
|
#include "cafPdmUiFieldHandle.h"
|
||||||
#include "cafPdmUiItem.h"
|
#include "cafPdmUiItem.h"
|
||||||
#include "cafPdmUiObjectHandle.h"
|
#include "cafPdmUiObjectHandle.h"
|
||||||
@ -142,9 +143,9 @@ void ToggleItemsFeatureImpl::setObjectToggleStateForSelection( SelectionToggleTy
|
|||||||
{
|
{
|
||||||
caf::PdmField<bool>* field = dynamic_cast<caf::PdmField<bool>*>( uiObjectHandleChild->objectToggleField() );
|
caf::PdmField<bool>* field = dynamic_cast<caf::PdmField<bool>*>( uiObjectHandleChild->objectToggleField() );
|
||||||
|
|
||||||
if ( state == TOGGLE_ON ) field->setValueWithFieldChanged( true );
|
if ( state == TOGGLE_ON ) caf::setValueWithFieldChanged( field, true );
|
||||||
if ( state == TOGGLE_OFF ) field->setValueWithFieldChanged( false );
|
if ( state == TOGGLE_OFF ) caf::setValueWithFieldChanged( field, false );
|
||||||
if ( state == TOGGLE_SUBITEMS ) field->setValueWithFieldChanged( !( field->v() ) );
|
if ( state == TOGGLE_SUBITEMS ) caf::setValueWithFieldChanged( field, !( field->v() ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -158,11 +159,11 @@ void ToggleItemsFeatureImpl::setObjectToggleStateForSelection( SelectionToggleTy
|
|||||||
{
|
{
|
||||||
caf::PdmField<bool>* field = dynamic_cast<caf::PdmField<bool>*>( uiObjectHandle->objectToggleField() );
|
caf::PdmField<bool>* field = dynamic_cast<caf::PdmField<bool>*>( uiObjectHandle->objectToggleField() );
|
||||||
|
|
||||||
if ( state == TOGGLE_ON ) field->setValueWithFieldChanged( true );
|
if ( state == TOGGLE_ON ) caf::setValueWithFieldChanged( field, true );
|
||||||
if ( state == TOGGLE_OFF ) field->setValueWithFieldChanged( false );
|
if ( state == TOGGLE_OFF ) caf::setValueWithFieldChanged( field, false );
|
||||||
if ( state == TOGGLE_SUBITEMS || state == TOGGLE )
|
if ( state == TOGGLE_SUBITEMS || state == TOGGLE )
|
||||||
{
|
{
|
||||||
field->setValueWithFieldChanged( !( field->v() ) );
|
caf::setValueWithFieldChanged( field, !( field->v() ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
|
|
||||||
#include "cafPdmObject.h"
|
#include "cafPdmObject.h"
|
||||||
#include "cafPdmObjectHandle.h"
|
#include "cafPdmObjectHandle.h"
|
||||||
|
#include "cafPdmSetFieldValue.h"
|
||||||
#include "cafPdmUiItem.h"
|
#include "cafPdmUiItem.h"
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
|
||||||
@ -82,7 +83,7 @@ void ToggleItemsOnOthersOffFeature::onActionTriggered( bool isChecked )
|
|||||||
|
|
||||||
if ( field )
|
if ( field )
|
||||||
{
|
{
|
||||||
field->setValueWithFieldChanged( false );
|
caf::setValueWithFieldChanged( field, false );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +92,7 @@ void ToggleItemsOnOthersOffFeature::onActionTriggered( bool isChecked )
|
|||||||
{
|
{
|
||||||
caf::PdmField<bool>* field = dynamic_cast<caf::PdmField<bool>*>( selectedObject->objectToggleField() );
|
caf::PdmField<bool>* field = dynamic_cast<caf::PdmField<bool>*>( selectedObject->objectToggleField() );
|
||||||
|
|
||||||
field->setValueWithFieldChanged( true );
|
caf::setValueWithFieldChanged( field, true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ set(PROJECT_FILES
|
|||||||
cafPdmFieldCapability.h
|
cafPdmFieldCapability.h
|
||||||
cafPdmFieldHandle.cpp
|
cafPdmFieldHandle.cpp
|
||||||
cafPdmFieldHandle.h
|
cafPdmFieldHandle.h
|
||||||
|
cafPdmSetFieldValue.h
|
||||||
cafPdmObjectCapability.h
|
cafPdmObjectCapability.h
|
||||||
cafPdmFieldReorderCapability.cpp
|
cafPdmFieldReorderCapability.cpp
|
||||||
cafPdmFieldReorderCapability.h
|
cafPdmFieldReorderCapability.h
|
||||||
|
@ -41,7 +41,6 @@
|
|||||||
|
|
||||||
#include "cafAssert.h"
|
#include "cafAssert.h"
|
||||||
#include "cafInternalPdmValueFieldSpecializations.h"
|
#include "cafInternalPdmValueFieldSpecializations.h"
|
||||||
#include "cafPdmUiFieldHandleInterface.h"
|
|
||||||
|
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
@ -95,7 +94,6 @@ public:
|
|||||||
CAF_ASSERT( isInitializedByInitFieldMacro() );
|
CAF_ASSERT( isInitializedByInitFieldMacro() );
|
||||||
m_fieldValue = fieldValue;
|
m_fieldValue = fieldValue;
|
||||||
}
|
}
|
||||||
void setValueWithFieldChanged( const DataType& fieldValue );
|
|
||||||
|
|
||||||
// Implementation of PdmValueField interface
|
// Implementation of PdmValueField interface
|
||||||
|
|
||||||
@ -137,29 +135,4 @@ protected:
|
|||||||
DataType m_defaultFieldValue;
|
DataType m_defaultFieldValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
template <typename DataType>
|
|
||||||
void caf::PdmDataValueField<DataType>::setValueWithFieldChanged( const DataType& fieldValue )
|
|
||||||
{
|
|
||||||
CAF_ASSERT( isInitializedByInitFieldMacro() );
|
|
||||||
|
|
||||||
PdmUiFieldHandleInterface* uiFieldHandleInterface = capability<PdmUiFieldHandleInterface>();
|
|
||||||
if ( uiFieldHandleInterface )
|
|
||||||
{
|
|
||||||
QVariant oldValue = uiFieldHandleInterface->toUiBasedQVariant();
|
|
||||||
|
|
||||||
m_fieldValue = fieldValue;
|
|
||||||
|
|
||||||
QVariant newUiBasedQVariant = uiFieldHandleInterface->toUiBasedQVariant();
|
|
||||||
|
|
||||||
uiFieldHandleInterface->notifyFieldChanged( oldValue, newUiBasedQVariant );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_fieldValue = fieldValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // End of namespace caf
|
} // End of namespace caf
|
||||||
|
@ -0,0 +1,65 @@
|
|||||||
|
//##################################################################################################
|
||||||
|
//
|
||||||
|
// Custom Visualization Core library
|
||||||
|
// Copyright (C) 2023 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 "cafPdmFieldHandle.h"
|
||||||
|
#include "cafPdmUiFieldHandleInterface.h"
|
||||||
|
|
||||||
|
namespace caf
|
||||||
|
{
|
||||||
|
|
||||||
|
// This is a template function, and auto is used to allow the compiler to deduce the type of the arguments
|
||||||
|
void setValueWithFieldChanged( auto fieldHandle, auto fieldValue )
|
||||||
|
{
|
||||||
|
PdmUiFieldHandleInterface* uiFieldHandleInterface = fieldHandle->capability<PdmUiFieldHandleInterface>();
|
||||||
|
|
||||||
|
if ( uiFieldHandleInterface )
|
||||||
|
{
|
||||||
|
QVariant oldValue = uiFieldHandleInterface->toUiBasedQVariant();
|
||||||
|
|
||||||
|
fieldHandle->setValue( fieldValue );
|
||||||
|
|
||||||
|
QVariant newUiBasedQVariant = uiFieldHandleInterface->toUiBasedQVariant();
|
||||||
|
|
||||||
|
uiFieldHandleInterface->notifyFieldChanged( oldValue, newUiBasedQVariant );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fieldHandle->setValue( fieldValue );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // end namespace caf
|
Loading…
Reference in New Issue
Block a user