-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add class used to zoom all axis in a plot based on a screen rectangle.
- Loading branch information
Showing
8 changed files
with
171 additions
and
37 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
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
110 changes: 110 additions & 0 deletions
110
ApplicationLibCode/UserInterface/RiuQwtPlotZoomerMultiAxes.cpp
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,110 @@ | ||
///////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright (C) 2023- Equinor ASA | ||
// | ||
// ResInsight 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. | ||
// | ||
// ResInsight 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 at <http://www.gnu.org/licenses/gpl.html> | ||
// for more details. | ||
// | ||
///////////////////////////////////////////////////////////////////////////////// | ||
|
||
#include "RiuQwtPlotZoomerMultiAxes.h" | ||
|
||
#include "qwt_picker_machine.h" | ||
#include "qwt_plot.h" | ||
#include "qwt_scale_div.h" | ||
#include "qwt_scale_map.h" | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// Create a zoomer for a plot canvas. All axes will be scaled based on the rectangle in screen coordinates. | ||
//-------------------------------------------------------------------------------------------------- | ||
RiuQwtPlotZoomerMultiAxes::RiuQwtPlotZoomerMultiAxes( QWidget* canvas, bool doReplot ) | ||
: QwtPlotPicker( canvas ) | ||
{ | ||
if ( canvas ) | ||
{ | ||
setTrackerMode( ActiveOnly ); | ||
setRubberBand( RectRubberBand ); | ||
setStateMachine( new QwtPickerDragRectMachine() ); | ||
|
||
if ( doReplot && plot() ) plot()->replot(); | ||
} | ||
} | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// | ||
//-------------------------------------------------------------------------------------------------- | ||
bool RiuQwtPlotZoomerMultiAxes::end( bool ok ) | ||
{ | ||
ok = QwtPlotPicker::end( ok ); | ||
if ( !ok ) return false; | ||
|
||
QwtPlot* plot = RiuQwtPlotZoomerMultiAxes::plot(); | ||
if ( !plot ) return false; | ||
|
||
const QPolygon& pa = selection(); | ||
if ( pa.count() < 2 ) return false; | ||
|
||
QRect rect = QRect( pa.first(), pa.last() ); | ||
rect = rect.normalized(); | ||
|
||
zoomFromScreenCoords( rect ); | ||
|
||
return true; | ||
} | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// | ||
//-------------------------------------------------------------------------------------------------- | ||
void RiuQwtPlotZoomerMultiAxes::zoomFromScreenCoords( const QRectF& screenCoords ) | ||
{ | ||
QwtPlot* plot = RiuQwtPlotZoomerMultiAxes::plot(); | ||
if ( !plot ) return; | ||
|
||
const bool doReplot = plot->autoReplot(); | ||
plot->setAutoReplot( false ); | ||
|
||
for ( int axisPos = 0; axisPos < QwtAxis::AxisPositions; axisPos++ ) | ||
{ | ||
const int axesCount = plot->axesCount( axisPos ); | ||
for ( int i = 0; i < axesCount; i++ ) | ||
{ | ||
const QwtAxisId axisId( axisPos, i ); | ||
|
||
// Get the scale map for the axis used to convert between screen and domain coordinates | ||
const QwtScaleMap map = plot->canvasMap( axisId ); | ||
|
||
if ( axisId.isXAxis() ) | ||
{ | ||
const double screenX1 = screenCoords.left(); | ||
const double screenX2 = screenCoords.right(); | ||
const double domainX1 = map.invTransform( screenX1 ); | ||
const double domainX2 = map.invTransform( screenX2 ); | ||
|
||
plot->setAxisScale( axisId, domainX1, domainX2 ); | ||
} | ||
else | ||
{ | ||
const double screenY1 = screenCoords.bottom(); | ||
const double screenY2 = screenCoords.top(); | ||
const double domainY1 = map.invTransform( screenY1 ); | ||
const double domainY2 = map.invTransform( screenY2 ); | ||
|
||
plot->setAxisScale( axisId, domainY1, domainY2 ); | ||
} | ||
} | ||
} | ||
|
||
plot->setAutoReplot( doReplot ); | ||
plot->replot(); | ||
|
||
emit zoomed(); | ||
} |
40 changes: 40 additions & 0 deletions
40
ApplicationLibCode/UserInterface/RiuQwtPlotZoomerMultiAxes.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,40 @@ | ||
///////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright (C) 2023- Equinor ASA | ||
// | ||
// ResInsight 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. | ||
// | ||
// ResInsight 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 at <http://www.gnu.org/licenses/gpl.html> | ||
// for more details. | ||
// | ||
///////////////////////////////////////////////////////////////////////////////// | ||
|
||
#pragma once | ||
|
||
#include "qwt_plot_picker.h" | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// | ||
//-------------------------------------------------------------------------------------------------- | ||
class RiuQwtPlotZoomerMultiAxes : public QwtPlotPicker | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit RiuQwtPlotZoomerMultiAxes( QWidget*, bool doReplot = true ); | ||
|
||
Q_SIGNALS: | ||
void zoomed(); | ||
|
||
protected: | ||
bool end( bool ok = true ) override; | ||
|
||
private: | ||
void zoomFromScreenCoords( const QRectF& screenCoords ); | ||
}; |
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