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

kiten/lib

  • sources
  • kde-4.14
  • kdeedu
  • kiten
  • lib
historyptrlist.cpp
Go to the documentation of this file.
1 /*****************************************************************************
2  * This file is part of Kiten, a KDE Japanese Reference Tool *
3  * Copyright (C) 2006 Joseph Kerian <jkerian@gmail.com> *
4  * Copyright (C) 2006 Eric Kjeldergaard <kjelderg@gmail.com> *
5  * *
6  * This library is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Library General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Library General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Library General Public License *
17  * along with this library; see the file COPYING.LIB. If not, write to *
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
19  * Boston, MA 02110-1301, USA. *
20  *****************************************************************************/
21 
22 #include "historyptrlist.h"
23 
24 #include "entrylist.h"
25 
26 #include <QList>
27 #include <QMutableListIterator>
28 
29 class HistoryPtrList::Private
30 {
31  public:
32  Private() : index( -1 ) {}
33 
34  static const int max_size = 20;
35  int index;
36  QList<EntryList*> list;
37 };
38 
39 HistoryPtrList::HistoryPtrList()
40 : d( new Private )
41 {
42 }
43 
44 HistoryPtrList::~HistoryPtrList()
45 {
46  for( int i = d->list.size() - 1; i >= 0; i-- )
47  {
48  d->list.at( i )->deleteAll();
49  delete d->list.at( i );
50  }
51 
52  delete d;
53 }
54 
55 void HistoryPtrList::addItem( EntryList *newItem )
56 {
57  if( ! newItem ) return;
58  //If we're currently looking at something prior to the end of the list
59  //Remove everything in the list up to this point.
60  int currentPosition = d->index + 1;
61  EntryList *temp;
62  while( currentPosition < count() )
63  {
64  temp = d->list.takeLast();
65  temp->deleteAll();
66  delete temp;
67  }
68 
69  //Now... check to make sure our history isn't 'fat'
70  while( count() >= d->max_size )
71  {
72  temp = d->list.takeFirst();
73  temp->deleteAll();
74  delete temp;
75  }
76  d->index = count()-1; //Since we have trimmed down to the current position
77 
78  //One other odd case... if this query is a repeat of the last query
79  //replace the current one with the new one
80  if( d->list.size() > 0 )
81  {
82  if( current()->getQuery() == newItem->getQuery() )
83  {
84  temp = d->list.takeLast();
85  temp->deleteAll();
86  delete temp;
87  }
88  }
89  //Now add the item
90  d->list.append( newItem );
91  d->index = count() - 1;
92 }
93 
94 int HistoryPtrList::count()
95 {
96  return d->list.size();
97 }
98 
99 EntryList* HistoryPtrList::current()
100 {
101  if( d->index == -1 )
102  {
103  return NULL;
104  }
105 
106  return d->list.at( d->index );
107 }
108 
109 int HistoryPtrList::index()
110 {
111  return d->index;
112 }
113 
114 void HistoryPtrList::next( int distance )
115 {
116  if( distance + d->index > count() - 1 )
117  {
118  d->index = count() - 1;
119  }
120  else
121  {
122  d->index += distance;
123  }
124 }
125 
126 void HistoryPtrList::prev(int distance)
127 {
128  if( d->index - distance < 0 )
129  {
130  d->index = 0;
131  }
132  else
133  {
134  d->index -= distance;
135  }
136 }
137 
138 void HistoryPtrList::setCurrent( int i )
139 {
140  if( i<count() && i >= 0 )
141  {
142  d->index = i;
143  }
144 }
145 
146 //Get a StringList of the History Items
147 QStringList HistoryPtrList::toStringList()
148 {
149  QStringList result;
150 
151  foreach( const EntryList *p, d->list )
152  {
153  result.append( p->getQuery().toString() );
154  }
155 
156  return result;
157 }
158 
159 QStringList HistoryPtrList::toStringListNext()
160 {
161  HistoryPtrList localCopy( *this );
162 
163  int currentPosition = d->index + 1;
164  while( currentPosition-- )
165  {
166  localCopy.d->list.removeFirst();
167  }
168 
169  return localCopy.toStringList();
170 }
171 
172 QStringList HistoryPtrList::toStringListPrev()
173 {
174  QStringList result;
175 
176  for( int i = 0; i < d->index; i++ )
177  {
178  result.append( d->list.at( i )->getQuery().toString() );
179  }
180 
181  return result;
182 }
HistoryPtrList::next
void next(int distance=1)
Add one to the current location, convenient for 'forward' buttons.
Definition: historyptrlist.cpp:114
HistoryPtrList::setCurrent
void setCurrent(int i)
Set the current item.
Definition: historyptrlist.cpp:138
HistoryPtrList::toStringListPrev
QStringList toStringListPrev()
Return a list of the entries prior to the current one (not including the current entry.
Definition: historyptrlist.cpp:172
HistoryPtrList::toStringList
QStringList toStringList()
Return a list of the entries.
Definition: historyptrlist.cpp:147
HistoryPtrList::HistoryPtrList
HistoryPtrList()
Construct a HistoryPtrList, this should be done early on.
Definition: historyptrlist.cpp:39
HistoryPtrList::current
EntryList * current()
Return the item at the location given by the parameter, and set it to be the current history list ite...
Definition: historyptrlist.cpp:99
HistoryPtrList
Definition: historyptrlist.h:31
QList::append
void append(const T &value)
QList< EntryList * >
HistoryPtrList::addItem
void addItem(EntryList *newItem)
Add an item to the end of the history list and set it as the current displayed item.
Definition: historyptrlist.cpp:55
QStringList
DictQuery::toString
const QString toString() const
This returns a QString that represents the query.
Definition: dictquery.cpp:279
EntryList::deleteAll
void deleteAll()
Delete all Entry objects in our list.
Definition: entrylist.cpp:99
HistoryPtrList::count
int count()
Return the total number of items in the list.
Definition: historyptrlist.cpp:94
HistoryPtrList::index
int index()
Return the current numerican 0-based location.
Definition: historyptrlist.cpp:109
HistoryPtrList::prev
void prev(int distance=1)
Sub one from the current location, the counterpart to next()
Definition: historyptrlist.cpp:126
historyptrlist.h
EntryList
EntryList is a simple container for Entry objects, and is-a QList A few simple overrides allo...
Definition: entrylist.h:38
entrylist.h
HistoryPtrList::toStringListNext
QStringList toStringListNext()
Return a summary list that only includes those after the current.
Definition: historyptrlist.cpp:159
EntryList::getQuery
DictQuery getQuery() const
Get the query that generated this list, note that if you have appended EntryLists from two different ...
Definition: entrylist.cpp:323
HistoryPtrList::~HistoryPtrList
virtual ~HistoryPtrList()
Destructor...
Definition: historyptrlist.cpp:44
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:16:38 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kiten/lib

Skip menu "kiten/lib"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

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