mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Fix crash on plot deletion
This commit is contained in:
@@ -798,7 +798,7 @@ std::vector<RimWellLogCurve* > RimWellLogTrack::curvesVector()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimWellLogTrack::uiOrderingForShowFormationNamesAndCase(QString uiConfigName, caf::PdmUiOrdering& uiOrdering)
|
||||
{
|
||||
caf::PdmUiGroup* formationGroup = uiOrdering.addNewGroup("Formation Names Properties");
|
||||
caf::PdmUiGroup* formationGroup = uiOrdering.addNewGroup("Formation Names");
|
||||
formationGroup->add(&m_showFormations);
|
||||
formationGroup->add(&m_case);
|
||||
}
|
||||
@@ -995,7 +995,7 @@ void RimWellLogTrack::updateFormationNamesOnPlot()
|
||||
|
||||
if (m_annotationTool == nullptr)
|
||||
{
|
||||
m_annotationTool = std::unique_ptr<RiuPlotAnnotationTool>(new RiuPlotAnnotationTool(this->viewer()));
|
||||
m_annotationTool = std::unique_ptr<RiuPlotAnnotationTool>(new RiuPlotAnnotationTool());
|
||||
}
|
||||
|
||||
RimMainPlotCollection* mainPlotCollection;
|
||||
@@ -1050,7 +1050,7 @@ void RimWellLogTrack::updateFormationNamesOnPlot()
|
||||
&formationNamesToPlot,
|
||||
&yValues);
|
||||
|
||||
m_annotationTool->attachFormationNames(formationNamesToPlot, yValues);
|
||||
m_annotationTool->attachFormationNames(this->viewer(), formationNamesToPlot, yValues);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@@ -26,11 +26,20 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuPlotAnnotationTool::attachFormationNames(const std::vector<QString>& names, const std::vector<std::pair<double, double>> yPositions)
|
||||
RiuPlotAnnotationTool::~RiuPlotAnnotationTool()
|
||||
{
|
||||
detachAllAnnotations();
|
||||
if (names.size() != yPositions.size()) return;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuPlotAnnotationTool::attachFormationNames(QwtPlot* plot, const std::vector<QString>& names, const std::vector<std::pair<double, double>> yPositions)
|
||||
{
|
||||
detachAllAnnotations();
|
||||
|
||||
if (names.size() != yPositions.size()) return;
|
||||
m_plot = plot;
|
||||
QPen curvePen;
|
||||
curvePen.setStyle(Qt::DashLine);
|
||||
curvePen.setColor(Qt::blue);
|
||||
@@ -40,7 +49,7 @@ void RiuPlotAnnotationTool::attachFormationNames(const std::vector<QString>& nam
|
||||
|
||||
for (size_t i = 0; i < names.size(); i++)
|
||||
{
|
||||
std::unique_ptr<QwtPlotMarker> line(new QwtPlotMarker());
|
||||
QwtPlotMarker* line(new QwtPlotMarker());
|
||||
|
||||
line->setLineStyle(QwtPlotMarker::HLine);
|
||||
line->setLinePen(curvePen);
|
||||
@@ -57,7 +66,7 @@ void RiuPlotAnnotationTool::attachFormationNames(const std::vector<QString>& nam
|
||||
|
||||
if ((i != names.size() - 1) && cvf::Math::abs(yPositions[i].second - yPositions[i+1].first) > delta)
|
||||
{
|
||||
std::unique_ptr<QwtPlotMarker> line(new QwtPlotMarker());
|
||||
QwtPlotMarker* line(new QwtPlotMarker());
|
||||
|
||||
line->setLineStyle(QwtPlotMarker::HLine);
|
||||
line->setLinePen(curvePen);
|
||||
@@ -75,9 +84,13 @@ void RiuPlotAnnotationTool::attachFormationNames(const std::vector<QString>& nam
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuPlotAnnotationTool::detachAllAnnotations()
|
||||
{
|
||||
for (size_t i = 0; i < m_markers.size(); i++)
|
||||
if (m_plot)
|
||||
{
|
||||
m_markers[i]->detach();
|
||||
for (size_t i = 0; i < m_markers.size(); i++)
|
||||
{
|
||||
m_markers[i]->detach();
|
||||
delete m_markers[i];
|
||||
}
|
||||
}
|
||||
m_markers.clear();
|
||||
}
|
||||
|
@@ -23,18 +23,21 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
class QString;
|
||||
class QwtPlot;
|
||||
|
||||
class RiuPlotAnnotationTool
|
||||
{
|
||||
public:
|
||||
RiuPlotAnnotationTool(QwtPlot* plot) : m_plot(plot) {};
|
||||
RiuPlotAnnotationTool() {};
|
||||
~RiuPlotAnnotationTool();
|
||||
|
||||
void attachFormationNames(const std::vector<QString>& names, const std::vector<std::pair<double, double>> yPositions);
|
||||
void attachFormationNames(QwtPlot* plot, const std::vector<QString>& names, const std::vector<std::pair<double, double>> yPositions);
|
||||
void detachAllAnnotations();
|
||||
|
||||
private:
|
||||
QwtPlot* m_plot;
|
||||
std::vector<std::unique_ptr<QwtPlotMarker>> m_markers;
|
||||
QPointer<QwtPlot> m_plot;
|
||||
std::vector<QwtPlotMarker*> m_markers;
|
||||
};
|
||||
|
Reference in New Issue
Block a user