Skip to content

Commit

Permalink
refs #6271. Fixed layout removal bug
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Jan 7, 2013
1 parent 44d7c5d commit de0c84d
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class EXPORT_OPT_MANTIDQT_SLICEVIEWER PeaksViewer : public QWidget
PeaksViewer(QWidget *parent = 0);
void setPeaksWorkspaces(const SetPeaksWorkspaces& workspaces);
void setPresenter(boost::shared_ptr<ProxyCompositePeaksPresenter> presenter);
void hide();
~PeaksViewer();
private:
boost::shared_ptr<ProxyCompositePeaksPresenter> m_presenter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace SliceViewer
{
Q_OBJECT
public:
PeaksWorkspaceWidget(Mantid::API::IPeaksWorkspace_const_sptr ws, QWidget *parent = 0);
PeaksWorkspaceWidget(Mantid::API::IPeaksWorkspace_const_sptr ws, const std::string& coordinateSystem, QWidget *parent = 0);
~PeaksWorkspaceWidget();
private:
/// Populate the widget with model data.
Expand All @@ -24,6 +24,8 @@ namespace SliceViewer
Ui::PeaksWorkspaceWidget ui;
/// Peaks workspace to view.
Mantid::API::IPeaksWorkspace_const_sptr m_ws;
/// Coordinate system.
const std::string m_coordinateSystem;
private slots:
void expandChanged(bool);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ namespace MantidQt
void setBackgroundColour(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, Qt::GlobalColor);
/// Get references to all presented workspaces.
SetPeaksWorkspaces presentedWorkspaces() const;
/// Gets the transform name.
std::string getTransformName() const;

private:
/// Wrapped composite to delegate to.
Expand Down
39 changes: 33 additions & 6 deletions Code/Mantid/MantidQt/SliceViewer/src/PeaksViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "MantidQtSliceViewer/PeaksWorkspaceWidget.h"
#include "MantidQtSliceViewer/ProxyCompositePeaksPresenter.h"
#include <QBoxLayout>
#include <QLayoutItem>

namespace MantidQt
{
Expand All @@ -10,12 +11,24 @@ namespace MantidQt
PeaksViewer::PeaksViewer(QWidget *parent)
: QWidget(parent)
{

this->setMinimumWidth(500);
}

void PeaksViewer::setPeaksWorkspaces(const SetPeaksWorkspaces& workspaces)
{

}

void removeLayout (QWidget* widget)
{
QLayout* layout = widget->layout ();
if (layout != 0)
{
QLayoutItem *item;
while ((item = layout->takeAt(0)) != 0)
layout->removeItem (item);
delete layout;
}
}

void PeaksViewer::setPresenter(boost::shared_ptr<ProxyCompositePeaksPresenter> presenter)
Expand All @@ -25,22 +38,36 @@ namespace MantidQt
// Configure the entire control using the managed workspaces.
auto workspaces = m_presenter->presentedWorkspaces();


auto coordinateSystem = presenter->getTransformName();

auto _layout = layout();
if(_layout)
if(layout())
{
delete _layout;
removeLayout(this);
}
this->setLayout(new QVBoxLayout);
auto it = workspaces.begin();
while(it != workspaces.end())
{
layout()->addWidget(new PeaksWorkspaceWidget(*it, this));
layout()->addWidget(new PeaksWorkspaceWidget(*it, coordinateSystem, this));
++it;
}
}

void PeaksViewer::hide()
{
QLayout* layout = this->layout();
const int size = layout->count();
for(int i = 0; i < size; ++i)
{
auto item = layout->itemAt(i);
if(auto widget = item->widget())
{
widget->hide();
}
}
QWidget::hide();
}

PeaksViewer::~PeaksViewer()
{
}
Expand Down
7 changes: 4 additions & 3 deletions Code/Mantid/MantidQt/SliceViewer/src/PeaksWorkspaceWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ namespace MantidQt
{
namespace SliceViewer
{
PeaksWorkspaceWidget::PeaksWorkspaceWidget(Mantid::API::IPeaksWorkspace_const_sptr ws, QWidget *parent)
: QWidget(parent), m_ws(ws)
PeaksWorkspaceWidget::PeaksWorkspaceWidget(Mantid::API::IPeaksWorkspace_const_sptr ws, const std::string& coordinateSystem, QWidget *parent)
: QWidget(parent), m_ws(ws), m_coordinateSystem(coordinateSystem)
{
ui.setupUi(this);

ui.tblPeaks->setHidden(true);
ui.tblPeaks->setFixedHeight(0);
connect(ui.ckExpand, SIGNAL(clicked(bool)), this, SLOT(expandChanged(bool)));


populate();
}

Expand All @@ -25,6 +24,8 @@ namespace MantidQt
const QString integratedMsg = "integrated";

ui.lblWorkspaceName->setText(m_ws->hasIntegratedPeaks() ? integratedMsg : unintegratedMsg );

ui.lblWorkspaceCoordinates->setText(m_coordinateSystem.c_str());
}

PeaksWorkspaceWidget::~PeaksWorkspaceWidget()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,20 @@ namespace MantidQt
m_compositePresenter->setBackgroundColour(ws, colour);
}

/*
/**
Get all the presented workspaces.
*/
SetPeaksWorkspaces ProxyCompositePeaksPresenter::presentedWorkspaces() const
{
return m_compositePresenter->presentedWorkspaces();
}

/**
Getter for the transform name.
*/
std::string ProxyCompositePeaksPresenter::getTransformName() const
{
return m_compositePresenter->getTransformName();
}
}
}
3 changes: 1 addition & 2 deletions Code/Mantid/MantidQt/SliceViewer/src/SliceViewerWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,7 @@ void SliceViewerWindow::showPeaksViewer(bool visible)
int w = this->width() - (m_peaksViewer->width() + m_splitter->handleWidth());
if (m_peaksViewer->width() > 0)
m_lastPeaksViewerWidth = m_peaksViewer->width();
m_peaksViewer->setVisible(false);

m_peaksViewer->hide();
// Save this value for resizing with the single shot timer
m_desiredWidth = w;
// This call is necessary to allow resizing smaller than would be allowed if both left/right widgets were visible.
Expand Down

0 comments on commit de0c84d

Please sign in to comment.