26 , mSettingsSection(
"browser" )
27 , mBrowserModel( nullptr )
37 mBrowserModel =
model;
66 void QgsBrowserTreeView::saveState()
70 settings.
setValue( expandedPathsKey(), expandedPaths );
74 void QgsBrowserTreeView::restoreState()
83 Q_FOREACH (
const QString& path, mExpandPaths )
92 if ( ptr && ( ptr->
capabilities2() & QgsDataItem::Capability::Collapse ) )
98 expandIndexSet.
insert( parentIndex );
102 expandIndexSet.
insert( expandIndex );
109 QgsDebugMsg(
"index for path " + path +
" not found" );
112 Q_FOREACH (
const QModelIndex& expandIndex, expandIndexSet )
114 expandTree( expandIndex );
135 expandTree( parentIndex );
138 bool QgsBrowserTreeView::treeExpanded(
const QModelIndex & index )
146 return treeExpanded( parentIndex );
188 if ( !treeExpanded( parentIndex ) )
190 Q_FOREACH (
const QString& path, mExpandPaths )
198 for (
int i = start; i <= end; i++ )
202 QString escapedChildPath = childPath;
203 escapedChildPath.
replace(
'|',
"\\|" );
205 QgsDebugMsgLevel(
"childPath = " + childPath +
" escapedChildPath = " + escapedChildPath, 2 );
206 if ( mExpandPaths.
contains( childPath ) || mExpandPaths.
indexOf(
QRegExp(
"^" + escapedChildPath +
"/.*" ) ) != -1 )
214 QString QgsBrowserTreeView::expandedPathsKey()
const 216 return '/' + mSettingsSection +
"/expandedPaths";
231 QStringList childrenPaths = expandedPathsList( childIndex );
232 if ( !childrenPaths.
isEmpty() )
234 paths.
append( childrenPaths );
virtual int rowCount(const QModelIndex &parent) const=0
virtual void setModel(QAbstractItemModel *model) override
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const=0
void setBrowserModel(QgsBrowserModel *model)
Set the browser model.
QModelIndex findPath(const QString &path, Qt::MatchFlag matchFlag=Qt::MatchExactly)
Return index of item with given path.
bool contains(const QString &str, Qt::CaseSensitivity cs) const
QString join(const QString &separator) const
const_iterator insert(const T &value)
QgsBrowserTreeView(QWidget *parent=nullptr)
bool hasExpandedDescendant(const QModelIndex &index) const
void setValue(const QString &key, const QVariant &value)
void append(const T &value)
#define QgsDebugMsgLevel(str, level)
virtual void rowsInserted(const QModelIndex &parent, int start, int end)
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
QgsDataItem * dataItem(const QModelIndex &idx) const
virtual void rowsInserted(const QModelIndex &parentIndex, int start, int end) override
virtual QVariant data(const QModelIndex &index, int role) const=0
bool isExpanded(const QModelIndex &index) const
virtual QModelIndex parent(const QModelIndex &index) const=0
Base class for all items in the model.
QString & replace(int position, int n, QChar after)
QVariant value(const QString &key, const QVariant &defaultValue) const
virtual void showEvent(QShowEvent *e) override
QStringList toStringList() const
virtual void setModel(QAbstractItemModel *model)
virtual void hideEvent(QHideEvent *e) override
int indexOf(const QRegExp &rx, int from) const
void expand(const QModelIndex &index)
QAbstractItemModel * model() const
QgsBrowserModel * browserModel()
Return the browser model.
bool removeOne(const T &value)
virtual Capabilities capabilities2() const