37 #include <QMessageBox>
39 #include <QStandardItem>
40 #include <QSortFilterProxyModel>
49 for (
auto keywordExtsIt = keywordExts.begin(); keywordExtsIt != keywordExts.end(); ++keywordExtsIt)
51 QString keywordId = (*keywordExtsIt)->GetAttribute(
"id");
52 QString keywordLabels = (*keywordExtsIt)->GetAttribute(
"label");
53 m_Keywords[keywordId].push_back(keywordLabels);
57 QStringList GetKeywords(
const QString&
id)
59 return m_Keywords[id];
62 QStringList GetKeywords(
const QStringList& ids)
65 for (
int i = 0; i < ids.size(); ++i)
67 result.append(this->GetKeywords(ids[i]));
73 QHash<QString, QStringList> m_Keywords;
77 class ClassFilterProxyModel :
public QSortFilterProxyModel
80 bool hasToBeDisplayed(
const QModelIndex index)
const;
81 bool displayElement(
const QModelIndex index)
const;
83 ClassFilterProxyModel(QObject *parent =
nullptr);
84 bool filterAcceptsRow(
int sourceRow,
const QModelIndex &sourceParent)
const override;
86 ClassFilterProxyModel::ClassFilterProxyModel(QObject *parent):
87 QSortFilterProxyModel(parent)
91 bool ClassFilterProxyModel::filterAcceptsRow(
int sourceRow,
92 const QModelIndex &sourceParent)
const
94 QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
96 return hasToBeDisplayed(index);
99 bool ClassFilterProxyModel::displayElement(
const QModelIndex index)
const
102 QString type = sourceModel()->data(index, Qt::DisplayRole).toString();
103 QStandardItem * item =
dynamic_cast<QStandardItemModel*
>(sourceModel())->itemFromIndex(index);
105 if (type.contains(filterRegExp()))
113 for (
int i = 0; i < viewItem->
m_Tags.size(); ++i)
115 if (viewItem->
m_Tags[i].contains(filterRegExp()))
130 for (
int i = 0; i < viewItem->
m_Tags.size(); ++i)
132 if (viewItem->
m_Tags[i].contains(filterRegExp()))
147 bool ClassFilterProxyModel::hasToBeDisplayed(
const QModelIndex index)
const
150 if ( sourceModel()->rowCount(index) > 0 )
152 for(
int ii = 0; ii < sourceModel()->rowCount(index); ii++)
154 QModelIndex childIndex = sourceModel()->index(ii,0,index);
155 if ( ! childIndex.isValid() )
157 result = hasToBeDisplayed(childIndex);
158 result |= displayElement(index);
167 result = displayElement(index);
192 parentWidget->UpdateTreeList();
199 parentWidget->m_ActivePerspective = newPerspective;
200 parentWidget->UpdateTreeList();
206 parentWidget->m_ActivePerspective =
nullptr;
207 parentWidget->UpdateTreeList();
213 parentWidget->UpdateTreeList();
219 parentWidget->m_ActivePerspective =
nullptr;
220 parentWidget->UpdateTreeList();
229 if (changeId==
"viewHide" && partRef->GetId()==
"org.mitk.views.viewnavigatorview")
232 parentWidget->UpdateTreeList(
nullptr, partRef.
GetPointer(), changeId);
243 return a->GetLabel().compare(b->GetLabel()) < 0;
250 return a->GetLabel().compare(b->GetLabel()) < 0;
255 if (a==
nullptr || b==
nullptr)
257 return a->text().compare(b->text()) < 0;
261 QWidget * parent, Qt::WindowFlags )
288 connect(
m_Controls.m_PluginTreeView, SIGNAL(doubleClicked(
const QModelIndex&)), SLOT(
ItemClicked(
const QModelIndex&)));
292 m_Controls.m_PluginTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
317 for (
int i=0; i<root->rowCount(); i++)
319 QStandardItem* item = root->child(i);
321 if (dynamic_cast<mitk::QtPerspectiveItem*>(item))
328 pItem->setFont(font);
333 QList<berry::IViewPart::Pointer> viewParts(page->GetViews());
334 for (
int i=0; i<viewParts.size(); i++)
335 if(viewParts[i]->GetPartName()==vItem->
m_View->GetLabel())
341 if( partRef!=
nullptr && partRef->
GetId()==vItem->
m_View->GetId() && changeId==
"viewHide")
344 vItem->setFont(font);
367 QStandardItem *treeRootItem =
m_TreeModel->invisibleRootItem();
371 QList<berry::IPerspectiveDescriptor::Pointer> perspectiveDescriptors(perspRegistry->
GetPerspectives());
375 KeywordRegistry keywordRegistry;
380 std::vector< QStandardItem* > categoryItems;
381 QStandardItem *perspectiveRootItem =
new QStandardItem(
"Workflows");
382 perspectiveRootItem->setEditable(
false);
383 perspectiveRootItem->setFont(QFont(
"", 12, QFont::Normal));
384 treeRootItem->appendRow(perspectiveRootItem);
386 for (
int i=0; i<perspectiveDescriptors.size(); i++)
404 QStringList keylist = p->GetKeywordReferences();
405 pItem->
m_Tags = keywordRegistry.GetKeywords(keylist);
406 pItem->setEditable(
false);
408 QFont font; font.setBold(
true);
409 if (currentPersp.
IsNotNull() && currentPersp->GetId()==p->GetId())
410 pItem->setFont(font);
412 QStringList catPath = p->GetCategoryPath();
413 if (catPath.isEmpty())
415 perspectiveRootItem->appendRow(pItem);
419 QStandardItem* categoryItem =
nullptr;
421 for (
unsigned int c=0; c<categoryItems.size(); c++)
423 if (categoryItems.at(c)->text() == catPath.front())
425 categoryItem = categoryItems.at(c);
430 if (categoryItem==
nullptr)
432 categoryItem =
new QStandardItem(QIcon(),catPath.front());
433 categoryItems.push_back(categoryItem);
435 categoryItem->setEditable(
false);
436 categoryItem->appendRow(pItem);
437 categoryItem->setFont(QFont(
"", 12, QFont::Normal));
441 for (
unsigned int i=0; i<categoryItems.size(); i++)
442 perspectiveRootItem->appendRow(categoryItems.at(i));
446 QList<berry::IViewDescriptor::Pointer> viewDescriptors(viewRegistry->
GetViews());
447 QList<berry::IViewPart::Pointer> viewParts(page->GetViews());
448 qSort(viewDescriptors.begin(), viewDescriptors.end(),
compareViews);
449 auto emptyItem =
new QStandardItem();
450 emptyItem->setFlags(Qt::ItemIsEnabled);
451 treeRootItem->appendRow(emptyItem);
455 QStringList viewExcludeList;
457 viewExcludeList.append(QString(
"org.blueberry.ui.internal.introview"));
459 QStandardItem* viewRootItem =
new QStandardItem(QIcon(),
"Views");
460 viewRootItem->setFont(QFont(
"", 12, QFont::Normal));
461 viewRootItem->setEditable(
false);
462 treeRootItem->appendRow(viewRootItem);
464 categoryItems.clear();
465 QStandardItem* noCategoryItem =
new QStandardItem(QIcon(),
"Miscellaneous");
466 noCategoryItem->setEditable(
false);
467 noCategoryItem->setFont(QFont(
"", 12, QFont::Normal));
469 for (
int i = 0; i < viewDescriptors.size(); ++i)
472 bool skipView =
false;
473 for(
int e=0; e<viewExcludeList.size(); e++)
474 if(viewExcludeList.at(e)==v->GetId())
482 QStringList catPath = v->GetCategoryPath();
484 QIcon icon = v->GetImageDescriptor();
487 vItem->setToolTip(v->GetDescription());
490 QStringList keylist = v->GetKeywordReferences();
491 vItem->
m_Tags = keywordRegistry.GetKeywords(keylist);
492 vItem->setEditable(
false);
494 for (
int i=0; i<viewParts.size(); i++)
495 if(viewParts[i]->GetPartName()==v->GetLabel())
497 QFont font; font.setBold(
true);
498 vItem->setFont(font);
503 noCategoryItem->appendRow(vItem);
506 QStandardItem* categoryItem =
nullptr;
508 for (
unsigned int c=0; c<categoryItems.size(); c++)
509 if (categoryItems.at(c)->text() == catPath.front())
511 categoryItem = categoryItems.at(c);
515 if (categoryItem==
nullptr)
517 categoryItem =
new QStandardItem(QIcon(),catPath.front());
518 categoryItems.push_back(categoryItem);
520 categoryItem->setEditable(
false);
521 categoryItem->appendRow(vItem);
522 categoryItem->setFont(QFont(
"", 12, QFont::Normal));
527 for (
unsigned int i=0; i<categoryItems.size(); i++)
528 viewRootItem->appendRow(categoryItems.at(i));
529 if (noCategoryItem->hasChildren())
530 viewRootItem->appendRow(noCategoryItem);
539 QString filterString =
m_Controls.lineEdit->text();
546 Qt::CaseSensitivity caseSensitivity = Qt::CaseInsensitive;
547 QString strPattern =
"^*" + filterString;
548 QRegExp regExp(strPattern, caseSensitivity);
557 if ( dynamic_cast< mitk::QtPerspectiveItem* >(item) )
566 QMessageBox::critical(
nullptr,
"Opening Perspective Failed", QString(
"The requested perspective could not be opened.\nSee the log for details."));
569 else if ( dynamic_cast< mitk::QtViewItem* >(item) )
578 page->ShowView(vItem->
m_View->GetId());
580 catch (berry::PartInitException e)
597 catch(
const berry::NotHandledException)
599 catch(
const berry::CommandException& e)
607 if (QMessageBox::Yes == QMessageBox(QMessageBox::Question,
"Please confirm",
"Do you really want to reset the current perspective?", QMessageBox::Yes|QMessageBox::No).exec())
613 if (QMessageBox::Yes == QMessageBox(QMessageBox::Question,
"Please confirm",
"Do you really want to close the current perspective?", QMessageBox::Yes|QMessageBox::No).exec())
616 page->ClosePerspective(page->GetPerspective(),
true,
true);
628 if (QMessageBox::Yes == QMessageBox(QMessageBox::Question,
"Please confirm",
"Do you really want to close all perspectives?", QMessageBox::Yes|QMessageBox::No).exec())
631 page->CloseAllPerspectives(
true,
true);
650 QModelIndex index =
m_Controls.m_PluginTreeView->indexAt(pos);
658 QAction* expandAction =
new QAction(
"Expand tree",
this);
660 connect(expandAction, SIGNAL(triggered()), SLOT(
ExpandAll()));
662 QAction* collapseAction =
new QAction(
"Collapse tree",
this);
664 connect(collapseAction, SIGNAL(triggered()), SLOT(
CollapseAll()));
669 if ( item!=
nullptr && dynamic_cast< mitk::QtPerspectiveItem* >(item) )
676 QAction* saveAsAction =
new QAction(
"Save As...",
this);
683 QAction* resetAction =
new QAction(
"Reset current perspective",
this);
687 QAction* closeAction =
new QAction(
"Close perspective",
this);
693 QAction* closeAllAction =
new QAction(
"Close all perspectives",
this);
berry::IViewDescriptor::Pointer m_View
virtual IPerspectiveRegistry * GetPerspectiveRegistry() const =0
virtual void PerspectiveActivated(const SmartPointer< IWorkbenchPage > &page, const IPerspectiveDescriptor::Pointer &perspective)
virtual void PerspectiveOpened(const SmartPointer< IWorkbenchPage > &page, const IPerspectiveDescriptor::Pointer &perspective)
virtual QString GetId() const =0
virtual void RemoveWindowListener(IWindowListener *listener)=0
static const QString WINDOW_SAVE_PERSPECTIVE_AS
virtual QList< IPerspectiveDescriptor::Pointer > GetPerspectives()=0
virtual Object::Pointer ExecuteCommand(const QString &commandId, const SmartPointer< const UIElement > &uielement)=0
berry::IPerspectiveDescriptor::Pointer m_Perspective
virtual void PerspectiveClosed(const SmartPointer< IWorkbenchPage > &page, const IPerspectiveDescriptor::Pointer &perspective)
virtual Events::Types GetPerspectiveEventTypes() const =0
virtual QList< IViewDescriptor::Pointer > GetViews() const =0
virtual QList< SmartPointer< IConfigurationElement > > GetConfigurationElementsFor(const QString &extensionPointId) const =0
virtual IWorkbenchWindow::Pointer GetActiveWorkbenchWindow() const =0
The custom viewer plugin implements simple viewer functionality presented in a customized look and feel It was developed to demonstrate extensibility and customizability of the blueberry application framework As an example for the GUI customization capabilities provided by the BlueBerry application the custom viewer plugin was developed It features simple viewer functionality presented in a customized look and feel The custom viewer consists of two i e a viewer perspective and a DICOM perspective As part of the viewer perspective
ObjectType * GetPointer() const
virtual IViewRegistry * GetViewRegistry() const =0
virtual void PerspectiveSavedAs(const SmartPointer< IWorkbenchPage > &page, const IPerspectiveDescriptor::Pointer &oldPerspective, const IPerspectiveDescriptor::Pointer &newPerspective)
virtual SmartPointer< IWorkbenchPage > ShowPerspective(const QString &perspectiveId, IWorkbenchWindow::Pointer window)=0
virtual void PerspectiveChanged(const SmartPointer< IWorkbenchPage > &page, const IPerspectiveDescriptor::Pointer &perspective, const QString &changeId)
virtual void PerspectiveDeactivated(const SmartPointer< IWorkbenchPage > &page, const IPerspectiveDescriptor::Pointer &perspective)