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)
|
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_showFormations);
|
||||||
formationGroup->add(&m_case);
|
formationGroup->add(&m_case);
|
||||||
}
|
}
|
||||||
@@ -995,7 +995,7 @@ void RimWellLogTrack::updateFormationNamesOnPlot()
|
|||||||
|
|
||||||
if (m_annotationTool == nullptr)
|
if (m_annotationTool == nullptr)
|
||||||
{
|
{
|
||||||
m_annotationTool = std::unique_ptr<RiuPlotAnnotationTool>(new RiuPlotAnnotationTool(this->viewer()));
|
m_annotationTool = std::unique_ptr<RiuPlotAnnotationTool>(new RiuPlotAnnotationTool());
|
||||||
}
|
}
|
||||||
|
|
||||||
RimMainPlotCollection* mainPlotCollection;
|
RimMainPlotCollection* mainPlotCollection;
|
||||||
@@ -1050,7 +1050,7 @@ void RimWellLogTrack::updateFormationNamesOnPlot()
|
|||||||
&formationNamesToPlot,
|
&formationNamesToPlot,
|
||||||
&yValues);
|
&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();
|
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;
|
QPen curvePen;
|
||||||
curvePen.setStyle(Qt::DashLine);
|
curvePen.setStyle(Qt::DashLine);
|
||||||
curvePen.setColor(Qt::blue);
|
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++)
|
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->setLineStyle(QwtPlotMarker::HLine);
|
||||||
line->setLinePen(curvePen);
|
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)
|
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->setLineStyle(QwtPlotMarker::HLine);
|
||||||
line->setLinePen(curvePen);
|
line->setLinePen(curvePen);
|
||||||
@@ -74,10 +83,14 @@ void RiuPlotAnnotationTool::attachFormationNames(const std::vector<QString>& nam
|
|||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RiuPlotAnnotationTool::detachAllAnnotations()
|
void RiuPlotAnnotationTool::detachAllAnnotations()
|
||||||
|
{
|
||||||
|
if (m_plot)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < m_markers.size(); i++)
|
for (size_t i = 0; i < m_markers.size(); i++)
|
||||||
{
|
{
|
||||||
m_markers[i]->detach();
|
m_markers[i]->detach();
|
||||||
|
delete m_markers[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m_markers.clear();
|
m_markers.clear();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,18 +23,21 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <QPointer>
|
||||||
|
|
||||||
class QString;
|
class QString;
|
||||||
class QwtPlot;
|
class QwtPlot;
|
||||||
|
|
||||||
class RiuPlotAnnotationTool
|
class RiuPlotAnnotationTool
|
||||||
{
|
{
|
||||||
public:
|
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();
|
void detachAllAnnotations();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QwtPlot* m_plot;
|
QPointer<QwtPlot> m_plot;
|
||||||
std::vector<std::unique_ptr<QwtPlotMarker>> m_markers;
|
std::vector<QwtPlotMarker*> m_markers;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user