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
24 #include "utilities.h"
27 #include "HEXABLOCKGUI_DocumentDelegate.hxx"
28 #include "HEXABLOCKGUI_DocumentItem.hxx"
29 #include "HEXABLOCKGUI_DocumentPanel.hxx"
32 using namespace HEXABLOCK::GUI;
35 DocumentDelegate::DocumentDelegate(QDockWidget *dw, QObject *parent)
36 : QItemDelegate(parent),
39 _patternDataSelectionModel(0),
40 _patternBuilderSelectionModel(0),
41 _groupsSelectionModel(0),
42 _meshSelectionModel(0)
44 // connect( this, SIGNAL( closeEditor(QWidget *, QAbstractItemDelegate::EndEditHint) ),
45 // this, SLOT( onCloseEditor(QWidget *, QAbstractItemDelegate::EndEditHint) ) );
46 // connect( this, SIGNAL( commitData ( QWidget * ) ),
47 // this, SLOT( onCommitData ( QWidget * ) ) );
51 // void DocumentDelegate::commitEditor()
53 // MESSAGE("DocumentDelegate::commitEditor(){")
54 // MESSAGE("* sender is: " << sender() );
55 // QWidget* editor = qobject_cast<QWidget*>(sender());
56 // emit commitData(editor);
57 // // emit closeEditor(editor);
61 QWidget *DocumentDelegate::createEditor( QWidget *parent,
62 const QStyleOptionViewItem &option,
63 const QModelIndex &index ) const
65 MESSAGE("DocumentDelegate::createEditor(){");
66 MESSAGE("* parent is: " << parent);
67 MESSAGE("* _dw is: " << _dw);
68 MESSAGE("* item is: " << index.data(Qt::DisplayRole).toString().toStdString());
70 HexaBaseDialog *editor = 0;
72 switch ( index.data(HEXA_TREE_ROLE).toInt() ){
73 case VERTEX_TREE : editor = new VertexDialog(parent, HexaBaseDialog::UPDATE_MODE); break;
74 case EDGE_TREE : editor = new EdgeDialog(parent, /*HexaBaseDialog::NEW_MODE*/HexaBaseDialog::INFO_MODE); break;
75 case QUAD_TREE : editor = new QuadDialog(parent, HexaBaseDialog::INFO_MODE); break;
76 case HEXA_TREE : editor = new HexaDialog(parent, HexaBaseDialog::INFO_MODE); break;
77 case VECTOR_TREE : editor = new VectorDialog(parent, HexaBaseDialog::INFO_MODE); break;
78 case CYLINDER_TREE : editor = new CylinderDialog(parent, HexaBaseDialog::INFO_MODE); break;
79 case PIPE_TREE : editor = new PipeDialog(parent, HexaBaseDialog::INFO_MODE); break;
80 // case ELEMENTS_TREE : break;
81 // case CROSSELEMENTS_TREE : break;
82 case GROUP_TREE : editor = new GroupDialog(parent, HexaBaseDialog::INFO_MODE/*UPDATE_MODE*/); break;
83 case LAW_TREE : editor = new LawDialog(parent, HexaBaseDialog::UPDATE_MODE); break;
84 case PROPAGATION_TREE : editor = new PropagationDialog(parent, HexaBaseDialog::INFO_MODE); break;
87 if ( _documentModel ) editor->setDocumentModel( _documentModel );
88 if ( _patternDataSelectionModel ) editor->setPatternDataSelectionModel( _patternDataSelectionModel );
89 if ( _patternBuilderSelectionModel ) editor->setPatternBuilderSelectionModel( _patternBuilderSelectionModel);
90 if ( _groupsSelectionModel ) editor->setGroupsSelectionModel( _groupsSelectionModel );
91 if ( _meshSelectionModel ) editor->setMeshSelectionModel( _meshSelectionModel);
93 // QWidget* w = _dw->widget();
95 if ( !_dw->isVisible() ) _dw->setVisible(true);
96 _dw->setWidget( editor );
97 _dw->setWindowTitle( editor->windowTitle() );
98 // connect ( editor, SIGNAL( editingFinished() ), this, SLOT ( commitEditor() ) );
102 // editor->setFocus();
107 // return new QLineEdit(parent);
111 void DocumentDelegate::setEditorData( QWidget *editor,
112 const QModelIndex &index) const
114 MESSAGE("DocumentDelegate::setEditorData(){");
115 MESSAGE("* item is: " << index.data(Qt::DisplayRole).toString().toStdString());
117 // HexaBaseDialog* editor = dynamic_cast<HexaBaseDialog*>( editor );
119 switch ( index.data(HEXA_TREE_ROLE).toInt() ){
121 HEXA_NS::Vertex *value = index.data( HEXA_DATA_ROLE ).value< HEXA_NS::Vertex* >();
122 VertexDialog *vertexEditor = static_cast<VertexDialog*>(editor);
123 vertexEditor->setValue(value);
127 HEXA_NS::Edge *value = index.data( HEXA_DATA_ROLE ).value< HEXA_NS::Edge* >();
128 EdgeDialog *edgeEditor = static_cast<EdgeDialog*>(editor);
129 edgeEditor->setValue(value);
133 HEXA_NS::Quad *value = index.data( HEXA_DATA_ROLE ).value< HEXA_NS::Quad* >();
134 QuadDialog *quadEditor = static_cast<QuadDialog*>(editor);
135 quadEditor->setValue(value);
139 HEXA_NS::Hexa *value = index.data( HEXA_DATA_ROLE ).value< HEXA_NS::Hexa* >();
140 HexaDialog *hexaEditor = static_cast<HexaDialog*>(editor);
141 hexaEditor->setValue(value);
145 HEXA_NS::Vector *value = index.data( HEXA_DATA_ROLE ).value< HEXA_NS::Vector* >();
146 VectorDialog *vectorEditor = static_cast<VectorDialog*>(editor);
147 vectorEditor->setValue(value);
150 case CYLINDER_TREE : {
151 HEXA_NS::Cylinder *value = index.data( HEXA_DATA_ROLE ).value< HEXA_NS::Cylinder* >();
152 CylinderDialog *cylinderEditor = static_cast<CylinderDialog*>(editor);
153 cylinderEditor->setValue(value);
157 HEXA_NS::Pipe *value = index.data( HEXA_DATA_ROLE ).value< HEXA_NS::Pipe* >();
158 PipeDialog *pipeEditor= static_cast<PipeDialog*>(editor);
159 pipeEditor->setValue(value);
162 // case ELEMENTSITEM : editor = new ElementsDialog(parent); break;
163 // case CROSSELEMENTSITEM : editor = new CrossElementsDialog(parent); break;
165 HEXA_NS::Group *value = index.data( HEXA_DATA_ROLE ).value< HEXA_NS::Group* >();
166 GroupDialog *groupEditor = static_cast<GroupDialog*>(editor);
167 groupEditor->setValue(value);
171 HEXA_NS::Law *value = index.data( HEXA_DATA_ROLE ).value< HEXA_NS::Law* >();
172 LawDialog *lawEditor = static_cast<LawDialog*>(editor);
173 lawEditor->setValue(value);
176 case PROPAGATION_TREE : {
177 HEXA_NS::Propagation *value = index.data( HEXA_DATA_ROLE ).value< HEXA_NS::Propagation* >();
178 PropagationDialog *propagationEditor = static_cast<PropagationDialog*>(editor);
179 propagationEditor->setValue(value);
184 // editor->setFocus();
189 // void DocumentDelegate::setModelData( QWidget *editor, QAbstractItemModel *model,
190 // const QModelIndex &index) const
192 // cout << "//////////////////// CS_BP DocumentDelegate::setModelData BEGIN "<< editor << endl;
193 // // // QStandardItem *item = 0;
194 // // // QItemDelegate::setModelData( editor, model,index);
196 // // // // CS_TODO : simplification?
197 // // QSortFilterProxyModel *pmodel = dynamic_cast<QSortFilterProxyModel *>( model );
199 // // QStandardItemModel *smodel = dynamic_cast<QStandardItemModel *>( pmodel->sourceModel() );
201 // // // item = smodel->itemFromIndex(index);
202 // // QItemDelegate::setModelData( editor, smodel, pmodel->mapToSource(index));
205 // // QStandardItemModel *smodel = dynamic_cast<QStandardItemModel *>( model );
207 // // // item = smodel->itemFromIndex(index);
208 // // QItemDelegate::setModelData( editor, model,index);
211 // // QItemDelegate::setModelData( editor, model, index);
212 // cout << "//////////////////// CS_BP DocumentDelegate::setModelData END"<< editor << endl;
217 void DocumentDelegate::setModelData( QWidget *editor,
218 QAbstractItemModel *model,
219 const QModelIndex &index) const
221 // cout <<" XXXXXXXXXXXXXX setModelData editor => " << editor << endl;
222 MESSAGE("DocumentDelegate::setModelData(){");
223 MESSAGE("* item is: " << index.data(Qt::DisplayRole).toString().toStdString());
224 // HexaDialog *hexaEditor = qobject_cast<HexaDialog*>(editor);
225 // // PipeDialog *qtcast = qobject_cast<PipeDialog*>(editor);
226 // // PipeDialog *cppcast = dynamic_cast<PipeDialog*>(editor);
228 // if ( hexaEditor ){
229 // HEXA_NS::Hexa *value = hexaEditor->getValue();
230 // cout << "XXXXXXXXXXX DocumentDelegate::setModelData value "<< value << endl;
231 // model->setData( index, QVariant::fromValue( value ), HEXA_DATA_ROLE );
232 // model->setData( index, value->getName(), Qt::DisplayRole/*Qt::EditRole*/ );
233 // model->setData( index, QString::number( reinterpret_cast<intptr_t>(value) ), HEXA_ENTRY_ROLE );
238 // cout << "AAAAAAA _dw"<< _dw<< endl;
239 // cout << "AAAAAAA _dw->widget()"<< _dw->widget() << endl;
240 // cout << "AAAAAAA isVisible"<< _dw->isVisible() << endl;
241 // cout << "AAAAAAA editor isVisible"<< editor->isVisible() << endl;
242 // // editor = new HexaDialog();
243 // _dw->setWindowTitle( "HOOOOOOOOOO" );
244 // _dw->setWidget(editor);
245 // _dw->setVisible(false);
246 // // editor->raise();
248 // _dw->setVisible(true);
249 // cout << "BBBBBBB _dw"<< _dw<< endl;
250 // cout << "BBBBBBB _dw->widget()"<< _dw->widget() << endl;
251 // cout << "BBBBBBB isVisible"<< _dw->isVisible() << endl;
252 // cout << "BBBBBBB editor isVisible"<< editor->isVisible() << endl;
254 // HEXA_NS::Quad *value = quadEditor->getValue();
255 // model->setData(index, QVariant::fromValue( value ), HEXA_DATA_ROLE);
263 void DocumentDelegate::updateEditorGeometry( QWidget *editor,
264 const QStyleOptionViewItem &option,
265 const QModelIndex &index ) const
268 MESSAGE("DocumentDelegate::updateEditorGeometry(){");
269 MESSAGE("* item is: " << index.data(Qt::DisplayRole).toString().toStdString());
270 // cout << "CS_BP option.rect.size()"<<option.rect.size()<<endl;
271 MESSAGE("* option.rect.width() is: " << option.rect.width() << option.rect.width() );
272 MESSAGE("* option.rect.x() is: " << option.rect.x() << option.rect.x() );
273 MESSAGE("* option.rect.y() is: " << option.rect.y() << option.rect.y() );
274 // editor->setGeometry(option.rect);
284 void DocumentDelegate::setDocumentModel( DocumentModel* m )
289 void DocumentDelegate::setPatternDataSelectionModel( PatternDataSelectionModel* s )
291 _patternDataSelectionModel = s;
294 void DocumentDelegate::setPatternBuilderSelectionModel( PatternBuilderSelectionModel* s )
296 _patternBuilderSelectionModel = s;
299 void DocumentDelegate::setGroupsSelectionModel( GroupsSelectionModel* s )
301 _groupsSelectionModel = s ;
304 void DocumentDelegate::setMeshSelectionModel( MeshSelectionModel* s )
306 _meshSelectionModel = s;
311 bool DocumentDelegate::editorEvent ( QEvent *event,
312 QAbstractItemModel *model,
313 const QStyleOptionViewItem &option,
314 const QModelIndex &index )
316 MESSAGE("DocumentDelegate::editorEvent(){");
317 MESSAGE("* item is: " << index.data().toString().toStdString());
318 MESSAGE("* event is: " << event->type() );
320 Qt::ItemFlags flags = model->flags(index);
321 if ( flags == Qt::ItemFlags( ~Qt::ItemIsEditable ) ){
322 MESSAGE("* you can select it ");
324 MESSAGE("* you cannot select it ");
330 // if ( event->type() == 3 ){
333 // r = QItemDelegate::editorEvent ( event, model, option, index );
335 // MESSAGE("* result is: " << r );
339 return QItemDelegate::editorEvent ( event, model, option, index );
342 // void DocumentDelegate::onCloseEditor( QWidget *w, QAbstractItemDelegate::EndEditHint h)
344 // MESSAGE("DocumentDelegate::onCloseEditor(){");
349 // void DocumentDelegate::onCommitData ( QWidget * editor )
351 // MESSAGE("DocumentDelegate::onCommitData(){");
356 // connect( this, SIGNAL( commitData ( QWidget * ) ),
357 // this, SLOT( onCommitData ( QWidget * ) ) );
360 // // virtual bool eventFilter ( QObject * editor, QEvent * event )
362 // // // std::cout << "eventFilter eventFilter " << event->type() << std::endl;
363 // // // std::cout << std::endl;
365 // // if (event->type() == QEvent::FocusOut) {
366 // // // QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
367 // // // qDebug() << "Ate key press" << keyEvent->key();
368 // // // return true;
371 // // return QItemDelegate::eventFilter ( editor, event );
372 // // // return false;
377 // void DocumentDelegate::setModelData( QWidget *editor, QAbstractItemModel *model,
378 // const QModelIndex &index) const
380 // cout << "*********************** CS_BP DocumentDelegate::setModelData BEGIN "<< editor << endl;
381 // QStandardItem *item = 0;
383 // // CS_TODO : simplification?
384 // QSortFilterProxyModel *pmodel = dynamic_cast<QSortFilterProxyModel *>( model );
386 // QStandardItemModel *smodel = dynamic_cast<QStandardItemModel *>( pmodel->sourceModel() );
388 // item = smodel->itemFromIndex(pmodel->mapToSource(index));
391 // QStandardItemModel *smodel = dynamic_cast<QStandardItemModel *>( model );
393 // item = smodel->itemFromIndex(index);
399 // // cout << "item " << item->type() << endl;
400 // if ( item->data().isValid() )
401 // cout << "*************** item " << item->data(Qt::DisplayRole).toString().toStdString() << endl;
402 // switch ( item->type() ){
403 // case VERTEXITEM : {
404 // VertexDialog *vertexEditor = static_cast<VertexDialog*>(editor);
405 // HEXA_NS::Vertex *value = vertexEditor->getValue();
406 // model->setData(index, QVariant::fromValue( value ), HEXA_DATA_ROLE);
411 // EdgeDialog *edgeEditor = static_cast<EdgeDialog*>(editor);
412 // HEXA_NS::Edge *value = edgeEditor->getValue();
413 // model->setData(index, QVariant::fromValue( value ), HEXA_DATA_ROLE);
418 // QuadDialog *quadEditor = static_cast<QuadDialog*>(editor);
419 // HEXA_NS::Quad *value = quadEditor->getValue();
420 // model->setData(index, QVariant::fromValue( value ), HEXA_DATA_ROLE);
425 // HexaDialog *hexaEditor = static_cast<HexaDialog*>(editor);
426 // HEXA_NS::Hexa *value = hexaEditor->getValue();
427 // model->setData(index, QVariant::fromValue( value ), HEXA_DATA_ROLE);
431 // case VECTORITEM : {
432 // VectorDialog *vectorEditor = static_cast<VectorDialog*>(editor);
433 // HEXA_NS::Vector *value = vectorEditor->getValue();
434 // model->setData(index, QVariant::fromValue( value ), HEXA_DATA_ROLE);
438 // case CYLINDERITEM : {
439 // CylinderDialog *cylinderEditor = static_cast<CylinderDialog*>(editor);
440 // HEXA_NS::Cylinder *value = cylinderEditor->getValue();
441 // model->setData(index, QVariant::fromValue( value ), HEXA_DATA_ROLE);
445 // PipeDialog *pipeEditor = static_cast<PipeDialog*>(editor);
446 // HEXA_NS::Pipe *value = pipeEditor->getValue();
447 // model->setData(index, QVariant::fromValue( value ), HEXA_DATA_ROLE);
450 // // case ELEMENTSITEM : editor = new ElementsDialog(parent); break;
451 // // case CROSSELEMENTSITEM : editor = new CrossElementsDialog(parent); break;
453 // GroupDialog *groupEditor = static_cast<GroupDialog*>(editor);
454 // HEXA_NS::Group *value = groupEditor->getValue();
455 // model->setData(index, QVariant::fromValue( value ), HEXA_DATA_ROLE);
459 // LawDialog *lawEditor = static_cast<LawDialog*>(editor);
460 // HEXA_NS::Law *value = lawEditor->getValue();
461 // model->setData(index, QVariant::fromValue( value ), HEXA_DATA_ROLE);
464 // case PROPAGATIONITEM : {
465 // PropagationDialog *propagationEditor = static_cast<PropagationDialog*>(editor);
466 // HEXA_NS::Propagation *value = propagationEditor->getValue();
467 // model->setData(index, QVariant::fromValue( value ), HEXA_DATA_ROLE);
474 // cout << "*********************** CS_BP DocumentDelegate::setModelData END "<< editor << endl;