00001 #include "Fields.h"
00002 #include "ObjectGUI.h"
00003
00004 namespace X3DTK {
00005 namespace Qt{
00006
00007
00008 template <typename TypeSField>
00009 void SField<TypeSField>::add(QWidget * parent)
00010 {
00011 TypeSField * ptr = static_cast<TypeSField *>(pointer);
00012 ObjectGUI* objectGUI = dynamic_cast<ObjectGUI* >(parent);
00013 if ( objectGUI &&
00014 objectGUI->page(0) &&
00015 objectGUI->page(0)->layout())
00016 {
00017 QWidget * SF = SFieldGUI(name, ptr, objectGUI->page(0));
00018 QWidget::connect( SF, SIGNAL( changed() ), objectGUI, SLOT(ok()));
00019 objectGUI->page(0)->layout()->add(SF);
00020 }
00021 }
00022
00023
00024 template <typename TypeSField>
00025 void MField<TypeSField>::add(QWidget * parent)
00026 {
00027 std::vector<TypeSField> * ptr = static_cast<std::vector<TypeSField> *>(pointer);
00028
00029
00030
00031
00032 if (!objectGUI)
00033 objectGUI = dynamic_cast< ObjectGUI* >(parent);
00034
00035
00036 if (!MFtab && objectGUI)
00037 {
00038 MFtab = new QWidget(objectGUI);
00039 objectGUI->insertTab( MFtab, name);
00040
00041
00042 MFtabLayout = new QGridLayout( MFtab );
00043 }
00044
00045 if(!MFtab || !objectGUI)
00046 {
00047 std::cerr<<"Warning MField::add(): impossible to add a MField because MFtab or objectGUI are NULL."<<std::endl;
00048 return;
00049 }
00050 else
00051 {
00052 for ( std::list<QWidget *>::iterator i = chidrenMFtabList.begin();
00053 i != chidrenMFtabList.end();
00054 ++i)
00055 {
00056 MFtabLayout->remove((*i));
00057 delete (*i);
00058 }
00059 chidrenMFtabList.clear();
00060 }
00061
00062 QString str;
00063 unsigned int c = 0;
00064 for (; c < ptr->size(); ++c)
00065 {
00066
00067 QWidget * w = SFieldGUI(str.setNum(c), &(*ptr)[c], MFtab);
00068 chidrenMFtabList.push_back(w);
00069 MFtabLayout->addWidget(w,c/nbColumns,c%nbColumns);
00070 w->show();
00071 QWidget::connect( w, SIGNAL( changed() ), objectGUI, SLOT(ok()));
00072
00073
00074 }
00075
00076 if (edit)
00077 {
00078 QPushButton * editButton = new QPushButton(MFtab, "Edit");
00079 MFtabLayout->addWidget(editButton,1+c/nbColumns,0);
00080 editButton->setText("Edit");
00081 new MFEditor(this, editButton, MFtab);
00082 }
00083 }
00084
00086 template <typename TypeSField>
00087 QString MField<TypeSField>::read()
00088 {
00089 std::vector<TypeSField> * ptr = static_cast<std::vector<TypeSField> *>(pointer);
00090 std::ostringstream ost;
00091 for (unsigned int c = 0 ; c< ptr->size(); ++c)
00092 {
00093 ost<<(*ptr)[c];
00094 if (c!=ptr->size()-1)
00095 {
00096 ost<<" ; ";
00097 if (!((c+1)%nbColumns))
00098 ost<<std::endl;
00099 }
00100 }
00101 return QString(ost.str().c_str());
00102 }
00103
00105 template <typename TypeSField>
00106 void MField<TypeSField>::write(QString s)
00107 {
00108 std::vector<TypeSField> * ptr = static_cast<std::vector<TypeSField> *>(pointer);
00109
00110
00111
00112
00113 ptr->clear();
00114 TypeSField SF;
00115 std::istringstream ist(s.data());
00116 std::string r;
00117 ist>>SF;
00118 ptr->push_back(SF);
00119 while (ist>>r)
00120 {
00121 ist>>SF;
00122 ptr->push_back(SF);
00123
00124 }
00125 add(objectGUI);
00126 objectGUI->ok();
00127
00128 }
00129
00130
00157 template class SField<float>;
00158 template class SField<int>;
00159 template class SField<bool>;
00160 template class SField<QString>;
00161 template class SField<animal::Vec2>;
00162 template class SField<animal::Vec3>;
00163 template class SField<animal::Vec4>;
00164 template class SField<X3DTK::SFVec2f>;
00165 template class SField<X3DTK::SFVec3f>;
00166 template class SField<X3DTK::SFRotation>;
00167 template class MField<float>;
00168 template class MField<int>;
00169
00170
00171 template class MField<animal::Vec2>;
00172 template class MField<animal::Vec3>;
00173 template class MField<animal::Vec4>;
00174 template class MField<X3DTK::SFVec2f>;
00175 template class MField<X3DTK::SFVec3f>;
00176 template class MField<X3DTK::SFRotation>;
00177
00178
00179 }
00180 }
00181
00182
00183