Salome HOME
18e9821318598f26eaf342634f95a14bab7cda3d
[modules/paravis.git] / src / PVGUI / PVGUI_ParaViewSettingsPane.cxx
1 // PARAVIS : ParaView wrapper SALOME module
2 //
3 // Copyright (C) 2010-2014  CEA/DEN, EDF R&D
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 //
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //
21 // File   : PVGUI_ParaViewSettingsPane.cxx
22 // Author : Vitaly Smetannikov
23 //
24
25 #include "PVGUI_ParaViewSettingsPane.h"
26 #include "ui_pqOptionsDialog.h"
27
28 #include <pqApplicationSettingsReaction.h>
29
30 #include <QString>
31
32
33 //class OptionsDialogModelItem
34 //{
35 //public:
36 //  OptionsDialogModelItem();
37 //  OptionsDialogModelItem(const QString &name);
38 //  ~OptionsDialogModelItem();
39 //
40 //  OptionsDialogModelItem *Parent;
41 //  QString Name;
42 //  QList<OptionsDialogModelItem *> Children;
43 //};
44 //
45 //
46 //class OptionsDialogModel : public QAbstractItemModel
47 //{
48 //public:
49 //  OptionsDialogModel(QObject *parent=0);
50 //  virtual ~OptionsDialogModel();
51 //
52 //  virtual int rowCount(const QModelIndex &parent=QModelIndex()) const;
53 //  virtual int columnCount(const QModelIndex &parent=QModelIndex()) const;
54 //  virtual QModelIndex index(int row, int column,
55 //      const QModelIndex &parent=QModelIndex()) const;
56 //  virtual QModelIndex parent(const QModelIndex &child) const;
57 //
58 //  virtual QVariant data(const QModelIndex &index,
59 //      int role=Qt::DisplayRole) const;
60 //
61 //  QModelIndex getIndex(const QString &path) const;
62 //  QString getPath(const QModelIndex &index) const;
63 //  void addPath(const QString &path);
64 //  bool removeIndex(const QModelIndex &index);
65 //
66 //private:
67 //  QModelIndex getIndex(OptionsDialogModelItem *item) const;
68 //
69 //private:
70 //  OptionsDialogModelItem *Root;
71 //};
72
73
74 class OptionsDialogForm : public Ui::PVGUIOptionsFrame
75 {
76 public:
77   OptionsDialogForm();
78   ~OptionsDialogForm();
79
80 //  QMap<QString, pqOptionsPage *> Pages;
81 //  OptionsDialogModel *Model;
82 //  int ApplyUseCount;
83   //bool ApplyNeeded;
84 };
85
86
87 //----------------------------------------------------------------------------
88 //OptionsDialogModelItem::OptionsDialogModelItem()
89 //  : Name(), Children()
90 //{
91 //  this->Parent = 0;
92 //}
93 //
94 //OptionsDialogModelItem::OptionsDialogModelItem(const QString &name)
95 //  : Name(name), Children()
96 //{
97 //  this->Parent = 0;
98 //}
99 //
100 //OptionsDialogModelItem::~OptionsDialogModelItem()
101 //{
102 //  QList<OptionsDialogModelItem *>::Iterator iter = this->Children.begin();
103 //  for( ; iter != this->Children.end(); ++iter)
104 //    {
105 //    delete *iter;
106 //    }
107 //}
108
109
110 //----------------------------------------------------------------------------
111 //OptionsDialogModel::OptionsDialogModel(QObject *parentObject)
112 //  : QAbstractItemModel(parentObject)
113 //{
114 //  this->Root = new OptionsDialogModelItem();
115 //}
116 //
117 //OptionsDialogModel::~OptionsDialogModel()
118 //{
119 //  delete this->Root;
120 //}
121 //
122 //int OptionsDialogModel::rowCount(const QModelIndex &parentIndex) const
123 //{
124 //  OptionsDialogModelItem *item = this->Root;
125 //  if(parentIndex.isValid())
126 //    {
127 //    item = reinterpret_cast<OptionsDialogModelItem *>(
128 //        parentIndex.internalPointer());
129 //    }
130 //
131 //  return item->Children.size();
132 //}
133 //
134 //int OptionsDialogModel::columnCount(const QModelIndex &) const
135 //{
136 //  return 1;
137 //}
138 //
139 //QModelIndex OptionsDialogModel::index(int row, int column,
140 //    const QModelIndex &parentIndex) const
141 //{
142 //  OptionsDialogModelItem *item = this->Root;
143 //  if(parentIndex.isValid())
144 //    {
145 //    item = reinterpret_cast<OptionsDialogModelItem *>(
146 //        parentIndex.internalPointer());
147 //    }
148 //
149 //  if(column == 0 && row >= 0 && row < item->Children.size())
150 //    {
151 //    return this->createIndex(row, column, item->Children[row]);
152 //    }
153 //
154 //  return QModelIndex();
155 //}
156 //
157 //QModelIndex OptionsDialogModel::parent(const QModelIndex &child) const
158 //{
159 //  if(child.isValid())
160 //    {
161 //    OptionsDialogModelItem *item =
162 //        reinterpret_cast<OptionsDialogModelItem *>(child.internalPointer());
163 //    return this->getIndex(item->Parent);
164 //    }
165 //
166 //  return QModelIndex();
167 //}
168 //
169 //QVariant OptionsDialogModel::data(const QModelIndex &idx, int role) const
170 //{
171 //  if(idx.isValid())
172 //    {
173 //    OptionsDialogModelItem *item =
174 //        reinterpret_cast<OptionsDialogModelItem *>(idx.internalPointer());
175 //    if(role == Qt::DisplayRole || role == Qt::ToolTipRole)
176 //      {
177 //      return QVariant(item->Name);
178 //      }
179 //    }
180 //
181 //  return QVariant();
182 //}
183 //
184 //QModelIndex OptionsDialogModel::getIndex(const QString &path) const
185 //{
186 //  OptionsDialogModelItem *item = this->Root;
187 //  QStringList names = path.split(".");
188 //  QStringList::Iterator iter = names.begin();
189 //  for( ; item && iter != names.end(); ++iter)
190 //    {
191 //    OptionsDialogModelItem *child = 0;
192 //    QList<OptionsDialogModelItem *>::Iterator jter = item->Children.begin();
193 //    for( ; jter != item->Children.end(); ++jter)
194 //      {
195 //      if((*jter)->Name == *iter)
196 //        {
197 //        child = *jter;
198 //        break;
199 //        }
200 //      }
201 //
202 //    item = child;
203 //    }
204 //
205 //  if(item && item != this->Root)
206 //    {
207 //    return this->getIndex(item);
208 //    }
209 //
210 //  return QModelIndex();
211 //}
212 //
213 //QString OptionsDialogModel::getPath(const QModelIndex &idx) const
214 //{
215 //  if(idx.isValid())
216 //    {
217 //    QString path;
218 //    OptionsDialogModelItem *item =
219 //        reinterpret_cast<OptionsDialogModelItem *>(idx.internalPointer());
220 //    if(item)
221 //      {
222 //      path = item->Name;
223 //      item = item->Parent;
224 //      }
225 //
226 //    while(item && item != this->Root)
227 //      {
228 //      path.prepend(".").prepend(item->Name);
229 //      item = item->Parent;
230 //      }
231 //
232 //    return path;
233 //    }
234 //
235 //  return QString();
236 //}
237 //
238 //void OptionsDialogModel::addPath(const QString &path)
239 //{
240 //  OptionsDialogModelItem *item = this->Root;
241 //  QStringList names = path.split(".");
242 //  QStringList::Iterator iter = names.begin();
243 //  for( ; iter != names.end(); ++iter)
244 //    {
245 //    OptionsDialogModelItem *child = 0;
246 //    QList<OptionsDialogModelItem *>::Iterator jter = item->Children.begin();
247 //    for( ; jter != item->Children.end(); ++jter)
248 //      {
249 //      if((*jter)->Name == *iter)
250 //        {
251 //        child = *jter;
252 //        break;
253 //        }
254 //      }
255 //
256 //    if(!child)
257 //      {
258 //      child = new OptionsDialogModelItem(*iter);
259 //      child->Parent = item;
260 //      QModelIndex parentIndex = this->getIndex(item);
261 //      int row = item->Children.size();
262 //      this->beginInsertRows(parentIndex, row, row);
263 //      item->Children.append(child);
264 //      this->endInsertRows();
265 //      }
266 //
267 //    item = child;
268 //    }
269 //}
270 //
271 //bool OptionsDialogModel::removeIndex(const QModelIndex &idx)
272 //{
273 //  if(idx.isValid())
274 //    {
275 //    OptionsDialogModelItem *item =
276 //        reinterpret_cast<OptionsDialogModelItem *>(idx.internalPointer());
277 //    if(item->Children.size() == 0)
278 //      {
279 //      QModelIndex parentIndex = this->getIndex(item->Parent);
280 //      this->beginRemoveRows(parentIndex, idx.row(), idx.row());
281 //      item->Parent->Children.removeAt(idx.row());
282 //      this->endRemoveRows();
283 //      delete item;
284 //      return true;
285 //      }
286 //    }
287 //
288 //  return false;
289 //}
290 //
291 //QModelIndex OptionsDialogModel::getIndex(
292 //    OptionsDialogModelItem *item) const
293 //{
294 //  if(item && item->Parent)
295 //    {
296 //    return this->createIndex(item->Parent->Children.indexOf(item), 0, item);
297 //    }
298 //
299 //  return QModelIndex();
300 //}
301
302
303 //----------------------------------------------------------------------------
304 OptionsDialogForm::OptionsDialogForm()
305   : Ui::PVGUIOptionsFrame()
306 {
307 //  this->Model = new OptionsDialogModel();
308 //  this->ApplyUseCount = 0;
309 //  //this->ApplyNeeded = false;
310 }
311
312 OptionsDialogForm::~OptionsDialogForm()
313 {
314 //  delete this->Model;
315 }
316
317
318 //----------------------------------------------------------------------------
319 PVGUI_ParaViewSettingsPane::PVGUI_ParaViewSettingsPane(QWidget *widgetParent)
320   : QtxUserDefinedContent(widgetParent)
321 {
322   Form = new OptionsDialogForm();
323   Form->setupUi(this);
324   
325   // Connect the button to the standard ParaView 4.2 setting reaction for now:
326   connect(Form->pvButton, SIGNAL(clicked()),
327           this, SLOT(onRequestParaviewSettings()));
328
329   
330 ////  this->Form->PageNames->setModel(this->Form->Model);
331 //
332 //  // Hide the tree widget header view.
333 //  this->Form->PageNames->header()->hide();
334 //
335 //  // Hide the apply and reset buttons until they are needed.
336 //  //this->Form->ApplyButton->setEnabled(false);
337 //  //this->Form->ResetButton->setEnabled(false);
338 //  //this->Form->ApplyButton->hide();
339 //  //this->Form->ResetButton->hide();
340 //
341 //  this->connect(this->Form->PageNames->selectionModel(),
342 //      SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
343 //      this, SLOT(changeCurrentPage()));
344 //  //this->connect(this->Form->ApplyButton, SIGNAL(clicked()),
345 //  //    this, SLOT(applyChanges()));
346 //  //this->connect(this->Form->ResetButton, SIGNAL(clicked()),
347 //  //    this, SLOT(resetChanges()));
348 //  //this->connect(this->Form->CloseButton, SIGNAL(clicked()),
349 //  //    this, SLOT(accept()));
350 //
351 //  // Code From pqApplicationOptionsDialog
352 //  //this->setApplyNeeded(true);
353 //
354 //  pqApplicationOptions* appOptions = new pqApplicationOptions;
355 //  this->addOptions(appOptions);
356 //
357 //  pqGlobalRenderViewOptions* renOptions = new pqGlobalRenderViewOptions;
358 //  this->addOptions(renOptions);
359 //
360 //  QStringList pages = appOptions->getPageList();
361 //  if(pages.size())
362 //    {
363 //    this->setCurrentPage(pages[0]);
364 //    }
365 //
366 //  /// Add panes as plugins are loaded.
367 //  QObject::connect(pqApplicationCore::instance()->getPluginManager(),
368 //    SIGNAL(guiInterfaceLoaded(QObject*)),
369 //    this, SLOT(pluginLoaded(QObject*)));
370 //
371 //  // Load panes from already loaded plugins.
372 //  foreach (QObject* plugin_interface, pqApplicationCore::instance()->interfaceTracker()->interfaces())
373 //           //pqApplicationCore::instance()->getPluginManager()->interfaces())
374 //    {
375 //    this->pluginLoaded(plugin_interface);
376 //    }
377 }
378
379 PVGUI_ParaViewSettingsPane::~PVGUI_ParaViewSettingsPane()
380 {
381   delete this->Form;
382 }
383
384 void PVGUI_ParaViewSettingsPane::onRequestParaviewSettings()
385 {
386   pqApplicationSettingsReaction::showApplicationSettingsDialog();
387 }
388
389 /*
390 bool PVGUI_ParaViewSettingsPane::isApplyNeeded() const
391 {
392   return this->Form->ApplyNeeded;
393 }
394 */
395 /*
396 void PVGUI_ParaViewSettingsPane::setApplyNeeded(bool applyNeeded)
397 {
398   if(applyNeeded != this->Form->ApplyNeeded)
399     {
400     if(!applyNeeded)
401       {
402       this->Form->ApplyNeeded = false;
403       //this->Form->ApplyButton->setEnabled(false);
404       //this->Form->ResetButton->setEnabled(false);
405       }
406     else if(this->Form->ApplyUseCount > 0)
407       {
408       this->Form->ApplyNeeded = true;
409       //this->Form->ApplyButton->setEnabled(true);
410       //this->Form->ResetButton->setEnabled(true);
411       }
412     }
413 }
414 */
415 //void PVGUI_ParaViewSettingsPane::addOptions(const QString &path, pqOptionsPage *options)
416 //{
417 //  if(!options)
418 //    {
419 //    return;
420 //    }
421 //
422 //  // See if the page is a container.
423 //  pqOptionsContainer *container = qobject_cast<pqOptionsContainer *>(options);
424 //  if(!container && path.isEmpty())
425 //    {
426 //    return;
427 //    }
428 //
429 //  // See if the page/container uses the apply button.
430 //  if(options->isApplyUsed())
431 //    {
432 //    this->Form->ApplyUseCount++;
433 //    /*if(this->Form->ApplyUseCount == 1)
434 //      {
435 //        //this->Form->ApplyButton->show();
436 //        //this->Form->ResetButton->show();
437 //        //QObject::connect(this, SIGNAL(accepted()), this, SLOT(applyChanges()));
438 //        }*/
439 //
440 //    //this->connect(options, SIGNAL(changesAvailable()),
441 //    //this, SLOT(enableButtons()));
442 //    }
443 //
444 //  // Add the widget to the stack.
445 //  this->Form->Stack->addWidget(options);
446 //
447 //  // Add the page(s) to the map and the model.
448 //  if(container)
449 //    {
450 //    // If the path is not empty, use it as the page prefix.
451 //    QString prefix;
452 //    if(!path.isEmpty())
453 //      {
454 //      prefix = path;
455 //      prefix.append(".");
456 //      }
457 //
458 //    container->setPagePrefix(prefix);
459 //
460 //    // Get the list of pages from the container.
461 //    QStringList pathList = container->getPageList();
462 //    QStringList::Iterator iter = pathList.begin();
463 //    for( ; iter != pathList.end(); ++iter)
464 //      {
465 //      this->Form->Pages.insert(prefix + *iter, options);
466 //      this->Form->Model->addPath(prefix + *iter);
467 //      }
468 //    }
469 //  else
470 //    {
471 //    this->Form->Pages.insert(path, options);
472 //    this->Form->Model->addPath(path);
473 //    }
474 //}
475 //
476 //void PVGUI_ParaViewSettingsPane::addOptions(pqOptionsContainer *options)
477 //{
478 //  this->addOptions(QString(), options);
479 //}
480 //
481 //void PVGUI_ParaViewSettingsPane::removeOptions(pqOptionsPage *options)
482 //{
483 //  if(!options)
484 //    {
485 //    return;
486 //    }
487 //
488 //  // Remove the widget from the stack.
489 //  this->Form->Stack->removeWidget(options);
490 //
491 //  // See if the options use the apply button.
492 //  if(options->isApplyUsed())
493 //    {
494 //    this->Form->ApplyUseCount--;
495 //    /*if(this->Form->ApplyUseCount == 0)
496 //      {
497 //        //this->Form->ApplyNeeded = false;
498 //      //this->Form->ApplyButton->setEnabled(false);
499 //      //this->Form->ResetButton->setEnabled(false);
500 //      //this->Form->ApplyButton->hide();
501 //      //this->Form->ResetButton->hide();
502 //      //QObject::disconnect(this, SIGNAL(accepted()), this, SLOT(applyChanges()));
503 //      }*/
504 //
505 //    this->disconnect(options, 0, this, 0);
506 //    }
507 //
508 //  // Search the map for the paths to remove.
509 //  QMap<QString, pqOptionsPage *>::Iterator iter = this->Form->Pages.begin();
510 //  while(iter != this->Form->Pages.end())
511 //    {
512 //    if(*iter == options)
513 //      {
514 //      QString path = iter.key();
515 //      iter = this->Form->Pages.erase(iter);
516 //
517 //      // Remove the item from the tree model as well.
518 //      QModelIndex index = this->Form->Model->getIndex(path);
519 //      QPersistentModelIndex parentIndex = index.parent();
520 //      if(this->Form->Model->removeIndex(index))
521 //        {
522 //        // Remove any empty parent items.
523 //        while(parentIndex.isValid() &&
524 //            this->Form->Model->rowCount(parentIndex) == 0)
525 //          {
526 //          index = parentIndex;
527 //          parentIndex = index.parent();
528 //
529 //          // Make sure the index path isn't in the map.
530 //          path = this->Form->Model->getPath(index);
531 //          if(this->Form->Pages.find(path) == this->Form->Pages.end())
532 //            {
533 //            if(!this->Form->Model->removeIndex(index))
534 //              {
535 //              break;
536 //              }
537 //            }
538 //          }
539 //        }
540 //      }
541 //    else
542 //      {
543 //      ++iter;
544 //      }
545 //    }
546 //}
547 //
548 //void PVGUI_ParaViewSettingsPane::setCurrentPage(const QString &path)
549 //{
550 //  QModelIndex current = this->Form->Model->getIndex(path);
551 //  this->Form->PageNames->setCurrentIndex(current);
552 //}
553
554 void PVGUI_ParaViewSettingsPane::applyChanges()
555 {
556   //if(this->Form->ApplyNeeded)
557   //  {
558 //    BEGIN_UNDO_SET("Changed View Settings");
559 //    emit this->aboutToApplyChanges();
560 //    QMap<QString, pqOptionsPage *>::Iterator iter = this->Form->Pages.begin();
561 //    for( ; iter != this->Form->Pages.end(); ++iter)
562 //      {
563 //      (*iter)->applyChanges();
564 //      }
565 //
566 //    //this->setApplyNeeded(false);
567 //    emit this->appliedChanges();
568 //    END_UNDO_SET();
569     //}
570 }
571
572 void PVGUI_ParaViewSettingsPane::resetChanges()
573 {
574   //if(this->Form->ApplyNeeded)
575   //{
576 //    QMap<QString, pqOptionsPage *>::Iterator iter = this->Form->Pages.begin();
577 //    for( ; iter != this->Form->Pages.end(); ++iter)
578 //      {
579 //      (*iter)->resetChanges();
580 //      }
581
582     //this->setApplyNeeded(false);
583     //}
584 }
585
586 //void PVGUI_ParaViewSettingsPane::changeCurrentPage()
587 //{
588 //  // Get the current index from the view.
589 //  QModelIndex current = this->Form->PageNames->currentIndex();
590 //
591 //  // Look up the path for the current index.
592 //  QString path = this->Form->Model->getPath(current);
593 //  QMap<QString, pqOptionsPage *>::Iterator iter = this->Form->Pages.find(path);
594 //  if(iter == this->Form->Pages.end())
595 //    {
596 //    // If no page is found, show the blank page.
597 //    this->Form->Stack->setCurrentWidget(this->Form->BlankPage);
598 //    }
599 //  else
600 //    {
601 //    this->Form->Stack->setCurrentWidget(*iter);
602 //    pqOptionsContainer *container = qobject_cast<pqOptionsContainer *>(*iter);
603 //    if(container)
604 //      {
605 //      // Get the path prefix from the container.
606 //      QString prefix = container->getPagePrefix();
607 //      if(!prefix.isEmpty())
608 //        {
609 //        // Remove the prefix from the path.
610 //        path.remove(0, prefix.length());
611 //        }
612 //
613 //      // Set the page on the container object.
614 //      container->setPage(path);
615 //      }
616 //    }
617 //}
618 //
619 ////-----------------------------------------------------------------------------
620 //void PVGUI_ParaViewSettingsPane::pluginLoaded(QObject* iface)
621 //{
622 //  pqViewOptionsInterface* viewOptions =
623 //    qobject_cast<pqViewOptionsInterface*>(iface);
624 //  if (viewOptions)
625 //    {
626 //    foreach(QString viewtype, viewOptions->viewTypes())
627 //      {
628 //      // Try to create global view options
629 //      pqOptionsContainer* globalOptions =
630 //        viewOptions->createGlobalViewOptions(viewtype, this);
631 //      if (globalOptions)
632 //        {
633 //        this->addOptions(globalOptions);
634 //        }
635 //      }
636 //    }
637 //}
638
639 void PVGUI_ParaViewSettingsPane::store(QtxResourceMgr* , QtxPreferenceMgr* )
640 {
641   applyChanges();
642 }
643
644 void PVGUI_ParaViewSettingsPane::retrieve(QtxResourceMgr* , QtxPreferenceMgr* )
645 {
646 }
647