~ubuntu-branches/ubuntu/precise/kalzium/precise

« back to all changes in this revision

Viewing changes to src/search.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Philip Muškovac
  • Date: 2011-07-03 12:28:58 UTC
  • Revision ID: james.westby@ubuntu.com-20110703122858-q1yyxncs89e4w0hs
Tags: upstream-4.6.90+repack
Import upstream version 4.6.90+repack

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2006      by Pino Toscano, toscano.pino@tiscali.it      *
 
3
 *                                                                         *
 
4
 *   This program is free software; you can redistribute it and/or modify  *
 
5
 *   it under the terms of the GNU General Public License as published by  *
 
6
 *   the Free Software Foundation; either version 2 of the License, or     *
 
7
 *   (at your option) any later version.                                   *
 
8
 *                                                                         *
 
9
 *   This program is distributed in the hope that it will be useful,       *
 
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
12
 *   GNU General Public License for more details.                          *
 
13
 *                                                                         *
 
14
 *   You should have received a copy of the GNU General Public License     *
 
15
 *   along with this program; if not, write to the                         *
 
16
 *   Free Software Foundation, Inc.,                                       *
 
17
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
 
18
 ***************************************************************************/
 
19
 
 
20
#include "search.h"
 
21
 
 
22
#include "element.h"
 
23
#include "kalziumdataobject.h"
 
24
 
 
25
Search::Search()
 
26
        : m_isActive( false ), m_searchKind( Search::SearchAll )
 
27
{
 
28
}
 
29
 
 
30
QString Search::searchText() const
 
31
{
 
32
    return m_searchText;
 
33
}
 
34
 
 
35
Search::SearchKind Search::searchKind() const
 
36
{
 
37
    return m_searchKind;
 
38
}
 
39
 
 
40
bool Search::isActive() const
 
41
{
 
42
    return m_isActive;
 
43
}
 
44
 
 
45
const QList<Element*>& Search::foundElements() const
 
46
{
 
47
    return m_foundElements;
 
48
}
 
49
 
 
50
bool Search::matches( Element* e ) const
 
51
{
 
52
    return m_foundElements.contains( e );
 
53
}
 
54
 
 
55
bool Search::matches(int el) const
 
56
{
 
57
    Element *element =  KalziumDataObject::instance()->element( el );
 
58
    return matches(element);
 
59
}
 
60
 
 
61
void Search::doSearch( const QString& text, SearchKind kind )
 
62
{
 
63
    m_isActive = true;
 
64
    m_searchText = text;
 
65
    m_searchKind = kind;
 
66
    QList<Element*> newresults;
 
67
    foreach( Element* e, KalziumDataObject::instance()->ElementList )
 
68
    {
 
69
        bool found = false;
 
70
        if ( !found && e->dataAsString( ChemicalDataObject::name ).contains( text, Qt::CaseInsensitive ) ) found = true;
 
71
        if ( !found && e->dataAsString( ChemicalDataObject::symbol ).contains( text, Qt::CaseInsensitive ) ) found = true;
 
72
        if ( found )
 
73
            newresults << e;
 
74
    }
 
75
    if ( newresults != m_foundElements )
 
76
    {
 
77
        m_foundElements = newresults;
 
78
        emit searchChanged();
 
79
    }
 
80
}
 
81
 
 
82
void Search::resetSearch()
 
83
{
 
84
    if ( !m_isActive ) return;
 
85
 
 
86
    m_foundElements.clear();
 
87
    m_isActive = false;
 
88
    emit searchReset();
 
89
}
 
90
 
 
91
#include "search.moc"