mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
System : Added a temporary selection role to for application specific selection items
This commit is contained in:
@@ -30,6 +30,7 @@
|
|||||||
RiuSelectionManager::RiuSelectionManager()
|
RiuSelectionManager::RiuSelectionManager()
|
||||||
: m_notificationCenter(new RiuSelectionChangedHandler)
|
: m_notificationCenter(new RiuSelectionChangedHandler)
|
||||||
{
|
{
|
||||||
|
m_selection.resize(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@@ -37,6 +38,9 @@ RiuSelectionManager::RiuSelectionManager()
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
RiuSelectionManager::~RiuSelectionManager()
|
RiuSelectionManager::~RiuSelectionManager()
|
||||||
{
|
{
|
||||||
|
deleteAllItemsFromSelection(RUI_APPLICATION_GLOBAL);
|
||||||
|
deleteAllItemsFromSelection(RUI_TEMPORARY);
|
||||||
|
|
||||||
delete m_notificationCenter;
|
delete m_notificationCenter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,64 +56,75 @@ RiuSelectionManager* RiuSelectionManager::instance()
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RiuSelectionManager::selectedItems(std::vector<RiuSelectionItem*>& items) const
|
void RiuSelectionManager::selectedItems(std::vector<RiuSelectionItem*>& items, int role) const
|
||||||
{
|
{
|
||||||
items = m_selection;
|
const std::vector<RiuSelectionItem*>& s = m_selection[role];
|
||||||
|
|
||||||
|
items = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RiuSelectionManager::appendItemToSelection(RiuSelectionItem* item)
|
void RiuSelectionManager::appendItemToSelection(RiuSelectionItem* item, int role)
|
||||||
{
|
{
|
||||||
m_selection.push_back(item);
|
std::vector<RiuSelectionItem*>& s = m_selection[role];
|
||||||
|
|
||||||
m_notificationCenter->handleItemAppended(item);
|
s.push_back(item);
|
||||||
|
|
||||||
|
if (role == RUI_APPLICATION_GLOBAL) m_notificationCenter->handleItemAppended(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RiuSelectionManager::setSelectedItem(RiuSelectionItem* item)
|
void RiuSelectionManager::setSelectedItem(RiuSelectionItem* item, int role)
|
||||||
{
|
{
|
||||||
deleteAllItemsFromSelection();
|
deleteAllItemsFromSelection(role);
|
||||||
|
|
||||||
m_selection.push_back(item);
|
std::vector<RiuSelectionItem*>& s = m_selection[role];
|
||||||
|
|
||||||
m_notificationCenter->handleSetSelectedItem(item);
|
s.push_back(item);
|
||||||
|
|
||||||
|
if (role == RUI_APPLICATION_GLOBAL) m_notificationCenter->handleSetSelectedItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RiuSelectionManager::deleteAllItems()
|
void RiuSelectionManager::deleteAllItems(int role)
|
||||||
{
|
{
|
||||||
if (m_selection.size() == 0) return;
|
if (!isEmpty(role))
|
||||||
|
|
||||||
deleteAllItemsFromSelection();
|
|
||||||
|
|
||||||
m_notificationCenter->handleSelectionDeleted();
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
bool RiuSelectionManager::isEmpty() const
|
|
||||||
{
|
|
||||||
return m_selection.size() == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void RiuSelectionManager::deleteAllItemsFromSelection()
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < m_selection.size(); i++)
|
|
||||||
{
|
{
|
||||||
delete m_selection[i];
|
deleteAllItemsFromSelection(role);
|
||||||
|
|
||||||
|
if (role == RUI_APPLICATION_GLOBAL) m_notificationCenter->handleSelectionDeleted();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool RiuSelectionManager::isEmpty(int role) const
|
||||||
|
{
|
||||||
|
const std::vector<RiuSelectionItem*>& s = m_selection[role];
|
||||||
|
|
||||||
|
return s.size() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RiuSelectionManager::deleteAllItemsFromSelection(int role)
|
||||||
|
{
|
||||||
|
std::vector<RiuSelectionItem*>& s = m_selection[role];
|
||||||
|
|
||||||
|
for (RiuSelectionItem* item : s)
|
||||||
|
{
|
||||||
|
delete item;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_selection.clear();
|
s.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -41,6 +41,12 @@ class RimGeoMechView;
|
|||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
class RiuSelectionManager
|
class RiuSelectionManager
|
||||||
{
|
{
|
||||||
|
enum SelectionRole
|
||||||
|
{
|
||||||
|
RUI_APPLICATION_GLOBAL, // Selection role intended to manage the cells selected by left mouse click in the 3D view
|
||||||
|
RUI_TEMPORARY // Selection role intended to manage the items selected by a right mouse click in the 3D view
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RiuSelectionManager();
|
RiuSelectionManager();
|
||||||
~RiuSelectionManager();
|
~RiuSelectionManager();
|
||||||
@@ -49,26 +55,26 @@ public:
|
|||||||
|
|
||||||
// Returns selected items
|
// Returns selected items
|
||||||
// Selection manager owns the selection items
|
// Selection manager owns the selection items
|
||||||
void selectedItems(std::vector<RiuSelectionItem*>& items) const;
|
void selectedItems(std::vector<RiuSelectionItem*>& items, int role = RUI_APPLICATION_GLOBAL) const;
|
||||||
|
|
||||||
// Append item to selected items
|
// Append item to selected items
|
||||||
// SelectionManager takes ownership of the item
|
// SelectionManager takes ownership of the item
|
||||||
void appendItemToSelection(RiuSelectionItem* item);
|
void appendItemToSelection(RiuSelectionItem* item, int role = RUI_APPLICATION_GLOBAL);
|
||||||
|
|
||||||
// Set one selected item
|
// Set one selected item
|
||||||
// SelectionManager takes ownership of the item
|
// SelectionManager takes ownership of the item
|
||||||
void setSelectedItem(RiuSelectionItem* item);
|
void setSelectedItem(RiuSelectionItem* item, int role = RUI_APPLICATION_GLOBAL);
|
||||||
|
|
||||||
// Deletes all items in the SelectionManager
|
// Deletes all items in the SelectionManager
|
||||||
void deleteAllItems();
|
void deleteAllItems(int role = RUI_APPLICATION_GLOBAL);
|
||||||
|
|
||||||
bool isEmpty() const;
|
bool isEmpty(int role = RUI_APPLICATION_GLOBAL) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void deleteAllItemsFromSelection();
|
void deleteAllItemsFromSelection(int role);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector < RiuSelectionItem* > m_selection;
|
std::vector< std::vector<RiuSelectionItem*> > m_selection;
|
||||||
|
|
||||||
RiuSelectionChangedHandler* m_notificationCenter;
|
RiuSelectionChangedHandler* m_notificationCenter;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user