mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#3935 Measurements : Add Esc button to abort measurement mode
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
|
||||
set (SOURCE_GROUP_HEADER_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimMeasurement.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuMeasurementEventFilter.h
|
||||
)
|
||||
|
||||
set (SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimMeasurement.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuMeasurementEventFilter.cpp
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES
|
||||
@@ -16,6 +18,7 @@ ${SOURCE_GROUP_SOURCE_FILES}
|
||||
)
|
||||
|
||||
set (QT_MOC_HEADERS
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuMeasurementEventFilter.h
|
||||
${QT_MOC_HEADERS}
|
||||
)
|
||||
|
||||
|
||||
@@ -24,9 +24,11 @@
|
||||
|
||||
#include "MeasurementCommands/RicMeasurementPickEventHandler.h"
|
||||
|
||||
#include "RiuMeasurementEventFilter.h"
|
||||
#include "RiuViewerCommands.h"
|
||||
|
||||
#include "cvfGeometryTools.h"
|
||||
#include "RiuMainWindow.h"
|
||||
|
||||
CAF_PDM_SOURCE_INIT(RimMeasurement, "RimMeasurement");
|
||||
|
||||
@@ -52,12 +54,26 @@ void RimMeasurement::setMeasurementMode(bool measurementMode)
|
||||
m_isInMeasurementMode = measurementMode;
|
||||
|
||||
if (m_isInMeasurementMode)
|
||||
{
|
||||
RiuViewerCommands::setPickEventHandler(RicMeasurementPickEventHandler::instance());
|
||||
|
||||
m_eventFilter = new RiuMeasurementEventFilter(this);
|
||||
m_eventFilter->registerFilter();
|
||||
}
|
||||
else
|
||||
{
|
||||
RiuViewerCommands::removePickEventHandlerIfActive(RicMeasurementPickEventHandler::instance());
|
||||
removeAllPoints();
|
||||
|
||||
if (m_eventFilter)
|
||||
{
|
||||
m_eventFilter->unregisterFilter();
|
||||
m_eventFilter->deleteLater();
|
||||
m_eventFilter = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
RiuMainWindow::instance()->refreshViewActions();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -22,7 +22,10 @@
|
||||
#include "cvfBase.h"
|
||||
#include "cvfVector3.h"
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
class Rim3dView;
|
||||
class RiuMeasurementEventFilter;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
@@ -76,4 +79,6 @@ private:
|
||||
bool m_isInMeasurementMode;
|
||||
std::vector<Vec3d> m_pointsInDomainCoords;
|
||||
caf::PdmPointer<Rim3dView> m_sourceView;
|
||||
|
||||
QPointer<RiuMeasurementEventFilter> m_eventFilter;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2019- 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 "RiuMeasurementEventFilter.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
|
||||
#include "RimMeasurement.h"
|
||||
|
||||
#include "RiuMainWindow.h"
|
||||
#include <QKeyEvent>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiuMeasurementEventFilter::RiuMeasurementEventFilter(RimMeasurement* parent)
|
||||
: QObject(nullptr)
|
||||
, m_parent(parent)
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuMeasurementEventFilter::registerFilter()
|
||||
{
|
||||
RiaApplication::instance()->installEventFilter(this);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuMeasurementEventFilter::unregisterFilter()
|
||||
{
|
||||
RiaApplication::instance()->removeEventFilter(this);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiuMeasurementEventFilter::eventFilter(QObject* obj, QEvent* event)
|
||||
{
|
||||
if (event->type() == QEvent::KeyPress)
|
||||
{
|
||||
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
|
||||
|
||||
if (keyEvent->key() == Qt::Key_Escape)
|
||||
{
|
||||
keyEvent->setAccepted(true);
|
||||
|
||||
unregisterFilter();
|
||||
|
||||
if (m_parent)
|
||||
{
|
||||
m_parent->setMeasurementMode(false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return QObject::eventFilter(obj, event);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2019- 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 "cafPdmPointer.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QEvent;
|
||||
class RimMeasurement;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
//
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class RiuMeasurementEventFilter : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit RiuMeasurementEventFilter(RimMeasurement* parent);
|
||||
|
||||
void registerFilter();
|
||||
void unregisterFilter();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||
|
||||
private:
|
||||
caf::PdmPointer<RimMeasurement> m_parent;
|
||||
};
|
||||
Reference in New Issue
Block a user