1#include <Gui/SelectionManager/SelectionManager.hpp>
3#include <Core/Utils/Log.hpp>
4#include <Engine/RadiumEngine.hpp>
11using namespace Core::Utils;
13SelectionManager::SelectionManager( ItemModel* model, QObject* parent ) :
14 QItemSelectionModel( model, parent ) {
15 connect(
this, &SelectionManager::selectionChanged,
this, &SelectionManager::printSelection );
16 connect( model, &ItemModel::modelRebuilt,
this, &SelectionManager::onModelRebuilt );
19bool SelectionManager::isSelected(
const ItemEntry& ent )
const {
20 QModelIndex idx = itemModel()->findEntryIndex( ent );
21 if ( idx.isValid() ) {
22 const auto& pos =
std::find( selectedIndexes().begin(), selectedIndexes().end(), idx );
23 return ( pos != selectedIndexes().end() );
30 result.
reserve( uint( selectedIndexes().size() ) );
31 for (
const auto& idx : selectedIndexes() ) {
32 result.
push_back( itemModel()->getEntry( idx ) );
33 CORE_ASSERT( result.
back().isValid(),
"Invalid entry in selection" );
38const ItemEntry& SelectionManager::currentItem()
const {
40 return itemModel()->getEntry( currentIndex() );
43void SelectionManager::select(
const ItemEntry& ent, QItemSelectionModel::SelectionFlags command ) {
44 QModelIndex idx = itemModel()->findEntryIndex( ent );
45 if ( idx.isValid() && ent.
isSelectable() ) { QItemSelectionModel::select( idx, command ); }
48void SelectionManager::setCurrentEntry(
const ItemEntry& ent,
49 QItemSelectionModel::SelectionFlags command ) {
50 QModelIndex idx = itemModel()->findEntryIndex( ent );
51 if ( idx.isValid() ) {
52 QItemSelectionModel::setCurrentIndex( idx, command );
53 emit currentChanged( idx, idx );
57void SelectionManager::onModelRebuilt() {
61void SelectionManager::printSelection()
const {
62 LOG( logDEBUG ) <<
"Selected entries : ";
63 for (
const auto& ent : selectedEntries() ) {
64 LOG( logDEBUG ) <<
getEntryName( Ra::Engine::RadiumEngine::getInstance(), ent );
66 LOG( logDEBUG ) <<
"Current : "
67 <<
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.