File indexing completed on 2024-04-21 03:42:01

0001 /*
0002     This file is part of Kiten, a KDE Japanese Reference Tool
0003     SPDX-FileCopyrightText: 2001 Jason Katz-Brown <jason@katzbrown.com>
0004     SPDX-FileCopyrightText: 2006 Joseph Kerian <jkerian@gmail.com>
0005     SPDX-FileCopyrightText: 2006 Eric Kjeldergaard <kjelderg@gmail.com>
0006 
0007     SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 
0010 #ifndef KITEN_ENTRYLIST_H
0011 #define KITEN_ENTRYLIST_H
0012 
0013 #include <QList>
0014 #include <QString>
0015 #include <QStringList>
0016 
0017 #include "dictquery.h"
0018 #include "entry.h"
0019 #include "kiten_export.h"
0020 
0021 /**
0022  * EntryList is a simple container for Entry objects, and is-a QList<Entry*>
0023  * A few simple overrides allow you to deal with sorting and translating.
0024  */
0025 class KITEN_EXPORT EntryList : public QList<Entry *>
0026 {
0027 public:
0028     /**
0029      * A simple overridden iterator for working with the Entries
0030      */
0031     typedef QListIterator<Entry *> EntryIterator;
0032 
0033     /**
0034      * Basic constructor, create an empty EntryList
0035      */
0036     EntryList();
0037     /**
0038      * Copy constructor
0039      */
0040     EntryList(const EntryList &old);
0041     /**
0042      * Basic Destructor, does not delete Entry* objects. Please remember to call
0043      * deleteAll() before deleting an EntryList.
0044      */
0045     virtual ~EntryList();
0046     /**
0047      * Delete all Entry objects in our list. In the future, we'll switch to a reference
0048      * counting system, and this will be deprecated.
0049      */
0050     void deleteAll();
0051 
0052     /**
0053      * Convert every element of the EntryList to a QString and return it
0054      */
0055     QString toString() const;
0056     /**
0057      * Convert every element of the EntryList to a QString in HTML form and return it
0058      */
0059     QString toHTML() const;
0060 
0061     /**
0062      * Convert a given range of the EntryList to a QString and return it
0063      * @param start the location in the list where we should start
0064      * @param length the length of the list we should generate
0065      */
0066     QString toString(unsigned int start, unsigned int length) const;
0067     /**
0068      * Convert a given range of the EntryList to a QString in HTML form and return it
0069      * @param start the location in the list where we should start
0070      * @param length the length of the list we should generate
0071      */
0072     QString toHTML(unsigned int start, unsigned int length) const;
0073     /**
0074      * Convert the entire list to KVTML for export to a flashcard app
0075      * @param start the location in the list where we should start
0076      * @param length the length of the list we should generate
0077      */
0078     QString toKVTML(unsigned int start, unsigned int length) const;
0079 
0080     /**
0081      * Sort the list according to the given fields in sortOrder, if dictionaryOrder
0082      * is blank, don't order the list by dictionary, otherwise items are sorted by dictionary
0083      * then by sortOrder aspects
0084      * @param sortOrder the keys to sort by, this should be a list of fields to sort by, this should
0085      *        be the same as the fields that are returned from dictFile::listDictDisplayOptions().
0086      *        "--NewLine--" entries will be ignored, "Word/Kanji", "Meaning", and "Reading" entries will
0087      *        be accepted. An entry which has an extended attribute is considered higher ranking (sorted to
0088      *        a higher position) than an entry which does not have such an attribute.
0089      * @param dictionaryOrder the order for the Entry objects to be sorted in, dictionary-wise. This should
0090      *        match the names of the dictionary objects, passed to the DictionaryManager.
0091      */
0092     void sort(QStringList &sortOrder, QStringList &dictionaryOrder);
0093 
0094     /**
0095      * Append another EntryList onto this one
0096      */
0097     const EntryList &operator+=(const EntryList &other);
0098     /**
0099      * Copy an entry list
0100      */
0101     const EntryList &operator=(const EntryList &other);
0102     /**
0103      * Append another EntryList onto this one
0104      */
0105     void appendList(const EntryList *other);
0106     /**
0107      * Get the query that generated this list, note that if you have appended EntryLists from
0108      * two different queries, the resulting DictQuery from this is undefined.
0109      */
0110     DictQuery getQuery() const;
0111     /**
0112      * Set the query for this list.  See getQuery() for a potential problem with this
0113      */
0114     void setQuery(const DictQuery &newQuery);
0115 
0116     int scrollValue() const;
0117     void setScrollValue(int val);
0118 
0119 private:
0120     class Private;
0121     Private *const d;
0122 };
0123 
0124 #endif