1#include <Core/CoreMacros.hpp>
2#include <Core/Utils/Log.hpp>
3#include <Engine/RadiumEngine.hpp>
4#include <Engine/Scene/ItemEntry.hpp>
5#include <Gui/SelectionManager/SelectionManager.hpp>
6#include <Gui/TreeModel/EntityTreeModel.hpp>
19using namespace Core::Utils;
21SelectionManager::SelectionManager( ItemModel* model, QObject* parent ) :
22 QItemSelectionModel( model, parent ) {
23 connect(
this, &SelectionManager::selectionChanged,
this, &SelectionManager::printSelection );
24 connect( model, &ItemModel::modelRebuilt,
this, &SelectionManager::onModelRebuilt );
27bool SelectionManager::isSelected(
const ItemEntry& ent )
const {
28 QModelIndex idx = itemModel()->findEntryIndex( ent );
29 if ( idx.isValid() ) {
30 const auto& pos =
std::find( selectedIndexes().begin(), selectedIndexes().end(), idx );
31 return ( pos != selectedIndexes().end() );
38 result.
reserve( uint( selectedIndexes().size() ) );
39 for (
const auto& idx : selectedIndexes() ) {
40 result.
push_back( itemModel()->getEntry( idx ) );
41 CORE_ASSERT( result.
back().isValid(),
"Invalid entry in selection" );
46const ItemEntry& SelectionManager::currentItem()
const {
48 return itemModel()->getEntry( currentIndex() );
51void SelectionManager::select(
const ItemEntry& ent, QItemSelectionModel::SelectionFlags command ) {
52 QModelIndex idx = itemModel()->findEntryIndex( ent );
53 if ( idx.isValid() && ent.
isSelectable() ) { QItemSelectionModel::select( idx, command ); }
56void SelectionManager::setCurrentEntry(
const ItemEntry& ent,
57 QItemSelectionModel::SelectionFlags command ) {
58 QModelIndex idx = itemModel()->findEntryIndex( ent );
59 if ( idx.isValid() ) {
60 QItemSelectionModel::setCurrentIndex( idx, command );
61 emit currentChanged( idx, idx );
65void SelectionManager::onModelRebuilt() {
69void SelectionManager::printSelection()
const {
70 LOG( logDEBUG ) <<
"Selected entries : ";
71 for (
const auto& ent : selectedEntries() ) {
72 LOG( logDEBUG ) <<
getEntryName( Ra::Engine::RadiumEngine::getInstance(), ent );
74 LOG( logDEBUG ) <<
"Current : "
75 <<
getEntryName( Ra::Engine::RadiumEngine::getInstance(), currentItem() );
std::string getEntryName(const Engine::RadiumEngine *engine, const ItemEntry &ent)
Returns the name associated to the given item.
hepler function to manage enum as underlying types in VariableSet
bool isSelectable() const
Returns true if the item can be selected.