This class describes a property that can be used in components and actions or any class that needs to be passed to ObjectControler. A property has a type, a description (to be displayed for example as a tooltip, can be rich-text, see http://qt-project.org/doc/qt-4.8/richtext-html-subset.html for supported html tags), a value, a unit of measurement (SI unit if possible), and some specific attributes (that depends on the type, e.g. minimal and maximal values, single steps, number of decimals, regular expression...). An enum type can also be used for properties. More...
#include <Property.h>
Public Member Functions | |
QVariant | getAttribute (QString attName) |
get the current value of a given attribute, see setAttribute() if the attribute attName was never set using setAttribute(), the return QVariant is invalid. More... | |
QStringList | getAttributeList () |
returns the list of attribute names that are specific to this property More... | |
const QString & | getDescription () const |
get the description More... | |
QMap< int, QIcon > | getEnumIcons () const |
get the enum icons More... | |
QString | getEnumTypeName () const |
QString | getEnumValueAsString (const QObject *objectDeclaringTheEnum) const |
Utility method to get the current property value as a string. More... | |
QString | getGroupName () const |
get this property subgroup's name More... | |
const QVariant & | getInitialValue () const |
return the initial (default) value More... | |
const QString & | getName () const |
get the name of the property More... | |
bool | getReadOnly () const |
Property (QString name, const QVariant &variant, QString description, QString unit) | |
Constructor. More... | |
void | setAttribute (const QString &attribute, const QVariant &value) |
Set a given property for this attribute. More... | |
void | setDescription (QString) |
set the description (can be rich text) More... | |
void | setEnumIcons (const QMap< int, QIcon > &enumIcons) |
set the icons for all the enums More... | |
void | setEnumTypeName (QString enumTypeName, QObject *objectDeclaringTheEnum) |
if the property's type is an enum, set the name of the registered Qt Enum AND automatically build the enum names that will be used in the GUI. More... | |
void | setEnumTypeName (QString) |
if the property's type is an enum, set the name of the registered Qt Enum. More... | |
void | setGroupName (QString groupName) |
Set the group name. More... | |
void | setReadOnly (bool) |
set this property as read-only More... | |
virtual | ~Property ()=default |
Destructor. More... | |
Private Attributes | |
QMap< QString, QVariant > | attributeValues |
map containing all the attributes and their values More... | |
QString | description |
description of the property, can be rich text More... | |
QMap< int, QIcon > | enumIcons |
map containing all the icons for the enum More... | |
QString | enumTypeName |
if the property's type is an enum, this is the Qt registered enum name, otherwise it is the null string More... | |
QString | groupName |
name of the group in which this property is classified (null if no group name were set) More... | |
QVariant | initialValue |
initial value of the property, Only needed between the time when the property is instantiated and the time it is created by the Component or Action as a Qt Meta Property. More... | |
QString | name |
name of the property More... | |
bool | readOnly |
is the property read only More... | |
This class describes a property that can be used in components and actions or any class that needs to be passed to ObjectControler. A property has a type, a description (to be displayed for example as a tooltip, can be rich-text, see http://qt-project.org/doc/qt-4.8/richtext-html-subset.html for supported html tags), a value, a unit of measurement (SI unit if possible), and some specific attributes (that depends on the type, e.g. minimal and maximal values, single steps, number of decimals, regular expression...). An enum type can also be used for properties.
Properties can be grouped in subgroups, see Property::setGroupName().
Basically this is a way to overcome the Qt Meta Object properties limitations. A camitk::Property enriches a Qt Meta Object property (a very simplified Decorator Design Pattern).
Using camitk::Property instead of directly using Qt Meta Object property helps to build a better interactive GUI (in the property explorer for components and in the ActionWidget for actions). Note that a camitk::Property is represented as a regular Qt Meta Object property as well (the value of the camitk::Property is in fact stored by the Qt Meta Object property)
Here are some examples to get started with:
The GUI interaction is automatically build and managed by the class ObjectControler.
An example for adding properties to an action can be seen in tutorials/actions/properties. More specifically see the EnumPropertyExample action to learn about how to use enum properties.
The class PropComponent and PropAction in the tutorials demonstrates how to use camitk::Property instead of Qt Meta Object Property.
The available property types are:
Property Type | Property Type Id |
---|---|
int | QVariant::Int |
double | QVariant::Double |
bool | QVariant::Bool |
QString | QVariant::String |
QVector3D | QVariant::QVector3D |
QColor | QVariant::Color |
QDate | QVariant::Date |
QTime | QVariant::Time |
QChar | QVariant::Char |
QDateTime | QVariant::DateTime |
QPoint | Variant::Point |
QPointF | QVariant::PointF |
QKeySequence | QVariant::KeySequence |
QLocale | QVariant::Locale |
QSize | QVariant::Size |
QSizeF | QVariant::SizeF |
QRect | QVariant::Rect |
QRectF | QVariant::RectF |
QSizePolicy | QVariant::SizePolicy |
QFont | QVariant::Font |
QCursor | QVariant::Cursor |
enum | enumTypeId() |
flag | flagTypeId() |
group | groupTypeId() |
Possible attributes depends on the property type, mostly (see also QtVariantPropertyManager API doc):
Property Type | Attribute Name | Attribute Type |
---|---|---|
int | minimum | QVariant::Int |
int | maximum | QVariant::Int |
int | singleStep | QVariant::Int |
double | minimum | QVariant::Double |
double | maximum | QVariant::Double |
double | singleStep | QVariant::Double |
double | decimals | QVariant::Int |
QString | regExp | QVariant::RegExp |
QDate | minimum | QVariant::Date |
QDate | maximum | QVariant::Date |
QPointF | decimals | QVariant::Int |
QSize | minimum | QVariant::Size |
QSize | maximum | QVariant::Size |
QSizeF | minimum | QVariant::SizeF |
QSizeF | maximum | QVariant::SizeF |
QSizeF | decimals | QVariant::Int |
QRect | constraint | QVariant::Rect |
QRectF | constraint | QVariant::RectF |
QRectF | decimals | QVariant::Int |
enum | enumNames | QVariant::StringList (note that this can be build automatically) |
flag | flagNames (NOT IMPLEMENTED YET) | QVariant::StringList |
You can change the enum value names in the GUI using the "enumNames" attributes. There is also a way to automatically build nicer enumNames (see below).
Enum icons might be set using Property::setEnumIcons.
For instance in the header:
And then in the code:
camitk::Property::Property | ( | QString | name, |
const QVariant & | variant, | ||
QString | description, | ||
QString | unit | ||
) |
Constructor.
The variant parameters also allows you to initialize the value of the property. By default a Property is enabled and editable (i.e. by default it is not read-only)
name | property name (unique identifier of your class property |
variant | specify the property type (QVariant) and initial value |
description | a sentence or two to describe the property (and its unit if any), can be Rich Text |
unit | a unit of measurement (in SI unit), use symbols from https://en.wikipedia.org/wiki/SI_base_unit or https://en.wikipedia.org/wiki/SI_derived_unit when possible |
|
virtualdefault |
Destructor.
QVariant camitk::Property::getAttribute | ( | QString | attName | ) |
get the current value of a given attribute, see setAttribute() if the attribute attName was never set using setAttribute(), the return QVariant is invalid.
To test if a QVariant is invalid, use the QVariant::isValid() method e.g.: if (!myProp.getAttribute("bad").isValid()) { CAMITK_INFO(tr("myProp does not have an attribute 'bad' (or this attribute is still equals to the default value)")) }
It is recommended to only use this method inside a foreach(QString s: getAttributeList())
QStringList camitk::Property::getAttributeList | ( | ) |
returns the list of attribute names that are specific to this property
const QString & camitk::Property::getDescription | ( | ) | const |
get the description
QMap< int, QIcon > camitk::Property::getEnumIcons | ( | ) | const |
get the enum icons
QString camitk::Property::getEnumTypeName | ( | ) | const |
QString camitk::Property::getEnumValueAsString | ( | const QObject * | objectDeclaringTheEnum | ) | const |
Utility method to get the current property value as a string.
The string corresponds one of the enum values: not the gui enum values set using setAttribute("enumNames"...)
If the property's type is an enum, this is the string corresponding to its value (the property value can be accessed, the normal way using the QVariant toInt() to get the int value (classical C++ enum value)
objectDeclaringTheEnum | is a pointer to the object instantiated from the class that declared the enum |
QString camitk::Property::getGroupName | ( | ) | const |
get this property subgroup's name
const QVariant & camitk::Property::getInitialValue | ( | ) | const |
return the initial (default) value
Referenced by CamiTKPropertyList::addProperty().
const QString & camitk::Property::getName | ( | ) | const |
get the name of the property
References description.
Referenced by CamiTKPropertyList::addProperty(), PropertyExplorer::eventFilter(), PropertyExplorer::getWidget(), and camitk::PropertyObject::~PropertyObject().
bool camitk::Property::getReadOnly | ( | ) | const |
void camitk::Property::setAttribute | ( | const QString & | attribute, |
const QVariant & | value | ||
) |
Set a given property for this attribute.
Note that not all the attributes are not usable for all property type (see table above). The supported attribute names are (see QtVariantPropertyManagerPrivate() constructor):
attribute | name of the attribute |
value | value of this attribute |
Referenced by AnglesAndTranslationAction::AnglesAndTranslationAction(), AnisotropicDiffusion::AnisotropicDiffusion(), CannyEdgeDetection::CannyEdgeDetection(), ChangeParent::ChangeParent(), CleanPolyData::CleanPolyData(), PropertyExplorer::createProperties(), Decimation::Decimation(), Derivative::Derivative(), FillWithPoints::FillWithPoints(), GaussianFilter::GaussianFilter(), ManualThreshold::getWidget(), ResampleAction::getWidget(), MeshProjection::getWidget(), GradientMagnitudeRecursiveGaussian::GradientMagnitudeRecursiveGaussian(), ICPRegistration::ICPRegistration(), ImageReconstructionAction::ImageReconstructionAction(), VtkMeshComponent::initDynamicProperties(), LaplacianRecursiveGaussian::LaplacianRecursiveGaussian(), ManualThreshold::ManualThreshold(), MeanFilter::MeanFilter(), MedianFilter::MedianFilter(), MergeMeshs::MergeMeshs(), MeshProjection::MeshProjection(), MorphologicalOperators::MorphologicalOperators(), OtsuFilter::OtsuFilter(), PixelColorChanger::PixelColorChanger(), ResampleAction::ResampleAction(), ShowFrame::ShowFrame(), SmoothFilter::SmoothFilter(), SphereTopology::SphereTopology(), ChangeParent::updateComboBox(), and WarpOut::WarpOut().
void camitk::Property::setDescription | ( | QString | description | ) |
set the description (can be rich text)
void camitk::Property::setEnumIcons | ( | const QMap< int, QIcon > & | enumIcons | ) |
set the icons for all the enums
void camitk::Property::setEnumTypeName | ( | QString | enumTypeName, |
QObject * | objectDeclaringTheEnum | ||
) |
if the property's type is an enum, set the name of the registered Qt Enum AND automatically build the enum names that will be used in the GUI.
There is no need to set the "enumNames" attribute, the enum names will automatically be build from the enum literals:
enumTypeName | the enum type name as declared in the header file |
objectDeclaringTheEnum | is a pointer to the object instantiated from the class that declared the enum |
void camitk::Property::setEnumTypeName | ( | QString | nameOfTheEnum | ) |
if the property's type is an enum, set the name of the registered Qt Enum.
The enum names that will appear in the GUI will have to be given by setting the "enumNames" attribute.
Referenced by AnglesAndTranslationAction::AnglesAndTranslationAction(), AnisotropicDiffusion::AnisotropicDiffusion(), ChangeParent::ChangeParent(), ComputeCurvatures::ComputeCurvatures(), PropertyExplorer::createProperties(), Derivative::Derivative(), GaussianFilter::GaussianFilter(), ICPRegistration::ICPRegistration(), MeshProjection::MeshProjection(), MorphologicalOperators::MorphologicalOperators(), and ResampleAction::ResampleAction().
void camitk::Property::setGroupName | ( | QString | groupName | ) |
Set the group name.
Properties can be separated into subgroups. Just set the group name and they will be arranged/classified by group.
groupName | name of the group for this property |
Referenced by PMLExplorerWidget::createAtomPropertyList().
void camitk::Property::setReadOnly | ( | bool | isReadOnly | ) |
set this property as read-only
Referenced by ConnectedComponents::ConnectedComponents(), PMLExplorerWidget::createCellPropertyList(), PMLExplorerWidget::createMCPropertyList(), PMLExplorerWidget::createSCPropertyList(), ResampleAction::getWidget(), PMLComponent::initDynamicProperties(), and OtsuFilter::OtsuFilter().
|
private |
map containing all the attributes and their values
|
private |
description of the property, can be rich text
|
private |
map containing all the icons for the enum
|
private |
if the property's type is an enum, this is the Qt registered enum name, otherwise it is the null string
|
private |
name of the group in which this property is classified (null if no group name were set)
|
private |
|
private |
name of the property
|
private |
is the property read only