Skip to content

Commit

Permalink
refs #6271. Remove single overlay, and other GUI fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Jan 11, 2013
1 parent 97ed69c commit 623f343
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ namespace MantidQt
PeakPalette getPalette() const;
/// Setter for indicating whether the background radius will be shown.
void setBackgroundRadiusShown(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, const bool shown);
/// Remove the workspace and corresponding presenter.
void remove(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> peaksWS);
private:
/// Alias for container of subjects type.
typedef std::vector<PeaksPresenter_sptr> SubjectContainer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public slots:
void onPeakColourChanged(Mantid::API::IPeaksWorkspace_const_sptr, QColor);
void onBackgroundColourChanged(Mantid::API::IPeaksWorkspace_const_sptr, QColor);
void onBackgroundRadiusShown(Mantid::API::IPeaksWorkspace_const_sptr, bool);
void onRemoveWorkspace(Mantid::API::IPeaksWorkspace_const_sptr);
private:
boost::shared_ptr<ProxyCompositePeaksPresenter> m_presenter;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace SliceViewer
void peakColourChanged(Mantid::API::IPeaksWorkspace_const_sptr, QColor);
void backgroundColourChanged(Mantid::API::IPeaksWorkspace_const_sptr, QColor);
void backgroundRadiusShown(Mantid::API::IPeaksWorkspace_const_sptr, bool);
void removeWorkspace(Mantid::API::IPeaksWorkspace_const_sptr);
private:
/// Populate the widget with model data.
void populate();
Expand All @@ -40,6 +41,7 @@ namespace SliceViewer
void onBackgroundColourClicked();
void onForegroundColourClicked();
void onShowBackgroundChanged(bool);
void onRemoveWorkspaceClicked();
};

} //namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,39 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="lblWorkspaceState">
<property name="text">
<string>[Integrated/UnIntegrated]</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="lblWorkspaceCoordinates">
<property name="text">
Expand Down Expand Up @@ -87,13 +113,6 @@
</item>
<item>
<layout class="QHBoxLayout" name="controlsLayout">
<item>
<widget class="QPushButton" name="btnHide">
<property name="text">
<string>Hide</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnRemove">
<property name="text">
Expand All @@ -108,7 +127,7 @@
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<width>30</width>
<height>20</height>
</size>
</property>
Expand All @@ -128,8 +147,30 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>8</width>
<height>8</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="minimumSize">
<size>
<width>110</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Peak Background Color</string>
</property>
Expand All @@ -142,6 +183,22 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>8</width>
<height>8</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="ckShowBackground">
<property name="text">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ namespace MantidQt
std::string getTransformName() const;
/// Change whether the background radius is shown.
void setBackgroundRadiusShown(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, const bool shown);
/// Remove the workspace and corresponding presenter.
void remove(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> peaksWS);

private:
/// Wrapped composite to delegate to.
Expand Down
18 changes: 13 additions & 5 deletions Code/Mantid/MantidQt/SliceViewer/src/CompositePeaksPresenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ namespace MantidQt
void CompositePeaksPresenter::clear()
{
m_subjects.clear();
PeakPalette temp;
m_palette = temp;
}

