moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kvoctrain / kvoctrain / kvt-core / MultipleChoice.cpp
blobfc58f96aa481e9d5a3535e0b6173439cd64c4a9d
1 /***************************************************************************
3 $Id$
5 manage multiple choice suggestions for queries
7 -----------------------------------------------------------------------
9 begin : Mon Oct 29 18:09:29 1999
11 copyright : (C) 1999-2001 Ewald Arnold
12 (C) 2001 The KDE-EDU team
13 email : kvoctrain@ewald-arnold.de
15 -----------------------------------------------------------------------
17 ***************************************************************************/
19 /***************************************************************************
20 * *
21 * This program is free software; you can redistribute it and/or modify *
22 * it under the terms of the GNU General Public License as published by *
23 * the Free Software Foundation; either version 2 of the License, or *
24 * (at your option) any later version. *
25 * *
26 ***************************************************************************/
28 #include "MultipleChoice.h"
30 MultipleChoice::MultipleChoice (
31 const QString &mc1,
32 const QString &mc2,
33 const QString &mc3,
34 const QString &mc4,
35 const QString &mc5
38 setMC1 (mc1);
39 setMC2 (mc2);
40 setMC3 (mc3);
41 setMC4 (mc4);
42 setMC5 (mc5);
46 bool MultipleChoice::isEmpty() const
48 return muc1.stripWhiteSpace().isEmpty()
49 && muc2.stripWhiteSpace().isEmpty()
50 && muc3.stripWhiteSpace().isEmpty()
51 && muc4.stripWhiteSpace().isEmpty()
52 && muc5.stripWhiteSpace().isEmpty();
56 void MultipleChoice::clear()
58 muc1 = "";
59 muc2 = "";
60 muc3 = "";
61 muc4 = "";
62 muc5 = "";
66 QString MultipleChoice::mc (unsigned idx) const
68 switch (idx) {
69 case 0: return muc1;
70 case 1: return muc2;
71 case 2: return muc3;
72 case 3: return muc4;
73 case 4: return muc5;
75 return "";
79 unsigned MultipleChoice::size()
81 normalize();
82 unsigned num = 0;
83 if (!muc1.isEmpty() )
84 ++num;
85 if (!muc2.isEmpty() )
86 ++num;
87 if (!muc3.isEmpty() )
88 ++num;
89 if (!muc4.isEmpty() )
90 ++num;
91 if (!muc5.isEmpty() )
92 ++num;
93 return num;
97 void MultipleChoice::normalize()
99 // fill from first to last
101 if (muc1.isEmpty()) {
102 muc1 = muc2;
103 muc2 = "";
106 if (muc2.isEmpty()) {
107 muc2 = muc3;
108 muc3 = "";
111 if (muc3.isEmpty()) {
112 muc3 = muc4;
113 muc4 = "";
116 if (muc4.isEmpty()) {
117 muc4 = muc5;
118 muc5 = "";