Commit 04f20460 authored by Maxime Calka's avatar Maxime Calka

Add list of viewer in the explorer tree

parent 73f4b960
......@@ -92,6 +92,9 @@ using ComponentList = QList<Component*>;
/// A set of Action
using ActionSet = QSet<Action*>;
/// A set of Viewer
using ViewerSet = QSet<Viewer*>;
/// A list of Action
using ActionList = QList<Action*>;
......
......@@ -790,6 +790,12 @@ bool actionLessThan(const camitk::Action* a1, const camitk::Action* a2) {
return a1->getName() < a2->getName();
}
// ---------------- viewerLessThan ----------------
bool viewerLessThan(const camitk::Viewer* v1, const camitk::Viewer* v2) {
// This method is needed by qsort in the sort method to sort viewer by name
return v1->getName() < v2->getName();
}
// ---------------- sort ----------------
ActionList Application::sort(ActionSet actionSet) {
// sort actions by name
......@@ -799,6 +805,15 @@ ActionList Application::sort(ActionSet actionSet) {
return actionList;
}
ViewerList Application::sort(ViewerSet viewerSet)
{
// sort actions by name
ViewerList viewerList = viewerSet.toList();
qSort(viewerList.begin(), viewerList.end(), viewerLessThan);
return viewerList;
}
// ---------------- getAction ----------------
Action* Application::getAction(QString name) {
return getActionMap().value(name);
......@@ -875,6 +890,34 @@ const ViewerList Application::getViewers() {
return getViewerMap().values();
}
ViewerList Application::getViewers(Component *component)
{
ViewerSet viewers;
if (component) {
QStringList componentHierarchy = component->getHierarchy();
foreach(Viewer* currentViewer, Application::getViewers()) {
foreach(QString compType, currentViewer->getComponents()) {
if (componentHierarchy.contains(compType)) {
viewers.insert(currentViewer);
}
}
}
}
else {
foreach(Viewer* currentViewer, Application::getViewers()) {
foreach(QString compType, currentViewer->getComponents()) {
if (compType.isEmpty()) {
viewers.insert(currentViewer);
}
}
}
}
return sort(viewers);
}
// ---------- isAlive ----------
bool Application::isAlive(Component* comp) {
return getAllComponents().contains(comp);
......
......@@ -265,6 +265,9 @@ public:
/// get all the viewers registered in the application (note: the returned ViewerList is garanteed to be sorted by viewer name and to not contain any duplicate)
static const ViewerList getViewers();
/// get all the actions that can be applied on a given component (note: the returned ActionList is garanteed to be sorted by action name and to contain no duplicates)
static ViewerList getViewers(Component*);
/** register all viewers from the given ViewerExtension
* @return the number of viewers effectively registered (in case a viewer's name is already registered by another viewer extension, it won't be registered a second time)
*/
......@@ -509,6 +512,8 @@ private:
/// sort an ActionSet by action's name
static ActionList sort(ActionSet);
static ViewerList sort(ViewerSet);
///@}
/// @name viewer management
......
......@@ -373,12 +373,21 @@ QMenu* Component::getActionMenu() {
}
}
ViewerList viewerList = Application::getViewers(this);
if (viewerList.size() > 0) {
QMenu* familyMenu = actionsMenu->addMenu(QString("Viewers"));
foreach(Viewer* viewer, viewerList) {
familyMenu->addAction(viewer->getQAction());
}
}
// no menu if no action
if (actionsMenu->actions().size() == 0) {
delete actionsMenu;
actionsMenu = nullptr;
}
}
return actionsMenu;
}
......
......@@ -27,6 +27,8 @@
#include "ViewerExtension.h"
#include "Component.h"
#include "Application.h"
#include "MainWindow.h"
#include "MedicalImageViewer.h"
namespace camitk {
......@@ -35,6 +37,8 @@ Viewer::Viewer(QString name): QObject() {
this->name = name;
setObjectName(name);
toolbarVisibility = true;
qAction = nullptr;
components << "" ;
}
//---------------------- selectionChanged ------------------------
......@@ -43,7 +47,6 @@ void Viewer::selectionChanged(camitk::ComponentList& compSet) {
comp->setSelected(true);
}
emit selectionChanged();
}
void Viewer::selectionChanged(Component* comp) {
......@@ -67,4 +70,37 @@ bool Viewer::getToolBarVisibility() {
return toolbarVisibility;
}
QAction* Viewer::getQAction() {
if (!qAction) {
// create the corresponding QAction (using the icon, name and descriptions)
qAction = new QAction(getIcon(), getName(), this);
qAction->setStatusTip(getDescription());
qAction->setWhatsThis(getName() + "\n" + getDescription());
// connect it to the trigger slot
connect(qAction, SIGNAL(triggered()), this, SLOT(switchCentralViewer()));
}
return qAction;
}
// -------------------- setIcon --------------------
void Viewer::setIcon(QPixmap icon) {
this->icon = icon;
}
// -------------------- getIcon --------------------
QPixmap Viewer::getIcon() {
return icon;
}
void Viewer::setComponents(QStringList components)
{
this->components = components;
}
QStringList Viewer::getComponents()
{
return components;
}
}
\ No newline at end of file
......@@ -31,10 +31,14 @@
// -- QT stuff
#include <QObject>
#include <QSet>
#include <QPixMap>
// -- QT stuff classes
class QToolBar;
class QMenu;
class QAction;
class QPixMap;
namespace camitk {
class Component;
......@@ -105,16 +109,28 @@ public:
/// get the current value of the toolbar visibility
bool getToolBarVisibility();
QAction* getQAction();
virtual QPixmap getIcon();
/// Update the whole tree of the representation of the Component.
/// Is actually useful (and defined) in Explorer.
virtual void refreshInterfaceNode(Component* comp) {};
QStringList getComponents();
signals:
/// this signal is emitted when the current selection was changed by the viewer
void selectionChanged();
public slots:
virtual void switchCentralViewer() {
return;
};
protected:
/** The selection has changed to the given ComponentList.
......@@ -129,6 +145,10 @@ protected:
/// clear the selection
void clearSelection();
void setIcon(QPixmap icon);
void setComponents(QStringList);
private:
QString name;
......@@ -137,6 +157,13 @@ private:
ViewerExtension* extension;
QAction* qAction;
/// the Viewer pixmap icon
QPixmap icon;
QStringList components;
/// the current toolbar visibility
bool toolbarVisibility;
};
......
......@@ -49,6 +49,7 @@ TextViewer::TextViewer() : Viewer(viewerName) {
myWidget = nullptr;
isVisible = false;
displayedTopLevelComponents = 0;
setComponents(QStringList() << "ImageComponent");
}
// -------------------- getInstance --------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment