mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Updated to version 0.8.0
This commit is contained in:
@@ -6,6 +6,10 @@ add_library( ${PROJECT_NAME}
|
||||
cafPdmObject.cpp
|
||||
cafPdmDocument.cpp
|
||||
cafPdmField.cpp
|
||||
cafPdmUiItem.cpp
|
||||
cafPdmPointer.cpp
|
||||
cafPdmUiItem.cpp
|
||||
cafPdmUiOrdering.cpp
|
||||
cafPdmUiEditorHandle.cpp
|
||||
cafPdmUiFieldEditorHandle.cpp
|
||||
cafPdmUiObjectEditorHandle.cpp
|
||||
)
|
||||
|
||||
@@ -28,14 +28,21 @@ namespace caf
|
||||
//==================================================================================================
|
||||
/// A generic Factory class template
|
||||
/// Usage:
|
||||
/// caf::Factory<BaseType, KeyType>::instance()->registerCreator<TypeToCreate>(key);
|
||||
/// Initialization in source file (Initialization :
|
||||
/// bool TypeToCreate_Factory_initialized = caf::Factory<BaseType, KeyType>::instance()->registerCreator<TypeToCreate>(key);
|
||||
/*INIT_FACTORY(BaseType, KeyType,TypeToCreate )
|
||||
bool TypeToCreate_Factory_initialized = caf::Factory<BaseType, KeyType>::instance()->registerCreator<TypeToCreate>(QString("TypeToCreate"));*/
|
||||
/// When you need an object:
|
||||
/// BaseType* newObject = caf::Factory<BaseType, KeyType>::instance()->create(key);
|
||||
//==================================================================================================
|
||||
|
||||
template<typename BaseType, typename KeyType>
|
||||
class Factory
|
||||
{
|
||||
class ObjectCreatorBase;
|
||||
public:
|
||||
typedef typename std::map<KeyType, ObjectCreatorBase*>::iterator iterator_type;
|
||||
|
||||
static Factory<BaseType, KeyType> * instance()
|
||||
{
|
||||
static Factory<BaseType, KeyType>* fact = new Factory<BaseType, KeyType>;
|
||||
@@ -43,9 +50,9 @@ namespace caf
|
||||
}
|
||||
|
||||
template< typename TypeToCreate >
|
||||
void registerCreator(const KeyType& key)
|
||||
bool registerCreator(const KeyType& key)
|
||||
{
|
||||
std::map<KeyType, ObjectCreatorBase*>::iterator entryIt;
|
||||
iterator_type entryIt;
|
||||
|
||||
entryIt = m_factoryMap.find(key);
|
||||
if (entryIt == m_factoryMap.end())
|
||||
@@ -57,12 +64,14 @@ namespace caf
|
||||
{
|
||||
assert(key != entryIt->first); // classNameKeyword has already been used
|
||||
assert(false); // To be sure ..
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
BaseType* create(const KeyType& key);
|
||||
BaseType* create(const KeyType& key)
|
||||
{
|
||||
std::map<KeyType, ObjectCreatorBase*>::iterator entryIt;
|
||||
iterator_type entryIt;
|
||||
|
||||
entryIt = m_factoryMap.find(key);
|
||||
if (entryIt != m_factoryMap.end())
|
||||
{
|
||||
@@ -74,11 +83,13 @@ namespace caf
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
Factory () {}
|
||||
~Factory()
|
||||
{
|
||||
std::map<KeyType, ObjectCreatorBase*>::iterator entryIt;
|
||||
iterator_type entryIt;
|
||||
|
||||
for (entryIt = m_factoryMap.begin(); entryIt != m_factoryMap.end(); ++entryIt)
|
||||
{
|
||||
delete(entryIt->second);
|
||||
@@ -107,4 +118,4 @@ namespace caf
|
||||
};
|
||||
|
||||
|
||||
} //End of namespace caf
|
||||
}//End of namespace caf
|
||||
|
||||
@@ -61,7 +61,7 @@ void PdmObjectGroup::deleteObjects()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmObjectGroup::removeNullPtrs()
|
||||
{
|
||||
objects.removeAll(NULL);
|
||||
objects.removeChildObject(NULL);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#include "cafPdmUiItem.h"
|
||||
#include "cafPdmFieldImpl.h"
|
||||
|
||||
|
||||
#include <set>
|
||||
#include <assert.h>
|
||||
|
||||
#include <QXmlStreamWriter>
|
||||
@@ -34,6 +34,7 @@ namespace caf
|
||||
|
||||
class PdmObject;
|
||||
template <class T> class PdmPointer;
|
||||
class PdmUiFieldEditorHandle;
|
||||
|
||||
//==================================================================================================
|
||||
/// Base class for all fields, making it possible to handle them generically
|
||||
@@ -42,12 +43,17 @@ template <class T> class PdmPointer;
|
||||
class PdmFieldHandle : public PdmUiItem
|
||||
{
|
||||
public:
|
||||
PdmFieldHandle() { m_ownerObject = NULL; m_keyword = "UNDEFINED"; }
|
||||
PdmFieldHandle() : m_isIOReadable(true), m_isIOWritable(true) { m_ownerObject = NULL; m_keyword = "UNDEFINED"; }
|
||||
virtual ~PdmFieldHandle() { }
|
||||
|
||||
virtual void readFieldData(QXmlStreamReader& xmlStream) = 0;
|
||||
virtual void writeFieldData(QXmlStreamWriter& xmlStream) = 0;
|
||||
|
||||
bool isIOReadable() { return m_isIOReadable; }
|
||||
bool isIOWritable() { return m_isIOWritable; }
|
||||
void setIOWritable(bool isWritable) { m_isIOWritable = isWritable; }
|
||||
void setIOReadable(bool isReadable) { m_isIOReadable = isReadable; }
|
||||
|
||||
void setKeyword(const QString& keyword) { m_keyword = keyword; }
|
||||
QString keyword() const { return m_keyword; }
|
||||
|
||||
@@ -59,6 +65,7 @@ public:
|
||||
virtual QVariant uiValue() const { return QVariant(); }
|
||||
virtual void setValueFromUi(const QVariant& ) { }
|
||||
virtual void childObjects(std::vector<PdmObject*>* ) { }
|
||||
virtual void removeChildObject(PdmObject* ) { }
|
||||
virtual QList<PdmOptionItemInfo>
|
||||
valueOptions( bool* useOptionsOnly) { return QList<PdmOptionItemInfo>(); }
|
||||
|
||||
@@ -68,6 +75,9 @@ protected:
|
||||
PdmObject* m_ownerObject;
|
||||
private:
|
||||
QString m_keyword;
|
||||
bool m_isIOReadable;
|
||||
bool m_isIOWritable;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -86,8 +96,8 @@ public:
|
||||
virtual ~PdmField() {}
|
||||
|
||||
// Copy and assignment must ignore the default value.
|
||||
PdmField(const PdmField& other) { assertValid(); m_fieldValue = other.m_fieldValue; }
|
||||
PdmField(const DataType& fieldValue) { assertValid(); m_fieldValue = fieldValue; }
|
||||
PdmField(const PdmField& other) : PdmFieldHandle() { assertValid(); m_fieldValue = other.m_fieldValue; }
|
||||
PdmField(const DataType& fieldValue) : PdmFieldHandle() { assertValid(); m_fieldValue = fieldValue; }
|
||||
PdmField& operator= (const PdmField& other) { assertValid(); m_fieldValue = other.m_fieldValue; return *this; }
|
||||
PdmField& operator= (const DataType& fieldValue) { assertValid(); m_fieldValue = fieldValue; return *this; }
|
||||
|
||||
@@ -135,7 +145,7 @@ class PdmField <DataType*> : public PdmFieldHandle
|
||||
{
|
||||
typedef DataType* DataTypePtr;
|
||||
public:
|
||||
PdmField() { m_fieldValue = NULL; }
|
||||
PdmField() : PdmFieldHandle() { m_fieldValue = NULL; }
|
||||
PdmField(const PdmField& other);
|
||||
PdmField(const DataTypePtr& fieldValue);
|
||||
virtual ~PdmField();
|
||||
@@ -205,8 +215,7 @@ public:
|
||||
|
||||
void clear();
|
||||
void erase(size_t index);
|
||||
void removeAll(DataType* pointer);
|
||||
void deleteChildren();
|
||||
void deleteAllChildObjects();
|
||||
|
||||
// Reimplementation of PdmFieldhandle methods
|
||||
virtual void readFieldData(QXmlStreamReader& xmlStream);
|
||||
@@ -214,6 +223,8 @@ public:
|
||||
|
||||
// Gui generalized methods
|
||||
virtual void childObjects(std::vector<PdmObject*>* objects);
|
||||
virtual void removeChildObject(PdmObject* object);
|
||||
|
||||
private:
|
||||
void removeThisAsParentField();
|
||||
void addThisAsParentField();
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "cafPdmObject.h"
|
||||
#include <vector>
|
||||
#include "cafPdmUiFieldEditorHandle.h"
|
||||
|
||||
namespace caf
|
||||
{
|
||||
@@ -60,6 +61,9 @@ void caf::PdmField<DataType>::setValueFromUi(const QVariant& uiValue)
|
||||
{
|
||||
assert(m_ownerObject != NULL);
|
||||
m_ownerObject->fieldChangedByUi(this, oldValue, newValue);
|
||||
|
||||
// This assumes that all field editors are updated by an instance of PdmUiObjectEditorHandle
|
||||
m_ownerObject->updateConnectedEditors();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,6 +189,7 @@ void caf::PdmField<DataType*>::childObjects(std::vector<PdmObject*>* objects)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<typename DataType >
|
||||
caf::PdmField<DataType*>::PdmField(const PdmField& other)
|
||||
: PdmFieldHandle()
|
||||
{
|
||||
if (m_fieldValue) m_fieldValue.rawPtr()->removeParentField(this);
|
||||
m_fieldValue = other.m_fieldValue;
|
||||
@@ -334,7 +339,7 @@ void PdmPointersField<DataType*>::clear()
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<typename DataType>
|
||||
void PdmPointersField<DataType*>::deleteChildren()
|
||||
void PdmPointersField<DataType*>::deleteAllChildObjects()
|
||||
{
|
||||
size_t index;
|
||||
for (index = 0; index < m_pointers.size(); ++index)
|
||||
@@ -355,13 +360,14 @@ void PdmPointersField<DataType*>::erase(size_t index)
|
||||
m_pointers.erase(m_pointers.begin() + index);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<typename DataType>
|
||||
void PdmPointersField<DataType*>::removeAll(DataType* pointer)
|
||||
void PdmPointersField<DataType*>::removeChildObject(PdmObject* object)
|
||||
{
|
||||
DataType* pointer = dynamic_cast<DataType*>(object);
|
||||
|
||||
size_t index;
|
||||
std::vector< PdmPointer<DataType> > tempPointers;
|
||||
tempPointers = m_pointers;
|
||||
@@ -379,6 +385,7 @@ void PdmPointersField<DataType*>::removeAll(DataType* pointer)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -433,7 +440,7 @@ template<typename DataType>
|
||||
}
|
||||
|
||||
currentObject->readFields(xmlStream);
|
||||
m_pointers.push_back(currentObject);
|
||||
this->push_back(currentObject);
|
||||
|
||||
// Skip comments and for some reason: Characters. The last bit should not be correct,
|
||||
// but Qt reports a character token between EndElement and StartElement
|
||||
@@ -490,4 +497,5 @@ void PdmPointersField<DataType*>::addThisAsParentField()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} //End of namespace caf
|
||||
|
||||
@@ -74,16 +74,23 @@ void PdmObject::readFields (QXmlStreamReader& xmlStream )
|
||||
PdmFieldHandle* currentField = findField(name);
|
||||
if (currentField)
|
||||
{
|
||||
// readFieldData assumes that the xmlStream points to first token of field content.
|
||||
// After reading, the xmlStream is supposed to point to the first token after the field content.
|
||||
// (typically an "endElement")
|
||||
QXmlStreamReader::TokenType tt;
|
||||
tt = xmlStream.readNext();
|
||||
currentField->readFieldData( xmlStream );
|
||||
if (currentField->isIOReadable())
|
||||
{
|
||||
// readFieldData assumes that the xmlStream points to first token of field content.
|
||||
// After reading, the xmlStream is supposed to point to the first token after the field content.
|
||||
// (typically an "endElement")
|
||||
QXmlStreamReader::TokenType tt;
|
||||
tt = xmlStream.readNext();
|
||||
currentField->readFieldData( xmlStream );
|
||||
}
|
||||
else
|
||||
{
|
||||
xmlStream.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Warning: Could not find a field with name " << name.toLatin1().data() << " in the current object : " << classKeyword().toLatin1().data() << std::endl;
|
||||
std::cout << "Line "<< xmlStream.lineNumber() << ": Warning: Could not find a field with name " << name.toLatin1().data() << " in the current object : " << classKeyword().toLatin1().data() << std::endl;
|
||||
xmlStream.skipCurrentElement();
|
||||
}
|
||||
break;
|
||||
@@ -119,11 +126,14 @@ void PdmObject::writeFields(QXmlStreamWriter& xmlStream)
|
||||
std::vector<PdmFieldHandle*>::iterator it;
|
||||
for (it = m_fields.begin(); it != m_fields.end(); ++it)
|
||||
{
|
||||
PdmFieldHandle* obj = *it;
|
||||
QString keyword = obj->keyword();
|
||||
xmlStream.writeStartElement("", keyword);
|
||||
obj->writeFieldData(xmlStream);
|
||||
xmlStream.writeEndElement();
|
||||
PdmFieldHandle* field = *it;
|
||||
if (field->isIOWritable())
|
||||
{
|
||||
QString keyword = field->keyword();
|
||||
xmlStream.writeStartElement("", keyword);
|
||||
field->writeFieldData(xmlStream);
|
||||
xmlStream.writeEndElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,6 +208,37 @@ void PdmObject::parentFields(std::vector<PdmFieldHandle*>& parentFields) const
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmObject::parentObjects(std::vector<PdmObject*>& objects) const
|
||||
{
|
||||
std::vector<caf::PdmFieldHandle*> parentFields;
|
||||
this->parentFields(parentFields);
|
||||
size_t i;
|
||||
for (i = 0; i < parentFields.size(); i++)
|
||||
{
|
||||
objects.push_back(parentFields[i]->ownerObject());
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmObject::removeFromParentFields()
|
||||
{
|
||||
std::vector<caf::PdmFieldHandle*> parentFields;
|
||||
this->parentFields(parentFields);
|
||||
size_t i;
|
||||
for (i = 0; i < parentFields.size(); i++)
|
||||
{
|
||||
parentFields[i]->removeChildObject(this);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmObject::addFieldNoDefault(PdmFieldHandle* field, const QString& keyword, PdmUiItemInfo * fieldDescription)
|
||||
{
|
||||
field->setUiItemInfo(fieldDescription);
|
||||
@@ -208,4 +249,33 @@ void PdmObject::addFieldNoDefault(PdmFieldHandle* field, const QString& keyword,
|
||||
m_fields.push_back(field);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmObject::uiOrdering(QString uiConfigName, PdmUiOrdering& uiOrdering) const
|
||||
{
|
||||
this->defineUiOrdering(uiConfigName, uiOrdering);
|
||||
if (!uiOrdering.forgetRemainingFields())
|
||||
{
|
||||
// Add the remaining Fields To UiConfig
|
||||
|
||||
for (size_t i = 0; i < m_fields.size(); ++i)
|
||||
{
|
||||
if (!uiOrdering.contains(m_fields[i]))
|
||||
{
|
||||
uiOrdering.add( m_fields[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmObject::editorAttribute(const PdmFieldHandle* field, QString uiConfigName, PdmUiEditorAttribute * attribute)
|
||||
{
|
||||
this->defineEditorAttribute(field, uiConfigName, attribute);
|
||||
}
|
||||
|
||||
|
||||
} //End of namespace caf
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "cafPdmUiItem.h"
|
||||
#include "cafPdmUiOrdering.h"
|
||||
#include "cafPdmPointer.h"
|
||||
|
||||
#include <set>
|
||||
@@ -28,11 +29,27 @@
|
||||
class QXmlStreamReader;
|
||||
class QXmlStreamWriter;
|
||||
|
||||
|
||||
// Taken from gtest.h
|
||||
//
|
||||
// Due to C++ preprocessor weirdness, we need double indirection to
|
||||
// concatenate two tokens when one of them is __LINE__. Writing
|
||||
//
|
||||
// foo ## __LINE__
|
||||
//
|
||||
// will result in the token foo__LINE__, instead of foo followed by
|
||||
// the current line number. For more details, see
|
||||
// http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.6
|
||||
#define PDM_OBJECT_STRING_CONCATENATE(foo, bar) PDM_OBJECT_STRING_CONCATENATE_IMPL_(foo, bar)
|
||||
#define PDM_OBJECT_STRING_CONCATENATE_IMPL_(foo, bar) foo ## bar
|
||||
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
class PdmFieldHandle;
|
||||
template < class FieldDataType > class PdmField;
|
||||
class PdmUiEditorAttribute;
|
||||
|
||||
//==================================================================================================
|
||||
/// Macros helping in development of PDM objects
|
||||
@@ -51,7 +68,7 @@ public: \
|
||||
|
||||
#define CAF_PDM_SOURCE_INIT(ClassName, keyword) \
|
||||
QString ClassName::classKeywordStatic() { return keyword; } \
|
||||
bool ClassName##_initialized = caf::PdmObjectFactory::instance()->registerCreator<ClassName>()
|
||||
static bool PDM_OBJECT_STRING_CONCATENATE(pdm_object_factory_init_, __LINE__) = caf::PdmObjectFactory::instance()->registerCreator<ClassName>()
|
||||
|
||||
/// InitObject sets up the user interface related information for the object
|
||||
/// Placed in the constructor of your PdmObject
|
||||
@@ -93,6 +110,9 @@ public:
|
||||
PdmObject() { }
|
||||
virtual ~PdmObject();
|
||||
|
||||
/// The classKeyword method is overridden in subclasses by the CAF_PDM_HEADER_INIT macro
|
||||
virtual QString classKeyword() = 0;
|
||||
|
||||
void readFields (QXmlStreamReader& inputStream );
|
||||
void writeFields(QXmlStreamWriter& outputStream);
|
||||
|
||||
@@ -100,9 +120,18 @@ public:
|
||||
void fields(std::vector<PdmFieldHandle*>& fields) const;
|
||||
/// The fields containing pointers to this PdmObject. Use ownerObject() on the fieldHandle to get the PdmObject parent.
|
||||
void parentFields(std::vector<PdmFieldHandle*>& fields) const;
|
||||
/// Remove pointer to this from all parent fields
|
||||
void removeFromParentFields();
|
||||
|
||||
/// The classKeyword method is overridden in subclasses by the CAF_PDM_HEADER_INIT macro
|
||||
virtual QString classKeyword() = 0;
|
||||
///
|
||||
void parentObjects(std::vector<PdmObject*>& objects) const;
|
||||
|
||||
/// Method to be called from the Ui classes creating Auto Gui to get the group information
|
||||
/// supplied by the \sa defineUiOrdering method that can be reimplemented
|
||||
void uiOrdering(QString uiConfigName, PdmUiOrdering& uiOrdering) const;
|
||||
|
||||
/// For a specific field, return editor specific parameters used to customize the editor behavior..
|
||||
void editorAttribute(const PdmFieldHandle* field, QString uiConfigName, PdmUiEditorAttribute * attribute);
|
||||
|
||||
// Virtual interface to override in subclasses to support special behaviour if needed
|
||||
public: // Virtual
|
||||
@@ -112,6 +141,7 @@ public: // Virtual
|
||||
/// Method to re-implement to supply option values for a specific field
|
||||
virtual QList<PdmOptionItemInfo>
|
||||
calculateValueOptions(const PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly) { return QList<PdmOptionItemInfo>(); }
|
||||
// For later // virtual void editorAttributeChangedByUI(const PdmFieldHandle* field, QString uiConfigName, const PdmUiAttributeHandle * attributes);
|
||||
|
||||
protected: // Virtual
|
||||
/// Method gets called from PdmDocument after all objects are read.
|
||||
@@ -120,6 +150,15 @@ protected: // Virtual
|
||||
/// Method gets called from PdmDocument before saving document.
|
||||
/// Re-implement to make sure your fields have correct data before saving
|
||||
virtual void setupBeforeSave() {};
|
||||
|
||||
/// Override to customize the order and grouping of the Gui.
|
||||
/// Fill up the uiOrdering object with groups and field references to create the gui structure
|
||||
/// If the uiOrdering is empty, it is interpreted as meaning all fields w/o grouping.
|
||||
virtual void defineUiOrdering(QString uiConfigName, PdmUiOrdering& uiOrdering) const {}
|
||||
|
||||
/// Override to provide editor specific data for the field and uiConfigName
|
||||
virtual void defineEditorAttribute(const PdmFieldHandle* field, QString uiConfigName, PdmUiEditorAttribute * attribute) {}
|
||||
|
||||
public:
|
||||
/// operator= implemented to avoid copying the internal m_fields
|
||||
PdmObject& operator=(const PdmObject& ) { return *this; }
|
||||
|
||||
@@ -5,37 +5,12 @@ namespace caf
|
||||
|
||||
|
||||
|
||||
class PdmFieldHandle
|
||||
{
|
||||
// ....
|
||||
|
||||
void removeFieldView(PdmUiFieldViewHandle* fieldView) { m_fieldViews.erase(fieldView); }
|
||||
void addFieldView(PdmUiFieldViewHandle* fieldView) { m_fieldViews.insert(fieldView); }
|
||||
private:
|
||||
std::set<PdmUiFieldViewHandle*> m_fieldViews;
|
||||
// ....
|
||||
void setValueFromUI(...)
|
||||
{
|
||||
//...
|
||||
std::set<PdmUiFieldViewHandle*>::iterator it;
|
||||
for (it = m_fieldViews.begin(); it != m_fieldViews.end(); ++it)
|
||||
{
|
||||
m_fieldViews[i]->updateUiValue();
|
||||
}
|
||||
|
||||
//...
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
class PdmUiItemInfo
|
||||
{
|
||||
// ....
|
||||
QString m_editorType; // Int, type_info, className or ??
|
||||
int m_isHidden;
|
||||
int m_isReadOnly;
|
||||
const type_info* m_editorType;
|
||||
int m_isHidden;
|
||||
int m_isReadOnly;
|
||||
|
||||
};
|
||||
|
||||
@@ -46,8 +21,8 @@ class PdmUiItem
|
||||
{
|
||||
// ...
|
||||
|
||||
QString editorType(const QString& uiConfigName);
|
||||
void setEditorType(const QString& uiConfigName, const QString& editorKeyword);
|
||||
const type_info* editorType(const QString& uiConfigName);
|
||||
void setEditorType(const QString& uiConfigName, const type_info* editorType);
|
||||
|
||||
bool isHidden(QString uiConfigName);
|
||||
void setHidden(QString uiConfigName, bool isHidden);
|
||||
@@ -67,12 +42,11 @@ private :
|
||||
|
||||
|
||||
|
||||
|
||||
class PdmUiConfiguration
|
||||
class PdmUiOrdering
|
||||
{
|
||||
public:
|
||||
PdmUiConfiguration(): m_forgetRemainingFields(false) { };
|
||||
virtual ~PdmUiConfiguration()
|
||||
PdmUiOrdering(): m_forgetRemainingFields(false) { };
|
||||
virtual ~PdmUiOrdering()
|
||||
{
|
||||
for (size_t i = 0; i < m_createdGroups.size(); ++i)
|
||||
{
|
||||
@@ -87,21 +61,21 @@ public:
|
||||
group->setUiName(displayName);
|
||||
|
||||
m_createdGroups.push_back(group);
|
||||
m_config.push_back(group);
|
||||
m_ordering.push_back(group);
|
||||
}
|
||||
|
||||
void add(PdmUiItem* item) { m_config.push_back(item); }
|
||||
void add(PdmUiItem* item) { m_ordering.push_back(item); }
|
||||
bool forgetRemainingFields() const { return m_forgetRemainingFields; }
|
||||
void setForgetRemainingFields(bool val) { m_forgetRemainingFields = val; }
|
||||
|
||||
const std::vector<PdmUiItem*>& uiItems() const { return m_config; }
|
||||
const std::vector<PdmUiItem*>& uiItems() const { return m_ordering; }
|
||||
|
||||
private:
|
||||
// Private copy constructor and assignment to prevent this. (The vectors below will make trouble)
|
||||
PdmUiConfiguration(const PdmUiConfiguration& other) { }
|
||||
PdmUiConfiguration& operator= (const PdmUiConfiguration& other) { }
|
||||
PdmUiOrdering(const PdmUiOrdering& other) { }
|
||||
PdmUiOrdering& operator= (const PdmUiOrdering& other) { }
|
||||
|
||||
std::vector<PdmUiItem*> m_config;
|
||||
std::vector<PdmUiItem*> m_ordering;
|
||||
std::vector<PdmUiGroup*> m_createdGroups; /// Owned PdmUiGroups, for mem management
|
||||
bool m_forgetRemainingFields;
|
||||
|
||||
@@ -110,47 +84,184 @@ private:
|
||||
|
||||
|
||||
|
||||
class PdmUiGroup : public PdmUiItem, PdmUiConfiguration
|
||||
class PdmUiGroup : public PdmUiItem, PdmUiOrdering
|
||||
{
|
||||
virtual bool isGroup() { return true; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class PdmObject : public PdmUiItem
|
||||
{
|
||||
public:
|
||||
|
||||
/// For a specific field, return editor specific parameters used to customize the editor behavior..
|
||||
virtual void setUpUiAttribute(const PdmFieldHandle* field, QString uiConfigName, PdmUiAttributeHandle * attributes);
|
||||
void editorAttribute(const PdmFieldHandle* field, QString uiConfigName, PdmUiEditorAttribute * attribute)
|
||||
{
|
||||
this->defineEditorAttribute(field, uiConfigName, attribute);
|
||||
}
|
||||
|
||||
// For later // virtual void uiAttributeChangedByUI(const PdmFieldHandle* field, QString uiConfigName, const PdmUiAttributeHandle * attributes);
|
||||
|
||||
// Method to be called from the Ui classes creating Auto Gui to get the group information
|
||||
// supplied by the \sa setUpUIConfiguration method that can be reimplemented
|
||||
|
||||
void uiConfiguration(QString uiConfigName, PdmUiConfiguration& uiConfig)
|
||||
// supplied by the \sa defineUiOrdering method that can be reimplemented
|
||||
void uiOrdering(QString uiConfigName, PdmUiOrdering& uiOrdering)
|
||||
{
|
||||
this->setUpUIConfiguration(uiConfigName, uiConfig);
|
||||
if (!uiConfig.forgetRemainingFields())
|
||||
this->defineUiOrdering(uiConfigName, uiOrdering);
|
||||
if (!uiOrdering.forgetRemainingFields())
|
||||
{
|
||||
// Todo: add Remaining Fields To UiConfig
|
||||
|
||||
// Add the remaining Fields To UiConfig
|
||||
|
||||
for (size_t i = 0; i < m_fields.size(); ++i)
|
||||
{
|
||||
if (!uiOrdering.contains(m_fields[i]))
|
||||
{
|
||||
uiOrdering.add( m_fields[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
/// Fill up the UiConfig object with groups and field references to create the gui structure
|
||||
/// If the uiConfig is empty, it is interpreted as meaning all fields w/o grouping.
|
||||
/// Override to customize the order and grouping of the Gui.
|
||||
/// Fill up the uiOrdering object with groups and field references to create the gui structure
|
||||
/// If the uiOrdering is empty, it is interpreted as meaning all fields w/o grouping.
|
||||
virtual void defineUiOrdering(QString uiConfigName, PdmUiOrdering& uiOrdering) {}
|
||||
|
||||
virtual void setUpUIConfiguration(QString uiConfigName, PdmUiConfiguration& uiConfig) ;
|
||||
/// Override to provide editor specific data for the field and uiConfigName
|
||||
virtual void defineEditorAttribute(const PdmFieldHandle* field, QString uiConfigName, PdmUiEditorAttribute * attribute) {}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class PdmUiObjectEditorHandle: public QObject
|
||||
{
|
||||
public:
|
||||
PdmUiObjectEditorHandle() : m_pdmObject(NULL) {}
|
||||
~PdmUiObjectEditorHandle() {}
|
||||
///
|
||||
QWidget* getOrCreateWidget(QWidget* parent)
|
||||
{
|
||||
if (m_widget.isNull())
|
||||
{
|
||||
m_widget = this->createWidget(parent);
|
||||
}
|
||||
return m_widget;
|
||||
}
|
||||
QWidget* widget() { return m_widget; }
|
||||
|
||||
/// Virtual method to be overridden. Needs to set up the supplied widget
|
||||
/// with all signals etc to make it communicate with this object
|
||||
void setPdmObject(PdmObject* object, QString uiConfigName) { m_pdmObject = object; }
|
||||
PdmObject* pdmObject() { return m_pdmObject; }
|
||||
|
||||
virtual void updateUi(QString uiConfigName) = 0;
|
||||
|
||||
protected:
|
||||
|
||||
virtual QWidget* createWidget(QWidget* parent) = 0;
|
||||
|
||||
private:
|
||||
PdmObject* m_pdmObject;
|
||||
QPointer<QWidget> m_widget;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class PdmUiFieldEditorHandle : public QObject
|
||||
{
|
||||
public:
|
||||
PdmUiFieldEditorHandle() : m_field(NULL) {}
|
||||
~PdmUiFieldEditorHandle()
|
||||
{
|
||||
if (m_field) m_field->removeFieldEditor(this);
|
||||
|
||||
if (!m_combinedWidget.isNull()) delete m_combinedWidget;
|
||||
if (!m_editorWidget.isNull()) delete m_editorWidget ;
|
||||
if (!m_labelWidget.isNull()) delete m_labelWidget;
|
||||
}
|
||||
|
||||
///
|
||||
PdmFieldHandle* field() { return m_field; }
|
||||
void setField(PdmFieldHandle * field)
|
||||
{
|
||||
if (m_field) m_field->removeFieldEditor(this);
|
||||
m_field = field;
|
||||
if (m_field) m_field->addFieldEditor(this);
|
||||
}
|
||||
|
||||
|
||||
void setValueToField(const QVariant& value)
|
||||
{
|
||||
if (m_field) m_field->setUiValue(value);
|
||||
}
|
||||
|
||||
void createWidgets(QWidget * parent)
|
||||
{
|
||||
if (m_combinedWidget.isNull()) m_combinedWidget = createCombinedWidget(parent);
|
||||
if (m_editorWidget.isNull()) m_editorWidget = createEditorWidget(parent);
|
||||
if (m_labelWidget.isNull()) m_labelWidget = createLabelWidget(parent);
|
||||
}
|
||||
|
||||
QWidget* combinedWidget() { return m_combinedWidget; }
|
||||
QWidget* editorWidget() { return m_editorWidget; }
|
||||
QWidget* labelWidget() { return m_labelWidget; }
|
||||
|
||||
public: // Virtual interface to override
|
||||
/// Update only the display of the data value, because some other view has changed it.
|
||||
virtual void updateUiValue() = 0;
|
||||
|
||||
/// Supposed to update all parts of the widgets, both visibility, sensitivity, decorations and field data
|
||||
virtual void updateUi(QString uiConfigName) = 0;
|
||||
|
||||
/// Supposed to do all wiring of singals and slots
|
||||
virtual void connectUi() = 0;
|
||||
|
||||
protected: // Virtual interface to override
|
||||
/// Implement one of these, or both editor and label. The widgets will be used in the parent layout according to
|
||||
/// being "Label" Editor" or a single combined widget.
|
||||
|
||||
virtual QWidget* createCombinedWidget(QWidget * parent) { return NULL; }
|
||||
virtual QWidget* createEditorWidget(QWidget * parent) { return NULL; }
|
||||
virtual QWidget* createLabelWidget(QWidget * parent) { return NULL; }
|
||||
|
||||
private:
|
||||
PdmFieldHandle* m_field;
|
||||
|
||||
QPointer<QWidget> m_combinedWidget;
|
||||
QPointer<QWidget> m_editorWidget;
|
||||
QPointer<QWidget> m_labelWidget;
|
||||
};
|
||||
|
||||
|
||||
class PdmFieldHandle
|
||||
{
|
||||
// ....
|
||||
|
||||
void removeFieldEditor(PdmUiFieldEditorHandle* fieldView) { m_fieldEditors.erase(fieldView); }
|
||||
void addFieldEditor(PdmUiFieldEditorHandle* fieldView) { m_fieldEditors.insert(fieldView); }
|
||||
private:
|
||||
std::set<PdmUiFieldEditorHandle*> m_fieldEditors;
|
||||
// ....
|
||||
void setValueFromUI(...)
|
||||
{
|
||||
//...
|
||||
std::set<PdmUiFieldEditorHandle*>::iterator it;
|
||||
for (it = m_fieldEditors.begin(); it != m_fieldEditors.end(); ++it)
|
||||
{
|
||||
m_fieldEditors[i]->updateUiValue();
|
||||
}
|
||||
|
||||
//...
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
class PdmPropertyWindow : public QWidget
|
||||
{
|
||||
public:
|
||||
@@ -196,7 +307,7 @@ public:
|
||||
m_currentObjectView = PdmObjViewFactory::instance()->create(object->editorType(m_uiConfigName));
|
||||
if (!m_currentObjectView)
|
||||
{
|
||||
m_currentObjectView = new PdmStdObjView();
|
||||
m_currentObjectView = new PdmUiDefaultObjectEditor();
|
||||
}
|
||||
|
||||
// Create widget to handle this
|
||||
@@ -213,119 +324,27 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
PdmObjectViewHandle* m_currentObjectView;
|
||||
PdmUiObjectEditorHandle* m_currentObjectView;
|
||||
QString m_uiConfigName;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class PdmObjectViewHandle: public QObject
|
||||
class PdmUiEditorAttribute
|
||||
{
|
||||
public:
|
||||
PdmObjectViewHandle() : m_pdmObject(NULL) {}
|
||||
~PdmObjectViewHandle() {}
|
||||
///
|
||||
QWidget* getOrCreateWidget(QWidget* parent)
|
||||
{
|
||||
if (m_widget.isNull())
|
||||
{
|
||||
m_widget = this->createWidget(parent);
|
||||
}
|
||||
return m_widget;
|
||||
}
|
||||
QWidget* widget() { return m_widget; }
|
||||
|
||||
/// Virtual method to be overridden. Needs to set up the supplied widget
|
||||
/// with all signals etc to make it communicate with this object
|
||||
void setPdmObject(PdmObject* object, QString uiConfigName) { m_pdmObject = object; }
|
||||
PdmObject* pdmObject() { return m_pdmObject; }
|
||||
|
||||
virtual void updateUi(QString uiConfigName) = 0;
|
||||
|
||||
protected:
|
||||
|
||||
virtual QWidget* createWidget(QWidget* parent) = 0;
|
||||
|
||||
private:
|
||||
PdmObject* m_pdmObject;
|
||||
QPointer<QWidget> m_widget;
|
||||
PdmUiEditorAttribute() {}
|
||||
virtual ~PdmUiEditorAttribute() {}
|
||||
};
|
||||
|
||||
|
||||
|
||||
class PdmUiFieldViewHandle : public QObject
|
||||
|
||||
class PdmUiDefaultObjectEditor : PdmUiObjectEditorHandle
|
||||
{
|
||||
public:
|
||||
PdmUiFieldViewHandle() : m_field(NULL) {}
|
||||
~PdmUiFieldViewHandle()
|
||||
{
|
||||
if (m_field) m_field->removeFieldView(this);
|
||||
|
||||
if (!m_combinedWidget.isNull()) delete m_combinedWidget;
|
||||
if (!m_editorWidget.isNull()) delete m_editorWidget ;
|
||||
if (!m_labelWidget.isNull()) delete m_labelWidget;
|
||||
}
|
||||
|
||||
///
|
||||
PdmFieldHandle* field() { return m_field; }
|
||||
void setField(PdmFieldHandle * field)
|
||||
{
|
||||
if (m_field) m_field->removeFieldView(this);
|
||||
m_field = field;
|
||||
if (m_field) m_field->addFieldView(this);
|
||||
}
|
||||
|
||||
|
||||
void setValueToField(const QVariant& value)
|
||||
{
|
||||
if (m_field) m_field->setUiValue(value);
|
||||
}
|
||||
|
||||
void createWidgets(QWidget * parent)
|
||||
{
|
||||
if (m_combinedWidget.isNull()) m_combinedWidget = createCombinedWidget(parent);
|
||||
if (m_editorWidget.isNull()) m_editorWidget = createEditorWidget(parent);
|
||||
if (m_labelWidget.isNull()) m_labelWidget = createLabelWidget(parent);
|
||||
}
|
||||
|
||||
QWidget* combinedWidget() { return m_combinedWidget; }
|
||||
QWidget* editorWidget() { return m_editorWidget; }
|
||||
QWidget* labelWidget() { return m_labelWidget; }
|
||||
|
||||
public: // Virtual interface to override
|
||||
/// Update only the display of the data value, because some other view has changed it.
|
||||
virtual void updateUiValue() = 0;
|
||||
|
||||
/// Supposed to update all parts of the widgets, both visibility, sensitivity, decorations and field data
|
||||
virtual void updateUi(QString uiConfigName) = 0;
|
||||
|
||||
/// Supposed to do all wiring of singals and slots
|
||||
virtual void connectUi() = 0;
|
||||
|
||||
protected: // Virtual interface to override
|
||||
/// Implement one of these, or both editor and label. The widgets will be used in the parent layout according to
|
||||
/// being "Label" Editor" or a single combined widget.
|
||||
|
||||
virtual QWidget* createCombinedWidget(QWidget * parent) { return NULL; }
|
||||
virtual QWidget* createEditorWidget(QWidget * parent) { return NULL; }
|
||||
virtual QWidget* createLabelWidget(QWidget * parent) { return NULL; }
|
||||
|
||||
private:
|
||||
PdmFieldHandle* m_field;
|
||||
|
||||
QPointer<QWidget> m_combinedWidget;
|
||||
QPointer<QWidget> m_editorWidget;
|
||||
QPointer<QWidget> m_labelWidget;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class PdmStdObjView : PdmObjectViewHandle
|
||||
{
|
||||
public:
|
||||
PdmStdObjView() {};
|
||||
~PdmStdObjView() {}
|
||||
PdmUiDefaultObjectEditor() {};
|
||||
~PdmUiDefaultObjectEditor() {}
|
||||
|
||||
protected:
|
||||
|
||||
@@ -339,8 +358,8 @@ protected:
|
||||
|
||||
virtual void updateUi(QString uiConfigName)
|
||||
{
|
||||
PdmUiConfiguration config;
|
||||
m_pdmObject->uiConfiguration(uiConfigName, &config);
|
||||
PdmUiOrdering config;
|
||||
m_pdmObject->uiOrdering(uiConfigName, &config);
|
||||
|
||||
// Set all fieldViews to be unvisited
|
||||
std::map<QString, PdmFieldViewHandle*>::iterator it;
|
||||
@@ -435,13 +454,13 @@ protected:
|
||||
else
|
||||
{
|
||||
PdmFieldHandle* field = dynamic_cast<PdmFieldHandle*>(uiItems[i]);
|
||||
PdmUiFieldViewHandle* fvh = NULL;
|
||||
PdmUiFieldEditorHandle* fvh = NULL;
|
||||
|
||||
if (!field->isHidden(uiConfName))
|
||||
{
|
||||
|
||||
// Find or create FieldView
|
||||
std::map<QString, PdmUiFieldViewHandle*>::iterator it;
|
||||
std::map<QString, PdmUiFieldEditorHandle*>::iterator it;
|
||||
it = m_fieldViews.find(field->keyword());
|
||||
|
||||
if (it == m_fieldViews.end())
|
||||
@@ -502,7 +521,7 @@ protected:
|
||||
|
||||
private:
|
||||
|
||||
std::map<QString, PdmUiFieldViewHandle*> m_fieldViews;
|
||||
std::map<QString, PdmUiFieldEditorHandle*> m_fieldViews;
|
||||
std::map<QString, QPointer<QGroupBox> > m_groupBoxes;
|
||||
std::map<QString, QPointer<QGroupBox> > m_newGroupBoxes; ///< used temporarily to store the new(complete) set of group boxes
|
||||
|
||||
@@ -512,30 +531,23 @@ private:
|
||||
|
||||
|
||||
|
||||
caf::Factory<PdmUiFieldViewHandle, type_info>::instance()->registerCreator<PdmLineEditFieldView>(typeid(PdmField<QString>));
|
||||
caf::Factory<PdmUiFieldViewHandle, type_info>::instance()->registerCreator<PdmLineEditFieldView>(typeid(PdmField<int>));
|
||||
caf::Factory<PdmUiFieldViewHandle, type_info>::instance()->registerCreator<PdmLineEditFieldView>(typeid(PdmField<double>));
|
||||
caf::Factory<PdmUiFieldViewHandle, type_info>::instance()->registerCreator<PdmLineEditFieldView>(typeid(PdmField<size_t>));
|
||||
caf::Factory<PdmUiFieldEditorHandle, type_info>::instance()->registerCreator<PdmUiLineEditor>(typeid(PdmField<QString>));
|
||||
caf::Factory<PdmUiFieldEditorHandle, type_info>::instance()->registerCreator<PdmUiLineEditor>(typeid(PdmField<int>));
|
||||
caf::Factory<PdmUiFieldEditorHandle, type_info>::instance()->registerCreator<PdmUiLineEditor>(typeid(PdmField<double>));
|
||||
caf::Factory<PdmUiFieldEditorHandle, type_info>::instance()->registerCreator<PdmUiLineEditor>(typeid(PdmField<size_t>));
|
||||
|
||||
caf::Factory<PdmUiFieldViewHandle, type_info>::instance()->registerCreator<PdmLineEditFieldView>(typeid(PdmUiFileEditor));
|
||||
caf::Factory<PdmUiFieldEditorHandle, type_info>::instance()->registerCreator<PdmUiLineEditor>(typeid(PdmUiFileEditor));
|
||||
|
||||
class PdmUiAttributeHandle
|
||||
{
|
||||
public:
|
||||
PdmUiAttributeHandle() {}
|
||||
virtual ~PdmUiAttributeHandle() {}
|
||||
};
|
||||
|
||||
class PdmLineEditAttribute : public PdmUiAttributeHandle
|
||||
class PdmUiLineEditorAttribute : public PdmUiEditorAttribute
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
class PdmLineEditFieldView : public PdmUiFieldViewHandle
|
||||
class PdmUiLineEditor : public PdmUiFieldEditorHandle
|
||||
{
|
||||
public:
|
||||
PdmLineEditFieldView() {}
|
||||
virtual ~PdmLineEditFieldView() {}
|
||||
PdmUiLineEditor() {}
|
||||
virtual ~PdmUiLineEditor() {}
|
||||
|
||||
|
||||
virtual void updateUiValue()
|
||||
@@ -563,8 +575,8 @@ public:
|
||||
m_lineEdit->setEnabled(!m_field->readOnly(uiConfigName));
|
||||
m_label->setEnabled(!m_field->readOnly(uiConfigName));
|
||||
|
||||
PdmLineEditAttribute leab;
|
||||
m_field->ownerObject()->setUpUiAttribute(m_field, uiConfigName, &leab);
|
||||
PdmUiLineEditorAttribute leab;
|
||||
m_field->ownerObject()->defineEditorAttribute(m_field, uiConfigName, &leab);
|
||||
|
||||
if (dynamic_cast<PdmField<int>*> (m_field))
|
||||
{
|
||||
@@ -628,7 +640,7 @@ DemoPdmObj::DemoPdmObj()
|
||||
|
||||
}
|
||||
|
||||
void DemoPdmObj::setUpUIConfiguration(QString uiConfigName, PdmUiConfiguration& uiConfig)
|
||||
void DemoPdmObj::setUpUIConfiguration(QString uiConfigName, PdmUiOrdering& uiConfig)
|
||||
{
|
||||
if (uiConfigName == "DetailsView")
|
||||
{
|
||||
|
||||
45
cafProjectDataModel/cafPdmUiEditorHandle.cpp
Normal file
45
cafProjectDataModel/cafPdmUiEditorHandle.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#include "cafPdmUiEditorHandle.h"
|
||||
#include "cafPdmUiItem.h"
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PdmUiEditorHandle::~PdmUiEditorHandle()
|
||||
{
|
||||
if (m_pdmItem) m_pdmItem->removeFieldEditor(this);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiEditorHandle::bindToPdmItem(PdmUiItem* item)
|
||||
{
|
||||
if (m_pdmItem) m_pdmItem->removeFieldEditor(this);
|
||||
m_pdmItem = item;
|
||||
if (m_pdmItem) m_pdmItem->addFieldEditor(this);
|
||||
}
|
||||
|
||||
} //End of namespace caf
|
||||
|
||||
75
cafProjectDataModel/cafPdmUiEditorHandle.h
Normal file
75
cafProjectDataModel/cafPdmUiEditorHandle.h
Normal file
@@ -0,0 +1,75 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <QString>
|
||||
#include <QObject>
|
||||
#include "cafPdmUiItem.h"
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
class PdmUiItem;
|
||||
|
||||
//==================================================================================================
|
||||
/// Abstract class to handle editors
|
||||
//==================================================================================================
|
||||
|
||||
class PdmUiEditorHandle: public QObject
|
||||
{
|
||||
public:
|
||||
PdmUiEditorHandle() : m_pdmItem(NULL) {}
|
||||
virtual ~PdmUiEditorHandle();
|
||||
|
||||
public:
|
||||
/// Virtual method to be overridden. Needs to set up the supplied widget
|
||||
/// with all signals etc to make it communicate with this object
|
||||
|
||||
void updateUi(const QString& uiConfigName)
|
||||
{
|
||||
m_currentConfigName = uiConfigName;
|
||||
this->configureAndUpdateUi(uiConfigName);
|
||||
};
|
||||
|
||||
void updateUi()
|
||||
{
|
||||
this->configureAndUpdateUi(m_currentConfigName);
|
||||
};
|
||||
|
||||
protected: // Interface to override:
|
||||
|
||||
/// Supposed to update all parts of the widgets, both visibility, sensitivity, decorations and field data
|
||||
virtual void configureAndUpdateUi(const QString& uiConfigName) = 0;
|
||||
|
||||
protected:
|
||||
/// This needs to be called from subclass when connecting to a PdmField or Object
|
||||
void bindToPdmItem(PdmUiItem* item);
|
||||
PdmUiItem* pdmItem() { return m_pdmItem; }
|
||||
|
||||
private:
|
||||
friend PdmUiItem::~PdmUiItem();
|
||||
PdmUiItem* m_pdmItem;
|
||||
QString m_currentConfigName;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // End of namespace caf
|
||||
|
||||
83
cafProjectDataModel/cafPdmUiFieldEditorHandle.cpp
Normal file
83
cafProjectDataModel/cafPdmUiFieldEditorHandle.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#include "cafPdmUiFieldEditorHandle.h"
|
||||
#include "cafPdmField.h"
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PdmUiFieldEditorHandle::PdmUiFieldEditorHandle()
|
||||
{
|
||||
m_combinedWidget = QPointer<QWidget>();
|
||||
m_editorWidget = QPointer<QWidget>();
|
||||
m_labelWidget = QPointer<QWidget>();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PdmUiFieldEditorHandle::~PdmUiFieldEditorHandle()
|
||||
{
|
||||
if (!m_combinedWidget.isNull()) delete m_combinedWidget;
|
||||
if (!m_editorWidget.isNull()) delete m_editorWidget ;
|
||||
if (!m_labelWidget.isNull()) delete m_labelWidget;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiFieldEditorHandle::setField(PdmFieldHandle * field)
|
||||
{
|
||||
this->bindToPdmItem(field);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PdmFieldHandle* PdmUiFieldEditorHandle::field()
|
||||
{
|
||||
return dynamic_cast<PdmFieldHandle*>(pdmItem());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiFieldEditorHandle::createWidgets(QWidget * parent)
|
||||
{
|
||||
if (m_combinedWidget.isNull()) m_combinedWidget = createCombinedWidget(parent);
|
||||
if (m_editorWidget.isNull()) m_editorWidget = createEditorWidget(parent);
|
||||
if (m_labelWidget.isNull()) m_labelWidget = createLabelWidget(parent);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiFieldEditorHandle::setValueToField(const QVariant& value)
|
||||
{
|
||||
if (field()) field()->setValueFromUi(value);
|
||||
}
|
||||
|
||||
|
||||
} //End of namespace caf
|
||||
|
||||
123
cafProjectDataModel/cafPdmUiFieldEditorHandle.h
Normal file
123
cafProjectDataModel/cafPdmUiFieldEditorHandle.h
Normal file
@@ -0,0 +1,123 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <QString>
|
||||
|
||||
#include "cafPdmUiItem.h"
|
||||
#include <QPointer>
|
||||
#include <QWidget>
|
||||
|
||||
#include "cafFactory.h"
|
||||
|
||||
#include "cafPdmUiEditorHandle.h"
|
||||
|
||||
// Taken from gtest.h
|
||||
//
|
||||
// Due to C++ preprocessor weirdness, we need double indirection to
|
||||
// concatenate two tokens when one of them is __LINE__. Writing
|
||||
//
|
||||
// foo ## __LINE__
|
||||
//
|
||||
// will result in the token foo__LINE__, instead of foo followed by
|
||||
// the current line number. For more details, see
|
||||
// http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.6
|
||||
#define PDM_FIELD_EDITOR_STRING_CONCATENATE(foo, bar) PDM_FIELD_EDITOR_STRING_CONCATENATE_IMPL_(foo, bar)
|
||||
#define PDM_FIELD_EDITOR_STRING_CONCATENATE_IMPL_(foo, bar) foo ## bar
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
//==================================================================================================
|
||||
/// Macros helping in development of PDM UI editors
|
||||
//==================================================================================================
|
||||
|
||||
/// Create a QString based on a typename
|
||||
#define qStringTypeName(TypeName) QString(typeid(TypeName).name())
|
||||
|
||||
/// CAF_PDM_UI_EDITOR_HEADER_INIT assists the factory used when creating editors
|
||||
/// Place this in the header file inside the class definition of your PdmUiEditor
|
||||
|
||||
#define CAF_PDM_UI_FIELD_EDITOR_HEADER_INIT \
|
||||
public: \
|
||||
static QString uiEditorTypeName()
|
||||
|
||||
/// CAF_PDM_UI_FIELD_EDITOR_SOURCE_INIT implements editorTypeName() and registers the field editor in the field editor factory
|
||||
/// Place this in the cpp file, preferably above the constructor
|
||||
|
||||
#define CAF_PDM_UI_FIELD_EDITOR_SOURCE_INIT(EditorClassName) \
|
||||
QString EditorClassName::uiEditorTypeName() { return #EditorClassName; } \
|
||||
static bool PDM_FIELD_EDITOR_STRING_CONCATENATE(pdm_field_editor_registrate_, __LINE__) = caf::Factory<caf::PdmUiFieldEditorHandle, QString>::instance()->registerCreator<EditorClassName>(EditorClassName::uiEditorTypeName())
|
||||
|
||||
#define CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(EditorClassName, TypeName) \
|
||||
static bool PDM_FIELD_EDITOR_STRING_CONCATENATE(pdm_field_register_default_editor_, __LINE__) = caf::Factory<caf::PdmUiFieldEditorHandle, QString>::instance()->registerCreator<EditorClassName>(qStringTypeName(caf::PdmField<TypeName>))
|
||||
|
||||
class PdmUiGroup;
|
||||
class PdmFieldHandle;
|
||||
|
||||
//==================================================================================================
|
||||
/// Abstract class to handle editors of PdmFields
|
||||
//==================================================================================================
|
||||
|
||||
class PdmUiFieldEditorHandle : public PdmUiEditorHandle
|
||||
{
|
||||
public:
|
||||
|
||||
PdmUiFieldEditorHandle();
|
||||
~PdmUiFieldEditorHandle();
|
||||
|
||||
PdmFieldHandle* field();
|
||||
void setField(PdmFieldHandle * field);
|
||||
|
||||
void createWidgets(QWidget * parent);
|
||||
QWidget* combinedWidget() { return m_combinedWidget; }
|
||||
QWidget* editorWidget() { return m_editorWidget; }
|
||||
QWidget* labelWidget() { return m_labelWidget; }
|
||||
|
||||
protected: // Virtual interface to override
|
||||
/// Implement one of these, or both editor and label. The widgets will be used in the parent layout according to
|
||||
/// being "Label" Editor" or a single combined widget.
|
||||
|
||||
virtual QWidget* createCombinedWidget(QWidget * parent) { return NULL; }
|
||||
virtual QWidget* createEditorWidget(QWidget * parent) { return NULL; }
|
||||
virtual QWidget* createLabelWidget(QWidget * parent) { return NULL; }
|
||||
|
||||
void setValueToField(const QVariant& value);
|
||||
|
||||
private:
|
||||
QPointer<QWidget> m_combinedWidget;
|
||||
QPointer<QWidget> m_editorWidget;
|
||||
QPointer<QWidget> m_labelWidget;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
/// Abstract base class to handle special editor dependent attributes
|
||||
//==================================================================================================
|
||||
|
||||
class PdmUiEditorAttribute
|
||||
{
|
||||
public:
|
||||
PdmUiEditorAttribute() {}
|
||||
virtual ~PdmUiEditorAttribute() {}
|
||||
};
|
||||
|
||||
|
||||
} // End of namespace caf
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
//##################################################################################################
|
||||
|
||||
#include "cafPdmUiItem.h"
|
||||
|
||||
#include "cafPdmUiEditorHandle.h"
|
||||
|
||||
namespace caf
|
||||
{
|
||||
@@ -62,64 +62,168 @@ bool PdmOptionItemInfo::findValue(const QList<PdmOptionItemInfo>& optionList , Q
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const QString PdmUiItem::uiName() const
|
||||
const QString PdmUiItem::uiName(QString uiConfigName) const
|
||||
{
|
||||
if(m_dynamicItemInfo.m_uiName.isNull())
|
||||
const PdmUiItemInfo* conInfo = configInfo(uiConfigName);
|
||||
const PdmUiItemInfo* defInfo = defaultInfo();
|
||||
const PdmUiItemInfo* sttInfo = m_staticItemInfo;
|
||||
|
||||
if (conInfo && !(conInfo->m_uiName.isNull())) return conInfo->m_uiName;
|
||||
if (defInfo && !(defInfo->m_uiName.isNull())) return defInfo->m_uiName;
|
||||
if (sttInfo && !(sttInfo->m_uiName.isNull())) return sttInfo->m_uiName;
|
||||
|
||||
return QString("");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const QIcon PdmUiItem::uiIcon(QString uiConfigName) const
|
||||
{
|
||||
const PdmUiItemInfo* conInfo = configInfo(uiConfigName);
|
||||
const PdmUiItemInfo* defInfo = defaultInfo();
|
||||
const PdmUiItemInfo* sttInfo = m_staticItemInfo;
|
||||
|
||||
if (conInfo && !(conInfo->m_icon.isNull())) return conInfo->m_icon;
|
||||
if (defInfo && !(defInfo->m_icon.isNull())) return defInfo->m_icon;
|
||||
if (sttInfo && !(sttInfo->m_icon.isNull())) return sttInfo->m_icon;
|
||||
|
||||
return QIcon();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const QString PdmUiItem::uiToolTip(QString uiConfigName) const
|
||||
{
|
||||
const PdmUiItemInfo* conInfo = configInfo(uiConfigName);
|
||||
const PdmUiItemInfo* defInfo = defaultInfo();
|
||||
const PdmUiItemInfo* sttInfo = m_staticItemInfo;
|
||||
|
||||
if (conInfo && !(conInfo->m_toolTip.isNull())) return conInfo->m_toolTip;
|
||||
if (defInfo && !(defInfo->m_toolTip.isNull())) return defInfo->m_toolTip;
|
||||
if (sttInfo && !(sttInfo->m_toolTip.isNull())) return sttInfo->m_toolTip;
|
||||
|
||||
return QString("");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const QString PdmUiItem::uiWhatsThis(QString uiConfigName) const
|
||||
{
|
||||
const PdmUiItemInfo* conInfo = configInfo(uiConfigName);
|
||||
const PdmUiItemInfo* defInfo = defaultInfo();
|
||||
const PdmUiItemInfo* sttInfo = m_staticItemInfo;
|
||||
|
||||
if (conInfo && !(conInfo->m_whatsThis.isNull())) return conInfo->m_whatsThis;
|
||||
if (defInfo && !(defInfo->m_whatsThis.isNull())) return defInfo->m_whatsThis;
|
||||
if (sttInfo && !(sttInfo->m_whatsThis.isNull())) return sttInfo->m_whatsThis;
|
||||
|
||||
return QString("");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool PdmUiItem::isUiHidden(QString uiConfigName) const
|
||||
{
|
||||
const PdmUiItemInfo* conInfo = configInfo(uiConfigName);
|
||||
const PdmUiItemInfo* defInfo = defaultInfo();
|
||||
const PdmUiItemInfo* sttInfo = m_staticItemInfo;
|
||||
|
||||
if (conInfo && !(conInfo->m_isHidden == -1)) return conInfo->m_isHidden;
|
||||
if (defInfo && !(defInfo->m_isHidden == -1)) return defInfo->m_isHidden;
|
||||
if (sttInfo && !(sttInfo->m_isHidden == -1)) return sttInfo->m_isHidden;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool PdmUiItem::isUiReadOnly(QString uiConfigName /*= ""*/)
|
||||
{
|
||||
const PdmUiItemInfo* conInfo = configInfo(uiConfigName);
|
||||
const PdmUiItemInfo* defInfo = defaultInfo();
|
||||
const PdmUiItemInfo* sttInfo = m_staticItemInfo;
|
||||
|
||||
if (conInfo && !(conInfo->m_isReadOnly == -1)) return conInfo->m_isReadOnly;
|
||||
if (defInfo && !(defInfo->m_isReadOnly == -1)) return defInfo->m_isReadOnly;
|
||||
if (sttInfo && !(sttInfo->m_isReadOnly == -1)) return sttInfo->m_isReadOnly;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString PdmUiItem::uiEditorTypeName(const QString& uiConfigName) const
|
||||
{
|
||||
const PdmUiItemInfo* conInfo = configInfo(uiConfigName);
|
||||
const PdmUiItemInfo* defInfo = defaultInfo();
|
||||
const PdmUiItemInfo* sttInfo = m_staticItemInfo;
|
||||
|
||||
if (conInfo && !(conInfo->m_editorTypeName.isEmpty())) return conInfo->m_editorTypeName;
|
||||
if (defInfo && !(defInfo->m_editorTypeName.isEmpty())) return defInfo->m_editorTypeName;
|
||||
if (sttInfo && !(sttInfo->m_editorTypeName.isEmpty())) return sttInfo->m_editorTypeName;
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
const PdmUiItemInfo* PdmUiItem::configInfo(QString uiConfigName) const
|
||||
{
|
||||
if (uiConfigName == "" || uiConfigName.isNull()) return NULL;
|
||||
|
||||
std::map<QString, PdmUiItemInfo>::const_iterator it;
|
||||
it = m_configItemInfos.find(uiConfigName);
|
||||
|
||||
if (it != m_configItemInfos.end()) return &(it->second);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
const PdmUiItemInfo* PdmUiItem::defaultInfo() const
|
||||
{
|
||||
std::map<QString, PdmUiItemInfo>::const_iterator it;
|
||||
it = m_configItemInfos.find("");
|
||||
|
||||
if (it != m_configItemInfos.end()) return &(it->second);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiItem::updateConnectedEditors()
|
||||
{
|
||||
std::set<PdmUiEditorHandle*>::iterator it;
|
||||
for (it = m_editors.begin(); it != m_editors.end(); ++it)
|
||||
{
|
||||
if(m_staticItemInfo) return m_staticItemInfo->m_uiName;
|
||||
else return QString("");
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_dynamicItemInfo.m_uiName;
|
||||
(*it)->updateUi();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const QIcon PdmUiItem::uiIcon() const
|
||||
PdmUiItem::~PdmUiItem()
|
||||
{
|
||||
if(m_dynamicItemInfo.m_icon.isNull())
|
||||
std::set<PdmUiEditorHandle*>::iterator it;
|
||||
for (it = m_editors.begin(); it != m_editors.end(); ++it)
|
||||
{
|
||||
if(m_staticItemInfo) return m_staticItemInfo->m_icon;
|
||||
else return QIcon();
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_dynamicItemInfo.m_icon;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const QString PdmUiItem::uiToolTip() const
|
||||
{
|
||||
if(m_dynamicItemInfo.m_toolTip.isNull())
|
||||
{
|
||||
if(m_staticItemInfo) return m_staticItemInfo->m_toolTip;
|
||||
else return QString("");
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_dynamicItemInfo.m_toolTip;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const QString PdmUiItem::uiWhatsThis() const
|
||||
{
|
||||
if(m_dynamicItemInfo.m_whatsThis.isNull())
|
||||
{
|
||||
if(m_staticItemInfo) return m_staticItemInfo->m_whatsThis;
|
||||
else return QString("");
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_dynamicItemInfo.m_whatsThis;
|
||||
(*it)->m_pdmItem = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <QString>
|
||||
#include <QIcon>
|
||||
#include <QVariant>
|
||||
#include <set>
|
||||
|
||||
namespace caf
|
||||
{
|
||||
@@ -33,16 +34,24 @@ namespace caf
|
||||
class PdmUiItemInfo
|
||||
{
|
||||
public:
|
||||
PdmUiItemInfo() {}
|
||||
PdmUiItemInfo()
|
||||
: m_editorTypeName(""), m_isHidden(-1) , m_isReadOnly(-1)
|
||||
{}
|
||||
|
||||
PdmUiItemInfo( QString uiName, QIcon icon = QIcon(), QString toolTip = "", QString whatsThis = "")
|
||||
: m_uiName(uiName), m_icon(icon), m_toolTip(toolTip), m_whatsThis(whatsThis)
|
||||
: m_uiName(uiName), m_icon(icon), m_toolTip(toolTip), m_whatsThis(whatsThis),
|
||||
m_editorTypeName(""), m_isHidden(false) , m_isReadOnly(false)
|
||||
{ }
|
||||
|
||||
QString m_uiName;
|
||||
QString m_toolTip;
|
||||
QString m_whatsThis;
|
||||
QIcon m_icon;
|
||||
private:
|
||||
friend class PdmUiItem;
|
||||
QString m_uiName;
|
||||
QString m_toolTip;
|
||||
QString m_whatsThis;
|
||||
QIcon m_icon;
|
||||
QString m_editorTypeName; ///< Use this exact type of editor to edit this UiItem
|
||||
int m_isHidden; ///< UiItem should be hidden. -1 means not set
|
||||
int m_isReadOnly; ///< UiItem should be insensitive, or read only. -1 means not set.
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
@@ -68,6 +77,8 @@ public:
|
||||
unsigned int* indexToValue = NULL);
|
||||
};
|
||||
|
||||
class PdmUiEditorHandle;
|
||||
|
||||
//==================================================================================================
|
||||
/// Base class for all datastructure items (fields or objects) to make them have information on
|
||||
/// how to display them in the GUI. All the information can have a static variant valid for all
|
||||
@@ -78,39 +89,59 @@ public:
|
||||
class PdmUiItem
|
||||
{
|
||||
public:
|
||||
PdmUiItem() : m_staticItemInfo(NULL), m_isHidden(false) { }
|
||||
virtual ~PdmUiItem() { }
|
||||
PdmUiItem() : m_staticItemInfo(NULL) { }
|
||||
virtual ~PdmUiItem();
|
||||
|
||||
// Copy and assignment to avoid hampering our internal pointer.
|
||||
PdmUiItem(const PdmUiItem& ) : m_staticItemInfo(NULL) , m_isHidden(false) { }
|
||||
PdmUiItem& operator=(const PdmUiItem& ) { return *this; }
|
||||
PdmUiItem(const PdmUiItem& ) : m_staticItemInfo(NULL) { }
|
||||
PdmUiItem& operator=(const PdmUiItem& ) { return *this; }
|
||||
|
||||
const QString uiName() const;
|
||||
void setUiName(const QString& uiName) { m_dynamicItemInfo.m_uiName = uiName; }
|
||||
const QString uiName(QString uiConfigName = "") const;
|
||||
void setUiName(const QString& uiName, QString uiConfigName = "") { m_configItemInfos[uiConfigName].m_uiName = uiName; }
|
||||
|
||||
const QIcon uiIcon() const;
|
||||
void setUiIcon(const QIcon& uiIcon) { m_dynamicItemInfo.m_icon = uiIcon; }
|
||||
const QIcon uiIcon(QString uiConfigName = "") const;
|
||||
void setUiIcon(const QIcon& uiIcon, QString uiConfigName = "") { m_configItemInfos[uiConfigName].m_icon = uiIcon; }
|
||||
|
||||
const QString uiToolTip() const;
|
||||
void setUiToolTip(const QString& uiToolTip) { m_dynamicItemInfo.m_toolTip = uiToolTip; }
|
||||
const QString uiToolTip(QString uiConfigName = "") const;
|
||||
void setUiToolTip(const QString& uiToolTip, QString uiConfigName = "") { m_configItemInfos[uiConfigName].m_toolTip = uiToolTip; }
|
||||
|
||||
const QString uiWhatsThis() const;
|
||||
void setUiWhatsThis(const QString& uiWhatsThis) { m_dynamicItemInfo.m_whatsThis = uiWhatsThis; }
|
||||
const QString uiWhatsThis(QString uiConfigName = "") const;
|
||||
void setUiWhatsThis(const QString& uiWhatsThis, QString uiConfigName = "") { m_configItemInfos[uiConfigName].m_whatsThis = uiWhatsThis; }
|
||||
|
||||
bool isHidden() const { return m_isHidden; }
|
||||
void setHidden(bool isHidden) { m_isHidden = isHidden; }
|
||||
bool isUiHidden(QString uiConfigName = "") const;
|
||||
void setUiHidden(bool isHidden, QString uiConfigName = "") { m_configItemInfos[uiConfigName].m_isHidden = isHidden; }
|
||||
|
||||
bool isUiReadOnly(QString uiConfigName = "");
|
||||
void setUiReadOnly(bool isReadOnly, QString uiConfigName = "") { m_configItemInfos[uiConfigName].m_isReadOnly = isReadOnly; }
|
||||
|
||||
QString uiEditorTypeName(const QString& uiConfigName) const;
|
||||
void setUiEditorTypeName(const QString& editorTypeName, QString uiConfigName = "") { m_configItemInfos[uiConfigName].m_editorTypeName = editorTypeName; }
|
||||
|
||||
virtual bool isUiGroup() { return false; }
|
||||
|
||||
void updateConnectedEditors();
|
||||
|
||||
public: // Pdm-Private only
|
||||
//==================================================================================================
|
||||
/// This method sets the GUI description pointer, which is supposed to be statically allocated
|
||||
/// somewhere. the PdmGuiEntry class will not delete it in any way, and always trust it to be present.
|
||||
/// Consider as PRIVATE to the PdmSystem
|
||||
//==================================================================================================
|
||||
|
||||
void setUiItemInfo(PdmUiItemInfo* itemInfo) { m_staticItemInfo = itemInfo; }
|
||||
void setUiItemInfo(PdmUiItemInfo* itemInfo) { m_staticItemInfo = itemInfo; }
|
||||
|
||||
void removeFieldEditor(PdmUiEditorHandle* fieldView) { m_editors.erase(fieldView); }
|
||||
void addFieldEditor(PdmUiEditorHandle* fieldView) { m_editors.insert(fieldView); }
|
||||
|
||||
protected:
|
||||
std::set<PdmUiEditorHandle*> m_editors;
|
||||
|
||||
private:
|
||||
PdmUiItemInfo* m_staticItemInfo;
|
||||
PdmUiItemInfo m_dynamicItemInfo;
|
||||
bool m_isHidden;
|
||||
const PdmUiItemInfo* defaultInfo() const;
|
||||
const PdmUiItemInfo* configInfo(QString uiConfigName) const;
|
||||
|
||||
PdmUiItemInfo* m_staticItemInfo;
|
||||
std::map< QString, PdmUiItemInfo > m_configItemInfos;
|
||||
};
|
||||
|
||||
|
||||
|
||||
56
cafProjectDataModel/cafPdmUiObjectEditorHandle.cpp
Normal file
56
cafProjectDataModel/cafPdmUiObjectEditorHandle.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#include "cafPdmUiObjectEditorHandle.h"
|
||||
#include "cafPdmObject.h"
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QWidget* PdmUiObjectEditorHandle::getOrCreateWidget(QWidget* parent)
|
||||
{
|
||||
if (m_widget.isNull())
|
||||
{
|
||||
m_widget = this->createWidget(parent);
|
||||
}
|
||||
return m_widget;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiObjectEditorHandle::setPdmObject(PdmObject* object)
|
||||
{
|
||||
this->bindToPdmItem(object);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PdmObject* PdmUiObjectEditorHandle::pdmObject()
|
||||
{
|
||||
return dynamic_cast<PdmObject*>(pdmItem());
|
||||
}
|
||||
|
||||
} //End of namespace caf
|
||||
|
||||
59
cafProjectDataModel/cafPdmUiObjectEditorHandle.h
Normal file
59
cafProjectDataModel/cafPdmUiObjectEditorHandle.h
Normal file
@@ -0,0 +1,59 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <QString>
|
||||
#include <QWidget>
|
||||
#include <QPointer>
|
||||
#include "cafPdmUiEditorHandle.h"
|
||||
#include "cafPdmPointer.h"
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
class PdmObject;
|
||||
|
||||
//==================================================================================================
|
||||
/// Abstract class to handle editors for complete PdmObjects
|
||||
//==================================================================================================
|
||||
|
||||
class PdmUiObjectEditorHandle: public PdmUiEditorHandle
|
||||
{
|
||||
public:
|
||||
PdmUiObjectEditorHandle() {}
|
||||
~PdmUiObjectEditorHandle() {}
|
||||
|
||||
QWidget* getOrCreateWidget(QWidget* parent);
|
||||
QWidget* widget() { return m_widget; }
|
||||
|
||||
void setPdmObject(PdmObject* object);
|
||||
PdmObject* pdmObject();
|
||||
|
||||
protected:
|
||||
virtual QWidget* createWidget(QWidget* parent) = 0;
|
||||
|
||||
protected:
|
||||
QPointer<QWidget> m_widget;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // End of namespace caf
|
||||
|
||||
70
cafProjectDataModel/cafPdmUiOrdering.cpp
Normal file
70
cafProjectDataModel/cafPdmUiOrdering.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#include "cafPdmUiOrdering.h"
|
||||
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PdmUiOrdering::~PdmUiOrdering()
|
||||
{
|
||||
for (size_t i = 0; i < m_createdGroups.size(); ++i)
|
||||
{
|
||||
delete m_createdGroups[i];
|
||||
m_createdGroups[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PdmUiGroup* PdmUiOrdering::addNewGroup(QString displayName)
|
||||
{
|
||||
PdmUiGroup* group = new PdmUiGroup;
|
||||
group->setUiName(displayName);
|
||||
|
||||
m_createdGroups.push_back(group);
|
||||
m_ordering.push_back(group);
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool PdmUiOrdering::contains(const PdmUiItem* item)
|
||||
{
|
||||
for (size_t i = 0; i < m_ordering.size(); ++i)
|
||||
{
|
||||
if (m_ordering[i] == item) return true;
|
||||
if (m_ordering[i] && m_ordering[i]->isUiGroup())
|
||||
{
|
||||
if (static_cast<PdmUiGroup*>(m_ordering[i])->contains(item)) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} //End of namespace caf
|
||||
|
||||
75
cafProjectDataModel/cafPdmUiOrdering.h
Normal file
75
cafProjectDataModel/cafPdmUiOrdering.h
Normal file
@@ -0,0 +1,75 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <QString>
|
||||
|
||||
#include "cafPdmUiItem.h"
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
class PdmUiGroup;
|
||||
|
||||
//==================================================================================================
|
||||
/// Class storing the order and grouping of fields and groups of fields etc. to be used in the Gui
|
||||
//==================================================================================================
|
||||
|
||||
class PdmUiOrdering
|
||||
{
|
||||
public:
|
||||
PdmUiOrdering(): m_forgetRemainingFields(false) { };
|
||||
virtual ~PdmUiOrdering();
|
||||
|
||||
PdmUiGroup* addNewGroup(QString displayName);
|
||||
void add(PdmUiItem* item) { m_ordering.push_back(item); }
|
||||
|
||||
/// HACK constness of this class and functions must be revisited
|
||||
void add(const PdmUiItem* item) { m_ordering.push_back(const_cast<PdmUiItem*>(item)); }
|
||||
|
||||
bool forgetRemainingFields() const { return m_forgetRemainingFields; }
|
||||
void setForgetRemainingFields(bool val) { m_forgetRemainingFields = val; }
|
||||
|
||||
const std::vector<PdmUiItem*>& uiItems() const { return m_ordering; }
|
||||
bool contains(const PdmUiItem* item);
|
||||
|
||||
private:
|
||||
// Private copy constructor and assignment to prevent this. (The vectors below will make trouble)
|
||||
PdmUiOrdering(const PdmUiOrdering& other) { }
|
||||
PdmUiOrdering& operator= (const PdmUiOrdering& other) { }
|
||||
|
||||
std::vector<PdmUiItem*> m_ordering; ///< The order of groups and fields
|
||||
std::vector<PdmUiGroup*> m_createdGroups; ///< Owned PdmUiGroups, for mem management
|
||||
bool m_forgetRemainingFields;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
/// Class representing a group of fields
|
||||
//==================================================================================================
|
||||
|
||||
class PdmUiGroup : public PdmUiItem, public PdmUiOrdering
|
||||
{
|
||||
virtual bool isUiGroup() { return true; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // End of namespace caf
|
||||
|
||||
Reference in New Issue
Block a user