-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #4641 thread-safe QwtPlot replacement
Also refs #4516, using this safeqwtPlot in SliceViewer looks to make it impossible to segfault
- Loading branch information
Janik Zikovsky
committed
Jan 24, 2012
1 parent
9de3648
commit 2673799
Showing
5 changed files
with
138 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#ifndef MANTID_API_SAFEQWTPLOT_H_ | ||
#define MANTID_API_SAFEQWTPLOT_H_ | ||
|
||
#include "MantidKernel/System.h" | ||
#include <qwt_plot.h> | ||
#include <qpainter.h> | ||
#include "qwt_text.h" | ||
#include "MantidAPI/Workspace.h" | ||
|
||
|
||
namespace MantidQt | ||
{ | ||
namespace API | ||
{ | ||
|
||
/** A version of QwtPlot that adds a layer of thread safety. | ||
* Each SafeQwtPlot has a workspace associated with it. | ||
* Before drawing, it acquires a ReadLock to prevent | ||
* an algorithm from modifying the underlying workspace while it is | ||
* drawing. | ||
@date 2012-01-24 | ||
Copyright © 2012 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory | ||
This file is part of Mantid. | ||
Mantid is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 3 of the License, or | ||
(at your option) any later version. | ||
Mantid is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid> | ||
Code Documentation is available at: <http://doxygen.mantidproject.org> | ||
*/ | ||
class DLLExport SafeQwtPlot : public QwtPlot | ||
{ | ||
public: | ||
explicit SafeQwtPlot(QWidget * parent = NULL); | ||
explicit SafeQwtPlot(const QwtText &title, QWidget *p = NULL); | ||
|
||
virtual ~SafeQwtPlot(); | ||
|
||
virtual void drawCanvas(QPainter * painter); | ||
|
||
void setWorkspace(Mantid::API::Workspace_sptr ws); | ||
|
||
private: | ||
/// Workspace being read-locked | ||
Mantid::API::Workspace_sptr m_ws; | ||
}; | ||
|
||
|
||
} // namespace API | ||
} // namespace MantidQt | ||
|
||
#endif /* MANTID_API_SAFEQWTPLOT_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include "MantidQtAPI/SafeQwtPlot.h" | ||
#include "MantidKernel/System.h" | ||
#include "MantidKernel/ReadLock.h" | ||
|
||
using namespace Mantid::Kernel; | ||
|
||
namespace MantidQt | ||
{ | ||
namespace API | ||
{ | ||
|
||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Constructor | ||
*/ | ||
SafeQwtPlot::SafeQwtPlot(QWidget * parent) | ||
: QwtPlot(parent) | ||
{ | ||
} | ||
|
||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Constructor | ||
*/ | ||
SafeQwtPlot::SafeQwtPlot(const QwtText &title, QWidget * parent) | ||
: QwtPlot(title, parent) | ||
{ | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Destructor | ||
*/ | ||
SafeQwtPlot::~SafeQwtPlot() | ||
{ | ||
} | ||
|
||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Set the workspace that we read-lock when drawing. | ||
* | ||
* @param ws :: shared ptr to workspace | ||
*/ | ||
void SafeQwtPlot::setWorkspace(Mantid::API::Workspace_sptr ws) | ||
{ | ||
m_ws = ws; | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Overridden drawCanvas() that protects the | ||
* workspace from being overwritten while being drawn | ||
* | ||
* @param painter :: QPainter | ||
*/ | ||
void SafeQwtPlot::drawCanvas(QPainter * painter) | ||
{ | ||
// Do nothing if the workspace is not valid. | ||
if (!m_ws) return; | ||
// Get the scoped read lock. | ||
ReadLock lock(*m_ws); | ||
// Draw using the usual procedure. | ||
QwtPlot::drawCanvas(painter); | ||
} | ||
|
||
} // namespace MantidQt | ||
} // namespace API |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters