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:
parent
f099b8a747
commit
20f9bf4318
@ -55,6 +55,7 @@ void RicToggleMeasurementModeFeature::onActionTriggered(bool isChecked)
|
||||
{
|
||||
auto meas = measurement();
|
||||
meas->setMeasurementMode(!meas->isInMeasurementMode());
|
||||
|
||||
refreshActionLook();
|
||||
}
|
||||
|
||||
@ -64,12 +65,29 @@ void RicToggleMeasurementModeFeature::onActionTriggered(bool isChecked)
|
||||
void RicToggleMeasurementModeFeature::setupActionLook(QAction* actionToSetup)
|
||||
{
|
||||
actionToSetup->setText("Measurement Mode");
|
||||
actionToSetup->setIcon(QIcon(":/Ruler16x16.png"));
|
||||
|
||||
/*
|
||||
auto* meas = measurement();
|
||||
if (meas && meas->isInMeasurementMode())
|
||||
actionToSetup->setIcon(QIcon(":/NoRuler16x16.png"));
|
||||
else
|
||||
actionToSetup->setIcon(QIcon(":/Ruler16x16.png"));
|
||||
*/
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicToggleMeasurementModeFeature::isCommandChecked()
|
||||
{
|
||||
auto meas = measurement();
|
||||
if (meas)
|
||||
{
|
||||
return meas->isInMeasurementMode();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -33,14 +33,14 @@ class RicToggleMeasurementModeFeature : public caf::CmdFeature
|
||||
{
|
||||
CAF_CMD_HEADER_INIT;
|
||||
|
||||
public:
|
||||
void refreshActionLook();
|
||||
|
||||
protected:
|
||||
// Overrides
|
||||
bool isCommandEnabled() override;
|
||||
void onActionTriggered( bool isChecked ) override;
|
||||
void setupActionLook(QAction* actionToSetup) override;
|
||||
bool isCommandChecked() override;
|
||||
|
||||
private:
|
||||
void refreshActionLook();
|
||||
|
||||
private:
|
||||
RimMeasurement* measurement() const;
|
||||
|
@ -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,14 +54,28 @@ 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;
|
||||
};
|
@ -871,6 +871,7 @@ void RiuMainWindow::slotRefreshViewActions()
|
||||
|
||||
updateScaleValue();
|
||||
|
||||
{
|
||||
QStringList commandIds;
|
||||
commandIds << "RicLinkVisibleViewsFeature"
|
||||
<< "RicTileWindowsFeature"
|
||||
@ -878,14 +879,13 @@ void RiuMainWindow::slotRefreshViewActions()
|
||||
<< "RicViewZoomAllFeature";
|
||||
|
||||
caf::CmdFeatureManager::instance()->refreshEnabledState(commandIds);
|
||||
}
|
||||
|
||||
|
||||
caf::CmdFeatureManager* cmdFeatureMgr = caf::CmdFeatureManager::instance();
|
||||
auto feature = dynamic_cast<RicToggleMeasurementModeFeature*>(
|
||||
cmdFeatureMgr->getCommandFeature("RicToggleMeasurementModeFeature"));
|
||||
if (feature)
|
||||
{
|
||||
feature->refreshActionLook();
|
||||
QStringList commandIds;
|
||||
commandIds << "RicToggleMeasurementModeFeature";
|
||||
|
||||
caf::CmdFeatureManager::instance()->refreshCheckedState(commandIds);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user