Skip to content

Commit

Permalink
Close action implemented, free memory when closed
Browse files Browse the repository at this point in the history
The close button now closes the main ImageView window and
all objects created in the main are disposed of when the
window is closed.
refs #5058
  • Loading branch information
DennisMikkelson committed Apr 29, 2012
1 parent 738f0eb commit 8556752
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QActionGroup>

#include "ui_ImageView.h"
#include "MantidQtImageViewer/ImageView.h"
#include "MantidQtImageViewer/TrackingPicker.h"
#include "MantidQtImageViewer/ImageDisplay.h"
#include "MantidQtImageViewer/GraphDisplay.h"
Expand Down Expand Up @@ -60,13 +61,15 @@ class EXPORT_OPT_MANTIDQT_IMAGEVIEWER IVConnections: public QWidget
/// Construct the object that links the GUI components to the other specifed
/// higher level objects.
IVConnections( Ui_MainWindow* ui,
ImageView* image_view,
ImageDisplay* image_display,
GraphDisplay* h_graph_display,
GraphDisplay* v_graph_display );

~IVConnections();

public slots:
void close_viewer();
void toggle_Hscroll();
void toggle_Vscroll();
void range_changed();
Expand All @@ -89,6 +92,7 @@ public slots:
private:

Ui_MainWindow* iv_ui;
ImageView* iv_main_window;
ImageDisplay* image_display;
GraphDisplay* h_graph_display;
GraphDisplay* v_graph_display;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
@class ImageView
This is the top level class for the ImageView data viewer. Data is
This is the QMainWindow for the ImageView data viewer. Data is
displayed in an ImageView, by constructing the ImageView object and
specifying a particular data source.
Expand Down Expand Up @@ -45,7 +45,7 @@ namespace ImageView
{


class EXPORT_OPT_MANTIDQT_IMAGEVIEWER ImageView
class EXPORT_OPT_MANTIDQT_IMAGEVIEWER ImageView : public QMainWindow
{
public:

Expand All @@ -55,7 +55,6 @@ class EXPORT_OPT_MANTIDQT_IMAGEVIEWER ImageView
~ImageView();

private:
QMainWindow* window;
GraphDisplay* h_graph;
GraphDisplay* v_graph;

Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/MantidQt/ImageViewer/src/DataArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ DataArray::DataArray( double xmin, double xmax,

DataArray::~DataArray()
{
// std::cout << "DataArray destructor called" << std::endl;

if ( data )
{
delete[] data;
Expand Down
7 changes: 5 additions & 2 deletions Code/Mantid/MantidQt/ImageViewer/src/EventWSImageView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ using namespace ImageView;
EventWSImageView::EventWSImageView( IEventWorkspace_sptr ev_ws )
{
EventWSDataSource* source = new EventWSDataSource( ev_ws );
image_view = new ImageView( source );

image_view = new ImageView( source ); // this is the QMainWindow
// for the viewer. It is
// deleted when the window
// is closed
}

EventWSImageView::~EventWSImageView()
{
delete image_view;
}

1 change: 1 addition & 0 deletions Code/Mantid/MantidQt/ImageViewer/src/GraphDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ GraphDisplay::GraphDisplay( QwtPlot* graph_plot,

GraphDisplay::~GraphDisplay()
{
// std::cout << "GraphDisplay destructor called" << std::endl;
delete curve;
}

Expand Down
15 changes: 13 additions & 2 deletions Code/Mantid/MantidQt/ImageViewer/src/IVConnections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ namespace ImageView
*
*/
IVConnections::IVConnections( Ui_MainWindow* ui,
ImageView* iv_main_window,
ImageDisplay* image_display,
GraphDisplay* h_graph_display,
GraphDisplay* v_graph_display )
{
iv_ui = ui;
// first disable a few un-implemented controls
iv_ui->menuFile->setDisabled(true);
iv_ui->actionClose->setDisabled(true);
iv_ui->menuGraph_Selected->setDisabled(true);
iv_ui->actionClear_Selections->setDisabled(true);
iv_ui->actionOverlaid->setDisabled(true);
Expand All @@ -46,6 +45,10 @@ IVConnections::IVConnections( Ui_MainWindow* ui,
iv_ui->graph_max_label->setDisabled(true);
iv_ui->label_2->setDisabled(true);

this->iv_main_window = iv_main_window;
QObject::connect( iv_ui->actionClose, SIGNAL(triggered()),
this, SLOT(close_viewer()) );

// now set up the gui components
this->image_display = image_display;
this->h_graph_display = h_graph_display;
Expand Down Expand Up @@ -231,13 +234,21 @@ IVConnections::IVConnections( Ui_MainWindow* ui,

IVConnections::~IVConnections()
{
// std::cout << "IVConnections destructor called" << std::endl;

delete image_picker;
delete h_graph_picker;
delete v_graph_picker;
delete color_group;
}


void IVConnections::close_viewer()
{
iv_main_window->close();
}


void IVConnections::toggle_Hscroll()
{
bool is_on = iv_ui->action_Hscroll->isChecked();
Expand Down
1 change: 1 addition & 0 deletions Code/Mantid/MantidQt/ImageViewer/src/ImageDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ ImageDisplay::ImageDisplay( QwtPlot* image_plot,

ImageDisplay::~ImageDisplay()
{
// std::cout << "ImageDisplay destructor called" << std::endl;
delete image_plot_item;
}

Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/MantidQt/ImageViewer/src/ImagePlotItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ ImagePlotItem::ImagePlotItem()

ImagePlotItem::~ImagePlotItem()
{
//std::cout << "ImagePlotItem destructor called" << std::endl;

if ( data_array_0 )
{
delete data_array_0;
Expand Down
17 changes: 10 additions & 7 deletions Code/Mantid/MantidQt/ImageViewer/src/ImageView.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

#include <iostream>
#include "MantidQtImageViewer/ImageView.h"
#include "MantidQtImageViewer/ColorMaps.h"

Expand Down Expand Up @@ -27,13 +28,16 @@ namespace ImageView
ImageView::ImageView( ImageDataSource* data_source )
{
Ui_MainWindow* ui = new Ui_MainWindow();
window = new QMainWindow();
saved_ui = ui;

QMainWindow* window = this;

ui->setupUi( window );
window->resize( 1050, 800 );
window->show();
window->setAttribute(Qt::WA_DeleteOnClose);
window->setAttribute(Qt::WA_DeleteOnClose); // We just need to close the
// window to trigger the
// destructor and clean up

SliderHandler* slider_handler = new SliderHandler( ui );
saved_slider_handler = slider_handler;
Expand All @@ -51,7 +55,8 @@ ImageView::ImageView( ImageDataSource* data_source )
ui->image_table );
saved_image_display = image_display;

IVConnections* iv_connections = new IVConnections( ui, image_display,
IVConnections* iv_connections = new IVConnections( ui, this,
image_display,
h_graph, v_graph );
saved_iv_connections = iv_connections;

Expand All @@ -61,9 +66,8 @@ ImageView::ImageView( ImageDataSource* data_source )

ImageView::~ImageView()
{
/* // Why does Mantid seg fault, or show nothing if I delete these objects?
delete window;
// std::cout << "ImageView destructor called" << std::endl;

delete h_graph;
delete v_graph;

Expand All @@ -84,7 +88,6 @@ ImageView::~ImageView()

Ui_MainWindow* ui = static_cast<Ui_MainWindow*>(saved_ui);
delete ui;
*/
}


Expand Down

0 comments on commit 8556752

Please sign in to comment.