Skip to content
Snippets Groups Projects
Commit c3415553 authored by Van Herck, Walter's avatar Van Herck, Walter
Browse files

Merge branch 'propeditor'

parents a971e27b df1742e4
No related branches found
No related tags found
No related merge requests found
Showing
with 208 additions and 484 deletions
......@@ -26,6 +26,9 @@ QList<QString> ItemFactory::m_all_item_names = QList<QString>()
ParameterizedItem *ItemFactory::createItem(const QString &model_name,
ParameterizedItem *parent)
{
if (model_name.isEmpty()) {
return createEmptyItem();
}
if (!m_all_item_names.contains(model_name)) {
return 0;
}
......@@ -40,3 +43,8 @@ ParameterizedItem *ItemFactory::createItem(const QString &model_name,
}
return 0;
}
ParameterizedItem *ItemFactory::createEmptyItem()
{
return new ParameterizedItem();
}
......@@ -21,8 +21,14 @@
class ItemFactory
{
public:
//! create ParameterizedItem of specific type and parent
static ParameterizedItem *createItem(const QString &model_name,
ParameterizedItem *parent=0);
//! create empty ParameterizedItem that serves as a root item
static ParameterizedItem *createEmptyItem();
//! retrieve list of all possible item names
static QList<QString> getAllItemNames() {
return m_all_item_names;
}
......
......@@ -18,7 +18,7 @@
LayerItem::LayerItem(ParameterizedItem *parent)
: ParameterizedItem(QString("Layer"), parent)
{
m_parameters[QString("Thickness")] = 0.0;
setProperty("Thickness", 0.0);
m_valid_children.append(QString("ParticleDecoration"));
}
......
......@@ -20,6 +20,7 @@
class LayerItem : public ParameterizedItem
{
Q_OBJECT
public:
explicit LayerItem(ParameterizedItem *parent=0);
~LayerItem();
......
......@@ -19,7 +19,7 @@
MultiLayerItem::MultiLayerItem(ParameterizedItem *parent)
: ParameterizedItem(QString("MultiLayer"), parent)
{
m_parameters[QString("Cross Correlation Length")] = 0.0;
setProperty("Cross Correlation Length", 0.0);
m_valid_children.append(QString("Layer"));
}
......
......@@ -20,6 +20,7 @@
class MultiLayerItem : public ParameterizedItem
{
Q_OBJECT
public:
explicit MultiLayerItem(ParameterizedItem *parent=0);
~MultiLayerItem();
......
......@@ -41,26 +41,6 @@ ParameterizedItem *ParameterizedItem::takeChildItem(int row)
return item;
}
double ParameterizedItem::parameterValue(const QString &name) const
{
if (!m_parameters.contains(name)) {
throw Exceptions::RuntimeErrorException(
"ParameterizedItem::getParameterValue: "
"parameter does not exist");
}
return m_parameters[name];
}
void ParameterizedItem::setParameter(const QString &name, double value)
{
if (!m_parameters.contains(name)) {
throw Exceptions::RuntimeErrorException(
"ParameterizedItem::getParameterValue: "
"parameter does not exist");
}
m_parameters[name] = value;
}
bool ParameterizedItem::acceptsAsChild(const QString &child_name) const
{
return m_valid_children.contains(child_name);
......
......@@ -20,11 +20,10 @@
#include <QList>
#include <QMap>
class ParameterizedItem
class ParameterizedItem : public QObject
{
Q_OBJECT
public:
explicit ParameterizedItem(const QString &model_type=QString(),
ParameterizedItem *parent=0);
~ParameterizedItem();
//! retrieves the model type
......@@ -73,15 +72,6 @@ public:
//! take child item (this removes it from the current item)
ParameterizedItem *takeChildItem(int row);
//! retrieves the parameter's value
double parameterValue(const QString &name) const;
//! sets the parameter's value, if it exists
void setParameter(const QString &name, double value);
//! retrieves the whole list of paramaters
QMap<QString, double> &parameters() { return m_parameters; }
//! indicates if the passed item can be set as
//! a child item
bool acceptsAsChild(const QString &child_name) const;
......@@ -89,9 +79,12 @@ public:
//! get list of acceptable child object names
QList<QString> acceptableChildItems() const { return m_valid_children; }
friend class ItemFactory;
protected:
explicit ParameterizedItem(const QString &model_type=QString(),
ParameterizedItem *parent=0);
QList<QString> m_valid_children;
QMap<QString, double> m_parameters;
private:
QString m_model_type;
......
......@@ -20,6 +20,7 @@
class ParticleDecorationItem : public ParameterizedItem
{
Q_OBJECT
public:
explicit ParticleDecorationItem(ParameterizedItem *parent=0);
~ParticleDecorationItem();
......
#ifndef SELECTIONLISTMODEL_H_
#define SELECTIONLISTMODEL_H_
// ********************************************************************
// * The BornAgain project *
// * Simulation of neutron and x-ray scattering at grazing incidence *
// * *
// * LICENSE AND DISCLAIMER *
// * Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris *
// * eget quam orci. Quisque porta varius dui, quis posuere nibh *
// * mollis quis. Mauris commodo rhoncus porttitor. *
// ********************************************************************
//! @file SelectionListModel.h
//! @brief Definition of SelectionListModel template
//! @author Scientific Computing Group at FRM II
//! @date Feb 19, 2013
#include "SafePointerVector.h"
//- -------------------------------------------------------------------
//! @class SelectionListModel
//! @brief Definition of a templated list with a selected element
//! \tparam <T> type of the contained elements
//- -------------------------------------------------------------------
template <class T> class SelectionListModel : public SafePointerVector<T>
{
public:
SelectionListModel();
virtual ~SelectionListModel() {}
//! get the currently selected entry
T *getSelectedEntry();
//! get the current selection index
size_t getCurrentIndex() const { return m_selected_index; }
//! set the selection to the indicated entry
void setSelection(size_t index);
private:
bool indexInAllowedRange(size_t index) const;
size_t m_selected_index;
};
template<class T>
inline SelectionListModel<T>::SelectionListModel()
: m_selected_index(0)
{
}
template<class T>
inline T* SelectionListModel<T>::getSelectedEntry()
{
if (indexInAllowedRange(m_selected_index)) {
return (*this)[m_selected_index];
}
return 0;
}
template<class T>
inline void SelectionListModel<T>::setSelection(size_t index)
{
if (indexInAllowedRange(index)) {
m_selected_index = index;
}
}
template<class T>
inline bool SelectionListModel<T>::indexInAllowedRange(size_t index) const
{
return index < this->size();
}
#endif /* SELECTIONLISTMODEL_H_ */
......@@ -228,7 +228,7 @@ ParameterizedItem *SessionModel::insertNewItem(QString model_type,
int row)
{
if (!m_root_item) {
m_root_item = new ParameterizedItem;
m_root_item = ItemFactory::createEmptyItem();
}
ParameterizedItem *parent_item = itemForIndex(parent);
if (row==-1) row = parent_item->childItemCount();
......@@ -267,7 +267,7 @@ void SessionModel::load(const QString &filename)
if (!file.open(QIODevice::ReadOnly))
throw GUIHelpers::Error(file.errorString());
clear();
m_root_item = new ParameterizedItem;
m_root_item = ItemFactory::createEmptyItem();
QXmlStreamReader reader(&file);
readItems(&reader, m_root_item);
if (reader.hasError())
......@@ -300,7 +300,7 @@ ParameterizedItem *SessionModel::insertNewItem(QString model_type,
int row)
{
if (!m_root_item) {
m_root_item = new ParameterizedItem;
m_root_item = ItemFactory::createEmptyItem();
}
if (!parent) parent = m_root_item;
if (row == -1) row = parent->childItemCount();
......@@ -340,13 +340,7 @@ void SessionModel::readItems(QXmlStreamReader *reader, ParameterizedItem *item,
row = -1; // all but the first item should be appended
}
else if (reader->name() == SessionXML::ParameterTag) {
const QString parameter_name = reader->attributes()
.value(SessionXML::ParameterNameAttribute)
.toString();
double parameter_value = reader->attributes()
.value(SessionXML::ParameterValueAttribute)
.toDouble();
item->setParameter(parameter_name, parameter_value);
readProperty(reader, item);
}
}
else if (reader->isEndElement()) {
......@@ -357,6 +351,27 @@ void SessionModel::readItems(QXmlStreamReader *reader, ParameterizedItem *item,
}
}
void SessionModel::readProperty(QXmlStreamReader *reader, ParameterizedItem *item)
{
const QString parameter_name = reader->attributes()
.value(SessionXML::ParameterNameAttribute)
.toString();
const QString parameter_type = reader->attributes()
.value(SessionXML::ParameterTypeAttribute)
.toString();
if (parameter_type == "double") {
double parameter_value = reader->attributes()
.value(SessionXML::ParameterValueAttribute)
.toDouble();
item->setProperty(parameter_name.toUtf8().constData(),
parameter_value);
}
else {
throw GUIHelpers::Error(tr("SessionModel::readProperty: "
"Parameter type not supported"));
}
}
void SessionModel::writeItemAndChildItems(QXmlStreamWriter *writer,
ParameterizedItem *item) const
{
......@@ -366,15 +381,10 @@ void SessionModel::writeItemAndChildItems(QXmlStreamWriter *writer,
item->modelType());
writer->writeAttribute(SessionXML::ItemNameAttribute,
item->itemName());
QMapIterator<QString, double> it(item->parameters());
QListIterator<QByteArray> it(item->dynamicPropertyNames());
while (it.hasNext()) {
it.next();
writer->writeStartElement(SessionXML::ParameterTag);
writer->writeAttribute(SessionXML::ParameterNameAttribute,
it.key());
writer->writeAttribute(SessionXML::ParameterValueAttribute,
QString::number(it.value(), 'g', 12) );
writer->writeEndElement(); // ParameterTag
const char *name = it.next().constData();
writeProperty(writer, item, name);
}
}
foreach (ParameterizedItem *child_item, item->childItems()) {
......@@ -384,3 +394,27 @@ void SessionModel::writeItemAndChildItems(QXmlStreamWriter *writer,
writer->writeEndElement(); // ItemTag
}
}
void SessionModel::writeProperty(QXmlStreamWriter *writer,
ParameterizedItem *item,
const char *property_name) const
{
QVariant variant = item->property(property_name);
if (variant.isValid()) {
writer->writeStartElement(SessionXML::ParameterTag);
writer->writeAttribute(SessionXML::ParameterNameAttribute,
QString(property_name));
writer->writeAttribute(SessionXML::ParameterTypeAttribute,
QString(variant.typeName()) );
switch (variant.type()) {
case QMetaType::Double:
writer->writeAttribute(SessionXML::ParameterValueAttribute,
QString::number(variant.toDouble(), 'e', 12));
break;
default:
throw GUIHelpers::Error(tr("SessionModel::writeProperty: "
"Parameter type not supported"));
}
writer->writeEndElement(); // end ParameterTag
}
}
......@@ -28,6 +28,7 @@ const QString ModelTypeAttribute("ModelType");
const QString ItemNameAttribute("ItemName");
const QString ParameterTag("Parameter");
const QString ParameterNameAttribute("ParName");
const QString ParameterTypeAttribute("ParType");
const QString ParameterValueAttribute("ParValue");
}
......@@ -88,8 +89,11 @@ private:
ParameterizedItem *itemForIndex(const QModelIndex &index) const;
void readItems(QXmlStreamReader *reader, ParameterizedItem *item,
int row=-1);
void readProperty(QXmlStreamReader *reader, ParameterizedItem *item);
void writeItemAndChildItems(QXmlStreamWriter *writer,
ParameterizedItem *item) const;
void writeProperty(QXmlStreamWriter *writer, ParameterizedItem *item,
const char *property_name) const;
QString m_filename;
ParameterizedItem *m_root_item;
};
......
......@@ -14,7 +14,6 @@
//! @author Scientific Computing Group at FRM II
//! @date Feb 19, 2013
#include "SelectionListModel.h"
#include "ISample.h"
#include "ISampleBuilder.h"
#include "Instrument.h"
......
......@@ -26,6 +26,8 @@
#include <QVariant>
#include <iostream>
#include <QItemSelectionModel>
#include <QMetaObject>
#include <QMetaProperty>
#include <QVBoxLayout>
......@@ -39,38 +41,18 @@
#include "DesignerScene.h"
#include "DesignerHelper.h"
#include <QGraphicsItem>
//#include <QGraphicsItem>
#include "ParameterizedItem.h"
SamplePropertyEditor::SamplePropertyEditor(SampleDesignerInterface *sample_designer, QWidget *parent)
// : SamplePropertyEditorInterface(parent)
SamplePropertyEditor::SamplePropertyEditor(QItemSelectionModel *selection_model,
QWidget *parent)
: QWidget(parent)
, m_sample_designer(sample_designer)
// , m_variantManager(0)
// , m_propertyEditor(0)
, m_object(0)
, m_selection_model(selection_model)
, m_item(0)
{
setWindowTitle(QLatin1String("Property Editor"));
setObjectName(QLatin1String("PropertyEditor"));
// m_variantManager = new QtVariantPropertyManager(this);
// connect(m_variantManager, SIGNAL(valueChanged(QtProperty*, QVariant)), SLOT(valueChanged(QtProperty*,QVariant)));
// QtVariantEditorFactory *variantFactory = new QtVariantEditorFactory(this);
// m_propertyEditor = new QtTreePropertyBrowser(this);
// m_propertyEditor->setFactoryForManager(m_variantManager, variantFactory);
// QVBoxLayout *layout = new QVBoxLayout;
// layout->addWidget(m_propertyEditor);
// setLayout(layout);
// QtVariantProperty *property = m_variantManager->addProperty(QVariant::Double, tr("pos X"));
// property->setValue(3.3);
// QtBrowserItem *item = m_propertyEditor->addProperty(property);
QtTreePropertyBrowser *browser = new QtTreePropertyBrowser(this);
browser->setRootIsDecorated(false);
m_browser = browser;
......@@ -78,61 +60,24 @@ SamplePropertyEditor::SamplePropertyEditor(SampleDesignerInterface *sample_desig
layout->setMargin(0);
layout->addWidget(m_browser);
//m_readOnlyManager = new QtVariantPropertyManager(this);
//m_readOnlyManager = new VariantManager(this);
m_readOnlyManager = new PropertyVariantManager(this);
m_read_only_manager = new PropertyVariantManager(this);
//m_manager = new QtVariantPropertyManager(this);
//m_manager = new VariantManager(this);
m_manager = new PropertyVariantManager(this);
// QtVariantEditorFactory *factory = new QtVariantEditorFactory(this);
// m_browser->setFactoryForManager(m_manager, factory);
QtVariantEditorFactory *factory = new PropertyVariantFactory();
m_browser->setFactoryForManager(m_manager, factory);
connect(m_manager, SIGNAL(valueChanged(QtProperty *, const QVariant &)),
this, SLOT(slotValueChanged(QtProperty *, const QVariant &)));
if(m_sample_designer)
connect(m_sample_designer->getScene(), SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
if(m_selection_model)
connect(m_selection_model,
SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
this,
SLOT(selectionChanged(QItemSelection,QItemSelection)) );
}
//int SamplePropertyEditor::enumToInt(const QMetaEnum &metaEnum, int enumValue) const
//{
// QMap<int, int> valueMap; // dont show multiple enum values which have the same values
// int pos = 0;
// for (int i = 0; i < metaEnum.keyCount(); i++) {
// int value = metaEnum.value(i);
// if (!valueMap.contains(value)) {
// if (value == enumValue)
// return pos;
// valueMap[value] = pos++;
// }
// }
// return -1;
//}
//int SamplePropertyEditor::intToEnum(const QMetaEnum &metaEnum, int intValue) const
//{
// QMap<int, bool> valueMap; // dont show multiple enum values which have the same values
// QList<int> values;
// for (int i = 0; i < metaEnum.keyCount(); i++) {
// int value = metaEnum.value(i);
// if (!valueMap.contains(value)) {
// valueMap[value] = true;
// values.append(value);
// }
// }
// if (intValue >= values.count())
// return -1;
// return values.at(intValue);
//}
bool SamplePropertyEditor::isSubValue(int value, int subValue) const
{
if (value == subValue)
......@@ -149,288 +94,105 @@ bool SamplePropertyEditor::isSubValue(int value, int subValue) const
return true;
}
//bool SamplePropertyEditor::isPowerOf2(int value) const
//{
// while (value) {
// if (value & 1) {
// return value == 1;
// }
// value = value >> 1;
// }
// return false;
//}
//int SamplePropertyEditor::flagToInt(const QMetaEnum &metaEnum, int flagValue) const
//{
// if (!flagValue)
// return 0;
// int intValue = 0;
// QMap<int, int> valueMap; // dont show multiple enum values which have the same values
// int pos = 0;
// for (int i = 0; i < metaEnum.keyCount(); i++) {
// int value = metaEnum.value(i);
// if (!valueMap.contains(value) && isPowerOf2(value)) {
// if (isSubValue(flagValue, value))
// intValue |= (1 << pos);
// valueMap[value] = pos++;
// }
// }
// return intValue;
//}
//int SamplePropertyEditor::intToFlag(const QMetaEnum &metaEnum, int intValue) const
//{
// QMap<int, bool> valueMap; // dont show multiple enum values which have the same values
// QList<int> values;
// for (int i = 0; i < metaEnum.keyCount(); i++) {
// int value = metaEnum.value(i);
// if (!valueMap.contains(value) && isPowerOf2(value)) {
// valueMap[value] = true;
// values.append(value);
// }
// }
// int flagValue = 0;
// int temp = intValue;
// int i = 0;
// while (temp) {
// if (i >= values.count())
// return -1;
// if (temp & 1)
// flagValue |= values.at(i);
// i++;
// temp = temp >> 1;
// }
// return flagValue;
//}
void SamplePropertyEditor::updateClassProperties(const QMetaObject *metaObject, bool recursive)
{
if (!metaObject)
return;
std::cout << "AAA SamplePropertyEditor::updateClassProperties " << recursive << std::endl;
if (recursive)
updateClassProperties(metaObject->superClass(), recursive);
QtProperty *classProperty = m_classToProperty.value(metaObject);
if (!classProperty)
return;
for (int idx = metaObject->propertyOffset(); idx < metaObject->propertyCount(); idx++) {
QMetaProperty metaProperty = metaObject->property(idx);
if (metaProperty.isReadable()) {
if (m_classToIndexToProperty.contains(metaObject) && m_classToIndexToProperty[metaObject].contains(idx)) {
QtVariantProperty *subProperty = m_classToIndexToProperty[metaObject][idx];
// if (metaProperty.isEnumType()) {
// if (metaProperty.isFlagType())
// subProperty->setValue(flagToInt(metaProperty.enumerator(), metaProperty.read(m_object).toInt()));
// else
// subProperty->setValue(enumToInt(metaProperty.enumerator(), metaProperty.read(m_object).toInt()));
// } else {
subProperty->setValue(metaProperty.read(m_object));
// }
}
}
}
}
// show property of currently selected object (triggered by the graphics scene)
// if more than one object is selected, show only last selected
void SamplePropertyEditor::selectionChanged()
void SamplePropertyEditor::selectionChanged(const QItemSelection & selected,
const QItemSelection & deselected)
{
QList<QGraphicsItem *> items = m_sample_designer->getScene()->selectedItems();
QObject *object(0);
if( items.size() ) object = items.back()->toGraphicsObject();
setObject(object);
(void)deselected;
QModelIndexList indices = selected.indexes();
ParameterizedItem *item = static_cast<ParameterizedItem *>(
indices.back().internalPointer());
setItem(item);
}
// assigns objects to the property editor
void SamplePropertyEditor::setObject(QObject *object)
void SamplePropertyEditor::addItemProperties(const ParameterizedItem *item)
{
std::cout << "SamplePropertyEditor::setObject() -> 2.1" << std::endl;
if (m_object == object) return;
std::cout << "SamplePropertyEditor::setObject() -> 2.2" << std::endl;
if (m_object) {
// saveExpandedState();
QListIterator<QtProperty *> it(m_topLevelProperties);
while (it.hasNext()) {
m_browser->removeProperty(it.next());
}
m_topLevelProperties.clear();
}
std::cout << "SamplePropertyEditor::setObject() -> 2.3" << std::endl;
m_object = object;
if (!m_object) return;
std::cout << "SamplePropertyEditor::setObject() -> 2.4" << std::endl;
addClassProperties(m_object->metaObject());
std::cout << "SamplePropertyEditor::setObject() -> 2.5" << std::endl;
// restoreExpandedState();
}
void SamplePropertyEditor::addClassProperties(const QMetaObject *metaObject)
{
std::cout << "SamplePropertyEditor::addClassProperties() -> 3.1" << std::endl;
if (!metaObject) return;
// complex_t aaa(1,2);
// QVariant var;
// var.setValue(aaa); // copy s into the variant
// std::cout << "BBB " << var.type() << std::endl;
// complex_t aaa2 = var.value<complex_t>();
// std::cout << "AAA XXX " << aaa2 << std::endl;
//addClassProperties(metaObject->superClass());
QtProperty *classProperty = m_classToProperty.value(metaObject);
if (!classProperty) {
std::cout << "SamplePropertyEditor::addClassProperties() -> 3.2" << std::endl;
QString className = QLatin1String(metaObject->className());
classProperty = m_manager->addProperty(QtVariantPropertyManager::groupTypeId(), className);
m_classToProperty[metaObject] = classProperty;
m_propertyToClass[classProperty] = metaObject;
for (int idx = metaObject->propertyOffset(); idx < metaObject->propertyCount(); idx++) {
QMetaProperty metaProperty = metaObject->property(idx);
int type = metaProperty.userType();
std::cout << "XXX metaProperty.name():" << metaProperty.name()
<< " metaProperty.type():" << metaProperty.type()
<< " metaProperty.typeName():" << metaProperty.typeName()
<< " metaProperty.userType():" << metaProperty.userType()
<< std::endl;
QtProperty *item_property = m_item_to_property.value(item);
if (!item_property) {
QString item_type = item->modelType();
item_property = m_manager->addProperty(
QtVariantPropertyManager::groupTypeId(), item_type);
m_item_to_property[item] = item_property;
m_property_to_item[item_property] = item;
QList<QByteArray> property_names = item->dynamicPropertyNames();
for (int i = 0; i < property_names.length(); ++i) {
QString prop_name = QString(property_names[i]);
QVariant prop_value = item->property(prop_name.toUtf8().data());
QVariant::Type type = prop_value.type();
QtVariantProperty *subProperty = 0;
if (!metaProperty.isReadable()) {
subProperty = m_readOnlyManager->addProperty(QVariant::String, QLatin1String(metaProperty.name()));
subProperty->setValue(QLatin1String("< Non Readable >"));
// } else if (metaProperty.isEnumType()) {
// if (metaProperty.isFlagType()) {
// subProperty = m_manager->addProperty(QtVariantPropertyManager::flagTypeId(), QLatin1String(metaProperty.name()));
// QMetaEnum metaEnum = metaProperty.enumerator();
// QMap<int, bool> valueMap;
// QStringList flagNames;
// for (int i = 0; i < metaEnum.keyCount(); i++) {
// int value = metaEnum.value(i);
// if (!valueMap.contains(value) && isPowerOf2(value)) {
// valueMap[value] = true;
// flagNames.append(QLatin1String(metaEnum.key(i)));
// }
// subProperty->setAttribute(QLatin1String("flagNames"), flagNames);
// subProperty->setValue(flagToInt(metaEnum, metaProperty.read(m_object).toInt()));
// }
// } else {
// subProperty = m_manager->addProperty(QtVariantPropertyManager::enumTypeId(), QLatin1String(metaProperty.name()));
// QMetaEnum metaEnum = metaProperty.enumerator();
// QMap<int, bool> valueMap; // dont show multiple enum values which have the same values
// QStringList enumNames;
// for (int i = 0; i < metaEnum.keyCount(); i++) {
// int value = metaEnum.value(i);
// if (!valueMap.contains(value)) {
// valueMap[value] = true;
// enumNames.append(QLatin1String(metaEnum.key(i)));
// }
// }
// subProperty->setAttribute(QLatin1String("enumNames"), enumNames);
// subProperty->setValue(enumToInt(metaEnum, metaProperty.read(m_object).toInt()));
// }
// } else if(metaProperty.typeName() == QString("complex_t")) {
// subProperty = m_manager->addProperty(1024, QLatin1String(" PointF Property"));
// subProperty->setValue(QPointF(1.2345, -1.23451));
// subProperty->setAttribute(QLatin1String("decimals"), 3);
//topItem->addSubProperty(item);
} else if (m_manager->isPropertyTypeSupported(type)) {
std::cout << "XXXXX adding property " << type << std::endl;
if (!metaProperty.isWritable())
subProperty = m_readOnlyManager->addProperty(type, QLatin1String(metaProperty.name()) + QLatin1String(" (Non Writable)"));
if (!metaProperty.isDesignable())
subProperty = m_readOnlyManager->addProperty(type, QLatin1String(metaProperty.name()) + QLatin1String(" (Non Designable)"));
else
subProperty = m_manager->addProperty(type, QLatin1String(metaProperty.name()));
subProperty->setValue(metaProperty.read(m_object));
if (m_manager->isPropertyTypeSupported(type)) {
subProperty = m_manager->addProperty(type, prop_name);
subProperty->setValue(prop_value);
} else {
subProperty = m_readOnlyManager->addProperty(QVariant::String, QLatin1String(metaProperty.name()));
subProperty = m_read_only_manager->addProperty(QVariant::String,
prop_name);
subProperty->setValue(QLatin1String("< Unknown Type >"));
subProperty->setEnabled(false);
}
classProperty->addSubProperty(subProperty);
m_propertyToIndex[subProperty] = idx;
m_classToIndexToProperty[metaObject][idx] = subProperty;
item_property->addSubProperty(subProperty);
m_property_to_index[subProperty] = i;
m_item_to_index_to_property[item][i] = subProperty;
}
} else {
updateClassProperties(metaObject, false);
updateItemProperties(item);
}
m_topLevelProperties.append(classProperty);
m_browser->addProperty(classProperty);
m_top_level_properties.append(item_property);
m_browser->addProperty(item_property);
}
void SamplePropertyEditor::updateItemProperties(const ParameterizedItem *item)
{
if (!item)
return;
//void SamplePropertyEditor::saveExpandedState()
//{
//}
//void SamplePropertyEditor::restoreExpandedState()
//{
//}
QtProperty *item_property = m_item_to_property.value(item);
if (!item_property)
return;
QList<QByteArray> prop_list = item->dynamicPropertyNames();
for (int i=0; i<prop_list.length(); ++i) {
const char *name = prop_list[i].constData();
QVariant variant = item->property(name);
QtVariantProperty *subProperty =
m_item_to_index_to_property[item][i];
subProperty->setValue(variant);
}
}
void SamplePropertyEditor::slotValueChanged(QtProperty *property, const QVariant &value)
void SamplePropertyEditor::slotValueChanged(QtProperty *property,
const QVariant &value)
{
std::cout << "SamplePropertyEditor::slotValueChanged() -> 1.1" << std::endl;
if (!m_propertyToIndex.contains(property))
if (!m_property_to_index.contains(property))
return;
std::cout << "SamplePropertyEditor::slotValueChanged() -> 1.2" << std::endl;
int idx = m_propertyToIndex.value(property);
const QMetaObject *metaObject = m_object->metaObject();
QMetaProperty metaProperty = metaObject->property(idx);
// if (metaProperty.isEnumType()) {
// if (metaProperty.isFlagType())
// metaProperty.write(m_object, intToFlag(metaProperty.enumerator(), value.toInt()));
// else
// metaProperty.write(m_object, intToEnum(metaProperty.enumerator(), value.toInt()));
// } else {
metaProperty.write(m_object, value);
// }
std::cout << "SamplePropertyEditor::slotValueChanged() -> 1.3" << std::endl;
// updateClassProperties(metaObject, false);
}
int index = m_property_to_index.value(property);
QList<QByteArray> prop_list = m_item->dynamicPropertyNames();
if (index > prop_list.length()) {
return;
}
m_item->setProperty(prop_list[index].constData(), value);
}
//void SamplePropertyEditor::valueChanged(QtProperty *property, const QVariant &value)
//{
// std::cout << "SamplePropertyEditor::valueChange() " << std::endl;
// Q_UNUSED(property);
// Q_UNUSED(value);
// std::cout << "SamplePropertyEditor::valueChange() " << std::endl;
//}
// assigns item to the property editor
void SamplePropertyEditor::setItem(ParameterizedItem *item)
{
if (m_item == item) return;
if (m_item) {
QListIterator<QtProperty *> it(m_top_level_properties);
while (it.hasNext()) {
m_browser->removeProperty(it.next());
}
m_top_level_properties.clear();
}
//void SamplePropertyEditor::attributeChanged(QtProperty *property,
// const QString &attribute, const QVariant &val)
//{
// std::cout << "SamplePropertyEditor::attributeChange() " << std::endl;
m_item = item;
//}
if (!m_item) return;
addItemProperties(m_item);
}
......@@ -6,12 +6,15 @@
#include <QMap>
class SampleDesignerInterface;
class QItemSelectionModel;
class QItemSelection;
class QtVariantPropertyManager;
class QtTreePropertyBrowser;
class QtProperty;
class QtVariantProperty;
class QVariant;
class QtAbstractPropertyBrowser;
class ParameterizedItem;
//! property editor to modify property of the objectcurrently selected on the graphics scene
......@@ -21,50 +24,46 @@ class SamplePropertyEditor : public QWidget
Q_OBJECT
public:
SamplePropertyEditor(SampleDesignerInterface *sample_designer, QWidget *parent = 0);
SamplePropertyEditor(QItemSelectionModel *selection_model,
QWidget *parent = 0);
virtual ~SamplePropertyEditor(){}
QObject *getObject() const;
public slots:
//! show property of currently selected object (triggered by graphics scene)
void selectionChanged();
void selectionChanged(const QItemSelection & selected,
const QItemSelection & deselected);
private slots:
void slotValueChanged(QtProperty *property, const QVariant &value);
private:
//! assigns objects to the property editor
void setObject(QObject *object);
//! assigns item to the property editor
void setItem(ParameterizedItem *item);
SampleDesignerInterface *m_sample_designer;
ParameterizedItem *m_item; //! object to modify
QObject *m_object; //! object to modify
QItemSelectionModel *m_selection_model;
QMap<const QMetaObject *, QtProperty *> m_classToProperty;
QMap<QtProperty *, const QMetaObject *> m_propertyToClass;
QMap<QtProperty *, int> m_propertyToIndex;
QMap<const QMetaObject *, QMap<int, QtVariantProperty *> > m_classToIndexToProperty;
QMap<const ParameterizedItem *, QtProperty *> m_item_to_property;
QMap<QtProperty *, const ParameterizedItem *> m_property_to_item;
QMap<QtProperty *, bool> m_propertyToExpanded;
QMap<QtProperty *, int> m_property_to_index;
QMap<const ParameterizedItem *, QMap<int, QtVariantProperty *> >
m_item_to_index_to_property;
QList<QtProperty *> m_topLevelProperties;
QMap<QtProperty *, bool> m_property_to_expanded;
QList<QtProperty *> m_top_level_properties;
QtAbstractPropertyBrowser *m_browser;
QtVariantPropertyManager *m_manager;
QtVariantPropertyManager *m_readOnlyManager;
void addClassProperties(const QMetaObject *metaObject);
void updateClassProperties(const QMetaObject *metaObject, bool recursive);
// void saveExpandedState();
// void restoreExpandedState();
// int enumToInt(const QMetaEnum &metaEnum, int enumValue) const;
// int intToEnum(const QMetaEnum &metaEnum, int intValue) const;
// int flagToInt(const QMetaEnum &metaEnum, int flagValue) const;
// int intToFlag(const QMetaEnum &metaEnum, int intValue) const;
bool isSubValue(int value, int subValue) const;
// bool isPowerOf2(int value) const;
QtVariantPropertyManager *m_read_only_manager;
void addItemProperties(const ParameterizedItem *item);
void updateItemProperties(const ParameterizedItem *item);
bool isSubValue(int value, int subValue) const;
};
......
......@@ -94,7 +94,8 @@ void SampleView::initSubWindows()
m_subWindows[SampleTreeView] = m_tree_view;
m_subWindows[PropertyEditorSubWindow] =
SampleViewComponents::createPropertyEditor(m_sampleDesigner, this);
SampleViewComponents::createPropertyEditor(
m_tree_view->selectionModel(), this);
SampleInfoStreamInterface *ae =
SampleViewComponents::createInfoStream(this);
......
......@@ -24,22 +24,25 @@
// return result;
//}
SampleWidgetBox *SampleViewComponents::createWidgetBox(SampleDesignerInterface *core, QWidget *parent)
SampleWidgetBox *SampleViewComponents::createWidgetBox(
SampleDesignerInterface *core, QWidget *parent)
{
return new SampleWidgetBox(core, parent);
}
//SamplePropertyEditorInterface *SampleViewComponents::createPropertyEditor(QWidget *parent)
SamplePropertyEditor *SampleViewComponents::createPropertyEditor(SampleDesignerInterface *core, QWidget *parent)
SamplePropertyEditor *SampleViewComponents::createPropertyEditor(
QItemSelectionModel *selection_model, QWidget *parent)
{
//SamplePropertyEditorInterface *result = new SamplePropertyEditorInterface(parent);
// SamplePropertyEditor *result = new SamplePropertyEditor(core, parent);
// result->setWindowTitle(QLatin1String("Property Editor"));
// result->setObjectName(QLatin1String("PropertyEditor"));
return new SamplePropertyEditor(core, parent);
return new SamplePropertyEditor(selection_model, parent);
}
QTreeView *SampleViewComponents::createTreeView(SessionModel *session_model, QWidget *parent)
QTreeView *SampleViewComponents::createTreeView(
SessionModel *session_model, QWidget *parent)
{
QTreeView *tree_view = new QTreeView(parent);
tree_view->setModel(session_model);
......@@ -51,7 +54,8 @@ QTreeView *SampleViewComponents::createTreeView(SessionModel *session_model, QWi
return tree_view;
}
SampleInfoStreamInterface *SampleViewComponents::createInfoStream(QWidget *parent)
SampleInfoStreamInterface *SampleViewComponents::createInfoStream(
QWidget *parent)
{
return new SampleInfoStreamInterface(parent);
}
......
......@@ -41,9 +41,12 @@ public:
class SampleViewComponents
{
public:
static SampleWidgetBox *createWidgetBox(SampleDesignerInterface *core, QWidget *parent);
static SamplePropertyEditor *createPropertyEditor(SampleDesignerInterface *core,QWidget *parent);
static QTreeView *createTreeView(SessionModel *session_model, QWidget *parent);
static SampleWidgetBox *createWidgetBox(
SampleDesignerInterface *core, QWidget *parent);
static SamplePropertyEditor *createPropertyEditor(
QItemSelectionModel *selection_model, QWidget *parent);
static QTreeView *createTreeView(
SessionModel *session_model, QWidget *parent);
static SampleInfoStreamInterface *createInfoStream(QWidget *parent);
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment