File indexing completed on 2022-10-04 13:56:35

0001 /*
0002  * manage multiple choice suggestions for queries
0003  * SPDX-FileCopyrightText: 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de>
0004  * SPDX-FileCopyrightText: 2005 Peter Hedlund <peter.hedlund@kdemail.net>
0005  * SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #include "keduvocmultiplechoice.h"
0009 
0010 class KEduVocMultipleChoice::KEduVocMultipleChoicePrivate
0011 {
0012 public:
0013     QStringList m_choices;
0014 };
0015 
0016 KEduVocMultipleChoice::KEduVocMultipleChoice()
0017         : d( new KEduVocMultipleChoicePrivate )
0018 {}
0019 
0020 KEduVocMultipleChoice::KEduVocMultipleChoice( const KEduVocMultipleChoice &other )
0021         : d( new KEduVocMultipleChoicePrivate )
0022 {
0023     d->m_choices = other.choices();
0024 }
0025 
0026 KEduVocMultipleChoice::KEduVocMultipleChoice( const QStringList &choices )
0027         : d( new KEduVocMultipleChoicePrivate )
0028 {
0029     foreach ( const QString &choice, choices ) {
0030         // use appendChoice to check for empty entries
0031         appendChoice(choice);
0032     }
0033 }
0034 
0035 KEduVocMultipleChoice::~KEduVocMultipleChoice()
0036 {
0037     delete d;
0038 }
0039 
0040 KEduVocMultipleChoice &KEduVocMultipleChoice::operator= ( const KEduVocMultipleChoice &other )
0041 {
0042     d->m_choices = other.choices();
0043     return *this;
0044 }
0045 
0046 QStringList KEduVocMultipleChoice::choices() const
0047 {
0048     return d->m_choices;
0049 }
0050 
0051 bool KEduVocMultipleChoice::isEmpty() const
0052 {
0053     return d->m_choices.isEmpty();
0054 }
0055 
0056 
0057 void KEduVocMultipleChoice::clear()
0058 {
0059     d->m_choices.clear();
0060 }
0061 
0062 
0063 QString KEduVocMultipleChoice::choice( int index ) const
0064 {
0065     QString choice;
0066     if ( d->m_choices.size() > index ) {
0067         choice = d->m_choices[index];
0068     }
0069     return choice;
0070 }
0071 
0072 unsigned KEduVocMultipleChoice::size() const
0073 {
0074     return d->m_choices.size();
0075 }
0076 
0077 bool KEduVocMultipleChoice::operator== ( const KEduVocMultipleChoice &choice ) const
0078 {
0079     return d->m_choices == choice.choices();
0080 }
0081 
0082 void KEduVocMultipleChoice::appendChoice( const QString &s )
0083 {
0084     if ( !s.isEmpty() ) {
0085         d->m_choices.append( s );
0086     }
0087 }