mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-20 00:41:23 +00:00
extract the BookmarkView in an own file, part of the bookmark model system
svn path=/trunk/KDE/kdebase/apps/; revision=1120612
This commit is contained in:
parent
47ec488e85
commit
f8221354f7
|
@ -5,6 +5,7 @@ set(kbookmarkmodel_SRCS
|
|||
commands.cpp
|
||||
model.cpp
|
||||
treeitem.cpp
|
||||
view.cpp
|
||||
)
|
||||
|
||||
kde4_add_library(kbookmarkmodel_private SHARED ${kbookmarkmodel_SRCS})
|
||||
|
|
76
keditbookmarks/kbookmarkmodel/view.cpp
Normal file
76
keditbookmarks/kbookmarkmodel/view.cpp
Normal file
|
@ -0,0 +1,76 @@
|
|||
/* This file is part of the KDE project
|
||||
Copyright (C) 2000 David Faure <faure@kde.org>
|
||||
Copyright (C) 2002-2003 Alexander Kellett <lypanov@kde.org>
|
||||
Copyright (C) 2005 Daniel Teske <teske@squorn.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) version 3.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#include "view.h"
|
||||
|
||||
#include <kbookmark.h>
|
||||
|
||||
BookmarkView::BookmarkView( QWidget * parent )
|
||||
: QTreeView(parent), m_loadingState(false)
|
||||
{
|
||||
setAcceptDrops(true);
|
||||
setDefaultDropAction(Qt::MoveAction);
|
||||
connect(this, SIGNAL(expanded(QModelIndex)), this, SLOT(slotExpanded(QModelIndex)));
|
||||
connect(this, SIGNAL(collapsed(QModelIndex)), this, SLOT(slotCollapsed(QModelIndex)));
|
||||
}
|
||||
|
||||
BookmarkView::~BookmarkView()
|
||||
{
|
||||
}
|
||||
|
||||
void BookmarkView::loadFoldedState()
|
||||
{
|
||||
m_loadingState = true;
|
||||
loadFoldedState(QModelIndex());
|
||||
m_loadingState = false;
|
||||
}
|
||||
|
||||
void BookmarkView::loadFoldedState(const QModelIndex& parentIndex)
|
||||
{
|
||||
const int count = model()->rowCount(parentIndex);
|
||||
for (int row = 0; row < count; ++row) {
|
||||
const QModelIndex index = model()->index(row, 0, parentIndex);
|
||||
const KBookmark bk = bookmarkForIndex(index);
|
||||
if (bk.isNull()) {
|
||||
expand(index);
|
||||
}
|
||||
else if (bk.isGroup()) {
|
||||
setExpanded(index, bk.toGroup().isOpen());
|
||||
loadFoldedState(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarkView::slotExpanded(const QModelIndex& index)
|
||||
{
|
||||
if (!m_loadingState) {
|
||||
KBookmark bk = bookmarkForIndex(index);
|
||||
bk.internalElement().setAttribute("folded", "no");
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarkView::slotCollapsed(const QModelIndex& index)
|
||||
{
|
||||
if (!m_loadingState) {
|
||||
KBookmark bk = bookmarkForIndex(index);
|
||||
bk.internalElement().setAttribute("folded", "yes");
|
||||
}
|
||||
}
|
||||
|
||||
#include "view.moc"
|
44
keditbookmarks/kbookmarkmodel/view.h
Normal file
44
keditbookmarks/kbookmarkmodel/view.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
/* This file is part of the KDE project
|
||||
Copyright (C) 2005 Daniel Teske <teske@squorn.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public
|
||||
License version 2 as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef BOOKMARKMODEL_BOOKMARKVIEW_H
|
||||
#define BOOKMARKMODEL_BOOKMARKVIEW_H
|
||||
|
||||
#include <QtGui/QTreeView>
|
||||
|
||||
class KBookmark;
|
||||
|
||||
class BookmarkView : public QTreeView
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
BookmarkView( QWidget * parent = 0 );
|
||||
virtual ~BookmarkView();
|
||||
virtual KBookmark bookmarkForIndex(const QModelIndex & idx) const = 0;
|
||||
void loadFoldedState();
|
||||
|
||||
private Q_SLOTS:
|
||||
void slotExpanded(const QModelIndex& index);
|
||||
void slotCollapsed(const QModelIndex& index);
|
||||
|
||||
private:
|
||||
void loadFoldedState(const QModelIndex& parentIndex);
|
||||
bool m_loadingState;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue