26 , mSettingsSection(
"browser" )
63 void QgsBrowserTreeView::saveState()
67 QStringList expandedPaths = expandedPathsList( QModelIndex() );
68 settings.setValue( expandedPathsKey(), expandedPaths );
69 QgsDebugMsg(
"expandedPaths = " + expandedPaths.join(
" " ) );
72 void QgsBrowserTreeView::restoreState()
76 mExpandPaths = settings.value( expandedPathsKey(), QVariant() ).toStringList();
78 QgsDebugMsg(
"mExpandPaths = " + mExpandPaths.join(
" " ) );
79 if ( !mExpandPaths.isEmpty() )
81 QSet<QModelIndex> expandIndexSet;
82 foreach ( QString path, mExpandPaths )
85 if ( expandIndex.isValid() )
86 expandIndexSet.insert( expandIndex );
89 QgsDebugMsg(
"index for path " + path +
" not found" );
92 foreach ( QModelIndex expandIndex, expandIndexSet )
94 expandTree( expandIndex );
105 void QgsBrowserTreeView::expandTree(
const QModelIndex &
index )
114 QModelIndex parentIndex = model()->parent( index );
115 if ( parentIndex.isValid() )
116 expandTree( parentIndex );
119 bool QgsBrowserTreeView::treeExpanded(
const QModelIndex & index )
123 if ( !isExpanded( index ) )
125 QModelIndex parentIndex = model()->parent( index );
126 if ( parentIndex.isValid() )
127 return treeExpanded( parentIndex );
137 for (
int i = 0 ; i < model()->rowCount( index ); i++ )
139 QModelIndex childIndex = model()->index( i, 0, index );
140 if ( isExpanded( childIndex ) )
157 if ( mExpandPaths.isEmpty() )
166 mExpandPaths.removeOne( parentPath );
169 if ( !treeExpanded( parentIndex ) )
171 foreach ( QString path, mExpandPaths )
173 if ( path.startsWith( parentPath +
"/" ) )
174 mExpandPaths.removeOne( path );
179 for (
int i = start; i <= end; i++ )
181 QModelIndex childIndex = model()->index( i, 0, parentIndex );
183 QString escapedChildPath = childPath;
184 escapedChildPath.replace(
"|",
"\\|" );
186 QgsDebugMsgLevel(
"childPath = " + childPath +
" escapedChildPath = " + escapedChildPath, 2 );
187 if ( mExpandPaths.contains( childPath ) || mExpandPaths.indexOf( QRegExp(
"^" + escapedChildPath +
"/.*" ) ) != -1 )
190 expand( childIndex );
195 QString QgsBrowserTreeView::expandedPathsKey()
const
197 return "/" + mSettingsSection +
"/expandedPaths";
200 QStringList QgsBrowserTreeView::expandedPathsList(
const QModelIndex & index )
207 for (
int i = 0; i < model()->rowCount( index ); i++ )
209 QModelIndex childIndex = model()->index( i, 0, index );
210 if ( isExpanded( childIndex ) )
212 QStringList childrenPaths = expandedPathsList( childIndex );
213 if ( !childrenPaths.isEmpty() )
215 paths.append( childrenPaths );