Commit 02c5dfe2 authored by Emmanuel Promayon's avatar Emmanuel Promayon

FIXED code cleaning, double delete and crash at exit

parent 3938f439
......@@ -458,6 +458,7 @@ void camitk::ExtensionManager::unloadAllViewerExtensions() {
}
}
// -------------------- getViewerExtensionsList --------------------
const QList<ViewerExtension*> camitk::ExtensionManager::getViewerExtensionsList() {
QList< ViewerExtension* > sortedList = getViewerExtensionMap().values().toSet().toList(); // to remove duplicates
qSort(sortedList.begin(), sortedList.end(), ExtensionManager::viewerExtensionLessThan);
......@@ -465,6 +466,7 @@ const QList<ViewerExtension*> camitk::ExtensionManager::getViewerExtensionsList(
return sortedList;
}
// -------------------- getViewerExtension --------------------
ViewerExtension* camitk::ExtensionManager::getViewerExtension(QString file) {
return getViewerExtensionMap().value(file);
}
......@@ -473,18 +475,13 @@ ViewerExtension* camitk::ExtensionManager::getViewerExtension(QString file) {
bool ExtensionManager::unloadViewerExtension(QString fileName) {
if (getViewerExtensionMap().contains(fileName)) {
ViewerExtension* ext = getViewerExtensionMap().value(fileName);
//-- unregister all actions
foreach (Viewer* viewer, ext->getViewers()) {
getViewerExtensionMap().remove(viewer->getName());
}
//-- unregister extension
// unregister extension
getViewerExtensionMap().remove(fileName);
// -- unregister actions from application
// unregister actions from application
Application::unregisterAllViewers(ext);
//-- delete extensions (and all its actions)
// delete extensions (and all its actions)
delete ext;
return true;
}
else {
......@@ -572,11 +569,6 @@ bool ExtensionManager::unloadActionExtension(QString fileName) {
if (getActionExtensionMap().contains(fileName)) {
ActionExtension* ext = getActionExtensionMap().value(fileName);
//-- unregister all actions
foreach (Action* action, ext->getActions()) {
getActionExtensionMap().remove(action->getName());
}
//-- unregister extension
getActionExtensionMap().remove(fileName);
// -- unregister actions from application
......
......@@ -213,8 +213,9 @@ void Application::quitting() {
ExtensionManager::unloadAllActionExtensions();
ExtensionManager::unloadAllViewerExtensions();
if (translator) {
delete translator; //delete instance of internationalization support
if (translator != nullptr) {
// delete instance of internationalization support
delete translator;
}
}
......
......@@ -78,7 +78,7 @@ MainWindow::MainWindow(QString title) : QMainWindow() {
myProgressBar->setMaximum(100);
statusBarLayout->addWidget(myProgressBar, 0, 1, 1, 1, Qt::AlignVCenter | Qt::AlignRight);
statusBar()->addPermanentWidget(statusBarAdditionalWidget); // myProgressBar, 0);
statusBar()->addPermanentWidget(statusBarAdditionalWidget);
// create the console window
consoleWindow = new QDockWidget();
......@@ -181,6 +181,14 @@ MainWindow::MainWindow(QString title) : QMainWindow() {
MainWindow::~MainWindow() {
delete consoleWindow;
consoleWindow = nullptr;
// delete the dock widgets
// (the viewers should have been deleted and removed from the dock before hand
// otherwise it's a double delete)
auto dockList = dockWidgetMap.values();
while (!dockList.isEmpty()) {
delete dockList.takeFirst();
}
}
// ------------- getName -----------------
......
......@@ -90,15 +90,16 @@ InteractiveViewer::InteractiveViewer(QString& name, ViewerType type) : Viewer(na
// ---------------------- destructor ----------------------------
InteractiveViewer::~InteractiveViewer() {
delete viewerMenu;
viewerMenu = nullptr;
// do not delete the menu as it will be deleted automatically
// if it was inserted inside the application "View" for instance
delete viewerToolbar;
if (viewerToolbar != nullptr) {
delete viewerToolbar;
}
viewerToolbar = nullptr;
if (frame != nullptr)
delete frame;
frame = nullptr;
// do not delete the frame as it will automatically be deleted
// when the embedder widget will be deleted
}
// ---------------------- init ----------------------------
......@@ -2292,9 +2293,6 @@ void InteractiveViewer::createProperties() {
propertyObject->addProperty(pointSizeProperty);
// TODO BlockZOOM
// backface culling property
//backfaceCullingProperty = new Property("Backface culling", false, "Compute the non visible polygons and display them?", "");
//propertyObject->addProperty(backfaceCullingProperty);
}
// ---------------- eventFilter ----------------
......@@ -2375,3 +2373,4 @@ void InteractiveViewerFrame::keyPressEvent(QKeyEvent* e) {
#include "moc_InteractiveViewer.cpp"
}
......@@ -69,8 +69,11 @@ using vtkSmartPointerCamera = vtkSmartPointer<vtkCamera>;
class CAMITK_API InteractiveViewerFrame : public QFrame {
public:
/// default constructor
InteractiveViewerFrame(QWidget* parent, InteractiveViewer* s3D) : QFrame(parent), myInteractiveViewer(s3D) {}
InteractiveViewerFrame(QWidget* parent, InteractiveViewer* s3D) : QFrame(parent), myInteractiveViewer(s3D) {};
/// default constructor
~InteractiveViewerFrame() = default;
/// Handle keyboard events in the scene frame, just send everything to InteractiveViewer!
void keyPressEvent(QKeyEvent*) override;
......
......@@ -50,11 +50,14 @@ BitmapViewer::BitmapViewer(QString name) : InteractiveViewer(name, InteractiveVi
// can only display 2D bitmap = SingleImageComponent
setComponents(QStringList() << "SingleImageComponent");
myWidget = nullptr;
myToolbar = nullptr;
}
// -------------------- Destructor --------------------
BitmapViewer::~BitmapViewer() {
// do not delete myWidget as it will automatically be deleted
// when the embedder widget will be deleted
}
// -------------------- refresh --------------------
......@@ -65,9 +68,11 @@ void BitmapViewer::refresh(Viewer* whoIsAsking) {
// -------------------- getWidget --------------------
QWidget* BitmapViewer::getWidget() {
QWidget* myWidget = InteractiveViewer::getWidget();
// hide slice slider
sideFrame->hide();
if (myWidget == nullptr) {
myWidget = InteractiveViewer::getWidget();
// hide slice slider
sideFrame->hide();
}
updateVisibility();
return myWidget;
}
......
......@@ -42,7 +42,7 @@ class BITMAP_VIEWER_API BitmapViewer : public camitk::InteractiveViewer {
Q_OBJECT
public:
Q_INVOKABLE BitmapViewer(QString name);
Q_INVOKABLE BitmapViewer(QString name);
virtual ~BitmapViewer() override;
......@@ -53,12 +53,15 @@ public:
QToolBar* getToolBar() override;
private:
/// specific toolbar that show a screenshot + switch central viewer
QToolBar* myToolbar;
// set visibility of all possible component (that is component that can be displayed in 2D)
/// the bitmap viewer widget
QWidget* myWidget;
/// set visibility of all possible component (that is component that can be displayed in 2D)
void updateVisibility();
};
......
......@@ -56,7 +56,7 @@ public:
Q_INVOKABLE InteractiveGeometryViewer(QString name);
/** destructor */
~InteractiveGeometryViewer() = default;
virtual ~InteractiveGeometryViewer() = default;
};
......
......@@ -33,29 +33,29 @@
#include <ViewerExtension.h>
class INTERACTIVEGEOMETRYVIEWER_API InteractiveGeometryViewerExtension : public camitk::ViewerExtension {
Q_OBJECT
Q_INTERFACES(camitk::ViewerExtension);
Q_PLUGIN_METADATA(IID "fr.imag.camitk.interactivegeometryviewerextension.viewer.interactivegeometryviewerextension")
Q_OBJECT
Q_INTERFACES(camitk::ViewerExtension);
Q_PLUGIN_METADATA(IID "fr.imag.camitk.interactivegeometryviewerextension.viewer.interactivegeometryviewerextension")
public:
/// Constructor
InteractiveGeometryViewerExtension() : camitk::ViewerExtension() {};
/// Constructor
InteractiveGeometryViewerExtension() : camitk::ViewerExtension() {};
/// Destructor
virtual ~InteractiveGeometryViewerExtension() = default;
/// Destructor
virtual ~InteractiveGeometryViewerExtension() = default;
/// Method returning the action extension name
virtual QString getName() {
return "Interactive Geometry Viewer Extension";
};
/// Method returning the action extension name
virtual QString getName() {
return "Interactive Geometry Viewer Extension";
};
/// Method returning the action extension descrption
virtual QString getDescription() {
return "An extension for the interactive geometry viewer";
};
/// Method returning the action extension descrption
virtual QString getDescription() {
return "An extension for the interactive geometry viewer";
};
/// initialize all the actions
virtual void init();
/// initialize all the actions
virtual void init();
};
......
......@@ -57,12 +57,13 @@ MedicalImageViewer::MedicalImageViewer(QString name) : Viewer(name) {
// -------------------- Destructor --------------------
MedicalImageViewer::~MedicalImageViewer() {
if (viewerMenu) {
if (viewerMenu != nullptr) {
viewerMenu->clear();
delete viewerMenu;
}
delete frame;
// do not delete the frame as it will automatically be deleted
// when the embedder widget will be deleted
}
// -------------------- refresh --------------------
......
......@@ -33,29 +33,29 @@
#include <ViewerExtension.h>
class MEDICALIMAGEVIEWER_API MedicalImageViewerExtension : public camitk::ViewerExtension {
Q_OBJECT
Q_INTERFACES(camitk::ViewerExtension);
Q_PLUGIN_METADATA(IID "fr.imag.camitk.medicalimageviewerextension.viewer.medicalimageviewerextension")
Q_OBJECT
Q_INTERFACES(camitk::ViewerExtension);
Q_PLUGIN_METADATA(IID "fr.imag.camitk.medicalimageviewerextension.viewer.medicalimageviewerextension")
public:
/// Constructor
MedicalImageViewerExtension() : ViewerExtension() {};
/// Constructor
MedicalImageViewerExtension() : ViewerExtension() {};
/// Destructor
virtual ~MedicalImageViewerExtension() = default;
/// Destructor
virtual ~MedicalImageViewerExtension() = default;
/// Method returning the action extension name
virtual QString getName() {
return "Medical Image Viewer Extension";
};
/// Method returning the action extension name
virtual QString getName() {
return "Medical Image Viewer Extension";
};
/// Method returning the action extension descrption
virtual QString getDescription() {
return "An extension for the Medical Image Viewer";
};
/// Method returning the action extension descrption
virtual QString getDescription() {
return "An extension for the Medical Image Viewer";
};
/// initialize all the actions
virtual void init();
/// initialize all the actions
virtual void init();
};
......
......@@ -106,6 +106,13 @@ FancyMainWindow::~FancyMainWindow() {
delete mainWidget;
}
// ------------- destructor -----------------
void FancyMainWindow::closeEvent(QCloseEvent* event) {
// the current component is going to be closed, avoid dangling pointer
comp = nullptr;
MainWindow::closeEvent(event);
}
// ------------- updateComponent -----------------
void FancyMainWindow::updateComponent() {
// get the current state from the current selected component top level
......
......@@ -68,8 +68,13 @@ public slots:
void fancyFileOpen();
/// refresh everything!
virtual void refresh();
virtual void refresh() override;
protected:
/// overriden from MainWindow, just to unset the current comp and avoid crash
void closeEvent(QCloseEvent*) override;
private:
/// currently shown viewer
......
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