summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Ander Peñalba <jonan88@gmail.com>2010-08-20 12:03:14 +0200
committerJon Ander Peñalba <jonan88@gmail.com>2010-08-20 12:03:14 +0200
commit8d48c62aaf14e023b49c4701c26552732e7c609b (patch)
treee363e4492287c489a5954a54b1984475cc2ede5a
parentBookmarks panel code clean-up (diff)
downloadrekonq-8d48c62aaf14e023b49c4701c26552732e7c609b.tar.xz
Bookmarks panel code reordered
-rw-r--r--src/bookmarks/bookmarkspanel.cpp150
-rw-r--r--src/bookmarks/bookmarkstreemodel.cpp112
-rw-r--r--src/bookmarks/bookmarkstreemodel.h1
3 files changed, 132 insertions, 131 deletions
diff --git a/src/bookmarks/bookmarkspanel.cpp b/src/bookmarks/bookmarkspanel.cpp
index 557fabc2..22701baa 100644
--- a/src/bookmarks/bookmarkspanel.cpp
+++ b/src/bookmarks/bookmarkspanel.cpp
@@ -76,6 +76,81 @@ void BookmarksPanel::showing(bool b)
}
+void BookmarksPanel::startLoadFoldedState()
+{
+ m_loadingState = true;
+ loadFoldedState(QModelIndex());
+ m_loadingState = false;
+}
+
+
+void BookmarksPanel::contextMenu(const QPoint &pos)
+{
+ if (m_loadingState)
+ return;
+
+ BookmarksContextMenu menu(bookmarkForIndex( m_treeView->indexAt(pos) ),
+ Application::bookmarkProvider()->bookmarkManager(),
+ Application::bookmarkProvider()->bookmarkOwner(),
+ this
+ );
+
+ menu.exec(m_treeView->mapToGlobal(pos));
+}
+
+
+void BookmarksPanel::deleteBookmark()
+{
+ QModelIndex index = m_treeView->currentIndex();
+ if (m_loadingState || !index.isValid())
+ return;
+
+ Application::bookmarkProvider()->bookmarkOwner()->bookmarkSelected(bookmarkForIndex(index));
+ Application::bookmarkProvider()->bookmarkOwner()->deleteBookmark();
+}
+
+
+void BookmarksPanel::onCollapse(const QModelIndex &index)
+{
+ if (m_loadingState)
+ return;
+
+ bookmarkForIndex(index).internalElement().setAttribute("folded", "yes");
+ emit expansionChanged();
+}
+
+
+void BookmarksPanel::onExpand(const QModelIndex &index)
+{
+ if (m_loadingState)
+ return;
+
+ bookmarkForIndex(index).internalElement().setAttribute("folded", "no");
+ emit expansionChanged();
+}
+
+
+void BookmarksPanel::loadFoldedState(const QModelIndex &root)
+{
+ int count = m_treeView->model()->rowCount(root);
+ QModelIndex index;
+
+ for (int i = 0; i < count; ++i)
+ {
+ index = m_treeView->model()->index(i, 0, root);
+ if (index.isValid())
+ {
+ KBookmark bm = bookmarkForIndex(index);
+ if (bm.isGroup())
+ {
+ m_treeView->setExpanded(index, bm.toGroup().isOpen());
+ loadFoldedState(index);
+ }
+ }
+ }
+}
+
+
void BookmarksPanel::setup()
{
kDebug() << "Loading bookmarks panel setup...";
@@ -143,78 +218,3 @@ KBookmark BookmarksPanel::bookmarkForIndex(const QModelIndex &index)
BtmItem *node = static_cast<BtmItem*>(originalIndex.internalPointer());
return node->getBkm();
}
-
-
-void BookmarksPanel::onCollapse(const QModelIndex &index)
-{
- if (m_loadingState)
- return;
-
- bookmarkForIndex(index).internalElement().setAttribute("folded", "yes");
- emit expansionChanged();
-}
-
-
-void BookmarksPanel::onExpand(const QModelIndex &index)
-{
- if (m_loadingState)
- return;
-
- bookmarkForIndex(index).internalElement().setAttribute("folded", "no");
- emit expansionChanged();
-}
-
-
-void BookmarksPanel::startLoadFoldedState()
-{
- m_loadingState = true;
- loadFoldedState(QModelIndex());
- m_loadingState = false;
-}
-
-
-void BookmarksPanel::loadFoldedState(const QModelIndex &root)
-{
- int count = m_treeView->model()->rowCount(root);
- QModelIndex index;
-
- for (int i = 0; i < count; ++i)
- {
- index = m_treeView->model()->index(i, 0, root);
- if (index.isValid())
- {
- KBookmark bm = bookmarkForIndex(index);
- if (bm.isGroup())
- {
- m_treeView->setExpanded(index, bm.toGroup().isOpen());
- loadFoldedState(index);
- }
- }
- }
-}
-
-
-void BookmarksPanel::contextMenu(const QPoint &pos)
-{
- if (m_loadingState)
- return;
-
- BookmarksContextMenu menu(bookmarkForIndex( m_treeView->indexAt(pos) ),
- Application::bookmarkProvider()->bookmarkManager(),
- Application::bookmarkProvider()->bookmarkOwner(),
- this
- );
-
- menu.exec(m_treeView->mapToGlobal(pos));
-}
-
-
-void BookmarksPanel::deleteBookmark()
-{
- QModelIndex index = m_treeView->currentIndex();
- if (m_loadingState || !index.isValid())
- return;
-
- Application::bookmarkProvider()->bookmarkOwner()->bookmarkSelected(bookmarkForIndex(index));
- Application::bookmarkProvider()->bookmarkOwner()->deleteBookmark();
-}
diff --git a/src/bookmarks/bookmarkstreemodel.cpp b/src/bookmarks/bookmarkstreemodel.cpp
index 5bf1f769..8e95a615 100644
--- a/src/bookmarks/bookmarkstreemodel.cpp
+++ b/src/bookmarks/bookmarkstreemodel.cpp
@@ -250,6 +250,62 @@ QVariant BookmarksTreeModel::data(const QModelIndex &index, int role) const
}
+QStringList BookmarksTreeModel::mimeTypes() const
+{
+ return KBookmark::List::mimeDataTypes();
+}
+
+
+bool BookmarksTreeModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
+{
+ if (action != Qt::MoveAction || !data->hasFormat("application/rekonq-bookmark"))
+ return false;
+
+ QByteArray addresses = data->data("application/rekonq-bookmark");
+ KBookmark bookmark = Application::bookmarkProvider()->bookmarkManager()->findByAddress(QString::fromLatin1(addresses.data()));
+
+ KBookmarkGroup root;
+ if (parent.isValid())
+ root = bookmarkForIndex(parent).toGroup();
+ else
+ root = Application::bookmarkProvider()->rootGroup();
+
+ QModelIndex destIndex = index(row, column, parent);
+
+ if (destIndex.isValid() && row != -1)
+ {
+ root.moveBookmark(bookmark, root.previous(bookmarkForIndex(destIndex)));
+ }
+ else
+ {
+ root.deleteBookmark(bookmark);
+ root.addBookmark(bookmark);
+ }
+
+ Application::bookmarkProvider()->bookmarkManager()->emitChanged();
+
+ return true;
+}
+
+
+Qt::DropActions BookmarksTreeModel::supportedDropActions() const
+{
+ return Qt::MoveAction;
+}
+
+
+QMimeData* BookmarksTreeModel::mimeData(const QModelIndexList &indexes) const
+{
+ QMimeData *mimeData = new QMimeData;
+
+ QByteArray address = bookmarkForIndex(indexes.first()).address().toLatin1();
+ mimeData->setData("application/rekonq-bookmark", address);
+ bookmarkForIndex(indexes.first()).populateMimeData(mimeData);
+
+ return mimeData;
+}
+
+
void BookmarksTreeModel::bookmarksChanged(const QString &groupAddress)
{
if (groupAddress.isEmpty())
@@ -325,59 +381,3 @@ KBookmark BookmarksTreeModel::bookmarkForIndex(const QModelIndex &index) const
{
return static_cast<BtmItem*>(index.internalPointer())->getBkm();
}
-
-
-Qt::DropActions BookmarksTreeModel::supportedDropActions() const
-{
- return Qt::MoveAction;
-}
-
-
-QStringList BookmarksTreeModel::mimeTypes() const
-{
- return KBookmark::List::mimeDataTypes();
-}
-
-
-QMimeData* BookmarksTreeModel::mimeData(const QModelIndexList &indexes) const
-{
- QMimeData *mimeData = new QMimeData;
-
- QByteArray address = bookmarkForIndex(indexes.first()).address().toLatin1();
- mimeData->setData("application/rekonq-bookmark", address);
- bookmarkForIndex(indexes.first()).populateMimeData(mimeData);
-
- return mimeData;
-}
-
-
-bool BookmarksTreeModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
-{
- if (action != Qt::MoveAction || !data->hasFormat("application/rekonq-bookmark"))
- return false;
-
- QByteArray addresses = data->data("application/rekonq-bookmark");
- KBookmark bookmark = Application::bookmarkProvider()->bookmarkManager()->findByAddress(QString::fromLatin1(addresses.data()));
-
- KBookmarkGroup root;
- if (parent.isValid())
- root = bookmarkForIndex(parent).toGroup();
- else
- root = Application::bookmarkProvider()->rootGroup();
-
- QModelIndex destIndex = index(row, column, parent);
-
- if (destIndex.isValid() && row != -1)
- {
- root.moveBookmark(bookmark, root.previous(bookmarkForIndex(destIndex)));
- }
- else
- {
- root.deleteBookmark(bookmark);
- root.addBookmark(bookmark);
- }
-
- Application::bookmarkProvider()->bookmarkManager()->emitChanged();
-
- return true;
-}
diff --git a/src/bookmarks/bookmarkstreemodel.h b/src/bookmarks/bookmarkstreemodel.h
index 0f115272..6b85365b 100644
--- a/src/bookmarks/bookmarkstreemodel.h
+++ b/src/bookmarks/bookmarkstreemodel.h
@@ -43,6 +43,7 @@ class BtmItem
public:
BtmItem(const KBookmark &bm);
~BtmItem();
+
QVariant data(int role = Qt::DisplayRole) const;
int row() const;
int childCount() const;