1 // PARAVIS : ParaView wrapper SALOME module
3 // Copyright (C) 2010-2014 CEA/DEN, EDF R&D
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.
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.
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
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : PVGUI_ParaViewSettingsPane.cxx
22 // Author : Vitaly Smetannikov
25 #include "PVGUI_ParaViewSettingsPane.h"
26 #include "ui_pqOptionsDialog.h"
28 #include <pqApplicationSettingsReaction.h>
33 //class OptionsDialogModelItem
36 // OptionsDialogModelItem();
37 // OptionsDialogModelItem(const QString &name);
38 // ~OptionsDialogModelItem();
40 // OptionsDialogModelItem *Parent;
42 // QList<OptionsDialogModelItem *> Children;
46 //class OptionsDialogModel : public QAbstractItemModel
49 // OptionsDialogModel(QObject *parent=0);
50 // virtual ~OptionsDialogModel();
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;
58 // virtual QVariant data(const QModelIndex &index,
59 // int role=Qt::DisplayRole) const;
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);
67 // QModelIndex getIndex(OptionsDialogModelItem *item) const;
70 // OptionsDialogModelItem *Root;
74 class OptionsDialogForm : public Ui::PVGUIOptionsFrame
80 // QMap<QString, pqOptionsPage *> Pages;
81 // OptionsDialogModel *Model;
87 //----------------------------------------------------------------------------
88 //OptionsDialogModelItem::OptionsDialogModelItem()
89 // : Name(), Children()
94 //OptionsDialogModelItem::OptionsDialogModelItem(const QString &name)
95 // : Name(name), Children()
100 //OptionsDialogModelItem::~OptionsDialogModelItem()
102 // QList<OptionsDialogModelItem *>::Iterator iter = this->Children.begin();
103 // for( ; iter != this->Children.end(); ++iter)
110 //----------------------------------------------------------------------------
111 //OptionsDialogModel::OptionsDialogModel(QObject *parentObject)
112 // : QAbstractItemModel(parentObject)
114 // this->Root = new OptionsDialogModelItem();
117 //OptionsDialogModel::~OptionsDialogModel()
119 // delete this->Root;
122 //int OptionsDialogModel::rowCount(const QModelIndex &parentIndex) const
124 // OptionsDialogModelItem *item = this->Root;
125 // if(parentIndex.isValid())
127 // item = reinterpret_cast<OptionsDialogModelItem *>(
128 // parentIndex.internalPointer());
131 // return item->Children.size();
134 //int OptionsDialogModel::columnCount(const QModelIndex &) const
139 //QModelIndex OptionsDialogModel::index(int row, int column,
140 // const QModelIndex &parentIndex) const
142 // OptionsDialogModelItem *item = this->Root;
143 // if(parentIndex.isValid())
145 // item = reinterpret_cast<OptionsDialogModelItem *>(
146 // parentIndex.internalPointer());
149 // if(column == 0 && row >= 0 && row < item->Children.size())
151 // return this->createIndex(row, column, item->Children[row]);
154 // return QModelIndex();
157 //QModelIndex OptionsDialogModel::parent(const QModelIndex &child) const
159 // if(child.isValid())
161 // OptionsDialogModelItem *item =
162 // reinterpret_cast<OptionsDialogModelItem *>(child.internalPointer());
163 // return this->getIndex(item->Parent);
166 // return QModelIndex();
169 //QVariant OptionsDialogModel::data(const QModelIndex &idx, int role) const
173 // OptionsDialogModelItem *item =
174 // reinterpret_cast<OptionsDialogModelItem *>(idx.internalPointer());
175 // if(role == Qt::DisplayRole || role == Qt::ToolTipRole)
177 // return QVariant(item->Name);
181 // return QVariant();
184 //QModelIndex OptionsDialogModel::getIndex(const QString &path) const
186 // OptionsDialogModelItem *item = this->Root;
187 // QStringList names = path.split(".");
188 // QStringList::Iterator iter = names.begin();
189 // for( ; item && iter != names.end(); ++iter)
191 // OptionsDialogModelItem *child = 0;
192 // QList<OptionsDialogModelItem *>::Iterator jter = item->Children.begin();
193 // for( ; jter != item->Children.end(); ++jter)
195 // if((*jter)->Name == *iter)
205 // if(item && item != this->Root)
207 // return this->getIndex(item);
210 // return QModelIndex();
213 //QString OptionsDialogModel::getPath(const QModelIndex &idx) const
218 // OptionsDialogModelItem *item =
219 // reinterpret_cast<OptionsDialogModelItem *>(idx.internalPointer());
222 // path = item->Name;
223 // item = item->Parent;
226 // while(item && item != this->Root)
228 // path.prepend(".").prepend(item->Name);
229 // item = item->Parent;
238 //void OptionsDialogModel::addPath(const QString &path)
240 // OptionsDialogModelItem *item = this->Root;
241 // QStringList names = path.split(".");
242 // QStringList::Iterator iter = names.begin();
243 // for( ; iter != names.end(); ++iter)
245 // OptionsDialogModelItem *child = 0;
246 // QList<OptionsDialogModelItem *>::Iterator jter = item->Children.begin();
247 // for( ; jter != item->Children.end(); ++jter)
249 // if((*jter)->Name == *iter)
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();
271 //bool OptionsDialogModel::removeIndex(const QModelIndex &idx)
275 // OptionsDialogModelItem *item =
276 // reinterpret_cast<OptionsDialogModelItem *>(idx.internalPointer());
277 // if(item->Children.size() == 0)
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();
291 //QModelIndex OptionsDialogModel::getIndex(
292 // OptionsDialogModelItem *item) const
294 // if(item && item->Parent)
296 // return this->createIndex(item->Parent->Children.indexOf(item), 0, item);
299 // return QModelIndex();
303 //----------------------------------------------------------------------------
304 OptionsDialogForm::OptionsDialogForm()
305 : Ui::PVGUIOptionsFrame()
307 // this->Model = new OptionsDialogModel();
308 // this->ApplyUseCount = 0;
309 // //this->ApplyNeeded = false;
312 OptionsDialogForm::~OptionsDialogForm()
314 // delete this->Model;
318 //----------------------------------------------------------------------------
319 PVGUI_ParaViewSettingsPane::PVGUI_ParaViewSettingsPane(QWidget *widgetParent)
320 : QtxUserDefinedContent(widgetParent)
322 Form = new OptionsDialogForm();
325 // Connect the button to the standard ParaView 4.2 setting reaction for now:
326 connect(Form->pvButton, SIGNAL(clicked()),
327 this, SLOT(onRequestParaviewSettings()));
330 //// this->Form->PageNames->setModel(this->Form->Model);
332 // // Hide the tree widget header view.
333 // this->Form->PageNames->header()->hide();
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();
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()));
351 // // Code From pqApplicationOptionsDialog
352 // //this->setApplyNeeded(true);
354 // pqApplicationOptions* appOptions = new pqApplicationOptions;
355 // this->addOptions(appOptions);
357 // pqGlobalRenderViewOptions* renOptions = new pqGlobalRenderViewOptions;
358 // this->addOptions(renOptions);
360 // QStringList pages = appOptions->getPageList();
363 // this->setCurrentPage(pages[0]);
366 // /// Add panes as plugins are loaded.
367 // QObject::connect(pqApplicationCore::instance()->getPluginManager(),
368 // SIGNAL(guiInterfaceLoaded(QObject*)),
369 // this, SLOT(pluginLoaded(QObject*)));
371 // // Load panes from already loaded plugins.
372 // foreach (QObject* plugin_interface, pqApplicationCore::instance()->interfaceTracker()->interfaces())
373 // //pqApplicationCore::instance()->getPluginManager()->interfaces())
375 // this->pluginLoaded(plugin_interface);
379 PVGUI_ParaViewSettingsPane::~PVGUI_ParaViewSettingsPane()
384 void PVGUI_ParaViewSettingsPane::onRequestParaviewSettings()
386 pqApplicationSettingsReaction::showApplicationSettingsDialog();
390 bool PVGUI_ParaViewSettingsPane::isApplyNeeded() const
392 return this->Form->ApplyNeeded;
396 void PVGUI_ParaViewSettingsPane::setApplyNeeded(bool applyNeeded)
398 if(applyNeeded != this->Form->ApplyNeeded)
402 this->Form->ApplyNeeded = false;
403 //this->Form->ApplyButton->setEnabled(false);
404 //this->Form->ResetButton->setEnabled(false);
406 else if(this->Form->ApplyUseCount > 0)
408 this->Form->ApplyNeeded = true;
409 //this->Form->ApplyButton->setEnabled(true);
410 //this->Form->ResetButton->setEnabled(true);
415 //void PVGUI_ParaViewSettingsPane::addOptions(const QString &path, pqOptionsPage *options)
422 // // See if the page is a container.
423 // pqOptionsContainer *container = qobject_cast<pqOptionsContainer *>(options);
424 // if(!container && path.isEmpty())
429 // // See if the page/container uses the apply button.
430 // if(options->isApplyUsed())
432 // this->Form->ApplyUseCount++;
433 // /*if(this->Form->ApplyUseCount == 1)
435 // //this->Form->ApplyButton->show();
436 // //this->Form->ResetButton->show();
437 // //QObject::connect(this, SIGNAL(accepted()), this, SLOT(applyChanges()));
440 // //this->connect(options, SIGNAL(changesAvailable()),
441 // //this, SLOT(enableButtons()));
444 // // Add the widget to the stack.
445 // this->Form->Stack->addWidget(options);
447 // // Add the page(s) to the map and the model.
450 // // If the path is not empty, use it as the page prefix.
452 // if(!path.isEmpty())
455 // prefix.append(".");
458 // container->setPagePrefix(prefix);
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)
465 // this->Form->Pages.insert(prefix + *iter, options);
466 // this->Form->Model->addPath(prefix + *iter);
471 // this->Form->Pages.insert(path, options);
472 // this->Form->Model->addPath(path);
476 //void PVGUI_ParaViewSettingsPane::addOptions(pqOptionsContainer *options)
478 // this->addOptions(QString(), options);
481 //void PVGUI_ParaViewSettingsPane::removeOptions(pqOptionsPage *options)
488 // // Remove the widget from the stack.
489 // this->Form->Stack->removeWidget(options);
491 // // See if the options use the apply button.
492 // if(options->isApplyUsed())
494 // this->Form->ApplyUseCount--;
495 // /*if(this->Form->ApplyUseCount == 0)
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()));
505 // this->disconnect(options, 0, this, 0);
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())
512 // if(*iter == options)
514 // QString path = iter.key();
515 // iter = this->Form->Pages.erase(iter);
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))
522 // // Remove any empty parent items.
523 // while(parentIndex.isValid() &&
524 // this->Form->Model->rowCount(parentIndex) == 0)
526 // index = parentIndex;
527 // parentIndex = index.parent();
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())
533 // if(!this->Form->Model->removeIndex(index))
548 //void PVGUI_ParaViewSettingsPane::setCurrentPage(const QString &path)
550 // QModelIndex current = this->Form->Model->getIndex(path);
551 // this->Form->PageNames->setCurrentIndex(current);
554 void PVGUI_ParaViewSettingsPane::applyChanges()
556 //if(this->Form->ApplyNeeded)
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)
563 // (*iter)->applyChanges();
566 // //this->setApplyNeeded(false);
567 // emit this->appliedChanges();
572 void PVGUI_ParaViewSettingsPane::resetChanges()
574 //if(this->Form->ApplyNeeded)
576 // QMap<QString, pqOptionsPage *>::Iterator iter = this->Form->Pages.begin();
577 // for( ; iter != this->Form->Pages.end(); ++iter)
579 // (*iter)->resetChanges();
582 //this->setApplyNeeded(false);
586 //void PVGUI_ParaViewSettingsPane::changeCurrentPage()
588 // // Get the current index from the view.
589 // QModelIndex current = this->Form->PageNames->currentIndex();
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())
596 // // If no page is found, show the blank page.
597 // this->Form->Stack->setCurrentWidget(this->Form->BlankPage);
601 // this->Form->Stack->setCurrentWidget(*iter);
602 // pqOptionsContainer *container = qobject_cast<pqOptionsContainer *>(*iter);
605 // // Get the path prefix from the container.
606 // QString prefix = container->getPagePrefix();
607 // if(!prefix.isEmpty())
609 // // Remove the prefix from the path.
610 // path.remove(0, prefix.length());
613 // // Set the page on the container object.
614 // container->setPage(path);
619 ////-----------------------------------------------------------------------------
620 //void PVGUI_ParaViewSettingsPane::pluginLoaded(QObject* iface)
622 // pqViewOptionsInterface* viewOptions =
623 // qobject_cast<pqViewOptionsInterface*>(iface);
626 // foreach(QString viewtype, viewOptions->viewTypes())
628 // // Try to create global view options
629 // pqOptionsContainer* globalOptions =
630 // viewOptions->createGlobalViewOptions(viewtype, this);
631 // if (globalOptions)
633 // this->addOptions(globalOptions);
639 void PVGUI_ParaViewSettingsPane::store(QtxResourceMgr* , QtxPreferenceMgr* )
644 void PVGUI_ParaViewSettingsPane::retrieve(QtxResourceMgr* , QtxPreferenceMgr* )