Skip to content
Snippets Groups Projects
Commit 3d972e47 authored by Pospelov, Gennady's avatar Pospelov, Gennady
Browse files

One the way to provide editing of instrument properties.

parent 77035bc2
No related branches found
No related tags found
No related merge requests found
#include "BeamItem.h" #include "BeamItem.h"
const QString BeamItem::P_INTENSITY = "Intensity [1/s]";
const QString BeamItem::P_WAVELENGTH = "Wavelength [nm]";
const QString BeamItem::P_INCLINATION_ANGLE = "Inclination Angle";
const QString BeamItem::P_AZIMUTHAL_ANGLE = "Azimuthal Angle";
BeamItem::BeamItem(ParameterizedItem *parent) BeamItem::BeamItem(ParameterizedItem *parent)
: ParameterizedItem(QString("Beam"), parent) : ParameterizedItem(QString("Beam"), parent)
{ {
setItemName("Beam"); setItemName("Beam");
registerProperty(P_INTENSITY, 1000.0);
registerProperty(P_WAVELENGTH, 0.1);
registerProperty(P_INCLINATION_ANGLE, 0.2);
registerProperty(P_AZIMUTHAL_ANGLE, 0.0);
} }
...@@ -8,6 +8,7 @@ class BeamItem : public ParameterizedItem ...@@ -8,6 +8,7 @@ class BeamItem : public ParameterizedItem
{ {
Q_OBJECT Q_OBJECT
public: public:
static const QString P_INTENSITY, P_WAVELENGTH, P_INCLINATION_ANGLE, P_AZIMUTHAL_ANGLE;
explicit BeamItem(ParameterizedItem *parent=0); explicit BeamItem(ParameterizedItem *parent=0);
~BeamItem(){} ~BeamItem(){}
}; };
......
#include "InstrumentEditorWidget.h" #include "InstrumentEditorWidget.h"
#include "ParameterizedItem.h" #include "ParameterizedItem.h"
#include "BeamItem.h"
#include <QBoxLayout> #include <QBoxLayout>
#include <QGroupBox>
#include "qtvariantproperty.h"
#include "qttreepropertybrowser.h"
#include "qtbuttonpropertybrowser.h"
#include "qtgroupboxpropertybrowser.h"
#include <QDebug>
InstrumentEditorWidget::InstrumentEditorWidget(QWidget *parent) InstrumentEditorWidget::InstrumentEditorWidget(QWidget *parent)
: QWidget(parent) : QWidget(parent)
, m_label(new QLabel) , m_label(new QLabel)
, m_variantManager(new QtVariantPropertyManager(this))
, m_propertyBrowser(0)
{ {
setMinimumSize(400, 400); setMinimumSize(400, 400);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
QVBoxLayout *verticalLayout = new QVBoxLayout;
verticalLayout->addWidget(m_label);
setLayout(verticalLayout); //m_propertyBrowser = new QtTreePropertyBrowser(this);
//m_propertyBrowser = new QtButtonPropertyBrowser(this);
m_propertyBrowser = new QtGroupBoxPropertyBrowser();
m_variantManager = new QtVariantPropertyManager(this);
// connect(m_variantManager, SIGNAL(valueChanged(QtProperty *, const QVariant &)),
// this, SLOT(valueChanged(QtProperty *, const QVariant &)));
QtVariantEditorFactory *variantFactory = new QtVariantEditorFactory(this);
m_propertyBrowser->setFactoryForManager(m_variantManager, variantFactory);
QGroupBox *beamParamsGroup = new QGroupBox(tr("Beam Parameters"));
QVBoxLayout *beamParamsLayout = new QVBoxLayout;
beamParamsLayout->addWidget(m_propertyBrowser);
beamParamsGroup->setLayout(beamParamsLayout);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(beamParamsGroup);
mainLayout->addStretch();
setLayout(mainLayout);
}
void InstrumentEditorWidget::updateExpandState()
{
// QList<QtBrowserItem *> list = m_propertyBrowser->topLevelItems();
// QListIterator<QtBrowserItem *> it(list);
// while (it.hasNext()) {
// QtBrowserItem *item = it.next();
// QtProperty *prop = item->property();
// idToExpanded[propertyToId[prop]] = m_propertyBrowser->isExpanded(item);
// }
} }
void InstrumentEditorWidget::setInstrumentItem(ParameterizedItem *instrument) void InstrumentEditorWidget::setInstrumentItem(ParameterizedItem *instrument)
{ {
m_label->setText(instrument->itemName()); // m_label->setText(instrument->itemName());
updateExpandState();
// QMap<QtProperty *, QString>::ConstIterator itProp = propertyToId.constBegin();
// while (itProp != propertyToId.constEnd()) {
// delete itProp.key();
// itProp++;
// }
// propertyToId.clear();
// idToProperty.clear();
// QtVariantProperty *property;
// property = m_variantManager->addProperty(QVariant::String, tr("Name"));
// property->setValue(instrument->itemName());
// addProperty(property, ParameterizedItem::P_NAME);
// BeamItem *beamItem = instrument->getS
ParameterizedItem *beamItem;
foreach(ParameterizedItem *item, instrument->childItems()) {
if(item->modelType() == QStringLiteral("Beam")) beamItem = item;
}
Q_ASSERT(beamItem);
QString item_type = beamItem->modelType();
QtProperty *item_property = m_variantManager->addProperty(
QtVariantPropertyManager::groupTypeId(), item_type);
addSubProperties(item_property, beamItem);
m_propertyBrowser->addProperty(item_property);
}
void InstrumentEditorWidget::addProperty(QtVariantProperty *property, const QString &id)
{
// propertyToId[property] = id;
// idToProperty[id] = property;
// QtBrowserItem *item = m_propertyBrowser->addProperty(property);
//// if (idToExpanded.contains(id))
//// m_propertyBrowser->setExpanded(item, idToExpanded[id]);
}
void InstrumentEditorWidget::addSubProperties(QtProperty *item_property, ParameterizedItem *item)
{
Q_ASSERT(item_property);
Q_ASSERT(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());
int type = prop_value.type();
if (type == QVariant::UserType) {
type = prop_value.userType();
}
QtVariantProperty *subProperty = 0;
if (m_variantManager->isPropertyTypeSupported(type)) {
subProperty = m_variantManager->addProperty(type, prop_name);
subProperty->setValue(prop_value);
if(type == QVariant::Double) {
subProperty->setAttribute(QLatin1String("singleStep"), 0.1);
subProperty->setAttribute(QLatin1String("decimals"), 5);
}
if (item->getSubItems().contains(prop_name)) {
subProperty->setAttribute(QLatin1String("readOnly"), true);
ParameterizedItem *subitem = item->getSubItems()[prop_name];
if (subitem) {
addSubProperties(subProperty, subitem);
}
}
}
// else {
// subProperty = m_readOnlyManager->addProperty(QVariant::String,
// prop_name);
// subProperty->setValue(QLatin1String("< Unknown Type >"));
// subProperty->setEnabled(false);
// }
item_property->addSubProperty(subProperty);
SubItem subitem(item,prop_name);
m_property_to_subitem[subProperty] = subitem;
m_material_to_property[item][prop_name] = subProperty;
}
} }
...@@ -4,8 +4,11 @@ ...@@ -4,8 +4,11 @@
#include <QWidget> #include <QWidget>
#include <QLabel> #include <QLabel>
#include <QMap>
class ParameterizedItem; class ParameterizedItem;
class QtProperty;
class QtVariantProperty;
class InstrumentEditorWidget : public QWidget class InstrumentEditorWidget : public QWidget
{ {
...@@ -17,8 +20,37 @@ public: ...@@ -17,8 +20,37 @@ public:
void setInstrumentItem(ParameterizedItem *instrument); void setInstrumentItem(ParameterizedItem *instrument);
struct SubItem {
SubItem(ParameterizedItem *owner=0, QString name = QString())
: m_owner(owner), m_name(name) {}
ParameterizedItem *m_owner;
QString m_name;
friend bool operator <(const SubItem& left, const SubItem& right)
{
if(left.m_owner == right.m_owner)
return left.m_name < right.m_name;
return left.m_owner < right.m_owner;
}
};
private: private:
void addProperty(QtVariantProperty *property, const QString &id);
void updateExpandState();
void addSubProperties(QtProperty *item_property, ParameterizedItem *item);
QLabel *m_label; QLabel *m_label;
class QtVariantPropertyManager *m_variantManager;
class QtAbstractPropertyBrowser *m_propertyBrowser;
// QMap<QtProperty *, QString> propertyToId;
// QMap<QString, QtVariantProperty *> idToProperty;
// QMap<QString, bool> idToExpanded;
QMap<QtProperty *, SubItem> m_property_to_subitem;
QMap<ParameterizedItem *, QMap<QString, QtVariantProperty *> > m_material_to_property;
}; };
#endif #endif
...@@ -68,12 +68,13 @@ void InstrumentSelectorWidget::setInstrumentModel(SessionModel *model) ...@@ -68,12 +68,13 @@ void InstrumentSelectorWidget::setInstrumentModel(SessionModel *model)
this, this,
SIGNAL( selectionChanged(const QItemSelection&, const QItemSelection&) ) SIGNAL( selectionChanged(const QItemSelection&, const QItemSelection&) )
); );
} }
} }
//QItemSelectionModel *InstrumentSelectorWidget::getSelectionModel() QItemSelectionModel *InstrumentSelectorWidget::getSelectionModel()
//{ {
// return m_listView->selectionModel(); return m_listView->selectionModel();
//} }
...@@ -21,7 +21,7 @@ public: ...@@ -21,7 +21,7 @@ public:
void setInstrumentModel(SessionModel *model); void setInstrumentModel(SessionModel *model);
// QItemSelectionModel *getSelectionModel(); QItemSelectionModel *getSelectionModel();
signals: signals:
void selectionChanged(const QItemSelection&, const QItemSelection&); void selectionChanged(const QItemSelection&, const QItemSelection&);
......
...@@ -83,3 +83,14 @@ void GroupPropertyEdit::textChanged(QString text) ...@@ -83,3 +83,14 @@ void GroupPropertyEdit::textChanged(QString text)
emit groupPropertyChanged(m_groupProperty); emit groupPropertyChanged(m_groupProperty);
} }
} }
QSize GroupPropertyEdit::sizeHint() const
{
return m_box->sizeHint();
}
QSize GroupPropertyEdit::minimumSizeHint() const
{
return m_box->minimumSizeHint();
}
...@@ -40,6 +40,10 @@ public: ...@@ -40,6 +40,10 @@ public:
GroupProperty getGroupProperty() const { GroupProperty getGroupProperty() const {
return m_groupProperty; return m_groupProperty;
} }
QSize sizeHint() const;
QSize minimumSizeHint() const;
signals: signals:
void groupPropertyChanged(const GroupProperty &material); void groupPropertyChanged(const GroupProperty &material);
private slots: private slots:
......
...@@ -49,6 +49,9 @@ InstrumentView2::InstrumentView2(SessionModel *model, QWidget *parent) ...@@ -49,6 +49,9 @@ InstrumentView2::InstrumentView2(SessionModel *model, QWidget *parent)
); );
QModelIndex itemIndex = m_instrumentModel->index(0,0,QModelIndex());
m_instrumentSelector->getSelectionModel()->select(itemIndex, QItemSelectionModel::Select);
} }
......
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