~thomas-moenicke/phablet-extras/maliit-plugins-0.99-server

« back to all changes in this revision

Viewing changes to maliit-keyboard/tests/preedit-string/wordengineprobe.cpp

  • Committer: Thomas Moenicke
  • Date: 2012-11-21 15:19:50 UTC
  • mto: This revision was merged to the branch mainline in revision 2086.
  • Revision ID: thomas.moenicke@canonical.com-20121121151950-vwz3ilncpu0r4rjj
* merging 
* New release 
* New release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * This file is part of Maliit Plugins
3
 
 *
4
 
 * Copyright (C) 2012 Openismus GmbH
5
 
 *
6
 
 * Contact: maliit-discuss@lists.maliit.org
7
 
 *
8
 
 * Redistribution and use in source and binary forms, with or without modification,
9
 
 * are permitted provided that the following conditions are met:
10
 
 *
11
 
 * Redistributions of source code must retain the above copyright notice, this list
12
 
 * of conditions and the following disclaimer.
13
 
 * Redistributions in binary form must reproduce the above copyright notice, this list
14
 
 * of conditions and the following disclaimer in the documentation and/or other materials
15
 
 * provided with the distribution.
16
 
 * Neither the name of Nokia Corporation nor the names of its contributors may be
17
 
 * used to endorse or promote products derived from this software without specific
18
 
 * prior written permission.
19
 
 *
20
 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
21
 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22
 
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23
 
 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24
 
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
 
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26
 
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
 
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28
 
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 
 *
30
 
 */
31
 
 
32
 
#include "wordengineprobe.h"
33
 
 
34
 
namespace MaliitKeyboard {
35
 
namespace Logic {
36
 
 
37
 
//! \class WordEngineProbe
38
 
//! A word engine that deterministically predicts word candidates, in
39
 
//! such a way that it can be used for tests. Does not require
40
 
//! Hunspell or Presage. This word engine is for language where all
41
 
//! words begin with "a" and ends with "d". So, if we type "abc" we
42
 
//! can expect "abcd". If we type "abcd" we expect no candidates, but
43
 
//! it is a correct word. If we type "bcd" then we get no candidates,
44
 
//! because this word is wrong - it does not begin with "a".
45
 
 
46
 
 
47
 
//! \param parent The owner of this instance (optional).
48
 
WordEngineProbe::WordEngineProbe(QObject *parent)
49
 
    : AbstractWordEngine(parent)
50
 
{}
51
 
 
52
 
 
53
 
WordEngineProbe::~WordEngineProbe()
54
 
{}
55
 
 
56
 
 
57
 
//! \brief Returns new candidates.
58
 
//! \param text Text model.
59
 
WordCandidateList WordEngineProbe::fetchCandidates(Model::Text *text)
60
 
{
61
 
    const QString preedit(text->preedit());
62
 
    WordCandidateList result;
63
 
    Model::Text::PreeditFace face;
64
 
 
65
 
    if (preedit.left(1) == "a") {
66
 
        if (preedit.right(1) == "d") {
67
 
            // simulates case when there are no candidates but preedit
68
 
            // has incorrect spelling
69
 
            face = Model::Text::PreeditDefault;
70
 
        } else {
71
 
            // simulates case when there are some candidates, preedit
72
 
            // spelling correctnes is not important here.
73
 
            WordCandidate candidate;
74
 
            candidate.rLabel().setText(preedit + "d");
75
 
            result << candidate;
76
 
            face = Model::Text::PreeditActive;
77
 
        }
78
 
    } else {
79
 
        // simulates case when there are no candidates and preedit has
80
 
        // incorrect spelling
81
 
        face = Model::Text::PreeditNoCandidates;
82
 
    }
83
 
 
84
 
    text->setPreeditFace(face);
85
 
    return result;
86
 
}
87
 
 
88
 
}} // namespace MaliitKeyboard::Logic