2 // Copyright (C) 2009-2013 CEA/DEN, EDF R&D
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
27 #include "utilities.h"
28 #include "HEXABLOCKGUI.hxx"
31 #include "HEXABLOCKGUI_DocumentDelegate.hxx"
34 using namespace HEXABLOCK::GUI;
37 //QWidget* currentEditor = NULL;
39 DocumentDelegate::DocumentDelegate(QDockWidget *dw, QObject *parent)
40 : QItemDelegate(parent),
47 QWidget *DocumentDelegate::createEditor( QWidget *parent,
48 const QStyleOptionViewItem &option,
49 const QModelIndex &index ) const
51 //close current editor if there's one before creating a new one
52 if (_currentEditor != NULL)
54 delete _currentEditor;
55 _currentEditor = NULL;
58 HexaBaseDialog *editor = NULL;
60 if (_dw->widget()) _dw->widget()->close();
61 if ( !_dw->isVisible() ) _dw->setVisible(true);
63 switch ( index.data(HEXA_TREE_ROLE).toInt() ){
64 case VERTEX_TREE : editor = new VertexDialog(_dw, HexaBaseDialog::INFO_MODE); break;
65 case EDGE_TREE : editor = new EdgeDialog(_dw, HexaBaseDialog::INFO_MODE); break;
66 case QUAD_TREE : editor = new QuadDialog(_dw, HexaBaseDialog::INFO_MODE); break;
67 case HEXA_TREE : editor = new HexaDialog(_dw, HexaBaseDialog::INFO_MODE); break;
68 case VECTOR_TREE : editor = new VectorDialog(_dw, HexaBaseDialog::INFO_MODE); break;
70 // case ELEMENTS_DIR_TREE : trouver le type exact (cylinder ou pipe) et creer la boite d'info en fonction.
73 // case CYLINDER_TREE : editor = new CylinderDialog(_dw, HexaBaseDialog::INFO_MODE); break;
74 // case PIPE_TREE : editor = new PipeDialog(_dw, HexaBaseDialog::INFO_MODE); break;
77 case GROUP_TREE : editor = new GroupDialog(_dw, HexaBaseDialog::INFO_MODE/*UPDATE_MODE*/); break;
78 case LAW_TREE : editor = new LawDialog(_dw, HexaBaseDialog::INFO_MODE); break;
79 case PROPAGATION_TREE : editor = new PropagationDialog(_dw, HexaBaseDialog::INFO_MODE); break;
81 if ( editor != NULL ){
82 HEXABLOCKGUI::assocInProgress = false;
84 //show the editor in the dockwidget
85 editor->resetSizeAndShow(_dw);
90 _currentEditor = editor;
94 //Close the current edition dialog
95 void DocumentDelegate::closeDialog()
97 if (_currentEditor!=NULL)
99 _currentEditor->close();
100 emit closeEditor(_currentEditor, NoHint);
101 delete _currentEditor;
102 _currentEditor = NULL;
106 void DocumentDelegate::setEditorData( QWidget *editor,
107 const QModelIndex &index) const
109 HexaBaseDialog* hexaEditor = dynamic_cast<HexaBaseDialog*>( editor );
110 if (hexaEditor == NULL) return;
111 DocumentModel* documentModel = hexaEditor->getDocumentModel();
112 if (documentModel == NULL) return;
114 switch ( index.data(HEXA_TREE_ROLE).toInt() ){
116 HEXA_NS::Vertex *value = documentModel->getHexaPtr<HEXA_NS::Vertex *>(index);
117 VertexDialog *vertexEditor = static_cast<VertexDialog*>(editor);
118 vertexEditor->setValue(value);
122 HEXA_NS::Edge *value = documentModel->getHexaPtr<HEXA_NS::Edge*>(index);
123 EdgeDialog *edgeEditor = static_cast<EdgeDialog*>(editor);
124 edgeEditor->setValue(value);
128 HEXA_NS::Quad *value = documentModel->getHexaPtr<HEXA_NS::Quad*>(index);
129 QuadDialog *quadEditor = static_cast<QuadDialog*>(editor);
130 quadEditor->setValue(value);
134 HEXA_NS::Hexa *value = documentModel->getHexaPtr<HEXA_NS::Hexa*>(index);
135 HexaDialog *hexaEditor = static_cast<HexaDialog*>(editor);
136 hexaEditor->setValue(value);
140 HEXA_NS::Vector *value = documentModel->getHexaPtr<HEXA_NS::Vector*>(index);
141 VectorDialog *vectorEditor = static_cast<VectorDialog*>(editor);
142 vectorEditor->setValue(value);
147 case ELEMENTS_DIR_TREE : {
148 HEXA_NS::Elements* value = documentModel->getHexaPtr<HEXA_NS::Elements*>(index);
149 // trouver le type exact (cylinder ou pipe) pour choisir le bon editor
150 // editor->setValue(value)
155 // ************ OBSOLETE ********************
156 // case CYLINDER_TREE : {
157 // HEXA_NS::Cylinder *value = documentModel->getHexaPtr<HEXA_NS::Cylinder*>(index);
158 // CylinderDialog *cylinderEditor = static_cast<CylinderDialog*>(editor);
159 // cylinderEditor->setValue(value);
162 // case PIPE_TREE : {
163 // HEXA_NS::Pipe *value = documentModel->getHexaPtr<HEXA_NS::Pipe*>(index);
164 // PipeDialog *pipeEditor= static_cast<PipeDialog*>(editor);
165 // pipeEditor->setValue(value);
168 // ************ FIN OBSOLETE *****************
171 HEXA_NS::Group *value = index.data( HEXA_DATA_ROLE ).value< HEXA_NS::Group* >();
172 GroupDialog *groupEditor = static_cast<GroupDialog*>(editor);
173 groupEditor->setValue(value);
177 HEXA_NS::Law *value = index.data( HEXA_DATA_ROLE ).value< HEXA_NS::Law* >();
178 LawDialog *lawEditor = static_cast<LawDialog*>(editor);
179 lawEditor->setValue(value);
182 case PROPAGATION_TREE : {
183 HEXA_NS::Propagation *value = index.data( HEXA_DATA_ROLE ).value< HEXA_NS::Propagation* >();
184 PropagationDialog *propagationEditor = static_cast<PropagationDialog*>(editor);
185 propagationEditor->setValue(value);
193 bool DocumentDelegate::editorEvent ( QEvent *event,
194 QAbstractItemModel *model,
195 const QStyleOptionViewItem &option,
196 const QModelIndex &index )
198 return QItemDelegate::editorEvent ( event, model, option, index );
201 bool DocumentDelegate::eventFilter ( QObject * editor, QEvent * event )
203 if ( event->type() == QEvent::FocusOut ){
204 return true; //do nothing for this signal
206 else if (event->type() == QEvent::HideToParent && editor != NULL)
208 //close the current editor when the tree is reduced
209 ((QWidget*) editor->parent())->close();