#1000 System : Prepare for handling of copy/paste actions

This commit is contained in:
Magne Sjaastad 2016-11-24 08:03:45 +01:00
parent d59a1a90c6
commit a70939f1b6
4 changed files with 97 additions and 43 deletions

View File

@ -28,6 +28,7 @@
#include "RimIdenticalGridCaseGroup.h"
#include "RiuMainWindow.h"
#include "cafCmdFeature.h"
#include "cafCmdFeatureManager.h"
#include "cafPdmUiTreeView.h"
#include "cafSelectionManager.h"
@ -54,51 +55,34 @@ bool RiuTreeViewEventFilter::eventFilter(QObject *obj, QEvent *event)
{
QKeyEvent* keyEvent = static_cast<QKeyEvent *>(event);
QString featureToActivate;
caf::PdmUiItem* uiItem = caf::SelectionManager::instance()->selectedItem();
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))
QAction* actionToTrigger = caf::CmdFeatureManager::instance()->action("RicCopyReferencesToClipboardFeature");
assert(actionToTrigger);
actionToTrigger->trigger();
keyEvent->setAccepted(true);
return true;
}
else if (keyEvent->matches(QKeySequence::Paste))
{
std::vector<caf::CmdFeature*> matches = caf::CmdFeatureManager::instance()->commandFeaturesMatchingSubString("Paste");
for (caf::CmdFeature* feature : matches)
{
featureToActivate = "RicCopyReferencesToClipboardFeature";
if (feature->canFeatureBeExecuted())
{
feature->actionTriggered(false);
keyEvent->setAccepted(true);
return true;
}
}
}
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);
actionToTrigger->trigger();
keyEvent->setAccepted(true);
return true;
}
if (!RiuMainWindow::instance()->projectTreeView()->isTreeItemEditWidgetActive())

View File

@ -59,6 +59,16 @@ CmdFeatureManager::CmdFeatureManager()
{
CmdDeleteItemFeature::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

View File

@ -71,15 +71,20 @@ public:
CmdFeature* getCommandFeature(const std::string& commandId);
std::vector<CmdFeature*> commandFeaturesMatchingSubString(const std::string& subString) const;
private:
CmdFeatureManager();
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> createFeature(const std::string& commandId);
std::pair<CmdFeature*, size_t> findExistingCmdFeature(const std::string& commandId);
std::vector<CmdFeature*> m_commandFeatures;
std::map<std::string , size_t > m_commandIdToFeatureIdxMap;
std::map<QAction*, size_t > m_actionToFeatureIdxMap;
CmdFeature* commandFeature(const std::string& commandId) const;
private:
std::vector<CmdFeature*> m_commandFeatures;
std::map<std::string , size_t > m_commandIdToFeatureIdxMap;
std::map<QAction*, size_t > m_actionToFeatureIdxMap;
};

View File

@ -39,6 +39,7 @@
#include <assert.h>
#include <map>
#include <vector>
#include <cstddef>
// 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:
Factory () {}