mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-09 23:16:00 -06:00
#862 Added scale picker to select axis
This commit is contained in:
parent
71f1966c1c
commit
d5213b2a43
@ -120,6 +120,8 @@ set( USER_INTERFACE_FILES
|
||||
UserInterface/RiuPropertyViewTabWidget.cpp
|
||||
UserInterface/RiuRecentFileActionProvider.h
|
||||
UserInterface/RiuRecentFileActionProvider.cpp
|
||||
UserInterface/RiuQwtScalePicker.h
|
||||
UserInterface/RiuQwtScalePicker.cpp
|
||||
)
|
||||
|
||||
set( SOCKET_INTERFACE_FILES
|
||||
@ -233,6 +235,7 @@ set ( QT_MOC_HEADERS
|
||||
UserInterface/RiuWellLogTrack.h
|
||||
UserInterface/RiuRecentFileActionProvider.h
|
||||
UserInterface/RiuSummaryQwtPlot.h
|
||||
UserInterface/RiuQwtScalePicker.h
|
||||
)
|
||||
|
||||
qt4_wrap_cpp( MOC_FILES_CPP ${QT_MOC_HEADERS} )
|
||||
|
@ -142,6 +142,26 @@ bool RimSummaryPlot::isLogarithmicScaleEnabled(RimDefines::PlotAxis plotAxis) co
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryPlot::selectAxisInPropertyEditor(int axis)
|
||||
{
|
||||
RiuMainPlotWindow* plotwindow = RiaApplication::instance()->getOrCreateAndShowMainPlotWindow();
|
||||
if (axis == QwtPlot::yLeft)
|
||||
{
|
||||
plotwindow->selectAsCurrentItem(m_leftYAxisProperties);
|
||||
}
|
||||
else if (axis == QwtPlot::yRight)
|
||||
{
|
||||
plotwindow->selectAsCurrentItem(m_rightYAxisProperties);
|
||||
}
|
||||
else if (axis == QwtPlot::xBottom)
|
||||
{
|
||||
plotwindow->selectAsCurrentItem(this);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -79,6 +79,7 @@ public:
|
||||
|
||||
bool isLogarithmicScaleEnabled(RimDefines::PlotAxis plotAxis) const;
|
||||
|
||||
void selectAxisInPropertyEditor(int axis);
|
||||
protected:
|
||||
// Overridden PDM methods
|
||||
virtual caf::PdmFieldHandle* objectToggleField() { return &m_showWindow; }
|
||||
|
93
ApplicationCode/UserInterface/RiuQwtScalePicker.cpp
Normal file
93
ApplicationCode/UserInterface/RiuQwtScalePicker.cpp
Normal file
@ -0,0 +1,93 @@
|
||||
// Based on the example scalepicker from the Qwt/examples/event_filter
|
||||
|
||||
#include "RiuQwtScalePicker.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
|
||||
#include <qwt_plot.h>
|
||||
#include <qwt_scale_widget.h>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiuQwtScalePicker::RiuQwtScalePicker( QwtPlot *plot ):
|
||||
QObject( plot )
|
||||
{
|
||||
for ( uint i = 0; i < QwtPlot::axisCnt; i++ )
|
||||
{
|
||||
QwtScaleWidget *scaleWidget = plot->axisWidget( i );
|
||||
if ( scaleWidget )
|
||||
scaleWidget->installEventFilter( this );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiuQwtScalePicker::eventFilter( QObject *object, QEvent *event )
|
||||
{
|
||||
if ( event->type() == QEvent::MouseButtonPress )
|
||||
{
|
||||
QwtScaleWidget *scaleWidget = qobject_cast<QwtScaleWidget *>( object );
|
||||
if ( scaleWidget )
|
||||
{
|
||||
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>( event );
|
||||
mouseClicked( scaleWidget, mouseEvent->pos() );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return QObject::eventFilter( object, event );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQwtScalePicker::mouseClicked( const QwtScaleWidget *scale, const QPoint &pos )
|
||||
{
|
||||
QRect rect = scale->rect();
|
||||
|
||||
int margin = 10; // 10 pixels tolerance
|
||||
rect.setRect( rect.x() - margin, rect.y() - margin,
|
||||
rect.width() + 2 * margin, rect.height() + 2 * margin );
|
||||
|
||||
if ( rect.contains( pos ) ) // No click on the title
|
||||
{
|
||||
// translate the position in a value on the scale
|
||||
|
||||
double value = 0.0;
|
||||
int axis = -1;
|
||||
|
||||
const QwtScaleDraw *sd = scale->scaleDraw();
|
||||
switch( scale->alignment() )
|
||||
{
|
||||
case QwtScaleDraw::LeftScale:
|
||||
{
|
||||
value = sd->scaleMap().invTransform( pos.y() );
|
||||
axis = QwtPlot::yLeft;
|
||||
break;
|
||||
}
|
||||
case QwtScaleDraw::RightScale:
|
||||
{
|
||||
value = sd->scaleMap().invTransform( pos.y() );
|
||||
axis = QwtPlot::yRight;
|
||||
break;
|
||||
}
|
||||
case QwtScaleDraw::BottomScale:
|
||||
{
|
||||
value = sd->scaleMap().invTransform( pos.x() );
|
||||
axis = QwtPlot::xBottom;
|
||||
break;
|
||||
}
|
||||
case QwtScaleDraw::TopScale:
|
||||
{
|
||||
value = sd->scaleMap().invTransform( pos.x() );
|
||||
axis = QwtPlot::xTop;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Q_EMIT clicked( axis, value );
|
||||
}
|
||||
}
|
||||
|
24
ApplicationCode/UserInterface/RiuQwtScalePicker.h
Normal file
24
ApplicationCode/UserInterface/RiuQwtScalePicker.h
Normal file
@ -0,0 +1,24 @@
|
||||
// Based on the example scalepicker from the Qwt/examples/event_filter
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QRect>
|
||||
|
||||
class QwtPlot;
|
||||
class QwtScaleWidget;
|
||||
|
||||
class RiuQwtScalePicker : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
RiuQwtScalePicker(QwtPlot *plot);
|
||||
|
||||
virtual bool eventFilter( QObject *, QEvent * );
|
||||
|
||||
Q_SIGNALS:
|
||||
void clicked( int axis, double value );
|
||||
|
||||
private:
|
||||
void mouseClicked( const QwtScaleWidget *, const QPoint & );
|
||||
};
|
@ -19,9 +19,12 @@
|
||||
#include "RiuSummaryQwtPlot.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
|
||||
#include "RimSummaryCurve.h"
|
||||
#include "RimSummaryPlot.h"
|
||||
|
||||
#include "RiuMainPlotWindow.h"
|
||||
#include "RiuQwtScalePicker.h"
|
||||
|
||||
#include "qwt_date_scale_draw.h"
|
||||
#include "qwt_date_scale_engine.h"
|
||||
@ -69,6 +72,9 @@ RiuSummaryQwtPlot::RiuSummaryQwtPlot(RimSummaryPlot* plotDefinition, QWidget* pa
|
||||
m_zoomerRight = new QwtPlotZoomer(canvas());
|
||||
m_zoomerRight->setAxis(xTop, yRight);
|
||||
m_zoomerRight->setTrackerMode(QwtPicker::AlwaysOff);
|
||||
|
||||
RiuQwtScalePicker* scalePicker = new RiuQwtScalePicker(this);
|
||||
connect(scalePicker, SIGNAL(clicked(int, double)), this, SLOT(onAxisClicked(int, double)));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -296,3 +302,13 @@ void RiuSummaryQwtPlot::onZoomedSlot()
|
||||
|
||||
m_plotDefinition->updateZoomFromQwt();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuSummaryQwtPlot::onAxisClicked(int axis, double value)
|
||||
{
|
||||
if (!m_plotDefinition) return;
|
||||
|
||||
m_plotDefinition->selectAxisInPropertyEditor(axis);
|
||||
}
|
||||
|
@ -61,6 +61,7 @@ private:
|
||||
|
||||
private slots:
|
||||
void onZoomedSlot( );
|
||||
void onAxisClicked(int axis, double value);
|
||||
|
||||
private:
|
||||
QwtPlotGrid* m_grid;
|
||||
|
Loading…
Reference in New Issue
Block a user