File indexing completed on 2024-03-24 05:53:11
0001 /* This file is part of the KDE project 0002 Copyright (C) 2000 David Faure <faure@kde.org> 0003 Copyright (C) 2002-2003 Alexander Kellett <lypanov@kde.org> 0004 Copyright (C) 2005 Daniel Teske <teske@squorn.de> 0005 0006 This program is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU General Public License as 0008 published by the Free Software Foundation; either version 2 of 0009 the License, or (at your option) version 3. 0010 0011 This program is distributed in the hope that it will be useful, 0012 but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 GNU General Public License for more details. 0015 0016 You should have received a copy of the GNU General Public License 0017 along with this program. If not, see <http://www.gnu.org/licenses/> 0018 */ 0019 0020 #include "view.h" 0021 0022 #include <KBookmark> 0023 0024 KBookmarkView::KBookmarkView(QWidget *parent) 0025 : QTreeView(parent) 0026 , m_loadingState(false) 0027 { 0028 setAcceptDrops(true); 0029 setDefaultDropAction(Qt::MoveAction); 0030 connect(this, &QTreeView::expanded, this, &KBookmarkView::slotExpanded); 0031 connect(this, &QTreeView::collapsed, this, &KBookmarkView::slotCollapsed); 0032 } 0033 0034 KBookmarkView::~KBookmarkView() 0035 { 0036 } 0037 0038 void KBookmarkView::loadFoldedState() 0039 { 0040 m_loadingState = true; 0041 loadFoldedState(QModelIndex()); 0042 m_loadingState = false; 0043 } 0044 0045 void KBookmarkView::loadFoldedState(const QModelIndex &parentIndex) 0046 { 0047 const int count = model()->rowCount(parentIndex); 0048 for (int row = 0; row < count; ++row) { 0049 const QModelIndex index = model()->index(row, 0, parentIndex); 0050 const KBookmark bk = bookmarkForIndex(index); 0051 if (bk.isNull()) { 0052 expand(index); 0053 } else if (bk.isGroup()) { 0054 setExpanded(index, bk.toGroup().isOpen()); 0055 loadFoldedState(index); 0056 } 0057 } 0058 } 0059 0060 void KBookmarkView::slotExpanded(const QModelIndex &index) 0061 { 0062 if (!m_loadingState) { 0063 KBookmark bk = bookmarkForIndex(index); 0064 bk.internalElement().setAttribute(QStringLiteral("folded"), QStringLiteral("no")); 0065 } 0066 } 0067 0068 void KBookmarkView::slotCollapsed(const QModelIndex &index) 0069 { 0070 if (!m_loadingState) { 0071 KBookmark bk = bookmarkForIndex(index); 0072 bk.internalElement().setAttribute(QStringLiteral("folded"), QStringLiteral("yes")); 0073 } 0074 } 0075 0076 #include "moc_view.cpp"