• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • core
bookmarklist.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Okteta Core library, made within the KDE community.
3 
4  Copyright 2007,2009 Friedrich W. H. Kossebau <kossebau@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) version 3, or any
10  later version accepted by the membership of KDE e.V. (or its
11  successor approved by the membership of KDE e.V.), which shall
12  act as a proxy defined in Section 6 of version 3 of the license.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #include "bookmarklist.h"
24 
25 // Qt
26 #include <QtCore/QList>
27 
28 
29 namespace Okteta
30 {
31 
32 BookmarkList::BookmarkList() {}
33 
34 void BookmarkList::addBookmark( const Bookmark &bookmark )
35 {
36  if( !bookmark.isValid() )
37  return;
38 
39  iterator B = begin();
40  for( ; B!=end(); ++B )
41  {
42  // new bookmark before next bookmark?
43  if( bookmark.offset() < B->offset() )
44  {
45  // put the new before it
46  insert( B, bookmark );
47  return;
48  }
49 
50  // bookmark already present?
51  if( bookmark.offset() == B->offset() )
52  {
53  *B = bookmark;
54  return;
55  }
56  }
57 
58  // all others before the new?
59  if( B == end() )
60  // add it at the end
61  append( bookmark );
62 }
63 
64 void BookmarkList::addBookmarks( const QList<Okteta::Bookmark> &bookmarks )
65 {
66  foreach( const Bookmark &bookmark, bookmarks )
67  addBookmark( bookmark );
68 }
69 
70 void BookmarkList::removeBookmark( const Bookmark &bookmark )
71 {
72  if( !bookmark.isValid() )
73  return;
74 
75  iterator B = begin();
76  for( ; B!=end(); ++B )
77  {
78  if( bookmark.offset() == B->offset() )
79  {
80  erase( B );
81  break;
82  }
83  }
84 }
85 
86 void BookmarkList::removeBookmarks( const QList<Okteta::Bookmark> &bookmarks )
87 {
88  foreach( const Bookmark &bookmark, bookmarks )
89  removeBookmark( bookmark );
90 }
91 
92 void BookmarkList::setBookmark( unsigned int index, const Bookmark& bookmark )
93 {
94  const Iterator endIt = end();
95  unsigned int i = 0;
96  for( Iterator it = begin(); it!=endIt; ++it,++i )
97  {
98  if( i == index )
99  {
100  *it = bookmark;
101  break;
102  }
103  }
104 }
105 
106 bool BookmarkList::adjustToReplaced( Address offset, Size removedLength, Size insertedLength )
107 {
108  bool result = false;
109 
110  iterator bIt = begin();
111  while( bIt!=end() && bIt->offset() < offset )
112  ++bIt;
113  // remove bookmarks in removed section
114  while( bIt!=end() && bIt->offset() < offset+removedLength )
115  {
116  bIt = erase( bIt );
117  result = true;
118  }
119  // adjust bookmarks in moved section
120  const Size diff = insertedLength - removedLength;
121  if( diff != 0 )
122  for( ; bIt!=end(); ++bIt )
123  {
124  (*bIt).move( diff );
125  result = true;
126  }
127 
128  return result;
129 }
130 
131 bool BookmarkList::adjustToSwapped( Address firstPartStart, Address secondPartStart, Size secondPartLength )
132 {
133  bool result = false;
134 
135  iterator bIt = begin();
136  while( bIt!=end() && bIt->offset() < firstPartStart )
137  ++bIt;
138  QList<Okteta::Bookmark> bookmarksInFirstPart;
139  // take bookmarks from first part
140  while( bIt!=end() && bIt->offset() < secondPartStart )
141  {
142  bookmarksInFirstPart.append( *bIt );
143  bIt = erase( bIt );
144  }
145  // move bookmarks from second to first
146  const Size diff = firstPartStart - secondPartStart;
147  const Address behindLast = secondPartStart + secondPartLength;
148  for( ; bIt!=end() && bIt->offset() < behindLast; ++bIt )
149  {
150  (*bIt).move( diff );
151  result = true;
152  }
153  // append bookmarks from first part as second
154  if( !bookmarksInFirstPart.isEmpty() )
155  {
156  foreach( Bookmark bookmark, bookmarksInFirstPart ) // krazy:exclude=foreach
157  {
158  bookmark.move( secondPartLength );
159  insert( bIt, bookmark );
160  }
161  result = true;
162  }
163 
164  return result;
165 }
166 
167 QList<Okteta::Bookmark> BookmarkList::list() const
168 {
169  QList<Okteta::Bookmark> result;
170 
171  foreach( const Bookmark &bookmark, *this )
172  result.append( bookmark );
173 
174  return result;
175 }
176 
177 const Bookmark& BookmarkList::bookmark( Address offset ) const
178 {
179  const ConstIterator endIt = end();
180  for( ConstIterator it = begin(); it!=endIt; ++it )
181  {
182  if( it->offset() == offset )
183  return *it;
184  }
185  static const Bookmark* const noBookmark = 0;
186 
187  return (const Bookmark&)*noBookmark;
188 }
189 
190 bool BookmarkList::contains( Address offset ) const
191 {
192  bool result = false;
193 
194  const_iterator B = begin();
195  for( ; B!=end(); ++B )
196  {
197  if( B->offset() == offset )
198  {
199  result = true;
200  break;
201  }
202  }
203 
204  return result;
205 }
206 
207 const Bookmark& BookmarkList::at( unsigned int index ) const
208 {
209  Q_ASSERT_X( (int)index < size(), "BookmarkList::at", "index out of range" );
210 
211  const ConstIterator endIt = end();
212  unsigned int i = 0;
213  for( ConstIterator it = begin(); it!=endIt; ++it,++i )
214  {
215  if( i == index )
216  return *it;
217  }
218  static const Bookmark* const noBookmark = 0;
219  return (const Bookmark&)*noBookmark;
220 }
221 
222 BookmarkList::~BookmarkList() {}
223 
224 }
Okteta::Address
qint32 Address
Definition: address.h:34
Okteta::BookmarkList::bookmark
const Bookmark & bookmark(Address offset) const
Definition: bookmarklist.cpp:177
Okteta::Bookmark::offset
Address offset() const
Definition: bookmark.h:66
Okteta::BookmarkList::removeBookmarks
void removeBookmarks(const QList< Okteta::Bookmark > &bookmarks)
Definition: bookmarklist.cpp:86
Okteta::Bookmark
Definition: bookmark.h:38
Okteta::BookmarkList::addBookmark
void addBookmark(const Bookmark &bookmark)
Definition: bookmarklist.cpp:34
Okteta::BookmarkList::removeBookmark
void removeBookmark(const Bookmark &bookmark)
Definition: bookmarklist.cpp:70
Okteta::BookmarkList::adjustToSwapped
bool adjustToSwapped(Address firstPartStart, Address secondPartStart, Size secondPartLength)
Definition: bookmarklist.cpp:131
Okteta::BookmarkList::adjustToReplaced
bool adjustToReplaced(Address offset, Size removedLength, Size insertedLength)
Definition: bookmarklist.cpp:106
Okteta::BookmarkList::contains
bool contains(Address offset) const
Definition: bookmarklist.cpp:190
Okteta::Bookmark::isValid
bool isValid() const
Definition: bookmark.h:65
Okteta::BookmarkList::addBookmarks
void addBookmarks(const QList< Okteta::Bookmark > &bookmarks)
Definition: bookmarklist.cpp:64
Okteta::BookmarkList::list
QList< Okteta::Bookmark > list() const
Definition: bookmarklist.cpp:167
Okteta::Bookmark::move
void move(Size offset)
Definition: bookmark.h:69
bookmarklist.h
Okteta::BookmarkList::setBookmark
void setBookmark(unsigned int index, const Bookmark &bookmark)
Definition: bookmarklist.cpp:92
Okteta::Size
qint32 Size
Definition: size.h:33
Okteta::BookmarkList::BookmarkList
BookmarkList()
Definition: bookmarklist.cpp:32
Okteta::BookmarkList::~BookmarkList
~BookmarkList()
Definition: bookmarklist.cpp:222
QList
Definition: bookmarkable.h:29
Okteta::BookmarkList::at
const Bookmark & at(unsigned int index) const
Definition: bookmarklist.cpp:207
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:06 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

Skip menu "okteta"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal