-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add static function to define a subset of enums to be used for AppEnum
Add a static map between field keyword and a subset of enum values to be displayed in the GUI If a subset is defined, automatically calculate value options for this subset, otherwise, use all enums Improve the macro so it is possible to use the `EnumType` instead of `AppEnum<EnumType>` when defining the default value
- Loading branch information
Showing
13 changed files
with
204 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
Fwk/AppFwk/cafTests/cafTestApplication/ApplicationEnum.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
|
||
#include "ApplicationEnum.h" | ||
#include "cafPdmUiListEditor.h" | ||
#include "cafPdmUiTreeSelectionEditor.h" | ||
|
||
template <> | ||
void caf::AppEnum<ApplicationEnum::MyEnumType>::setUp() | ||
{ | ||
addItem( ApplicationEnum::MyEnumType::T1, "T1", "T 1" ); | ||
addItem( ApplicationEnum::MyEnumType::T2, "T2", "T 2" ); | ||
addItem( ApplicationEnum::MyEnumType::T3, "T3", "T 3" ); | ||
addItem( ApplicationEnum::MyEnumType::T4, "T4", "T 4" ); | ||
addItem( ApplicationEnum::MyEnumType::T5, "T5", "T 5" ); | ||
addItem( ApplicationEnum::MyEnumType::T6, "T5", "T 6" ); | ||
addItem( ApplicationEnum::MyEnumType::T7, "T6", "T 7" ); | ||
|
||
setDefault( ApplicationEnum::MyEnumType::T4 ); | ||
} | ||
|
||
CAF_PDM_SOURCE_INIT( ApplicationEnum, "ApplicationEnum" ); | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// | ||
//-------------------------------------------------------------------------------------------------- | ||
ApplicationEnum::ApplicationEnum() | ||
{ | ||
CAF_PDM_InitObject( "Application Enum", "", "", "" ); | ||
|
||
// Enum field displaying all defined enums | ||
CAF_PDM_InitFieldNoDefault( &m_enumField, "EnumField", "All Enums" ); | ||
|
||
// Enum field displaying a subset of the defined enums using the static function setEnumSubset() | ||
CAF_PDM_InitField( &m_enum2Field, "Enum2Field", MyEnumType::T6, "Subset using setEnumSubset()" ); | ||
caf::AppEnum<MyEnumType>::setEnumSubset( m_enum2Field.keyword(), { MyEnumType::T2, MyEnumType::T6 } ); | ||
|
||
// Enum field displaying a subset of the defined enums using calculateValueOptions() | ||
CAF_PDM_InitFieldNoDefault( &m_enum3Field, "Enum3Field", "Subset using calculateValueOptions()" ); | ||
m_enum3Field = MyEnumType::T2; | ||
} | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// | ||
//-------------------------------------------------------------------------------------------------- | ||
QList<caf::PdmOptionItemInfo> ApplicationEnum::calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions ) | ||
{ | ||
if ( fieldNeedingOptions == &m_enum3Field ) | ||
{ | ||
QList<caf::PdmOptionItemInfo> options; | ||
|
||
options.push_back( | ||
caf::PdmOptionItemInfo( caf::AppEnum<ApplicationEnum::MyEnumType>::uiText( ApplicationEnum::MyEnumType::T2 ), | ||
ApplicationEnum::MyEnumType::T2 ) ); | ||
|
||
options.push_back( | ||
caf::PdmOptionItemInfo( caf::AppEnum<ApplicationEnum::MyEnumType>::uiText( ApplicationEnum::MyEnumType::T3 ), | ||
ApplicationEnum::MyEnumType::T3 ) ); | ||
|
||
return options; | ||
} | ||
|
||
return {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma once | ||
|
||
#include "cafPdmField.h" | ||
#include "cafPdmObject.h" | ||
|
||
class ApplicationEnum : public caf::PdmObject | ||
{ | ||
CAF_PDM_HEADER_INIT; | ||
|
||
public: | ||
enum class MyEnumType | ||
{ | ||
T1, | ||
T2, | ||
T3, | ||
T4, | ||
T5, | ||
T6, | ||
T7 | ||
}; | ||
|
||
public: | ||
ApplicationEnum(); | ||
|
||
private: | ||
QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions ) override; | ||
|
||
private: | ||
caf::PdmField<caf::AppEnum<MyEnumType>> m_enumField; | ||
caf::PdmField<caf::AppEnum<MyEnumType>> m_enum2Field; | ||
caf::PdmField<caf::AppEnum<MyEnumType>> m_enum3Field; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters