2 // Copyright (C) 2009-2012 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),
43 _patternDataSelectionModel(0),
44 _patternBuilderSelectionModel(0),
45 _groupsSelectionModel(0),
46 _meshSelectionModel(0),
49 // connect( this, SIGNAL( closeEditor(QWidget *, QAbstractItemDelegate::EndEditHint) ),
50 // this, SLOT( onCloseEditor(QWidget *, QAbstractItemDelegate::EndEditHint) ) );
51 // connect( this, SIGNAL( commitData ( QWidget * ) ),
52 // this, SLOT( onCommitData ( QWidget * ) ) );
56 QWidget *DocumentDelegate::createEditor( QWidget *parent,
57 const QStyleOptionViewItem &option,
58 const QModelIndex &index ) const
60 MESSAGE("DocumentDelegate::createEditor(){");
61 MESSAGE("* parent is: " << parent);
62 MESSAGE("* _dw is: " << _dw);
63 MESSAGE("* item is: " << index.data(Qt::DisplayRole).toString().toStdString());
65 //close current editor if there's one before creating a new one
66 if (_currentEditor != NULL)
68 delete _currentEditor;
69 _currentEditor = NULL;
72 HexaBaseDialog *editor = NULL;
74 if (_dw->widget()) _dw->widget()->close();
75 if ( !_dw->isVisible() ) _dw->setVisible(true);
77 switch ( index.data(HEXA_TREE_ROLE).toInt() ){
78 case VERTEX_TREE : editor = new VertexDialog(_dw, HexaBaseDialog::UPDATE_MODE); break;
79 case EDGE_TREE : editor = new EdgeDialog(_dw, /*HexaBaseDialog::NEW_MODE*/HexaBaseDialog::INFO_MODE); break;
80 case QUAD_TREE : editor = new QuadDialog(_dw, HexaBaseDialog::INFO_MODE); break;
81 case HEXA_TREE : editor = new HexaDialog(_dw, HexaBaseDialog::INFO_MODE); break;
82 case VECTOR_TREE : editor = new VectorDialog(_dw, HexaBaseDialog::INFO_MODE); break;
83 case CYLINDER_TREE : editor = new CylinderDialog(_dw, HexaBaseDialog::INFO_MODE); break;
84 case PIPE_TREE : editor = new PipeDialog(_dw, HexaBaseDialog::INFO_MODE); break;
85 // case ELEMENTS_TREE : break;
86 // case CROSSELEMENTS_TREE : break;
87 case GROUP_TREE : editor = new GroupDialog(_dw, HexaBaseDialog::INFO_MODE/*UPDATE_MODE*/); break;
88 case LAW_TREE : editor = new LawDialog(_dw, HexaBaseDialog::UPDATE_MODE); break;
89 case PROPAGATION_TREE : editor = new PropagationDialog(_dw, HexaBaseDialog::INFO_MODE); break;
91 if ( editor != NULL ){
92 if ( _documentModel ) editor->setDocumentModel( _documentModel );
93 if ( _patternDataSelectionModel )
95 editor->setPatternDataSelectionModel( _patternDataSelectionModel );
96 // _patternDataSelectionModel->currentDialog = editor;
98 if ( _patternBuilderSelectionModel ) editor->setPatternBuilderSelectionModel( _patternBuilderSelectionModel);
99 if ( _groupsSelectionModel ) editor->setGroupsSelectionModel( _groupsSelectionModel );
100 if ( _meshSelectionModel ) editor->setMeshSelectionModel( _meshSelectionModel);
102 HEXABLOCKGUI::assocInProgress = false;
103 //show the editor in the dockwidget
104 editor->resetSizeAndShow(_dw);
111 _currentEditor = editor;
115 //Close the current edition dialog
116 void DocumentDelegate::closeDialog()
118 if (_currentEditor!=NULL)
120 _currentEditor->close();
121 emit closeEditor(_currentEditor, NoHint);
122 delete _currentEditor;
123 _currentEditor = NULL;
127 void DocumentDelegate::setEditorData( QWidget *editor,
128 const QModelIndex &index) const
130 MESSAGE("DocumentDelegate::setEditorData(){");
131 MESSAGE("* item is: " << index.data(Qt::DisplayRole).toString().toStdString());
133 // HexaBaseDialog* editor = dynamic_cast<HexaBaseDialog*>( editor );
135 switch ( index.data(HEXA_TREE_ROLE).toInt() ){
137 // HEXA_NS::Vertex *value = index.data( HEXA_DATA_ROLE ).value< HEXA_NS::Vertex* >();
138 HEXA_NS::Vertex *value = _documentModel->getHexaPtr<HEXA_NS::Vertex *>(index);
139 VertexDialog *vertexEditor = static_cast<VertexDialog*>(editor);
140 vertexEditor->setValue(value);
144 HEXA_NS::Edge *value = _documentModel->getHexaPtr<HEXA_NS::Edge*>(index);
145 EdgeDialog *edgeEditor = static_cast<EdgeDialog*>(editor);
146 edgeEditor->setValue(value);
150 HEXA_NS::Quad *value = _documentModel->getHexaPtr<HEXA_NS::Quad*>(index);
151 QuadDialog *quadEditor = static_cast<QuadDialog*>(editor);
152 quadEditor->setValue(value);
156 HEXA_NS::Hexa *value = _documentModel->getHexaPtr<HEXA_NS::Hexa*>(index);
157 HexaDialog *hexaEditor = static_cast<HexaDialog*>(editor);
158 hexaEditor->setValue(value);
162 HEXA_NS::Vector *value = _documentModel->getHexaPtr<HEXA_NS::Vector*>(index);
163 VectorDialog *vectorEditor = static_cast<VectorDialog*>(editor);
164 vectorEditor->setValue(value);
167 case CYLINDER_TREE : {
168 HEXA_NS::Cylinder *value = _documentModel->getHexaPtr<HEXA_NS::Cylinder*>(index);
169 CylinderDialog *cylinderEditor = static_cast<CylinderDialog*>(editor);
170 cylinderEditor->setValue(value);
174 HEXA_NS::Pipe *value = _documentModel->getHexaPtr<HEXA_NS::Pipe*>(index);
175 PipeDialog *pipeEditor= static_cast<PipeDialog*>(editor);
176 pipeEditor->setValue(value);
179 // case ELEMENTSITEM : editor = new ElementsDialog(parent); break;
180 // case CROSSELEMENTSITEM : editor = new CrossElementsDialog(parent); break;
182 HEXA_NS::Group *value = index.data( HEXA_DATA_ROLE ).value< HEXA_NS::Group* >();
183 GroupDialog *groupEditor = static_cast<GroupDialog*>(editor);
184 groupEditor->setValue(value);
188 HEXA_NS::Law *value = index.data( HEXA_DATA_ROLE ).value< HEXA_NS::Law* >();
189 LawDialog *lawEditor = static_cast<LawDialog*>(editor);
190 lawEditor->setValue(value);
193 case PROPAGATION_TREE : {
194 HEXA_NS::Propagation *value = index.data( HEXA_DATA_ROLE ).value< HEXA_NS::Propagation* >();
195 PropagationDialog *propagationEditor = static_cast<PropagationDialog*>(editor);
196 propagationEditor->setValue(value);
205 bool DocumentDelegate::editorEvent ( QEvent *event,
206 QAbstractItemModel *model,
207 const QStyleOptionViewItem &option,
208 const QModelIndex &index )
210 MESSAGE("DocumentDelegate::editorEvent(){");
211 MESSAGE("* item is: " << index.data().toString().toStdString());
212 MESSAGE("* event is: " << event->type() );
214 Qt::ItemFlags flags = model->flags(index);
215 if ( flags == Qt::ItemFlags( ~Qt::ItemIsEditable ) ){
216 MESSAGE("* you can select it ");
218 MESSAGE("* you cannot select it ");
221 //return QItemDelegate::editorEvent ( event, model, option, index );
225 bool DocumentDelegate::eventFilter ( QObject * editor, QEvent * event )
227 if ( event->type() == QEvent::FocusOut ){
228 //((QWidget*) editor->parent())->close();