/**
Expand Down Expand Up @@ -252,10 +254,16 @@ namespace MantidQt
return m_palette.backgroundIndexToColour(pos);
}

void CompositePeaksPresenter::setBackgroundRadiusShown(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, const bool shown)
{
auto iterator = getPresenterIteratorFromWorkspace(ws);
(*iterator)->showBackgroundRadius(shown);
}
void CompositePeaksPresenter::setBackgroundRadiusShown(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> ws, const bool shown)
{
auto iterator = getPresenterIteratorFromWorkspace(ws);
(*iterator)->showBackgroundRadius(shown);
}

void CompositePeaksPresenter::remove(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> peaksWS)
{
auto iterator = getPresenterIteratorFromWorkspace(peaksWS);
m_subjects.erase(iterator);
}
}
}
7 changes: 7 additions & 0 deletions Code/Mantid/MantidQt/SliceViewer/src/PeaksViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ namespace MantidQt
connect(widget, SIGNAL(peakColourChanged(Mantid::API::IPeaksWorkspace_const_sptr, QColor)), this, SLOT(onPeakColourChanged(Mantid::API::IPeaksWorkspace_const_sptr, QColor)));
connect(widget, SIGNAL(backgroundColourChanged(Mantid::API::IPeaksWorkspace_const_sptr, QColor)), this, SLOT(onBackgroundColourChanged(Mantid::API::IPeaksWorkspace_const_sptr, QColor)));
connect(widget, SIGNAL(backgroundRadiusShown(Mantid::API::IPeaksWorkspace_const_sptr, bool)), this, SLOT(onBackgroundRadiusShown(Mantid::API::IPeaksWorkspace_const_sptr, bool)));
connect(widget, SIGNAL(removeWorkspace(Mantid::API::IPeaksWorkspace_const_sptr)), this, SLOT(onRemoveWorkspace(Mantid::API::IPeaksWorkspace_const_sptr)));

layout()->addWidget(widget);
++it;
}
Expand Down Expand Up @@ -96,5 +98,10 @@ namespace MantidQt
m_presenter->setBackgroundRadiusShown(peaksWS, show);
}

void PeaksViewer::onRemoveWorkspace(Mantid::API::IPeaksWorkspace_const_sptr peaksWS)
{
m_presenter->remove(peaksWS);
}

} // namespace
}
12 changes: 11 additions & 1 deletion Code/Mantid/MantidQt/SliceViewer/src/PeaksWorkspaceWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace MantidQt
connect(ui.ckShowBackground, SIGNAL(clicked(bool)), this, SLOT(onShowBackgroundChanged(bool)));
connect(ui.btnBackgroundColor, SIGNAL(clicked()), this, SLOT(onBackgroundColourClicked()));
connect(ui.btnPeakColor, SIGNAL(clicked()), this, SLOT(onForegroundColourClicked()));
connect(ui.btnRemove, SIGNAL(clicked()), this, SLOT(onRemoveWorkspaceClicked()));

populate();
}
Expand All @@ -24,14 +25,17 @@ namespace MantidQt
{
const QString nameText = "Workspace name: " + QString(m_ws->name().c_str());
ui.lblWorkspaceName->setText(nameText);
ui.lblWorkspaceName->setToolTip(nameText);

const QString integratedMsg = m_ws->hasIntegratedPeaks() ? "Yes" : "No";
const QString integratedText = "Peaks Integrated: " + integratedMsg;

ui.lblWorkspaceName->setText(integratedText);
ui.lblWorkspaceState->setText(integratedText);
ui.lblWorkspaceState->setToolTip(integratedText);

const QString coordinateText = "Coordinate system: " + QString(m_coordinateSystem.c_str());
ui.lblWorkspaceCoordinates->setText(coordinateText);
ui.lblWorkspaceCoordinates->setToolTip(coordinateText);

ui.btnBackgroundColor->setBackgroundColor(m_backgroundColour);
ui.btnPeakColor->setBackgroundColor(m_foregroundColour);
Expand Down Expand Up @@ -68,5 +72,11 @@ namespace MantidQt
emit backgroundRadiusShown(this->m_ws, show);
}

void PeaksWorkspaceWidget::onRemoveWorkspaceClicked()
{
emit removeWorkspace(this->m_ws);
this->hide();
}

} // namespace
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,10 @@ namespace MantidQt
{
m_compositePresenter->setBackgroundRadiusShown(ws, shown);
}

void ProxyCompositePeaksPresenter::remove(boost::shared_ptr<const Mantid::API::IPeaksWorkspace> peaksWS)
{
m_compositePresenter->remove(peaksWS);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using namespace MantidQt::SliceViewer;
using namespace Mantid;
using namespace testing;
using Mantid::API::IPeaksWorkspace_sptr;

class CompositePeaksPresenterTest : public CxxTest::TestSuite
{
Expand Down Expand Up @@ -363,7 +364,57 @@ class CompositePeaksPresenterTest : public CxxTest::TestSuite
TS_ASSERT(Mock::VerifyAndClearExpectations(pSubject));
}


void test_remove()
{
class DyingMockPeaksPresenter : public MockPeaksPresenter
{
public:
MOCK_METHOD0(die, void());
virtual ~DyingMockPeaksPresenter(){die();}
};

// Create a subject presenter that will be deleted.
auto A = new NiceMock<DyingMockPeaksPresenter>();
// Create a subject presenter that won't be deleted.
auto B = new NiceMock<MockPeaksPresenter>();

{
// Create some input peaks workspaces.
IPeaksWorkspace_sptr peaksWS_A = boost::make_shared<Mantid::DataObjects::PeaksWorkspace>();
SetPeaksWorkspaces setA;
setA.insert(peaksWS_A);

IPeaksWorkspace_sptr peaksWS_B = boost::make_shared<Mantid::DataObjects::PeaksWorkspace>();
SetPeaksWorkspaces setB;
setA.insert(peaksWS_B);

PeaksPresenter_sptr subjectA(A);
EXPECT_CALL(*A, presentedWorkspaces()).WillRepeatedly(Return(setA));
EXPECT_CALL(*A, die()).Times(1); // This will be called on destruction, because we will foreably remove this presenter!

PeaksPresenter_sptr subjectB(B);
EXPECT_CALL(*B, presentedWorkspaces()).WillRepeatedly(Return(setB));

// Set a background colour on the composite.
CompositePeaksPresenter composite;
composite.addPeaksPresenter(subjectA);
composite.addPeaksPresenter(subjectB);

const size_t preRemovalSize = composite.size(); // benchmark the current size.

/// Remove one of the presenters via its workspace.
composite.remove(peaksWS_A);

const size_t postRemovalSize = composite.size();

TSM_ASSERT_EQUALS("A presenter should have been removed.",preRemovalSize, postRemovalSize + 1);
}
// Check that the correct presenter has been removed.
TS_ASSERT(Mock::VerifyAndClearExpectations(A));
TS_ASSERT(Mock::VerifyAndClearExpectations(B));
}



};

Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/MantidQt/SliceViewer/test/MockObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace
MOCK_METHOD1(setBackgroundColour, void(const QColor));
MOCK_CONST_METHOD0(getTransformName, std::string());
MOCK_METHOD1(showBackgroundRadius, void(const bool));
~MockPeaksPresenter(){}
virtual ~MockPeaksPresenter(){}
};

/*------------------------------------------------------------
Expand Down

0 comments on commit 623f343

Please sign in to comment.