Commit ca1f4ae2 authored by Emmanuel Promayon's avatar Emmanuel Promayon

NEW MainWindow's central viewer is now a stack widget

This simplify the modification of the central viewer (for
instance to add a custom viewer easily to camitk-imp or
any other camitk::Application
parent d46cbc8e
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include <QUrl> #include <QUrl>
#include <QCloseEvent> #include <QCloseEvent>
#include <QMimeData> #include <QMimeData>
#include <QStackedWidget>
namespace camitk { namespace camitk {
// ------------- constructor ----------------- // ------------- constructor -----------------
...@@ -203,20 +204,6 @@ bool MainWindow::addViewer(Viewer* theViewer) { ...@@ -203,20 +204,6 @@ bool MainWindow::addViewer(Viewer* theViewer) {
// ------------- removeViewer ----------------- // ------------- removeViewer -----------------
bool MainWindow::removeViewer(Viewer* viewer) { bool MainWindow::removeViewer(Viewer* viewer) {
if (!viewers.contains(viewer)) {
return false;
}
// tell all component not to be visible anymore in this viewer
foreach (Component* comp, Application::getAllComponents()) {
comp->setVisibility(viewer, false);
}
// remove it properly
disconnect(viewer, SIGNAL(selectionChanged()), this, SLOT(refresh()));
viewers.removeAll(viewer);
delete viewer;
return true; return true;
} }
...@@ -260,14 +247,20 @@ void MainWindow::addDockViewer(Qt::DockWidgetArea dockingArea, Viewer* theViewer ...@@ -260,14 +247,20 @@ void MainWindow::addDockViewer(Qt::DockWidgetArea dockingArea, Viewer* theViewer
// ------------- setCentralViewer ----------------- // ------------- setCentralViewer -----------------
void MainWindow::setCentralViewer(Viewer* theViewer) { void MainWindow::setCentralViewer(Viewer* theViewer) {
if (theViewer->getWidget(this) && addViewer(theViewer)) { // get the viewer widget (must have something to show as it is a viewer after all!)
// remove actual central viewer properly QWidget *viewerWidget = theViewer->getWidget(this);
if (centralViewer && (theViewer != centralViewer)) { if (viewerWidget != nullptr) {
removeViewer(centralViewer); // add the viewer to the list (if not already in the list)
addViewer(theViewer);
// if needed, create the default (empty) central widget inside which the central viewers can be added
if (centralWidget()==0) {
setCentralWidget(new QStackedWidget(this));
} }
// set the central widget // add the widget to the central widget
setCentralWidget(theViewer->getWidget(this)); qobject_cast<QStackedWidget*>(centralWidget())->addWidget(viewerWidget);
qobject_cast<QStackedWidget*>(centralWidget())->setCurrentWidget(viewerWidget);
centralViewer = theViewer; centralViewer = theViewer;
} }
} }
......
...@@ -50,14 +50,20 @@ class Viewer; ...@@ -50,14 +50,20 @@ class Viewer;
* @ingroup group_sdk_libraries_core_application * @ingroup group_sdk_libraries_core_application
* *
* @brief * @brief
* This Class is the base class for your application. It sets up the main * This class is the base class for your application. It sets up the main
* window and providing a menubar, toolbar and statusbar (all hidden). * window and creates a menubar, toolbar and statusbar (all hidden by default).
*
* It is the default main window for a application. * It is the default main window for a application.
* *
* Create a class that inherits from MainWindow to * Create a class that inherits from MainWindow to
* get all the goodies of Core and add your own customization/UI. * get all the goodies of CamiTK and add your own customization/UI.
* See applications for examples. *
* See tutorials applications for examples.
* *
* The central widget is a QStackWidget: when new central viewers are added, the previous central
* viewer is hidden, not destroyed. See the "switchviewer" action tutorial for some example on
* how to embed an new central viewer to the imp main window (and switch back to medical image viewer
* whenever required).
*/ */
class CAMITK_API MainWindow : public QMainWindow { class CAMITK_API MainWindow : public QMainWindow {
Q_OBJECT Q_OBJECT
...@@ -184,13 +190,21 @@ protected: ...@@ -184,13 +190,21 @@ protected:
/// just call open with the dragged uri /// just call open with the dragged uri
void dropEvent(QDropEvent* event) override; void dropEvent(QDropEvent* event) override;
///@cond
/** /**
* TODO CAMITK_DEPRECATED. This section list all the methods marked as deprecated. They are to be removed in CamiTK 5.0
* @deprecated
* Removing viewers can be harmful. Central viewer is now simply hidden, therefore there is no need to remove it.
* It will keep itself refreshed and when shown again will be up to date.
* DEPRECATED (CamiTK 5.0) -> to be removed
*
* @brief Remove the given viewer from the list of viewer. * @brief Remove the given viewer from the list of viewer.
* @note This tell all Component not to be visible anymore in this viewer instance, remove it from the list of viewers and delete it. * @note This tell all Component not to be visible anymore in this viewer instance, remove it from the list of viewers and delete it.
* @param viewer The viewer to remove. * @param viewer The viewer to remove.
* @return True if removing succeeded, false otherwise. * @return True if removing succeeded, false otherwise.
*/ */
bool removeViewer(Viewer* viewer); bool removeViewer(Viewer* viewer);
///@endcond
/** /**
* @brief The actual central Viewer. * @brief The actual central Viewer.
...@@ -227,6 +241,7 @@ private: ...@@ -227,6 +241,7 @@ private:
/// the main part of the title /// the main part of the title
QString mainTitle; QString mainTitle;
}; };
} }
......
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