25 #include <QContextMenuEvent>
29 , mDefaultActions( 0 )
32 setHeaderHidden(
true );
34 setDragEnabled(
true );
35 setAcceptDrops(
true );
36 setDropIndicatorShown(
true );
37 setEditTriggers( EditKeyPressed );
38 setExpandsOnDoubleClick(
false );
40 setSelectionMode( ExtendedSelection );
53 if ( !qobject_cast<QgsLayerTreeModel*>( model ) )
56 connect( model, SIGNAL( rowsInserted( QModelIndex,
int,
int ) ),
this, SLOT(
modelRowsInserted( QModelIndex,
int,
int ) ) );
57 connect( model, SIGNAL( rowsRemoved( QModelIndex,
int,
int ) ),
this, SLOT(
modelRowsRemoved() ) );
63 connect( selectionModel(), SIGNAL( currentChanged( QModelIndex, QModelIndex ) ),
this, SLOT(
onCurrentChanged() ) );
97 setCurrentIndex( QModelIndex() );
114 QModelIndex idx = indexAt( event->pos() );
115 if ( !idx.isValid() )
116 setCurrentIndex( QModelIndex() );
119 if ( menu && menu->actions().count() != 0 )
120 menu->exec( mapToGlobal( event->pos() ) );
134 QStringList expandedNodeKeys = parentNode->
customProperty(
"expandedLegendNodes" ).toStringList();
135 if ( expandedNodeKeys.isEmpty() )
141 if ( expandedNodeKeys.contains( ruleKey ) )
147 QList<QgsLayerTreeNode*> children = parentNode->
children();
148 for (
int i = start; i <= end; ++i )
167 node->setExpanded( isExpanded( index ) );
172 QStringList lst = node->layerNode()->customProperty(
"expandedLegendNodes" ).toStringList();
173 bool expanded = isExpanded( index );
174 bool isInList = lst.contains( ruleKey );
175 if ( expanded && !isInList )
177 lst.append( ruleKey );
178 node->layerNode()->setCustomProperty(
"expandedLegendNodes", lst );
180 else if ( !expanded && isInList )
182 lst.removeAll( ruleKey );
183 node->layerNode()->setCustomProperty(
"expandedLegendNodes", lst );
191 QString layerCurrentID = layerCurrent ? layerCurrent->
id() : QString();
196 QModelIndex nodeLayerIndex;
212 if ( isExpanded( idx ) != expanded )
213 setExpanded( idx, expanded );
283 QList<QgsLayerTreeLayer*> layerNodes;
294 QList<QgsMapLayer*> list;
298 list << node->
layer();