Preparations for #1321: Aligned default stuff between the plot types.

This commit is contained in:
Jacob Støren 2017-03-27 16:47:59 +02:00
parent a82677c743
commit c0ff734cc7
8 changed files with 111 additions and 181 deletions

View File

@ -23,12 +23,14 @@
#include "qwt_plot_curve.h"
#include "qwt_date_scale_draw.h"
#include <QEvent>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuQwtCurvePointTracker::RiuQwtCurvePointTracker(QwtPlot* plot, bool isMainAxisHorizontal): QwtPlotPicker(plot->canvas()), m_plot(plot), m_isMainAxisHorizontal(isMainAxisHorizontal)
RiuQwtCurvePointTracker::RiuQwtCurvePointTracker(QwtPlot* plot, bool isMainAxisHorizontal)
: QwtPlotPicker(plot->canvas()), m_plot(plot), m_isMainAxisHorizontal(isMainAxisHorizontal)
{
this->setTrackerMode(QwtPicker::AlwaysOn);
m_plotMarker = new QwtPlotMarker;
@ -60,6 +62,20 @@ void RiuQwtCurvePointTracker::removeMarkerOnFocusLeave()
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiuQwtCurvePointTracker::eventFilter(QObject *watched, QEvent *event)
{
if ( event->type() == QEvent::Leave )
{
this->removeMarkerOnFocusLeave();
}
// pass the event on to the parent class
return QwtPlotPicker::eventFilter(watched, event);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -33,12 +33,20 @@ public:
explicit RiuQwtCurvePointTracker(QwtPlot* plot, bool isMainAxisHorizontal);
~RiuQwtCurvePointTracker();
protected:
virtual bool eventFilter(QObject *, QEvent *) override;
void removeMarkerOnFocusLeave();
protected:
virtual QwtText trackerText(const QPoint& pos) const override;
QPointF closestCurvePoint(const QPoint& cursorPosition, QString* valueAxisValueString, QString* mainAxisValueString, QwtPlot::Axis* relatedXAxis, QwtPlot::Axis* relatedYAxis) const;
void updateClosestCurvePointMarker(const QPointF& closestPoint, QwtPlot::Axis relatedXAxis, QwtPlot::Axis relatedYAxis) const;
QPointF closestCurvePoint(const QPoint& cursorPosition,
QString* valueAxisValueString,
QString* mainAxisValueString,
QwtPlot::Axis* relatedXAxis,
QwtPlot::Axis* relatedYAxis) const;
void updateClosestCurvePointMarker(const QPointF& closestPoint,
QwtPlot::Axis relatedXAxis,
QwtPlot::Axis relatedYAxis) const;
QPointer<QwtPlot> m_plot;
QwtPlotMarker* m_plotMarker;

View File

@ -39,6 +39,7 @@
#include <QMenu>
#include <QContextMenuEvent>
#include "RiuSummaryQwtPlot.h"
//--------------------------------------------------------------------------------------------------
@ -47,9 +48,6 @@
RiuResultQwtPlot::RiuResultQwtPlot(QWidget* parent)
: QwtPlot(parent)
{
m_grid = new QwtPlotGrid;
m_grid->attach(this);
setDefaults();
}
@ -59,9 +57,6 @@ RiuResultQwtPlot::RiuResultQwtPlot(QWidget* parent)
RiuResultQwtPlot::~RiuResultQwtPlot()
{
deleteAllCurves();
m_grid->detach();
delete m_grid;
}
//--------------------------------------------------------------------------------------------------
@ -152,59 +147,20 @@ void RiuResultQwtPlot::contextMenuEvent(QContextMenuEvent* event)
//--------------------------------------------------------------------------------------------------
void RiuResultQwtPlot::setDefaults()
{
QPalette newPalette(palette());
newPalette.setColor(QPalette::Background, Qt::white);
setPalette(newPalette);
setAutoFillBackground(true);
setCanvasBackground(Qt::white);
QFrame* canvasFrame = dynamic_cast<QFrame*>(canvas());
if (canvasFrame)
{
canvasFrame->setFrameShape(QFrame::NoFrame);
}
canvas()->setMouseTracking(true);
canvas()->installEventFilter(this);
QPen gridPen(Qt::SolidLine);
gridPen.setColor(Qt::lightGray);
m_grid->setPen(gridPen);
RiuSummaryQwtPlot::setCommonPlotBehaviour(this);
enableAxis(QwtPlot::xBottom, true);
enableAxis(QwtPlot::yLeft, true);
enableAxis(QwtPlot::xTop, false);
enableAxis(QwtPlot::yRight, false);
plotLayout()->setAlignCanvasToScales(true);
QwtDateScaleDraw* scaleDraw = new QwtDateScaleDraw(Qt::UTC);
scaleDraw->setDateFormat(QwtDate::Year, QString("dd-MM-yyyy"));
QwtDateScaleEngine* scaleEngine = new QwtDateScaleEngine(Qt::UTC);
setAxisScaleEngine(QwtPlot::xBottom, scaleEngine);
setAxisScaleDraw(QwtPlot::xBottom, scaleDraw);
QFont xAxisFont = axisFont(QwtPlot::xBottom);
xAxisFont.setPixelSize(9);
setAxisFont(QwtPlot::xBottom, xAxisFont);
QFont yAxisFont = axisFont(QwtPlot::yLeft);
yAxisFont.setPixelSize(9);
setAxisFont(QwtPlot::yLeft, yAxisFont);
QwtText axisTitleY = axisTitle(QwtPlot::yLeft);
QFont yAxisTitleFont = axisTitleY.font();
yAxisTitleFont.setPixelSize(9);
yAxisTitleFont.setBold(false);
axisTitleY.setFont(yAxisTitleFont);
axisTitleY.setRenderFlags(Qt::AlignRight);
setAxisTitle(QwtPlot::yLeft, axisTitleY);
RiuSummaryQwtPlot::enableDateBasedBottomXAxis(this);
QwtLegend* legend = new QwtLegend(this);
setAxisMaxMinor(QwtPlot::xBottom, 2);
setAxisMaxMinor(QwtPlot::yLeft, 3);
// The legend will be deleted in the destructor of the plot or when
// another legend is inserted.
QwtLegend* legend = new QwtLegend(this);
this->insertLegend(legend, BottomLegend);
}

View File

@ -55,6 +55,5 @@ private:
private:
std::vector<QwtPlotCurve*> m_plotCurves;
QwtPlotGrid* m_grid;
};

View File

@ -45,6 +45,8 @@
#include <QWheelEvent>
#include <float.h>
#include "qwt_plot_magnifier.h"
#include "RiuQwtPlotWheelZoomer.h"
//--------------------------------------------------------------------------------------------------
///
@ -54,9 +56,6 @@ RiuSummaryQwtPlot::RiuSummaryQwtPlot(RimSummaryPlot* plotDefinition, QWidget* pa
Q_ASSERT(plotDefinition);
m_plotDefinition = plotDefinition;
m_grid = new QwtPlotGrid;
m_grid->attach(this);
setDefaults();
// LeftButton for the zooming
@ -85,9 +84,6 @@ RiuSummaryQwtPlot::RiuSummaryQwtPlot(RimSummaryPlot* plotDefinition, QWidget* pa
RiuQwtScalePicker* scalePicker = new RiuQwtScalePicker(this);
connect(scalePicker, SIGNAL(clicked(int, double)), this, SLOT(onAxisClicked(int, double)));
// Create a plot picker to display values next to mouse cursor
m_curvePointTracker = new RiuQwtCurvePointTracker(this, true);
}
//--------------------------------------------------------------------------------------------------
@ -95,15 +91,11 @@ RiuSummaryQwtPlot::RiuSummaryQwtPlot(RimSummaryPlot* plotDefinition, QWidget* pa
//--------------------------------------------------------------------------------------------------
RiuSummaryQwtPlot::~RiuSummaryQwtPlot()
{
m_grid->detach();
delete m_grid;
if (m_plotDefinition)
{
m_plotDefinition->detachAllCurves();
m_plotDefinition->handleMdiWindowClosed();
}
}
//--------------------------------------------------------------------------------------------------
@ -191,71 +183,99 @@ QSize RiuSummaryQwtPlot::sizeHint() const
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::setDefaults()
{
QPalette newPalette(palette());
newPalette.setColor(QPalette::Background, Qt::white);
setPalette(newPalette);
setAutoFillBackground(true);
setCanvasBackground(Qt::white);
QFrame* canvasFrame = dynamic_cast<QFrame*>(canvas());
if (canvasFrame)
{
canvasFrame->setFrameShape(QFrame::NoFrame);
}
canvas()->setMouseTracking(true);
canvas()->installEventFilter(this);
QPen gridPen(Qt::SolidLine);
gridPen.setColor(Qt::lightGray);
m_grid->setPen(gridPen);
setCommonPlotBehaviour(this);
enableAxis(QwtPlot::xBottom, true);
enableAxis(QwtPlot::yLeft, true);
enableAxis(QwtPlot::xTop, false);
enableAxis(QwtPlot::yRight, false);
plotLayout()->setAlignCanvasToScales(true);
useDateBasedTimeAxis();
QFont xAxisFont = axisFont(QwtPlot::xBottom);
xAxisFont.setPixelSize(11);
setAxisFont(QwtPlot::xBottom, xAxisFont);
setAxisMaxMinor(QwtPlot::xBottom, 2);
QFont yAxisFont = axisFont(QwtPlot::yLeft);
yAxisFont.setPixelSize(11);
setAxisFont(QwtPlot::yLeft, yAxisFont);
setAxisMaxMinor(QwtPlot::yLeft, 3);
QwtText axisTitleY = axisTitle(QwtPlot::yLeft);
QFont yAxisTitleFont = axisTitleY.font();
yAxisTitleFont.setPixelSize(11);
yAxisTitleFont.setBold(false);
axisTitleY.setFont(yAxisTitleFont);
axisTitleY.setRenderFlags(Qt::AlignRight);
setAxisTitle(QwtPlot::yLeft, axisTitleY);
QwtLegend* legend = new QwtLegend(this);
// The legend will be deleted in the destructor of the plot or when
// another legend is inserted.
QwtLegend* legend = new QwtLegend(this);
this->insertLegend(legend, BottomLegend);
}
void RiuSummaryQwtPlot::setCommonPlotBehaviour(QwtPlot* plot)
{
// Plot background and frame look
QPalette newPalette(plot->palette());
newPalette.setColor(QPalette::Background, Qt::white);
plot->setPalette(newPalette);
plot->setAutoFillBackground(true);
plot->setCanvasBackground(Qt::white);
QFrame* canvasFrame = dynamic_cast<QFrame*>(plot->canvas());
if (canvasFrame)
{
canvasFrame->setFrameShape(QFrame::NoFrame);
}
// Grid
QwtPlotGrid* grid = new QwtPlotGrid;
grid->attach(plot);
QPen gridPen(Qt::SolidLine);
gridPen.setColor(Qt::lightGray);
grid->setPen(gridPen);
// Axis number font
QFont axisFont = plot->axisFont(QwtPlot::xBottom);
axisFont.setPixelSize(11);
plot->setAxisFont(QwtPlot::xBottom, axisFont);
plot->setAxisFont(QwtPlot::xTop, axisFont);
plot->setAxisFont(QwtPlot::yLeft, axisFont);
plot->setAxisFont(QwtPlot::yRight, axisFont);
// Axis title font
QwtText axisTitle = plot->axisTitle(QwtPlot::xBottom);
QFont axisTitleFont = axisTitle.font();
axisTitleFont.setPixelSize(11);
axisTitleFont.setBold(false);
axisTitle.setFont(axisTitleFont);
axisTitle.setRenderFlags(Qt::AlignRight);
plot->setAxisTitle(QwtPlot::xBottom, axisTitle);
plot->setAxisTitle(QwtPlot::xTop, axisTitle);
plot->setAxisTitle(QwtPlot::yLeft, axisTitle);
plot->setAxisTitle(QwtPlot::yRight, axisTitle);
// Enable mousetracking and event filter
plot->canvas()->setMouseTracking(true);
plot->canvas()->installEventFilter(plot);
plot->plotLayout()->setAlignCanvasToScales(true);
new RiuQwtCurvePointTracker(plot, true);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::useDateBasedTimeAxis()
{
enableDateBasedBottomXAxis(this);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::enableDateBasedBottomXAxis(QwtPlot* plot)
{
QwtDateScaleDraw* scaleDraw = new QwtDateScaleDraw(Qt::UTC);
scaleDraw->setDateFormat(QwtDate::Year, QString("dd-MM-yyyy"));
QwtDateScaleEngine* scaleEngine = new QwtDateScaleEngine(Qt::UTC);
setAxisScaleEngine(QwtPlot::xBottom, scaleEngine);
setAxisScaleDraw(QwtPlot::xBottom, scaleDraw);
plot->setAxisScaleEngine(QwtPlot::xBottom, scaleEngine);
plot->setAxisScaleDraw(QwtPlot::xBottom, scaleDraw);
}
//--------------------------------------------------------------------------------------------------
@ -288,13 +308,6 @@ bool RiuSummaryQwtPlot::eventFilter(QObject* watched, QEvent* event)
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::leaveEvent(QEvent *)
{
m_curvePointTracker->removeMarkerOnFocusLeave();
}
//--------------------------------------------------------------------------------------------------
///
@ -335,11 +348,6 @@ void RiuSummaryQwtPlot::selectClosestCurve(const QPoint& pos)
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::onZoomedSlot()
{
QwtInterval left, right, time;
currentVisibleWindow(&left, &right, &time);
this->setZoomWindow(left, right, time);
m_plotDefinition->updateZoomWindowFromQwt();
}

View File

@ -58,9 +58,11 @@ public:
const QwtInterval& rightAxis,
const QwtInterval& timeAxis);
static void setCommonPlotBehaviour(QwtPlot* plot);
static void enableDateBasedBottomXAxis(QwtPlot* plot);
protected:
virtual bool eventFilter(QObject* watched, QEvent* event) override;
virtual void leaveEvent(QEvent *) override;
virtual QSize sizeHint() const override;
virtual QSize minimumSizeHint() const override;
@ -76,7 +78,6 @@ private slots:
void onAxisClicked(int axis, double value);
private:
QwtPlotGrid* m_grid;
RiuQwtCurvePointTracker* m_curvePointTracker;
caf::PdmPointer<RimSummaryPlot> m_plotDefinition;

View File

@ -45,6 +45,7 @@
#include <QWheelEvent>
#include <float.h>
#include "RiuSummaryQwtPlot.h"
#define RIU_SCROLLWHEEL_ZOOMFACTOR 1.1
#define RIU_SCROLLWHEEL_PANFACTOR 0.1
@ -57,16 +58,9 @@ RiuWellLogTrack::RiuWellLogTrack(RimWellLogTrack* plotTrackDefinition, QWidget*
{
Q_ASSERT(plotTrackDefinition);
m_plotTrackDefinition = plotTrackDefinition;
m_grid = new QwtPlotGrid();
m_grid->attach(this);
setFocusPolicy(Qt::ClickFocus);
setDefaults();
// Create a plot picker to display values next to mouse cursor
m_curvePointTracker = new RiuQwtCurvePointTracker(this, false);
}
//--------------------------------------------------------------------------------------------------
@ -74,8 +68,7 @@ RiuWellLogTrack::RiuWellLogTrack(RimWellLogTrack* plotTrackDefinition, QWidget*
//--------------------------------------------------------------------------------------------------
RiuWellLogTrack::~RiuWellLogTrack()
{
m_grid->detach();
delete m_grid;
}
@ -84,33 +77,13 @@ RiuWellLogTrack::~RiuWellLogTrack()
//--------------------------------------------------------------------------------------------------
void RiuWellLogTrack::setDefaults()
{
QPalette newPalette(palette());
newPalette.setColor(QPalette::Background, Qt::white);
setPalette(newPalette);
setAutoFillBackground(true);
setCanvasBackground(Qt::white);
QFrame* canvasFrame = dynamic_cast<QFrame*>(canvas());
if (canvasFrame)
{
canvasFrame->setFrameShape(QFrame::NoFrame);
}
canvas()->setMouseTracking(true);
canvas()->installEventFilter(this);
QPen gridPen(Qt::SolidLine);
gridPen.setColor(Qt::lightGray);
m_grid->setPen(gridPen);
RiuSummaryQwtPlot::setCommonPlotBehaviour(this);
enableAxis(QwtPlot::xTop, true);
enableAxis(QwtPlot::yLeft, true);
enableAxis(QwtPlot::xBottom, false);
enableAxis(QwtPlot::yRight, false);
plotLayout()->setAlignCanvasToScales(true);
axisScaleEngine(QwtPlot::yLeft)->setAttribute(QwtScaleEngine::Inverted, true);
// Align the canvas with the actual min and max values of the curves
@ -119,28 +92,6 @@ void RiuWellLogTrack::setDefaults()
setAxisScale(QwtPlot::yLeft, 1000, 0);
setAxisScale(QwtPlot::xTop, -10, 100);
QFont xAxisFont = axisFont(QwtPlot::xTop);
xAxisFont.setPixelSize(9);
setAxisFont(QwtPlot::xTop, xAxisFont);
QwtText axisTitleX = axisTitle(QwtPlot::yLeft);
QFont xAxisTitleFont = axisTitleX.font();
xAxisTitleFont.setPixelSize(9);
xAxisTitleFont.setBold(false);
axisTitleX.setFont(xAxisTitleFont);
axisTitleX.setRenderFlags(Qt::AlignRight);
setAxisTitle(QwtPlot::xTop, axisTitleX);
QFont yAxisFont = axisFont(QwtPlot::yLeft);
yAxisFont.setPixelSize(9);
setAxisFont(QwtPlot::yLeft, yAxisFont);
QwtText axisTitleY = axisTitle(QwtPlot::yLeft);
QFont yAxisTitleFont = axisTitleY.font();
yAxisTitleFont.setPixelSize(9);
yAxisTitleFont.setBold(false);
axisTitleY.setFont(yAxisTitleFont);
axisTitleY.setRenderFlags(Qt::AlignRight);
setAxisTitle(QwtPlot::yLeft, axisTitleY);
}
//--------------------------------------------------------------------------------------------------
@ -303,13 +254,6 @@ QSize RiuWellLogTrack::minimumSizeHint() const
return QSize(0, 0);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellLogTrack::leaveEvent(QEvent *)
{
m_curvePointTracker->removeMarkerOnFocusLeave();
}
//--------------------------------------------------------------------------------------------------
///

View File

@ -60,7 +60,6 @@ protected:
virtual void focusInEvent(QFocusEvent* event);
virtual QSize sizeHint() const;
virtual QSize minimumSizeHint() const;
virtual void leaveEvent(QEvent *) override;
private:
void setDefaults();
@ -68,7 +67,6 @@ private:
private:
caf::PdmPointer<RimWellLogTrack> m_plotTrackDefinition;
QwtPlotGrid* m_grid;
RiuQwtCurvePointTracker* m_curvePointTracker;
};