mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#1000 System : Prepare for handling of copy/paste actions
This commit is contained in:
@@ -28,6 +28,7 @@
|
|||||||
#include "RimIdenticalGridCaseGroup.h"
|
#include "RimIdenticalGridCaseGroup.h"
|
||||||
#include "RiuMainWindow.h"
|
#include "RiuMainWindow.h"
|
||||||
|
|
||||||
|
#include "cafCmdFeature.h"
|
||||||
#include "cafCmdFeatureManager.h"
|
#include "cafCmdFeatureManager.h"
|
||||||
#include "cafPdmUiTreeView.h"
|
#include "cafPdmUiTreeView.h"
|
||||||
#include "cafSelectionManager.h"
|
#include "cafSelectionManager.h"
|
||||||
@@ -54,45 +55,12 @@ bool RiuTreeViewEventFilter::eventFilter(QObject *obj, QEvent *event)
|
|||||||
{
|
{
|
||||||
QKeyEvent* keyEvent = static_cast<QKeyEvent *>(event);
|
QKeyEvent* keyEvent = static_cast<QKeyEvent *>(event);
|
||||||
|
|
||||||
QString featureToActivate;
|
|
||||||
|
|
||||||
caf::PdmUiItem* uiItem = caf::SelectionManager::instance()->selectedItem();
|
caf::PdmUiItem* uiItem = caf::SelectionManager::instance()->selectedItem();
|
||||||
if (uiItem)
|
if (uiItem)
|
||||||
{
|
|
||||||
if (dynamic_cast<RimEclipseCase*>(uiItem)
|
|
||||||
|| dynamic_cast<RimEclipseView*>(uiItem)
|
|
||||||
|| dynamic_cast<RimGeoMechCase*>(uiItem)
|
|
||||||
|| dynamic_cast<RimGeoMechView*>(uiItem))
|
|
||||||
{
|
{
|
||||||
if (keyEvent->matches(QKeySequence::Copy))
|
if (keyEvent->matches(QKeySequence::Copy))
|
||||||
{
|
{
|
||||||
featureToActivate = "RicCopyReferencesToClipboardFeature";
|
QAction* actionToTrigger = caf::CmdFeatureManager::instance()->action("RicCopyReferencesToClipboardFeature");
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (keyEvent->matches(QKeySequence::Paste))
|
|
||||||
{
|
|
||||||
if (dynamic_cast<RimIdenticalGridCaseGroup*>(uiItem)
|
|
||||||
|| dynamic_cast<RimCaseCollection*>(uiItem))
|
|
||||||
{
|
|
||||||
featureToActivate = "RicPasteEclipseCasesFeature";
|
|
||||||
}
|
|
||||||
else if (dynamic_cast<RimEclipseCase*>(uiItem)
|
|
||||||
|| dynamic_cast<RimEclipseView*>(uiItem))
|
|
||||||
{
|
|
||||||
featureToActivate = "RicPasteEclipseViewsFeature";
|
|
||||||
}
|
|
||||||
else if (dynamic_cast<RimGeoMechCase*>(uiItem)
|
|
||||||
|| dynamic_cast<RimGeoMechView*>(uiItem))
|
|
||||||
{
|
|
||||||
featureToActivate = "RicPasteGeoMechViewsFeature";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!featureToActivate.isEmpty())
|
|
||||||
{
|
|
||||||
QAction* actionToTrigger = caf::CmdFeatureManager::instance()->action(featureToActivate);
|
|
||||||
assert(actionToTrigger);
|
assert(actionToTrigger);
|
||||||
|
|
||||||
actionToTrigger->trigger();
|
actionToTrigger->trigger();
|
||||||
@@ -100,6 +68,22 @@ bool RiuTreeViewEventFilter::eventFilter(QObject *obj, QEvent *event)
|
|||||||
keyEvent->setAccepted(true);
|
keyEvent->setAccepted(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else if (keyEvent->matches(QKeySequence::Paste))
|
||||||
|
{
|
||||||
|
std::vector<caf::CmdFeature*> matches = caf::CmdFeatureManager::instance()->commandFeaturesMatchingSubString("Paste");
|
||||||
|
|
||||||
|
for (caf::CmdFeature* feature : matches)
|
||||||
|
{
|
||||||
|
if (feature->canFeatureBeExecuted())
|
||||||
|
{
|
||||||
|
feature->actionTriggered(false);
|
||||||
|
|
||||||
|
keyEvent->setAccepted(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!RiuMainWindow::instance()->projectTreeView()->isTreeItemEditWidgetActive())
|
if (!RiuMainWindow::instance()->projectTreeView()->isTreeItemEditWidgetActive())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -59,6 +59,16 @@ CmdFeatureManager::CmdFeatureManager()
|
|||||||
{
|
{
|
||||||
CmdDeleteItemFeature::idNameStatic();
|
CmdDeleteItemFeature::idNameStatic();
|
||||||
CmdAddItemFeature::idNameStatic();
|
CmdAddItemFeature::idNameStatic();
|
||||||
|
|
||||||
|
// Make sure all command features are created. The command feature is registered
|
||||||
|
// in the command factory, and instantiated when required. This will enable possibility
|
||||||
|
// of searching through all command features instead of having to use the string keys to
|
||||||
|
// be sure all command features are present.
|
||||||
|
std::vector<std::string> keys = CommandFeatureFactory::instance()->allKeys();
|
||||||
|
for (size_t i = 0; i < keys.size(); i++)
|
||||||
|
{
|
||||||
|
action(QString::fromStdString(keys[i]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@@ -152,6 +162,26 @@ std::pair<CmdFeature*, size_t> CmdFeatureManager::findExistingCmdFeature(const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
caf::CmdFeature* CmdFeatureManager::commandFeature(const std::string& commandId) const
|
||||||
|
{
|
||||||
|
std::map<std::string, size_t>::const_iterator it;
|
||||||
|
it = m_commandIdToFeatureIdxMap.find(commandId);
|
||||||
|
|
||||||
|
if (it != m_commandIdToFeatureIdxMap.end())
|
||||||
|
{
|
||||||
|
size_t itemIndex = it->second;
|
||||||
|
|
||||||
|
CmdFeature* item = m_commandFeatures[itemIndex];
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@@ -248,5 +278,27 @@ CmdFeature* CmdFeatureManager::getCommandFeature(const std::string& commandId)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
std::vector<CmdFeature*> CmdFeatureManager::commandFeaturesMatchingSubString(const std::string& subString) const
|
||||||
|
{
|
||||||
|
std::vector<CmdFeature*> matches;
|
||||||
|
|
||||||
|
std::vector<std::string> keys = CommandFeatureFactory::instance()->allKeys();
|
||||||
|
for (size_t i = 0; i < keys.size(); i++)
|
||||||
|
{
|
||||||
|
if (keys[i].find(subString) != std::string::npos)
|
||||||
|
{
|
||||||
|
caf::CmdFeature* cmdFeature = commandFeature(keys[i]);
|
||||||
|
if (cmdFeature)
|
||||||
|
{
|
||||||
|
matches.push_back(cmdFeature);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
|
||||||
} // end namespace caf
|
} // end namespace caf
|
||||||
|
|||||||
@@ -71,12 +71,17 @@ public:
|
|||||||
|
|
||||||
CmdFeature* getCommandFeature(const std::string& commandId);
|
CmdFeature* getCommandFeature(const std::string& commandId);
|
||||||
|
|
||||||
|
std::vector<CmdFeature*> commandFeaturesMatchingSubString(const std::string& subString) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CmdFeatureManager();
|
CmdFeatureManager();
|
||||||
|
|
||||||
std::pair<CmdFeature*, size_t> createFeature(const std::string& commandId);
|
std::pair<CmdFeature*, size_t> createFeature(const std::string& commandId);
|
||||||
std::pair<CmdFeature*, size_t> findExistingCmdFeature(const std::string& commandId);
|
std::pair<CmdFeature*, size_t> findExistingCmdFeature(const std::string& commandId);
|
||||||
|
|
||||||
|
CmdFeature* commandFeature(const std::string& commandId) const;
|
||||||
|
|
||||||
|
private:
|
||||||
std::vector<CmdFeature*> m_commandFeatures;
|
std::vector<CmdFeature*> m_commandFeatures;
|
||||||
std::map<std::string , size_t > m_commandIdToFeatureIdxMap;
|
std::map<std::string , size_t > m_commandIdToFeatureIdxMap;
|
||||||
std::map<QAction*, size_t > m_actionToFeatureIdxMap;
|
std::map<QAction*, size_t > m_actionToFeatureIdxMap;
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
// Taken from gtest.h
|
// Taken from gtest.h
|
||||||
@@ -132,6 +133,18 @@ namespace caf
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<KeyType> allKeys()
|
||||||
|
{
|
||||||
|
std::vector<KeyType> keys;
|
||||||
|
|
||||||
|
iterator_type entryIt;
|
||||||
|
for (entryIt = m_factoryMap.begin(); entryIt != m_factoryMap.end(); ++entryIt)
|
||||||
|
{
|
||||||
|
keys.push_back(entryIt->first);
|
||||||
|
}
|
||||||
|
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Factory () {}
|
Factory () {}
|
||||||
|
|||||||
Reference in New Issue
Block a user