19 #include <QtCore/QSet>
20 #include <QtGui/QLineEdit>
21 #include <QtGui/QComboBox>
23 #include <tulip/ForEach.h>
24 #include <tulip/VectorEditionWidget.h>
25 #include <tulip/GraphPropertiesModel.h>
31 QWidget* LineEditEditorCreator<T>::createWidget(QWidget *parent)
const {
32 return new QLineEdit(parent);
36 void LineEditEditorCreator<T>::setEditorData(QWidget* editor,
const QVariant &data,
bool,
tlp::Graph*) {
37 typename T::RealType val = data.value<
typename T::RealType>();
38 static_cast<QLineEdit*
>(editor)->setText(QString::fromUtf8(T::toString(val).c_str()));
42 QVariant LineEditEditorCreator<T>::editorData(QWidget* editor,
tlp::Graph*) {
43 std::string strVal = std::string(static_cast<QLineEdit*>(editor)->text().toUtf8().data());
45 typename T::RealType val;
47 if (T::fromString(val,strVal))
48 result.setValue<
typename T::RealType>(val);
53 template<
typename PROPTYPE>
54 QWidget* PropertyEditorCreator<PROPTYPE>::createWidget(QWidget* parent)
const {
55 return new QComboBox(parent);
58 template<
typename PROPTYPE>
59 void PropertyEditorCreator<PROPTYPE>::setEditorData(QWidget* w,
const QVariant& val,
bool isMandatory,
tlp::Graph* g) {
65 PROPTYPE* prop = val.value<PROPTYPE*>();
66 QComboBox* combo =
static_cast<QComboBox*
>(w);
67 GraphPropertiesModel<PROPTYPE>* model = NULL;
70 model =
new GraphPropertiesModel<PROPTYPE>(g,
false,combo);
72 model =
new GraphPropertiesModel<PROPTYPE>(QObject::trUtf8(
"Select a property"),g,
false,combo);
74 combo->setModel(model);
75 combo->setCurrentIndex(model->rowOf(prop));
78 template<
typename PROPTYPE>
79 QVariant PropertyEditorCreator<PROPTYPE>::editorData(QWidget* w,
tlp::Graph* g) {
83 QComboBox* combo =
static_cast<QComboBox*
>(w);
84 GraphPropertiesModel<PROPTYPE>* model =
static_cast<GraphPropertiesModel<PROPTYPE> *
>(combo->model());
85 QVariant var = model->data(model->index(combo->currentIndex(),0),TulipModel::PropertyRole);
87 PROPTYPE* prop = (PROPTYPE*)(pi);
88 return QVariant::fromValue<PROPTYPE*>(prop);
91 template<
typename PROPTYPE>
92 QString PropertyEditorCreator<PROPTYPE>::displayText(
const QVariant& v)
const {
93 PROPTYPE *prop = v.value<PROPTYPE*>();
96 return QObject::trUtf8(
"Select a property");
98 return QString::fromUtf8(prop->getName().c_str());
101 template<
typename ElementType>
102 QWidget* VectorEditorCreator<ElementType>::createWidget(QWidget*)
const {
103 VectorEditionWidget* w =
new VectorEditionWidget(NULL);
104 w->setWindowFlags(Qt::Dialog);
105 w->setWindowModality(Qt::ApplicationModal);
110 template<
typename ElementType>
111 void VectorEditorCreator<ElementType>::setEditorData(QWidget* editor,
const QVariant& v,
bool,
tlp::Graph*) {
112 QVector<QVariant> editorData;
113 std::vector<ElementType> vect = v.value<std::vector<ElementType> >();
115 for (
size_t i=0; i < vect.size(); ++i) {
116 editorData.push_back(QVariant::fromValue<ElementType>(vect[i]));
119 static_cast<VectorEditionWidget*
>(editor)->setVector(editorData,qMetaTypeId<ElementType>());
121 static_cast<VectorEditionWidget*
>(editor)->move(QCursor::pos());
124 template<
typename ElementType>
125 QVariant VectorEditorCreator<ElementType>::editorData(QWidget* editor,
tlp::Graph*) {
126 std::vector<ElementType> result;
127 QVector<QVariant> editorData =
static_cast<VectorEditionWidget*
>(editor)->vector();
128 foreach(QVariant v, editorData)
129 result.push_back(v.value<ElementType>());
130 return QVariant::fromValue<std::vector<ElementType> >(result);
133 template<
typename ElementType>
134 QString VectorEditorCreator<ElementType>::displayText(
const QVariant &data)
const {
135 std::vector<ElementType> v = data.value<std::vector<ElementType> >();
136 return QString::number(v.size()) + QObject::trUtf8(
" elements");