33 #include <QMessageBox> 35 #include <QStandardItem> 36 #include <QSortFilterProxyModel> 45 for (
auto keywordExtsIt = keywordExts.begin(); keywordExtsIt != keywordExts.end(); ++keywordExtsIt)
47 QString keywordId = (*keywordExtsIt)->GetAttribute(
"id");
48 QString keywordLabels = (*keywordExtsIt)->GetAttribute(
"label");
49 m_Keywords[keywordId].push_back(keywordLabels);
53 QStringList GetKeywords(
const QString&
id)
55 return m_Keywords[id];
58 QStringList GetKeywords(
const QStringList& ids)
61 for (
int i = 0; i < ids.size(); ++i)
63 result.append(this->GetKeywords(ids[i]));
69 QHash<QString, QStringList> m_Keywords;
73 class ClassFilterProxyModel :
public QSortFilterProxyModel
76 bool hasToBeDisplayed(
const QModelIndex index)
const;
77 bool displayElement(
const QModelIndex index)
const;
79 ClassFilterProxyModel(QObject *parent =
nullptr);
80 bool filterAcceptsRow(
int sourceRow,
const QModelIndex &sourceParent)
const override;
82 ClassFilterProxyModel::ClassFilterProxyModel(QObject *parent):
83 QSortFilterProxyModel(parent)
87 bool ClassFilterProxyModel::filterAcceptsRow(
int sourceRow,
88 const QModelIndex &sourceParent)
const 90 QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
92 return hasToBeDisplayed(index);
95 bool ClassFilterProxyModel::displayElement(
const QModelIndex index)
const 98 QString type = sourceModel()->data(index, Qt::DisplayRole).toString();
99 QStandardItem * item =
dynamic_cast<QStandardItemModel*
>(sourceModel())->itemFromIndex(index);
101 if (type.contains(filterRegExp()))
109 for (
int i = 0; i < viewItem->
m_Tags.size(); ++i)
111 if (viewItem->
m_Tags[i].contains(filterRegExp()))
126 for (
int i = 0; i < viewItem->
m_Tags.size(); ++i)
128 if (viewItem->
m_Tags[i].contains(filterRegExp()))
143 bool ClassFilterProxyModel::hasToBeDisplayed(
const QModelIndex index)
const 146 if ( sourceModel()->rowCount(index) > 0 )
148 for(
int ii = 0; ii < sourceModel()->rowCount(index); ii++)
150 QModelIndex childIndex = sourceModel()->index(ii,0,index);
151 if ( ! childIndex.isValid() )
153 result = hasToBeDisplayed(childIndex);
154 result |= displayElement(index);
163 result = displayElement(index);
177 Events::Types GetPerspectiveEventTypes()
const override 179 return Events::ACTIVATED | Events::SAVED_AS | Events::DEACTIVATED
181 | Events::CLOSED | Events::OPENED | Events::PART_CHANGED;
188 parentWidget->UpdateTreeList();
195 parentWidget->m_ActivePerspective = newPerspective;
196 parentWidget->UpdateTreeList();
202 parentWidget->m_ActivePerspective =
nullptr;
203 parentWidget->UpdateTreeList();
209 parentWidget->UpdateTreeList();
215 parentWidget->m_ActivePerspective =
nullptr;
216 parentWidget->UpdateTreeList();
219 using IPerspectiveListener::PerspectiveChanged;
225 if (changeId==
"viewHide" && partRef->GetId()==
"org.mitk.views.viewnavigatorview")
228 parentWidget->UpdateTreeList(
nullptr, partRef.
GetPointer(), changeId);
239 return a->GetLabel().compare(b->GetLabel()) < 0;
246 return a->GetLabel().compare(b->GetLabel()) < 0;
251 if (a==
nullptr || b==
nullptr)
253 return a->text().compare(b->text()) < 0;
257 QWidget * parent, Qt::WindowFlags )
284 connect(
m_Controls.m_PluginTreeView, SIGNAL(doubleClicked(
const QModelIndex&)), SLOT(
ItemClicked(
const QModelIndex&)));
288 m_Controls.m_PluginTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
313 for (
int i=0; i<root->rowCount(); i++)
315 QStandardItem* item = root->child(i);
317 if (dynamic_cast<mitk::QtPerspectiveItem*>(item))
324 pItem->setFont(font);
329 QList<berry::IViewPart::Pointer> viewParts(page->GetViews());
330 for (
int i=0; i<viewParts.size(); i++)
331 if(viewParts[i]->GetPartName()==vItem->
m_View->GetLabel())
337 if( partRef!=
nullptr && partRef->
GetId()==vItem->
m_View->GetId() && changeId==
"viewHide")
340 vItem->setFont(font);
363 QStandardItem *treeRootItem =
m_TreeModel->invisibleRootItem();
367 QList<berry::IPerspectiveDescriptor::Pointer> perspectiveDescriptors(perspRegistry->
GetPerspectives());
371 KeywordRegistry keywordRegistry;
376 std::vector< QStandardItem* > categoryItems;
377 QStandardItem *perspectiveRootItem =
new QStandardItem(
"Perspectives");
378 perspectiveRootItem->setEditable(
false);
379 perspectiveRootItem->setFont(QFont(
"", 12, QFont::Normal));
380 treeRootItem->appendRow(perspectiveRootItem);
382 for (
int i=0; i<perspectiveDescriptors.size(); i++)
400 QStringList keylist = p->GetKeywordReferences();
401 pItem->
m_Tags = keywordRegistry.GetKeywords(keylist);
402 pItem->setEditable(
false);
404 QFont font; font.setBold(
true);
405 if (currentPersp.
IsNotNull() && currentPersp->GetId()==p->GetId())
406 pItem->setFont(font);
408 QStringList catPath = p->GetCategoryPath();
409 if (catPath.isEmpty())
411 perspectiveRootItem->appendRow(pItem);
415 QStandardItem* categoryItem =
nullptr;
417 for (
unsigned int c=0; c<categoryItems.size(); c++)
419 if (categoryItems.at(c)->text() == catPath.front())
421 categoryItem = categoryItems.at(c);
426 if (categoryItem==
nullptr)
428 categoryItem =
new QStandardItem(QIcon(),catPath.front());
429 categoryItems.push_back(categoryItem);
431 categoryItem->setEditable(
false);
432 categoryItem->appendRow(pItem);
433 categoryItem->setFont(QFont(
"", 12, QFont::Normal));
437 for (
unsigned int i=0; i<categoryItems.size(); i++)
438 perspectiveRootItem->appendRow(categoryItems.at(i));
442 QList<berry::IViewDescriptor::Pointer> viewDescriptors(viewRegistry->
GetViews());
443 QList<berry::IViewPart::Pointer> viewParts(page->GetViews());
444 qSort(viewDescriptors.begin(), viewDescriptors.end(),
compareViews);
445 auto emptyItem =
new QStandardItem();
446 emptyItem->setFlags(Qt::ItemIsEnabled);
447 treeRootItem->appendRow(emptyItem);
451 QStringList viewExcludeList;
453 viewExcludeList.append(QString(
"org.blueberry.ui.internal.introview"));
454 viewExcludeList.append(QString(
"org.mitk.views.controlvisualizationpropertiesview"));
455 viewExcludeList.append(QString(
"org.mitk.views.modules"));
456 viewExcludeList.append(QString(
"org.mitk.views.viewnavigatorview"));
458 QStandardItem* viewRootItem =
new QStandardItem(QIcon(),
"Views");
459 viewRootItem->setFont(QFont(
"", 12, QFont::Normal));
460 viewRootItem->setEditable(
false);
461 treeRootItem->appendRow(viewRootItem);
463 categoryItems.clear();
464 QStandardItem* noCategoryItem =
new QStandardItem(QIcon(),
"Miscellaneous");
465 noCategoryItem->setEditable(
false);
466 noCategoryItem->setFont(QFont(
"", 12, QFont::Normal));
468 for (
int i = 0; i < viewDescriptors.size(); ++i)
471 bool skipView =
false;
472 for(
int e=0; e<viewExcludeList.size(); e++)
473 if(viewExcludeList.at(e)==v->GetId())
481 QStringList catPath = v->GetCategoryPath();
483 QIcon icon = v->GetImageDescriptor();
486 vItem->setToolTip(v->GetDescription());
489 QStringList keylist = v->GetKeywordReferences();
490 vItem->
m_Tags = keywordRegistry.GetKeywords(keylist);
491 vItem->setEditable(
false);
493 for (
int i=0; i<viewParts.size(); i++)
494 if(viewParts[i]->GetPartName()==v->GetLabel())
496 QFont font; font.setBold(
true);
497 vItem->setFont(font);
502 noCategoryItem->appendRow(vItem);
505 QStandardItem* categoryItem =
nullptr;
507 for (
unsigned int c=0; c<categoryItems.size(); c++)
508 if (categoryItems.at(c)->text() == catPath.front())
510 categoryItem = categoryItems.at(c);
514 if (categoryItem==
nullptr)
516 categoryItem =
new QStandardItem(QIcon(),catPath.front());
517 categoryItems.push_back(categoryItem);
519 categoryItem->setEditable(
false);
520 categoryItem->appendRow(vItem);
521 categoryItem->setFont(QFont(
"", 12, QFont::Normal));
526 for (
unsigned int i=0; i<categoryItems.size(); i++)
527 viewRootItem->appendRow(categoryItems.at(i));
528 if (noCategoryItem->hasChildren())
529 viewRootItem->appendRow(noCategoryItem);
538 QString filterString =
m_Controls.lineEdit->text();
545 Qt::CaseSensitivity caseSensitivity = Qt::CaseInsensitive;
546 QString strPattern =
"^*" + filterString;
547 QRegExp regExp(strPattern, caseSensitivity);
556 if ( dynamic_cast< mitk::QtPerspectiveItem* >(item) )
565 QMessageBox::critical(
nullptr,
"Opening Perspective Failed", QString(
"The requested perspective could not be opened.\nSee the log for details."));
568 else if ( dynamic_cast< mitk::QtViewItem* >(item) )
577 page->ShowView(vItem->
m_View->GetId());
579 catch (
const berry::PartInitException& e)
596 catch(
const berry::NotHandledException&)
598 catch(
const berry::CommandException& e)
606 if (QMessageBox::Yes == QMessageBox(QMessageBox::Question,
"Please confirm",
"Do you really want to reset the current perspective?", QMessageBox::Yes|QMessageBox::No).exec())
612 if (QMessageBox::Yes == QMessageBox(QMessageBox::Question,
"Please confirm",
"Do you really want to close the current perspective?", QMessageBox::Yes|QMessageBox::No).exec())
615 page->ClosePerspective(page->GetPerspective(),
true,
true);
627 if (QMessageBox::Yes == QMessageBox(QMessageBox::Question,
"Please confirm",
"Do you really want to close all perspectives?", QMessageBox::Yes|QMessageBox::No).exec())
630 page->CloseAllPerspectives(
true,
true);
649 QModelIndex index =
m_Controls.m_PluginTreeView->indexAt(pos);
657 QAction* expandAction =
new QAction(
"Expand tree",
this);
659 connect(expandAction, SIGNAL(triggered()), SLOT(
ExpandAll()));
661 QAction* collapseAction =
new QAction(
"Collapse tree",
this);
663 connect(collapseAction, SIGNAL(triggered()), SLOT(
CollapseAll()));
668 if ( item!=
nullptr && dynamic_cast< mitk::QtPerspectiveItem* >(item) )
675 QAction* saveAsAction =
new QAction(
"Save As...",
this);
682 QAction* resetAction =
new QAction(
"Reset current perspective",
this);
686 QAction* closeAction =
new QAction(
"Close perspective",
this);
692 QAction* closeAllAction =
new QAction(
"Close all perspectives",
this);
berry::IViewDescriptor::Pointer m_View
virtual IPerspectiveRegistry * GetPerspectiveRegistry() const =0
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 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
virtual IViewRegistry * GetViewRegistry() const =0
virtual SmartPointer< IWorkbenchPage > ShowPerspective(const QString &perspectiveId, IWorkbenchWindow::Pointer window)=0
ObjectType * GetPointer() const