Skip to content

Commit

Permalink
Refs #3866 avoid occasional error expanding SliceViewer
Browse files Browse the repository at this point in the history
Due to uninitialized variable
  • Loading branch information
Janik Zikovsky committed Dec 22, 2011
1 parent 1fee420 commit d54ae8e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions Code/Mantid/MantidPlot/test/MantidPlotSliceViewerTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
FakeMDEventData("mdw", PeakParams="1e4, 2,4,6, 1.5")
BinToMDHistoWorkspace("mdw", "uniform", 1, "x,0,10,30", "y,0,10,30", "z,0,10,30", IterateEvents="1", Parallel="0")


class MantidPlotSliceViewerTest(unittest.TestCase):

def setUp(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ protected slots:
void showLineViewer(bool);
void changeStartOrEnd(Mantid::Kernel::VMD, Mantid::Kernel::VMD);
void changePlanarWidth(double);
void resizeWindow();

protected:
void deleteHandle(const std::string& wsName,const boost::shared_ptr<Mantid::API::Workspace> ws);
Expand All @@ -79,6 +80,8 @@ protected slots:
/// Width of the LineViewer last time it was open
int m_lastLinerWidth;

/// Window width
int m_desiredWidth;
};


Expand Down
21 changes: 16 additions & 5 deletions Code/Mantid/MantidQt/SliceViewer/src/SliceViewerWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ namespace SliceViewer
*/
SliceViewerWindow::SliceViewerWindow(const QString& wsName, const QString& label, Qt::WFlags f)
: QMainWindow(NULL, f),
WorkspaceObserver()
WorkspaceObserver(),
m_lastLinerWidth(0)
{
// Set the window icon
QIcon icon;
Expand Down Expand Up @@ -211,11 +212,13 @@ void SliceViewerWindow::showLineViewer(bool visible)
if (m_liner->width() > 0)
m_lastLinerWidth = m_liner->width();
m_liner->setVisible(false);
QApplication::processEvents();
this->resize(w, this->height());

// 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.
QApplication::processEvents();
this->resize(w, this->height());
// This needs 2 calls ro resizeWindow() to really work!
QTimer::singleShot(0, this, SLOT(resizeWindow()));
QTimer::singleShot(0, this, SLOT(resizeWindow()));
}
else
{
Expand All @@ -227,6 +230,14 @@ void SliceViewerWindow::showLineViewer(bool visible)
}


//------------------------------------------------------------------------------------------------
/** Special slot called to resize the window
* after some events have been processed. */
void SliceViewerWindow::resizeWindow()
{
this->resize(m_desiredWidth, this->height());
}

//------------------------------------------------------------------------------------------------
/** Using the positions from the LineOverlay, set the values in the LineViewer,
* but don't update view. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
// Little hack to avoid repeating code
#include "main_common.cpp"

using MantidQt::SliceViewer::SliceViewerWindow;

/** Main application
*
* @param argc :: ignored
Expand All @@ -32,7 +34,7 @@ int main( int argc, char ** argv )
app.setApplicationName("SliceViewerWindow demo");
IMDWorkspace_sptr mdew = makeDemoData();

SliceViewerWindow * mainWin = new SliceViewerWindow("mdew", NULL);
SliceViewerWindow * mainWin = new SliceViewerWindow("mdew");
//mainWin->getSlicer()->getLineOverlay()->setSnap(0.5);
// mainWin->getSlicer()->getLineOverlay()->setSnapLength(0.1);
mainWin->move(100, 100);
Expand All @@ -42,7 +44,6 @@ int main( int argc, char ** argv )
app.exec();

mainWin->close();
delete mainWin;
return 0;
}

0 comments on commit d54ae8e

Please sign in to comment.