Warning, file /office/calligra/libs/text/KoBookmarkManager.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002  * Copyright (C) 2007 Fredy Yanardi <fyanardi@gmail.com>
0003  * Copyright (c) 2011 Boudewijn Rempt <boud@kogmbh.com>
0004  *
0005  * This library is free software; you can redistribute it and/or
0006  * modify it under the terms of the GNU Library General Public
0007  * License as published by the Free Software Foundation; either
0008  * version 2 of the License, or (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  * Library General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Library General Public License
0016  * along with this library; see the file COPYING.LIB.  If not, write to
0017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018  * Boston, MA 02110-1301, USA.
0019  */
0020 
0021 #include "KoBookmarkManager.h"
0022 #include "KoBookmark.h"
0023 
0024 #include "TextDebug.h"
0025 #include <QHash>
0026 
0027 class KoBookmarkManagerPrivate
0028 {
0029 public:
0030     KoBookmarkManagerPrivate() { }
0031     QHash<QString, KoBookmark*> bookmarkHash;
0032     QList<QString> bookmarkNameList;
0033     int lastId;
0034 };
0035 
0036 KoBookmarkManager::KoBookmarkManager()
0037         : d(new KoBookmarkManagerPrivate)
0038 {
0039 }
0040 
0041 KoBookmarkManager::~KoBookmarkManager()
0042 {
0043     delete d;
0044 }
0045 
0046 void KoBookmarkManager::insert(const QString &name, KoBookmark *bookmark)
0047 {
0048     bookmark->setName(name);
0049     d->bookmarkHash[name] = bookmark;
0050     d->bookmarkNameList.append(name);
0051 }
0052 
0053 void KoBookmarkManager::remove(const QString &name)
0054 {
0055     d->bookmarkHash.remove(name);
0056     d->bookmarkNameList.removeAt(d->bookmarkNameList.indexOf(name));
0057 }
0058 
0059 void KoBookmarkManager::rename(const QString &oldName, const QString &newName)
0060 {
0061     QHash<QString, KoBookmark*>::iterator i = d->bookmarkHash.begin();
0062 
0063     while (i != d->bookmarkHash.end()) {
0064         if (i.key() == oldName) {
0065             KoBookmark *bookmark = d->bookmarkHash.take(i.key());
0066             bookmark->setName(newName);
0067             d->bookmarkHash.insert(newName, bookmark);
0068             int listPos = d->bookmarkNameList.indexOf(oldName);
0069             d->bookmarkNameList.replace(listPos, newName);
0070             return;
0071         }
0072         ++i;
0073     }
0074 }
0075 
0076 KoBookmark *KoBookmarkManager::bookmark(const QString &name) const
0077 {
0078     KoBookmark *bookmark = d->bookmarkHash.value(name);
0079     return bookmark;
0080 }
0081 
0082 QList<QString> KoBookmarkManager::bookmarkNameList() const
0083 {
0084     return d->bookmarkNameList;
0085 }